mirror of https://github.com/sveltejs/svelte
Tweaks the timing when we resolve earlier/outdated batches. Instead of doing that right away we only do it once the current batch is committed. That way - the old batch will not render right away in case this was the last pending value, while the current batch is still pending, causing tearing (because we partly render values of the current batch in the old batch already) - the old batch still has a chance to resolve itself in the meantime if the current batch is still pending in other areaspull/18181/head
parent
cc505f0ec5
commit
036a8b6221
@ -0,0 +1,34 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
await tick();
|
||||
const [button1, button2, pop, shift] = target.querySelectorAll('button');
|
||||
const [p] = target.querySelectorAll('p');
|
||||
|
||||
button1.click();
|
||||
await tick();
|
||||
button2.click();
|
||||
await tick();
|
||||
assert.htmlEqual(p.innerHTML, `0 + 0 = 0 | 0 0`);
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
assert.htmlEqual(p.innerHTML, `0 + 0 = 0 | 0 0`);
|
||||
|
||||
pop.click();
|
||||
await tick();
|
||||
assert.htmlEqual(p.innerHTML, `0 + 0 = 0 | 0 0`);
|
||||
|
||||
pop.click();
|
||||
await tick();
|
||||
assert.htmlEqual(p.innerHTML, `1 + 0 = 1 | 1 0`);
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
pop.click();
|
||||
await tick();
|
||||
assert.htmlEqual(p.innerHTML, `1 + 2 = 3 | 1 1`);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,21 @@
|
||||
<script>
|
||||
const queue1 = [];
|
||||
const queue2 = [];
|
||||
|
||||
let a = $state(0);
|
||||
let b = $state(0);
|
||||
let c = $state(0);
|
||||
let d = $state(0)
|
||||
|
||||
function push(value, where = 1) {
|
||||
if (!value) return value;
|
||||
return new Promise(r => (where === 1 ? queue1 : queue2).push(() => r(value)));
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={() => {a++;c++}}>a / c</button>
|
||||
<button onclick={() => {b+=2;d++}}>b / d</button>
|
||||
<button onclick={() => queue1.pop()?.()}>pop 1</button>
|
||||
<button onclick={() => queue2.shift()?.()}>shift 2</button>
|
||||
|
||||
<p>{a} + {b} = {await push(a + b)} | {await push(c, 2)} {await push(d, 2)}</p>
|
||||
Loading…
Reference in new issue