Skip to content

perf(router): use URL.canParse for absolute URL checks - #8251

Merged
Sheraff merged 4 commits into
mainfrom
codex/url-can-parse
Sep 5, 2026
Merged

perf(router): use URL.canParse for absolute URL checks#8251
Sheraff merged 4 commits into
mainfrom
codex/url-can-parse

Conversation

@Sheraff

@SheraffSheraff commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

🎯 Changes

Use URL.canParse for 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 isAbsoluteUrl helper with a constructor fallback for older browsers. The Start and Nitro build plugins use URL.canParse directly 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 optional undefined and returns a boolean.

Local Node 25.8.1 validation benchmark results, median of seven samples of 100,000 checks after warmup, in ns/check:

InputConstructor + catchNative check with fallback detectionSpeedup
Absolute URL2171141.9×
Relative path3,9204097.5×
Malformed URL3,9888248.4×
Mixed2,8995552.4×

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) and pnpm test:types (37 affected projects).
  • React basic example browser smoke test with native support enabled and disabled.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Improved detection of absolute URLs across links, navigation, redirects, and application configuration.
    • Preserved support for older browsers without URL.canParse through a compatibility fallback.
    • Maintained existing external-link handling, including dangerous-protocol protection.
    • Applied consistent absolute-URL handling across React, Solid, Vue, and core routing experiences.
    • Improved handling of optional or undefined navigation destinations without changing expected routing behavior.

@chatgpt-codex-connector

chatgpt-codex-connectorBot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

ReviewStatusCommitReview trigger
📝 Code ReviewCompleted2026-09-05T16:13:12.729680Z5b6a8c4PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitaiBot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: fce19bb3-b79e-4d0f-b93d-a23ac0388df4

📥 Commits

Reviewing files that changed from the base of the PR and between a2c330b and 7cbd52e.

📒 Files selected for processing (3)
  • packages/react-router/src/link.tsx
  • packages/router-core/src/utils.ts
  • packages/solid-router/src/link.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/router-core/src/utils.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The change centralizes absolute URL detection with URL.canParse and a fallback. Router navigation, redirects, framework links, and build base URL handling now use the shared detection.

Changes

URL validation

Layer / File(s)Summary
Core URL detection and routing
packages/router-core/src/utils.ts, packages/router-core/src/index.ts, packages/router-core/src/redirect.ts, packages/router-core/src/router.ts
Adds and exports isAbsoluteUrl, then uses it for navigation and redirect handling.
Framework link detection
packages/react-router/src/link.tsx, packages/solid-router/src/link.tsx, packages/vue-router/src/link.tsx
Framework link components use the shared predicate instead of new URL() try/catch checks.
Build base URL detection
packages/nitro-v2-vite-plugin/src/index.ts, packages/start-plugin-core/src/planning.ts
Build configuration uses URL.canParse and removes local full-URL helpers.
Release metadata
.changeset/pink-candies-attack.md
Declares patch releases for the affected router and build packages.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk:⚪ Minimal · up to fcca2

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:schiller-manuel

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 12 files.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
Title check✅ PassedThe title clearly and concisely describes the main change: using URL.canParse for absolute URL checks.
Description check✅ PassedThe description follows the required template, explains the changes and motivation, documents validation, and confirms the changeset. One non-critical checklist item about understanding AI-assisted co…
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/url-can-parse

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

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

@nx-cloud

nx-cloudBot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit fcca22d

