Skip to content

fix(layout): a client-side navigation announces nothing and moves no focus - #72

Merged
sydevs-bot merged 2 commits into
mainfrom
claude/fix-route-announcer
Sep 2, 2026
Merged

sydevs-bot merged 2 commits into
mainfrom
claude/fix-route-announcer

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • A client-side navigation now announces the new page title into a polite live region, and moves focus into <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).
  • Focus is deliberately not moved on back/forward: the browser has restored the scroll position, and focusing <main> would scroll to the top and lose the reader's place. It still announces.
  • The two transition hooks did nothing but log four lines per navigation and toggle a page-transition class 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 own docs: commit.

Preview

Branch aliases, discovered from the Workers Builds check output and the Cloudflare bot comment:

I 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" and id="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

  • Lean gate: ✓ eslint . (0 errors), tsc --noEmit (clean), vitest run — 49 files / 511 tests
  • Targeted specs: ✓ lib/route-announcer.test.ts (4), layouts/LayoutRoot.test.tsx (2)
  • Build: ✓ vike build — run deliberately, because deleting a +-prefixed file under pages/ is a Vike config change and the build is the only thing that checks it; lint and tsc both pass either way.
  • CI: ✓ 5 of 5 green on d3129a2.

⚠ I ran those local binaries directly out of node_modules/.bin rather than through pnpm. Every pnpm <script> in this checkout fails before running anything: its deps-status check shells out to pnpm install, which exits 1 with ERR_PNPM_IGNORED_BUILDS (@sentry/cli, @swc/core, esbuild, msw, sharp, workerd) and writes a pnpm-workspace.yaml stub full of set this to true or false placeholders. I deleted that stub rather than committing it. The commands run are exactly what the package.json scripts expand to, so the coverage is the same — but flagging it rather than reporting a clean pnpm lint I did not run. CI is unaffected, and green.

Both new behaviours were watched failing, at the site that would really cause them:

Mutation Result
Remove the if (isBackwardNavigation) return guard back/forward case reds — "expected not to be called, been called 1 times"
Remove the main?.focus?.() call (the pre-existing behaviour) the other three red

Manual verification

  1. From /, 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.
  2. With VoiceOver or NVDA, repeat — the new title should be spoken each time.
  3. Navigate forward twice, then Back: the title is spoken, and the scroll position is unchanged from today's behaviour. This is the one that would regress silently if the guard were "simplified" away.

Notes for reviewer

Two judgement calls, both worth a yes/no.

I deleted pages/+onPageTransitionStart.ts rather than leaving it empty. Dropping the dead page-transition class 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.tsx needed changing, which is worth a look rather than taken on trust: it asserted html === '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 to toContain, because "renders no chrome" is the property that file exists to hold and a toContain would wave through whatever gets added next.

Detail — evidence, and why the ids are constants

The dead class, measured. grep -rn "page-transition" . (excluding node_modules and .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: getElementById returns null, the optional chain swallows it, and the feature is silently off with every test still green. The constants make that unrepresentable.

Why a narrow AnnouncerDocument interface. The lane is node-only with no jsdom (docs/rules/testing.md is explicit that it should stay that way), so the module takes the slice of Document it actually touches. The test drives it with a stub recording textContent and focus calls. 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.

isBackwardNavigation is boolean | null | undefined. tsc caught this: Vike's PageContext types it optional, and null (first render) and undefined both mean "not a back/forward navigation", so both take the focus branch. A third test pins the null case.

sr-only is the established utility here — used by FormBuilder and Spinner, 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

… 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
@sydevs-bot sydevs-bot self-assigned this Sep 2, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying wemeditate-design with  Cloudflare Pages  Cloudflare Pages

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

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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 Ardnived left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Ardnived Ardnived assigned sydevs-bot and unassigned Ardnived Sep 2, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

No — Vike ships nothing for this, and neither does vike-react. I checked the installed packages, not just the docs. Your instinct is right about the ecosystem in general; it's wrong about Vike specifically, and the reason is worth a sentence.

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 onPageTransitionStart/End and expects the app to decide what a navigation means. Those hooks existing at all is Vike's answer to this problem.

grep -rIl "aria-live\|announcer\|aria-atomic" across [email protected], [email protected] and vike-photon returns zero files, and there is no .focus( call anywhere in Vike's client runtime. So nothing is being reimplemented here — there was nothing to configure.

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 write

Evidence. [email protected], [email protected] (versions read from each package.json). grep -rIl "aria-live\|announcer\|aria-atomic" node_modules/vike node_modules/vike-react node_modules/vike-photon → no matches. grep -rIn "\.focus(" node_modules/vike/dist/esm/client → no matches.

Docs, read separately: vike-react enumerates its settings, components and hooks — <Layout>, <Wrapper>, <Head>, <ClientOnly>, +ssr, +title, lang, … — with no accessibility entry. Client Routing covers scroll position (+keepScrollPosition) and says nothing about focus or announcement.

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 (lib/route-announcer.ts, announceRouteChange). Focusing <main> on a Back navigation scrolls to the top and undoes the browser's scroll restoration — the reader loses their place in the page they just returned to. So the announcement fires on every navigation and the focus move doesn't. isBackwardNavigation is null on first render and undefined under Server Routing, and both correctly fall through to the focus branch; lib/route-announcer.test.ts pins all three.

Happy to be wrong if you know of a vike-* community extension I haven't found — I searched and turned up nothing, but that's weaker evidence than the grep above.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot
sydevs-bot merged commit 34f3a17 into main Sep 2, 2026
5 checks passed
@Ardnived
Ardnived deleted the claude/fix-route-announcer branch November 13, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(layout): a client-side navigation announces nothing and moves no focus

3 participants