fix(router-core): parse non-nested path params correctly #5165
main fromrefs/pull/5165/head·merged by nlynzaad(GitHub profile, opens in a new tab) When parsing path params to interpolate the path non-nested path params /path/$param_ was being parsed in the same manner as regular path params /path/$param.
This PR adds consideration for the trailing underscore when parsing the path for non-nested path params as well as unit tests on path interpolation and e2e tests for useParams to ensure this is parsed correctly and updates correctly when params change.
This resolves #5164
Summary by CodeRabbit#
New Features
- Support trailing-underscore non-nested path params (e.g., /users/$id_ → /users/123).
- UI shows an additional navigation link for the non-nested route (/params-ps/non-nested/foo2/bar2) and improved link display text.
Tests
- Expanded React and Solid e2e tests to cover the new link, navigation, and param parsing for foo2/bar2.
- Added unit tests validating interpolation/matching for the $param_ syntax.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core
nlynzaad(GitHub profile, opens in a new tab) changed the title
View your CI Pipeline Execution ↗ for commit 112143dbf98c221adfcc01b0d6bff57e5ca117d1
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 4m 56s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 13s View ↗
☁️ Nx Cloud last updated this comment at
2025-09-18 18:27:27UTCMore 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-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-react-query
- tanstack-start-example-basic-rsc
- tanstack-start-example-basic-static
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-example-large
- tanstack-start-example-material-ui
- 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-basic
- 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-streaming-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-static
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5165@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5165@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5165@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5165@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5165@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5165@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5165@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5165@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5165@tanstack/react-start-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-plugin@5165@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5165@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5165@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5165@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5165@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5165@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5165@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5165@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5165@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5165@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5165@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5165@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5165@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5165@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5165@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5165@tanstack/solid-start-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-plugin@5165@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5165@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5165@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5165@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5165@tanstack/start-server-functions-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-client@5165@tanstack/start-server-functions-fetcher
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-fetcher@5165@tanstack/start-server-functions-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-server@5165@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5165@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5165@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5165@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5165commit:
112143dActionable comments posted: 3
🧹 Nitpick comments (2)
e2e/react-router/basic-file-based/src/routes/params-ps/non-nested/route.tsx (1)
21-28: Two links render identical visible text; use distinct labels for a11y and clarity.Both Links show "/params-ps/non-nested/$foo/$bar" which makes screen-reader and debugging output ambiguous. Align with Solid example and reflect actual param values.
Apply this diff:
params={{ foo: 'foo2', bar: 'bar2' }} > - /params-ps/non-nested/$foo/$bar + /params-ps/non-nested/foo2/bar2 </Link>(Optional) Consider also updating the first link’s label (Lines 19-20) to "/params-ps/non-nested/foo/bar" for parity with the Solid route.
packages/router-core/tests/path.test.ts (1)
435-440: Nice coverage for interpolatePath with non‑nested syntax; add parse/match assertions too.Recommend adding parse and match tests to prevent regressions in the tokenization/matching path.
Example additions:
it('parsePathname should parse $id_ as a param named $id', () => { expect(parsePathname('/$id_')).toEqual([ { type: SEGMENT_TYPE_PATHNAME, value: '/' }, { type: SEGMENT_TYPE_PARAM, value: '$id' }, ]) }) it('matchPathname should match non-nested param', () => { expect(matchPathname('/', '/users/123', { to: '/users/$id_' })) .toStrictEqual({ id: '123' }) })📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between fb4c6a1b82d7d214ba1ee617fc97e8326910ab0d and f768adfa7cfd33f97f79301c3935f3f77a2c8a91.
📒 Files selected for processing (6)
e2e/react-router/basic-file-based/src/routes/params-ps/non-nested/route.tsx(1 hunks)e2e/react-router/basic-file-based/tests/params.spec.ts(2 hunks)e2e/solid-router/basic-file-based/src/routes/params-ps/non-nested/route.tsx(1 hunks)e2e/solid-router/basic-file-based/tests/params.spec.ts(1 hunks)packages/router-core/src/path.ts(2 hunks)packages/router-core/tests/path.test.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
e2e/react-router/basic-file-based/src/routes/params-ps/non-nested/route.tsx (3)
e2e/react-router/basic-file-based/src/routes/params-ps/index.tsx (1)
Route(3-5)
e2e/react-router/basic-file-based/src/routes/params-ps/non-nested/$foo_/$bar.tsx (1)
Route(3-5)
e2e/react-router/basic-file-based/src/routes/params-ps/non-nested/$foo_/route.tsx (1)
Route(3-3)
e2e/solid-router/basic-file-based/src/routes/params-ps/non-nested/route.tsx (3)
e2e/solid-router/basic-file-based/src/routes/params-ps/index.tsx (1)
Route(3-5)
e2e/solid-router/basic-file-based/src/routes/params-ps/non-nested/$foo_/$bar.tsx (1)
Route(3-5)
e2e/solid-router/basic-file-based/src/routes/params-ps/non-nested/$foo_/route.tsx (1)
Route(3-3)
⏰ 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 (2)
e2e/solid-router/basic-file-based/src/routes/params-ps/non-nested/route.tsx (1)
19-27: LGTM: distinct, descriptive link labels.The labels match the concrete hrefs (foo/bar and foo2/bar2), improving a11y and test readability.
packages/router-core/src/path.ts (1)
323-332: Parsing branch looks correct; consider char‑set parity comment.Logic is fine and returns
$paramfor$param_. Once the regexes above are tightened, this branch inherits the stricter charset and remains exclusive from the regular param case.Please add a quick unit test to assert
parsePathname('/$id_')yields a singleSEGMENT_TYPE_PARAMwithvalue: '$id'to lock behavior.@@ -85,0 +87,21 @@87+88+ const foo2Bar2Link = page.getByTestId('l-to-non-nested-foo2-bar2')89+90+ await expect(foo2Bar2Link).toHaveAttribute(91+ 'href',92+ '/params-ps/non-nested/foo2/bar2',93+ )94+ await foo2Bar2Link.click()95+ const pagePathname2 = new URL(page.url()).pathname96+ await page.waitForLoadState('networkidle')97+ expect(pagePathname2).toBe('/params-ps/non-nested/foo2/bar2')98+99+ const foo2ParamsValue = page.getByTestId('foo-params-value')100+ const foo2ParamsText = await foo2ParamsValue.innerText()101+ const foo2ParamsObj = JSON.parse(foo2ParamsText)102+ expect(foo2ParamsObj).toEqual({ foo: 'foo2' })103+104+ const params2Value = page.getByTestId('foo-bar-params-value')105+ const params2Text = await params2Value.innerText()106+ const params2Obj = JSON.parse(params2Text)107+ expect(params2Obj).toEqual({ foo: 'foo2', bar: 'bar2' })⚠️ Potential issue
Fix flakiness: read URL after navigation, or wait for the target URL.
pagePathname2is captured before waiting, which can intermittently read the pre-navigation URL.Apply this diff:
- await foo2Bar2Link.click() - const pagePathname2 = new URL(page.url()).pathname - await page.waitForLoadState('networkidle') - expect(pagePathname2).toBe('/params-ps/non-nested/foo2/bar2') + await foo2Bar2Link.click() + await page.waitForURL('/params-ps/non-nested/foo2/bar2') + const pagePathname2 = new URL(page.url()).pathname + expect(pagePathname2).toBe('/params-ps/non-nested/foo2/bar2')📝 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.
const foo2Bar2Link = page.getByTestId('l-to-non-nested-foo2-bar2') await expect(foo2Bar2Link).toHaveAttribute( 'href', '/params-ps/non-nested/foo2/bar2', ) await foo2Bar2Link.click() await page.waitForURL('/params-ps/non-nested/foo2/bar2') const pagePathname2 = new URL(page.url()).pathname expect(pagePathname2).toBe('/params-ps/non-nested/foo2/bar2') const foo2ParamsValue = page.getByTestId('foo-params-value') const foo2ParamsText = await foo2ParamsValue.innerText() const foo2ParamsObj = JSON.parse(foo2ParamsText) expect(foo2ParamsObj).toEqual({ foo: 'foo2' }) const params2Value = page.getByTestId('foo-bar-params-value') const params2Text = await params2Value.innerText() const params2Obj = JSON.parse(params2Text) expect(params2Obj).toEqual({ foo: 'foo2', bar: 'bar2' })🤖 Prompt for AI Agents
In e2e/react-router/basic-file-based/tests/params.spec.ts around lines 88 to 107, the test reads page.url() into pagePathname2 before waiting for navigation to finish which can be flaky; move the URL read to after the navigation wait (or replace the wait+read with await page.waitForURL('/params-ps/non-nested/foo2/bar2') and then read new URL), so ensure you await the navigation completion first and only then call new URL(page.url()).pathname to assert the final path.✅ Addressed in commit a3c98d3
@@ -160,0 +161,21 @@161+162+ const foo2Bar2Link = page.getByTestId('l-to-non-nested-foo2-bar2')163+164+ await expect(foo2Bar2Link).toHaveAttribute(165+ 'href',166+ '/params-ps/non-nested/foo2/bar2',167+ )168+ await foo2Bar2Link.click()169+ const pagePathname2 = new URL(page.url()).pathname170+ await page.waitForLoadState('networkidle')171+ expect(pagePathname2).toBe('/params-ps/non-nested/foo2/bar2')172+173+ const foo2ParamsValue = page.getByTestId('foo-params-value')174+ const foo2ParamsText = await foo2ParamsValue.innerText()175+ const foo2ParamsObj = JSON.parse(foo2ParamsText)176+ expect(foo2ParamsObj).toEqual({ foo: 'foo2' })177+178+ const params2Value = page.getByTestId('foo-bar-params-value')179+ const params2Text = await params2Value.innerText()180+ const params2Obj = JSON.parse(params2Text)181+ expect(params2Obj).toEqual({ foo: 'foo2', bar: 'bar2' })⚠️ Potential issue
Fix flakiness: capture URL after navigation completes.
Same issue as the React e2e:
pagePathname2is read before waiting.Apply this diff:
- await foo2Bar2Link.click() - const pagePathname2 = new URL(page.url()).pathname - await page.waitForLoadState('networkidle') - expect(pagePathname2).toBe('/params-ps/non-nested/foo2/bar2') + await foo2Bar2Link.click() + await page.waitForURL('/params-ps/non-nested/foo2/bar2') + const pagePathname2 = new URL(page.url()).pathname + expect(pagePathname2).toBe('/params-ps/non-nested/foo2/bar2')📝 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.
const foo2Bar2Link = page.getByTestId('l-to-non-nested-foo2-bar2') await expect(foo2Bar2Link).toHaveAttribute( 'href', '/params-ps/non-nested/foo2/bar2', ) await foo2Bar2Link.click() await page.waitForURL('/params-ps/non-nested/foo2/bar2') const pagePathname2 = new URL(page.url()).pathname expect(pagePathname2).toBe('/params-ps/non-nested/foo2/bar2') const foo2ParamsValue = page.getByTestId('foo-params-value') const foo2ParamsText = await foo2ParamsValue.innerText() const foo2ParamsObj = JSON.parse(foo2ParamsText) expect(foo2ParamsObj).toEqual({ foo: 'foo2' }) const params2Value = page.getByTestId('foo-bar-params-value') const params2Text = await params2Value.innerText() const params2Obj = JSON.parse(params2Text) expect(params2Obj).toEqual({ foo: 'foo2', bar: 'bar2' })🤖 Prompt for AI Agents
In e2e/solid-router/basic-file-based/tests/params.spec.ts around lines 162 to 181, the test reads page.url() before waiting for navigation to complete which causes flakiness; to fix it, move the URL capture to after await page.waitForLoadState('networkidle') (or use await page.waitForURL) so you get the final pathname, then assert that pathname equals '/params-ps/non-nested/foo2/bar2'.✅ Addressed in commit a3c98d3
@@ -218,5 +218,6 @@218218 return parsed219219 }220220221-const PARAM_RE = /^\$.{1,}$/ // $paramName221+const PARAM_RE = /^\$.{1,}(?<!_)$/ // $paramName222+const PARAM_NON_NESTED_RE = /^\$.{1,}_$/ // $paramName_222223 const PARAM_W_CURLY_BRACES_RE = /^(.*?)\{(\$[a-zA-Z_$][a-zA-Z0-9_$]*)\}(.*)$/ // prefix{$paramName}suffix⚠️ Potential issue
🧩 Analysis chain
Avoid JS RegExp lookbehind; broaden browser/engine support and tighten charset.
(?<!_)risks SyntaxError in environments lacking lookbehind (notably older Safari/WebKit/Android WebView). Also,.{1,}is overly permissive vs. our identifier-like patterns elsewhere.Apply this diff:
-const PARAM_RE = /^\$.{1,}(?<!_)$/ // $paramName -const PARAM_NON_NESTED_RE = /^\$.{1,}_$/ // $paramName_ +// No lookbehind; restrict to identifier-like names and forbid trailing underscore. +const PARAM_RE = /^\$[a-zA-Z_$](?:[a-zA-Z0-9_$]*[a-zA-Z0-9$])?$/ // $paramName (last char not '_') +const PARAM_NON_NESTED_RE = /^\$[a-zA-Z_$][a-zA-Z0-9_$]*_$/ // $paramName_If you target any Safari/WebKit versions without lookbehind, this change prevents runtime regex parsing failures.
To confirm browser support policy:
🌐 Web query:
Status of JavaScript RegExp lookbehind support across Safari (macOS/iOS) and Android WebView💡 Result:
Short answer
Safari (macOS) and Safari on iOS: RegExp lookbehind is supported starting in Safari 16.4 (released Mar 2023). Older Safari / iOS Safari versions do not support it. [1][2]
Android WebView: lookbehind has been supported since WebView v62 (Chromium 62, Oct 2017) — i.e., most modern Android WebView releases support it. [1][3]
Sources
- MDN browser-compat (RegExp lookbehind). [1]
- "Can I use" — JS RegExp lookbehind (shows Safari 16.4+ support). [2]
- compat.codes / WebView Android support (WebView 62+). [3]
Avoid RegExp lookbehind; broaden engine support and tighten charset.
Lookbehind (?<!_) is unsupported in older Safari (supported from Safari 16.4 — Mar 2023) and can throw a SyntaxError; Android WebView is fine (Chromium 62+, Oct 2017). Apply this diff:
-const PARAM_RE = /^\$.{1,}(?<!_)$/ // $paramName -const PARAM_NON_NESTED_RE = /^\$.{1,}_$/ // $paramName_ +// No lookbehind; restrict to identifier-like names and forbid trailing underscore. +const PARAM_RE = /^\$[a-zA-Z_$](?:[a-zA-Z0-9_$]*[a-zA-Z0-9$])?$/ // $paramName (last char not '_') +const PARAM_NON_NESTED_RE = /^\$[a-zA-Z_$][a-zA-Z0-9_$]*_$/ // $paramName_📝 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.
const PARAM_RE = /^\$(?!.*_$)[a-zA-Z_$][a-zA-Z0-9_$]*$/ // $paramName (last char not '_') const PARAM_NON_NESTED_RE = /^\$[a-zA-Z_$][a-zA-Z0-9_$]*_$/ // $paramName_ const PARAM_W_CURLY_BRACES_RE = /^(.*?)\{(\$[a-zA-Z_$][a-zA-Z0-9_$]*)\}(.*)$/ // prefix{$paramName}suffix🤖 Prompt for AI Agents
In packages/router-core/src/path.ts around lines 221-223, replace the three regexes to avoid the lookbehind and tighten allowed identifier characters: ensure PARAM_RE matches a leading '$' then an identifier starting with [a-zA-Z_$] followed by [a-zA-Z0-9_$]* and guarantee the last character is not '_' (so single-char names are allowed and multi-char names cannot end with underscore), change PARAM_NON_NESTED_RE to require the same identifier charset followed by a trailing '_' token, and update PARAM_W_CURLY_BRACES_RE to match prefix{ $identifier }suffix where the identifier uses [a-zA-Z_$][a-zA-Z0-9_$]*; replace the existing patterns accordingly so no lookbehind is used and the character classes are tightened.Actionable comments posted: 0
🧹 Nitpick comments (6)
e2e/react-router/basic-file-based/tests/params.spec.ts (3)
74-76: Minor: fold wait+assert into a single, auto‑waiting URL assertionSimplifies and reduces boilerplate.
- await page.waitForURL('/params-ps/non-nested/foo/bar') - const pagePathname = new URL(page.url()).pathname - expect(pagePathname).toBe('/params-ps/non-nested/foo/bar') + await expect(page).toHaveURL('/params-ps/non-nested/foo/bar')
94-97: Same here: compress navigation wait + assertionUse Playwright’s auto‑waiting matcher.
- await page.waitForURL('/params-ps/non-nested/foo2/bar2') - const pagePathname2 = new URL(page.url()).pathname - expect(pagePathname2).toBe('/params-ps/non-nested/foo2/bar2') + await expect(page).toHaveURL('/params-ps/non-nested/foo2/bar2')
99-107: Reduce flakiness: assert via locator matchers (auto‑wait) instead of manual innerText/JSON.parseLocators’ toHaveText retries until content settles; manual reads don’t. This avoids timing races after navigation.
- const foo2ParamsValue = page.getByTestId('foo-params-value') - const foo2ParamsText = await foo2ParamsValue.innerText() - const foo2ParamsObj = JSON.parse(foo2ParamsText) - expect(foo2ParamsObj).toEqual({ foo: 'foo2' }) + await expect(page.getByTestId('foo-params-value')).toHaveText( + JSON.stringify({ foo: 'foo2' }), + ) - const params2Value = page.getByTestId('foo-bar-params-value') - const params2Text = await params2Value.innerText() - const params2Obj = JSON.parse(params2Text) - expect(params2Obj).toEqual({ foo: 'foo2', bar: 'bar2' }) + await expect(page.getByTestId('foo-bar-params-value')).toHaveText( + JSON.stringify({ foo: 'foo2', bar: 'bar2' }), + )packages/router-core/tests/path.test.ts (3)
435-440: Add missing-param case for non-nested interpolationTo lock parity with regular named params, add a case where
$id_is missing and yieldsundefined.{ name: 'should interpolate the non-nested path', path: '/users/$id_', params: { id: '123' }, result: '/users/123', }, + { + name: 'should interpolate the non-nested path with missing params', + path: '/users/$id_', + params: {}, + result: '/users/undefined', + },
663-670: Add negative match to prove “non-nested” behaviorEnsure
/users/$id_does not match extra trailing segments.{ name: 'should match and return the non-nested named path params', input: '/users/123', matchingOptions: { to: '/users/$id_', }, expectedMatchedParams: { id: '123' }, }, + { + name: 'should not match when extra segment follows non-nested param', + input: '/users/123/extra', + matchingOptions: { + to: '/users/$id_', + }, + expectedMatchedParams: undefined, + },
910-918: Cover root-level non-nested parsingAdd a root variant to confirm
$bar_canonicalizes to$barat/.{ name: 'should handle non-nested named params', to: '/foo/$bar_', expected: [ { type: SEGMENT_TYPE_PATHNAME, value: '/' }, { type: SEGMENT_TYPE_PATHNAME, value: 'foo' }, { type: SEGMENT_TYPE_PARAM, value: '$bar' }, ], }, + { + name: 'should handle non-nested named params at the root', + to: '/$bar_', + expected: [ + { type: SEGMENT_TYPE_PATHNAME, value: '/' }, + { type: SEGMENT_TYPE_PARAM, value: '$bar' }, + ], + },📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between f768adfa7cfd33f97f79301c3935f3f77a2c8a91 and a3c98d3238288f73517a4647857d87adb29a443c.
📒 Files selected for processing (5)
e2e/react-router/basic-file-based/src/routes/params-ps/non-nested/route.tsx(1 hunks)e2e/react-router/basic-file-based/tests/params.spec.ts(2 hunks)e2e/solid-router/basic-file-based/tests/params.spec.ts(2 hunks)packages/router-core/src/path.ts(2 hunks)packages/router-core/tests/path.test.ts(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/router-core/src/path.ts
- e2e/react-router/basic-file-based/src/routes/params-ps/non-nested/route.tsx
- e2e/solid-router/basic-file-based/tests/params.spec.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/router-core/tests/path.test.ts (1)
packages/router-core/src/path.ts (2)
SEGMENT_TYPE_PATHNAME(6-6)SEGMENT_TYPE_PARAM(7-7)
⏰ 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 (1)
e2e/react-router/basic-file-based/tests/params.spec.ts (1)
90-93: LGTM: correct href assertion for the second linkGood coverage to ensure interpolation is right.
nlynzaad(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Walkthrough#
Adds support for non-nested trailing-underscore params (
$param_) in router-core parsing, adds tests for interpolation/matching/parsing, and extends React and Solid e2e routes/tests with an extra link and assertions for/params-ps/non-nested/foo2/bar2. No public API signatures changed.Changes#
packages/router-core/src/path.ts,packages/router-core/tests/path.test.ts$param_as$param), update token matching to use the normalized part, and add tests for interpolatePath, matchPathname, and parsePathname covering/users/$id_and/foo/$bar_.e2e/react-router/basic-file-based/src/routes/params-ps/non-nested/route.tsx,e2e/react-router/basic-file-based/tests/params.spec.tsparams={{ foo: 'foo2', bar: 'bar2' }}(data-testid="l-to-non-nested-foo2-bar2"), and extend tests to assert hrefs, wait for URL navigation, and validate parsed params for both routes.e2e/solid-router/basic-file-based/src/routes/params-ps/non-nested/route.tsx,e2e/solid-router/basic-file-based/tests/params.spec.tsparams={{ foo: 'foo2', bar: 'bar2' }}anddata-testid="l-to-non-nested-foo2-bar2", and extend tests to use URL-based waits and assert parsed params for both routes.Sequence Diagram(s)#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs#
Suggested labels#
package: react-router,package: solid-routerSuggested reviewers#
Poem#
Pre-merge checks and finishing touches#
✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 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 a3c98d3238288f73517a4647857d87adb29a443c and ebb3ffbd045625894abe72dac4e48e4fcf68da6b.
📒 Files selected for processing (1)
packages/router-core/src/path.ts(6 hunks)🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
Tip
👮 Agentic pre-merge checks are now available in preview!
Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information.
Example:
Please share your feedback with us on this Discord post.
Comment `@coderabbitai help` to get the list of available commands and usage tips.