File tree Expand file tree Collapse file tree 3 files changed +25
-14
lines changed
packages/svelte/src/internal/client Expand file tree Collapse file tree 3 files changed +25
-14
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ import {
2222 increment_write_version ,
2323 set_active_effect ,
2424 push_reaction_value ,
25- is_destroying_effect
25+ is_destroying_effect ,
26+ update_derived_status
2627} from '../runtime.js' ;
2728import { equals , safe_equals } from './equality.js' ;
2829import * as e from '../errors.js' ;
@@ -386,13 +387,7 @@ export function update_derived(derived) {
386387 }
387388 }
388389
389- // Only mark as MAYBE_DIRTY if disconnected AND has dependencies.
390- // Deriveds with no deps can never become dirty from dependency changes.
391390 if ( batch_values === null || derived . deps === null ) {
392- if ( ( derived . f & CONNECTED ) === 0 && derived . deps !== null ) {
393- set_signal_status ( derived , MAYBE_DIRTY ) ;
394- } else {
395- set_signal_status ( derived , CLEAN ) ;
396- }
391+ update_derived_status ( derived ) ;
397392 }
398393}
Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ import {
1616 is_destroying_effect ,
1717 push_reaction_value ,
1818 set_is_updating_effect ,
19- is_updating_effect
19+ is_updating_effect ,
20+ update_derived_status
2021} from '../runtime.js' ;
2122import { equals , safe_equals } from './equality.js' ;
2223import {
@@ -218,12 +219,14 @@ export function internal_set(source, value) {
218219 }
219220
220221 if ( ( source . f & DERIVED ) !== 0 ) {
222+ const derived = /** @type {Derived } */ ( source ) ;
223+
221224 // if we are assigning to a dirty derived we set it to clean/maybe dirty but we also eagerly execute it to track the dependencies
222225 if ( ( source . f & DIRTY ) !== 0 ) {
223- execute_derived ( /** @type { Derived } */ ( source ) ) ;
226+ execute_derived ( derived ) ;
224227 }
225228
226- set_signal_status ( source , ( source . f & CONNECTED ) !== 0 ? CLEAN : MAYBE_DIRTY ) ;
229+ update_derived_status ( derived ) ;
227230 }
228231
229232 source . wv = increment_write_version ( ) ;
Original file line number Diff line number Diff line change @@ -185,12 +185,12 @@ export function is_dirty(reaction) {
185185 }
186186
187187 if (
188- ( flags & CONNECTED ) !== 0 &&
188+ ( flags & DERIVED ) !== 0 &&
189189 // During time traveling we don't want to reset the status so that
190190 // traversal of the graph in the other batches still happens
191- batch_values === null
191+ ( batch_values === null || reaction . deps === null )
192192 ) {
193- set_signal_status ( reaction , CLEAN ) ;
193+ update_derived_status ( /** @type { Derived } */ ( reaction ) ) ;
194194 }
195195 }
196196
@@ -732,6 +732,19 @@ export function set_signal_status(signal, status) {
732732 signal . f = ( signal . f & STATUS_MASK ) | status ;
733733}
734734
735+ /**
736+ * Set a derived's status to CLEAN or MAYBE_DIRTY based on its connection state.
737+ * @param {Derived } derived
738+ */
739+ export function update_derived_status ( derived ) {
740+ // Only mark as MAYBE_DIRTY if disconnected and has dependencies.
741+ if ( ( derived . f & CONNECTED ) !== 0 || derived . deps === null ) {
742+ set_signal_status ( derived , CLEAN ) ;
743+ } else {
744+ set_signal_status ( derived , MAYBE_DIRTY ) ;
745+ }
746+ }
747+
735748/**
736749 * @param {Record<string | symbol, unknown> } obj
737750 * @param {Array<string | symbol> } keys
You can’t perform that action at this time.
0 commit comments