Skip to content

Commit d2f453f

Browse files
authored
fix: don't restore batch in #await (#17051)
#16977 had one slight regression which might contribute to #16990: The batch from earlier was restored, but that doesn't make sense in this situations since this has nothing to do with our new async logic of batches suspending until pending work is done. As a result you could end up with a batch being created, and then the restore then instead reverting to an earlier batch that was already done, which means a ghost-batch ends up in the set of batches, subsequently triggering time traveling when it shouldn't. This may help with #16990 No test because basically impossible to do so
1 parent cc0143c commit d2f453f

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

.changeset/shaky-jars-cut.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: don't restore batch in `#await`

packages/svelte/src/internal/client/dom/blocks/await.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { queue_micro_task } from '../task.js';
1313
import { HYDRATION_START_ELSE, UNINITIALIZED } from '../../../../constants.js';
1414
import { is_runes } from '../../context.js';
15-
import { flushSync, is_flushing_sync } from '../../reactivity/batch.js';
15+
import { Batch, flushSync, is_flushing_sync } from '../../reactivity/batch.js';
1616
import { BranchManager } from './branches.js';
1717
import { capture, unset_context } from '../../reactivity/async.js';
1818

@@ -69,7 +69,11 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
6969
if (destroyed) return;
7070

7171
resolved = true;
72-
restore();
72+
// We don't want to restore the previous batch here; {#await} blocks don't follow the async logic
73+
// we have elsewhere, instead pending/resolve/fail states are each their own batch so to speak.
74+
restore(false);
75+
// Make sure we have a batch, since the branch manager expects one to exist
76+
Batch.ensure();
7377

7478
if (hydrating) {
7579
// `restore()` could set `hydrating` to `true`, which we very much

packages/svelte/src/internal/client/reactivity/async.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
set_hydrating,
3434
skip_nodes
3535
} from '../dom/hydration.js';
36-
import { create_text } from '../dom/operations.js';
3736

3837
/**
3938
*
@@ -102,11 +101,11 @@ export function capture() {
102101
var previous_dev_stack = dev_stack;
103102
}
104103

105-
return function restore() {
104+
return function restore(activate_batch = true) {
106105
set_active_effect(previous_effect);
107106
set_active_reaction(previous_reaction);
108107
set_component_context(previous_component_context);
109-
previous_batch?.activate();
108+
if (activate_batch) previous_batch?.activate();
110109

111110
if (was_hydrating) {
112111
set_hydrating(true);

0 commit comments

Comments
 (0)