Skip to content

Commit

Permalink
fix: repair href attribute mismatches
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dummdidumm committed Aug 26, 2024
1 parent e366c49 commit 61bae04
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/two-cats-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: repair `href` attribute mismatches
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 61bae04

Please sign in to comment.