Repository: sveltejs/svelte
File: packages/svelte/src/internal/client/runtime.js (JavaScript)

Code before:
 */
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_skip_reaction = skip_reaction;
	var prev_derived_sources = derived_sources;
	var previous_component_context = component_context;
	var previous_untracking = untracking;
	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;
	// prettier-ignore
	skip_reaction =
		(flags & UNOWNED) !== 0 &&
		(!is_flushing_effect ||
			// If we were previously not in a reactive context and we're reading an unowned derived
			// that was created inside another derived, then we don't fully know the real owner and thus
			// we need to skip adding any reactions for this unowned
				((previous_reaction === null || previous_untracking) &&
				(/** @type {Derived} */ (reaction).parent !== null &&
				(/** @type {Derived} */ (reaction).parent.f & DERIVED) !== 0)));

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

	try {
		var result = /** @type {Function} */ (0, reaction.fn)();
		var deps = reaction.deps;

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

			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 (!skip_reaction) {

Review comment (suggestion):
Pretty sure you can reduce this to `/** @type {Derived} */ (reaction).parent?.f & DERIVED) !== 0`

Code after:
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_skip_reaction = skip_reaction;
	var prev_derived_sources = derived_sources;
	var previous_component_context = component_context;
	var previous_untracking = untracking;
	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;
	// prettier-ignore
	skip_reaction =
		(flags & UNOWNED) !== 0 &&
		(!is_flushing_effect ||
			// If we were previously not in a reactive context and we're reading an unowned derived
			// that was created inside another reaction, then we don't fully know the real owner and thus
			// we need to skip adding any reactions for this unowned
				((previous_reaction === null || previous_untracking) &&
				/** @type {Derived} */ (reaction).parent !== null));

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

	try {
		var result = /** @type {Function} */ (0, reaction.fn)();
		var deps = reaction.deps;

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

			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 (!skip_reaction) {
				for (i = skipped_deps; i < deps.length; i++) {
					(deps[i].reactions ??= []).push(reaction);