mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem The `ask-the-docs` feature-flags reference describes the docs experiments as they worked before the IA nav (`docs-ia-mvp-v1`) changes, so agents give wrong answers about how to preview the new nav and why a reader sees a variant: - It says a `?<flag>=<variant>` URL override applies only to the page in the URL. Since #53381, the IA nav hook saves the override in `sessionStorage`, so it lasts until the tab closes. - It doesn't mention the layout switch from #53688. The switch saves the reader's pick in `localStorage`, the pick wins over the flag unless the flag is off, and picking a layout clears the saved override. - It says the server always renders `control`. Since #52735, `proxy.ts` server-renders a variant that the URL forces on the docs home and guide pages. - Its hook rules say every variant hook caches in `localStorage`, but the getting-started hook hides its content until the flags load instead. The A/B test for the new nav launched on 2026-12-01, so these questions come up now. Resolves [DOCS-1832](https://linear.app/supabase/issue/DOCS-1832). ## Solution In `.agents/skills/ask-the-docs/reference/feature-flags.md`: - Says the override lasts one page by default, that the IA nav keeps it until the tab closes, and that `?docs-ia-mvp-v1=control` goes back - Describes both pre-flag approaches in the hook rules: cache like the IA nav, or hide until the flags load like getting-started - Updates the exposure rule and gotcha for saved overrides and layout choices - Lists the order the IA nav head script checks, and adds gotchas for the proxy rewrite and the layout switch - Adds a `Verified at` line, after checking every line against `c1330ca99f` In `.agents/skills/ask-the-docs/reference/app-map.md`, the "Layout v2" paragraph now mentions how long the override lasts and the layout switch. Its `Verified at` line stays as is, because only that paragraph was checked. These were checked on supabase.com: the override survives links and reloads and ends with the tab, `?docs-ia-mvp-v1=control` goes back, the layout switch clears the override and saves its pick, the getting-started override reads only the URL, and a forced guide page has the new nav in its server HTML. ## Review category (docs PRs only) - [ ] Critical: needs a review as soon as possible - [ ] Urgent: the feature ships soon, or it's blocking something else - [ ] Moderate: good to have soon, not urgent - [x] Low: get to it when you can ## Review instructions 1. Read the diff of `feature-flags.md` and the "Layout v2" paragraph in `app-map.md` 2. Compare the override and layout claims with `apps/docs/features/IaNav/useIaNavVariant.ts`, `layoutChoice.ts`, and `IA_NAV_CACHE_SCRIPT` in `constants.ts` 3. Compare the server-render gotcha with `forcedVariantRewrite` in `apps/docs/proxy.ts` 4. Compare the hook rules with `apps/docs/features/getting-started/useGettingStartedVariant.ts` ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
7.3 KiB
7.3 KiB
Feature flags in apps/docs
Docs has two flag systems. Static flags resolve at build time. PostHog flags resolve in the browser.
Verified at: c1330ca99f (2026-12-01).
Static flags (enabled-features)
- Source:
packages/common/enabled-features/enabled-features.json. The schema isenabled-features.schema.jsonin the same folder. - Read a flag with
isFeatureEnabledfromcommon/enabled-features. One key returns a boolean. An array of keys returns an object with camelCased names ('logs:templates'becomeslogsTemplates). - To add a flag, follow
packages/common/enabled-features/README.md. Do not copy those steps here. - Studio-only runtime overrides (
ENABLED_FEATURES_*env vars,profile.disabled_features) do not apply to docs. Docs reads the JSON at build time. ENABLED_FEATURES_OVERRIDE_DISABLE_ALL=truemakes everyisFeatureEnabledcall returnfalse. Theembeddings:nimbusandembeddings:nimbus:refreshscripts inapps/docs/package.jsonset it to build the filtered search index.
Where docs uses static flags:
| Place | Effect |
|---|---|
components/Navigation/NavigationMenu/NavigationMenu.constants.ts |
Nav items use an enabled value from isFeatureEnabled([...]). |
features/directives/Show.ts ($Show in MDX) |
<$Show if="flag"> keeps or removes content. if="!flag" negates. |
lib/content-listings.utils.ts |
A content listing item with a feature field drops out when the flag is off. |
internals/generate-reference-markdown.ts |
Skips a reference whose feature flag is off. |
PostHog flags
features/app.providers.tsxwraps the app inFeatureFlagProviderfrompackages/common/feature-flags.tsx. It passesenabled={IS_PLATFORM}, so flags load only when the app runs on the platform.- The provider loads PostHog flags from the platform API path
/telemetry/feature-flags. - Read them with
useFeatureFlags()fromcommon. Use theposthogobject (flag key to value) and thehasLoadedboolean. BeforehasLoadedistrue,posthogis empty. - Local and staging only: the dev toolbar writes the
x-ph-flag-overridescookie, and the provider merges it intoposthog. See../../dev-toolbar-review/SKILL.md. - Reload the page to apply a toolbar override. The provider ignores the cookie when no PostHog flags load, so the override does nothing in a local build.
Without Supabase access
- A local build is not on the platform, so no PostHog flags load. Variant hooks return
controlor the value cached from an earlier visit. The IA nav hook also uses a saved override or a saved layout choice (see Gotchas). - The URL override still works.
?<flag>=<variant>shows that variant locally with no PostHog access. - Navigation links drop the query parameter. By default, a hook reads the override only from the URL, so add the parameter to each page that you want to preview. After you follow a link, the page returns to
controlor the cached variant. - The IA nav hook (
features/IaNav/useIaNavVariant.ts) is the exception. It saves a valid override insessionStorage, so it lasts until you close the tab. To go back, open a page with?docs-ia-mvp-v1=control. - Only Supabase staff can create, change, or ramp PostHog flags. Contributors without access suggest an experiment in the PR or a GitHub issue. See
pm-the-docsfor both paths.
Variant hook pattern
Each experiment reads its flag through a variant hook. To find the current hooks, search apps/docs for captureExperimentExposure. A variant hook follows these rules:
- Decide what shows before the flags load. Either use the value from the last visit, stored in
localStorage, as the IA nav hook does, or hide the changed content until the flags load and showcontrolafter a timeout, as the getting-started hook does. A cached value can be any variant, not onlycontrol. - If the hook caches, keep the cached value after
hasLoadedistrueif PostHog returns no flags (an empty response or a failed request). Only a non-empty response replaces the cache. - If the cached or loaded flag value is not a known variant, use
controlunless a valid URL override applies. - Let the
?<flag>=<variant>query parameter override the variant. Only known variants count. By default, the override lasts for one page. A site-wide change, like the IA nav, can also save it insessionStorage, because links drop the parameter. - Treat a
falseflag value as "outside the rollout", not as an assignment tocontrol. - Call
posthogClient.captureExperimentExposure(flag, { variant }, hasAccepted)only when the loaded flag picks the variant: no URL or saved override, and no layout the reader chose. Pass the consent value fromuseConsentState. A cached value never records an exposure.
Write tests for each variant hook, next to the hook.
To test a nav variant, override the nav constants for that variant and select them in a hook. Every nav consumer must read the nav items from that hook.
Gotchas
$Showreads static flags only. It cannot read PostHog flags. For a PostHog-driven change, branch in a React component with a variant hook.- The server renders
control, so a visitor in another variant can see a flicker. To limit it, add an inline script toapp/layout.tsx. The script reads the variant before paint and marks<html>. The changed component hides itself until hydration when that mark is set. Add a fallback that restores visibility if hydration does not complete. The IA nav script,IA_NAV_CACHE_SCRIPTinfeatures/IaNav/constants.ts, checks the URL override, then the saved override, then the saved layout choice, then the cached flag. - A URL that forces an IA nav variant doesn't flicker on the docs home or on guide pages.
proxy.tsrewrites the request to a variant route, so the server renders that variant, andIaNavRouteProviderpasses it to the hook. - A first-time visitor has no cached value, so the flicker can still happen on the first visit.
- Exposure is not recorded for a forced variant (URL or saved override), a layout the reader chose, or a cached value.
- The IA nav layout switch (
features/DocsLayout/LayoutSwitchButton.tsx) saves the reader's pick inlocalStoragethroughsetLayoutChoice(features/IaNav/layoutChoice.ts). The pick lasts across sessions and wins over the flag, unless the flag is off. Picking a layout also clears the saved override. - The cache is a
localStoragevalue. A stale value can show the wrong variant until the flags load.
Related
../../telemetry-standards/SKILL.md, section "Feature Flag Measurement". It describes Studio patterns (usePHFlag). Use it for measurement ideas, not as a docs hook template.../../dev-toolbar-review/SKILL.mdfor the override cookies and environment guards.- PMs: see
pm-the-docs. Docs engineering owns creating and ramping PostHog flags. Contributors without Supabase access follow the OSS path inpm-the-docs. - Example (2026): the IA nav experiment, flag
docs-ia-mvp-v1, infeatures/IaNav/. It can be removed after the experiment ends.