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
fix(router-core): merge synchronous beforeLoad context before offering pending match - #9019
In contextualize (packages/router-core/src/load-client.ts), options[7 /* onReady */]?.() previously ran before invoking beforeLoad, allowing a route whose pendingMs had already elapsed to offer its pendingComponent on the microtask before synchronous beforeLoad output merged into match.context.
Defer offer?.() until after match.context merges when beforeLoad returns synchronously (!isAsync), while calling offer?.() immediately after starting async beforeLoad (isAsync), and on non-SUCCESS / catch exits (unless aborted).
Note: @tanstack/solid-router test:unit passed 21 non-.tsx files (169 type tests, Type Errors: no errors) on Windows Node 24, while .tsx files hit pre-existing Windows Vitest transform TypeError on file:///@solid-refresh.
AI assistance disclosure: authored and verified with AI coding assistance; I have reviewed and tested the diff.
I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
I fully understand the code in this pull request, including any code generated with AI assistance.
🚀 Release Impact
This change affects published code, and I have generated a changeset.
This change is docs/CI/dev-only (no release).
Summary by CodeRabbit
Bug Fixes
Fixed an issue where a route’s pending screen could miss context provided by synchronous setup steps when navigation took long enough to show it.
Pending screens continue to render while asynchronous setup is unresolved; that route’s context becomes available once setup completes, alongside the ready screen and loader data.
Reviewing files that changed from the base of the PR and between c70491b and 1c938b1.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The change updates pending readiness timing around route beforeLoad execution. It adds regression tests for synchronous and asynchronous beforeLoad behavior and a patch changeset for @tanstack/router-core.
contextualize offers pending readiness before awaiting asynchronous beforeLoad work, or after synchronous work completes or fails. It marks a match pending only when a readiness callback is available.
TanStack/router#9016: Changes the useRouteContext contract inside a route’s own pendingComponent, which intersects with the context asserted by this PR’s regression tests.
Suggested reviewers:sheraff
Merge Risk: Minimal · previous review c7049
This change makes a route's pending component see the context from its synchronous beforeLoad, even when the pending delay has already elapsed. Asynchronous beforeLoad behavior is unchanged. Regression tests and a patch changeset are included, and no merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: synchronous beforeLoad context is merged before the pending match is offered, in router-core. This matches the load-client.ts change, where offer is deferred until aft…
Description check
The description follows the template. It has the Changes section with motivation and a code snippet, and the checklist items are filled in. It discloses AI assistance, as the template asks. It lists t…
Linked Issues check
[#9009] The reported defect is that a route's pendingComponent misses its own synchronous beforeLoad result when pendingMs has already elapsed. The diff in packages/router-core/src/load-client.ts (con…
Out of Scope Changes check
The changes touch three areas: the contextualize logic in packages/router-core/src/load-client.ts, a patch changeset for @tanstack/router-core, and regression tests for #9009. All are directly tied to…
Full details: Title check
Explanation
The title names the main change: synchronous beforeLoad context is merged before the pending match is offered, in router-core. This matches the load-client.ts change, where offer is deferred until after the merge for synchronous beforeLoad. The title is specific and scoped, and it uses the conventional fix(scope) form.
Full details: Description check
Explanation
The description follows the template. It has the Changes section with motivation and a code snippet, and the checklist items are filled in. It discloses AI assistance, as the template asks. It lists test and verification results and a changeset. The Release Impact section is marked correctly. The description does not state the reason for the async-path behavior in detail, but the core intent is clear. It also links issue #9009 and notes that the contract and typing work from the linked issue is out of scope.
Full details: Linked Issues check
Explanation
[#9009] The reported defect is that a route's pendingComponent misses its own synchronous beforeLoad result when pendingMs has already elapsed. The diff in packages/router-core/src/load-client.ts (contextualize) moves offer?.() for synchronous beforeLoad (!isAsync) to run after the match.context merge on SUCCESS, and on non-SUCCESS and catch exits (unless aborted). The pending match is therefore offered only after the synchronous result is merged. This makes the three rows of the issue table consistent, which meets the issue's first expected behavior (the pending component always sees a synchronous beforeLoad result). For asynchronous beforeLoad, offer?.() runs right after the call starts, so the pending component still lacks the route's own context while the promise is unresolved. The issue treats that as a separate contract and typing concern (item 2 in the issue, also excluded by the PR objectives), not as part of the timing requirement. Regression tests are added in packages/react-router/tests/issue-9009-pending-sync-beforeload-context.test.tsx. I did not read the test file contents; the test claims rely on the PR description and summary. The contract and typing request (dedicated hook or typed props for pending and error components) is not implemented, and this assessment does not require it.
Full details: Out of Scope Changes check
Explanation
The changes touch three areas: the contextualize logic in packages/router-core/src/load-client.ts, a patch changeset for @tanstack/router-core, and regression tests for #9009. All are directly tied to the timing fix for #9009. The load-client.ts diff contains only changes to the offer timing and the isAsync flag, with no unrelated edits. The changeset and tests support that fix and do not add unrelated behavior.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
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
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.
Fixes #9009
🎯 Changes
In
contextualize(packages/router-core/src/load-client.ts),options[7 /* onReady */]?.()previously ran before invokingbeforeLoad, allowing a route whosependingMshad already elapsed to offer itspendingComponenton the microtask before synchronousbeforeLoadoutput merged intomatch.context.offer?.()until aftermatch.contextmerges whenbeforeLoadreturns synchronously (!isAsync), while callingoffer?.()immediately after starting asyncbeforeLoad(isAsync), and on non-SUCCESS/catchexits (unless aborted)..changeset/sync-beforeload-pending-context.md('@tanstack/router-core': patch).packages/react-router/tests/issue-9009-pending-sync-beforeload-context.test.tsx.Verification
pnpm --filter @tanstack/router-core test:unit -- --run:139files,3,651passed (4expected fail,3skipped),Type Errors: no errorspnpm --filter @tanstack/react-router test:unit -- --run:99files,1,244passed (1skipped),Type Errors: no errorspnpm --filter @tanstack/vue-router test:unit -- --run:73files,1,020passed (1skipped),Type Errors: no errorspnpm --filter @tanstack/router-core test:eslint(0errors,25pre-existing warnings) &@tanstack/react-router test:eslint(0errors,100pre-existing warnings)pnpm --filter @tanstack/router-core test:types&@tanstack/react-router test:types: passed (ts56–ts70)pnpm --filter @tanstack/router-core test:build&@tanstack/react-router test:build: passed (publint --strict+attw)@tanstack/solid-router test:unitpassed21non-.tsxfiles (169type tests,Type Errors: no errors) on Windows Node 24, while.tsxfiles hit pre-existing Windows Vitest transformTypeErroronfile:///@solid-refresh.AI assistance disclosure: authored and verified with AI coding assistance; I have reviewed and tested the diff.
✅ Checklist
🚀 Release Impact
Summary by CodeRabbit