mirror of https://github.com/sveltejs/svelte
fix: don't fail on `flushSync` while flushing effects (#16674)
* fix: don't fail on `flushSync` while flushing effects WIP fixes #16640 * cleanup, unrelated lint * revert * fixpull/16677/head
parent
5314f48d95
commit
bde51ed7dc
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: don't fail on `flushSync` while flushing effects
|
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
let { text } = $props();
|
||||||
|
|
||||||
|
$effect(() => console.log(text));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{text}
|
@ -0,0 +1,12 @@
|
|||||||
|
import { async_mode } from '../../../helpers';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
// In legacy mode this succeeds and logs 'hello'
|
||||||
|
// In async mode this throws an error because flushSync is called inside an effect
|
||||||
|
async test({ assert, target, logs }) {
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>show</button> <div>hello</div>`);
|
||||||
|
assert.deepEqual(logs, ['hello']);
|
||||||
|
},
|
||||||
|
runtime_error: async_mode ? 'flush_sync_in_effect' : undefined
|
||||||
|
});
|
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
import { flushSync, mount } from 'svelte'
|
||||||
|
import Child from './Child.svelte';
|
||||||
|
|
||||||
|
let show = $state(false);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => show = true}>show</button>
|
||||||
|
|
||||||
|
<div {@attach (target) => {
|
||||||
|
mount(Child, { target, props: { text: 'hello' } });
|
||||||
|
flushSync();
|
||||||
|
}}></div>
|
Loading…
Reference in new issue