mirror of https://github.com/sveltejs/svelte
fix: address bug in before/after update (#9448)
* fix: address bug in before/after update fix: address bug in before/after update * Add changeset * use every instead of filter - more explicit and enables early-exit from the loop * Update logic and comment --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/9464/head
parent
f5101c0d8c
commit
9eb969ddd4
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: corrects a beforeUpdate/afterUpdate bug
|
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
const {count, increment} = $props();
|
||||
</script>
|
||||
|
||||
<button onclick={increment}>
|
||||
{count}
|
||||
</button>
|
@ -0,0 +1,15 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: '<button>0</button>',
|
||||
|
||||
async test({ assert, target, component }) {
|
||||
const [btn] = target.querySelectorAll('button');
|
||||
flushSync(() => {
|
||||
btn.click();
|
||||
});
|
||||
assert.deepEqual(component.log, ['beforeUpdate', 'afterUpdate']);
|
||||
assert.htmlEqual(target.innerHTML, `<button>1</button>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,22 @@
|
||||
<script>
|
||||
import Child from './Child.svelte'
|
||||
import {afterUpdate, beforeUpdate} from 'svelte';
|
||||
|
||||
const {log = []} = $props();
|
||||
|
||||
let count = $state(0);
|
||||
|
||||
const increment = () => {
|
||||
count++;
|
||||
}
|
||||
|
||||
beforeUpdate(() => {
|
||||
log.push('beforeUpdate');
|
||||
});
|
||||
|
||||
afterUpdate(() => {
|
||||
log.push('afterUpdate');
|
||||
});
|
||||
</script>
|
||||
|
||||
<Child count={count} increment={increment} />
|
Loading…
Reference in new issue