@@ -26,12 +26,7 @@ import {
2626 EFFECT_IS_UPDATING
2727} from './constants.js' ;
2828import { 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' ;
3530import { destroy_derived_effects , update_derived } from './reactivity/deriveds.js' ;
3631import * as e from './errors.js' ;
3732import { FILENAME } from '../../constants.js' ;
@@ -87,6 +82,20 @@ export function set_active_reaction(reaction) {
8782/** @type {null | Effect } */
8883export 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 */
91100export 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