Files
supabase/.agents/skills/ask-the-docs/reference/feature-flags.md
Alexis Aguilar 6482c700f9 docs(skills): update the ask-the-docs feature flag notes for the IA nav experiment (#54442)
## 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)
2026-12-01 17:04:51 -07:00

71 lines
7.3 KiB
Markdown

# 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 is `enabled-features.schema.json` in the same folder.
- Read a flag with `isFeatureEnabled` from `common/enabled-features`. One key returns a boolean. An array of keys returns an object with camelCased names (`'logs:templates'` becomes `logsTemplates`).
- 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=true` makes every `isFeatureEnabled` call return `false`. The `embeddings:nimbus` and `embeddings:nimbus:refresh` scripts in `apps/docs/package.json` set 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.tsx` wraps the app in `FeatureFlagProvider` from `packages/common/feature-flags.tsx`. It passes `enabled={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()` from `common`. Use the `posthog` object (flag key to value) and the `hasLoaded` boolean. Before `hasLoaded` is `true`, `posthog` is empty.
- Local and staging only: the dev toolbar writes the `x-ph-flag-overrides` cookie, and the provider merges it into `posthog`. 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 `control` or the value cached from an earlier visit. The IA nav hook also uses a saved override or a saved layout choice (see [Gotchas](#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 `control` or the cached variant.
- The IA nav hook (`features/IaNav/useIaNavVariant.ts`) is the exception. It saves a valid override in `sessionStorage`, 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-docs` for 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:
1. 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 show `control` after a timeout, as the getting-started hook does. A cached value can be any variant, not only `control`.
2. If the hook caches, keep the cached value after `hasLoaded` is `true` if PostHog returns no flags (an empty response or a failed request). Only a non-empty response replaces the cache.
3. If the cached or loaded flag value is not a known variant, use `control` unless a valid URL override applies.
4. 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 in `sessionStorage`, because links drop the parameter.
5. Treat a `false` flag value as "outside the rollout", not as an assignment to `control`.
6. 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 from `useConsentState`. 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
- `$Show` reads 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 to `app/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_SCRIPT` in `features/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.ts` rewrites the request to a variant route, so the server renders that variant, and `IaNavRouteProvider` passes 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 in `localStorage` through `setLayoutChoice` (`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 `localStorage` value. 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.md` for 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 in `pm-the-docs`.
- Example (2026): the IA nav experiment, flag `docs-ia-mvp-v1`, in `features/IaNav/`. It can be removed after the experiment ends.