mirror of https://github.com/sveltejs/svelte
fix: discard batches made obsolete by commit (#17934)
Batches that are made stale (because of a `STALE_REACTION`) can end up sticking around indefinitely, forcing every subsequent batch into time-traveling mode and causing incorrect `previous` values to be rendered. This partially fixes it, by discarding any older batches that are subsets of a batch currently being committed. It's not a complete fix, though — if an earlier batch is stale but is _not_ a subset of the committed batch, it becomes a zombie, and its changes will never be applied. Haven't quite figured out how to think about that yet. ### Before submitting the PR, please make sure you do the following - [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs - [x] Prefix your PR title with `feat:`, `fix:`, `chore:`, or `docs:`. - [x] This message body should clearly illustrate what problems it solves. - [x] Ideally, include a test that fails without this PR but passes with it. - [x] If this PR changes code within `packages/svelte/src`, add a changeset (`npx changeset`). ### Tests and linting - [x] Run the tests with `pnpm test` and lint the project with `pnpm lint`pull/17600/merge
parent
8b86bdd82d
commit
98e8b635fa
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: discard batches made obsolete by commit
|
||||
@ -0,0 +1,89 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
await tick();
|
||||
|
||||
const [increment, shift, pop] = target.querySelectorAll('button');
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>1</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>1 = 1</p>
|
||||
`
|
||||
);
|
||||
|
||||
increment.click();
|
||||
await tick();
|
||||
increment.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>3</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>1 = 1</p>
|
||||
`
|
||||
);
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>3</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>1 = 1</p>
|
||||
`
|
||||
);
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>3</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>3 = 3</p>
|
||||
`
|
||||
);
|
||||
|
||||
increment.click();
|
||||
await tick();
|
||||
increment.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>5</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>3 = 3</p>
|
||||
`
|
||||
);
|
||||
|
||||
pop.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>5</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>5 = 5</p>
|
||||
`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,36 @@
|
||||
<script>
|
||||
import { getAbortSignal } from 'svelte';
|
||||
|
||||
const queue = [];
|
||||
|
||||
function push(value) {
|
||||
if (value === 1) return 1;
|
||||
const d = Promise.withResolvers();
|
||||
|
||||
queue.push(() => d.resolve(value));
|
||||
|
||||
const signal = getAbortSignal();
|
||||
signal.onabort = () => d.reject(signal.reason);
|
||||
|
||||
return d.promise;
|
||||
}
|
||||
|
||||
function shift() {
|
||||
queue.shift()?.();
|
||||
}
|
||||
|
||||
function pop() {
|
||||
queue.pop()?.();
|
||||
}
|
||||
|
||||
let n = $state(1);
|
||||
</script>
|
||||
|
||||
<button onclick={() => n++}>
|
||||
{$state.eager(n)}
|
||||
</button>
|
||||
|
||||
<button onclick={shift}>shift</button>
|
||||
<button onclick={pop}>pop</button>
|
||||
|
||||
<p>{n} = {await push(n)}</p>
|
||||
Loading…
Reference in new issue