Skip to content

useRelativeHref#96068

Draft
acdlite wants to merge 1 commit into
canaryfrom
use-relative-href
Draft

useRelativeHref#96068
acdlite wants to merge 1 commit into
canaryfrom
use-relative-href

Conversation

@acdlite

@acdlite acdlite commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Adds a new App Router hook, useRelativeHref(target) (currently prefixed with unstable_), which computes a relative URL reference from the current page to a target URL. For example, if the current page is '/chat/123/settings', then useRelativeHref('/chat/[id]') returns './' and useRelativeHref('/chat/[id]/members') returns '../members/'. Neither result references the value of [id]. The result can be passed directly to a Link or anchor element's href prop.

The benefit of relative hrefs is that you can link to pages without needing to reference dynamic params in the shared part of the URL. This means that unlike usePathname, useRelativeHref can often be included during static prerendering (i.e. without being wrapped in a Suspense boundary).

There will still be cases where a relative href cannot be generated statically. If the target is at or below the current page, the result must spell the page's final URL segment back out (relative resolution drops it): on '/chat/123', useRelativeHref('/chat/[id]/settings') returns './123/settings/', which includes the value of [id] and therefore deopts when that value is only known at request time. Routes with a catch-all param always resolve at request time, since the amount of traversal depends on how many segments the catch-all matched. However, not all pages that use catch-all params will necessarily trigger a dynamic deopt: as long as there's at least one parallel route that can be fully resolved, we can know the shape of the URL.

Targets that aren't root-relative paths — absolute URLs ('https://…', 'mailto:…'), protocol-relative URLs, and hash- or query-only references ('#faq', '?tab=1') — are returned unchanged, so any href that's valid on a <Link> can be passed through the hook without changing its behavior.

The current page's URL parts are computed on the server and sent to the client as part of the initial RSC payload, so the initial render — including hydration — resolves hrefs against the same values on both sides. After the first router state update, the hook resolves against the URL pathname instead, the same source that populates usePathname; on the client these are always equivalent.

Review notes

Most of the diff is tests. I would start by reviewing the computeRelativeHref function, here:

