Skip to content

Commit 8cc5961

Browse files
committed
tweak
1 parent e0e48b3 commit 8cc5961

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class Fork {
149149
}
150150

151151
active_fork = new Fork();
152-
forks.add(active_fork); // TODO figure out where we remove this
152+
forks.add(active_fork);
153153
}
154154

155155
return active_fork;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import * as e from '../errors.js';
3434
import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js';
3535
import { get_stack } from '../dev/tracing.js';
3636
import { component_context, is_runes } from '../context.js';
37-
import { active_fork, Fork } from './forks.js';
37+
import { Fork } from './forks.js';
3838
import { proxy } from '../proxy.js';
3939
import { execute_derived } from './deriveds.js';
4040

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import * as w from './warnings.js';
3030
import * as e from './errors.js';
3131
import { assign_nodes } from './dom/template.js';
3232
import { is_passive_event } from '../../utils.js';
33-
import { active_fork, Fork } from './reactivity/forks.js';
3433

3534
/**
3635
* This is normally true — block effects should run their intro transitions —

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,7 @@ function infinite_loop_guard() {
683683

684684
function flush_queued_root_effects() {
685685
var was_updating_effect = is_updating_effect;
686-
687-
// TODO it should be impossible to get here without an active fork
688-
if (!active_fork && queued_root_effects.length > 0) {
689-
console.trace('here');
690-
}
686+
var fork = /** @type {Fork} */ (active_fork);
691687

692688
try {
693689
var flush_count = 0;
@@ -698,7 +694,7 @@ function flush_queued_root_effects() {
698694
infinite_loop_guard();
699695
}
700696

701-
var revert = active_fork?.apply();
697+
var revert = fork.apply();
702698

703699
/** @type {Effect[]} */
704700
var async_effects = [];
@@ -724,13 +720,13 @@ function flush_queued_root_effects() {
724720
process_effects(root, async_effects, render_effects, effects);
725721
}
726722

727-
if (async_effects.length === 0 && (active_fork === null || active_fork.pending === 0)) {
728-
active_fork?.commit();
723+
if (async_effects.length === 0 && fork.pending === 0) {
724+
fork.commit();
729725
flush_queued_effects(render_effects);
730726
flush_queued_effects(effects);
731727
}
732728

733-
revert?.();
729+
revert();
734730

735731
for (const effect of async_effects) {
736732
update_effect(effect);
@@ -795,11 +791,13 @@ export function schedule_effect(signal) {
795791
if (!is_flushing) {
796792
is_flushing = true;
797793
queueMicrotask(() => {
794+
if (active_fork === null) {
795+
// a flushSync happened in the meantime
796+
return;
797+
}
798+
798799
flush_queued_root_effects();
799800

800-
// TODO this doesn't seem quite right — may run into
801-
// interesting cases where there are multiple roots.
802-
// it'll do for now though
803801
if (active_fork?.pending === 0) {
804802
active_fork.remove();
805803
}
@@ -845,14 +843,14 @@ export function schedule_effect(signal) {
845843
*/
846844
function process_effects(root, async_effects, render_effects, effects) {
847845
var effect = root.first;
846+
var fork = /** @type {Fork} */ (active_fork);
848847

849848
while (effect !== null) {
850849
var flags = effect.f;
851850
var is_branch = (flags & BRANCH_EFFECT) !== 0;
852851
var is_skippable_branch = is_branch && (flags & CLEAN) !== 0;
853852

854-
var skip =
855-
is_skippable_branch || (flags & INERT) !== 0 || active_fork?.skipped_effects.has(effect);
853+
var skip = is_skippable_branch || (flags & INERT) !== 0 || fork.skipped_effects.has(effect);
856854

857855
if (!skip) {
858856
if ((flags & EFFECT_ASYNC) !== 0) {

0 commit comments

Comments
 (0)