Skip to content

fix(serving): browser Back no longer turns /café into /caf%C3%A9 - #367

Merged
allisonmahmood merged 2 commits into
mainfrom
fix/324-unicode-route
Sep 24, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
fix/324-unicode-route

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #366 (branch fix/331-double-config).

Closes #324.

A tier 1 patch that routed to /café saw /café after route.set, then /caf%C3%A9 after pressing Back to the same history entry, so a router matching the path showed "not found" while the URL hadn't changed (#324). The client kept its own raw request after a set. Back reported the browser's percent-encoded address. The initial load already decoded it.

Now the shell decodes the patch-relative path once, the same way hosted parsing does, and reports that form for the initial load and Back/Forward. route.set still acknowledges with null, as wire 1 promises. Right after the acknowledgement the shell sends its ordinary route event with the decoded path, so set("/caf%C3%A9") also settles on /café. The client still takes the requested path on acknowledgement, and it no longer notifies subscribers when a route update leaves the path unchanged, so a plain set reports once. Already-built bundles keep their null result and their cached request path is corrected by the same event; there is no wire-version bump, so no stored version is sent to the needs-rebuild door.

Tests:

  • New tier 1 browser test (set, Back, reload, encoded set) failed on the old code with Received: "/caf%C3%A9" after Back and passes now. The full Chromium tier 1 suite passes 5/5. Firefox wasn't run because its Playwright build isn't installed locally.
  • clientTransport.test.ts has the shell's route event repeat an unchanged path after a set and checks that subscribers aren't notified twice. That assertion fails without the change.
  • pnpm typecheck and pnpm lint are clean. pnpm test: 953/958 under load from parallel runs. The 5 failures were in devLifecycle.test.ts and the two Postgres integration files, none of which this PR touches, and all 17 tests in those files pass when run alone.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area size:s Under 100 changed lines labels Sep 23, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed origin/fix/331-double-config...HEAD, base 2718d91, head dc62de2, against #324. One merge blocker.

Standards

[P1] Method: version the changed route.set reply instead of silently changing wire v1. broker.ts:448–452 changes the result from null to { path }, but both wire constants remain 1. Already-built clients still pass the compatibility gate and expose that object directly from their declared Promise<null>. Existing null checks and truthiness-based control flow therefore change behavior. Resolving null in the newly built client does not protect those deployed bundles.

This contradicts ADR-0011's stable, separately versioned operation contract. Use the existing wire-version/needs-rebuild mechanism if this is an intentional breaking change, or preserve the v1 result contract. Do not ship a different result under the same version.

The new decodeURIComponent call is not a separate blocker on the normal routing path. routePath() already rejects malformed escapes before pushState; hosted addressRouteOf() catches them before serving a shell. A defensive catch here would need a reachable failure case, not just the fact that the decoder can throw.

Spec

No additional intent or YAGNI blockers. #324 explicitly asks for one representation across bootstrap, acknowledgements and history, and for the client to adopt the acknowledged route. The canonical acknowledgement is requested work, not speculative infrastructure; the change adds no router dependency.

Checked with an isolated Chromium probe using the actual broker and client transport, with synthetic HTTP responses: Unicode set/Back reports /café, encoded set reports /next/café and resolves null, and malformed /bad% is rejected with invalid_request while the client's route stays unchanged. Full hosted-server handling was not exercised.

Summary: Standards 1 blocker, the unversioned result-contract change. Spec 0 blockers.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review of the dc62de2 delta on this PR, stacked on fix/331-double-config, against issue #324. Four passes: standards, the issue's intent, the method, and whether the change stays small.

Standards

No Effect service findings. broker.ts and clientTransport.ts stay browser adapters. The diff does not create, move, refactor, or consume an Effect service.

