Skip to content

Commit 61bae04

Browse files
committed
fix: repair href attribute mismatches
The reasoning in #9662 turns out to be false: While it's true that the href would resolve to the same URL on the initial page, once you're doing a client-side navigation to a URL at a different depth, the relative path would now point to the wrong location. Therefore we need to repair href hydration mismatches fixes sveltejs/kit#12254
1 parent e366c49 commit 61bae04

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changeset/two-cats-approve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: repair `href` attribute mismatches

packages/svelte/src/internal/client/dom/elements/attributes.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ export function set_attribute(element, attribute, value, skip_warning) {
8989
if (hydrating) {
9090
attributes[attribute] = element.getAttribute(attribute);
9191

92-
if (attribute === 'src' || attribute === 'href' || attribute === 'srcset') {
92+
// Don't include href: When using a base path, SvelteKit will by default render relative URLs on the server
93+
// and use root-relative links on the client. While the href would resolve to the same URL on the initial
94+
// page, once you're doing a client-side navigation to a URL at a different depth, the relative path would
95+
// now point to the wrong location. Therefore we need to repair href mismatches.
96+
if (attribute === 'src' || attribute === 'srcset') {
9397
if (!skip_warning) {
9498
check_src_in_dev_hydration(element, attribute, value);
9599
}

0 commit comments

Comments
 (0)