Skip to content

Commit 8e7f6bf

Browse files
committed
reduce diff size
1 parent 548a696 commit 8e7f6bf

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import {
1313
update_effect,
1414
check_dirtiness,
1515
untracking,
16-
is_destroying_effect
16+
is_destroying_effect,
17+
reaction_sources,
18+
set_reaction_sources
1719
} from '../runtime.js';
1820
import { equals, safe_equals } from './equality.js';
1921
import {
@@ -38,14 +40,6 @@ import { proxy } from '../proxy.js';
3840
export let inspect_effects = new Set();
3941
export const old_values = new Map();
4042

41-
/** @type {Source[] | null} */
42-
export let reaction_sources = null;
43-
44-
/** @param {Source[] | null} v */
45-
export function set_reaction_sources(v) {
46-
reaction_sources = v;
47-
}
48-
4943
/**
5044
* @param {Set<any>} v
5145
*/
@@ -73,7 +67,7 @@ export function source(v, stack) {
7367

7468
if (active_reaction !== null && active_reaction.f & EFFECT_IS_UPDATING) {
7569
if (reaction_sources === null) {
76-
reaction_sources = [signal];
70+
set_reaction_sources([signal]);
7771
} else {
7872
reaction_sources.push(signal);
7973
}

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ import {
2626
EFFECT_IS_UPDATING
2727
} from './constants.js';
2828
import { flush_tasks } from './dom/task.js';
29-
import {
30-
internal_set,
31-
old_values,
32-
reaction_sources,
33-
set_reaction_sources
34-
} from './reactivity/sources.js';
29+
import { internal_set, old_values } from './reactivity/sources.js';
3530
import { destroy_derived_effects, update_derived } from './reactivity/deriveds.js';
3631
import * as e from './errors.js';
3732
import { FILENAME } from '../../constants.js';
@@ -87,6 +82,20 @@ export function set_active_reaction(reaction) {
8782
/** @type {null | Effect} */
8883
export let active_effect = null;
8984

85+
/**
86+
* When sources are created within a derived, we record them so that we can safely allow
87+
* local mutations to these sources without the side-effect error being invoked unnecessarily.
88+
* @type {null | Source[]}
89+
*/
90+
export let reaction_sources = null;
91+
92+
/**
93+
* @param {Source[] | null} sources
94+
*/
95+
export function set_reaction_sources(sources) {
96+
reaction_sources = sources;
97+
}
98+
9099
/** @param {null | Effect} effect */
91100
export function set_active_effect(effect) {
92101
active_effect = effect;
@@ -386,20 +395,20 @@ export function update_reaction(reaction) {
386395
var previous_untracked_writes = untracked_writes;
387396
var previous_reaction = active_reaction;
388397
var previous_skip_reaction = skip_reaction;
398+
var previous_reaction_sources = reaction_sources;
389399
var previous_component_context = component_context;
390400
var previous_untracking = untracking;
391-
var previous_reaction_sources = reaction_sources;
392401

393402
var flags = reaction.f;
394403

395-
set_reaction_sources(null);
396404
new_deps = /** @type {null | Value[]} */ (null);
397405
skipped_deps = 0;
398406
untracked_writes = null;
399407
skip_reaction =
400408
(flags & UNOWNED) !== 0 && (untracking || !is_updating_effect || active_reaction === null);
401409
active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
402410

411+
reaction_sources = null;
403412
set_component_context(reaction.ctx);
404413
untracking = false;
405414
read_version++;
@@ -475,9 +484,9 @@ export function update_reaction(reaction) {
475484
untracked_writes = previous_untracked_writes;
476485
active_reaction = previous_reaction;
477486
skip_reaction = previous_skip_reaction;
487+
reaction_sources = previous_reaction_sources;
478488
set_component_context(previous_component_context);
479489
untracking = previous_untracking;
480-
set_reaction_sources(previous_reaction_sources);
481490

482491
reaction.f ^= EFFECT_IS_UPDATING;
483492
}

0 commit comments

Comments
 (0)