mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #1067] [MERGED] perf(app-router): coalesce client reference preloads #1064
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#1064
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/1067
Author: @NathanDrake2406
Created: 5/5/2026
Status: ✅ Merged
Merged: 5/5/2026
Merged by: @james-elicx
Base:
main← Head:nathan/client-ref-preload-singleflight📝 Commits (1)
3ec59f4perf(app-router): coalesce client reference preloads📊 Changes
4 files changed (+236 additions, -32 deletions)
View changed files
📝
packages/vinext/src/global.d.ts(+9 -0)➕
packages/vinext/src/server/app-client-reference-preloader.ts(+100 -0)📝
packages/vinext/src/server/app-ssr-entry.ts(+15 -32)➕
tests/app-client-reference-preloader.test.ts(+112 -0)📄 Description
What this changes
App Router SSR now shares a single in-flight client-reference preload during cold starts instead of letting concurrent first requests each iterate the full
virtual:vite-rsc/client-referencesmanifest and allocate their ownPromise.allfan-out.The preload logic moved out of
app-ssr-entry.tsinto a typed helper that:preload(referenceIds)shape for a future route-level manifest without losing cross-route per-id dedupeWhy
The existing preload is required for correctness: first-request SSR can fail if React consumes the Flight stream before Vite RSC client references have resolved. But the state only tracked completion. During a cold burst, every request entering before the boolean flipped repeated manifest key iteration and promise fan-out even though Vite RSC memoized the underlying imports.
This keeps the correctness barrier and removes the duplicate orchestration work.
Approach
handleSsrstill awaits client-reference preload before creating the SSR tree. The difference is that it now delegates tocreateClientReferencePreloader, which owns the concurrency contract directly and is covered by focused unit tests.I did not synthesize a route-to-client-reference manifest in this PR.
@vitejs/plugin-rsccurrently owns the reliable client-reference graph behind private build metadata, while the public virtual module is app-global. Guessing that graph from transformed module IDs would be fragile for package client references and production hash keys.The new helper is intentionally shaped so a future generated route manifest can pass scoped ids once Vinext has trustworthy build metadata. That likely lines up with the RouteManifest/resource-dependency pieces of #726, not the entire #726 roadmap: once Vinext has authoritative route-to-module facts, SSR can call
preload(routeClientReferenceIds)for the matched route while retaining the same per-id dedupe and correctness barrier introduced here.Validation
vp check packages/vinext/src/server/app-client-reference-preloader.ts packages/vinext/src/server/app-ssr-entry.ts packages/vinext/src/global.d.ts tests/app-client-reference-preloader.test.tsvp test run tests/app-client-reference-preloader.test.tsvp test run tests/app-client-reference-preloader.test.ts tests/app-router.test.tsvp run vinext#buildRisks / follow-ups
The preloader intentionally treats individual client-reference preload failures as reported-but-complete, matching the previous best-effort behavior in
app-ssr-entry.ts. A future route-scoped manifest should be generated from authoritative RouteManifest/resource-dependency metadata from #726, not from source filename heuristics or Flight stream parsing.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.