Consolidate Resume Data Caches and partially revert #88556 (#94194)
This consolidates the two Resume Data Caches into a single discriminated union and reverts three non-load-bearing changes from #88556. The result sets up a follow-up that fixes a bug where pages exporting `unstable_instant = false` cause their `'use cache'` reads to be incorrectly treated as dynamic. The cache wrapper short-circuits a `'use cache'` miss to a dynamic hole when prerendering a fallback shell that was seeded with a read-only RDC from an earlier phase. The reasoning is that the seed was filled by a phase-1 prerender of a more-specific sibling route, so a miss in phase-2 means the cache key depends on a fallback param. In PR #79743, we set up an XOR on the work unit store that directly encoded this distinction: a prerender carried either a mutable `PrerenderResumeDataCache` (a phase-1 prerender filling caches as it runs) or an immutable `RenderResumeDataCache` (a phase-2 fallback shell reading from a phase-1-seeded cache), never both. The bail-out didn't use that signal directly, though; it was gated on `workUnitStore.allowEmptyStaticShell`, which at the time happened to coincide with "we have a read-only seed" because the fallback-shell flow was the only thing setting it. #89077 later widened that flag to also cover `unstable_instant = false`, which has no seed, so the bail-out started firing for routes that should be allowed to fill their caches normally. #88556 broke the XOR by carrying both caches at the same time. In a follow-up, the flag check is replaced with a precise `workUnitStore.resumeDataCache?.mutable === false`, which only lands cleanly once the XOR is back. The three reverts: (1) at the start of the Cache Components branch of `prerenderToStream`, phase-2 no longer creates a fresh mutable RDC alongside the prefilled one — it just uses the seed; (2) the swap between the prospective and final prerender passes that replaced the prefilled RDC with a freeze of the (now-gone) mutable one is removed, so the final pass reads from the same seed as the prospective pass; (3) the line in the cache wrapper that mirrored prefilled-RDC hits into the mutable RDC (only useful to feed the swap) is removed. The actual fix from #88556 — selecting the seed RDC by matching known params, `buildRDCCacheByPage` in `export/index.ts` — is kept, and the `ppr-root-param-fallback` test suite that was added in that PR still passes. On top of the revert, the two RDC types now carry a `mutable: true | false` discriminator, the store fields collapse into one `resumeDataCache: ResumeDataCache | null`, and the specialized `getPrerenderResumeDataCache` / `getRenderResumeDataCache` helpers are replaced by a single `getResumeDataCache` returning the union. Call sites narrow via `resumeDataCache?.mutable` directly, and the typing-lie in the old `getRenderResumeDataCache` (coercing a mutable cache to read-only via spread) is gone. Restoring the XOR as two separate fields would have worked, but the discriminated union makes the invariant compiler-enforced and removes a typing-lie that the original design already carried — and the revert touches the same call sites anyway, so bundling the refactor in one pass was cleaner than splitting it.
Showing
This diff is collapsed.
Please
register
or
sign in
to comment