Skip to content

Commit ae23e25

Browse files
committed
remove some stuff we dont need
1 parent 54cec48 commit ae23e25

File tree

2 files changed

+9
-42
lines changed

2 files changed

+9
-42
lines changed

packages/svelte/src/internal/client/dom/blocks/if.js

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ import {
2424
export function if_block(anchor, get_condition, consequent_fn, alternate_fn, elseif = false) {
2525
hydrate_block_anchor(anchor);
2626

27-
/** @type {undefined | import('#client').Dom} */
28-
let consequent_dom;
29-
30-
/** @type {undefined | import('#client').Dom} */
31-
let alternate_dom;
32-
3327
/** @type {import('#client').Effect | null} */
3428
let consequent_effect = null;
3529

@@ -68,48 +62,24 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
6862
if (consequent_effect) {
6963
resume_effect(consequent_effect);
7064
} else {
71-
consequent_effect = render_effect(() => {
72-
consequent_dom = consequent_fn(anchor);
73-
74-
return () => {
75-
// TODO make this unnecessary by linking the dom to the effect,
76-
// and removing automatically on teardown
77-
if (consequent_dom !== undefined) {
78-
remove(consequent_dom);
79-
consequent_dom = undefined;
80-
}
81-
};
82-
}, true);
65+
consequent_effect = render_effect(() => consequent_fn(anchor), true);
8366
}
8467

8568
if (alternate_effect) {
8669
pause_effect(alternate_effect, () => {
8770
alternate_effect = null;
88-
if (alternate_dom) remove(alternate_dom);
8971
});
9072
}
9173
} else {
9274
if (alternate_effect) {
9375
resume_effect(alternate_effect);
9476
} else if (alternate_fn) {
95-
alternate_effect = render_effect(() => {
96-
alternate_dom = alternate_fn(anchor);
97-
98-
return () => {
99-
// TODO make this unnecessary by linking the dom to the effect,
100-
// and removing automatically on teardown
101-
if (alternate_dom !== undefined) {
102-
remove(alternate_dom);
103-
alternate_dom = undefined;
104-
}
105-
};
106-
}, true);
77+
alternate_effect = render_effect(() => alternate_fn(anchor), true);
10778
}
10879

10980
if (consequent_effect) {
11081
pause_effect(consequent_effect, () => {
11182
consequent_effect = null;
112-
if (consequent_dom) remove(consequent_dom);
11383
});
11484
}
11585
}
@@ -125,16 +95,7 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
12595
}
12696

12797
if_effect.ondestroy = () => {
128-
// TODO make this unnecessary by linking the dom to the effect,
129-
// and removing automatically on teardown
130-
if (consequent_dom !== undefined) {
131-
remove(consequent_dom);
132-
}
133-
134-
if (alternate_dom !== undefined) {
135-
remove(alternate_dom);
136-
}
137-
98+
// TODO why is this not automatic? this should be children of `if_effect`
13899
if (consequent_effect) {
139100
destroy_effect(consequent_effect);
140101
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from '../constants.js';
2525
import { set } from './sources.js';
2626
import { noop } from '../../common.js';
27+
import { remove } from '../dom/reconciler.js';
2728

2829
/**
2930
* @param {import('./types.js').EffectType} type
@@ -241,6 +242,11 @@ export function destroy_effect(effect) {
241242
}
242243

243244
effect.teardown?.();
245+
246+
if (effect.dom !== null) {
247+
remove(effect.dom);
248+
}
249+
244250
effect.ondestroy?.();
245251

246252
// @ts-expect-error

0 commit comments

Comments
 (0)