Repository navigation
fix(layout): a client-side navigation announces nothing and moves no focus - #72
Conversation
… page
Vike Client Routing swaps the page under `<main>` while the chrome persists, so
a navigation does none of what a full page load does for free. `document.title`
changed with nothing to speak it — a WCAG 2.1 4.1.3 Status Messages (AA) gap —
and focus was never moved: a header link left focus in the nav, and a body link
dropped it to `<body>`, so the next Tab restarted from the top of the document.
The two hooks that are the natural home for this did nothing but write four
`console.log` lines per navigation and toggle a `page-transition` body class
that no stylesheet used (`grep -rn "page-transition" .` matched only those two
files; the repo's four stylesheets reference it nowhere).
- `lib/route-announcer.ts` — new. Owns both ids and the announce-and-focus
decision, against a narrow `AnnouncerDocument` interface so the node-only test
lane can drive it with no jsdom. The ids are constants rather than strings
typed at each of the three call sites because drift here fails SILENTLY:
`getElementById` returns null and the optional chain swallows it.
- `layouts/LayoutRoot.tsx` — one `sr-only` polite region, rendered once. In the
ROOT layout so bare embed routes announce too, and left empty on mount: a live
region only announces content inserted into a region the reader was already
observing, so seeding it would say nothing.
- `layouts/LayoutChrome.tsx`, `layouts/LayoutMap.tsx` — `id` + `tabIndex={-1}`
on `<main>`: focusable programmatically, absent from the tab order.
- `pages/+onPageTransitionEnd.ts` — calls it; the `console.log`s are gone.
- `pages/+onPageTransitionStart.ts` — deleted. Removing the dead class left the
function empty, and an empty Vike hook is the same dead code the ticket is
about.
Back/forward announces but does NOT move focus: the browser restores the
previous scroll position there, and focusing `<main>` would scroll to the top
and lose the reader's place.
`LayoutRoot.test.tsx` asserted byte-identical passthrough, which the announcer
changes. It stays a byte-for-byte equality against children + the announcer
rather than relaxing to `toContain` — "renders no chrome" is the property that
file exists to hold, and `toContain` would wave through the next addition.
Both new behaviours were watched failing: removing the back/forward guard reds
the back/forward case, and removing the focus call reds the other three.
Closes #70
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mva72DLxKBWJkgLkRXKwnA
Three parts of #70 look like dead markup to someone cleaning up, and each fails silently when removed: `tabIndex={-1}` on `<main>` (what makes it focusable without entering the tab order), the announcer being created once and left empty (a live region only announces into a region already being observed), and back/forward deliberately not moving focus (the browser has restored the scroll position; focusing `<main>` would undo it). Goes in the design-system rule because its `paths:` already cover `layouts/**` and `components/**` — so it loads for exactly the person about to touch this. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mva72DLxKBWJkgLkRXKwnA
Deploying wemeditate-design with
|
| Latest commit: |
d3129a2
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d9fbd0a2.wm-design.pages.dev |
| Branch Preview URL: | https://claude-fix-route-announcer.wm-design.pages.dev |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | d3129a2 | Commit Preview URL Branch Preview URL |
Sep 02 2026, 04:28 PM |
Ardnived
left a comment
There was a problem hiding this comment.
Are there any plugins or configurations for Vike that could handle this instead of all these custom code? This seems like a common accessibility problem which should already have a solution.
|
No — Vike ships nothing for this, and neither does Next.js does ship a route announcer — it's inside the router, which is why this feels like solved territory. Vike is deliberately thinner: it hands you
I also don't think a dependency is the right trade for what this is. The whole thing is 63 lines of which ~30 are comment, it has no state, and the two decisions in it are ours rather than a library's: which element takes focus, and that back/forward navigations are announced but not focused, so going Back doesn't throw away the restored scroll position. A generic package would have to be configured into exactly this shape anyway. What I ran, and what a package would still have left us to writeEvidence. Docs, read separately: vike-react enumerates its settings, components and hooks — Prior art I looked at. React Router's accessibility guide tells you to build this yourself, and Remix's does the same — neither ships a component for it. So the pattern here is the documented one, not an invention. The part no package decides for you is the back/forward branch ( Happy to be wrong if you know of a 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
<main>— previously it did neither, so a screen-reader user got no signal at all that the page had changed (WCAG 2.1 4.1.3, AA).<main>would scroll to the top and lose the reader's place. It still announces.page-transitionclass no stylesheet uses. Both are gone.Changes
lib/route-announcer.ts— new; owns the two element ids and the announce-and-focus decision.layouts/LayoutRoot.tsx— the live region, rendered once in the root layout so bare embed routes announce too.layouts/LayoutChrome.tsx,layouts/LayoutMap.tsx—id+tabIndex={-1}on<main>.pages/+onPageTransitionEnd.ts— calls it.pages/+onPageTransitionStart.ts— deleted; see below.docs/rules/design-system.md— its owndocs:commit.Preview
Branch aliases, discovered from the
Workers Buildscheck output and the Cloudflare bot comment:<main>this touches) — https://claude-fix-route-announcer-wemeditate-web.contact-c66.workers.dev/mapI did not stop at a 200. Both routes were fetched and the deployed HTML checked for the two things this PR adds —
id="route-announcer"andid="main-content"are each present exactly once on each, which is what confirms both layouts got the change rather than just the one I could see locally.Worth actually opening: three of the five acceptance criteria are keyboard/screen-reader behaviours no automated lane here can reach.
Test results
eslint .(0 errors),tsc --noEmit(clean),vitest run— 49 files / 511 testslib/route-announcer.test.ts(4),layouts/LayoutRoot.test.tsx(2)vike build— run deliberately, because deleting a+-prefixed file underpages/is a Vike config change and the build is the only thing that checks it; lint and tsc both pass either way.d3129a2.⚠ I ran those local binaries directly out of
node_modules/.binrather than throughpnpm. Everypnpm <script>in this checkout fails before running anything: its deps-status check shells out topnpm install, which exits 1 withERR_PNPM_IGNORED_BUILDS(@sentry/cli,@swc/core,esbuild,msw,sharp,workerd) and writes apnpm-workspace.yamlstub full ofset this to true or falseplaceholders. I deleted that stub rather than committing it. The commands run are exactly what thepackage.jsonscripts expand to, so the coverage is the same — but flagging it rather than reporting a cleanpnpm lintI did not run. CI is unaffected, and green.Both new behaviours were watched failing, at the site that would really cause them:
if (isBackwardNavigation) returnguardmain?.focus?.()call (the pre-existing behaviour)Manual verification
/, click a header nav link and then a body (ContentCard) link. After each, one Tab should land inside the new page rather than back in the nav or at the top of the document.Notes for reviewer
Two judgement calls, both worth a yes/no.
I deleted
pages/+onPageTransitionStart.tsrather than leaving it empty. Dropping the deadpage-transitionclass was the ticket's ask; what remained was a hook with no body, which is the same dead code the ticket is about. One-file revert if you disagree.I left the optional skip link out. The ticket offered it and asked me to say which — it is not a 2.4.1 failure today (the page has real landmarks, which technique ARIA11 accepts), and it is a separate, visible UI change. One behaviour per PR; happy to file it.
LayoutRoot.test.tsxneeded changing, which is worth a look rather than taken on trust: it assertedhtml === 'bare embed content', and the announcer breaks that byte-identity. I kept it a byte-for-byte equality against children + the announcer instead of relaxing totoContain, because "renders no chrome" is the property that file exists to hold and atoContainwould wave through whatever gets added next.Detail — evidence, and why the ids are constants
The dead class, measured.
grep -rn "page-transition" .(excludingnode_modulesand.git) matched only the two hook files. The repo's four stylesheets —components/organisms/SubtleSystem/SubtleSystem.css,layouts/style.css,layouts/tailwind.css,layouts/fonts.css— reference it nowhere. So it was added and removed on every navigation for nothing.Why the ids are shared constants. They are needed in three places — LayoutRoot renders the announcer, the two chrome layouts mark the target, the hook looks both up. A drifted string does not throw:
getElementByIdreturnsnull, the optional chain swallows it, and the feature is silently off with every test still green. The constants make that unrepresentable.Why a narrow
AnnouncerDocumentinterface. The lane is node-only with no jsdom (docs/rules/testing.mdis explicit that it should stay that way), so the module takes the slice ofDocumentit actually touches. The test drives it with a stub recordingtextContentandfocuscalls. That is not a compromise here: the contract under test is which element is looked up and what is done to it, which is exactly what the stub observes. A fourth case covers a missing element on either side — the drift failure mode must stay a no-op, never a throw that takes the navigation down with it.isBackwardNavigationisboolean | null | undefined.tsccaught this: Vike'sPageContexttypes it optional, andnull(first render) andundefinedboth mean "not a back/forward navigation", so both take the focus branch. A third test pins thenullcase.sr-onlyis the established utility here — used byFormBuilderandSpinner, and built into Tailwind 4. The announcer sits beside{children}inside the error boundary, so a page that throws still has it.Closes #70
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01Mva72DLxKBWJkgLkRXKwnA