Skip to content

Commit 3901965

Browse files
committed
docs(router): dispatch() edge cases that now answer as production
dispatch() now runs the handler's request stages, and in a few edge cases its answer moved to production's. List them in an Unreleased CHANGELOG entry, and make the testing skill's redirect line precise: when a global middleware matches the path, any 3xx leaving the chain on a partial or action request becomes a 204 + X-RSC-Redirect; without one, an action request's 3xx goes out raw, as production sends it.
1 parent f85a26f commit 3901965

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎packages/rangojs-router/CHANGELOG.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,47 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Changed: `dispatch()` answers as production in a few edge cases
6+
7+
**Before.** `dispatch()` from `@rangojs/router/testing` kept its own copy of
8+
the handler's steps around a response route: the global middleware passes,
9+
the response route's timeout, the redirect interception and the response's
10+
finalization. In a few cases its answer differed from the one `router.fetch`
11+
sends.
12+
13+
**After.** It runs the production handler's request stages, so these cases
14+
answer as production does:
15+
16+
- An action request (`?_rsc_action`, not a partial) whose final pass ran no
17+
global middleware, answered with a 3xx (a trailing-slash redirect, or a
18+
redirect from a response route or its route middleware): the 3xx, through
19+
the open-redirect guard, instead of a `204` + `X-RSC-Redirect`.
20+
- A partial request (`?_rsc_partial`) to a trailing-slash path: a global
21+
middleware that reads the response after `next()` sees the `204` +
22+
`X-RSC-Redirect` instead of a `308`. The response is unchanged.
23+
- A response route's `renderStartMs` timeout with no global middleware:
24+
`onResponse` callbacks the route registered before the deadline no longer
25+
apply to the 504 or `onTimeout` response.
26+
- A content-negotiated response route whose route middleware short-circuits:
27+
the response carries `Vary: Accept`.
28+
- A response route for a type with no MIME (image, stream, any) whose handler
29+
returns a value that is not a `Response`: the 500 carries production's
30+
message, `Response route handler for "…" must return a Response object`.
31+
- A throwing `onTimeout` logs `[RSC] onTimeout callback error:` instead of
32+
`[dispatch] onTimeout callback error:`.
33+
- A response-route timeout on a rewritten pass: `onError`, `onTimeout` and
34+
the `request.timeout` event carry the rewrite target's request and URL.
35+
Without a request-id header, that event's `requestId` then differs from the
36+
one on `dispatch`'s own `request.start` and `request.end`.
37+
- A stream-idle timeout's `onError` call and `request.timeout` event carry
38+
`routeKey`.
39+
- The same timeout, stream-idle or rewrite error reaches `onError` once per
40+
request.
41+
42+
No change in your code. A test that pinned one of the old answers now gets
43+
production's.
44+
345
## 0.27.0 (2026-10-23)
446

547
### Breaking: Back or Forward onto a page a server action made stale re-runs its loaders and route, as the action's own revalidation does, and every stale request renders live ([#1231](https://github.com/rangojs/rango/pull/1231))

‎packages/rangojs-router/skills/testing/response-routes.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe("api routes via dispatch", () => {
9696
- A router using `Prerender()`/`createLoader()`/`Static()` now constructs in a bare test (each assigns a runtime fallback `$$id`). Importing the whole router _file_ may still need the plugin (its page modules pull app deps / `virtual:` modules) — build from a focused include (your API routes) for whole-router dispatch.
9797
- A `throw rewrite(target)` from global or route middleware re-dispatches as the router does: global middleware matched on the target's path, the target's route middleware and handler, the same request context, `x-rango-rewrite` on the response, 508 on a loop. The visitor's URL is matched before middleware runs, so it must be a response route (or a redirect or 404) too; a rewrite target that is a component route throws the same error as a direct request.
9898
- A `_rsc_partial` request to a response route runs global middleware first (an auth gate can still 401/redirect), then returns `X-RSC-Reload` — route-level middleware is skipped, exactly like production.
99-
- `dispatch` does NOT execute server actions (`?_rsc_action`), but it DOES run the global middleware chain on an action request — middleware can still 401/redirect it, and a global middleware's 3xx redirect on a partial OR action request becomes a `204` + `X-RSC-Redirect` (fetch-safe interception), the raw `Location` dropped, as does a trailing-slash redirect on a partial request. Location state carried on such a redirect is dropped too (production embeds it in a Flight payload); cover that at e2e.
99+
- `dispatch` does NOT execute server actions (`?_rsc_action`), but it DOES run the global middleware chain on an action request — middleware can still 401/redirect it. When a global middleware matches the path, any 3xx that leaves the chain on a partial OR action request (a global or route middleware's redirect, a response route's, a trailing-slash redirect) becomes a `204` + `X-RSC-Redirect` (fetch-safe interception), the raw `Location` dropped. Without one, an action request's 3xx goes out raw (through the open-redirect guard), as production sends it; a trailing-slash redirect on a partial request is a `204` either way. Location state carried on such a redirect is dropped too (production embeds it in a Flight payload); cover that at e2e.
100100
- `createRouter({ onError })` is NOT invoked for a thrown non-Response HANDLER error here (the typed error Response still matches production), and `cache.decision` / `loader.*` telemetry never fires (no RSC render runs). Cover both at e2e.
101101

102102
## See also

0 commit comments

Comments
 (0)