Repository navigation
Conversation
|
This pull request was not reviewed automatically because its author does not have write access to this repository. A maintainer with write access can start a review by commenting |
@vinext/cloudflare
create-vinext-app
@vinext/types
vinext
@cloudflare/workers-response-store
commit: |
Performance benchmarksCompared 0 improved · 0 regressed · 7 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
|
Thanks for digging into this. There are three changes in here, so here's where each one stands: 1. Paths the manifest never stores ( 2. Mounted layouts on full prefetches: we're not planning to do this. It's the same case declined on #4814. Next.js does diff the prefetch tree against the current page. However, it stores the result per segment, so any page can reuse it later. vinext's prefetch cache holds one whole payload per URL. Sending the header would tie that entry to whichever page the user was on when the prefetch ran, and a click from anywhere else has to refetch. That's the slow path prefetching is meant to avoid. Doing this properly needs a per-segment prefetch cache first. 3. Remembering which paths turned out dynamic: this might be worth doing, but please open an issue for it rather than a PR. In the issue, describe the problem: on deployments without a manifest, a static-eligible route that uses a dynamic API renders its shared layouts again on every navigation. Include a repro and the approach you have in mind. Two things we'd want the issue to cover:
In general, for changes like 2 and 3, which change how responses are cached or reused, please start with an issue that describes the problem and the approach you have in mind. That way we can agree on the design before anyone writes code, and you don't end up building something we decline. It's also much easier for us to review one change per PR than several bundled together. I'll close this one in favour of #5047. Thanks again, this was a good find. |
Summary
Follows up on #4276 (
X-Vinext-Mounted-Layouts) to close two production gaps where shared layouts still re-rendered unnecessarily on App Router soft navigations and full prefetches:1. Respect
X-Vinext-Mounted-Layoutsfor manifest-excluded and runtime-dynamic static-pattern routes in productionisNeverStoredPath): Inpackages/vinext/src/server/app-page-dispatch.ts,isCacheCandidateandisStoredRenderalready excluded paths with no Workers Cache manifest admission state, butisUncacheableRenderomittedisNeverStoredPath. Including it lets manifest-excluded dynamic paths skip already-mounted layouts on the first navigation.vinext start/ Workers runtime admission): Static-pattern routes withoutexport const dynamic = "force-dynamic"whose shared layout or page calls dynamic APIs (cookies(),headers(),fetch(..., { cache: "no-store" })) previously fell into a worst-of-both-worlds loop in production: treated as cache candidates before render (droppingX-Vinext-Mounted-Layouts), then skipped from ISR caching after observing dynamic usage, causing shared layouts to re-run on every soft navigation.WeakMap<AppPageDispatchRoute, Set<string>>(cleared if a later full render stores into cache; never poisoned by query-param renders).X-Vinext-Mounted-Layoutsskip already-mounted layouts, bypass shared caching (isPartialPayload→private, no-cache, no-store), and preserveX-Vinext-Dynamic-Stale-Timeeven when the dynamic API lived only inside a skipped parent layout.HITs.2. Send
X-Vinext-Mounted-Layoutson navigation-reusable prefetches (<Link prefetch={true}>/router.prefetch(..., { kind: "full" }))FetchStrategy.Full, which diffs the target tree against the current router tree (diffRouteTreeAgainstCurrentinsegment-cache/scheduler.ts) and sendsNext-Router-State-TreesowalkTreeWithFlightRouterStateskips shared mounted layouts during full prefetches.getMountedLayoutsHeader()andholdsSkippedLayouts()throughNavigationRuntimeFunctions(including initial hydration state before the first router commit, released once committed) and attachesX-Vinext-Mounted-Layoutsto navigation-reusable prefetches inlink.tsxandapp-router-navigation.ts(never on loading-shell, dynamic-shell, route-tree, or intercepted prefetches).isPrefetchCacheEntryCompatibleWithMountedLayouts), and falls back cleanly to a whole RSC refetch inapp-browser-entry.tsif a consumed partial prefetch's skipped layouts are no longer held by the current router state.Verification
vp run vinext#build— passedvp checkon all modified/added files — passed (0 warnings/errors)vp test runacross 11 unit test suites (app-page-dispatch,app-page-render,app-page-route-wiring,app-rsc-handler,app-rsc-cache-busting,link,link-navigation,prefetch-cache,app-browser-entry,cloudflare-cdn-worker,cloudflare-response-store-worker) — 2,115 passedPLAYWRIGHT_PROJECT=app-router-isr-prod pnpm exec playwright test tests/e2e/app-router-prod/partial-layout-prefetch.spec.ts tests/e2e/app-router-prod/soft-nav-rsc-cache.spec.ts— 3 passed (both new production E2E tests and static soft-nav RSC cache regression test)