Skip to content

chore: simplify flushing #15348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify
  • Loading branch information
Rich-Harris committed Feb 21, 2025
commit 763ed356882ed4f4a6866cef10e297166a331c96
8 changes: 0 additions & 8 deletions packages/svelte/src/internal/client/reactivity/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import {
update_effect,
get,
is_destroying_effect,
is_flushing_effect,
remove_reactions,
schedule_effect,
set_active_reaction,
set_is_destroying_effect,
set_is_flushing_effect,
set_signal_status,
untrack,
skip_reaction,
untracking
} from '../runtime.js';
import {
Expand Down Expand Up @@ -118,17 +115,12 @@ function create_effect(type, fn, sync, push = true) {
}

if (sync) {
var previously_flushing_effect = is_flushing_effect;

try {
set_is_flushing_effect(true);
update_effect(effect);
effect.f |= EFFECT_RAN;
} catch (e) {
destroy_effect(effect);
throw e;
} finally {
set_is_flushing_effect(previously_flushing_effect);
}
} else if (fn !== null) {
schedule_effect(effect);
Expand Down
26 changes: 10 additions & 16 deletions packages/svelte/src/internal/client/reactivity/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
derived_sources,
set_derived_sources,
check_dirtiness,
set_is_flushing_effect,
is_flushing_effect,
untracking
} from '../runtime.js';
import { equals, safe_equals } from './equality.js';
Expand Down Expand Up @@ -202,22 +200,18 @@ export function internal_set(source, value) {

if (DEV && inspect_effects.size > 0) {
const inspects = Array.from(inspect_effects);
var previously_flushing_effect = is_flushing_effect;
set_is_flushing_effect(true);
try {
for (const effect of inspects) {
// Mark clean inspect-effects as maybe dirty and then check their dirtiness
// instead of just updating the effects - this way we avoid overfiring.
if ((effect.f & CLEAN) !== 0) {
set_signal_status(effect, MAYBE_DIRTY);
}
if (check_dirtiness(effect)) {
update_effect(effect);
}

for (const effect of inspects) {
// Mark clean inspect-effects as maybe dirty and then check their dirtiness
// instead of just updating the effects - this way we avoid overfiring.
if ((effect.f & CLEAN) !== 0) {
set_signal_status(effect, MAYBE_DIRTY);
}
if (check_dirtiness(effect)) {
update_effect(effect);
}
} finally {
set_is_flushing_effect(previously_flushing_effect);
}

inspect_effects.clear();
}
}
Expand Down
12 changes: 3 additions & 9 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ let last_scheduled_effect = null;
export let is_flushing_effect = false; // TODO do we still need this?
export let is_destroying_effect = false;

/** @param {boolean} value */
export function set_is_flushing_effect(value) {
is_flushing_effect = value;
}

/** @param {boolean} value */
export function set_is_destroying_effect(value) {
is_destroying_effect = value;
Expand Down Expand Up @@ -552,8 +547,10 @@ export function update_effect(effect) {

var previous_effect = active_effect;
var previous_component_context = component_context;
var previously_flushing_effect = is_flushing_effect;

active_effect = effect;
is_flushing_effect = true;

if (DEV) {
var previous_component_fn = dev_current_component_function;
Expand Down Expand Up @@ -595,6 +592,7 @@ export function update_effect(effect) {
} catch (error) {
handle_error(error, effect, previous_effect, previous_component_context || effect.ctx);
} finally {
is_flushing_effect = previously_flushing_effect;
active_effect = previous_effect;

if (DEV) {
Expand Down Expand Up @@ -646,9 +644,6 @@ function infinite_loop_guard() {
}

function flush_queued_root_effects() {
var previously_flushing_effect = is_flushing_effect;
is_flushing_effect = true;

try {
var flush_count = 0;

Expand All @@ -674,7 +669,6 @@ function flush_queued_root_effects() {
}
}
} finally {
is_flushing_effect = previously_flushing_effect;
is_flushing = false;

last_scheduled_effect = null;
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy