unset context synchronously

pull/15844/head
Rich Harris 2 months ago
parent db272883cf
commit ed8d73f5a4

@ -57,6 +57,7 @@ export function flatten(sync, async, fn) {
} }
batch?.deactivate(); batch?.deactivate();
unset_context();
}) })
.catch((error) => { .catch((error) => {
boundary.error(error); boundary.error(error);
@ -81,10 +82,6 @@ function capture() {
if (DEV) { if (DEV) {
set_from_async_derived(null); set_from_async_derived(null);
} }
// prevent the active effect from outstaying its welcome
// TODO this feels brittle
queue_micro_task(unset_context);
}; };
} }
@ -123,7 +120,7 @@ export async function track_reactivity_loss(promise) {
}; };
} }
function unset_context() { export function unset_context() {
set_active_effect(null); set_active_effect(null);
set_active_reaction(null); set_active_reaction(null);
set_component_context(null); set_component_context(null);

@ -30,6 +30,7 @@ import { DEV } from 'esm-env';
import { invoke_error_boundary } from '../error-handling.js'; import { invoke_error_boundary } from '../error-handling.js';
import { old_values } from './sources.js'; import { old_values } from './sources.js';
import { unlink_effect } from './effects.js'; import { unlink_effect } from './effects.js';
import { unset_context } from './async.js';
/** @type {Set<Batch>} */ /** @type {Set<Batch>} */
const batches = new Set(); const batches = new Set();
@ -589,6 +590,8 @@ export function suspend() {
return function unsuspend() { return function unsuspend() {
boundary.update_pending_count(-1); boundary.update_pending_count(-1);
if (!pending) batch.decrement(); if (!pending) batch.decrement();
unset_context();
}; };
} }

@ -34,6 +34,7 @@ import { Boundary } from '../dom/blocks/boundary.js';
import { component_context } from '../context.js'; import { component_context } from '../context.js';
import { UNINITIALIZED } from '../../../constants.js'; import { UNINITIALIZED } from '../../../constants.js';
import { batch_deriveds, current_batch } from './batch.js'; import { batch_deriveds, current_batch } from './batch.js';
import { unset_context } from './async.js';
/** @type {Effect | null} */ /** @type {Effect | null} */
export let current_async_effect = null; export let current_async_effect = null;
@ -179,6 +180,8 @@ export function async_derived(fn, location) {
boundary.update_pending_count(-1); boundary.update_pending_count(-1);
if (!pending) batch.decrement(); if (!pending) batch.decrement();
} }
unset_context();
}; };
promise.then(handler, (e) => handler(null, e || 'unknown')); promise.then(handler, (e) => handler(null, e || 'unknown'));

Loading…
Cancel
Save