Skip to content

fix(router-core): fix search middleware type to use schema output#7381

Open
sprusr wants to merge 1 commit into
TanStack:mainfrom
sprusr:main
Open

fix(router-core): fix search middleware type to use schema output#7381
sprusr wants to merge 1 commit into
TanStack:mainfrom
sprusr:main

Conversation

@sprusr
Copy link
Copy Markdown

@sprusr sprusr commented May 11, 2026

Summary

The type for search passed to a route's search middleware is currently set to the input of whatever is passed to validateSearch. In reality this value is the output of the search validator.

In the majority of cases these types are the same, but it becomes a pronounced issue with asymmetric schemas, for example with Zod codecs:

// input is number, output is BigInt
const numberToBigInt = z.codec(z.int(), z.bigint(), {
  decode: (num) => BigInt(num),
  encode: (bigint) => Number(bigint),
});

const searchSchema = z.object({
  codec: numberToBigInt.optional(),
})

The value that we get in the search middleware is a BigInt but it's typed as a number.

Changes

Simple switch from ResolveFullSearchSchemaInput to ResolveFullSearchSchema.

Reproduction

You can find here a small TanStack Start project with a demo of the mismatch: https://github.com/sprusr/tanstack-router-search-middleware-types

Summary by CodeRabbit

  • Refactor
    • Updated the type definitions for search middleware configuration to align with the resolved search schema structure. This change affects how middleware functions receive and process search parameters in routes.

Review Change Stack

@github-actions
Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: b1c061aff918
  • Measured at: 2026-05-11T16:48:47.955Z
  • Baseline source: history:b1c061aff918
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 87.29 KiB 0 B (0.00%) 87.15 KiB 274.07 KiB 75.85 KiB ▁▁▁▁▁▁▁▁▁██
react-router.full 90.82 KiB 0 B (0.00%) 90.68 KiB 285.58 KiB 78.89 KiB ▁▁▁▁▁▁▁▁▁██
solid-router.minimal 35.51 KiB 0 B (0.00%) 35.39 KiB 106.36 KiB 31.97 KiB ▁▁▁▁▁▁▁▁▁██
solid-router.full 40.23 KiB 0 B (0.00%) 40.10 KiB 120.58 KiB 36.14 KiB ▁▁▁▁▁▁▁▁▁██
vue-router.minimal 53.29 KiB 0 B (0.00%) 53.15 KiB 151.51 KiB 47.85 KiB ▁▁▁▁▁▁▁▁▁██
vue-router.full 58.41 KiB 0 B (0.00%) 58.28 KiB 167.69 KiB 52.39 KiB ▁▁▁▁▁▁▁▁▁██
react-start.minimal 101.97 KiB 0 B (0.00%) 101.83 KiB 322.51 KiB 88.17 KiB ▁▁▁▁▁▁▁▁▃██
react-start.full 105.41 KiB 0 B (0.00%) 105.27 KiB 332.84 KiB 91.19 KiB ▁▁▁▁▁▁▁▁▄██
react-start.rsbuild.minimal 99.60 KiB 0 B (0.00%) 99.43 KiB 316.97 KiB 85.64 KiB ▁▁▁▁▁▁▁▁▄██
react-start.rsbuild.full 102.89 KiB 0 B (0.00%) 102.72 KiB 327.41 KiB 88.45 KiB ▁▁▁▁▁▁▁▁▃██
solid-start.minimal 49.61 KiB 0 B (0.00%) 49.48 KiB 152.48 KiB 43.78 KiB ▁▁▁▁▁▁▁▁▄██
solid-start.full 55.40 KiB 0 B (0.00%) 55.27 KiB 169.39 KiB 48.72 KiB ▁▁▁▁▁▁▁▁▄██

Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 418768e3-9988-440e-856e-a2dc87c7b4d1

📥 Commits

Reviewing files that changed from the base of the PR and between b1c061a and 60d6382.

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

📝 Walkthrough

Walkthrough

The type of search middlewares in UpdatableRouteOptions was updated to use the resolved full search schema output type rather than the input type. The generic parameter passed to SearchMiddleware now references ResolveFullSearchSchema instead of ResolveFullSearchSchemaInput, changing what input/output shape middleware functions expect.

Changes

Search Middleware Type Update

Layer / File(s) Summary
Search Middleware Type Annotation
packages/router-core/src/route.ts
UpdatableRouteOptions.search.middlewares now types SearchMiddleware against ResolveFullSearchSchema (output type) instead of ResolveFullSearchSchemaInput (input type).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A type flows through the router's core,
From input shape to output lore,
The middleware now sees the final light,
Resolved schemas shining oh so bright!
One line of change, precise and clear,
TypeScript whispers in the ear.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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: fixing the search middleware type to use schema output instead of input, which matches the core TypeScript typing fix in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

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

@sprusr
Copy link
Copy Markdown
Author

sprusr commented May 11, 2026

Long time TanStack Router fan, first time contributor. I spent a bit of time validating my theory with this one, so hopefully haven't jumped to the wrong conclusion.

As an aside, I would love to see more comprehensive support of asymmetrical schemas particularly when it comes to search params. An example use case: I'm unhappy with the appearance of how arrays of strings are encoded in the url by default, and would prefer to have them as space-separated values - being able to do this with Zod codecs would be wonderful (I am already, but it relies on own middleware).

@sprusr
Copy link
Copy Markdown
Author

sprusr commented May 11, 2026

In fact if maintainers agree with conclusions here then I think buildLocation has wrong sided types too, which affects Link and navigate at least.

@schiller-manuel schiller-manuel requested a review from chorobin May 12, 2026 12:32
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