Skip to content

Commit 80ed24d

Browse files
committed
remove debug logging, better serialization behavior for numberish/booleanish strings
1 parent dc7ed7c commit 80ed24d

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

flag-url-override-plugin.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,34 @@ export function createFlagUrlOverridePlugin(options = {}) {
4646
return overrides;
4747
}
4848

49+
/**
50+
* Serialize a value for URL storage
51+
* Adds quotes to strings that would be interpreted as other JSON types
52+
*/
53+
function serializeValue(value) {
54+
if (typeof value === 'string') {
55+
// Check if the string would be parsed as a different type
56+
try {
57+
const parsed = JSON.parse(value);
58+
// If parsing succeeds and changes the type, we need to quote it
59+
if (typeof parsed !== 'string') {
60+
return JSON.stringify(value);
61+
}
62+
} catch (e) {
63+
// Not valid JSON, just a regular string
64+
}
65+
// For regular strings, just return as-is (no extra quotes)
66+
return value;
67+
}
68+
// For non-strings (booleans, numbers, objects), use JSON.stringify
69+
return JSON.stringify(value);
70+
}
71+
4972
/**
5073
* Sync overrides to URL using replaceState
5174
*/
5275
function syncOverridesToUrl(overrides) {
5376
try {
54-
logger.log('[syncOverridesToUrl] Called with overrides:', overrides);
5577
const url = new URL(window.location.href);
5678
const params = url.searchParams;
5779

@@ -66,30 +88,25 @@ export function createFlagUrlOverridePlugin(options = {}) {
6688

6789
// Add current overrides
6890
Object.entries(overrides).forEach(([flagKey, value]) => {
69-
params.set(`${parameterPrefix}${flagKey}`, JSON.stringify(value));
91+
params.set(`${parameterPrefix}${flagKey}`, serializeValue(value));
7092
});
7193

7294
// Update URL without reloading or creating history entry
73-
logger.log('[syncOverridesToUrl] About to call replaceState with URL:', url.toString());
7495
window.history.replaceState({}, '', url.toString());
75-
logger.log('[syncOverridesToUrl] Successfully updated URL');
7696
} catch (error) {
77-
logger.error('[syncOverridesToUrl] Error:', error);
97+
logger.error('Failed to sync overrides to URL:', error);
7898
}
7999
}
80100

81101
// Monkey patch setOverride to sync to URL and update display
82102
const originalSetOverride = plugin.setOverride.bind(plugin);
83103
plugin.setOverride = function(flagKey, value) {
84-
logger.log('[setOverride] Called with flagKey:', flagKey, 'value:', value);
85104
originalSetOverride(flagKey, value);
86-
logger.log('[setOverride] About to sync to URL');
87105
syncOverridesToUrl(this.getAllOverrides());
88106
// Notify callback if registered
89107
if (updateDisplayCallback) {
90108
updateDisplayCallback(flagKey, 'set');
91109
}
92-
logger.log('[setOverride] Completed');
93110
};
94111

95112
// Monkey patch removeOverride to sync to URL and update display

0 commit comments

Comments
 (0)