Skip to content

refactor(router-core): no validateSearch in buildLocation#6979

Open
Sheraff wants to merge 2 commits intomainfrom
refactor-router-core-no-search-validation-in-build-location
Open

refactor(router-core): no validateSearch in buildLocation#6979
Sheraff wants to merge 2 commits intomainfrom
refactor-router-core-no-search-validation-in-build-location

Conversation

@Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Mar 19, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Simplified search-parameter handling in lightweight route matching: the match now uses the URL's raw search string directly and no longer suppresses validation errors from route-level search validators.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2026

📝 Walkthrough

Walkthrough

The RouterCore.matchRoutesLightweight method no longer accumulates and validates search params across matched routes; the lightweight match now returns location.search directly instead of an iteratively validated accumulatedSearch.

Changes

Cohort / File(s) Summary
Search Validation Removal
packages/router-core/src/router.ts
Removed iterative construction and route-chain validateSearch calls (previously muted on error) from matchRoutesLightweight. The returned lightweight match sets search to location.search directly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I hopped through code, light on my paws,

I nudged the chain out without a cause,
Now searches travel straight and clear—
No whispered errors to overhear,
A simpler path, and cheer! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: removing validateSearch processing from the buildLocation/matchRoutesLightweight function, which aligns with the code summary showing removal of route-chain validateSearch and error-suppression logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor-router-core-no-search-validation-in-build-location
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Mar 19, 2026

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 9c41ff7

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ❌ Failed 15m 26s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 52s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-20 11:04:20 UTC

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Bundle Size Benchmarks

  • Commit: 21e39bde0832
  • Measured at: 2026-03-20T10:49:36.698Z
  • Baseline source: history:91cc62899b75
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Raw Brotli Trend
react-router.minimal 88.54 KiB -12 B (-0.01%) 279.26 KiB 76.88 KiB ▁▁▁▁▁▁▁▁████
react-router.full 91.70 KiB -30 B (-0.03%) 289.98 KiB 79.54 KiB ▁▁▁▁▁▁▁▁████
solid-router.minimal 36.09 KiB -35 B (-0.09%) 108.89 KiB 32.39 KiB ████████▁▁▁▁
solid-router.full 40.45 KiB -26 B (-0.06%) 121.99 KiB 36.20 KiB ████████▁▁▁▁
vue-router.minimal 54.09 KiB -21 B (-0.04%) 155.18 KiB 48.48 KiB ▁▁▁▁▁▁▁▁████
vue-router.full 58.87 KiB -18 B (-0.03%) 170.33 KiB 52.64 KiB ▁▁▁▁▁▁▁▁████
react-start.minimal 102.98 KiB -19 B (-0.02%) 327.32 KiB 88.96 KiB ▁▁▁▁▁▁▁▁████
react-start.full 106.35 KiB -15 B (-0.01%) 337.63 KiB 91.80 KiB ▁▁▁▁▁▁▁▁████
solid-start.minimal 50.28 KiB -45 B (-0.09%) 155.38 KiB 44.26 KiB ████████▁▁▁▁
solid-start.full 55.69 KiB -29 B (-0.05%) 171.18 KiB 48.96 KiB ████████▁▁▁▁

Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 19, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@6979

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@6979

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@6979

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@6979

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@6979

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@6979

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@6979

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@6979

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@6979

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@6979

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@6979

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@6979

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@6979

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@6979

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@6979

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@6979

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@6979

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@6979

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@6979

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@6979

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@6979

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@6979

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@6979

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@6979

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@6979

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@6979

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@6979

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@6979

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@6979

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@6979

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@6979

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@6979

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@6979

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@6979

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@6979

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@6979

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@6979

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@6979

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@6979

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@6979

commit: 9c41ff7

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b0af5ff06a

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

matchedRoutes,
fullPath: lastRoute.fullPath,
search: accumulatedSearch,
search: location.search,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep validated search when reusing current search

This drops the route-validated/defaulted search state whenever a caller preserves or updates the current search (search: true or search: prev => ...). buildLocation callers like the framework Link components (packages/react-router/src/link.tsx:418-419) and redirects (packages/router-core/src/router.ts:2711-2714) do not pass _includeValidateSearch, so they now see the raw parsed query instead of the validated one. In the redirect scenario covered by packages/react-router/tests/link.test.tsx:3948-4019, the callback should receive { postPage: 0 } from the current route's validateSearch, but after this change it receives {}, so links/redirects to routes that do not reintroduce the same validator lose existing defaulted params and generate the wrong URL/search state.

Useful? React with 👍 / 👎.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 19, 2026

Merging this PR will improve performance by 3.56%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 5 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
client-side navigation loop (react) 44.8 ms 43.2 ms +3.56%

Comparing refactor-router-core-no-search-validation-in-build-location (9c41ff7) with main (91cc628)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (21e39bd) during the generation of this report, so 91cc628 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/router-core/src/router.ts (1)

1693-1739: The change correctly removes search validation from lightweight matching, but the uncertain comment should be resolved.

The refactor to return location.search directly instead of validated search is consistent with the PR objective. This is a reasonable optimization since:

  1. The source location's search was already validated when that route was originally matched
  2. Destination route validation still occurs later in buildLocation when _includeValidateSearch is set (lines 1903-1921)

However, the comment on lines 1693-1694 expressing uncertainty ("I don't know if we should run the full search middleware chain, or just validateSearch") reads like an unresolved TODO rather than a design rationale. Consider either:

  • Rephrasing to document the deliberate decision (e.g., "We intentionally skip validation here because...")
  • Removing the commented-out code if this approach is confirmed
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/router-core/src/router.ts` around lines 1693 - 1739, Remove or
replace the uncertain TODO comment and commented-out code around the lightweight
match return to reflect the deliberate design: either delete the commented-out
applySearchMiddleware block and the "I don't know..." line, or replace it with a
concise explanatory comment such as "Intentionally skip full search middleware
here; source search was validated on original match and destination validation
runs in buildLocation via _includeValidateSearch." Reference the surrounding
symbols matchedRoutes, location.search, buildLocation, and
_includeValidateSearch to ensure the explanatory comment makes clear why
location.search is returned directly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/router-core/src/router.ts`:
- Around line 1693-1739: Remove or replace the uncertain TODO comment and
commented-out code around the lightweight match return to reflect the deliberate
design: either delete the commented-out applySearchMiddleware block and the "I
don't know..." line, or replace it with a concise explanatory comment such as
"Intentionally skip full search middleware here; source search was validated on
original match and destination validation runs in buildLocation via
_includeValidateSearch." Reference the surrounding symbols matchedRoutes,
location.search, buildLocation, and _includeValidateSearch to ensure the
explanatory comment makes clear why location.search is returned directly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 89a7fa96-5f4d-4784-92ef-0f043c553fdb

📥 Commits

Reviewing files that changed from the base of the PR and between b0af5ff and 9c41ff7.

📒 Files selected for processing (1)
  • packages/router-core/src/router.ts

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant