Skip to content

Conversation

Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Sep 3, 2025

This change is just for code readability

  • it changes nothing to the performance profile of this function
  • it should change nothing to the behavior

Summary by CodeRabbit

  • Refactor

    • Modularized URL path parsing for clarity and maintainability without changing the public API.
  • Bug Fixes

    • Correct handling of literal percent signs in paths.
    • Consistent interpretation of leading and trailing slashes, including root paths.
    • Improved parsing of wildcard and parameter segments, including optional prefixes/suffixes.
    • Ensures empty paths correctly resolve to root, preserving prior behavior.
  • Tests

    • Expanded coverage to validate new parsing behaviors and edge cases.

Copy link
Contributor

coderabbitai bot commented Sep 3, 2025

Walkthrough

Refactors pathname parsing in packages/router-core/src/path.ts by introducing splitPathname and partToSegment helpers. Updates baseParsePathname to use split-and-map parsing, explicitly representing leading/trailing slashes as PATHNAME segments, and adds parsing for wildcard/parameter forms with optional prefixes/suffixes. No public API signatures changed.

Changes

Cohort / File(s) Summary
Router path parsing refactor
packages/router-core/src/path.ts
Rewrote baseParsePathname to use splitPathname and partToSegment; added decoding and segment classification logic; now encodes leading/trailing slashes as explicit PATHNAME segments; preserves root path behavior; no exported API changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Parser as baseParsePathname
  participant Split as splitPathname
  participant Segment as partToSegment

  Caller->>Parser: baseParsePathname(pathname)
  Note over Parser: Replace inline parsing with split-and-map
  Parser->>Split: decode + split(pathname)
  Split-->>Parser: parts[] (incl. markers for root/trailing slash)
  loop For each part
    Parser->>Segment: partToSegment(part)
    alt Matches {$}, {-$param}, {$param}, $param, $
      Segment-->>Parser: WILDCARD / (OPTIONAL_)PARAM segment
    else Default
      Segment-->>Parser: PATHNAME segment
    end
  end
  Parser-->>Caller: segments[]
  Note over Caller,Parser: Leading/trailing slashes become PATHNAME segments
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

package: router-core

Suggested reviewers

  • schiller-manuel
  • SeanCassiere

Poem

I hop through paths with careful sight,
Splitting crumbs of slash and byte,
Wildcards wiggle, params play,
Prefix, suffix join the fray—
Carrots mapped, the routes just right,
A tidy warren in the night. 🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-router-core-parse-pathname-flatten

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

nx-cloud bot commented Sep 3, 2025

View your CI Pipeline Execution ↗ for commit 31d3f6f

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

☁️ Nx Cloud last updated this comment at 2025-09-03 10:49:01 UTC

Copy link

pkg-pr-new bot commented Sep 3, 2025

More templates

@tanstack/arktype-adapter

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

@tanstack/directive-functions-plugin

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

@tanstack/eslint-plugin-router

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

@tanstack/history

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-plugin

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/server-functions-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-plugin

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-server-functions-client

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

@tanstack/start-server-functions-fetcher

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

@tanstack/start-server-functions-server

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/zod-adapter

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

commit: 31d3f6f

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 (2)
packages/router-core/src/path.ts (2)

308-319: Tiny cleanup: avoid concatenation for value.

Use the captured string directly.

-      value: '' + paramName,
+      value: paramName,

321-330: Prefer assigning the original part directly.

Keeps intent obvious and avoids extra substring/concat.

-  if (PARAM_RE.test(part)) {
-    const paramName = part.substring(1)
-    return {
-      type: SEGMENT_TYPE_PARAM,
-      value: '$' + paramName,
-      prefixSegment: undefined,
-      suffixSegment: undefined,
-    }
-  }
+  if (PARAM_RE.test(part)) {
+    return {
+      type: SEGMENT_TYPE_PARAM,
+      value: part,
+      prefixSegment: undefined,
+      suffixSegment: undefined,
+    }
+  }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bc5e78f and 31d3f6f.

📒 Files selected for processing (1)
  • packages/router-core/src/path.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/router-core/src/path.ts (1)
packages/router-core/src/utils.ts (1)
  • last (187-189)
⏰ 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 (6)
packages/router-core/src/path.ts (6)

247-260: Base parser flattening reads well; verify invariants across edge cases.

Nice simplification. Please add/confirm tests for:

  • '/', '/a', '/a/', '/a//b' (collapsed), '.', '..'
  • Encoded segments: '/a%2Fb', '/%20', '/%2525' (literal '%'), trailing slash preservation with resolvePath.

I can draft a small table-driven test covering these if helpful.


279-291: Wildcard with braces parsing looks correct.

Order-before-bare checks avoids false positives; prefix/suffix normalized well.


294-305: Optional param with braces parsing LGTM.

Value normalized to '$param', prefix/suffix captured; aligns with segmentToString.


332-340: Bare wildcard case LGTM.

Matches only '$' and normalizes as expected.


343-346: Default PATHNAME fallback LGTM.

Keeps decoded segment as-is; consistent with segmentToString.


262-277: Drop case-insensitive “%25” handling – no uppercase/lowercase distinction exists The literal sequence “%25” consists of digits only, so .includes('%25') and .split('%25') already cover all occurrences; the /i flag is redundant.

Likely an incorrect or invalid review comment.

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