Repository navigation
Description
Describe the bug
With experimental.async, an update that mounts a new <svelte:boundary> with a pending snippet is applied to the DOM at once, but its batch stays linked until the boundary's reads settle. While it is linked, any later batch that doesn't write one of the same sources undoes its writes in apply(). Effects that later batch re-runs render from the state before the first update, and nothing re-runs them when the first batch commits. The page keeps showing the old state for good.
In the reproduction below, step 1 writes rows and mounts a row whose await is pending. The page correctly shows rows: 1, saveable: true. Step 2 replaces rows[0], a different source, which dirties the saveable derived and the {#each}. That batch reads rows through batch_values, which apply() has set back to []. The row disappears, and the page shows rows: 0, saveable: false with Save disabled. Step 3 resolves the read and the first batch commits, but the page stays at rows: 0, although rows holds one row.
- Expected after step 3:
a (per hour),rows: 1, saveable: true, Save enabled. - Actual:
rows: 0, saveable: false, Save disabled, no row. - Control: step 1 then step 3, without step 2, ends correctly at
a (per minute),rows: 1, saveable: true.
We hit this in an app where loading a saved view mounts rows whose reads are slow. An edit made while they load left Save and the other actions disabled until a reload.
Why it happens
As far as I can tell:
- In
#process, the boundary's reads count toward#pendingbut not toward#blocking_pending, so#is_deferred()is false. The batch flushes its effects, but because#pending > 0it is not unlinked or committed. - In a later batch's
apply(), the loop overfirst_batch … #nextundoes every non-intersecting batch's changes frombatch.previous. That includes this batch, whose values are already on screen. - When the first batch commits after its reads resolve, the effects the later batch rendered from the undone values are not dirty, so they are never re-run.
This looks related to #19047 (a mixed-version UI that persists after all promises resolve) and #19157 (a value leaking between batches), but the trigger here is a flushed, still-linked batch, not a derived's first read. #18997 makes it easier to hit, since re-runs multiply while batches overlap.
What we do for now
We ship a local patch that skips undoing a batch whose effects have already been flushed:
#started = false;
+ #flushed = false;
@@ #process()
flush_queued_effects(render_effects);
flush_queued_effects(effects);
previous_batch = null;
+ this.#flushed = true;
@@ apply()
- if (batch === this || batch.is_fork) continue;
+ if (batch === this || batch.is_fork || batch.#flushed) continue;It fixes the reproduction and our app, and the rest of our test suite passes with it. It is not a complete fix. If a later batch merges into a flushed batch (#merge → #process) and that re-process is deferred by new blocking work, the merged values are visible to other batches before they are on screen. We also tried tracking the flushed values per source, so that only drawn values are protected and later merged ones are still undone. That broke a different flow in our app, so we didn't pursue it.
Reproduction
Playground (5.57.3). Click 1, 2, 3 in order.
<script>
let rows = $state([]);
// A derived over the rows, like "is there anything to save?"
const saveable = $derived(rows.filter((row) => row.name).length > 0);
const gate = Promise.withResolvers();
const slow = (value) => gate.promise.then(() => value);
</script>
<p>
<button onclick={() => (rows = [{ name: 'a', hourly: false }])}>1. load a row</button>
<button onclick={() => (rows[0] = { ...rows[0], hourly: !rows[0].hourly })}>2. edit the row</button>
<button onclick={() => gate.resolve()}>3. resolve its read</button>
</p>
{#each rows as row}
<!-- a NEW boundary with a pending snippet: its read does not block the batch that mounted it -->
<svelte:boundary>
{#snippet pending()}
<p>loading {row.name}…</p>
{/snippet}
<p>{await slow(row.name)} ({row.hourly ? 'per hour' : 'per minute'})</p>
</svelte:boundary>
{/each}
<p>
rows: {rows.length}, saveable: {saveable}
<button disabled={!saveable}>Save</button>
</p>Logs
No errors or warnings; the stale state is rendered silently.System Info
svelte: 5.57.3 (playground); also 5.57.2 with @sveltejs/kit 2.70.3 in our app
compilerOptions.experimental.async: true
Browsers: Brave (Chromium) on macOS; Chromium headless (Playwright)Severity
annoyance
Activity
svelte-triage-bot commentedon Nov 9, 2026
I reproduced the issue, but could not produce a safe, verified fix.
What I tried
set: pipefailncd: invalid option name; running its documented download.js command directly succeeded. Added a test exercising the original load/edit/resolve sequence without changing the reproduction component.pnpm test runtime-runeswith the regression marked solo on main c60f6e1.: Both DOM and hydration variants failed for the reported reason: the row disappeared permanently, rows showed 0, saveable showed false, and Save remained disabled after resolution.pnpm test runtime-runes, then restored the issue branch.: Both DOM and hydration regression variants passed: the expected row, rows: 1, saveable: true, and enabled Save were restored. Only these two variants were run; no full-suite verification was attempted. No product files were edited, committed, or pushed. The untracked regression and /workspace/notes.md remain available.Why I stopped
Stopped because an open PR already fixes the reproduced bug: “https://github.com/sveltejs/svelte/pull/19030” (fix: batch views of reactions). The exact regression fails in both rendering modes on main and passes in both on that PR’s current head, c8513b9. Its solution publishes flushed writes independently of the linked batch’s outstanding async ownership, avoiding the reporter’s unsafe blanket exemption for ever-flushed batches. A competing product patch is unnecessary; the regression can be incorporated into #19030.
miguelhoyoabascal-code commentedon Nov 13, 2026
Another trigger for the same thing, without
{#each}: a{#key}block with anawait, and a second unrelated write one microtask later (in our SvelteKit app this isreplaceStateupdatingpage.urlright after a debounced filter value changes).Clicking B, then A, then B: the keyed block and
urlupdate, butasked:stays one step behind every time (asked: A · url: B · data for B, thenasked: B · url: A · data for A, …). Writingurl = nextsynchronously instead of in a microtask renders correctly. Svelte 5.57.3, Chrome 156.