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 https://github.com/sveltejs/kit/issues/12254
pull/13032/head
Simon Holthausen 3 months ago
parent e366c49a86
commit 61bae04e3f

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: repair `href` attribute mismatches

@ -89,7 +89,11 @@ export function set_attribute(element, attribute, value, skip_warning) {
if (hydrating) {
attributes[attribute] = element.getAttribute(attribute);
if (attribute === 'src' || attribute === 'href' || attribute === 'srcset') {
// Don't include href: When using a base path, SvelteKit will by default render relative URLs on the server
// and use root-relative links on the client. While 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 mismatches.
if (attribute === 'src' || attribute === 'srcset') {
if (!skip_warning) {
check_src_in_dev_hydration(element, attribute, value);
}

Loading…
Cancel
Save