export function computeRelativeHref(
target: string,
baseRoute: readonly BaseUrlPart[],
trailingSlash: boolean
): RelativeHrefResult {
// Non-root-relative targets pass through verbatim (see above). '//' is a
// protocol-relative URL, not a path.
if (target[0] !== '/' || target[1] === '/') {
return {
href: target,
resolvedAgainstBase: false,
dependsOnUnknownBasePart: false,
}
}
// Split off the target's query and hash — everything from the first '?'
// or '#' — to be carried over to the result verbatim. Only the path part
// participates in matching.
let suffixStart = target.indexOf('?')
const hashStart = target.indexOf('#')
if (hashStart !== -1 && (suffixStart === -1 || hashStart < suffixStart)) {
suffixStart = hashStart
}
const suffix = suffixStart === -1 ? '' : target.slice(suffixStart)
const targetPath = suffixStart === -1 ? target : target.slice(0, suffixStart)
const targetSegments = splitPathSegments(targetPath)
const baseParts: readonly BaseUrlPart[] = baseRoute
// The URL depth of the current page.
const pageDepth = baseParts.length
// Relative URL resolution drops the base URL's final segment, unless the
// URL ends in a slash (i.e. `trailingSlash: true`).
const baseDepth = trailingSlash ? pageDepth : Math.max(0, pageDepth - 1)
// Find the shared prefix between the target's pattern segments and the
// current page's URL parts.
let shared = 0
let dependsOnUnknownParam = false
while (shared < targetSegments.length && shared < pageDepth) {
const targetSegment = targetSegments[shared]
if (isDynamicPatternSegment(targetSegment)) {
// '[id]' matches any one URL part, known or unknown.
if (
process.env.NODE_ENV !== 'production' &&
isCatchAllPatternSegment(targetSegment)
) {
warnCatchAllPatternTarget(target, targetSegment)
}
} else if (baseParts[shared] === null) {
// A concrete target segment compared against an unknown part: whether
// they match can't be known statically, and the two outcomes produce
// different hrefs. Treat it as a divergence — but the caller must
// deopt to dynamic rendering, where the part is known and the href
// may come out shorter.
dependsOnUnknownParam = true
break
} else if (targetSegment !== baseParts[shared]) {
break
}
shared++
}
// The shared prefix can extend past the resolution base (e.g. the target is
// the page's own route); only the portion within the base is expressed as
// traversal. The rest must be spelled back out.
const effectiveShared = Math.min(shared, baseDepth)
const ups = baseDepth - effectiveShared
// Spell out the concrete URL parts of the current page between the
// resolution base and the end of the shared prefix. This covers the
// own-route and descendant cases, where the page's final segment(s) must be
// spelled back out because relative resolution drops them. An unknown part
// here means the href needs a value that doesn't exist yet — the caller
// must deopt, and the target's pattern text stands in as a placeholder.
const spelled: string[] = []
for (let i = effectiveShared; i < shared; i++) {
const part = baseParts[i]
if (part === null) {
dependsOnUnknownParam = true
spelled.push(targetSegments[i])
} else {
spelled.push(part)
}
}
// `dependsOnUnknownParam` is final from here on: both places that set it
// are above.
// Development-only: when a fallback-shell prerender is about to deopt to
// dynamic rendering, skip the unresolved-segment warning below — the
// result reflects values the prerender doesn't know, and the render is
// abandoned and redone at request time anyway.
// `getPrerenderFallbackParams` is server-only (undefined in the browser)
// and only returns params during a prerender that has unknown ones.
let suppressUnresolvedWarning = false
if (process.env.NODE_ENV !== 'production' && dependsOnUnknownParam) {
const fallbackParams = getPrerenderFallbackParams?.()
suppressUnresolvedWarning =
fallbackParams != null && fallbackParams.size > 0
}
// Spell out the target's pattern segments past the shared prefix. Static
// text is emitted as-is. A dynamic segment here has no value available, so
// its literal pattern text is emitted (technically a valid URL segment).
for (let i = shared; i < targetSegments.length; i++) {
const segment = targetSegments[i]
if (
process.env.NODE_ENV !== 'production' &&
isDynamicPatternSegment(segment)
) {
if (isCatchAllPatternSegment(segment)) {
warnCatchAllPatternTarget(target, segment)
} else if (!suppressUnresolvedWarning) {
console.error(
`unstable_useRelativeHref('${target}') could not resolve the dynamic ` +
`segment(s) ${segment} because it doesn't lie on the current ` +
`route. The literal segment text was left in the result, which ` +
`is almost certainly a mistake.`
)
}
}
spelled.push(segment)
}
let href = ups > 0 ? '../'.repeat(ups) : './'
for (const segment of spelled) {
href += segment + '/'
}
href += suffix
return {
href,
resolvedAgainstBase: true,
dependsOnUnknownBasePart: dependsOnUnknownParam,
}
}

That function contains the core algorithm.

@vercel vercel Bot 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.

Additional Suggestion:

The client-only hook unstable_useRelativeHref is missing from the next/navigation entry in invalid_server_lib_apis_mapping, so importing it in a Server Component doesn't produce the friendly RSC build error.

Fix on Vercel

@acdlite
acdlite force-pushed the use-relative-href branch from 74488f5 to 304efed Compare July 22, 2026 17:21
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Stats from current PR

🔴 1 regression, 1 improvement

Metric Canary PR Change Trend
node_modules Size 527 MB 528 MB 🔴 +790 kB (+0%) ▁████
Webpack Warm (First Request) 3.588s 3.418s 🟢 170ms (-5%) ▁█▁▃▃
📊 All Metrics
📖 Metrics Glossary

Dev Server Metrics:

  • Listen = TCP port starts accepting connections
  • First Request = HTTP server returns successful response
  • Cold = Fresh build (no cache)
  • Warm = With cached build artifacts

Build Metrics:

  • Fresh = Clean build (no .next directory)
  • Cached = With existing .next directory

Change Thresholds:

  • Time: Changes < 50ms AND < 10%, OR < 2% are insignificant
  • Size: Changes < 1KB AND < 1% are insignificant
  • All other changes are flagged to catch regressions

⚡ Dev Server

