refactor(app-rsc-entry): centralize request-derived page inputs [1/6]#838
Conversation
Reshape buildPageElements to accept a single pageRequest object bundling opts, searchParams, isRscRequest, request, and mountedSlotsHeader. Lift the mounted-slots header read to the handler scope so every call site shares one source of truth and a future refactor cannot silently drift one read path out of the other.
commit: |
There was a problem hiding this comment.
Pull request overview
Refactors the App RSC entry template to centralize request-derived page inputs by threading a single pageRequest object into buildPageElements, and ensuring the x-vinext-mounted-slots header is normalized exactly once at handler scope.
Changes:
- Updated
buildPageElementssignature to accept a singlepageRequestbag and destructure needed values from it. - Moved
x-vinext-mounted-slotsheader normalization to_handleRequestand passed the normalized value throughpageRequestto all call sites. - Regenerated template snapshot output to reflect the new function signature and header threading.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/vinext/src/entries/app-rsc-entry.ts | Centralizes mounted-slots header normalization at handler scope and threads request-derived inputs via a pageRequest object. |
| tests/snapshots/entry-templates.test.ts.snap | Updates snapshot to match the refactored generated entry template output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/bigbonk review |
There was a problem hiding this comment.
Clean refactor — the motivation (collapsing two independent header reads into one shared value at handler scope) is sound and the execution is mechanical. All CI checks pass.
A few observations:
-
Optional chaining removal is safe. The old
buildPageElementscode usedrequest?.headers?.get("x-vinext-mounted-slots")defensively, sincerequestwas the last positional arg and could theoretically be omitted. The new code reads the header at handler scope withrequest.headers.get(...)(no optional chaining), which is correct —requestis the first parameter of_handleRequestand is always aRequestobject. -
routeandparamsstay positional. Good call keeping them outside the bag — they are route-matched values, not request-derived inputs. ThepageRequestbag cleanly scopes the request-derived fields (opts, searchParams, isRscRequest, request, mountedSlotsHeader). This makes the signature easier to extend in the follow-up PRs without growing the positional arg list. -
Snapshot diff is consistent. All 7 snapshot variants show the same mechanical transformation, matching the source change.
One minor nit below (non-blocking).
| isRscRequest, | ||
| request, | ||
| mountedSlotsHeader, | ||
| } = pageRequest; |
There was a problem hiding this comment.
Nit (non-blocking): If the stack plans to keep extending pageRequest (PRs 2–6 mention adding more fields), it might be worth adding a brief JSDoc type comment near the destructuring or at the function signature — even just /** @typedef {{ opts, searchParams, isRscRequest, request, mountedSlotsHeader }} PageRequest */ — so future readers know the shape at a glance without scanning all call sites. Generated code doesn't benefit from TypeScript, so a JSDoc hint would be the only inline documentation.
Fine to defer to a later PR in the stack if the shape isn't stable yet.
|
Review submitted with approval. Here's the summary: Approved PR #838 — a clean, mechanical refactor that:
Left one non-blocking nit suggesting a JSDoc type comment for the |
Summary
PR 1 of 6 — restack of #768. Pure refactor, no behavior change. Reshapes
buildPageElementsto take a singlepageRequestobject and lifts thex-vinext-mounted-slotsheader read to handler scope so every call site shares one source of truth.Previously, both the handler and
buildPageElementsread and normalizedx-vinext-mounted-slotsindependently. A future refactor changing only one of those paths would silently drift. This PR collapses the two reads into one at the handler scope and passes the normalized value through thepageRequestbag.Stack (in order)
Sibling: #837 (chore: shim error boundary import).
Test plan
vp test run tests/entry-templates.test.ts tests/app-router.test.ts(327 tests)