Skip to content

Commit ed8d73f

Browse files
committed
unset context synchronously
1 parent db27288 commit ed8d73f

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export function flatten(sync, async, fn) {
5757
}
5858

5959
batch?.deactivate();
60+
unset_context();
6061
})
6162
.catch((error) => {
6263
boundary.error(error);
@@ -81,10 +82,6 @@ function capture() {
8182
if (DEV) {
8283
set_from_async_derived(null);
8384
}
84-
85-
// prevent the active effect from outstaying its welcome
86-
// TODO this feels brittle
87-
queue_micro_task(unset_context);
8885
};
8986
}
9087

@@ -123,7 +120,7 @@ export async function track_reactivity_loss(promise) {
123120
};
124121
}
125122

126-
function unset_context() {
123+
export function unset_context() {
127124
set_active_effect(null);
128125
set_active_reaction(null);
129126
set_component_context(null);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { DEV } from 'esm-env';
3030
import { invoke_error_boundary } from '../error-handling.js';
3131
import { old_values } from './sources.js';
3232
import { unlink_effect } from './effects.js';
33+
import { unset_context } from './async.js';
3334

3435
/** @type {Set<Batch>} */
3536
const batches = new Set();
@@ -589,6 +590,8 @@ export function suspend() {
589590
return function unsuspend() {
590591
boundary.update_pending_count(-1);
591592
if (!pending) batch.decrement();
593+
594+
unset_context();
592595
};
593596
}
594597

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { Boundary } from '../dom/blocks/boundary.js';
3434
import { component_context } from '../context.js';
3535
import { UNINITIALIZED } from '../../../constants.js';
3636
import { batch_deriveds, current_batch } from './batch.js';
37+
import { unset_context } from './async.js';
3738

3839
/** @type {Effect | null} */
3940
export let current_async_effect = null;
@@ -179,6 +180,8 @@ export function async_derived(fn, location) {
179180
boundary.update_pending_count(-1);
180181
if (!pending) batch.decrement();
181182
}
183+
184+
unset_context();
182185
};
183186

184187
promise.then(handler, (e) => handler(null, e || 'unknown'));

0 commit comments

Comments
 (0)