Metric Canary PR Change Trend
Cold (Listen) 814ms 813ms ▂▂▁▁▁
Cold (Ready in log) 803ms 806ms ▂▁▁▁▁
Cold (First Request) 1.377s 1.408s ▃▁▁▁▁
Warm (Listen) 814ms 814ms ▂▁▁▂▁
Warm (Ready in log) 807ms 809ms ▂▁▁▁▁
Warm (First Request) 1.367s 1.377s ▂▁▁▁▁
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 813ms 812ms ▁████
Cold (Ready in log) 780ms 779ms ▁▄▃▄▅
Cold (First Request) 3.626s 3.638s ▂▆▃▂▅
Warm (Listen) 812ms 811ms █████
Warm (Ready in log) 776ms 773ms ▁▂▂▄▁
Warm (First Request) 3.588s 3.418s 🟢 170ms (-5%) ▁█▁▃▃

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 5.626s 5.556s ▄▁▁▁▁
Cached Build 5.640s 5.668s ▃▁▁▁▁
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 24.786s 24.939s ▄▅▃▃▂
Cached Build 25.738s 25.523s ▁▅▁▃▁
node_modules Size 527 MB 528 MB 🔴 +790 kB (+0%) ▁████
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles
Canary PR Change
00v6npozcc3c3.js gzip 155 B N/A -
0a-p0meqxynjz.js gzip 10.3 kB N/A -
0avtke4yefj4-.js gzip 13.1 kB N/A -
0cz1d0mv5g_q7.js gzip 39.4 kB 39.4 kB
0nvyq--brb2d1.js gzip 71.1 kB N/A -
0pt5of3ch6d2u.js gzip 13.6 kB N/A -
0xnsdo-6y9r3k.js gzip 5.72 kB N/A -
0yi7is8u4covm.js gzip 8.77 kB N/A -
1aqu9ze6v_-92.js gzip 157 B N/A -
1bhefyyiiy1a1.js gzip 160 B N/A -
1elt1qium-r2m.css gzip 115 B 115 B
1lh1fi2q329kp.js gzip 155 B N/A -
1lsl-hvtjoz38.js gzip 7.4 kB N/A -
1ltc02dslhmu0.js gzip 156 B N/A -
1prv-wg6jgtt2.js gzip 8.77 kB N/A -
1t47vod02e_4a.js gzip 8.75 kB N/A -
1tbq0-klq39t1.js gzip 156 B N/A -
1tf1phijqlx9j.js gzip 220 B 220 B
1tw002sq5bo4l.js gzip 10 kB N/A -
1wlerik1n7zbr.js gzip 8.7 kB N/A -
22vemgj_ppw9g.js gzip 157 B N/A -
28koph4jjzmen.js gzip 45.2 kB N/A -
2lviwqiqxm904.js gzip 3.52 kB N/A -
2pevdqjpbf3xk.js gzip 9.45 kB N/A -
2ppm-9338hg-g.js gzip 155 B N/A -
2qd2anu9eizlz.js gzip 8.75 kB N/A -
2sv39ae5_8vfj.js gzip 8.81 kB N/A -
2utx6n7w65xqa.js gzip 8.7 kB N/A -
2vo_g-1nu597x.js gzip 153 B N/A -
3_gkkw57bfro8.js gzip 168 B N/A -
3-ukivglqkfeq.js gzip 8.78 kB N/A -
325xisqrylugu.js gzip 450 B N/A -
3e9jui3nrs0cq.js gzip 161 B N/A -
3jc9ghvds1spf.js gzip 2.29 kB N/A -
3juwkvkgvywfe.js gzip 10.6 kB N/A -
3kbove7q58uqh.js gzip 13.2 kB N/A -
3qn7vntp30gaj.js gzip 1.47 kB N/A -
3tg5xymt-y3pf.js gzip 157 B N/A -
3y5l7macq6332.js gzip 156 B N/A -
45bnqre7r-j34.js gzip 65.6 kB N/A -
turbopack-0d..qkmb.js gzip 3.81 kB N/A -
turbopack-0m..pdb9.js gzip 3.78 kB N/A -
turbopack-1-..1ho9.js gzip 3.8 kB N/A -
turbopack-1d..316h.js gzip 3.82 kB N/A -
turbopack-1w..lyf1.js gzip 3.81 kB N/A -
turbopack-25..qyhv.js gzip 3.81 kB N/A -
turbopack-2c..lyeg.js gzip 3.81 kB N/A -
turbopack-2h..a-uq.js gzip 3.8 kB N/A -
turbopack-2j..bz11.js gzip 3.81 kB N/A -
turbopack-3-..gj1l.js gzip 3.81 kB N/A -
turbopack-36..evj4.js gzip 3.81 kB N/A -
turbopack-37.._yox.js gzip 3.8 kB N/A -
turbopack-3p..5n5c.js gzip 3.81 kB N/A -
turbopack-41..w-sa.js gzip 3.81 kB N/A -
00zqn4kqpayw4.js gzip N/A 157 B -
030a1njeh5b77.js gzip N/A 10 kB -
0hn69zqsx6fry.js gzip N/A 157 B -
0ot0qt5np20h7.js gzip N/A 8.78 kB -
0oyb0b9ahgr21.js gzip N/A 161 B -
0p45qqrw5lrs8.js gzip N/A 157 B -
0rxt9rt_30eey.js gzip N/A 13.2 kB -
12m9rr7_7cexd.js gzip N/A 8.7 kB -
16l4dguper5a6.js gzip N/A 152 B -
186r3y_rfvr0b.js gzip N/A 8.78 kB -
19btj2c7v_78e.js gzip N/A 169 B -
19v97848yrjp7.js gzip N/A 8.81 kB -
1nd_0rwgz2ozk.js gzip N/A 9.45 kB -
1oi9pltr_e10m.js gzip N/A 10.6 kB -
1rd9tzqgzsz2w.js gzip N/A 8.77 kB -
1rq1g_cwv642d.js gzip N/A 10.3 kB -
1ueabh0lmyo3o.js gzip N/A 156 B -
1uojw_uabeg93.js gzip N/A 450 B -
1w-7lusgyl81y.js gzip N/A 8.7 kB -
1xed2u0fz6rpq.js gzip N/A 156 B -
2-kdoq-jy_crq.js gzip N/A 7.41 kB -
21h56wdn9zddo.js gzip N/A 8.75 kB -
24qd_fib-5_av.js gzip N/A 155 B -
2hambmneabdgz.js gzip N/A 154 B -
2k7aci4f2g01r.js gzip N/A 71.1 kB -
2lg10omv7xu14.js gzip N/A 3.52 kB -
2lpk_v-xyf2dm.js gzip N/A 162 B -
2ovff1533zvno.js gzip N/A 13.2 kB -
2s4z8jy0z7v93.js gzip N/A 1.46 kB -
2t-2au3m9wrr3.js gzip N/A 157 B -
2y6gb5bs4mnam.js gzip N/A 8.75 kB -
341h71ln1jpl3.js gzip N/A 2.29 kB -
34ttpt_n7605h.js gzip N/A 5.72 kB -
35zwnfb32_rzf.js gzip N/A 45.9 kB -
3p_g-hdd5xct9.js gzip N/A 156 B -
3vdh6_u50pu5t.js gzip N/A 13.6 kB -
3vughx3b6vlec.js gzip N/A 65.6 kB -
turbopack-0-..q9wo.js gzip N/A 3.82 kB -
turbopack-0-..0m7z.js gzip N/A 3.8 kB -
turbopack-07..z-48.js gzip N/A 3.8 kB -
turbopack-08..o1ab.js gzip N/A 3.81 kB -
turbopack-09..77_5.js gzip N/A 3.8 kB -
turbopack-0c..9irk.js gzip N/A 3.81 kB -
turbopack-0v..wea4.js gzip N/A 3.8 kB -
turbopack-1-..4ctq.js gzip N/A 3.78 kB -
turbopack-26..lrlq.js gzip N/A 3.8 kB -
turbopack-2j..hgfw.js gzip N/A 3.8 kB -
turbopack-2k..c7-r.js gzip N/A 3.8 kB -
turbopack-2u..-guf.js gzip N/A 3.8 kB -
turbopack-3v..1h0o.js gzip N/A 3.8 kB -
turbopack-3x..vvxx.js gzip N/A 3.8 kB -
Total 448 kB 449 kB ⚠️ +805 B

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 780 B 772 B 🟢 8 B (-1%)
Total 780 B 772 B ✅ -8 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 433 B 432 B
Total 433 B 432 B ✅ -1 B

