mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 00:19:08 +00:00
Part of DOCS-1474 ## Problem Someone dogfooding the new navigation opens `?docs-ia-mvp-v1=option-1`, clicks a link, and sees today's navigation again. The override lives only in the URL. Links do not carry the query string, so the first click drops it. Everyone who uses the override link is affected, including people outside the PostHog rollout. ## Solution - **Save the override:** a forced variant is saved in `sessionStorage` and read on later pages. Closing the tab clears it. - **Read it before paint:** the head script reads the saved override, so a full reload does not flash today's navigation. - **Keep exposure clean:** a saved override records no PostHog exposure, the same as a URL override. - **Switch back:** `?docs-ia-mvp-v1=control` replaces the saved value. **Priority:** the URL wins over the saved override. The saved override wins over the PostHog value. **Not changed:** the `/docs/ia/option-1/…` rewrite that the evals use, and how PostHog assigns visitors. **Tests:** `vitest run features/IaNav` passes, 7 files and 32 tests. Three of the four new tests failed before the change. The fourth, a URL `control` over a saved `option-1`, passed before and guards the priority. **Unverified:** typecheck, ESLint, and the steps below. `tsc` reports no errors in `IaNav`, but this worktree has no generated GraphQL types. ESLint did not run. ## Manual testing 1. Open the deploy preview at `/docs?docs-ia-mvp-v1=option-1`. The top nav shows "Run and manage". 2. Click any guide link. The nav still shows "Run and manage". 3. Reload the page. The nav shows "Run and manage" with no flash of today's navigation. 4. Open `/docs?docs-ia-mvp-v1=control`, then click any guide link. The nav shows today's navigation and keeps it. --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
26 lines
1.4 KiB
TypeScript
26 lines
1.4 KiB
TypeScript
import { LOCAL_STORAGE_KEYS } from 'common/constants/local-storage'
|
|
|
|
// PostHog multivariate flag for the new docs information architecture.
|
|
export const IA_NAV_FLAG = 'docs-ia-mvp-v1'
|
|
|
|
export type IaNavVariant = 'control' | 'option-1'
|
|
|
|
const VARIANTS: IaNavVariant[] = ['control', 'option-1']
|
|
|
|
export const isIaNavVariant = (value: unknown): value is IaNavVariant =>
|
|
VARIANTS.includes(value as IaNavVariant)
|
|
|
|
// A forced variant is kept for the browser session, because links don't carry the query parameter.
|
|
export const IA_NAV_OVERRIDE_KEY = 'docs-ia-mvp-v1-override'
|
|
|
|
// runs before paint, so a visitor on option-1 never sees the control nav the server renders.
|
|
// the url override wins over the session override, which wins over the value from the last visit
|
|
export const IA_NAV_CACHE_SCRIPT = `try{var V=${JSON.stringify(VARIANTS)};var o=new URLSearchParams(location.search).get('${IA_NAV_FLAG}');var s=V.indexOf(o)>-1?o:sessionStorage.getItem('${IA_NAV_OVERRIDE_KEY}');var v=V.indexOf(s)>-1?s:localStorage.getItem('${LOCAL_STORAGE_KEYS.IA_NAV_FLAG}');if(v==='option-1')document.documentElement.dataset.iaNav='option-1'}catch(e){}`
|
|
|
|
export const IA_NAV_PENDING_CLASS = 'in-data-[ia-nav=option-1]:invisible'
|
|
|
|
// Requests that force a variant are rewritten under this segment so the server HTML has its nav.
|
|
export const IA_NAV_ROUTE_SEGMENT = 'ia'
|
|
|
|
export const iaNavRoutePrefix = (variant: IaNavVariant) => `/${IA_NAV_ROUTE_SEGMENT}/${variant}`
|