Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(router-core): merge synchronous beforeLoad context before offering pending match - #9019

Open
tranhoangtu-it wants to merge 1 commit into
TanStack:mainfrom
tranhoangtu-it:fix/pending-component-sync-beforeload-context-9009
Open

tranhoangtu-it wants to merge 1 commit into
TanStack:mainfrom
tranhoangtu-it:fix/pending-component-sync-beforeload-context-9009

Conversation

@tranhoangtu-it

@tranhoangtu-it tranhoangtu-it commented Nov 28, 2026 •

Copy link
Copy Markdown

Fixes #9009

🎯 Changes

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).
  • Add changeset .changeset/sync-beforeload-pending-context.md ('@tanstack/router-core': patch).
  • Add regression tests in packages/react-router/tests/issue-9009-pending-sync-beforeload-context.test.tsx.
isAsync = typeof value?.then === 'function'
if (isAsync) {
  offer?.()
}
// ... merge match.context on SUCCESS ...
if (!isAsync) {
  offer?.()
}

Verification

  • pnpm --filter @tanstack/router-core test:unit -- --run: 139 files, 3,651 passed (4 expected fail, 3 skipped), Type Errors: no errors
  • pnpm --filter @tanstack/react-router test:unit -- --run: 99 files, 1,244 passed (1 skipped), Type Errors: no errors
  • pnpm --filter @tanstack/vue-router test:unit -- --run: 73 files, 1,020 passed (1 skipped), Type Errors: no errors
  • pnpm --filter @tanstack/router-core test:eslint (0 errors, 25 pre-existing warnings) & @tanstack/react-router test:eslint (0 errors, 100 pre-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)
  • 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.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • 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.

…g pending match

Signed-off-by: Trần Hoàng Tú <tuth@ominext.com>
@changeset-bot

changeset-bot Bot commented Nov 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c70491b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@tanstack/router-core Patch
@tanstack/react-router Patch
@tanstack/react-start-client Patch
@tanstack/react-start-rsc Patch
@tanstack/react-start-server Patch
@tanstack/router-generator Patch
@tanstack/router-plugin Patch
@tanstack/solid-router Patch
@tanstack/solid-start-client Patch
@tanstack/solid-start-server Patch
@tanstack/start-client-core Patch
@tanstack/start-plugin-core Patch
@tanstack/start-server-core Patch
@tanstack/start-storage-context Patch
@tanstack/vue-router Patch
@tanstack/vue-start-client Patch
@tanstack/vue-start-server Patch
@tanstack/react-start Patch
@tanstack/router-cli Patch
@tanstack/router-vite-plugin Patch
@tanstack/solid-start Patch
@tanstack/start-static-server-functions Patch
@tanstack/vue-start Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-28T12:52:14.521530Z
We couldn’t complete this review. Comment @codex review to try again.
c70491b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.

Changes: Pending Component Context

Layer / File(s) Summary
beforeLoad readiness timing
packages/router-core/src/load-client.ts
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.
Context regression coverage
packages/react-router/tests/issue-9009-pending-sync-beforeload-context.test.tsx, .changeset/sync-beforeload-pending-context.md
Tests cover fast navigation, delayed ancestor beforeLoad, queued transactions, and unresolved asynchronous route beforeLoad. The changeset documents pending context from synchronous beforeLoad.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • 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 · up to 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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed [#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 Passed 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 10b22c2 and c70491b.

Files selected for processing: 3

  • .changeset/sync-beforeload-pending-context.md
  • packages/react-router/tests/issue-9009-pending-sync-beforeload-context.test.tsx
  • packages/router-core/src/load-client.ts

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 branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pendingComponent gets the route's own beforeLoad context on a fast navigation, loses it on a slow one

2 participants