fix hydration

aaa
Dominic Gannaway 8 months ago
parent e8e723b181
commit 8eeeeff141

@ -1,6 +1,6 @@
/** @import { Effect, TemplateNode, } from '#client' */ /** @import { Effect, TemplateNode, } from '#client' */
import { BOUNDARY_EFFECT, EFFECT_TRANSPARENT } from '../../constants.js'; import { BOUNDARY_EFFECT, DESTROYED, EFFECT_TRANSPARENT } from '../../constants.js';
import { import {
block, block,
branch, branch,
@ -27,7 +27,7 @@ import {
set_hydrate_node set_hydrate_node
} from '../hydration.js'; } from '../hydration.js';
import { get_next_sibling } from '../operations.js'; import { get_next_sibling } from '../operations.js';
import { queue_boundary_micro_task } from '../task.js'; import { queue_boundary_micro_task, queue_post_micro_task } from '../task.js';
const ASYNC_INCREMENT = Symbol(); const ASYNC_INCREMENT = Symbol();
const ASYNC_DECREMENT = Symbol(); const ASYNC_DECREMENT = Symbol();
@ -231,6 +231,14 @@ export function boundary(node, props, boundary_fn) {
// need to use hydration boundary comments to report whether // need to use hydration boundary comments to report whether
// the pending or main block was rendered for a given // the pending or main block was rendered for a given
// boundary, and hydrate accordingly // boundary, and hydrate accordingly
queueMicrotask(() => {
if ((!boundary_effect || boundary_effect.f & DESTROYED) !== 0) return;
destroy_effect(boundary_effect);
with_boundary(boundary, () => {
boundary_effect = branch(() => boundary_fn(anchor));
});
});
} else { } else {
boundary_effect = branch(() => boundary_fn(anchor)); boundary_effect = branch(() => boundary_fn(anchor));
} }

@ -1,4 +1,4 @@
import { tick } from 'svelte'; import { flushSync, tick } from 'svelte';
import { deferred } from '../../../../src/internal/shared/utils.js'; import { deferred } from '../../../../src/internal/shared/utils.js';
import { test } from '../../test'; import { test } from '../../test';
@ -22,6 +22,7 @@ export default test({
await Promise.resolve(); await Promise.resolve();
await Promise.resolve(); await Promise.resolve();
await tick(); await tick();
flushSync();
assert.htmlEqual(target.innerHTML, '<p class="cool">hello</p>'); assert.htmlEqual(target.innerHTML, '<p class="cool">hello</p>');
d = deferred(); d = deferred();

@ -1,4 +1,4 @@
import { tick } from 'svelte'; import { flushSync, tick } from 'svelte';
import { deferred } from '../../../../src/internal/shared/utils.js'; import { deferred } from '../../../../src/internal/shared/utils.js';
import { test } from '../../test'; import { test } from '../../test';
@ -24,6 +24,7 @@ export default test({
await Promise.resolve(); await Promise.resolve();
await Promise.resolve(); await Promise.resolve();
await tick(); await tick();
flushSync();
assert.htmlEqual(target.innerHTML, '<p>42</p>'); assert.htmlEqual(target.innerHTML, '<p>42</p>');
component.num = 2; component.num = 2;

@ -1,4 +1,4 @@
import { tick } from 'svelte'; import { flushSync, tick } from 'svelte';
import { deferred } from '../../../../src/internal/shared/utils.js'; import { deferred } from '../../../../src/internal/shared/utils.js';
import { test } from '../../test'; import { test } from '../../test';
@ -22,6 +22,7 @@ export default test({
await Promise.resolve(); await Promise.resolve();
await Promise.resolve(); await Promise.resolve();
await tick(); await tick();
flushSync();
assert.htmlEqual(target.innerHTML, '<p>a</p><p>b</p><p>c</p>'); assert.htmlEqual(target.innerHTML, '<p>a</p><p>b</p><p>c</p>');
d = deferred(); d = deferred();

@ -1,4 +1,4 @@
import { tick } from 'svelte'; import { flushSync, tick } from 'svelte';
import { deferred } from '../../../../src/internal/shared/utils.js'; import { deferred } from '../../../../src/internal/shared/utils.js';
import { test } from '../../test'; import { test } from '../../test';
@ -22,6 +22,7 @@ export default test({
await Promise.resolve(); await Promise.resolve();
await Promise.resolve(); await Promise.resolve();
await tick(); await tick();
flushSync();
assert.htmlEqual(target.innerHTML, '<p>hello</p>'); assert.htmlEqual(target.innerHTML, '<p>hello</p>');
} }
}); });

@ -1,4 +1,4 @@
import { tick } from 'svelte'; import { flushSync, tick } from 'svelte';
import { deferred } from '../../../../src/internal/shared/utils.js'; import { deferred } from '../../../../src/internal/shared/utils.js';
import { test } from '../../test'; import { test } from '../../test';
@ -22,6 +22,7 @@ export default test({
await Promise.resolve(); await Promise.resolve();
await Promise.resolve(); await Promise.resolve();
await tick(); await tick();
flushSync();
assert.htmlEqual(target.innerHTML, '<h1>yes</h1>'); assert.htmlEqual(target.innerHTML, '<h1>yes</h1>');
d = deferred(); d = deferred();

@ -1,4 +1,4 @@
import { tick } from 'svelte'; import { flushSync, tick } from 'svelte';
import { deferred } from '../../../../src/internal/shared/utils.js'; import { deferred } from '../../../../src/internal/shared/utils.js';
import { test } from '../../test'; import { test } from '../../test';
@ -22,6 +22,7 @@ export default test({
await Promise.resolve(); await Promise.resolve();
await Promise.resolve(); await Promise.resolve();
await tick(); await tick();
flushSync();
assert.htmlEqual(target.innerHTML, '<h1>hello</h1>'); assert.htmlEqual(target.innerHTML, '<h1>hello</h1>');
const h1 = target.querySelector('h1'); const h1 = target.querySelector('h1');

@ -1,4 +1,4 @@
import { tick } from 'svelte'; import { flushSync, tick } from 'svelte';
import { deferred } from '../../../../src/internal/shared/utils.js'; import { deferred } from '../../../../src/internal/shared/utils.js';
import { test } from '../../test'; import { test } from '../../test';
@ -22,6 +22,7 @@ export default test({
await Promise.resolve(); await Promise.resolve();
await Promise.resolve(); await Promise.resolve();
await tick(); await tick();
flushSync();
assert.htmlEqual(target.innerHTML, '<h1>hello</h1>'); assert.htmlEqual(target.innerHTML, '<h1>hello</h1>');
d = deferred(); d = deferred();

@ -1,4 +1,4 @@
import { tick } from 'svelte'; import { flushSync, tick } from 'svelte';
import { deferred } from '../../../../src/internal/shared/utils.js'; import { deferred } from '../../../../src/internal/shared/utils.js';
import { test } from '../../test'; import { test } from '../../test';
@ -20,6 +20,7 @@ export default test({
d.resolve('hello'); d.resolve('hello');
await Promise.resolve(); await Promise.resolve();
await tick(); await tick();
flushSync();
assert.htmlEqual(target.innerHTML, '<p>hello</p>'); assert.htmlEqual(target.innerHTML, '<p>hello</p>');
} }
}); });

Loading…
Cancel
Save