Not breaches. skills/patchy/SKILL.md still matches: client.route.get(), set(path), and subscribe(listener), including on public patches. It never said paths stay percent-encoded. SKILL.md did not change, so skills-lock.json needs no hash refresh. Project skills under packages/sdk/skills do not document the route client. The README is the right place for the decoded read-back. docs/API.md and packages/api are unchanged. route.set is not an /api operation. Its arguments still go through the broker-local routeArguments schema. The wire-contract rule in CLAUDE.md does not apply. ADR-0004 does not apply. Route-bridge terms in packages/serving/CONTEXT.md are unchanged.

Hard. ADR-0010 (docs/adr/ADR-0010-sandboxed-frame-and-broker.md: "An old shell with a supported bundle gets one cache-bypassing refresh", and "A tooling release change alone never retires a deployed bundle"). The wire stays at 1, so this skew does not refresh. The shell acknowledgement changed from null to { path }, and the client dropped the request-path update:

} else if (request.route) {
  // Adopt the shell's canonical route, never the raw request.
  const path = routeOf(value.value);
  if (path !== undefined) updateRoute(path);
  request.resolve(null);
}

An old shell still replies value: null. routeOf fails, so set resolves null while get() and subscribe stay on the previous path. The other way: an old bundle still does request.resolve(value.value), so a new shell makes route.set fulfill { path } instead of null. The same wire version has to tolerate both. When the acknowledgement has no string path, adopt the request path, and keep resolving null to patch code. Leave the wire at 1. A bump 409s every stored tier 1 version through the needs-rebuild door in Pages.ts.

Judgement. CLAUDE.md "Hit every surface". route() calls decodeURIComponent on the pathname with no catch. addressRouteOf catches URIError, and that address 404s before the shell mounts. popstate has no try. Inside route.set, a throw after pushState becomes unknown_outcome, so history would have moved and the client would adopt nothing. Happy-path decoding matches. The failure path does not. Same-document history cannot reach a bad %: routePath rejects a segment that will not decode before pushState.

Judgement smell. Mysterious Name. The pending field route: boolean means "this id is route.set, so adopt a canonical path from the result." The name does not say that.

Spec

The diff implements issue 324. Bootstrap, the set acknowledgement, and Back/forward report one percent-decoded path for the history entries the shell creates.

(a) Missing or partial

None. The spec requires one string for the same history entry across set, Back, and hosted init: "different strings for the same history entry" and "Choose one representation and use it for initial bootstrap, set acknowledgements and browser history events."

  • Bootstrap sends frame.dataset.route (broker.ts), which is hosted addressRouteOf (Pages.ts): decode inside try/catch, split, rejoin. /caf%C3%A9 becomes /café.
  • The set ack and popstate both use route(): decodeURIComponent of the pathname remainder. The same URL yields /café. On a historical address, base already includes /~v/N, so the slice is the suffix hosted parsing keeps.
  • The client stores that ack, not the request (clientTransport.ts). routePath still returns the original string, so set("/caf%C3%A9") is sent encoded and reported as /café.
  • Node 24's URL.pathname setter does not double-encode a valid sequence. Assigning /next/caf%C3%A9 leaves pathname /next/caf%C3%A9, and decodeURIComponent returns /next/café. That matches the new tier 1 test and a reload through addressRouteOf. "Explicitly encoded input instead differed on reload" is closed for a new client.
  • "Query and hash remained unchanged." new URL(location.href) then assigning only pathname keeps search and hash. Node confirms ?x=1 and #h survive. The new test never sets either.
  • "No router dependency is needed." The diff is the broker, the client transport, the README, and tests.

route() can throw URIError on a malformed %, unlike addressRouteOf. route.set cannot push those paths, and a direct load sets versionNumber: null and 404s. That sits outside the café entry.

(b) Scope creep

None. The README states the decoded contract. The wire result changed from null to { path } because the spec says to return the acknowledged route.

(c) Implemented but wrong

None for the café entry. route.set still resolves null. "Return the acknowledged route rather than having the client assume its raw request is canonical" is the shell path versus caching the raw argument. get() and subscribers adopt { path }. The patch-facing Promise<null> stays, as the README still documents.

Method

One shell read of the address is the right way to make set, Back, and reload agree. A matched pair does that. Across the deploy that wire 1 still allows, the new client is wrong.