CommandStatusDurationResult
nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded10m 32sView ↗
nx run-many --target=build --exclude=examples/*...✅ Succeeded2m 12sView ↗

☁️ Nx Cloud last updated this comment at 2026-09-05 19:07:22 UTC

@pkg-pr-new

pkg-pr-newBot commented Sep 5, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@8251

@tanstack/eslint-plugin-router

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

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8251

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@8251

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@8251

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@8251

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@8251

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@8251

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@8251

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8251

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@8251

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@8251

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@8251

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@8251

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8251

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@8251

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@8251

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8251

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@8251

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@8251

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8251

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@8251

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8251

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8251

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@8251

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@8251

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@8251

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@8251

commit: fcca22d

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

6 package(s) bumped directly, 18 bumped as dependents.

🟩 Patch bumps

PackageVersionReason
@tanstack/nitro-v2-vite-plugin1.155.0 → 1.155.1Changeset
@tanstack/react-router1.170.32 → 1.170.33Changeset
@tanstack/router-core1.171.27 → 1.171.28Changeset
@tanstack/solid-router1.170.30 → 1.170.31Changeset
@tanstack/start-plugin-core1.171.39 → 1.171.40Changeset
@tanstack/vue-router1.170.29 → 1.170.30Changeset
@tanstack/react-start1.168.49 → 1.168.50Dependent
@tanstack/react-start-client1.168.30 → 1.168.31Dependent
@tanstack/react-start-rsc0.1.48 → 0.1.49Dependent
@tanstack/react-start-server1.167.37 → 1.167.38Dependent
@tanstack/router-cli1.167.33 → 1.167.34Dependent
@tanstack/router-generator1.167.33 → 1.167.34Dependent
@tanstack/router-plugin1.168.35 → 1.168.36Dependent
@tanstack/router-vite-plugin1.167.35 → 1.167.36Dependent
@tanstack/solid-start1.168.47 → 1.168.48Dependent
@tanstack/solid-start-client1.168.29 → 1.168.30Dependent
@tanstack/solid-start-server1.167.36 → 1.167.37Dependent
@tanstack/start-client-core1.170.27 → 1.170.28Dependent
@tanstack/start-server-core1.169.31 → 1.169.32Dependent
@tanstack/start-static-server-functions1.167.32 → 1.167.33Dependent
@tanstack/start-storage-context1.167.29 → 1.167.30Dependent
@tanstack/vue-start1.168.46 → 1.168.47Dependent
@tanstack/vue-start-client1.167.32 → 1.167.33Dependent
@tanstack/vue-start-server1.167.36 → 1.167.37Dependent

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this test file

Comment threadpackages/react-router/src/link.tsx Outdated
Comment on lines +297 to +298
if (typeof to === 'string' && to.indexOf(':') > -1) {
try {
new URL(to)
if (isAbsoluteUrl(to)) {

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need nested ifs here, isAbsoluteUrl can just be part of the condition

Comment threadpackages/react-router/src/link.tsx
Comment threadpackages/react-router/src/link.tsx Outdated
Comment on lines +81 to +84
if (typeof to !== 'string' || to.indexOf(':') === -1) {
return undefined
}
try {
new URL(to)
if (isAbsoluteUrl(to)) {

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can re-arrange this into a single if block here

Comment threadpackages/solid-router/src/link.tsx Outdated
Comment on lines +179 to +182
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)) {

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can re-arrange this into a single if block

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this testing something useful? or are we just basically testing the built-in implementation of URL.canParse?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this, useful for the PR, but not to keep in the repo

@github-actions

github-actionsBot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: 893e4c48600f
  • Measured at: 2026-09-05T18:57:58.407Z
  • Baseline source: history:09da93257525
  • Dashboard: bundle-size history

The following scenarios have bundle-size changes compared with the baseline:

ScenarioCurrent (gzip)Initial (gzip)RawBrotliTrend
react-router.minimal83.8 KiB
-14 B
83.6 KiB
-11 B
262.0 KiB
-4 B
73.0 KiB
+28 B
███▁▅▅▅▅▆▆▆▃
react-router.full87.3 KiB
-3 B
87.1 KiB
-7 B
273.8 KiB
+8 B
76.0 KiB
+111 B
▇▇█▁▅▅▅▆▆▆▆▅
solid-router.minimal33.1 KiB
-3 B
33.0 KiB
-2 B
96.1 KiB
-4 B
29.9 KiB
-9 B
▇▇▇▁▇▇██████
solid-router.full38.0 KiB
+21 B
37.9 KiB
+17 B
110.8 KiB
-4 B
34.2 KiB
+57 B
▆▆▆▁▄▅▅▅▅▅▅█
vue-router.minimal49.5 KiB
+22 B
49.3 KiB
+24 B
138.2 KiB
+20 B
44.7 KiB
+40 B
███▁▄▄▅▄▄▄▄▇
vue-router.full55.1 KiB
+12 B
55.0 KiB
+12 B
156.4 KiB
+17 B
49.6 KiB
+84 B
▇▇█▁▃▄▄▄▄▄▄▅
react-start.minimal96.7 KiB
-10 B
96.5 KiB
-10 B
304.3 KiB
+19 B
83.8 KiB
+44 B
▇▇█▁▅▇▆▅▇▇▇▅
react-start.query-integration104.0 KiB
+17 B
103.9 KiB
+17 B
330.8 KiB
+23 B
90.1 KiB
-114 B
▆▆▇▁▄▅▅▅▅▅▅█
react-start.deferred-hydration97.4 KiB
+13 B
96.6 KiB
+7 B
305.7 KiB
+13 B
84.5 KiB
-57 B
▇▇█▁▃▆▆▅▆▆▆█
react-start.full99.8 KiB
+8 B
99.7 KiB
+9 B
314.0 KiB
-15 B
86.4 KiB
-64 B
▇▇█▁▅▆▇▆▆▆▆█
react-start.rsbuild.minimal100.0 KiB
+29 B
99.8 KiB
+29 B
314.6 KiB
-17 B
86.1 KiB
-182 B
███▁▄▃▃▂▃▃▃█
react-start.rsbuild.minimal-iife100.4 KiB
+24 B
100.2 KiB
+24 B
315.6 KiB
-17 B
86.6 KiB
-113 B
███▁▃▃▃▂▃▃▃▇
react-start.rsbuild.full103.3 KiB
+20 B
103.1 KiB
+20 B
324.7 KiB
-17 B
89.0 KiB
-44 B
█▇▇▁▃▂▃▁▃▃▃▆
solid-start.minimal46.0 KiB
0 B
45.8 KiB
-1 B
137.2 KiB
-4 B
41.0 KiB
+120 B
███▁▅▆█▇▇▇▇
solid-start.deferred-hydration49.1 KiB
-2 B
45.9 KiB
-3 B
144.7 KiB
-6 B
43.8 KiB
+67 B
▆▆▇▁▆▇█████▇
solid-start.full51.1 KiB
+4 B
50.9 KiB
+3 B
152.6 KiB
-4 B
45.3 KiB
+83 B
▇▇█▁▄▅▅▅▅▅▅▆
vue-start.minimal65.6 KiB
+9 B
65.5 KiB
+10 B
189.0 KiB
+23 B
58.4 KiB
+105 B
███▁▃▅▄▅▄▄▄▅
vue-start.full69.4 KiB
+13 B
69.3 KiB
+15 B
201.3 KiB
+11 B
61.8 KiB
+103 B
▇▇█▁▃▄▄▄▃▃▃▅

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.

@codspeed-hq

codspeed-hqBot commented Sep 5, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 7.4%

⚠️Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 9 improved benchmarks
❌ 8 (👁 8) regressed benchmarks
✅ 163 untouched benchmarks
⏩ 48 skipped benchmarks1

Performance Changes

ModeBenchmarkBASEHEADEfficiency
Memorymem client unique-location-churn (solid)492.4 KB235.8 KB×2.1
Memorymem server error-paths not-found (solid)897.8 KB551.3 KB+62.85%
Memorymem server peak-large-page (vue)1.1 MB1.1 MB+4.45%
Memorymem server server-fn-churn (vue)361.3 KB346 KB+4.44%
Memorymem server error-paths unmatched (solid)579.1 KB558.3 KB+3.74%
Simulationssr request loop (vue)719.9 ms694.5 ms+3.65%
Simulationclient-history navigation loop (vue)124.2 ms119.9 ms+3.54%
Memorymem server error-paths redirect (solid)370.9 KB358.4 KB+3.49%
Simulationclient-rewrites navigation loop (vue)161.3 ms156.5 ms+3.05%
👁Memorymem server error-paths not-found (vue)497.8 KB2,435.2 KB-79.56%
👁Memorymem server peak-large-page (solid)1.1 MB1.2 MB-5.73%
👁Memorymem server request-churn (solid)730.4 KB794 KB-8.01%
👁Memorymem server aborted-requests (react)783.4 KB963 KB-18.65%
👁Memorymem server error-paths not-found (react)402.1 KB440.7 KB-8.76%
👁Memorymem client navigation-churn (vue)1.5 MB1.6 MB-9.69%
👁Memorymem client unique-location-churn (vue)426.8 KB710.8 KB-39.95%
👁Memorymem client mount-unmount (solid)534.1 KB620.4 KB-13.9%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing codex/url-can-parse (fcca22d) with main (09da932)

Open in CodSpeed

Footnotes

  1. 48 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@nx-cloudnx-cloudBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Rerun CI

Nx Cloud View detailed reasoning on Nx Cloud ↗


🎓 Learn more about Self-Healing CI on nx.dev

@Sheraff
Sheraff merged commit 0497cae into mainSep 5, 2026
38 checks passed
@Sheraff
Sheraff deleted the codex/url-can-parse branch September 5, 2026 20:05
Sign up for freeto 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

@Sheraff@schiller-manuel