1- /** @import { Source } from './types.js' */
1+ /** @import { Derived, Source } from './types.js' */
22import { DEV } from 'esm-env' ;
33import {
44 PROPS_IS_BINDABLE ,
@@ -11,23 +11,15 @@ import { get_descriptor, is_function } from '../../shared/utils.js';
1111import { mutable_source , set , source , update } from './sources.js' ;
1212import { derived , derived_safe_equal } from './deriveds.js' ;
1313import {
14- active_effect ,
1514 get ,
1615 captured_signals ,
17- set_active_effect ,
1816 untrack ,
19- active_reaction ,
20- set_active_reaction
17+ set_is_destroying_effect ,
18+ is_destroying_effect
2119} from '../runtime.js' ;
2220import { safe_equals } from './equality.js' ;
2321import * as e from '../errors.js' ;
24- import {
25- BRANCH_EFFECT ,
26- LEGACY_DERIVED_PROP ,
27- LEGACY_PROPS ,
28- ROOT_EFFECT ,
29- STATE_SYMBOL
30- } from '../constants.js' ;
22+ import { LEGACY_DERIVED_PROP , LEGACY_PROPS , STATE_SYMBOL } from '../constants.js' ;
3123import { proxy } from '../proxy.js' ;
3224import { capture_store_binding } from './store.js' ;
3325import { legacy_mode_flag } from '../../flags/index.js' ;
@@ -249,6 +241,14 @@ export function spread_props(...props) {
249241 return new Proxy ( { props } , spread_props_handler ) ;
250242}
251243
244+ /**
245+ * @param {Derived } current_value
246+ * @returns {boolean }
247+ */
248+ function has_destoyed_component_ctx ( current_value ) {
249+ return current_value . ctx ?. d ?? false ;
250+ }
251+
252252/**
253253 * This function is responsible for synchronizing a possibly bound prop with the inner component state.
254254 * It is used whenever the compiler sees that the component writes to the prop, or when it has a default prop_value.
@@ -382,6 +382,11 @@ export function prop(props, key, flags, fallback) {
382382 return ( inner_current_value . v = parent_value ) ;
383383 } ) ;
384384
385+ // Ensure we eagerly capture the initial value if it's bindable
386+ if ( bindable ) {
387+ get ( current_value ) ;
388+ }
389+
385390 if ( ! immutable ) current_value . equals = safe_equals ;
386391
387392 return function ( /** @type {any } */ value , /** @type {boolean } */ mutation ) {
@@ -408,11 +413,21 @@ export function prop(props, key, flags, fallback) {
408413 if ( fallback_used && fallback_value !== undefined ) {
409414 fallback_value = new_value ;
410415 }
416+
417+ if ( has_destoyed_component_ctx ( current_value ) ) {
418+ return value ;
419+ }
420+
411421 untrack ( ( ) => get ( current_value ) ) ; // force a synchronisation immediately
412422 }
413423
414424 return value ;
415425 }
426+
427+ if ( has_destoyed_component_ctx ( current_value ) ) {
428+ return current_value . v ;
429+ }
430+
416431 return get ( current_value ) ;
417432 } ;
418433}
0 commit comments