route() decodes location.pathname for the set ack and for popstate. Bootstrap uses frame.dataset.route, produced by addressRouteOf: one decodeURIComponent, then split and rejoin. Those strings match on a live entry. The server catch returns an empty route and 404s. route() does not catch.

The client ships inside the published bundle. The shell ships with the server. WIRE_VERSION is still 1. The broker refreshes a page only when the bundle's wire differs, which is the gate ADR-0010 describes.

Old client, new shell. The client still stores the raw request and resolves value.value. That value is now { path }, so route.set fulfills with an object. The README says Promise<null>. Popstate sends the decoded path, so the reported case, set("/café") then Back, is fixed for bundles that have not been republished. An encoded set still reads back encoded until that bundle is republished. Leave the wire at 1 for this direction. A bump would put every stored tier 1 version on the needs-rebuild door.

New client, old shell. routeOf(null) is undefined, so the client skips updateRoute and still resolves null after pushState. get() and subscribers stay on the previous path while the address bar has moved. That is a rolling deploy, or a bundle built from this client opened on a server that does not have this broker yet. It is worse than the bug in #324.

Decoding only in route() and keeping the result null, with the client caching its request, fixes set("/café") then Back and reload. set("/caf%C3%A9") still stores the request, while Back and reload report /café. Same entry, two strings. The acknowledgement is what makes that second case one string, and the issue names it.

Ship this method. If the result has no string path, update the route from the request. An old shell then cannot leave the address bar ahead of get().

Node v24.20.0: pathname = "/acme/app/caf%C3%A9" stays single-encoded, the slice decodes to /café, and the query and hash survive the pathname assignment. Playwright was not re-run for this review.

YAGNI

This is the small fix. The shell decodes once and acknowledges that string. The client stores the acknowledgement. routeOf and route: boolean are that shape. A shell-only decode would be smaller, and it would leave set("/caf%C3%A9") reporting a different string from Back.

routePath still returns the raw request and lets the URL parser normalize. The acknowledgement is whatever landed, so set("/caf%C3%A9") and set("/café") meet.

routeOf is the event predicate, reused for the result. Four lines, two call sites. The flag replaces the stored raw path. A boolean is less state than the old optional path.

The broker comment states the invariant: one decode, the same form hosted parsing uses, for bootstrap, the set acknowledgement, and back/forward. The line above updateRoute states the other invariant: the raw request is not the route. Neither comment narrates the next statement.

route() reads the live address. routeOf pulls the string out of a message. route: boolean means "this result is a route acknowledgement." routeSet would be plainer and would still be the same fact.

The browser test is the reproduction: a literal set, Back, a deep link, an encoded set, and the address bar staying percent-encoded. The transport edit shows the client adopt { path: "/notes/néxt" } while the wire request stays "/notes/n%C3%A9xt".

Sharing addressRouteOf with the broker would pull server address parsing into the browser bundle for one decodeURIComponent. That is more machinery than the bug is worth. The comment is the coupling.

The as Promise<null> cast is the right boundary. Patch code still gets null. The shell's { path } stays inside the transport.

The result chain is readable. The route case sits after the bytes branch, which a route set cannot take.

Summary

Standards: 3 findings, 1 hard and 2 judgement. The worst is a new client on an old shell: route.set resolves null and leaves get() on the previous path, because wire 1 still pairs them.

Spec: 0 findings. For the history entries this shell creates, /café, the encoded set, bootstrap, and Back are one decoded path, and no router was added.

Before merge, when the acknowledgement has no string path, adopt the request path and keep resolving null. Leave the wire at 1.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review follow-up, pushed as 764f06a (rebased onto the updated fix/331-double-config).

