mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 00:09:23 +02:00
[PR #391] [MERGED] fix: register background KV ops and ISR regen with ctx.waitUntil on Workers #535
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#535
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/391
Author: @james-elicx
Created: 3/9/2026
Status: ✅ Merged
Merged: 3/9/2026
Merged by: @james-elicx
Base:
main← Head:fix/workers-waituntil-background-ops📝 Commits (2)
d5f67cdfix: register background KV ops and ISR regen with ctx.waitUntil on Workers5700a50regen snaps📊 Changes
7 files changed (+230 additions, -17 deletions)
View changed files
📝
packages/vinext/src/cloudflare/kv-cache-handler.ts(+53 -8)📝
packages/vinext/src/deploy.ts(+2 -2)📝
packages/vinext/src/entries/pages-server-entry.ts(+6 -3)📝
packages/vinext/src/server/isr-cache.ts(+23 -1)📝
tests/__snapshots__/entry-templates.test.ts.snap(+6 -3)📝
tests/isr-cache.test.ts(+27 -0)📝
tests/kv-cache-handler.test.ts(+113 -0)📄 Description
Problem
On Cloudflare Workers, any async work started after a `Response` is returned is killed immediately. Three places in vinext were silently losing work as a result:
ISR background regeneration dropped — `triggerBackgroundRegeneration` starts a revalidation promise but never calls `ctx.waitUntil()`, so every stale-while-revalidate revalidation on Workers is silently discarded. Pages appear perpetually stale.
Corrupt-entry deletes blocking the response — `KVCacheHandler.get()` used `await this.kv.delete(kvKey)` for cleanup of corrupt/invalid/tag-invalidated entries. This is pure background cleanup that was unnecessarily holding up the response.
Cache writes on the critical path — `KVCacheHandler.set()` awaited the KV write before returning. The client already has the rendered content at that point; the write can safely happen after the response is sent.
Solution
All changes are backward-compatible — `ctx` is optional everywhere; Node.js dev/prod behaviour is unchanged.
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.