Uh oh!
There was an error while loading. Please reload this page.
perf(router): use URL.canParse for absolute URL checks - #8251
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change centralizes absolute URL detection with ChangesURL validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk:⚪ Minimal · up to This change centralizes absolute URL detection across routing, links, redirects, and build configuration while preserving internal routing and dangerous-protocol protections. No concrete current-head merge-blocking risk remains. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
View your CI Pipeline Execution ↗ for commit fcca22d
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version Preview6 package(s) bumped directly, 18 bumped as dependents. 🟩 Patch bumps
|
| if (typeof to === 'string' && to.indexOf(':') > -1) { | ||
| try { | ||
| new URL(to) | ||
| if (isAbsoluteUrl(to)) { |
There was a problem hiding this comment.
we don't need nested ifs here, isAbsoluteUrl can just be part of the condition
Uh oh!
There was an error while loading. Please reload this page.
| if (typeof to !== 'string' || to.indexOf(':') === -1) { | ||
| return undefined | ||
| } | ||
| try { | ||
| new URL(to) | ||
| if (isAbsoluteUrl(to)) { |
There was a problem hiding this comment.
we can re-arrange this into a single if block here
| const safeInternal = isSafeInternal(to) | ||
| if (safeInternal) return undefined | ||
| if (typeof to !== 'string' || to.indexOf(':') === -1) return undefined | ||
| try { | ||
| new URL(to as any) | ||
| if (isAbsoluteUrl(to)) { |
There was a problem hiding this comment.
we can re-arrange this into a single if block
There was a problem hiding this comment.
is this testing something useful? or are we just basically testing the built-in implementation of URL.canParse?
There was a problem hiding this comment.
remove this, useful for the PR, but not to keep in the repo
Bundle Size Benchmarks
The following scenarios have bundle-size changes compared with the baseline:
Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better. |
Merging this PR will degrade performance by 7.4%
|
There was a problem hiding this comment.
Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud has identified a possible root cause for your failed CI:
We investigated the failing tanstack-react-start-e2e-rsc:test:e2e--vite-ssr--shard-1-of-6 task and found it crashes with a SyntaxError because @tanstack/router-e2e-utils does not export getDummyServerPort — this happens before any tests run, at Playwright config load time. Our PR only touches URL-parsing logic across router packages and has no connection to this e2e utility package, so the failure is an environment/dependency configuration issue unrelated to these changes.
No code changes were suggested for this issue.
Trigger a rerun:
🎓 Learn more about Self-Healing CI on nx.dev
Uh oh!
There was an error while loading. Please reload this page.
🎯 Changes
Use
URL.canParsefor checks that only need to know whether a string is an absolute URL. This avoids constructing a URL object on success and throwing on relative paths or malformed URLs.React, Solid, Vue, navigation, and redirects share an internal
isAbsoluteUrlhelper with a constructor fallback for older browsers. The Start and Nitro build plugins useURL.canParsedirectly because their minimum Node versions support it. Existing protocol checks and internal-link fast paths remain in place.React and Solid links use
!isSafeInternal(to) && isAbsoluteUrl(to): slash/dot paths skip parsing, and other destinations go directly to URL validation without separate type or colon checks. The internal helper accepts optionalundefinedand returns a boolean.Local Node 25.8.1 validation benchmark results, median of seven samples of 100,000 checks after warmup, in ns/check:
These are validation microbenchmarks, not whole-router speedups. React and Solid already skip parsing most internal links.
Validation:
pnpm test:unit(30 affected projects), including existing framework link/redirect coverage.pnpm test:eslint(33 affected projects) andpnpm test:types(37 affected projects).✅ Checklist
🚀 Release Impact
Summary by CodeRabbit
URL.canParsethrough a compatibility fallback.