Home / Function/ update_reaction() — svelte Function Reference

update_reaction() — svelte Function Reference

Architecture documentation for the update_reaction() function in runtime.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd["update_reaction()"]
  bde4209f_8ffc_1594_4024_b1835a44bcf6["runtime.js"]
  9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd -->|defined in| bde4209f_8ffc_1594_4024_b1835a44bcf6
  6ac29608_bb3f_4976_22d6_2651518ca4bc["execute_derived()"]
  6ac29608_bb3f_4976_22d6_2651518ca4bc -->|calls| 9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd
  19374192_7fff_dd82_3581_d62b472dfbdd["update_effect()"]
  19374192_7fff_dd82_3581_d62b472dfbdd -->|calls| 9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd
  7a5dcc8e_a227_a041_3278_04368ddf1422["set_component_context()"]
  9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd -->|calls| 7a5dcc8e_a227_a041_3278_04368ddf1422
  e95d0513_ce71_430f_7ef3_577e736f42c1["without_reactive_context()"]
  9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd -->|calls| e95d0513_ce71_430f_7ef3_577e736f42c1
  1ffeab26_17a7_43c8_1f19_a6f67d2606ea["remove_reactions()"]
  9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd -->|calls| 1ffeab26_17a7_43c8_1f19_a6f67d2606ea
  461d1f5f_ffa4_d984_98a4_868566c66f30["effect_tracking()"]
  9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd -->|calls| 461d1f5f_ffa4_d984_98a4_868566c66f30
  ea5280ff_3b87_42ee_3823_3570b76a5779["push()"]
  9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd -->|calls| ea5280ff_3b87_42ee_3823_3570b76a5779
  ad360ec3_c98b_ac47_212b_923d0363a0ce["is_runes()"]
  9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd -->|calls| ad360ec3_c98b_ac47_212b_923d0363a0ce
  e18484c6_b89d_ae11_a28b_147e60713b71["schedule_possible_effect_self_invalidation()"]
  9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd -->|calls| e18484c6_b89d_ae11_a28b_147e60713b71
  6c1ccbf4_9a62_285e_f0c7_95d2b223818c["handle_error()"]
  9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd -->|calls| 6c1ccbf4_9a62_285e_f0c7_95d2b223818c
  style 9e5743e3_8b9e_0ad6_5140_1a5ffaca62cd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/internal/client/runtime.js lines 222–354

export function update_reaction(reaction) {
	var previous_deps = new_deps;
	var previous_skipped_deps = skipped_deps;
	var previous_untracked_writes = untracked_writes;
	var previous_reaction = active_reaction;
	var previous_sources = current_sources;
	var previous_component_context = component_context;
	var previous_untracking = untracking;
	var previous_update_version = update_version;

	var flags = reaction.f;

	new_deps = /** @type {null | Value[]} */ (null);
	skipped_deps = 0;
	untracked_writes = null;
	active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;

	current_sources = null;
	set_component_context(reaction.ctx);
	untracking = false;
	update_version = ++read_version;

	if (reaction.ac !== null) {
		without_reactive_context(() => {
			/** @type {AbortController} */ (reaction.ac).abort(STALE_REACTION);
		});

		reaction.ac = null;
	}

	try {
		reaction.f |= REACTION_IS_UPDATING;
		var fn = /** @type {Function} */ (reaction.fn);
		var result = fn();
		var deps = reaction.deps;

		// Don't remove reactions during fork;
		// they must remain for when fork is discarded
		var is_fork = current_batch?.is_fork;

		if (new_deps !== null) {
			var i;

			if (!is_fork) {
				remove_reactions(reaction, skipped_deps);
			}

			if (deps !== null && skipped_deps > 0) {
				deps.length = skipped_deps + new_deps.length;
				for (i = 0; i < new_deps.length; i++) {
					deps[skipped_deps + i] = new_deps[i];
				}
			} else {
				reaction.deps = deps = new_deps;
			}

			if (effect_tracking() && (reaction.f & CONNECTED) !== 0) {
				for (i = skipped_deps; i < deps.length; i++) {
					(deps[i].reactions ??= []).push(reaction);
				}
			}
		} else if (!is_fork && deps !== null && skipped_deps < deps.length) {
			remove_reactions(reaction, skipped_deps);
			deps.length = skipped_deps;
		}

		// If we're inside an effect and we have untracked writes, then we need to
		// ensure that if any of those untracked writes result in re-invalidation
		// of the current effect, then that happens accordingly
		if (
			is_runes() &&
			untracked_writes !== null &&
			!untracking &&
			deps !== null &&
			(reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0
		) {
			for (i = 0; i < /** @type {Source[]} */ (untracked_writes).length; i++) {
				schedule_possible_effect_self_invalidation(
					untracked_writes[i],
					/** @type {Effect} */ (reaction)
				);

Domain

Subdomains

Frequently Asked Questions

What does update_reaction() do?
update_reaction() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/runtime.js.
Where is update_reaction() defined?
update_reaction() is defined in packages/svelte/src/internal/client/runtime.js at line 222.
What does update_reaction() call?
update_reaction() calls 8 function(s): effect_tracking, handle_error, is_runes, push, remove_reactions, schedule_possible_effect_self_invalidation, set_component_context, without_reactive_context.
What calls update_reaction()?
update_reaction() is called by 2 function(s): execute_derived, update_effect.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free