Repository navigation
fix(router-core): keep server loads pending until settled - #8740
BleedingDev wants to merge 9 commits into
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| Layer / File(s) | Summary |
|---|---|
Track active server loads packages/router-core/src/router.ts, packages/router-core/src/load-server.ts, packages/router-core/tests/server-route-lifecycle.test.ts, packages/router-core/tests/server-load-state.bench.ts, packages/router-core/package.json, packages/router-core/vitest.server-load.bench.config.ts |
Router state tracks active server loads and remains pending until they settle. Lifecycle tests cover overlapping, failed, and cancelled loads. A benchmark suite measures these workloads. |
Wait for loads during SSR packages/router-core/src/ssr/ssr-server.ts, packages/router-core/src/ssr/createRequestHandler.ts, packages/router-core/tests/server-load-dehydration.test.ts, packages/react-router/tests/server-load-state-hydration.test.tsx, .changeset/server-load-status.md |
SSR dehydration waits for active loads before and after custom hooks. It propagates recorded load failures and checks for redirects. Tests cover failure, cleanup, abort, redirect, and hydration behavior. |
Handle redirects and dynamic early hints packages/start-server-core/src/createStartHandler.ts, packages/start-server-core/src/request-handler.ts, packages/start-server-core/tests/createStartHandler.test.ts |
The start handler checks for redirects after dehydration and adjusts dynamic hint collection based on pending loads and server-result changes. Tests and documentation cover hint and redirect behavior. |
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant createStartHandler
participant RouterCore
participant serverSsr.dehydrate
participant routeLoader
createStartHandler->>RouterCore: Start server route load
RouterCore->>RouterCore: Set pending state and count active loads
RouterCore->>routeLoader: Run route loader
createStartHandler->>serverSsr.dehydrate: Dehydrate request
serverSsr.dehydrate->>RouterCore: Wait for active loads
routeLoader-->>RouterCore: Resolve or reject load
RouterCore-->>serverSsr.dehydrate: Resolve wait or report failure
serverSsr.dehydrate-->>createStartHandler: Return dehydrated state or redirect
Suggested reviewers: schiller-manuel
Merge Risk: 
Minimal · previous review cd9c1
-
Server-rendered requests now wait for every active route load to finish before capturing state or rendering. Redirects that complete during that wait are honored, and load failures surface as errors. No concrete defect was found in the change. Two behaviors are intentional and documented: a failing background load fails the request, and early hints already sent stay in place if a redirect follows. It looks ready to merge once normal CI passes.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description explains the motivation, implementation, testing status, AI assistance, release impact, and all required checklist items. It also identifies pending hosted CI and performance comparison work.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 12 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
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.
CodeRabbit Verify
- Run CodeRabbit Verify to test the changes in this pull request.
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Repository: TanStack/router/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4c3290ef-61f9-4540-9a5a-fcf77bf97208
📒 Files selected for processing: 14
-
.changeset/server-load-status.md
packages/react-router/tests/server-load-state-hydration.test.tsx
packages/router-core/package.json
packages/router-core/src/load-server.ts
packages/router-core/src/router.ts
packages/router-core/src/ssr/createRequestHandler.ts
packages/router-core/src/ssr/ssr-server.ts
packages/router-core/tests/server-load-dehydration.test.ts
packages/router-core/tests/server-load-state.bench.ts
packages/router-core/tests/server-route-lifecycle.test.ts
packages/router-core/vitest.server-load.bench.config.ts
packages/start-server-core/src/createStartHandler.ts
packages/start-server-core/src/request-handler.ts
packages/start-server-core/tests/createStartHandler.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Repository: TanStack/router/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4c3290ef-61f9-4540-9a5a-fcf77bf97208
📒 Files selected for processing: 14
-
.changeset/server-load-status.mdpackages/react-router/tests/server-load-state-hydration.test.tsxpackages/router-core/package.jsonpackages/router-core/src/load-server.tspackages/router-core/src/router.tspackages/router-core/src/ssr/createRequestHandler.tspackages/router-core/src/ssr/ssr-server.tspackages/router-core/tests/server-load-dehydration.test.tspackages/router-core/tests/server-load-state.bench.tspackages/router-core/tests/server-route-lifecycle.test.tspackages/router-core/vitest.server-load.bench.config.tspackages/start-server-core/src/createStartHandler.tspackages/start-server-core/src/request-handler.tspackages/start-server-core/tests/createStartHandler.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
🦋 Changeset detectedLatest commit: 21a627b The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 packages
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 |
… into fix/upstream-server-load-only-20261017
d0fa985 to
5f32976
Compare
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cd9c19070b
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| : undefined | ||
| // A custom hook can start a load. Capture matches only after it settles. | ||
| if (router._serverLoads || router._serverLoadFailure) { | ||
| await waitForServerLoads(router, serverSsr, opts?.signal) |
There was a problem hiding this comment.
Abort server lanes omitted from the final snapshot
When an initial server lane returns deferred data and an onEnter or dehydration hook starts a successful reload, this second drain lets the reload replace the stored matches before serialization. The earlier lane still registered an onCleanup callback in load-server.ts, but that callback skips abortLane() when serialization of the final reload reports settled=true; consequently, a promise or resource tied to the earlier lane's public abort signal can continue indefinitely after the response. Track which lanes were actually dehydrated or abort superseded lanes before treating serialization completion as settlement.
AGENTS.md reference: packages/router-core/AGENTS.md:L4-L4
Useful? React with 👍 / 👎.
🎯 Changes
Why the change
Wait for every active server load before reporting idle or capturing hydration state so SSR returns the final route data or redirect.
Special things to note
cd9c19070bpassed all 9 focused dehydration regressions, TypeScript 5.6–7.0 and ESLint; hosted CI and the final performance comparison remain pending.Change outline
✅ Checklist
🚀 Release Impact
Summary by CodeRabbit