Skip to content

Commit 6a0e4a2

Browse files
committed
create separate component_root effect
1 parent 0efb47e commit 6a0e4a2

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,24 @@ export function inspect_effect(fn) {
244244
/**
245245
* Internal representation of `$effect.root(...)`
246246
* @param {() => void | (() => void)} fn
247-
* @returns {(options?: { outro?: boolean }) => void}
247+
* @returns {() => void}
248248
*/
249249
export function effect_root(fn) {
250250
const effect = create_effect(ROOT_EFFECT, fn, true);
251251

252+
return () => {
253+
destroy_effect(effect);
254+
};
255+
}
256+
257+
/**
258+
* An effect root whose children can transition out
259+
* @param {() => void} fn
260+
* @returns {(options?: { outro?: boolean }) => void}
261+
*/
262+
export function component_root(fn) {
263+
const effect = create_effect(ROOT_EFFECT, fn, true);
264+
252265
return (options = {}) => {
253266
if (options.outro) {
254267
pause_effect(effect, () => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from './dom/operations.js';
1111
import { HYDRATION_END, HYDRATION_ERROR, HYDRATION_START } from '../../constants.js';
1212
import { push, pop, component_context, active_effect } from './runtime.js';
13-
import { effect_root, branch } from './reactivity/effects.js';
13+
import { component_root, branch } from './reactivity/effects.js';
1414
import {
1515
hydrate_next,
1616
hydrate_node,
@@ -204,7 +204,7 @@ function _mount(Component, { target, anchor, props = {}, events, context, intro
204204
// @ts-expect-error will be defined because the render effect runs synchronously
205205
var component = undefined;
206206

207-
var unmount = effect_root(() => {
207+
var unmount = component_root(() => {
208208
var anchor_node = anchor ?? target.appendChild(create_text());
209209

210210
branch(() => {

0 commit comments

Comments
 (0)