Skip to content

Commit 3aca2d3

Browse files
committed
docs: document clear mode configuration and usage
1 parent 5850810 commit 3aca2d3

File tree

1 file changed

+67
-4
lines changed

1 file changed

+67
-4
lines changed

README.md

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ A simple HTML5 application that provides a visual interface for viewing and mana
4747
https://your-github-username.github.io/repo-name/
4848
```
4949

50-
2. **Enter your LaunchDarkly Client-Side ID**
51-
- Paste your client-side ID in the configuration form
52-
- Click "Load SDK"
53-
- The SDK will initialize and display all your flags
50+
2. **Configure the Application**
51+
- **Client-Side ID**: Paste your LaunchDarkly client-side ID
52+
- **Override Behavior**: Choose how URL overrides interact with local storage:
53+
- *Auto* (default) - When the URL contains overrides, clear any overrides not present in the URL
54+
- *Explicit* - Only clear existing local overrides when URL includes `ld_override__clear`.
55+
- *Always* - Always clears local storage and then loads overrides from the URL. Effectively ignores local storage.
56+
- Click "Load SDK" to initialize
5457

5558
3. **View and Override Flags**
5659
- All flags are displayed with their current values
@@ -80,6 +83,66 @@ Values are JSON-encoded, supporting:
8083
- Strings: `"hello"`
8184
- JSON objects: `{"key":"value"}`
8285

86+
### Advanced Override Control
87+
88+
**Automatic localStorage clearing** (default behavior): When you share a URL with override parameters, existing overrides from localStorage are **automatically cleared** first. This ensures shared URLs work reliably - recipients see exactly the flag configuration you intended.
89+
90+
**Example:**
91+
```
92+
?clientSideId=abc&ld_override_feature=true&ld_override_theme=dark
93+
```
94+
When someone opens this URL, their existing localStorage overrides are cleared first, then your overrides are applied. This prevents conflicts and ensures predictable behavior.
95+
96+
**Additional control options:**
97+
98+
**Explicit clear flag:**
99+
```
100+
?ld_override__clear&ld_override_my-flag=value
101+
```
102+
Add `ld_override__clear` (just needs to be present) to explicitly signal clearing. This works regardless of clear mode settings.
103+
104+
**Remove specific overrides:**
105+
```
106+
?ld_override_old-flag=&ld_override_new-flag=value
107+
```
108+
Use an empty value (e.g., `ld_override_flagname=`) to explicitly remove a specific flag's override while keeping others.
109+
110+
**Configuring clear behavior:**
111+
112+
Clear mode can be set in two ways:
113+
114+
1. **Via UI Dropdown** (easiest): Select the "Override Behavior" option in the configuration form
115+
- Changes are saved to the URL as `?clearMode=auto/explicit/always`
116+
- Click "Load SDK" to apply changes
117+
118+
2. **Via URL Parameter**: Add `?clearMode=auto` to the URL
119+
```
120+
?clientSideId=abc&clearMode=explicit&ld_override_feature=true
121+
```
122+
123+
3. **Via Code** (advanced): Configure in `app.js` when creating the plugin
124+
```javascript
125+
import { createFlagUrlOverridePlugin, CLEAR_MODE_AUTO } from './flag-url-override-plugin.js';
126+
127+
const plugin = createFlagUrlOverridePlugin({
128+
clearMode: CLEAR_MODE_AUTO, // default: auto-clear when URL has overrides
129+
// clearMode: CLEAR_MODE_EXPLICIT, // only clear if ld_override__clear present
130+
// clearMode: CLEAR_MODE_ALWAYS, // always clear, even without URL overrides
131+
});
132+
```
133+
134+
**Clear modes:**
135+
- **Auto** (default) - Auto-clear localStorage when URL has override parameters
136+
- URL: `clearMode=auto` → Plugin: `CLEAR_MODE_AUTO`
137+
- **Explicit** - Only clear if `ld_override__clear` is present
138+
- URL: `clearMode=explicit` → Plugin: `CLEAR_MODE_EXPLICIT`
139+
- **Always** - Always clear localStorage before loading overrides
140+
- URL: `clearMode=always` → Plugin: `CLEAR_MODE_ALWAYS`
141+
142+
**Note:** The plugin API requires symbol values (`CLEAR_MODE_AUTO`), not strings. The application automatically converts URL string parameters to symbols.
143+
144+
**Note:** The double underscore in `_clear` prevents conflicts with flag names (flags cannot start with underscore).
145+
83146
## Architecture
84147

85148
### Files

0 commit comments

Comments
 (0)