Skip to content

Conversation

@adbjo
Copy link

@adbjo adbjo commented Dec 1, 2025

The router adds quotes around numerical strings in search params, for example:
http://my-app.com?p=123 changes to http://my-app.com?p="123"

Maybe this is intentional, but seems a bit wonky to me, so here is a fix.

Summary by CodeRabbit

  • Bug Fixes

    • Preserve parsed objects during query parse/serialize cycles; when a parser doesn't return an object, original string/primitive values are left unchanged.
    • Stop auto-coercing query values to numbers/booleans — values remain raw strings, and repeated keys produce arrays of strings.
  • Tests

    • Update round-trip tests to validate parse-then-stringify behavior, ensuring consistent parsing and serialization outcomes.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 1, 2025

Walkthrough

Parse/stringify logic updated to avoid coercing or replacing raw string values unless a parser returns an object; qss decoding no longer coerces strings to booleans/numbers; tests updated to validate parse-first then stringify roundtrips.

Changes

Cohort / File(s) Summary
Search params logic
packages/router-core/src/searchParams.ts
parseSearchWith now assigns parser results only when the parser returns an object; stringifySearchWith only re-stringifies when the parser returns an object, otherwise original string values are preserved.
Query-string decoding
packages/router-core/src/qss.ts
Removed the toValue coercion helper; decode now returns raw string values (and arrays of raw strings) instead of coercing to numbers/booleans.
Tests
packages/router-core/tests/searchParams.test.ts, packages/router-core/tests/qss.test.ts
Tests updated to parse-first then stringify for isomorphism checks; expectations adjusted to reflect raw-string decoding and arrays for repeated keys.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Inspect searchParams.ts parser branches for cases where parsers return primitives vs objects.
  • Verify callers of qss.decode and any consumers expecting coerced numeric/boolean types.
  • Run unit tests covering repeated keys, empty values, escaped literals, and custom parsers.

Possibly related PRs

Suggested reviewers

  • schiller-manuel
  • SeanCassiere

Poem

"I hopped through queries, kept each string intact,
I nudged only objects where parsers interact.
Numbers no longer sneak into string beds,
Roundtrips hum softly as tests nod their heads.
— 🐇"

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and does not accurately reflect the changeset. The changes involve removing automatic type coercion of search params to primitives and ensuring parsers handle object returns, which is broader than just preventing quotes around numerical params. Consider a more specific title that captures the core change, such as 'fix: Remove automatic type coercion in search params parsing' or 'fix: Preserve string values in search params instead of coercing to primitives'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8ae18e and 04bd7ad.

📒 Files selected for processing (4)
  • packages/router-core/src/qss.ts (1 hunks)
  • packages/router-core/src/searchParams.ts (2 hunks)
  • packages/router-core/tests/qss.test.ts (1 hunks)
  • packages/router-core/tests/searchParams.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/router-core/src/searchParams.ts
  • packages/router-core/tests/searchParams.test.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript strict mode with extensive type safety throughout the codebase

Files:

  • packages/router-core/src/qss.ts
  • packages/router-core/tests/qss.test.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: nlynzaad
Repo: TanStack/router PR: 5182
File: e2e/react-router/basic-file-based/src/routes/non-nested/named/$baz_.bar.tsx:3-5
Timestamp: 2025-09-22T00:56:49.237Z
Learning: In TanStack Router, underscores are intentionally stripped from route segments (e.g., `$baz_` becomes `baz` in generated types) but should be preserved in base path segments. This is the correct behavior as of the fix in PR #5182.
📚 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/qss.test.ts
📚 Learning: 2025-11-25T00:18:21.282Z
Learnt from: CR
Repo: TanStack/router PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T00:18:21.282Z
Learning: Applies to packages/solid-router/**/*.{ts,tsx} : Solid Router components and primitives should use the tanstack/solid-router package

Applied to files:

  • packages/router-core/tests/qss.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/router-core/tests/qss.test.ts
🔇 Additional comments (2)
packages/router-core/tests/qss.test.ts (1)

61-65: LGTM! Test expectation correctly updated.

The test expectation has been correctly updated to expect a string '1' instead of a number 1, which aligns with the new decode behavior that preserves values as strings without coercion.

packages/router-core/src/qss.ts (1)

56-65: Verify that downstream code handles string values correctly.

The decode function now preserves all values as strings instead of coercing them to numbers or booleans. Ensure that code consuming these decoded values can handle strings where numbers or booleans were previously expected.


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.

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.

Actionable comments posted: 0

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

74-83: Behavior change looks correct; consider tightening parser typing in this branch

Using const parsed = parser(val); return stringify(parsed) is the right fix: it makes stringifySearchWith actually round‑trip parseable strings (e.g. "123", "true", "null") according to the provided parser/stringify pair, and avoids adding extra quotes for numeric/boolean‑like search params. The silent error handling and overall control flow remain consistent with parseSearchWith, so this should be a safe and targeted behavior change.

One minor follow‑up: since parser is typed as optional, calling it here can trip strict TypeScript checks (Object is possibly 'undefined'). You already guard it via hasParser, but TS doesn’t narrow from that. If you want to keep strict mode fully happy, consider narrowing directly on parser in the condition, e.g.:

} else if (parser && typeof val === 'string') {
  try {
    const parsed = parser(val)
    return stringify(parsed)
  } catch (_err) {
    // silent
  }
}

This preserves runtime behavior while aligning with strict type expectations.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between afb4b24 and 1af0d4b.

📒 Files selected for processing (1)
  • packages/router-core/src/searchParams.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript strict mode with extensive type safety throughout the codebase

Files:

  • packages/router-core/src/searchParams.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: nlynzaad
Repo: TanStack/router PR: 5182
File: e2e/react-router/basic-file-based/src/routes/non-nested/named/$baz_.bar.tsx:3-5
Timestamp: 2025-09-22T00:56:49.237Z
Learning: In TanStack Router, underscores are intentionally stripped from route segments (e.g., `$baz_` becomes `baz` in generated types) but should be preserved in base path segments. This is the correct behavior as of the fix in PR #5182.

@adbjo adbjo changed the title fix: Do not add quotes to search params fix: Do not quote numerical search params Dec 1, 2025
@nx-cloud
Copy link

nx-cloud bot commented Dec 1, 2025

🤖 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 1af0d4b

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

☁️ Nx Cloud last updated this comment at 2025-12-01 19:37:23 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 1, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6000

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@6000

@tanstack/eslint-plugin-router

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

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6000

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6000

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6000

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6000

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@6000

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6000

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6000

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6000

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6000

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6000

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6000

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6000

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6000

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6000

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6000

commit: 1af0d4b

@adbjo adbjo force-pushed the do_not_add_quotes_to_search_params branch from 1af0d4b to c8ae18e Compare December 2, 2025 11:05
@adbjo adbjo force-pushed the do_not_add_quotes_to_search_params branch from c8ae18e to 04bd7ad Compare December 2, 2025 11:09
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