You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tanstack: app middlewares run before bindCacheStorage — cacheBackground is a no-op there, and joinInflight resumes joiners in the owner's context #726
On Cloudflare Workers with no_handle_cross_request_promise_resolution, a storefront (oficina-tanstack, deco-sites/oficina-tanstack#507) had requests hang forever after a client cancelled an earlier request. Every route was affected: /deco/invoke, PLP, PDP, and the /api/checkout proxy. The trigger was site middleware awaiting isolate-wide shared work. Two framework behaviours made it possible, and they will affect any site that shares work from middleware.
1. cacheBackground is a no-op inside app middleware
createDecoWorkerEntry (packages/tanstack/src/sdk/workerEntry.ts) runs getAppMiddleware()beforehandleRequest. Only handleRequest calls bindCacheStorage({ waitUntil }).
cacheBackground (packages/blocks/src/sdk/cacheStorage.ts) reads waitUntil from that binding. So work a middleware starts and shares with later requests is never kept alive. When the starting client disconnects, the runtime cancels its I/O, the shared Promise never settles, and every joiner hangs.
Proposal: bind the cache-storage context (or at least waitUntil) before running app middlewares. Alternatively, expose the ExecutionContext to middlewares, e.g. RequestContext.waitUntil.
2. joinInflight resumes the joiner in the owner's I/O context
joinInflight (packages/blocks/src/sdk/inflightTimeout.ts) resolves the joiner through shared.then(resolve). Under no_handle_cross_request_promise_resolution, the joiner's continuation then runs inside the owner's request. That includes everything the joiner does next: fetches, and timers created later. If the owner request ends or is cancelled, the joiner's later work dies with it.
The site works around this with a "settle in own context" helper. A reaction only records the outcome, and a timer chain created in the caller's context polls for it. A framework-level equivalent in joinInflight would remove that class of hang.
Measured impact on the site (in-place versions, same time window): hang rate went from 67–78% of rounds to 0/12, with the fix applied on the site side.
Activity