mirror of https://github.com/sveltejs/svelte
fix: handle hydration mismatches in await blocks (#15708)
* failing test for #15704 * handle hydration mismatches in await blocks * DRY out * changeset * update testpull/15726/head
parent
6c97a78049
commit
6d195f0350
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: handle hydration mismatches in await blocks
|
@ -0,0 +1,23 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
ssrHtml: '<button>fulfil</button><p>42</p><hr><p>loading...</p>',
|
||||||
|
html: '<button>fulfil</button><p>loading...</p><hr><p>42</p>',
|
||||||
|
|
||||||
|
props: {
|
||||||
|
browser: true
|
||||||
|
},
|
||||||
|
|
||||||
|
server_props: {
|
||||||
|
browser: false
|
||||||
|
},
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
|
||||||
|
flushSync(() => button?.click());
|
||||||
|
await Promise.resolve();
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>fulfil</button><p>42</p><hr><p>42</p>');
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,25 @@
|
|||||||
|
<script>
|
||||||
|
let { browser } = $props();
|
||||||
|
|
||||||
|
let fulfil;
|
||||||
|
let promise = new Promise((f) => (fulfil = f));
|
||||||
|
|
||||||
|
let a = browser ? promise : 42;
|
||||||
|
let b = browser ? 42 : promise;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => fulfil(42)}>fulfil</button>
|
||||||
|
|
||||||
|
{#await a}
|
||||||
|
{#if true}<p>loading...</p>{/if}
|
||||||
|
{:then a}
|
||||||
|
<p>{a}</p>
|
||||||
|
{/await}
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
{#await b}
|
||||||
|
{#if true}<p>loading...</p>{/if}
|
||||||
|
{:then b}
|
||||||
|
<p>{b}</p>
|
||||||
|
{/await}
|
Loading…
Reference in new issue