Skip to content

Commit 6cfed04

Browse files
authored
simplify (#11570)
1 parent 801cea7 commit 6cfed04

File tree

2 files changed

+32
-71
lines changed

2 files changed

+32
-71
lines changed

packages/svelte/src/internal/client/dom/legacy/lifecycle.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
import { CLEAN } from '../../constants.js';
21
import { run, run_all } from '../../../shared/utils.js';
32
import { user_pre_effect, user_effect } from '../../reactivity/effects.js';
4-
import {
5-
current_component_context,
6-
current_effect,
7-
deep_read_state,
8-
flush_local_render_effects,
9-
get,
10-
untrack
11-
} from '../../runtime.js';
3+
import { current_component_context, deep_read_state, get, untrack } from '../../runtime.js';
124

135
/**
146
* Legacy-mode only: Call `onMount` callbacks and set up `beforeUpdate`/`afterUpdate` effects
@@ -26,13 +18,6 @@ export function init() {
2618
user_pre_effect(() => {
2719
observe_all(context);
2820
run_all(callbacks.b);
29-
// beforeUpdate might change state that affects rendering, ensure the render effects following from it
30-
// are batched up with the current run. Avoids for example child components rerunning when they're
31-
// now hidden because beforeUpdate did set an if block to false.
32-
const parent = current_effect?.parent;
33-
if (parent != null && (parent.f & CLEAN) === 0) {
34-
flush_local_render_effects(parent);
35-
}
3621
});
3722
}
3823

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

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,27 @@ function infinite_loop_guard() {
516516
*/
517517
function flush_queued_root_effects(root_effects) {
518518
infinite_loop_guard();
519-
for (var i = 0; i < root_effects.length; i++) {
520-
flush_nested_effects(root_effects[i]);
519+
520+
var previously_flushing_effect = is_flushing_effect;
521+
is_flushing_effect = true;
522+
523+
try {
524+
for (var i = 0; i < root_effects.length; i++) {
525+
var effect = root_effects[i];
526+
527+
// When working with custom elements, the root effects might not have a root
528+
if (effect.first === null && (effect.f & BRANCH_EFFECT) === 0) {
529+
flush_queued_effects([effect]);
530+
} else {
531+
/** @type {import('#client').Effect[]} */
532+
var collected_effects = [];
533+
534+
process_effects(effect, collected_effects);
535+
flush_queued_effects(collected_effects);
536+
}
537+
}
538+
} finally {
539+
is_flushing_effect = previously_flushing_effect;
521540
}
522541
}
523542

@@ -586,11 +605,10 @@ export function schedule_effect(signal) {
586605
* effects to be flushed.
587606
*
588607
* @param {import('#client').Effect} effect
589-
* @param {boolean} recursive
590608
* @param {import('#client').Effect[]} collected_effects
591609
* @returns {void}
592610
*/
593-
function process_effects(effect, recursive, collected_effects) {
611+
function process_effects(effect, collected_effects) {
594612
var current_effect = effect.first;
595613
var effects = [];
596614

@@ -614,13 +632,14 @@ function process_effects(effect, recursive, collected_effects) {
614632
// Child might have been mutated since running the effect
615633
child = current_effect.first;
616634
}
617-
if (recursive && child !== null) {
635+
636+
if (child !== null) {
618637
current_effect = child;
619638
continue;
620639
}
621640
} else if ((flags & EFFECT) !== 0) {
622641
if (is_branch || is_clean) {
623-
if (recursive && child !== null) {
642+
if (child !== null) {
624643
current_effect = child;
625644
continue;
626645
}
@@ -650,58 +669,15 @@ function process_effects(effect, recursive, collected_effects) {
650669
current_effect = sibling;
651670
}
652671

653-
if (recursive) {
654-
// We might be dealing with many effects here, far more than can be spread into
655-
// an array push call (callstack overflow). So let's deal with each effect in a loop.
656-
for (var i = 0; i < effects.length; i++) {
657-
child = effects[i];
658-
collected_effects.push(child);
659-
process_effects(child, true, collected_effects);
660-
}
672+
// We might be dealing with many effects here, far more than can be spread into
673+
// an array push call (callstack overflow). So let's deal with each effect in a loop.
674+
for (var i = 0; i < effects.length; i++) {
675+
child = effects[i];
676+
collected_effects.push(child);
677+
process_effects(child, collected_effects);
661678
}
662679
}
663680

664-
/**
665-
*
666-
* This function recursively collects effects in topological order from the starting effect passed in.
667-
* Effects will be collected when they match the filtered bitwise flag passed in only. The collected
668-
* array will be populated with all the effects.
669-
*
670-
* @param {import('#client').Effect} effect
671-
* @param {boolean} [recursive]
672-
* @returns {void}
673-
*/
674-
function flush_nested_effects(effect, recursive = true) {
675-
var previously_flushing_effect = is_flushing_effect;
676-
is_flushing_effect = true;
677-
678-
try {
679-
// When working with custom elements, the root effects might not have a root
680-
if (effect.first === null && (effect.f & BRANCH_EFFECT) === 0) {
681-
flush_queued_effects([effect]);
682-
} else {
683-
/** @type {import('#client').Effect[]} */
684-
var collected_effects = [];
685-
686-
process_effects(effect, recursive, collected_effects);
687-
flush_queued_effects(collected_effects);
688-
}
689-
} finally {
690-
is_flushing_effect = previously_flushing_effect;
691-
}
692-
}
693-
694-
/**
695-
* @param {import('#client').Effect} effect
696-
* @returns {void}
697-
*/
698-
export function flush_local_render_effects(effect) {
699-
infinite_loop_guard();
700-
// We are entering a new flush sequence, so ensure counter is reset.
701-
flush_count = 0;
702-
flush_nested_effects(effect, false);
703-
}
704-
705681
/**
706682
* Internal version of `flushSync` with the option to not flush previous effects.
707683
* Returns the result of the passed function, if given.

0 commit comments

Comments
 (0)