You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4b4634c
Browse filesBrowse the repository at this point in the historyBrowse files
refactor(router): request stages shared by the handler and dispatch
Lift the stages around rendering out of the createRSCHandler closure
into rsc/request-stages.ts, which imports no @vitejs/plugin-rsc:
classify, guardRequest, partialRedirectResponse, runRequestPasses (the
rewrite passes and the global middleware chain), serveResponseRoute and
timeoutResponse, finalizeRequestResponse (redirect interception,
onResponse drain, rewrite header, open-redirect guard, stream idle),
createErrorReporter and reportBackgroundErrors.
createRSCHandler runs them around its Flight executor; HandlerContext
extends the stage context. dispatch drops its hand-kept copy of the same
orchestration and runs the passes, the response route, the partial
redirect and the finalization, keeping its previewMatch matching, its
throw on an RSC route, its telemetry lifecycle and its documented
boundaries. It loads the stages lazily, so the testing barrel's eager
graph is unchanged; a module-graph test pins both graphs plugin-rsc-free.
site error: a rewrite after `next()`, a disallowed mutation's rewrite in
726
728
global middleware (before the action), a mutation whose body middleware
727
729
read before the action, an action whose rewrite reaches a response route
728
-
or a redirect (`coreRequestHandler`: after it ran, or a JS action before);
730
+
or a redirect (`guardRequest` in `rsc/request-stages.ts`: after it ran, or
731
+
a JS action before);
729
732
a loader fetch
730
733
answers with the `loaderError``load()` rejects with; a handler's, loader's or server action's throw is its own error
731
734
(middleware only, by design: no loader rewrites).
@@ -1073,7 +1076,7 @@ The visitor's theme reads (the handler and middleware `ctx.theme`, `getRequestCo
1073
1076
- Default 504 response with `X-Rango-Timeout-Phase` header
1074
1077
-`onError` receives timeout errors with `metadata: { timeout: true, phase, durationMs, render? }`; `render` is the foreground Flight/HTML/response cursor when a render-start timeout interrupts the stage driver
1075
1078
-`onTimeout`, `request.timeout`, and `onError` each receive their OWN shallow copy of the `render` snapshot (`RenderTimeoutContext`: mode, phase, running/paused state, completed/total, partial phase duration) — value-equal, independent by reference, so a consumer mutating one surface's copy cannot corrupt the others
1076
-
-`dispatch()`mirrors response-route `renderStartMs`/`onTimeout`/timeout telemetry through the public testing entry; its timeout context deliberately has no `render` snapshot because dispatch does not run Flight/HTML
1079
+
-`dispatch()`runs the handler's response-route stage (`serveResponseRoute` and `timeoutResponse` in `rsc/request-stages.ts`), so `renderStartMs`/`onTimeout`/timeout telemetry match production through the public testing entry; its timeout context has no `render` snapshot because dispatch does not run Flight/HTML
1077
1080
- Timeout phases: `"action"` (server action execution), `"render-start"` (RSC render / response routes), `"stream-idle"` (post-handoff body idle-flow watchdog; onTimeout does not apply — the trip errors the stream and reports via onError with `metadata: { timeout: true, phase: "stream-idle", durationMs }` + the request.timeout event)
- 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.
97
97
- 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.
98
98
- 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 any 3xx redirect on a partial OR action request becomes a `204` + `X-RSC-Redirect` (fetch-safe interception), the raw `Location` dropped. 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, 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.
100
100
-`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.
0 commit comments