mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-19 22:09:37 +00:00
## Summary
- Adds `localStorage`-based dev-time override for feature flags, with
`ff:` key prefix (e.g.
`localStorage.setItem('ff:team_workspaces_enabled', 'true')`)
- Override priority: dev localStorage > remoteConfig >
serverFeatureFlags
- Guarded by `import.meta.env.DEV` — tree-shaken to empty function in
production builds
- Extracts `resolveFlag` helper in `useFeatureFlags` to eliminate
repeated fallback pattern
Fixes #9054
## Test plan
- [x] `getDevOverride` unit tests: boolean/number/string/object parsing,
prefix isolation, invalid JSON warning
- [x] `api.getServerFeature` / `serverSupportsFeature` override tests
- [x] `useFeatureFlags` override priority tests, including
`teamWorkspacesEnabled` bypassing guards
- [x] Production build verified: `getDevOverride` compiles to empty
function body, localStorage never accessed
- [x] `pnpm typecheck`, `pnpm lint` clean
┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-9075-feat-add-dev-time-feature-flag-overrides-via-localStorage-30f6d73d365081b394d3ccc461987b1a)
by [Unito](https://www.unito.io)
27 lines
925 B
TypeScript
27 lines
925 B
TypeScript
const FF_PREFIX = 'ff:'
|
|
|
|
/**
|
|
* Gets a dev-time feature flag override from localStorage.
|
|
* Stripped from production builds via import.meta.env.DEV tree-shaking.
|
|
*
|
|
* Returns undefined (not null) as the "no override" sentinel because
|
|
* null is a valid JSON value — JSON.parse('null') returns null.
|
|
* Using undefined avoids ambiguity between "no override set" and
|
|
* "override explicitly set to null".
|
|
*
|
|
* Usage in browser console:
|
|
* localStorage.setItem('ff:team_workspaces_enabled', 'true')
|
|
* localStorage.removeItem('ff:team_workspaces_enabled')
|
|
*/
|
|
export function getDevOverride<T>(flagKey: string): T | undefined {
|
|
if (!import.meta.env.DEV) return undefined
|
|
const raw = localStorage.getItem(`${FF_PREFIX}${flagKey}`)
|
|
if (raw === null) return undefined
|
|
try {
|
|
return JSON.parse(raw) as T
|
|
} catch {
|
|
console.warn(`[ff] Invalid JSON for override "${flagKey}":`, raw)
|
|
return undefined
|
|
}
|
|
}
|