fix: ensure component effects have the correct reaction owner (#13308)

* fix: ensure component effects have the correct reaction owner

* fix: ensure component effects have the correct reaction owner

* lint
pull/13311/head
Dominic Gannaway 2 months ago committed by GitHub
parent b23516121b
commit c4d8d405c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -203,7 +203,8 @@ export function user_effect(fn) {
var context = /** @type {ComponentContext} */ (component_context);
(context.e ??= []).push({
fn,
parent: active_effect
effect: active_effect,
reaction: active_reaction
});
} else {
var signal = effect(fn);

@ -1063,15 +1063,18 @@ export function pop(component) {
const component_effects = context_stack_item.e;
if (component_effects !== null) {
var previous_effect = active_effect;
var previous_reaction = active_reaction;
context_stack_item.e = null;
try {
for (var i = 0; i < component_effects.length; i++) {
var component_effect = component_effects[i];
set_active_effect(component_effect.parent);
set_active_effect(component_effect.effect);
set_active_reaction(component_effect.reaction);
effect(component_effect.fn);
}
} finally {
set_active_effect(previous_effect);
set_active_reaction(previous_reaction);
}
}
component_context = context_stack_item.p;

@ -1,6 +1,6 @@
import type { Store } from '#shared';
import { STATE_SYMBOL } from './constants.js';
import type { Effect, Source, Value } from './reactivity/types.js';
import type { Effect, Source, Value, Reaction } from './reactivity/types.js';
type EventCallback = (event: Event) => boolean;
export type EventCallbackMap = Record<string, EventCallback | EventCallback[]>;
@ -15,7 +15,11 @@ export type ComponentContext = {
/** context */
c: null | Map<unknown, unknown>;
/** deferred effects */
e: null | Array<{ fn: () => void | (() => void); parent: null | Effect }>;
e: null | Array<{
fn: () => void | (() => void);
effect: null | Effect;
reaction: null | Reaction;
}>;
/** mounted */
m: boolean;
/**

Loading…
Cancel
Save