-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor(router-core): flatten parsePathname #5077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughRefactors 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
View your CI Pipeline Execution ↗ for commit 31d3f6f
☁️ Nx Cloud last updated this comment at |
More templates
@tanstack/arktype-adapter
@tanstack/directive-functions-plugin
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/react-router
@tanstack/react-router-devtools
@tanstack/react-router-ssr-query
@tanstack/react-start
@tanstack/react-start-client
@tanstack/react-start-plugin
@tanstack/react-start-server
@tanstack/router-cli
@tanstack/router-core
@tanstack/router-devtools
@tanstack/router-devtools-core
@tanstack/router-generator
@tanstack/router-plugin
@tanstack/router-ssr-query-core
@tanstack/router-utils
@tanstack/router-vite-plugin
@tanstack/server-functions-plugin
@tanstack/solid-router
@tanstack/solid-router-devtools
@tanstack/solid-start
@tanstack/solid-start-client
@tanstack/solid-start-plugin
@tanstack/solid-start-server
@tanstack/start-client-core
@tanstack/start-plugin-core
@tanstack/start-server-core
@tanstack/start-server-functions-client
@tanstack/start-server-functions-fetcher
@tanstack/start-server-functions-server
@tanstack/start-storage-context
@tanstack/valibot-adapter
@tanstack/virtual-file-routes
@tanstack/zod-adapter
commit: |
There was a problem hiding this 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.
📒 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.
This change is just for code readability
Summary by CodeRabbit
Refactor
Bug Fixes
Tests