router icon indicating copy to clipboard operation
router copied to clipboard

Prevent the root path "/" from being removed

Open cxa opened this issue 1 month ago β€’ 8 comments

This PR prevents the root path "/" from being emptied by removeTrailingSlash.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved handling of trailing slashes in layout-type routes to correctly exclude the root path from trailing-slash removal.

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

cxa avatar Nov 19 '25 07:11 cxa

Walkthrough

The trailing-slash removal logic for layout-type route nodes is refined to preserve the root path. The condition now excludes removing trailing slashes when the cleaned path is '/'. The pathless_layout case handling remains unaffected.

Changes

Cohort / File(s) Summary
Layout Route Node Trailing-Slash Fix
packages/router-generator/src/generator.ts
Tightened trailing-slash removal condition for layout-type nodes to exclude root path ('/'). Checks that cleanedPath is not '/' before removing trailing slashes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

  • Verify the condition logic is correct and the root path '/' is properly excluded
  • Confirm no unintended side effects on layout node path handling

Possibly related PRs

  • TanStack/router#5909: Addresses the same trailing-slash preservation for root paths in a different function (trimPathRight within route-node handling)

Suggested reviewers

  • schiller-manuel

Poem

🐰 A path trimmed with care, Root "/" left standing there, Layout nodes now rightβ€” No slashes to fight! ✨

Pre-merge checks and finishing touches

βœ… 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 directly and clearly describes the main fix: preventing the root path from being removed, which matches the core change made to the route generator logic.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 f28edc8c81e84f062b64ad2c0e60965222b6e071 and 6bc7f5b0670890ff37cee4a5f3cad44e72d790d5.

πŸ“’ Files selected for processing (1)
  • packages/router-generator/src/generator.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/router-generator/src/generator.ts

[!TIP]

πŸ“ Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests β€” including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. πŸ“ Description β€” Summarize the main change in 50–60 words, explaining what was done.
  2. πŸ““ References β€” List relevant issues, discussions, documentation, or related PRs.
  3. πŸ“¦ Dependencies & Requirements β€” Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. πŸ“Š Contributor Summary β€” Include a Markdown table showing contributions: | Contributor | Lines Added | Lines Removed | Files Changed |
  5. βœ”οΈ Additional Notes β€” Add any extra reviewer context. Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

coderabbitai[bot] avatar Nov 19 '25 07:11 coderabbitai[bot]

View your CI Pipeline Execution β†— for commit f28edc8c81e84f062b64ad2c0e60965222b6e071

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... βœ… Succeeded 7m 27s View β†—
nx run-many --target=build --exclude=examples/*... βœ… Succeeded 32s View β†—

☁️ Nx Cloud last updated this comment at 2025-11-21 02:24:25 UTC

nx-cloud[bot] avatar Nov 19 '25 12:11 nx-cloud[bot]

More templates

@tanstack/arktype-adapter

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

commit: f28edc8

pkg-pr-new[bot] avatar Nov 19 '25 12:11 pkg-pr-new[bot]

@cxa there's a failing unit test that needs some attention.

birkskyum avatar Nov 19 '25 18:11 birkskyum

first of all we need to understand why this fix is needed. when would this occur?

schiller-manuel avatar Nov 19 '25 20:11 schiller-manuel

first of all we need to understand why this fix is needed. when would this occur?

Without this fix, file route like _auth.index/route.tsx will generate a wrong path: '' route instead of the correct path: '/' one. (Since route.tsx is treated as layout, maybe we should use a new FsRouteType for it?)

cxa avatar Nov 20 '25 06:11 cxa

first of all we need to understand why this fix is needed. when would this occur?

Without this fix, file route like _auth.index/route.tsx will generate a wrong path: '' route instead of the correct path: '/' one. (Since route.tsx is treated as layout, maybe we should use a new FsRouteType for it?)

nesting route.tsx under index is not a supported usage of file based routing. if this is only relevant for this, we won't merge this

schiller-manuel avatar Nov 22 '25 20:11 schiller-manuel

nesting route.tsx under index is not a supported usage of file based routing. if this is only relevant for this, we won't merge this

Makes sense, but if this PR enables nesting index/route.tsx without causing any issues, I don’t see why it would be rejected.

P.S. Is there anywhere that mentions nested index/route.tsx isn’t supported? (used since 2023 but recent updates made it broken)

cxa avatar Nov 23 '25 02:11 cxa