Skip to content

fix: Fix file-based route generation when custom routeToken or `ind…#7048

Merged
schiller-manuel merged 1 commit intomainfrom
fix-7036
Mar 26, 2026
Merged

fix: Fix file-based route generation when custom routeToken or `ind…#7048
schiller-manuel merged 1 commit intomainfrom
fix-7036

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Mar 26, 2026

…exTokenvalues start with regex metacharacters like+`.

fixes #7036

Summary by CodeRabbit

  • Bug Fixes
    • Fixed file-based route generation when custom token values begin with regex metacharacters (such as +). The router generator now properly handles routes with special character prefixes in token configurations.

…exToken` values start with regex metacharacters like `+`.

fixes #7036
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 26, 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: c2012d51-4e57-4da2-9b55-d8f3640e20dd

📥 Commits

Reviewing files that changed from the base of the PR and between a1ab264 and 58e5755.

📒 Files selected for processing (10)
  • .changeset/tiny-cars-taste.md
  • packages/router-generator/src/filesystem/physical/getRouteNodes.ts
  • packages/router-generator/src/utils.ts
  • packages/router-generator/tests/generator/regex-tokens-plus-json/routeTree.snapshot.ts
  • packages/router-generator/tests/generator/regex-tokens-plus-json/routes/+page.tsx
  • packages/router-generator/tests/generator/regex-tokens-plus-json/routes/__root.tsx
  • packages/router-generator/tests/generator/regex-tokens-plus-json/routes/dashboard/+layout.tsx
  • packages/router-generator/tests/generator/regex-tokens-plus-json/routes/dashboard/+page.tsx
  • packages/router-generator/tests/generator/regex-tokens-plus-json/routes/dashboard/settings.tsx
  • packages/router-generator/tests/generator/regex-tokens-plus-json/tsr.config.json

📝 Walkthrough

Walkthrough

The changes fix file-based route generation when user-provided routeToken or indexToken values begin with regex metacharacters (e.g., +). The core fix exports escapeRegExp and applies it to sanitize dynamic segments before constructing regex patterns. Test fixtures and configuration are added to verify the behavior.

Changes

Cohort / File(s) Summary
Core regex escaping logic
packages/router-generator/src/utils.ts, packages/router-generator/src/filesystem/physical/getRouteNodes.ts
Exported escapeRegExp as public API and applied it to sanitize stripSegment, updatedLastRouteSegment, and indexTokenCandidate values before inserting into regex patterns to treat special characters literally.
Test fixtures - Route definitions
packages/router-generator/tests/generator/regex-tokens-plus-json/routes/__root.tsx, packages/router-generator/tests/generator/regex-tokens-plus-json/routes/+page.tsx, packages/router-generator/tests/generator/regex-tokens-plus-json/routes/dashboard/+layout.tsx, packages/router-generator/tests/generator/regex-tokens-plus-json/routes/dashboard/+page.tsx, packages/router-generator/tests/generator/regex-tokens-plus-json/routes/dashboard/settings.tsx
Added route module fixtures for testing token regex patterns with + prefix, including root, home, dashboard layout, dashboard home, and settings routes.
Test fixtures - Configuration and snapshot
packages/router-generator/tests/generator/regex-tokens-plus-json/tsr.config.json, packages/router-generator/tests/generator/regex-tokens-plus-json/routeTree.snapshot.ts
Added configuration defining indexToken and routeToken regex patterns, and generated route tree snapshot with TypeScript interfaces and module augmentation for FileRoutesByPath.
Changeset entry
.changeset/tiny-cars-taste.md
Added patch version bump note for @tanstack/router-generator documenting the fix for regex metacharacter handling in tokens.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A plus symbol caused quite a fright,
In regex patterns, not treated right!
With escapeRegExp now exported and true,
Routes with + tokens work just like new!
The generator hops to fix what's broke,
No more metacharacter jokes! 🎉

🚥 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 file-based route generation when custom routeToken or indexToken values start with regex metacharacters like +.
Linked Issues check ✅ Passed The PR successfully addresses issue #7036 by escaping regex metacharacters in token handling to allow tokens starting with + to work correctly in both root and nested routes.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the regex metacharacter issue: regex escaping in getRouteNodes.ts, exporting escapeRegExp utility, adding test configuration with + tokens, and creating test fixtures.
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 fix-7036

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

@nx-cloud
Copy link

nx-cloud bot commented Mar 26, 2026

View your CI Pipeline Execution ↗ for commit 58e5755

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 16m 29s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 44s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-26 17:57:58 UTC

@github-actions
Copy link
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 7 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/router-generator 1.166.19 → 1.166.20 Changeset
@tanstack/react-start 1.167.9 → 1.167.10 Dependent
@tanstack/router-cli 1.166.20 → 1.166.21 Dependent
@tanstack/router-plugin 1.167.6 → 1.167.7 Dependent
@tanstack/router-vite-plugin 1.166.21 → 1.166.22 Dependent
@tanstack/solid-start 1.167.9 → 1.167.10 Dependent
@tanstack/start-plugin-core 1.167.11 → 1.167.12 Dependent
@tanstack/vue-start 1.167.9 → 1.167.10 Dependent

@github-actions
Copy link
Contributor

Bundle Size Benchmarks

  • Commit: a1ab2646348c
  • Measured at: 2026-03-26T17:42:23.301Z
  • Baseline source: history:a1ab2646348c
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Raw Brotli Trend
react-router.minimal 87.53 KiB 0 B (0.00%) 275.90 KiB 76.10 KiB █████▇▇▃▃▁▁
react-router.full 90.82 KiB 0 B (0.00%) 287.08 KiB 78.84 KiB ▇▇███▇▇▂▂▁▁
solid-router.minimal 35.56 KiB 0 B (0.00%) 107.23 KiB 31.90 KiB █████▄▄▄▄▁▁
solid-router.full 40.04 KiB 0 B (0.00%) 120.77 KiB 35.93 KiB ▅▅███▂▂▂▂▁▁
vue-router.minimal 53.42 KiB 0 B (0.00%) 153.17 KiB 47.88 KiB ███████▁▁▁▁
vue-router.full 58.28 KiB 0 B (0.00%) 168.63 KiB 52.20 KiB ▆▆█████▂▂▁▁
react-start.minimal 102.03 KiB 0 B (0.00%) 324.08 KiB 88.27 KiB ▆▆███▆▆▂▂▁▁
react-start.full 105.41 KiB 0 B (0.00%) 334.42 KiB 91.07 KiB ▇▇███▆▆▂▂▁▁
solid-start.minimal 49.65 KiB 0 B (0.00%) 153.42 KiB 43.76 KiB █████▄▄▄▄▁▁
solid-start.full 55.16 KiB 0 B (0.00%) 169.66 KiB 48.56 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 26, 2026

More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: 58e5755

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 26, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing fix-7036 (58e5755) with main (a1ab264)

Open in CodSpeed

@schiller-manuel schiller-manuel merged commit 70b2225 into main Mar 26, 2026
17 checks passed
@schiller-manuel schiller-manuel deleted the fix-7036 branch March 26, 2026 19:36
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.

Route and index token regex not working with "+" symbol at start

1 participant