@@ -10,7 +10,15 @@ import {
1010import { 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' ;
13- import { active_effect , get , captured_signals , set_active_effect , untrack } from '../runtime.js' ;
13+ import {
14+ active_effect ,
15+ get ,
16+ captured_signals ,
17+ set_active_effect ,
18+ untrack ,
19+ active_reaction ,
20+ set_active_reaction
21+ } from '../runtime.js' ;
1422import { safe_equals } from './equality.js' ;
1523import * as e from '../errors.js' ;
1624import {
@@ -241,6 +249,29 @@ export function spread_props(...props) {
241249 return new Proxy ( { props } , spread_props_handler ) ;
242250}
243251
252+ /**
253+ * @template T
254+ * @param {() => T } fn
255+ * @returns {T }
256+ */
257+ function with_parent_branch ( fn ) {
258+ var effect = active_effect ;
259+ var previous_effect = active_effect ;
260+ var previous_reaction = active_reaction ;
261+
262+ while ( effect !== null && ( effect . f & ( BRANCH_EFFECT | ROOT_EFFECT ) ) === 0 ) {
263+ effect = effect . parent ;
264+ }
265+ try {
266+ set_active_effect ( effect ) ;
267+ set_active_reaction ( effect ) ;
268+ return fn ( ) ;
269+ } finally {
270+ set_active_effect ( previous_effect ) ;
271+ set_active_reaction ( previous_reaction ) ;
272+ }
273+ }
274+
244275/**
245276 * This function is responsible for synchronizing a possibly bound prop with the inner component state.
246277 * It is used whenever the compiler sees that the component writes to the prop, or when it has a default prop_value.
@@ -259,11 +290,13 @@ export function prop(props, key, flags, fallback) {
259290 var is_store_sub = false ;
260291 var prop_value ;
261292
262- if ( bindable ) {
263- [ prop_value , is_store_sub ] = capture_store_binding ( ( ) => /** @type {V } */ ( props [ key ] ) ) ;
264- } else {
265- prop_value = /** @type {V } */ ( props [ key ] ) ;
266- }
293+ with_parent_branch ( ( ) => {
294+ if ( bindable ) {
295+ [ prop_value , is_store_sub ] = capture_store_binding ( ( ) => /** @type {V } */ ( props [ key ] ) ) ;
296+ } else {
297+ prop_value = /** @type {V } */ ( props [ key ] ) ;
298+ }
299+ } ) ;
267300
268301 // Can be the case when someone does `mount(Component, props)` with `let props = $state({...})`
269302 // or `createClassComponent(Component, props)`
0 commit comments