fix leakage of context

aaa
Dominic Gannaway 8 months ago
parent 28842f463b
commit 5f5375a3f1

@ -18,7 +18,7 @@ export function AwaitExpression(node, context) {
b.await(
b.call(
'$.suspend',
node.argument && /** @type {Expression} */ (context.visit(node.argument))
node.argument && b.thunk(/** @type {Expression} */ (context.visit(node.argument)))
)
),
'exit'

@ -266,10 +266,10 @@ export function trigger_async_boundary(effect, trigger) {
/**
* @template T
* @param {Promise<T>} promise
* @param {() => Promise<T> | Promise<T>} input
* @returns {Promise<{ exit: () => T }>}
*/
export async function suspend(promise) {
export async function suspend(input) {
var previous_effect = active_effect;
var previous_reaction = active_reaction;
var previous_component_context = component_context;
@ -290,6 +290,12 @@ export async function suspend(promise) {
// @ts-ignore
boundary?.fn(ASYNC_INCREMENT);
const promise = typeof input === 'function' ? input() : input;
// Ensure we reset the context back so it doesn't leak
set_active_effect(previous_effect);
set_active_reaction(previous_reaction);
set_component_context(previous_component_context);
const value = await promise;
return {

Loading…
Cancel
Save