fix(router-core): Catch errors thrown during hydrate #5686
main fromrefs/pull/5686/head·merged by birkskyum(GitHub profile, opens in a new tab) Summary by CodeRabbit#
New Features
- Added a not-found "via-head" route and navigation link in both React and Solid examples.
Bug Fixes
- SSR hydration now records/logs NotFound per-route and handles per-match hydration errors locally without crashing.
Tests
- Expanded not-found tests to exercise head-stage lifecycle and added whitelist for hydration NotFound noise.
- Added SSR hydration test suites covering adapter initialization, match hydration, and error handling.
Chores
- Excluded the new route from prerendering.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core
Actionable comments posted: 2
🧹 Nitpick comments (3)
packages/router-core/tests/hydrate.test.ts (3)
89-93: Consider more complete mock matches.The mock matches use a minimal structure with only
id,routeId,index, and_nonReactive. While this may be sufficient for the serialization adapter test, consider whether additional properties (e.g.,params,loaderDeps,context,abortController) are needed to accurately represent real matches and avoid potential runtime errors if thehydratefunction accesses these properties.
215-254: LGTM with suggestions for enhanced coverage.The test correctly validates that errors thrown during route context hydration (specifically from the
headhook) are caught and logged toconsole.errorrather than propagating. This aligns with the PR objective.Consider adding assertions to verify that:
- The
hydratefunction completes successfully despite the error (doesn't reject the promise) - Other matches continue to be processed when one match throws an error
13-255: Consider expanding test coverage for additional hydration scenarios.The current tests provide good coverage of core hydration mechanics and error handling. Consider adding tests for:
- CSP nonce meta tag handling
pendingMinMsand_forcePendinglogic for pending matches- SPA mode detection (
lastMatchIdmismatch) - Custom
router.options.hydratecallback invocation - Route chunk loading with
loadRouteChunk
These scenarios are exercised in the
hydrateimplementation but not currently validated by tests.📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 1ec38819b62343534b83ace70aa6f7318688079f and 2e96440045965b762ce2b5449765e91479db8eff.
📒 Files selected for processing (11)
e2e/react-start/basic/src/routeTree.gen.ts(10 hunks)e2e/react-start/basic/src/routes/not-found/index.tsx(1 hunks)e2e/react-start/basic/src/routes/not-found/via-head.tsx(1 hunks)e2e/react-start/basic/tests/not-found.spec.ts(3 hunks)e2e/react-start/basic/vite.config.ts(1 hunks)e2e/solid-start/basic/src/routeTree.gen.ts(10 hunks)e2e/solid-start/basic/src/routes/not-found/index.tsx(1 hunks)e2e/solid-start/basic/src/routes/not-found/via-head.tsx(1 hunks)e2e/solid-start/basic/tests/not-found.spec.ts(3 hunks)packages/router-core/src/ssr/ssr-client.ts(1 hunks)packages/router-core/tests/hydrate.test.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
e2e/react-start/basic/src/routes/not-found/index.tsxpackages/router-core/src/ssr/ssr-client.tse2e/react-start/basic/vite.config.tse2e/react-start/basic/tests/not-found.spec.tse2e/solid-start/basic/src/routes/not-found/index.tsxpackages/router-core/tests/hydrate.test.tse2e/solid-start/basic/tests/not-found.spec.tse2e/react-start/basic/src/routes/not-found/via-head.tsxe2e/solid-start/basic/src/routeTree.gen.tse2e/solid-start/basic/src/routes/not-found/via-head.tsxe2e/react-start/basic/src/routeTree.gen.ts
**/src/routes/**
📄 CodeRabbit inference engine (AGENTS.md)
Place file-based routes under src/routes/ directories
Files:
e2e/react-start/basic/src/routes/not-found/index.tsxe2e/solid-start/basic/src/routes/not-found/index.tsxe2e/react-start/basic/src/routes/not-found/via-head.tsxe2e/solid-start/basic/src/routes/not-found/via-head.tsx
e2e/**
📄 CodeRabbit inference engine (AGENTS.md)
Store end-to-end tests under the e2e/ directory
Files:
e2e/react-start/basic/src/routes/not-found/index.tsxe2e/react-start/basic/vite.config.tse2e/react-start/basic/tests/not-found.spec.tse2e/solid-start/basic/src/routes/not-found/index.tsxe2e/solid-start/basic/tests/not-found.spec.tse2e/react-start/basic/src/routes/not-found/via-head.tsxe2e/solid-start/basic/src/routeTree.gen.tse2e/solid-start/basic/src/routes/not-found/via-head.tsxe2e/react-start/basic/src/routeTree.gen.ts
packages/router-core/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep framework-agnostic core router logic in packages/router-core/
Files:
packages/router-core/src/ssr/ssr-client.tspackages/router-core/tests/hydrate.test.ts
🧬 Code graph analysis (5)
e2e/react-start/basic/src/routes/not-found/index.tsx (2)
e2e/react-start/basic/src/routes/not-found/via-head.tsx (1)
Route(3-15)
e2e/react-start/basic/src/routes/not-found/route.tsx (1)
Route(4-8)
e2e/solid-start/basic/src/routes/not-found/index.tsx (3)
e2e/react-start/basic/src/routes/not-found/index.tsx (1)
Route(3-41)
e2e/react-start/basic/src/routes/not-found/via-head.tsx (1)
Route(3-15)
e2e/solid-start/basic/src/routes/not-found/via-head.tsx (1)
Route(3-15)
packages/router-core/tests/hydrate.test.ts (1)
packages/router-core/src/ssr/ssr-client.ts (2)
TsrSsrGlobal(17-28)hydrate(59-279)
e2e/react-start/basic/src/routes/not-found/via-head.tsx (2)
e2e/react-start/basic/src/routes/not-found/index.tsx (1)
Route(3-41)
e2e/solid-start/basic/src/routes/not-found/via-head.tsx (1)
Route(3-15)
e2e/solid-start/basic/src/routes/not-found/via-head.tsx (1)
e2e/solid-start/basic/src/routes/not-found/index.tsx (1)
Route(3-41)
🔇 Additional comments (21)
e2e/react-start/basic/vite.config.ts (1)
23-23: LGTM!The addition of
/not-found/via-headto the prerender exclusion list is correct and consistent with other not-found routes. Routes that triggernotFound()should not be prerendered.e2e/solid-start/basic/src/routes/not-found/index.tsx (1)
28-37: LGTM!The via-head link addition follows the established pattern and uses proper Solid.js syntax (
class, signal accessorpreload()).e2e/react-start/basic/src/routes/not-found/index.tsx (1)
28-37: LGTM!The via-head link addition follows the established pattern and uses proper React syntax.
e2e/solid-start/basic/tests/not-found.spec.ts (2)
12-12: LGTM!The whitelisted error for route context hydration aligns with the PR's objective to improve SSR hydration error handling when
notFound()is thrown.
29-29: LGTM!Expanding the test matrices to include
'head'provides coverage for the new/not-found/via-headroute that triggersnotFound()during the head phase.Also applies to: 60-60
e2e/react-start/basic/tests/not-found.spec.ts (1)
12-12: LGTM!Test updates mirror the Solid implementation and properly extend coverage for the new via-head route with appropriate error whitelisting.
Also applies to: 29-29, 61-61
e2e/react-start/basic/src/routes/not-found/via-head.tsx (2)
3-15: Route correctly implements head-phase notFound() for testing.The route structure properly tests the scenario where
notFound()is thrown during theheadphase. ThenotFoundComponentwill be rendered instead of the regularcomponent.
17-23: RouteComponent exists for completeness.While
RouteComponentwon't render in practice (sincehead()always throwsnotFound()), it's appropriate to define it for test completeness. Thedata-serverattribute helps verify SSR/hydration behavior in tests.e2e/solid-start/basic/src/routes/not-found/via-head.tsx (1)
1-23: LGTM!The Solid implementation correctly mirrors the React version with appropriate framework-specific imports. The route properly tests
notFound()thrown during theheadphase.e2e/solid-start/basic/src/routeTree.gen.ts (1)
35-35: LGTM!The generated route tree correctly integrates the new
NotFoundViaHeadRoutewith proper imports, type definitions, and route registrations throughout the file.Also applies to: 167-171, 261-261, 295-295, 335-335, 375-375, 409-409, 448-448, 655-661, 765-765, 772-772
e2e/react-start/basic/src/routeTree.gen.ts (5)
173-177: Route constant definition is consistent.idandpathuse '/via-head' and parent isNotFoundRouteRoute, matching sibling routes.
281-282: Types and public route maps updated coherently.Additions for '/not-found/via-head' are present and consistent across FileRoutesByFullPath, FileRoutesByTo, FileRoutesById, and FileRouteTypes unions.
Also applies to: 317-318, 358-359, 401-402, 437-438, 477-478
688-694: Module augmentation entry matches generator conventions.fullPath,path,preLoaderRoute, andparentRoutealign with the new route; no discrepancies spotted.
819-820: Children wiring under NotFoundRouteRoute is correct.NotFoundViaHeadRouteadded to both the interface and value object. Mirrors sibling route patterns.Also applies to: 826-827
37-37: Import and route wiring verified successfully.The source file
e2e/react-start/basic/src/routes/not-found/via-head.tsxexists and correctly exportsRoutewith aheadhook that callsnotFound(). The import in routeTree.gen.ts is correctly wired.packages/router-core/tests/hydrate.test.ts (6)
54-58: LGTM!The test correctly validates the error handling when
window.$_TSRis missing.
60-72: LGTM!The test correctly validates the error handling when
window.$_TSR.routeris missing.
118-138: LGTM!The test correctly validates that no transformer map is created when serialization adapters are empty, while initialization still completes.
140-160: LGTM!The test correctly validates that the manifest is propagated from
window.$_TSR.routerintorouter.ssr.
162-213: LGTM!The test correctly validates that matches are hydrated with server-provided loader data and status flags, including the case where some matches lack dehydrated data.
4-10: I need to examine what this test file is actually testing to determine if importing from react-router is correct.The review comment is incorrect and should be disregarded.
The utilities being imported (
createMemoryHistory,createRootRoute,createRoute,createRouter,notFound) are framework-specific APIs that belong in@tanstack/react-router, notpackages/router-core. These are standard React Router imports, not router-core utilities. OnlynotFoundhas a framework-agnostic version in router-core; the others are inherently React-specific and cannot be imported from router-core because they don't exist there.If the concern is about framework coupling in router-core tests, that's a separate architectural question worth discussing, but the specific directive to import from
packages/router-core/srcis not actionable because these utilities do not and should not exist there by design.Likely an incorrect or invalid review comment.
@@ -216,5 +216,7 @@216216 match.headScripts = headFnContent?.scripts217217 match.styles = headFnContent?.styles218218 match.scripts = scripts219- }),220- )219+ })220+ ).catch((err) => {221+ console.error('Error during route context hydration:', err)222+ })⚠️ Potential issue | 🟠 Major
Risk of silent failures with indiscriminate error swallowing.
The catch handler logs all errors but doesn't distinguish between expected errors (e.g.,
notFound()thrown fromhead()) and unexpected errors (e.g., programming bugs). This means:- All errors are swallowed: TypeErrors, ReferenceErrors, and other bugs will be silently ignored, making debugging difficult in production
- No state tracking: The router and matches have no indication that hydration failed, so downstream code may encounter undefined properties (e.g.,
match.meta,match.context) - Inconsistent state risk: Since
Promise.allrejects on the first failure, some matches may have hydrated successfully while others have not, creating an inconsistent application state
Consider these improvements:
- ).catch((err) => { - console.error('Error during route context hydration:', err) - }) + ).catch((err) => { + console.error('Error during route context hydration:', err) + // Differentiate expected errors from unexpected ones + const isExpectedError = err?.isNotFound || err?.routeError + if (!isExpectedError) { + // For unexpected errors, consider updating router state to indicate hydration failure + router.__store.setState((s) => ({ + ...s, + hydrationError: err, + })) + } + // Re-throw unexpected errors in development for easier debugging + if (process.env.NODE_ENV !== 'production' && !isExpectedError) { + throw err + } + })Alternatively, document this behavior if swallowing all errors is intentional for hydration resilience.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In packages/router-core/src/ssr/ssr-client.ts around lines 219-222, the current catch handler indiscriminately logs and swallows all errors from the hydration Promise.all, which hides programming errors and leaves router/matches in inconsistent state; change to handle expected control-flow errors (e.g., notFound()) separately and propagate unexpected errors: replace the single Promise.all with Promise.allSettled or catch per-match errors so each match records success/failure (set a flag on match like match.hydrationFailed and attach error to match.context or match.error), log full error details for unexpected errors and rethrow them (or surface them to the caller) so they are not silently swallowed, and ensure the router state gets a hydration status flag to indicate partial/failed hydration for downstream code to check.✅ Addressed in commit 492a898
packages/react-router/tests/hydrate.test.ts line 48@@ -0,0 +26,21 @@26+ const history = createMemoryHistory({ initialEntries: ['/'] })27+28+ const rootRoute = createRootRoute({})29+30+ const indexRoute = createRoute({31+ getParentRoute: () => rootRoute,32+ path: '/',33+ component: () => 'Index',34+ notFoundComponent: () => 'Not Found',35+ head: mockHead,36+ })37+38+ const otherRoute = createRoute({39+ getParentRoute: () => indexRoute,40+ path: '/other',41+ component: () => 'Other',42+ })43+44+ const routeTree = rootRoute.addChildren([indexRoute.addChildren([otherRoute])])45+46+ mockRouter = createRouter({ routeTree, history, isServer: true })⚠️ Potential issue | 🟡 Minor
Verify the
isServer: trueflag for client hydration tests.The
hydratefunction is designed for client-side hydration, yet the router is created withisServer: true. This contradicts the test scenario and may affect router behavior. Consider usingisServer: falseor omitting the flag entirely to accurately simulate the client environment.🤖 Prompt for AI Agents
In packages/router-core/tests/hydrate.test.ts around line 46, the test creates the router with isServer: true which contradicts the client-side hydration scenario; update the router instantiation to use isServer: false (or remove the flag) so the router is created as a client environment, ensuring hydrate runs against client-mode behavior and any server-only branches are not triggered.- The
View your CI Pipeline Execution ↗ for commit dad79febdba715c1bdb1e30c28daa3c34fe41e10
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 1m 45s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 3s View ↗
☁️ Nx Cloud last updated this comment at
2025-11-19 20:00:57UTCActionable comments posted: 0
♻️ Duplicate comments (2)
packages/router-core/src/ssr/ssr-client.ts (1)
220-222: Error handling concern already raised in previous review.The indiscriminate error swallowing in this catch handler has been comprehensively flagged in the previous review, including concerns about silent failures, lack of state tracking, and inconsistent router state.
packages/router-core/tests/hydrate.test.ts (1)
48-48: isServer flag concern already raised in previous review.The use of
isServer: truefor client-side hydration tests has been flagged in the previous review as contradicting the test scenario.🧹 Nitpick comments (2)
packages/router-core/tests/hydrate.test.ts (2)
1-11: Consider importing from source instead of dist.The import on lines 4-10 uses
../../react-router/dist/esm, which is unusual for unit tests. Typically, tests import from source files to ensure they're testing the actual implementation rather than the built artifacts.Additionally, ESLint flags import ordering issues that could be addressed.
Apply this diff to import from source and fix ordering:
-import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { + createMemoryHistory, + createRootRoute, + createRoute, + createRouter, + notFound, +} from '../../react-router/src' import { hydrate } from '../src/ssr/ssr-client' import type { TsrSsrGlobal } from '../src/ssr/ssr-client' -import { - createMemoryHistory, - createRootRoute, - createRoute, - createRouter, - notFound, -} from '../../react-router/dist/esm' import type { AnyRouteMatch } from '../src'
217-259: Consider expanding error handling test coverage.The test validates that
notFound()errors during hydration are caught and logged. However, it only covers one error type and doesn't verify:- Router state remains consistent after the error
- Hydration completes successfully despite the error
- Other error types (e.g., TypeError, ReferenceError) are handled similarly
Consider adding test cases for:
it('should handle unexpected errors during route context hydration', async () => { // Test TypeError, ReferenceError, etc. }) it('should continue hydration after error in one match', async () => { // Verify that other matches complete hydration successfully })Additionally, verify that the router state is checked after error handling to ensure consistency.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 2e96440045965b762ce2b5449765e91479db8eff and f9ee4a5766cc5e4f57f2c51fdd2acd15e25aa54f.
📒 Files selected for processing (4)
e2e/react-start/basic/src/routes/not-found/via-head.tsx(1 hunks)e2e/solid-start/basic/src/routes/not-found/via-head.tsx(1 hunks)packages/router-core/src/ssr/ssr-client.ts(1 hunks)packages/router-core/tests/hydrate.test.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- e2e/solid-start/basic/src/routes/not-found/via-head.tsx
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/router-core/tests/hydrate.test.tse2e/react-start/basic/src/routes/not-found/via-head.tsxpackages/router-core/src/ssr/ssr-client.ts
packages/router-core/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep framework-agnostic core router logic in packages/router-core/
Files:
packages/router-core/tests/hydrate.test.tspackages/router-core/src/ssr/ssr-client.ts
**/src/routes/**
📄 CodeRabbit inference engine (AGENTS.md)
Place file-based routes under src/routes/ directories
Files:
e2e/react-start/basic/src/routes/not-found/via-head.tsx
e2e/**
📄 CodeRabbit inference engine (AGENTS.md)
Store end-to-end tests under the e2e/ directory
Files:
e2e/react-start/basic/src/routes/not-found/via-head.tsx
🧠 Learnings (7)
📓 Common learnings
Learnt from: CR PR: TanStack/router#0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to packages/router-core/** : Keep framework-agnostic core router logic in packages/router-core/Learnt from: CR PR: TanStack/router#0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to packages/{react-router,solid-router}/** : Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad PR: TanStack/router#5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
packages/router-core/tests/hydrate.test.tse2e/react-start/basic/src/routes/not-found/via-head.tsxpackages/router-core/src/ssr/ssr-client.ts
📚 Learning: 2025-10-01T18:30:26.591Z
Learnt from: schiller-manuel PR: TanStack/router#5330 File: packages/router-core/src/router.ts:2231-2245 Timestamp: 2025-10-01T18:30:26.591Z Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.Applied to files:
packages/router-core/tests/hydrate.test.ts
📚 Learning: 2025-09-23T17:36:12.598Z
Learnt from: CR PR: TanStack/router#0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to packages/router-core/** : Keep framework-agnostic core router logic in packages/router-core/Applied to files:
packages/router-core/tests/hydrate.test.ts
📚 Learning: 2025-10-01T18:31:35.420Z
Learnt from: schiller-manuel PR: TanStack/router#5330 File: e2e/react-start/custom-basepath/src/routeTree.gen.ts:58-61 Timestamp: 2025-10-01T18:31:35.420Z Learning: Do not review files named `routeTree.gen.ts` in TanStack Router repositories, as these are autogenerated files that should not be manually modified.Applied to files:
e2e/react-start/basic/src/routes/not-found/via-head.tsx
📚 Learning: 2025-09-23T17:36:12.598Z
Learnt from: CR PR: TanStack/router#0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to packages/{react-router,solid-router}/** : Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/Applied to files:
e2e/react-start/basic/src/routes/not-found/via-head.tsx
📚 Learning: 2025-09-28T21:41:45.233Z
Learnt from: nlynzaad PR: TanStack/router#5284 File: e2e/react-start/basic/server.js:50-0 Timestamp: 2025-09-28T21:41:45.233Z Learning: In Express v5, catch-all routes must use named wildcards. Use `/*splat` to match everything except root path, or `/{*splat}` (with braces) to match including root path. The old `*` syntax is not allowed and will cause "Missing parameter name" errors. This breaking change requires explicit naming of wildcard parameters.Applied to files:
packages/router-core/src/ssr/ssr-client.ts
🧬 Code graph analysis (2)
packages/router-core/tests/hydrate.test.ts (1)
packages/router-core/src/ssr/ssr-client.ts (2)
TsrSsrGlobal(17-28)hydrate(59-279)
e2e/react-start/basic/src/routes/not-found/via-head.tsx (1)
e2e/react-start/basic/src/routes/not-found/index.tsx (1)
Route(3-41)
🪛 ESLint
packages/router-core/tests/hydrate.test.ts
[error] 1-1: Member 'expect' of the import declaration should be sorted alphabetically.
(sort-imports)
[error] 4-10:
../../react-router/dist/esmimport should occur before type import of../src/ssr/ssr-client(import/order)
🔇 Additional comments (4)
packages/router-core/tests/hydrate.test.ts (1)
56-215: Comprehensive test coverage for core hydration scenarios.These tests effectively cover:
- Missing bootstrap data validation
- Serialization adapter initialization and buffer execution
- Manifest propagation to router.ssr
- Match hydration with server-provided data
The test structure is clear and assertions are appropriate.
e2e/react-start/basic/src/routes/not-found/via-head.tsx (3)
1-1: LGTM!The imports are correct and appropriate for creating a file-based route that tests
notFound()behavior.
17-23: LGTM!The
RouteComponentis well-implemented with appropriate test attributes. Thedata-server={typeof window}is a clever way to distinguish between server and client rendering contexts. While this component should not actually render (since theheadhook always throwsnotFound()), it serves as a valid test fixture to ensure thenotFoundComponenttakes precedence.
3-15: Implementation correctly matches all test expectations.The route implementation is correct:
- The
headhook throwsnotFound()immediately, preventingRouteComponentfrom rendering - The
notFoundComponenthasdata-testid="via-head-notFound-component"matching test expectations for visibility - The
RouteComponenthasdata-testid="via-head-route-component"matching test expectations for non-visibility - Both navigation and direct visit scenarios in the test suite will pass
- The hydration error
'Error during route context hydration: {isNotFound: true}'is properly whitelisted in the tests
Hi @schiller-manuel, do you need me to do anything more for this PR to merge? 🙏
github-actions[bot](GitHub profile, opens in a new tab) added labelsdocumentation
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-plugin
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-generator
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: directive-functions-plugin
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-cli
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: server-functions-plugin
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: valibot-adapter
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-devtools
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: zod-adapter
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: arktype-adapter
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-vite-plugin
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-start-server
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-start
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-start-client
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-start-client
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-start-server
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-devtools-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router-devtools
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-start
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router-devtools
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-plugin-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-server-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-client-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-static-server-functions
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-storage-context
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router-ssr-query
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-ssr-query-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router-ssr-query
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/router-core/tests/hydrate.test.ts (1)
217-261: Strengthen NotFound hydration test by assertingmatch.error.The test correctly verifies that
hydratelogs a NotFound error and does not throw, but it doesn’t assert that the match’serrorfield is set as intended. You can cover the new behavior more directly by also checkingmatch.error:- await hydrate(mockRouter) - - expect(consoleSpy).toHaveBeenCalledWith( + await hydrate(mockRouter) + + const [match] = mockRouter.state.matches as AnyRouteMatch[] + expect(match.error).toEqual({ isNotFound: true }) + + expect(consoleSpy).toHaveBeenCalledWith( 'NotFound error during hydration for routeId: /', expect.objectContaining({ isNotFound: true, }), )📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between a0796a69274d8f9254871664103ba0ed9e0be344 and 492a898cd9febc0ab158a202e42d307211bc152f.
📒 Files selected for processing (6)
e2e/react-start/basic/tests/not-found.spec.ts(3 hunks)e2e/solid-start/basic-solid-query/test-results/.last-run.json(1 hunks)e2e/solid-start/basic/tests/not-found.spec.ts(3 hunks)e2e/solid-start/query-integration/test-results/.last-run.json(1 hunks)packages/router-core/src/ssr/ssr-client.ts(2 hunks)packages/router-core/tests/hydrate.test.ts(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- e2e/solid-start/query-integration/test-results/.last-run.json
🚧 Files skipped from review as they are similar to previous changes (2)
- e2e/solid-start/basic/tests/not-found.spec.ts
- packages/router-core/src/ssr/ssr-client.ts
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
e2e/react-start/basic/tests/not-found.spec.tspackages/router-core/tests/hydrate.test.ts
📚 Learning: 2025-10-14T18:59:33.990Z
Learnt from: FatahChan Repo: TanStack/router PR: 5475 File: e2e/react-start/basic-prerendering/src/routes/redirect/$target/via-beforeLoad.tsx:8-0 Timestamp: 2025-10-14T18:59:33.990Z Learning: In TanStack Router e2e test files, when a route parameter is validated at the route level (e.g., using zod in validateSearch or param validation), switch statements on that parameter do not require a default case, as the validation ensures only expected values will reach the switch.Applied to files:
e2e/react-start/basic/tests/not-found.spec.ts
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5732 File: packages/start-client-core/src/client/hydrateStart.ts:6-9 Timestamp: 2025-11-02T16:16:24.898Z Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.Applied to files:
packages/router-core/tests/hydrate.test.ts
📚 Learning: 2025-10-01T18:30:26.591Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: packages/router-core/src/router.ts:2231-2245 Timestamp: 2025-10-01T18:30:26.591Z Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.Applied to files:
packages/router-core/tests/hydrate.test.ts
🧬 Code graph analysis (1)
packages/router-core/tests/hydrate.test.ts (1)
packages/router-core/src/ssr/ssr-client.ts (2)
TsrSsrGlobal(19-34)hydrate(65-301)
🪛 ESLint
packages/router-core/tests/hydrate.test.ts
[error] 1-1: Member 'expect' of the import declaration should be sorted alphabetically.
(sort-imports)
[error] 4-10:
../../react-router/dist/esmimport should occur before type import of../src/ssr/ssr-client(import/order)
🔇 Additional comments (2)
e2e/react-start/basic/tests/not-found.spec.ts (2)
12-12: LGTM! Appropriate whitelisted error for hydration.The new whitelisted error pattern correctly allows NotFound errors during hydration, which aligns with the PR's goal of handling errors thrown during the hydrate phase. The pattern is specific enough while accommodating variable routeId values.
29-29: LGTM! Improved test coverage with 'head' thrower.The addition of
'head'to both test matrices properly extends coverage to test the new lifecycle stage wherehead()can thrownotFound(). The test matrices now validate both navigation and direct-visit scenarios for the new/not-found/via-headroute.Also applies to: 61-61
@@ -0,0 +1,4 @@1+{2+ "status": "failed",3+ "failedTests": []4+}⚠️ Potential issue | 🟠 Major
🧩 Analysis chain
Do not commit test-result artifacts to source control.
This appears to be a test-run artifact file (
.last-run.json) that tracks test execution state. Such files should never be committed to version control as they are ephemeral outputs generated during test runs. Additionally, the data is contradictory:statusis marked as"failed"butfailedTestsis an empty array, which suggests the test results are either incomplete or malformed.Please verify:
- Whether this file was intentionally added or is an accidental commit
- Whether the
test-results/directory should be added to.gitignoreto prevent future commits of these artifacts - Whether the contradictory status/failedTests values indicate an actual test failure that should be investigated
If this was added by mistake, please remove it from the commit.
🏁 Script executed:
#!/bin/bash # Check if .gitignore exists and whether test-results is excluded echo "=== Checking .gitignore for test-results patterns ===" if [ -f .gitignore ]; then echo "Contents of .gitignore:" cat .gitignore | grep -i "test-results\|\.last-run" || echo "(no matches for test-results or .last-run)" else echo ".gitignore not found at root" fi echo "" echo "=== Checking for .gitignore in e2e/solid-start/basic-solid-query/ ===" if [ -f "e2e/solid-start/basic-solid-query/.gitignore" ]; then echo "Found .gitignore in e2e/solid-start/basic-solid-query/" cat "e2e/solid-start/basic-solid-query/.gitignore" else echo "No .gitignore in e2e/solid-start/basic-solid-query/" fi echo "" echo "=== Check git status for this file ===" git status "e2e/solid-start/basic-solid-query/test-results/.last-run.json" 2>/dev/null || echo "(file not tracked or git error)" echo "" echo "=== Search for other .last-run.json files ===" fd -name ".last-run.json" || echo "(none found)" echo "" echo "=== Check all test-results directories in repo ===" fd -type d -name "test-results" || echo "(none found)"Length of output: 874
🏁 Script executed:
#!/bin/bash # Check the actual file structure and content echo "=== Full path verification ===" ls -la "e2e/solid-start/basic-solid-query/test-results/" 2>/dev/null || echo "Directory not accessible or doesn't exist" echo "" echo "=== Check if directory has other files ===" find "e2e/solid-start/basic-solid-query/test-results/" -type f 2>/dev/null || echo "Cannot access directory" echo "" echo "=== Display the actual file content ===" cat "e2e/solid-start/basic-solid-query/test-results/.last-run.json" 2>/dev/null || echo "File not found"Length of output: 395
🏁 Script executed:
#!/bin/bash # Search for any patterns related to test result artifacts being ignored echo "=== Search for patterns in all .gitignore files ===" fd -name ".gitignore" -exec grep -l "test\|result\|\.last" {} \; 2>/dev/null || echo "(no matches)" echo "" echo "=== Check if similar test artifact patterns exist elsewhere ===" fd -type f -name "*.json" -path "*/test*" | grep -E "(result|last-run|test-report)" | head -20Length of output: 300
🏁 Script executed:
#!/bin/bash # Check if this file is part of the PR or was already in the repo echo "=== Check git log for this file ===" git log --oneline -- "e2e/solid-start/basic-solid-query/test-results/.last-run.json" 2>/dev/null | head -5 || echo "(No history found)" echo "" echo "=== Check git diff against main/master for this file ===" git diff HEAD~1 -- "e2e/solid-start/basic-solid-query/test-results/.last-run.json" 2>/dev/null | head -30 || echo "(No diff available)" echo "" echo "=== Check current branch commits ===" git log --oneline -10 2>/dev/null echo "" echo "=== Show untracked files that might be similar ===" git status --porcelain 2>/dev/null | grep -i "test" || echo "(No untracked test files)"Length of output: 1049
🏁 Script executed:
#!/bin/bash # Check if test-results directory structure and any README or documentation echo "=== Check directory structure and all files ===" find "e2e/solid-start/basic-solid-query/test-results/" -type f -o -type d echo "" echo "=== Look for any test configuration or runner files ===" find "e2e/solid-start/basic-solid-query/" -name "*.config.*" -o -name "vitest*" -o -name "jest*" | head -10 echo "" echo "=== Check if solid-start test folder has documentation ===" ls -la "e2e/solid-start/basic-solid-query/" | head -20Length of output: 1050
Remove test artifact file and add test-results to .gitignore.
This file (
.last-run.json) was newly added to the commit and is a generated test output from Playwright, which should never be committed to source control. The git diff confirms it's a new file addition. Additionally, no.gitignoreentry exists to prevent similar artifacts from being committed in the future.The data also shows a concerning contradiction:
status: "failed"butfailedTests: []is empty, indicating either an incomplete test run or a test framework issue that requires investigation.Required actions:
- Remove this file from the commit
- Add
test-results/directory to.gitignoreat the repository root or ine2e/ - Investigate why the test reports a failed status with no failed tests listed
🤖 Prompt for AI Agents
In e2e/solid-start/basic-solid-query/test-results/.last-run.json lines 1-4, a Playwright-generated test artifact was committed (status:"failed" with empty failedTests), which should be removed; delete this file from the commit (git rm --cached if already committed), add a gitignore entry for test-results/ at the repository root (or at e2e/ if preferred) to prevent future commits, and then rerun the Playwright suite to investigate why it reported status "failed" with no failedTests (check for interrupted runs, reporter configuration, or CI timeouts and capture the full report/logs to diagnose).@@ -0,0 +1,11 @@1+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'2+import { hydrate } from '../src/ssr/ssr-client'3+import type { TsrSsrGlobal } from '../src/ssr/ssr-client'4+import {5+ createMemoryHistory,6+ createRootRoute,7+ createRoute,8+ createRouter,9+ notFound,10+} from '../../react-router/dist/esm'11+import type { AnyRouteMatch } from '../src'⚠️ Potential issue | 🟡 Minor
Fix ESLint import order and specifier sorting.
Static analysis points out two lint violations: unordered Vitest specifiers and suboptimal import ordering between runtime and type-only imports. You can fix both without changing behavior by reordering:
-import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' -import { hydrate } from '../src/ssr/ssr-client' -import type { TsrSsrGlobal } from '../src/ssr/ssr-client' -import { - createMemoryHistory, - createRootRoute, - createRoute, - createRouter, - notFound, -} from '../../react-router/dist/esm' -import type { AnyRouteMatch } from '../src' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { + createMemoryHistory, + createRootRoute, + createRoute, + createRouter, + notFound, +} from '../../react-router/dist/esm' +import { hydrate } from '../src/ssr/ssr-client' +import type { TsrSsrGlobal } from '../src/ssr/ssr-client' +import type { AnyRouteMatch } from '../src'📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { createMemoryHistory, createRootRoute, createRoute, createRouter, notFound, } from '../../react-router/dist/esm' import { hydrate } from '../src/ssr/ssr-client' import type { TsrSsrGlobal } from '../src/ssr/ssr-client' import type { AnyRouteMatch } from '../src'🧰 Tools
🪛 ESLint
[error] 1-1: Member 'expect' of the import declaration should be sorted alphabetically.
(sort-imports)
[error] 4-10:
../../react-router/dist/esmimport should occur before type import of../src/ssr/ssr-client(import/order)
🤖 Prompt for AI Agents
In packages/router-core/tests/hydrate.test.ts around lines 1 to 11, fix ESLint import-order and specifier-sorting by reordering imports: sort the Vitest named specifiers alphabetically (e.g., afterEach, beforeEach, describe, expect, it, vi) and ensure runtime/value imports (react-router package) come before type-only imports (the TsrSsrGlobal and AnyRouteMatch type imports); keep import groups logically ordered and specifiers alphabetized so lint rules pass without changing behavior.✅ Addressed in commits b2eb15a to 0043a5c
Actionable comments posted: 0
♻️ Duplicate comments (1)
packages/router-core/tests/hydrate.test.ts (1)
18-49: Re‑checkisServer: truefor a client‑sidehydratetest setup.The router used for
hydrateis created withisServer: true. Sincehydrateis the client‑side hydration entry, it may be more representative to run these tests with a client‑mode router (isServer: falseor omitting the flag), unless there is a specific reason to exercise the server branch here. Please confirm this is intentional and not masking any client‑only behavior.🧹 Nitpick comments (1)
packages/router-core/tests/hydrate.test.ts (1)
217-261: Consider also asserting onmatch.errorfor stronger NotFound guarantees.This test nicely verifies that
notFound()thrown fromheadis caught and logged with the expected message and an error carryingisNotFound: true. To fully lock in the new behavior, you could additionally assert that the match’s error was normalized:const match = mockRouter.state.matches[0] as AnyRouteMatch expect(match.error).toEqual({ isNotFound: true })That would protect both the logging and
match.errorcontract of the NotFound hydration path.📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 492a898cd9febc0ab158a202e42d307211bc152f and 0043a5c04df6ae79a6829136356ab78d6858eaf7.
📒 Files selected for processing (1)
packages/router-core/tests/hydrate.test.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
packages/router-core/tests/hydrate.test.ts
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5732 File: packages/start-client-core/src/client/hydrateStart.ts:6-9 Timestamp: 2025-11-02T16:16:24.898Z Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.Applied to files:
packages/router-core/tests/hydrate.test.ts
📚 Learning: 2025-10-01T18:30:26.591Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: packages/router-core/src/router.ts:2231-2245 Timestamp: 2025-10-01T18:30:26.591Z Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.Applied to files:
packages/router-core/tests/hydrate.test.ts
🧬 Code graph analysis (1)
packages/router-core/tests/hydrate.test.ts (1)
packages/router-core/src/ssr/ssr-client.ts (2)
TsrSsrGlobal(19-34)hydrate(65-301)
🔇 Additional comments (2)
packages/router-core/tests/hydrate.test.ts (2)
56-140: Good coverage of bootstrap invariants and serialization adapter paths.The tests around missing
window.$_TSR, missingwindow.$_TSR.router, and adapter initialization accurately mirror thehydrateinvariants and adapter logic (including thetmap, buffer flushing, andinitializedflag). The use of stubs formatchRoutes/state.matcheskeeps these tests focused on the intended behavior without over‑mocking the router internals.
164-215: Match hydration assertions align well withhydrateMatchbehavior.The
should hydrate matchestest correctly verifies that dehydrated match fields (loaderData,status,ssr) are restored onto the client matches viahydrateMatch, using realistici/l/s/ssr/ushapes and the router’smatchespipeline. This is a solid regression check for the core SSR rehydration path.I believe this would also solve https://github.com/TanStack/router/issues/5427 , https://github.com/TanStack/router/issues/5546 and https://github.com/TanStack/router/issues/5322
More templates
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-authenticated-routes-firebase
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-default-search-params
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-basic-virtual-file-based
- tanstack-router-solid-example-basic-virtual-inside-file-based
- tanstack-router-solid-example-deferred-data
- tanstack-router-solid-i18n-paraglide
- tanstack-router-solid-example-kitchen-sink
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-large-file-based
- tanstack-router-solid-example-location-masking
- tanstack-router-solid-example-navigation-blocking
- tanstack-router-solid-example-quickstart
- tanstack-router-solid-example-quickstart-esbuild-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-router-solid-example-quickstart-rspack-file-based
- tanstack-router-solid-example-quickstart-webpack-file-based
- router-solid-mono-simple
- router-solid-mono-simple-lazy
- router-solid-monorepo-solid-query
- tanstack-router-solid-example-scroll-restoration
- tanstack-solid-router-search-validator-adapters
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-solid-start-example-counter
- tanstack-solid-start-i18n-paraglide
- tanstack-solid-start-example-large
- tanstack-solid-start-streaming-data-from-server-functions
- tanstack-solid-start-example-supabase-basic
- tanstack-solid-start-tailwind-v4
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-solid-example-with-trpc
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5686@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5686@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5686@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5686@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5686@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5686@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5686@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5686@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5686@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5686@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5686@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5686@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5686@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5686@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5686@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5686@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5686@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5686@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5686@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5686@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5686@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5686@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5686@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5686@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5686@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5686@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5686@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5686@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5686@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5686@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5686@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5686@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5686@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5686@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5686commit:
dad79febirkskyum(GitHub profile, opens in a new tab) approved these changes
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/router-core/src/ssr/ssr-client.ts (2)
186-207: Align context reconstruction with core router semantics for consistencyThe re-run of
route.options.contexthere is meant to rebuild route context after__beforeLoadContexthydration, but it currently diverges from the core router implementation:parentContextdoes not fall back to{}when bothparentMatch?.contextandrouter.options.contextare undefined, unlike the logic inrouter.matchRoutes. (app.unpkg.com)- The
contextFnContextomitssearch, which is included in the main router’sRouteContextOptionswhen invokingroute.options.context. (app.unpkg.com) contextpassed intoroute.options.contextuses onlyparentContext, not the already-mergedmatch.contextthat includes__routeContextand__beforeLoadContextlike router.ts does.
For behavioral parity and fewer subtle bugs, consider reshaping this block to follow the same pattern as
router.matchRoutes, roughly:- const parentMatch = router.state.matches[match.index - 1] - const parentContext = parentMatch?.context ?? router.options.context + const parentMatch = router.state.matches[match.index - 1] + const parentMatchId = parentMatch?.id + const parentContext = !parentMatchId + ? ((router.options.context as any) ?? {}) + : (parentMatch?.context ?? router.options.context ?? {}) ... - if (route.options.context) { - const contextFnContext: RouteContextOptions<any, any, any, any> = { - deps: match.loaderDeps, - params: match.params, - context: parentContext ?? {}, - location: router.state.location, - navigate: (opts: any) => - router.navigate({ - ...opts, - _fromLocation: router.state.location, - }), - buildLocation: router.buildLocation, - cause: match.cause, - abortController: match.abortController, - preload: false, - matches, - } - match.__routeContext = - route.options.context(contextFnContext) ?? undefined - } + // Rebuild route context using the same semantics as in matchRoutes + const baseContext = { + ...(parentContext ?? {}), + ...(match.__routeContext ?? {}), + ...(match.__beforeLoadContext ?? {}), + } + + if (route.options.context) { + const contextFnContext: RouteContextOptions<any, any, any, any> = { + search: match.search, + params: match.params, + context: baseContext, + location: router.state.location, + navigate: (opts: any) => + router.navigate({ + ...opts, + _fromLocation: router.state.location, + }), + buildLocation: router.buildLocation, + cause: match.cause, + abortController: match.abortController, + preload: false, + matches, + deps: match.loaderDeps, + } + match.__routeContext = + route.options.context?.(contextFnContext) ?? {} + }(Exact fields/types can be tuned to match current core APIs.)
This keeps SSR hydration’s context behavior in lockstep with the main router’s route-matching pipeline.
234-246: Preserve full NotFound error object instead of replacing with{ isNotFound: true }In the NotFound branch:
if (isNotFound(err)) { match.error = { isNotFound: true } // ... }you discard useful properties from the original
NotFoundError(routeId,data,headers, etc.), which other parts of the system (e.g.CatchNotFoundfallbacks that inspecterror.routeId) may rely on. (app.unpkg.com)To keep behavior consistent with the rest of the router, consider:
- if (isNotFound(err)) { - match.error = { isNotFound: true } + if (isNotFound(err)) { + match.error = err as any console.error( `NotFound error during hydration for routeId: ${match.routeId}`, err, )This still tags the error as not-found (via its
isNotFoundflag) but preserves any additional metadata.📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between cdf1237731ca06379b62ae617b9724683d9bbd73 and 8f450d5a0c831caf9c843fc86ab5b771e5f429f1.
📒 Files selected for processing (1)
packages/router-core/src/ssr/ssr-client.ts(2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5732 File: packages/start-client-core/src/client/hydrateStart.ts:6-9 Timestamp: 2025-11-02T16:16:24.898Z Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.Applied to files:
packages/router-core/src/ssr/ssr-client.ts
📚 Learning: 2025-09-28T21:41:45.233Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5284 File: e2e/react-start/basic/server.js:50-0 Timestamp: 2025-09-28T21:41:45.233Z Learning: In Express v5, catch-all routes must use named wildcards. Use `/*splat` to match everything except root path, or `/{*splat}` (with braces) to match including root path. The old `*` syntax is not allowed and will cause "Missing parameter name" errors. This breaking change requires explicit naming of wildcard parameters.Applied to files:
packages/router-core/src/ssr/ssr-client.ts
🧬 Code graph analysis (1)
packages/router-core/src/ssr/ssr-client.ts (1)
packages/router-core/src/route.ts (1)
RouteContextOptions(1075-1083)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Test
- GitHub Check: Preview
🔇 Additional comments (3)
packages/router-core/src/ssr/ssr-client.ts (3)
2-2: Import ofisNotFoundis appropriate and scoped correctlyThe new
isNotFoundimport matches its usage in the per‑match hydration error handling below and keeps SSR‑client logic aligned with core not‑found semantics.
218-233: Per-match head/scripts hydration and error isolation look solidRunning
head()andscripts()per match with an asset context of{ matches, match, params, loaderData }matches the documentedRouteOptions.head/scriptssignatures and ensures failures stay scoped to a single match instead of aborting the whole hydration pass. (tanstack.com)No issues here beyond the context-merging concerns already noted.
212-216: Review comment is factually incorrect about JavaScript runtime behaviorThe core claim in the review comment is wrong. Spreading
undefinedin JavaScript does not throw aTypeError; it produces an empty object{}. This was confirmed by runtime testing.Additionally, the same spread pattern with potentially undefined values exists throughout the codebase (e.g., router.ts lines 1495-1498 with
getParentContext()), and thegetParentContext()function itself explicitly returns potentially undefined values (router.ts line 1300). If this were truly a runtime error, router.ts would already be crashing.The code at ssr-client.ts lines 212-216 works as-is without the suggested nullish coalescing fix.
Likely an incorrect or invalid review comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
packages/router-core/tests/hydrate.test.ts (1)
48-48: Verify theisServer: trueflag for client hydration tests.The router is created with
isServer: true, which contradicts the client-side hydration scenario being tested. Consider usingisServer: falseor omitting this flag to accurately reflect the client environment.🧹 Nitpick comments (2)
packages/router-core/tests/hydrate.test.ts (2)
217-264: Add test coverage for non-NotFound error rethrow behavior.The current test verifies NotFound error handling, but the
hydratefunction also rethrows non-NotFound errors (seessr-client.tslines 272-278). Add a test case that verifies when a non-NotFound error is thrown during head/scripts execution, it propagates correctly after being logged.Example test structure:
it('should rethrow non-NotFound errors during route context hydration', async () => { const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {}) const testError = new Error('Unexpected error') mockHead.mockImplementation(() => { throw testError }) const mockMatches = [ { id: '/', routeId: '/', index: 0, ssr: true, _nonReactive: {} }, ] mockRouter.matchRoutes = vi.fn().mockReturnValue(mockMatches) mockRouter.state.matches = mockMatches mockWindow.$_TSR = { router: { manifest: { routes: {} }, dehydratedData: {}, lastMatchId: '/', matches: [ { i: '/', l: { data: 'test' }, s: 'success', ssr: true, u: Date.now(), }, ], }, c: vi.fn(), p: vi.fn(), buffer: [], initialized: false, } await expect(hydrate(mockRouter)).rejects.toThrow('Unexpected error') expect(consoleSpy).toHaveBeenCalledWith( 'Error during hydration for route /:', testError, ) consoleSpy.mockRestore() })
13-265: Consider expanding test coverage for additional hydration scenarios.While the existing tests cover core functionality well, several code paths in
hydrateremain untested:- CSP nonce extraction from meta tags
- Route chunk loading promises
minPendingPromiseand_forcePendingbehavior for pending routes- Custom
router.options.hydratecallback execution - SPA mode detection and special handling
- Route context reconstruction with parent context merging
Adding tests for these scenarios would improve confidence in the hydration logic, particularly for edge cases like SPA mode transitions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 56819effccf0e8b56d79ef0a93f1374bed7f821d and b4383214cd6e41e6c94b5e27691d6199cded7575.
📒 Files selected for processing (1)
packages/router-core/tests/hydrate.test.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
packages/router-core/tests/hydrate.test.ts
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5732 File: packages/start-client-core/src/client/hydrateStart.ts:6-9 Timestamp: 2025-11-02T16:16:24.898Z Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.Applied to files:
packages/router-core/tests/hydrate.test.ts
📚 Learning: 2025-10-01T18:30:26.591Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: packages/router-core/src/router.ts:2231-2245 Timestamp: 2025-10-01T18:30:26.591Z Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.Applied to files:
packages/router-core/tests/hydrate.test.ts
🧬 Code graph analysis (1)
packages/router-core/tests/hydrate.test.ts (1)
packages/router-core/src/ssr/ssr-client.ts (2)
TsrSsrGlobal(19-34)hydrate(65-307)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: autofix
- GitHub Check: Test
- GitHub Check: Preview
Actionable comments posted: 0
♻️ Duplicate comments (1)
packages/react-router/tests/hydrate.test.ts (1)
48-48: Verify theisServer: trueflag for this hydrate test routerHydration is a client-side concern; creating the router with
isServer: truemay exercise server-mode behavior and diverge from real client usage unless this is intentional.- mockRouter = createRouter({ routeTree, history, isServer: true }) + mockRouter = createRouter({ routeTree, history })#!/bin/bash # Inspect other hydrate tests and router configurations for consistency rg -n "hydrate\(" packages -S rg -n "isServer:\s*true" packages/react-router/tests -S🧹 Nitpick comments (3)
packages/react-router/tests/hydrate.test.ts (3)
18-54: Avoid deletingglobal.windowto keep the test environment reusablebeforeEachoverwritesglobal.windowandafterEachdeletes it, which can interfere with other suites (especially if Vitest runs with a jsdom environment). Safer is to capture the previous value and restore it instead of always deleting the property.- let mockWindow: { $_TSR?: TsrSsrGlobal } + let mockWindow: { $_TSR?: TsrSsrGlobal } + let originalWindow: any @@ - beforeEach(() => { - // Reset global window mock - mockWindow = {} - ;(global as any).window = mockWindow + beforeEach(() => { + // Reset global window mock and preserve any existing window + originalWindow = (global as any).window + mockWindow = {} + ;(global as any).window = mockWindow @@ - afterEach(() => { - vi.resetAllMocks() - delete (global as any).window - }) + afterEach(() => { + vi.resetAllMocks() + if (originalWindow !== undefined) { + ;(global as any).window = originalWindow + } else { + delete (global as any).window + } + })
76-140: Optional: assert buffer clearing /hydratedflag for stronger adapter coverageIf
hydrateis expected to clearbufferand/or setwindow.$_TSR.hydrated = true, adding assertions for that behavior in these adapter tests would tighten regression coverage; otherwise this block looks good.
217-264: Consider loosening the assertion on the exact log messageThe NotFound/head test correctly checks that errors are caught,
match.erroris set, andconsole.erroris invoked. To reduce brittleness if the log text ever changes slightly, you could assert with a partial match (e.g.expect.stringContaining('NotFound error during hydration')) instead of the full literal.📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between b4383214cd6e41e6c94b5e27691d6199cded7575 and 52cb3e0d6165b28294cf6dfd0bf0a10a9779b5e6.
📒 Files selected for processing (1)
packages/react-router/tests/hydrate.test.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
packages/react-router/tests/hydrate.test.ts
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5732 File: packages/start-client-core/src/client/hydrateStart.ts:6-9 Timestamp: 2025-11-02T16:16:24.898Z Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.Applied to files:
packages/react-router/tests/hydrate.test.ts
📚 Learning: 2025-10-01T18:30:26.591Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: packages/router-core/src/router.ts:2231-2245 Timestamp: 2025-10-01T18:30:26.591Z Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.Applied to files:
packages/react-router/tests/hydrate.test.ts
🧬 Code graph analysis (1)
packages/react-router/tests/hydrate.test.ts (1)
packages/router-core/src/ssr/ssr-client.ts (1)
TsrSsrGlobal(19-34)
🔇 Additional comments (2)
packages/react-router/tests/hydrate.test.ts (2)
56-75: Negative-path coverage for missing SSR bootstrap data looks solidThe first two tests clearly exercise the failure modes when
window.$_TSRorwindow.$_TSR.routerare absent and pin the expected error messages; no issues here.
142-162: Manifest propagation test correctly guardsrouter.ssr.manifestAsserting that
router.ssrmirrors the manifest fromwindow.$_TSR.router.manifestdirectly targets the SSR bootstrap contract; this test looks accurate and sufficient.Actionable comments posted: 1
♻️ Duplicate comments (1)
packages/react-router/tests/hydrate.test.ts (1)
18-49: ReconsiderisServer: truefor a client hydration test routerThe router used for
hydrateis created withisServer: true, even thoughhydraterepresents client-side hydration behavior. This mirrors a concern already raised in the router-core hydrate tests: server-mode configuration may subtly diverge from real client behavior or hit server-only branches.Unless you’re intentionally validating server-mode hydration, consider dropping the flag or using
isServer: falseto better reflect the client environment:- mockRouter = createRouter({ routeTree, history, isServer: true }) + mockRouter = createRouter({ routeTree, history }) + // or: createRouter({ routeTree, history, isServer: false })🧹 Nitpick comments (2)
packages/react-router/tests/hydrate.test.ts (1)
1-11: Fix import order to satisfy ESLintimport/orderruleThe static analysis hint is correct: the import from
@tanstack/router-core/ssr/clientshould be grouped with external deps before the internal../srcimport.You can fix this with a small reorder:
-import { - createMemoryHistory, - createRootRoute, - createRoute, - createRouter, - notFound, -} from '../src' -import { hydrate } from '@tanstack/router-core/ssr/client' -import type { TsrSsrGlobal } from '@tanstack/router-core/ssr/client' +import { hydrate } from '@tanstack/router-core/ssr/client' +import { + createMemoryHistory, + createRootRoute, + createRoute, + createRouter, + notFound, +} from '../src' +import type { TsrSsrGlobal } from '@tanstack/router-core/ssr/client' import type { AnyRouteMatch } from '../src'packages/solid-router/tests/hydrate.test.ts (1)
217-264: Nice NotFound hydration coverage; consider small reuse helperThe NotFound test both marks the match with
error.isNotFoundand asserts theconsole.errorsignature, which tightly guards the new behavior. The repeated construction ofmockWindow.$_TSRacross tests could optionally be factored into a small helper (e.g.,createTsr(routerOverrides)), but that’s purely for readability.📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 424fe830dab71a5d000614b2266538c84917ffff and aa6ce570cec8c27b322dc8b104462ddd2ed42d4b.
📒 Files selected for processing (2)
packages/react-router/tests/hydrate.test.ts(1 hunks)packages/solid-router/tests/hydrate.test.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
packages/solid-router/tests/hydrate.test.tspackages/react-router/tests/hydrate.test.ts
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5732 File: packages/start-client-core/src/client/hydrateStart.ts:6-9 Timestamp: 2025-11-02T16:16:24.898Z Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.Applied to files:
packages/solid-router/tests/hydrate.test.tspackages/react-router/tests/hydrate.test.ts
📚 Learning: 2025-10-01T18:30:26.591Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: packages/router-core/src/router.ts:2231-2245 Timestamp: 2025-10-01T18:30:26.591Z Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.Applied to files:
packages/react-router/tests/hydrate.test.ts
🧬 Code graph analysis (2)
packages/solid-router/tests/hydrate.test.ts (1)
packages/router-core/src/ssr/ssr-client.ts (1)
TsrSsrGlobal(19-34)
packages/react-router/tests/hydrate.test.ts (1)
packages/router-core/src/ssr/ssr-client.ts (1)
TsrSsrGlobal(19-34)
🪛 ESLint
packages/solid-router/tests/hydrate.test.ts
[error] 9-9:
@tanstack/router-core/ssr/clientimport should occur before import of../src(import/order)
packages/react-router/tests/hydrate.test.ts
[error] 9-9:
@tanstack/router-core/ssr/clientimport should occur before import of../src(import/order)
🔇 Additional comments (4)
packages/react-router/tests/hydrate.test.ts (1)
217-264: Strong coverage of NotFound errors during hydrationThis test nicely exercises the new per-match error handling by forcing
headto thrownotFound(), asserting the error is attached to the match and that a clearconsole.errorlog is emitted. It should help prevent regressions where NotFound errors bubble and break hydration.packages/solid-router/tests/hydrate.test.ts (3)
18-55: Global window mocking and router setup look solidThe
beforeEach/afterEachcorrectly isolateglobal.window, mocks, and router state per test, which should avoid cross-test leakage.
76-140: Good coverage of serialization adapter initializationThe tests for non-empty vs empty
serializationAdaptersvalidate the adapter registry (tmap), buffer flushing, andinitializedflag behavior in a focused way; this should catch regressions in the SSR client initialization path.
142-215: Match hydration test aligns with dehydrated shapeThe
dehydratedMatches→AnyRouteMatchexpectations forloaderData,status, andssrlook consistent with the compact match format and give good assurance that hydration wires up per-match state correctly.@@ -0,0 +1,11 @@1+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'2+import {3+ createMemoryHistory,4+ createRootRoute,5+ createRoute,6+ createRouter,7+ notFound,8+} from '../src'9+import { hydrate } from '@tanstack/router-core/ssr/client'10+import type { TsrSsrGlobal } from '@tanstack/router-core/ssr/client'11+import type { AnyRouteMatch } from '../src'⚠️ Potential issue | 🟠 Major
Fix import order to satisfy ESLint
import/orderESLint wants external imports before internal ones. You can also fold the type import from
../srcinto the same statement to avoid duplicate imports.-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { - createMemoryHistory, - createRootRoute, - createRoute, - createRouter, - notFound, -} from '../src' -import { hydrate } from '@tanstack/router-core/ssr/client' -import type { TsrSsrGlobal } from '@tanstack/router-core/ssr/client' -import type { AnyRouteMatch } from '../src' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { hydrate } from '@tanstack/router-core/ssr/client' +import type { TsrSsrGlobal } from '@tanstack/router-core/ssr/client' +import { + createMemoryHistory, + createRootRoute, + createRoute, + createRouter, + notFound, + type AnyRouteMatch, +} from '../src'📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { hydrate } from '@tanstack/router-core/ssr/client' import type { TsrSsrGlobal } from '@tanstack/router-core/ssr/client' import { createMemoryHistory, createRootRoute, createRoute, createRouter, notFound, type AnyRouteMatch, } from '../src'🧰 Tools
🪛 ESLint
[error] 9-9:
@tanstack/router-core/ssr/clientimport should occur before import of../src(import/order)
🤖 Prompt for AI Agents
In packages/solid-router/tests/hydrate.test.ts around lines 1 to 11, the import order violates ESLint import/order and duplicates imports from ../src; reorder imports so all external packages (vitest, @tanstack/router-core/ssr/client) come before internal project imports, and merge the type import from ../src into the same import statement that brings in runtime exports (createMemoryHistory, createRootRoute, etc.) to eliminate the duplicate import line and satisfy the linter.✅ Addressed in commit 7aa3bb5
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/solid-router/tests/hydrate.test.ts (1)
1-11: Consider fixing remaining ESLint import violations.ESLint still flags three formatting issues:
- Import order:
../srcshould come before the type-only import from@tanstack/router-core/ssr/client - Sort order:
AnyRouteMatchshould be sorted alphabetically within the import list - Type specifier style: Prefer a top-level
import typestatement instead of inlinetype AnyRouteMatch
While these don't affect functionality, addressing them would satisfy the linter.
Apply this diff to resolve all three issues:
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { hydrate } from '@tanstack/router-core/ssr/client' -import type { TsrSsrGlobal } from '@tanstack/router-core/ssr/client' import { + type AnyRouteMatch, createMemoryHistory, createRootRoute, createRoute, createRouter, notFound, - type AnyRouteMatch, } from '../src' +import { hydrate } from '@tanstack/router-core/ssr/client' +import type { TsrSsrGlobal } from '@tanstack/router-core/ssr/client'📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between aa6ce570cec8c27b322dc8b104462ddd2ed42d4b and c6525e64df9bba9609cbf40ef7f30d3e3bc0dc4b.
📒 Files selected for processing (2)
e2e/solid-start/basic/vite.config.ts(1 hunks)packages/solid-router/tests/hydrate.test.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-10-01T18:31:35.420Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: e2e/react-start/custom-basepath/src/routeTree.gen.ts:58-61 Timestamp: 2025-10-01T18:31:35.420Z Learning: Do not review files named `routeTree.gen.ts` in TanStack Router repositories, as these are autogenerated files that should not be manually modified.Applied to files:
e2e/solid-start/basic/vite.config.ts
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
packages/solid-router/tests/hydrate.test.ts
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5732 File: packages/start-client-core/src/client/hydrateStart.ts:6-9 Timestamp: 2025-11-02T16:16:24.898Z Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.Applied to files:
packages/solid-router/tests/hydrate.test.ts
🧬 Code graph analysis (1)
packages/solid-router/tests/hydrate.test.ts (1)
packages/router-core/src/ssr/ssr-client.ts (1)
TsrSsrGlobal(19-34)
🪛 ESLint
packages/solid-router/tests/hydrate.test.ts
[error] 4-11:
../srcimport should occur before type import of@tanstack/router-core/ssr/client(import/order)
[error] 10-10: Member 'AnyRouteMatch' of the import declaration should be sorted alphabetically.
(sort-imports)
[error] 10-10: Prefer using a top-level type-only import instead of inline type specifiers.
(import/consistent-type-specifier-style)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Test
🔇 Additional comments (4)
e2e/solid-start/basic/vite.config.ts (1)
23-23: LGTM! Correct exclusion of the new not-found route from prerendering.The addition of
'/not-found/via-head'to the prerender exclusion list is appropriate since this route throwsnotFound()in its head function. This is consistent with the exclusion of similar routes like/not-found/via-beforeLoadand/not-found/via-loader.packages/solid-router/tests/hydrate.test.ts (3)
56-215: Excellent test coverage for core hydration scenarios.These test cases comprehensively validate:
- Error handling for missing bootstrap data
- Serialization adapter initialization and mapping
- Manifest propagation
- Match hydration with correct data, status, and SSR flags
The test logic is sound, assertions are precise, and mock setup is appropriate for each scenario.
217-264: Strong validation of NotFound error handling during hydration.This test case directly addresses the PR objective by validating that:
- Errors thrown during route context hydration (specifically
notFound()fromhead()) are caught - The error is properly marked on the match as
{ isNotFound: true } - Diagnostic logging occurs via
console.error
The test setup correctly simulates the error condition, and the assertions verify both the error capture and logging behavior. This is a critical test for ensuring graceful error handling during SSR hydration.
48-48: No issue found. TheisServer: trueflag is correct for hydration tests.The router is intentionally initialized in server mode because hydration tests simulate the real SSR→client flow: a server-rendered router (with
isServer: true) transitions to client-side hydration via thehydrate()function. The tests verify this hydration mechanism works correctly by mocking the dehydrated SSR state and confirming the hydration process succeeds. This setup is consistent across both React and Solid router test suites and is the standard pattern for SSR hydration testing.- Import order:
Actionable comments posted: 0
♻️ Duplicate comments (1)
packages/react-router/tests/hydrate.test.ts (1)
13-55: Solid test harness; reconsiderisServer: truefor a client hydration scenario.The in-memory history, route tree, and window mocking look good and isolate the hydrate behavior nicely. The one question mark is:
- mockRouter = createRouter({ routeTree, history, isServer: true }) + mockRouter = createRouter({ routeTree, history }) + // or: createRouter({ routeTree, history, isServer: false })For SSR client hydration, the router is usually created in client mode; keeping
isServer: truemay hit server-only branches or subtly change behavior. If the intent is to simulate the browser-side hydrate, it’s worth double‑checking this flag (same concern as noted previously in the core hydrate tests).🧹 Nitpick comments (2)
packages/solid-router/tests/hydrate.test.ts (2)
164-215: Consider clarifying the partial hydration scenario.The test sets up two
mockMatchesbut only onedehydratedMatch. While the test correctly verifies that the first match is hydrated, it's unclear whether the second match's behavior (presumably remaining unhydrated) is intentional or incidental. Consider adding an assertion or comment to clarify the expected behavior for routes without corresponding dehydrated data.Example assertion for the second match:
const secondMatch = mockMatches[1] as AnyRouteMatch expect(secondMatch.loaderData).toBeUndefined() expect(secondMatch.ssr).toBeUndefined()
13-265: Optional: Consider additional error scenario coverage.The current test suite provides excellent coverage of the happy path and NotFound errors. For even more robust error handling, consider adding tests for:
- Non-NotFound errors thrown during hydration (to verify they're handled differently)
- Multiple matches encountering errors simultaneously
- Errors from other route lifecycle hooks beyond
head
These additions would further strengthen confidence in the error handling, but may be deferred if they're outside the scope of this PR's NotFound focus.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between c6525e64df9bba9609cbf40ef7f30d3e3bc0dc4b and dad79febdba715c1bdb1e30c28daa3c34fe41e10.
📒 Files selected for processing (2)
packages/react-router/tests/hydrate.test.ts(1 hunks)packages/solid-router/tests/hydrate.test.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
packages/react-router/tests/hydrate.test.tspackages/solid-router/tests/hydrate.test.ts
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5732 File: packages/start-client-core/src/client/hydrateStart.ts:6-9 Timestamp: 2025-11-02T16:16:24.898Z Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.Applied to files:
packages/react-router/tests/hydrate.test.tspackages/solid-router/tests/hydrate.test.ts
📚 Learning: 2025-10-01T18:30:26.591Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: packages/router-core/src/router.ts:2231-2245 Timestamp: 2025-10-01T18:30:26.591Z Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.Applied to files:
packages/react-router/tests/hydrate.test.ts
📚 Learning: 2025-10-14T18:59:33.990Z
Learnt from: FatahChan Repo: TanStack/router PR: 5475 File: e2e/react-start/basic-prerendering/src/routes/redirect/$target/via-beforeLoad.tsx:8-0 Timestamp: 2025-10-14T18:59:33.990Z Learning: In TanStack Router e2e test files, when a route parameter is validated at the route level (e.g., using zod in validateSearch or param validation), switch statements on that parameter do not require a default case, as the validation ensures only expected values will reach the switch.Applied to files:
packages/solid-router/tests/hydrate.test.ts
🧬 Code graph analysis (2)
packages/react-router/tests/hydrate.test.ts (1)
packages/router-core/src/ssr/ssr-client.ts (1)
TsrSsrGlobal(19-34)
packages/solid-router/tests/hydrate.test.ts (1)
packages/router-core/src/ssr/ssr-client.ts (1)
TsrSsrGlobal(19-34)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Test
- GitHub Check: Preview
🔇 Additional comments (12)
packages/react-router/tests/hydrate.test.ts (7)
56-60: Good coverage for missing bootstrap data onwindow.$_TSR.This test clearly asserts that hydrate fails with the expected error when no SSR bootstrap data is present, which is an important guardrail.
62-74: Good negative test for missingwindow.$_TSR.router.The shape of the mocked
$ _TSRmatches the client contract, and the expectation on the specific error message for a missingrouterfield is precise and valuable.
76-118: Well-structured test for serialization adapter initialization and buffer flushing.The adapter mock matches the expected interface, the router is wired with
serializationAdapters, and the assertions thattis aMap, that it holdsfromSerializableunder the adapter key, that the buffer callbacks are invoked, and thatinitializedis set totruecollectively validate the key responsibilities of the hydrate path.
120-140: Clear behavior definition for the “no adapters” case.Verifying that
tremainsundefinedwhileinitializedstill flips totruedocuments the intended contract when no serialization adapters are configured, which will prevent regressions in this edge case.
142-162: Accurate assertion that manifest is surfaced viarouter.ssr.Seeding
window.$_TSR.router.manifestand asserting that hydrate stores it onmockRouter.ssr.manifestcleanly specifies how SSR metadata should be exposed on the client router. This is concise and correct.
164-215: Good verification that dehydrated match data is applied to route matches.The test neatly wires
matchRoutes, seeds dehydrated matches on$ _TSR.router.matches, and then asserts that the first match receivesloaderData,status, andssrfrom the dehydrated payload while preserving itsid. This gives strong confidence that per-match state hydration behaves as intended.
217-264: Effective test of NotFound handling during route context hydration.By having
headthrownotFound(), then asserting thatmatch.erroris normalized to{ isNotFound: true }and that a descriptiveconsole.errorlog is emitted with the routeId and error payload, this test nails the new error-handling behavior and ensures NotFound during hydration is captured locally instead of crashing the whole pipeline.packages/solid-router/tests/hydrate.test.ts (5)
56-74: LGTM! Comprehensive error guard tests.These tests properly verify that the hydration process fails fast with clear error messages when required bootstrap data is missing. The error messages appropriately guide users to file an issue, which is good for debugging unexpected scenarios.
76-140: LGTM! Thorough serialization adapter tests.Excellent coverage of both the standard initialization path (with adapters) and the edge case (empty adapters). The tests verify all key aspects: transformer map creation, adapter registration, buffer execution, and the initialized flag. The separation into two distinct test cases makes the intent clear.
142-162: LGTM! Clear manifest propagation test.This test correctly verifies that the manifest data from the dehydrated router state is properly transferred to the router's SSR property, which is essential for SSR/hydration coordination.
217-264: LGTM! Critical NotFound error handling test.This test directly addresses the core objective of this PR: catching and handling NotFound errors thrown during hydration. The test comprehensively verifies:
- Errors thrown from route
headfunctions are caught during hydration - The error is properly attached to the match with
isNotFound: true - Appropriate debugging information is logged to console.error
- The hydration process continues gracefully instead of crashing
The mock setup and cleanup are handled correctly, ensuring no side effects.
48-48: Need to check the actual test file more carefully to understand the hydrate function and verify the isServer flag usage. Let me search the codebase directly.Based on my verification through code analysis and web search, I found that the router incorrectly identifies whether it's running on server based on
documentavailability, andisServercan be explicitly set to control this. The test setup withisServer: trueis intentionally creating a server-side router context, which is then passed to thehydrate()function to simulate the SSR-to-client transition.Looking at the SSR documentation, on the client Router defaults to
createBrowserHistory, while on the server it usescreateMemoryHistory. The tests usecreateMemoryHistorywithisServer: true, which correctly simulates a server-rendered router that will be hydrated on the client. This is the correct pattern for testing hydration functionality—the router is created in server mode, then thehydrate()function processes the dehydrated state for client-side restoration.The
isServer: trueflag in the hydration tests is correct and intentional. It properly simulates the SSR server context before client-side hydration occurs. No changes are needed.birkskyum(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Walkthrough#
Adds a new file route
/not-found/via-headfor React and Solid (itsheadthrowsnotFound()), updates generated route trees and not-found UIs, extends e2e tests and prerender excludes, and changes SSR client hydration to compute per-match contexts/assets and handle NotFound errors locally.Changes#
e2e/react-start/basic/src/routeTree.gen.ts,e2e/react-start/basic/src/routes/not-found/via-head.tsx,e2e/react-start/basic/src/routes/not-found/index.tsx/not-found/via-headfile route (Route withheadthat throwsnotFound(),component, andnotFoundComponent); register route in generated route tree and add aLinkin not-found index.e2e/react-start/basic/tests/not-found.spec.ts,e2e/react-start/basic/vite.config.tsheadstage (navigation and direct visit), add whitelist entry for NotFound hydration logs, and add/not-found/via-headto prerender exclude list.e2e/solid-start/basic/src/routeTree.gen.ts,e2e/solid-start/basic/src/routes/not-found/via-head.tsx,e2e/solid-start/basic/src/routes/not-found/index.tsx/not-found/via-headfile route for Solid (head throwsnotFound()), register it in generated route tree and add aLinkin not-found index.e2e/solid-start/basic/tests/not-found.spec.ts,e2e/solid-start/basic/vite.config.tsheadstage and whitelist NotFound hydration logs; add/not-found/via-headto prerender exclusion.packages/router-core/src/ssr/ssr-client.tsisNotFound; compute per-route__routeContextand merge with parent/beforeLoad contexts; buildassetContextto evaluatehead/scriptsand assign meta/links/scripts/styles to match; marknotFound()as NotFound on match (log) and rethrow other errors.packages/react-router/tests/hydrate.test.ts,packages/solid-router/tests/hydrate.test.tsSequence Diagram(s)#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~25 minutes
packages/router-core/src/ssr/ssr-client.ts— per-match try/catch,isNotFoundhandling, merge order of contexts, and asset/head/scripts evaluation.packages/react-router/tests/hydrate.test.ts,packages/solid-router/tests/hydrate.test.ts) — verify mocks/spies and assertions.routeTree.gen.tsupdates for React and Solid — verify ids/paths, parent links, and type augmentations.via-head.tsx) — ensureheadbehavior and test data-testid strings match tests.Possibly related PRs#
/not-found/via-headto prerender excludes.Suggested labels#
ssrSuggested reviewers#
Poem#
Pre-merge checks and finishing touches#
❌ Failed checks (1 warning)
@coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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