Uh oh!
There was an error while loading. Please reload this page.
refactor(router-core): improve parseSegment performance, parse without regex - #6470
Conversation
📝 WalkthroughWalkthroughReplaced regex-driven parsing with brace-position detection in the router segment parser. Changes
Sequence Diagram(s)(omitted — changes are internal parsing logic within a single module and do not introduce multi-component flows) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
View your CI Pipeline Execution ↗ for commit f1f2fbf
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/router-core/src/new-process-route-tree.ts`:
- Around line 119-172: The parsed brace indices (openBrace, closeBrace,
paramStart, dollarPos, afterDollar, etc.) are offsets inside part but are being
written into output as if they were absolute positions in path; add the start
offset when writing any brace-based positions into output so the output indexes
are absolute. Specifically, in the branches that set output[...] for
SEGMENT_TYPE_OPTIONAL_PARAM, SEGMENT_TYPE_WILDCARD and SEGMENT_TYPE_PARAM,
replace uses of openBrace, closeBrace, paramStart, dollarPos, afterDollar and
closeBrace + 1 with openBrace + start, closeBrace + start, paramStart + start,
dollarPos + start, afterDollar + start and (closeBrace + 1) + start respectively
(leave path.length and end as-is). Ensure all three branches (optional param,
wildcard, regular param) consistently apply the start offset so prefix/suffix
extraction uses absolute indexes.
Uh oh!
There was an error while loading. Please reload this page.
parseSegmentis in the hot path both forinterpolatePath, i.e. every Link, every navigation, every preload, ...Without the comments, this PR adds 7 lines of code in total, but increases performance by 0% to 40% depending on the type of segment we're parsing.
Because there is no enforcement of parameter name syntax at runtime anymore, we introduce
bench
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.