@@ -26,7 +26,7 @@ import {
2626import { equals , safe_equals } from './equality.js' ;
2727import * as e from '../errors.js' ;
2828import * as w from '../warnings.js' ;
29- import { async_effect , destroy_effect , teardown } from './effects.js' ;
29+ import { async_effect , destroy_effect , effect_tracking , teardown } from './effects.js' ;
3030import { eager_effects , internal_set , set_eager_effects , source } from './sources.js' ;
3131import { get_stack } from '../dev/tracing.js' ;
3232import { async_mode_flag , tracing_mode_flag } from '../../flags/index.js' ;
@@ -368,17 +368,11 @@ export function update_derived(derived) {
368368 // During time traveling we don't want to reset the status so that
369369 // traversal of the graph in the other batches still happens
370370 if ( batch_values !== null ) {
371- // Delete the value as the current one is now the latest.
372- // Deleting instead of updating handles the case where a derived
373- // is subsequently indirectly updated in the same batch — without
374- // deleting here we would incorrectly get the old value from `batch_values`
375- // instead of recomputing it. The one drawback is that it's now a bit
376- // more inefficient to get the value of that derived again in the same batch,
377- // as it has to check is_dirty all the way up the graph all the time.
378- // TODO if that turns out to be a performance problem, we could try
379- // to save the current status of the derived in a map and restore it
380- // before leaving the batch.
381- batch_values . delete ( derived ) ;
371+ // only cache the value if we're in a tracking context, otherwise we won't
372+ // clear the cache in `mark_reactions` when dependencies are updated
373+ if ( effect_tracking ( ) ) {
374+ batch_values . set ( derived , derived . v ) ;
375+ }
382376 } else {
383377 var status = ( derived . f & CONNECTED ) === 0 ? MAYBE_DIRTY : CLEAN ;
384378 set_signal_status ( derived , status ) ;
0 commit comments