Skip to content

Commit c4d8d40

Browse files
authored
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
1 parent b235161 commit c4d8d40

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ export function user_effect(fn) {
203203
var context = /** @type {ComponentContext} */ (component_context);
204204
(context.e ??= []).push({
205205
fn,
206-
parent: active_effect
206+
effect: active_effect,
207+
reaction: active_reaction
207208
});
208209
} else {
209210
var signal = effect(fn);

packages/svelte/src/internal/client/runtime.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,15 +1063,18 @@ export function pop(component) {
10631063
const component_effects = context_stack_item.e;
10641064
if (component_effects !== null) {
10651065
var previous_effect = active_effect;
1066+
var previous_reaction = active_reaction;
10661067
context_stack_item.e = null;
10671068
try {
10681069
for (var i = 0; i < component_effects.length; i++) {
10691070
var component_effect = component_effects[i];
1070-
set_active_effect(component_effect.parent);
1071+
set_active_effect(component_effect.effect);
1072+
set_active_reaction(component_effect.reaction);
10711073
effect(component_effect.fn);
10721074
}
10731075
} finally {
10741076
set_active_effect(previous_effect);
1077+
set_active_reaction(previous_reaction);
10751078
}
10761079
}
10771080
component_context = context_stack_item.p;

packages/svelte/src/internal/client/types.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Store } from '#shared';
22
import { STATE_SYMBOL } from './constants.js';
3-
import type { Effect, Source, Value } from './reactivity/types.js';
3+
import type { Effect, Source, Value, Reaction } from './reactivity/types.js';
44

55
type EventCallback = (event: Event) => boolean;
66
export type EventCallbackMap = Record<string, EventCallback | EventCallback[]>;
@@ -15,7 +15,11 @@ export type ComponentContext = {
1515
/** context */
1616
c: null | Map<unknown, unknown>;
1717
/** deferred effects */
18-
e: null | Array<{ fn: () => void | (() => void); parent: null | Effect }>;
18+
e: null | Array<{
19+
fn: () => void | (() => void);
20+
effect: null | Effect;
21+
reaction: null | Reaction;
22+
}>;
1923
/** mounted */
2024
m: boolean;
2125
/**

0 commit comments

Comments
 (0)