Skip to content

Commit de30bec

Browse files
committed
fix: ensure local prop value is read during teardown
1 parent 6f03561 commit de30bec

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

.changeset/clean-sloths-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure local prop value is read during teardown

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

Lines changed: 6 additions & 5 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,
@@ -20,7 +20,7 @@ import {
2020
} from '../runtime.js';
2121
import { safe_equals } from './equality.js';
2222
import * as e from '../errors.js';
23-
import { BRANCH_EFFECT, LEGACY_DERIVED_PROP, ROOT_EFFECT } from '../constants.js';
23+
import { BRANCH_EFFECT, DESTROYED, LEGACY_DERIVED_PROP, ROOT_EFFECT } from '../constants.js';
2424
import { proxy } from '../proxy.js';
2525

2626
/**
@@ -292,6 +292,8 @@ export function prop(props, key, flags, fallback) {
292292

293293
/** @type {() => V} */
294294
var getter;
295+
/** @type {Derived} */
296+
var derived_getter;
295297
if (runes) {
296298
getter = () => {
297299
var value = /** @type {V} */ (props[key]);
@@ -303,7 +305,7 @@ export function prop(props, key, flags, fallback) {
303305
} else {
304306
// Svelte 4 did not trigger updates when a primitive value was updated to the same value.
305307
// Replicate that behavior through using a derived
306-
var derived_getter = with_parent_branch(() =>
308+
derived_getter = with_parent_branch(() =>
307309
(immutable ? derived : derived_safe_equal)(() => /** @type {V} */ (props[key]))
308310
);
309311
derived_getter.f |= LEGACY_DERIVED_PROP;
@@ -353,12 +355,11 @@ export function prop(props, key, flags, fallback) {
353355
var parent_value = getter();
354356
var child_value = get(inner_current_value);
355357

356-
if (from_child) {
358+
if (from_child || (derived_getter !== undefined && (derived_getter.f & DESTROYED) !== 0)) {
357359
from_child = false;
358360
was_from_child = true;
359361
return child_value;
360362
}
361-
362363
was_from_child = false;
363364
return (inner_current_value.v = parent_value);
364365
})

0 commit comments

Comments
 (0)