Skip to content

Conversation

@andorep
Copy link

@andorep andorep commented Sep 30, 2025

Summary

This PR fixes the basepath rewrite logic to correctly match routes with or without a trailing slash.

Problem

The rewrite logic didn’t consider basepaths without a trailing slash. For example, if you define a basepath like /myapp and try to access the root page at /myapp, it would not work unless you added a trailing slash (i.e., /myapp/). This caused the root page to be inaccessible without the slash, breaking prerendering in Tanstack Start

Related Issue

See #5261 for more details

Summary by CodeRabbit

  • Bug Fixes
    • Improved route matching for base paths to handle URLs with or without a trailing slash, reducing false 404s and ensuring correct resolution.
    • Enhances compatibility across environments where base paths may be configured inconsistently, resulting in more reliable navigation and redirects.
    • Preserves existing case sensitivity behavior with no changes to the public API or configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 30, 2025

Walkthrough

Adjusted the basepath rewrite regex from ^/{{trimmedBasepath}}/ to ^/{{trimmedBasepath}}(?:/|$) to match when the basepath is followed by a slash or ends at the basepath. No public API or declaration changes.

Changes

Cohort / File(s) Summary
Router rewrite regex
packages/router-core/src/rewrite.ts
Updated basepath matching regex to allow matches at end-of-string or before a slash: `^/{{trimmedBasepath}}(?:/

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Router
  participant Rewriter
  participant Handler

  Client->>Router: Request path
  Router->>Rewriter: Apply basepath regex
  alt Path starts with basepath + "/" or ends at basepath
    Note right of Rewriter: Uses ^/{{trimmedBasepath}}(?:/|$)
    Rewriter-->>Router: Match + rewritten path
    Router->>Handler: Forward rewritten path
    Handler-->>Client: Response
  else No match
    Rewriter-->>Router: No rewrite
    Router->>Handler: Forward original path
    Handler-->>Client: Response
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my whiskers at the slashy gate,
A tidy regex trims my traveling fate.
Whether path ends here or takes a stride,
I hop right through, aligned with either side.
Soft paws, clean routes—no fuss, no thrash—
Just perfect paths, with or without a slash. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the core change—adjusting the basepath rewrite to handle trailing slash variations—which aligns exactly with the diff and PR objectives, and avoids unnecessary detail or noise.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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/rewrite.ts (1)

21-40: Regex change is correct; add output tests
The pattern ^/${trimmedBasepath}(?:/|$) now gracefully handles paths with or without trailing slash. All existing tests validate the input rewrite behavior, but none cover the output function. Please add tests to ensure output restores the basepath via joinPaths correctly across cases.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 581941a and 4139d1e.

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

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript in strict mode with extensive type safety across the codebase

Files:

  • packages/router-core/src/rewrite.ts
packages/router-core/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep framework-agnostic core router logic in packages/router-core/

Files:

  • packages/router-core/src/rewrite.ts

@schiller-manuel
Copy link
Contributor

we already have this PR open for that: #5244

maybe help out there to figure out why the tests work without the fix applied?

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.

2 participants