Skip to content

Commit a3387ab

Browse files
committed
fix test
1 parent 315a44b commit a3387ab

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ export function set_attribute(element, attribute, value, skip_warning) {
9393
// and use root-relative links on the client. While the href would resolve to the same URL on the initial
9494
// page, once you're doing a client-side navigation to a URL at a different depth, the relative path would
9595
// now point to the wrong location. Therefore we need to repair href mismatches.
96-
if (attribute === 'src' || attribute === 'srcset') {
96+
if (
97+
attribute === 'src' ||
98+
attribute === 'srcset' ||
99+
(attribute === 'href' && element.nodeName === 'LINK')
100+
) {
97101
if (!skip_warning) {
98102
check_src_in_dev_hydration(element, attribute, value);
99103
}
@@ -392,7 +396,7 @@ function check_src_in_dev_hydration(element, attribute, value) {
392396

393397
w.hydration_attribute_changed(
394398
attribute,
395-
element.outerHTML.replace(element.innerHTML, '...'),
399+
element.outerHTML.replace(element.innerHTML, element.innerHTML && '...'),
396400
String(value)
397401
);
398402
}

packages/svelte/tests/hydration/samples/ignore-mismatched-href/_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ export default test({
1010
},
1111

1212
test(assert, target) {
13-
assert.equal(target.querySelector('a')?.getAttribute('href'), '/bar');
13+
assert.equal(target.querySelector('link')?.getAttribute('href'), '/bar');
1414
},
1515

1616
errors: [
17-
'The `href` attribute on `<a href="/bar">...</a>` changed its value between server and client renders. The client value, `/foo`, will be ignored in favour of the server value'
17+
'The `href` attribute on `<link href="/bar">` changed its value between server and client renders. The client value, `/foo`, will be ignored in favour of the server value'
1818
]
1919
});

packages/svelte/tests/hydration/samples/ignore-mismatched-href/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
let { browser } = $props();
33
</script>
44

5-
<a href={browser ? '/foo': '/bar'}>foo</a>
5+
<link href={browser ? '/foo' : '/bar'} />

0 commit comments

Comments
 (0)