Fixed:

  • Wire 1 result contract (Astra P1, grok Standards/Method). route.set acknowledges with null again, so deployed bundles keep their Promise<null> behaviour and nothing is bumped. After a successful set, the shell sends the ordinary route event with the decoded path, after the acknowledgement. An old bundle's cached request path is corrected by that event.
  • New client on an old shell (grok Method). The client adopts the request path on acknowledgement again. An old shell that sends no event behaves as it did before this PR, which is not a regression. updateRoute skips unchanged paths, so an ASCII set still notifies once. A unit assertion covers it and fails without the change.
  • Mysterious route: boolean name (grok judgement). Removed along with routeOf. The event-based design doesn't need either.
  • README. It now says the initial link and back/forward report decoded paths, and the route event right after a set settles an encoded request on its decoded form.
  • Browser test. Still covers set, Back and reload reporting /café. The encoded-set step now waits for the rendered route instead of reading get() once, because the correcting event arrives just after the acknowledgement.

Kept as is:

  • decodeURIComponent in the shell's route() with no catch. No reachable failure: routePath rejects malformed escapes before pushState, and hosted addressRouteOf 404s a malformed address before a shell mounts. Both reviewers called this non-blocking.
  • No shared parser with addressRouteOf. Pulling server address parsing into the browser bundle for one decode is more machinery than the bug needs. The comment on route() records the coupling.

Evidence on 764f06a: tier 1 Chromium suite 5/5 (Firefox build not installed locally), clientTransport.test.ts 12/12, and typecheck and lint clean. The full pnpm test hit 5 load timeouts in untouched Postgres and dev-lifecycle files, and all 17 of those tests pass when run alone.

Base automatically changed from fix/331-double-config to main September 24, 2026 15:02
allisonmahmood and others added 2 commits September 24, 2026 17:03
The route bridge reported /café after route.set but /caf%C3%A9 after Back to
the same entry, because the client cached its raw request while popstate read
the percent-encoded location.pathname. Hosted bootstrap already decodes.

The broker now decodes the patch-relative path once for bootstrap, popstate
and set, and route.set acknowledges with the canonical { path }. The client
adopts that path instead of its raw request; route.set still resolves null.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ute by event

Wire 1 promised deployed bundles a null route.set result, so the shell keeps
it and sends its ordinary route event with the decoded path right after the
acknowledgement. Old bundles' cached request path is corrected by that event;
new clients still adopt the request on acknowledgement (so an older shell
behaves as before) and skip notifying for an unchanged path, so a set reports
once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 1b0cb7f into main Sep 24, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the fix/324-unicode-route branch September 24, 2026 15:11
allisonmahmood added a commit that referenced this pull request Sep 24, 2026
…ead client (#368)

Leaving a public patch and coming back with browser Back could restore a page that looked ready but whose client had already closed. Every route change then failed with `unknown_outcome` until you reloaded by hand. Fixes #341.

Stacked on #367 (branch fix/324-unicode-route).

The broker and client close on `pagehide`, and a back/forward-cache restore resumes that closed document without running setup again. The shell now reloads when it gets a `pageshow` with `persisted` set. That gives a fresh document and broker, and pending work is never replayed or sent over the old port. Reloading beats marking the public shell `no-store`: we keep its one-minute public cache, and `no-store` no longer reliably keeps a page out of the back/forward cache in Chromium or Safari. ADR-0010 now says this in one sentence.

**Test evidence**

- A new tier-1 Playwright case, "Back to a cached public patch leaves a working client", uses the browser's real back/forward cache. It runs full Chromium without Playwright's `--disable-back-forward-cache` flag, because the headless build refuses to cache. It checks that `pageshow.persisted` was true, then clicks the in-patch "Next route" button until the URL changes.
  - On the unfixed broker the restore is confirmed, but the clicks never move the URL off `/items/2`.
  - With the fix the test passes.
- The Chromium tier-1 suite passes (6 of 6). Firefox couldn't run locally because its Playwright build isn't installed.
- `pnpm typecheck` and `pnpm lint` pass.
- `pnpm test`: 955 of 957 passed. The 2 failures were 5-second timeouts in the integrations Postgres suites, which this change doesn't touch; both files pass when run alone.

Implemented by Claude Opus 5.5 via Claude Code (foreman run orchestrated by Claude Fable 5.1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:server Touches the server area size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serving: browser Back changes the representation of Unicode routes

1 participant