Skip to content

Commit

Permalink
fix hydration of top-level content (#4550)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau authored Mar 14, 2020
1 parent a66437b commit ec3589e
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

## 3.19.2

Expand Down
6 changes: 4 additions & 2 deletions src/runtime/internal/Component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler';
import { current_component, set_current_component } from './lifecycle';
import { blank_object, is_function, run, run_all, noop } from './utils';
import { children } from './dom';
import { children, detach } from './dom';
import { transition_in } from './transitions';

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

if (options.target) {
if (options.hydrate) {
const nodes = children(options.target);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment!.l(children(options.target));
$$.fragment && $$.fragment!.l(nodes);
nodes.forEach(detach);
} else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment!.c();
Expand Down
1 change: 1 addition & 0 deletions test/hydration/samples/top-level-cleanup-2/_after.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Hello world</div>
2 changes: 2 additions & 0 deletions test/hydration/samples/top-level-cleanup-2/_before.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<main>This should be thrown away</main>
<div>hello</div>
1 change: 1 addition & 0 deletions test/hydration/samples/top-level-cleanup-2/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
1 change: 1 addition & 0 deletions test/hydration/samples/top-level-cleanup-2/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Hello world</div>
1 change: 1 addition & 0 deletions test/hydration/samples/top-level-cleanup/_after.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Hello world</div>
1 change: 1 addition & 0 deletions test/hydration/samples/top-level-cleanup/_before.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<main>This should be thrown away</main>
1 change: 1 addition & 0 deletions test/hydration/samples/top-level-cleanup/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
1 change: 1 addition & 0 deletions test/hydration/samples/top-level-cleanup/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Hello world</div>

0 comments on commit ec3589e

Please sign in to comment.