1- /** @import { Source } from './types.js' */
1+ /** @import { Derived, Source } from './types.js' */
22import { DEV } from 'esm-env' ;
33import {
44 PROPS_IS_BINDABLE ,
@@ -12,6 +12,7 @@ import { mutable_source, set, source } from './sources.js';
1212import { derived , derived_safe_equal } from './deriveds.js' ;
1313import {
1414 active_effect ,
15+ active_reaction ,
1516 get ,
1617 is_signals_recorded ,
1718 set_active_effect ,
@@ -20,9 +21,8 @@ import {
2021} from '../runtime.js' ;
2122import { safe_equals } from './equality.js' ;
2223import * as e from '../errors.js' ;
23- import { BRANCH_EFFECT , LEGACY_DERIVED_PROP , ROOT_EFFECT } from '../constants.js' ;
24+ import { BRANCH_EFFECT , DESTROYED , LEGACY_DERIVED_PROP , ROOT_EFFECT } from '../constants.js' ;
2425import { proxy } from '../proxy.js' ;
25- import { teardown } from './effects.js' ;
2626
2727/**
2828 * @param {((value?: number) => number) } fn
@@ -350,21 +350,16 @@ export function prop(props, key, flags, fallback) {
350350 // source is written to from various places to persist this value.
351351 var inner_current_value = mutable_source ( prop_value ) ;
352352
353- teardown ( ( ) => {
354- // If the getter from the parent returns undefined, switch
355- // to using the local value from inner_current_value instead,
356- // as the parent value might have been torn down
357- if ( getter ( ) === undefined ) {
358- from_child = true ;
359- }
360- } ) ;
361-
362353 var current_value = with_parent_branch ( ( ) =>
363354 derived ( ( ) => {
364355 var parent_value = getter ( ) ;
365356 var child_value = get ( inner_current_value ) ;
357+ var current_derived = /** @type {Derived } */ ( active_reaction ) ;
366358
367- if ( from_child ) {
359+ // If the getter from the parent returns undefined, switch
360+ // to using the local value from inner_current_value instead,
361+ // as the parent value might have been torn down
362+ if ( from_child || ( parent_value === undefined && ( current_derived . f & DESTROYED ) !== 0 ) ) {
368363 from_child = false ;
369364 was_from_child = true ;
370365 return child_value ;
0 commit comments