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>
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { LOCAL_STORAGE_KEYS } from 'common/constants/local-storage'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
|
|
import { IA_NAV_CACHE_SCRIPT, IA_NAV_FLAG, IA_NAV_OVERRIDE_KEY } from './constants'
|
|
|
|
// the layout inlines this string in <head>, so the test runs it the same way the browser does
|
|
const runCacheScript = () => new Function(IA_NAV_CACHE_SCRIPT)()
|
|
|
|
describe('IA_NAV_CACHE_SCRIPT', () => {
|
|
afterEach(() => {
|
|
localStorage.clear()
|
|
sessionStorage.clear()
|
|
delete document.documentElement.dataset.iaNav
|
|
window.history.replaceState(null, '', '/')
|
|
})
|
|
|
|
it('marks the page for a visitor cached on option-1', () => {
|
|
localStorage.setItem(LOCAL_STORAGE_KEYS.IA_NAV_FLAG, 'option-1')
|
|
|
|
runCacheScript()
|
|
|
|
expect(document.documentElement.dataset.iaNav).toBe('option-1')
|
|
})
|
|
|
|
it('leaves the page unmarked for a visitor cached on control', () => {
|
|
localStorage.setItem(LOCAL_STORAGE_KEYS.IA_NAV_FLAG, 'control')
|
|
|
|
runCacheScript()
|
|
|
|
expect(document.documentElement.dataset.iaNav).toBeUndefined()
|
|
})
|
|
|
|
it('marks the page when the url forces option-1', () => {
|
|
window.history.replaceState(null, '', `/?${IA_NAV_FLAG}=option-1`)
|
|
|
|
runCacheScript()
|
|
|
|
expect(document.documentElement.dataset.iaNav).toBe('option-1')
|
|
})
|
|
|
|
it('marks the page from a saved override when the url has no param', () => {
|
|
localStorage.setItem(LOCAL_STORAGE_KEYS.IA_NAV_FLAG, 'false')
|
|
sessionStorage.setItem(IA_NAV_OVERRIDE_KEY, 'option-1')
|
|
|
|
runCacheScript()
|
|
|
|
expect(document.documentElement.dataset.iaNav).toBe('option-1')
|
|
})
|
|
|
|
it('leaves the page unmarked when the url forces control over a saved option-1', () => {
|
|
sessionStorage.setItem(IA_NAV_OVERRIDE_KEY, 'option-1')
|
|
window.history.replaceState(null, '', `/?${IA_NAV_FLAG}=control`)
|
|
|
|
runCacheScript()
|
|
|
|
expect(document.documentElement.dataset.iaNav).toBeUndefined()
|
|
})
|
|
|
|
it('leaves the page unmarked when the url forces control over a cached option-1', () => {
|
|
localStorage.setItem(LOCAL_STORAGE_KEYS.IA_NAV_FLAG, 'option-1')
|
|
window.history.replaceState(null, '', `/?${IA_NAV_FLAG}=control`)
|
|
|
|
runCacheScript()
|
|
|
|
expect(document.documentElement.dataset.iaNav).toBeUndefined()
|
|
})
|
|
})
|