feat: lazy per-route cache seeding for Workers#653
Open
NathanDrake2406 wants to merge 2 commits intocloudflare:mainfrom
Open
feat: lazy per-route cache seeding for Workers#653NathanDrake2406 wants to merge 2 commits intocloudflare:mainfrom
NathanDrake2406 wants to merge 2 commits intocloudflare:mainfrom
Conversation
commit: |
3e588f6 to
1b23050
Compare
NathanDrake2406
added a commit
to NathanDrake2406/vinext
that referenced
this pull request
Mar 23, 2026
- Only seed routes with router: "app" — Pages Router uses different keys (pages:...) and value shape (kind: "PAGES"), so seeding them as APP_PAGE entries would be unreachable at runtime. - Routes without a router field are skipped defensively (pre-cloudflare#653 manifests lack this field, but also lack buildId so populateKV would already skip). - Remove --app-prefix CLI flag — it writes prefixed keys without wiring the same prefix into the generated runtime, creating silently unreadable cache entries. Keep appPrefix on the programmatic PopulateKVOptions for advanced users who configure both sides manually.
NathanDrake2406
added a commit
to NathanDrake2406/vinext
that referenced
this pull request
Mar 23, 2026
- Only seed routes with router: "app" — Pages Router uses different keys (pages:...) and value shape (kind: "PAGES"), so seeding them as APP_PAGE entries would be unreachable at runtime. - Routes without a router field are skipped defensively (pre-cloudflare#653 manifests lack this field, but also lack buildId so populateKV would already skip). - Remove --app-prefix CLI flag — it writes prefixed keys without wiring the same prefix into the generated runtime, creating silently unreadable cache entries. Keep appPrefix on the programmatic PopulateKVOptions for advanced users who configure both sides manually.
5 tasks
NathanDrake2406
added a commit
to NathanDrake2406/vinext
that referenced
this pull request
Mar 23, 2026
- Only seed routes with router: "app" — Pages Router uses different keys (pages:...) and value shape (kind: "PAGES"), so seeding them as APP_PAGE entries would be unreachable at runtime. - Routes without a router field are skipped defensively (pre-cloudflare#653 manifests lack this field, but also lack buildId so populateKV would already skip). - Remove --app-prefix CLI flag — it writes prefixed keys without wiring the same prefix into the generated runtime, creating silently unreadable cache entries. Keep appPrefix on the programmatic PopulateKVOptions for advanced users who configure both sides manually.
On Cloudflare Workers with MemoryCacheHandler (the default when KV is not configured), pre-rendered routes now seed the memory cache on first request via the assets binding instead of triggering a full re-render. - Add seed-cache-workers.ts with lazy per-route seeding, manifest caching per isolate, and concurrent request dedup - Copy prerender files to dist/client/__prerender/ during deploy so they're available via env.ASSETS.fetch() - Add seeding call to generated App Router worker entry - 9 unit tests covering seeding, dedup, manifest caching, and graceful degradation
The Node.js and Workers seed-cache modules duplicated manifest types, revalidateCtx, and cache value construction. Extract to seed-cache-shared.ts to prevent drift between the two strategies. Also fixes stale JSDoc referencing "manifestPromise" (renamed to "loadedPromise").
1b23050 to
8011d47
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MemoryCacheHandler(the default when KV is not configured), pre-rendered routes now lazily seed the memory cache on first request viaenv.ASSETS.fetch()Pre-requisite
Depends on #645 for the manifest format changes (
buildId,router,trailingSlashfields).How it works
deploy.ts): After prerendering, copiesvinext-prerender.jsonand HTML/RSC files todist/client/__prerender/so they're deployed as static assetsseed-cache-workers.ts): On each request, checks if the route has prerendered data. On first miss, fetches HTML/RSC from the assets binding and populatesMemoryCacheHandler. Subsequent requests in the same isolate get cache HITsseedRouteFromAssets()before delegating to the RSC handlerChanges
src/server/seed-cache-workers.tssrc/deploy.tspackage.json./server/seed-cache-workerstests/seed-cache-workers.test.tsScope
This is Workers memory stub support only, not the final durable caching story. For persistent caching, users should use
KVCacheHandler(opt-in) with TPR for deploy-time KV population. Issue #562 tracks the generalised remote cache seeding.Ref #561
Test plan