Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rich-months-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

chore: deactivate current_batch by default in unset_context
4 changes: 2 additions & 2 deletions packages/svelte/src/internal/client/dom/blocks/await.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { queue_micro_task } from '../task.js';
import { HYDRATION_START_ELSE, UNINITIALIZED } from '../../../../constants.js';
import { is_runes } from '../../context.js';
import { Batch, flushSync, is_flushing_sync } from '../../reactivity/batch.js';
import { Batch, current_batch, flushSync, is_flushing_sync } from '../../reactivity/batch.js';
import { BranchManager } from './branches.js';
import { capture, unset_context } from '../../reactivity/async.js';

Expand Down Expand Up @@ -84,7 +84,7 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
try {
fn();
} finally {
unset_context();
unset_context(false);

// without this, the DOM does not update until two ticks after the promise
// resolves, which is unexpected behaviour (and somewhat irksome to test)
Expand Down
6 changes: 2 additions & 4 deletions packages/svelte/src/internal/client/reactivity/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export function flatten(blockers, sync, async, fn) {
}
}

batch?.deactivate();
unset_context();
}

Expand Down Expand Up @@ -207,10 +206,11 @@ export async function* for_await_track_reactivity_loss(iterable) {
}
}

export function unset_context() {
export function unset_context(deactivate_batch = true) {
set_active_effect(null);
set_active_reaction(null);
set_component_context(null);
if (deactivate_batch) current_batch?.deactivate();

if (DEV) {
set_from_async_derived(null);
Expand Down Expand Up @@ -271,9 +271,7 @@ export function run(thunks) {

promise.finally(() => {
blocker.settled = true;

unset_context();
current_batch?.deactivate();
});
}

Expand Down
3 changes: 0 additions & 3 deletions packages/svelte/src/internal/client/reactivity/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ let is_flushing = false;
export let is_flushing_sync = false;

export class Batch {
committed = false;

/**
* The current values of any sources that are updated in this batch
* They keys of this map are identical to `this.#previous`
Expand Down Expand Up @@ -425,7 +423,6 @@ export class Batch {
batch_values = previous_batch_values;
}

this.committed = true;
batches.delete(this);
}

Expand Down
12 changes: 1 addition & 11 deletions packages/svelte/src/internal/client/reactivity/deriveds.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,7 @@ export function async_derived(fn, label, location) {
// If this code is changed at some point, make sure to still access the then property
// of fn() to read any signals it might access, so that we track them as dependencies.
// We call `unset_context` to undo any `save` calls that happen inside `fn()`
Promise.resolve(fn())
.then(d.resolve, d.reject)
.then(() => {
if (batch === current_batch && batch.committed) {
// if the batch was rejected as stale, we need to cleanup
// after any `$.save(...)` calls inside `fn()`
batch.deactivate();
}

unset_context();
});
Promise.resolve(fn()).then(d.resolve, d.reject).finally(unset_context);
} catch (error) {
d.reject(error);
unset_context();
Expand Down
Loading