Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/plenty-plums-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure snippets after empty text correctly hydrate
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export function RegularElement(node, context) {
arg = b.member(arg, 'content');
}

process_children(trimmed, () => b.call('$.child', arg), true, {
process_children(trimmed, (is_text) => b.call('$.child', arg, is_text && b.true), true, {
...context,
state: child_state
});
Expand Down
8 changes: 7 additions & 1 deletion packages/svelte/src/internal/client/dom/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ export function get_next_sibling(node) {
* Don't mark this as side-effect-free, hydration needs to walk all nodes
* @template {Node} N
* @param {N} node
* @param {boolean} is_text
* @returns {Node | null}
*/
export function child(node) {
export function child(node, is_text) {
if (!hydrating) {
return get_first_child(node);
}
Expand All @@ -101,6 +102,11 @@ export function child(node) {
// Child can be null if we have an element with a single child, like `<p>{text}</p>`, where `text` is empty
if (child === null) {
child = hydrate_node.appendChild(create_text());
} else if (is_text && child.nodeType !== 3) {
var text = create_text();
child?.before(text);
set_hydrate_node(text);
return text;
}

set_hydrate_node(child);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
let {prop = '', children} = $props()
</script>

<div>{prop}{@render children()}</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { test } from '../../test';

export default test({
compileOptions: {
dev: true // Render in dev mode to check that the validation error is not thrown
},
html: `<div>123</div`
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import Child from './Child.svelte';
</script>

<Child>123</Child>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function Skip_static_subtree($$anchor, $$props) {
var fragment = root();
var main = $.sibling($.first_child(fragment), 2);
var h1 = $.child(main);
var text = $.child(h1);
var text = $.child(h1, true);

$.reset(h1);

Expand Down