Skip to content

Commit ec3589e

Browse files
authored
fix hydration of top-level content (#4550)
1 parent a66437b commit ec3589e

File tree

10 files changed

+14
-2
lines changed

10 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Allow `<svelte:self>` to be used in a slot ([#2798](https://github.com/sveltejs/svelte/issues/2798))
66
* Expose object of unknown props in `$$restProps` ([#2930](https://github.com/sveltejs/svelte/issues/2930))
7+
* Fix hydration of top-level content ([#4542](https://github.com/sveltejs/svelte/issues/4542))
78

89
## 3.19.2
910

src/runtime/internal/Component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler';
22
import { current_component, set_current_component } from './lifecycle';
33
import { blank_object, is_function, run, run_all, noop } from './utils';
4-
import { children } from './dom';
4+
import { children, detach } from './dom';
55
import { transition_in } from './transitions';
66

77
interface Fragment {
@@ -146,8 +146,10 @@ export function init(component, options, instance, create_fragment, not_equal, p
146146

147147
if (options.target) {
148148
if (options.hydrate) {
149+
const nodes = children(options.target);
149150
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
150-
$$.fragment && $$.fragment!.l(children(options.target));
151+
$$.fragment && $$.fragment!.l(nodes);
152+
nodes.forEach(detach);
151153
} else {
152154
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
153155
$$.fragment && $$.fragment!.c();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>Hello world</div>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<main>This should be thrown away</main>
2+
<div>hello</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>Hello world</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>Hello world</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<main>This should be thrown away</main>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>Hello world</div>

0 commit comments

Comments
 (0)