📦 Webpack

Client

Main Bundles
Canary PR Change
3322-HASH.js gzip 63.7 kB N/A -
4191.HASH.js gzip 169 B N/A -
7920-HASH.js gzip 4.68 kB N/A -
9784-HASH.js gzip 5.63 kB N/A -
b1ad9f4c-HASH.js gzip 62.9 kB N/A -
framework-HASH.js gzip 59.7 kB 59.7 kB
main-app-HASH.js gzip 255 B 252 B 🟢 3 B (-1%)
main-HASH.js gzip 40 kB 40 kB
webpack-HASH.js gzip 1.68 kB 1.68 kB
3577.HASH.js gzip N/A 168 B -
578-HASH.js gzip N/A 65.1 kB -
8590-HASH.js gzip N/A 5.61 kB -
9750-HASH.js gzip N/A 4.69 kB -
a8984546-HASH.js gzip N/A 62.9 kB -
Total 239 kB 240 kB ⚠️ +1.38 kB
Polyfills
Canary PR Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Total 39.4 kB 39.4 kB
Pages
Canary PR Change
_app-HASH.js gzip 194 B 193 B
_error-HASH.js gzip 181 B 182 B
css-HASH.js gzip 334 B 331 B
dynamic-HASH.js gzip 1.81 kB 1.81 kB
edge-ssr-HASH.js gzip 255 B 253 B
head-HASH.js gzip 349 B 351 B
hooks-HASH.js gzip 382 B 384 B
image-HASH.js gzip 581 B 582 B
index-HASH.js gzip 260 B 259 B
link-HASH.js gzip 2.48 kB 2.48 kB
routerDirect..HASH.js gzip 317 B 318 B
script-HASH.js gzip 384 B 386 B
withRouter-HASH.js gzip 316 B 315 B
1afbb74e6ecf..834.css gzip 106 B 106 B
Total 7.95 kB 7.95 kB ⚠️ +1 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 128 kB 128 kB
page.js gzip 287 kB 287 kB
Total 415 kB 415 kB ✅ -752 B
Middleware
Canary PR Change
middleware-b..fest.js gzip 618 B 618 B
middleware-r..fest.js gzip 156 B 156 B
middleware.js gzip 45.3 kB 45.3 kB
edge-runtime..pack.js gzip 842 B 842 B
Total 46.9 kB 46.9 kB ⚠️ +48 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 718 B 718 B
Total 718 B 718 B
Build Cache
Canary PR Change
0.pack gzip 4.83 MB 4.86 MB 🔴 +24.2 kB (+1%)
index.pack gzip 120 kB 120 kB
index.pack.old gzip 120 kB 121 kB 🔴 +1.6 kB (+1%)
Total 5.07 MB 5.1 MB ⚠️ +26.2 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 366 kB 366 kB
app-page-exp..prod.js gzip 202 kB 202 kB
app-page-tur...dev.js gzip 365 kB 366 kB
app-page-tur..prod.js gzip 202 kB 202 kB
app-page-tur...dev.js gzip 362 kB 362 kB
app-page-tur..prod.js gzip 200 kB 200 kB
app-page.run...dev.js gzip 362 kB 363 kB
app-page.run..prod.js gzip 200 kB 200 kB
app-route-ex...dev.js gzip 81.8 kB 81.8 kB
app-route-ex..prod.js gzip 55.6 kB 55.6 kB
app-route-tu...dev.js gzip 81.8 kB 81.8 kB
app-route-tu..prod.js gzip 55.6 kB 55.6 kB
app-route-tu...dev.js gzip 81.4 kB 81.4 kB
app-route-tu..prod.js gzip 55.4 kB 55.4 kB
app-route.ru...dev.js gzip 81.4 kB 81.4 kB
app-route.ru..prod.js gzip 55.4 kB 55.4 kB
dist_client_...dev.js gzip 324 B 324 B
dist_client_...dev.js gzip 326 B 326 B
dist_client_...dev.js gzip 318 B 318 B
dist_client_...dev.js gzip 317 B 317 B
pages-api-tu...dev.js gzip 45.4 kB 45.4 kB
pages-api-tu..prod.js gzip 34.1 kB 34.1 kB
pages-api.ru...dev.js gzip 45.4 kB 45.4 kB
pages-api.ru..prod.js gzip 34.1 kB 34.1 kB
pages-turbo....dev.js gzip 54.9 kB 54.9 kB
pages-turbo...prod.js gzip 39.7 kB 39.7 kB
pages.runtim...dev.js gzip 54.8 kB 54.8 kB
pages.runtim..prod.js gzip 39.7 kB 39.7 kB
server.runti..prod.js gzip 67.8 kB 67.8 kB
use-cache-pr...dev.js gzip 71.6 kB 71.6 kB
use-cache-pr...dev.js gzip 71.6 kB 71.6 kB
use-cache-pr...dev.js gzip 69.9 kB 69.9 kB
use-cache-pr...dev.js gzip 69.9 kB 69.9 kB
Total 3.51 MB 3.51 MB ⚠️ +3.12 kB
📝 Changed Files (12 files)

