Skip to content

Commit cb18f8f

Browse files
trueadmRich-Harris
andauthored
chore: root effects should not have parents (#10950)
* chore: root effects should not have parents * tune * oops * Update packages/svelte/src/internal/client/runtime.js Co-authored-by: Rich Harris <[email protected]> --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 9a4cd7e commit cb18f8f

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ import { remove } from '../dom/reconciler.js';
3939
* @returns {import('#client').Effect}
4040
*/
4141
function create_effect(type, fn, sync, init = true) {
42+
var is_root = (type & ROOT_EFFECT) !== 0;
4243
/** @type {import('#client').Effect} */
43-
const effect = {
44-
parent: current_effect,
44+
var effect = {
45+
parent: is_root ? null : current_effect,
4546
dom: null,
4647
deps: null,
4748
f: type | DIRTY,
@@ -58,7 +59,7 @@ function create_effect(type, fn, sync, init = true) {
5859
effect.l = current_effect.l + 1;
5960
}
6061

61-
if (current_reaction !== null) {
62+
if (current_reaction !== null && !is_root) {
6263
if (current_reaction.effects === null) {
6364
current_reaction.effects = [effect];
6465
} else {
@@ -68,7 +69,7 @@ function create_effect(type, fn, sync, init = true) {
6869

6970
if (init) {
7071
if (sync) {
71-
const previously_flushing_effect = is_flushing_effect;
72+
var previously_flushing_effect = is_flushing_effect;
7273

7374
try {
7475
set_is_flushing_effect(true);

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,7 @@ export function remove_reactions(signal, start_index) {
360360
export function destroy_children(signal) {
361361
if (signal.effects) {
362362
for (var i = 0; i < signal.effects.length; i += 1) {
363-
var effect = signal.effects[i];
364-
365-
// TODO ideally root effects would be parentless
366-
if ((effect.f & ROOT_EFFECT) === 0) {
367-
destroy_effect(effect);
368-
}
363+
destroy_effect(signal.effects[i]);
369364
}
370365
signal.effects = null;
371366
}

0 commit comments

Comments
 (0)