fix(tanstack): isolate pending page resolution between requests - #541
Open
viktormarinho wants to merge 1 commit into
Open
viktormarinho wants to merge 1 commit into
viktormarinho wants to merge 1 commit into
Conversation
JonasJesus42
approved these changes
Sep 9, 2026
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.
A stalled
loadCmsPagecurrently holds a module-global promise keyed by URL. Later visitors to the same URL join that promise, even when their own page resolution could succeed. The shared result also contains request-derived device, flags and URL values.Scope pending page resolution to the incoming
Requestwith aWeakMap. Concurrent callers within one request still deduplicate; separate visitors resolve independently. Completed and rejected work is removed, and query strings, navigation mode and globals options remain distinct.Validation:
requestSingleFlight.test.tsandcmsRoute.test.ts. Coverage includes a stuck first visitor with a healthy second visitor, within-request deduplication, rejection cleanup and distinct page options.?p=1returned 200, but a second request to the original URL timed out at 1,503 ms. After: that second request returned the expected Sabonete Barra page with HTTP 200 in 37 ms. Production fixtures remain outside this repository.This is a demonstrated fault-amplification mechanism, not confirmation that
pageInflightcaused Granado's production 524s. Healthy local heap snapshots showed no retained entries in this map after requests completed. The map predates the KV migration; KV introduced another asynchronous dependency that can expose the problem.Complementary website change: https://github.com/deco-sites/granadobr-tanstack/pull/492 bounds KV operations and is the immediate mitigation for an unsettled cache operation. This PR does not add another cache deadline. A visitor whose own dependency stalls still needs that deadline.
Tradeoff: simultaneous cache misses from separate visitors can perform more work because whole-page resolution is no longer shared across requests. Shared value caches remain in place; any future coalescing must operate on request-independent data.
Summary by cubic
Scopes pending page resolution to the incoming request so a stalled
loadCmsPagefor one visitor no longer blocks later visitors to the same URL. Previously, a module-global promise keyed by URL shared the result across requests, including request-specific device, flags, and URL values.Concurrent callers within the same request still deduplicate, but separate visitors resolve independently. Completed and rejected work is removed, and query strings, navigation mode, and globals options remain distinct. Simultaneous cache misses from separate visitors may perform more work because whole-page resolution is no longer shared across requests. This PR does not add a cache deadline; a complementary website change bounds KV operations.
Validation: 15 tests pass, TypeScript check and production build pass, and a manual worker test confirmed the fix.
Written for commit 07cd2f5. Summary will update on new commits.