Files with changes:

  • app-page-exp..ntime.dev.js
  • app-page-exp..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page.runtime.dev.js
  • app-page.runtime.prod.js
  • app-route-ex..ntime.dev.js
  • app-route-tu..ntime.dev.js
  • app-route-tu..ntime.dev.js
  • app-route.runtime.dev.js
View diffs
app-page-exp..ntime.dev.js
failed to diff
app-page-exp..time.prod.js
failed to diff
app-page-tur..ntime.dev.js
failed to diff
app-page-tur..time.prod.js
failed to diff
app-page-tur..ntime.dev.js
failed to diff
app-page-tur..time.prod.js
failed to diff
app-page.runtime.dev.js
failed to diff
app-page.runtime.prod.js
failed to diff
app-route-ex..ntime.dev.js

Diff too large to display

app-route-tu..ntime.dev.js

Diff too large to display

app-route-tu..ntime.dev.js

Diff too large to display

app-route.runtime.dev.js

Diff too large to display

📎 Tarball URL
https://vercel-packages.vercel.app/next/commits/c709c9d2a5f4f7533b1ff5c61baff063bcdb32f2/next

Commit: c709c9d

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 33a1f85

@acdlite
acdlite force-pushed the use-relative-href branch 4 times, most recently from d267c18 to c709c9d Compare July 22, 2026 20:44
Adds a new App Router hook, useRelativeHref(target) (currently prefixed with
unstable_), which computes a relative URL reference from the current page to a
target URL. For example, if the current page is '/chat/123/settings', then
`useRelativeHref('/chat/[id]')` returns './' and
`useRelativeHref('/chat/[id]/members')` returns '../members/'. Neither result
references the value of [id]. The result can be passed directly to a Link or
anchor element's href prop.

