mirror of https://github.com/sveltejs/svelte
fix: adjust render effect ordering (#10783)
We can simplify pre effects by not doing the flush logic at all now. Instead we can move the flushing logic to the only place its needed – for beforeUpdatepull/10789/head
parent
0c1026f166
commit
2cb78ac253
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: adjust render effect ordering
|
@ -0,0 +1,21 @@
|
||||
import { test } from '../../test';
|
||||
import { log } from './log.js';
|
||||
|
||||
export default test({
|
||||
get props() {
|
||||
return { n: 0 };
|
||||
},
|
||||
|
||||
before_test() {
|
||||
log.length = 0;
|
||||
},
|
||||
|
||||
async test({ assert, component }) {
|
||||
assert.deepEqual(log, ['$effect.pre 0', 'another $effect.pre 1', 'render n0', 'render i1']);
|
||||
|
||||
log.length = 0;
|
||||
component.n += 1;
|
||||
|
||||
assert.deepEqual(log, ['$effect.pre 1', 'another $effect.pre 2', 'render n1', 'render i2']);
|
||||
}
|
||||
});
|
@ -0,0 +1,2 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
import { untrack } from 'svelte';
|
||||
import { log } from './log.js';
|
||||
let { n = 0 } = $props();
|
||||
let i = $state(0);
|
||||
function logRender(i) {
|
||||
log.push(`render ${i}`);
|
||||
}
|
||||
$effect.pre(() => {
|
||||
log.push(`$effect.pre ${n}`);
|
||||
untrack(() => i++)
|
||||
});
|
||||
$effect.pre(() => {
|
||||
log.push('another $effect.pre '+ i);
|
||||
})
|
||||
</script>
|
||||
|
||||
<p>{logRender(`n${n}`)}</p>
|
||||
<p>{logRender(`i${i}`)}</p>
|
Loading…
Reference in new issue