Skip to content

Commit 4868f4d

Browse files
committed
less overhead
1 parent 1087f99 commit 4868f4d

File tree

1 file changed

+8
-13
lines changed
  • packages/svelte/src/internal/client/reactivity

1 file changed

+8
-13
lines changed

packages/svelte/src/internal/client/reactivity/props.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { Source } from './types.js' */
1+
/** @import { Derived, Source } from './types.js' */
22
import { DEV } from 'esm-env';
33
import {
44
PROPS_IS_BINDABLE,
@@ -12,6 +12,7 @@ import { mutable_source, set, source } from './sources.js';
1212
import { derived, derived_safe_equal } from './deriveds.js';
1313
import {
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';
2122
import { safe_equals } from './equality.js';
2223
import * 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';
2425
import { 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

Comments
 (0)