The benefit of relative hrefs is that you can link to pages without needing to
reference dynamic params in the shared part of the URL. This means that unlike
`usePathname`, `useRelativeHref` can often be included during static
prerendering (i.e. without being wrapped in a Suspense boundary).

There will still be cases where a relative href cannot be generated
statically. If the target is at or below the current page, the result must
spell the page's final URL segment back out (relative resolution drops it):
on '/chat/123', `useRelativeHref('/chat/[id]/settings')` returns
'./123/settings/', which includes the value of [id] and therefore deopts when
that value is only known at request time. Routes with a catch-all param
always resolve at request time, since the amount of traversal depends on how
many segments the catch-all matched. However, not all pages that use
catch-all params will necessarily trigger a dynamic deopt: as long as there's
at least one parallel route that can be fully resolved, we can know the shape
of the URL.

Targets that aren't root-relative paths — absolute URLs ('https://…',
'mailto:…'), protocol-relative URLs, and hash- or query-only references
('#faq', '?tab=1') — are returned unchanged, so any href that's valid on a
<Link> can be passed through the hook without changing its behavior.

The current page's URL parts are computed on the server and sent to the
client as part of the initial RSC payload, so the initial render — including
hydration — resolves hrefs against the same values on both sides. After the
first router state update, the hook resolves against the URL pathname
instead, the same source that populates usePathname; on the client these are
always equivalent.
@acdlite
acdlite force-pushed the use-relative-href branch from c709c9d to 33a1f85 Compare July 22, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant