Skip to content

Commit b275b24

Browse files
committed
fix: access last safe value of prop on unmount
1 parent eb9f587 commit b275b24

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

packages/svelte/src/internal/client/context.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { effect, teardown } from './reactivity/effects.js';
1515
import { legacy_mode_flag } from '../flags/index.js';
1616
import { CTX_CONTAINS_TEARDOWN, CTX_DESTROYED } from './constants.js';
17+
import { define_property } from '../shared/utils.js';
1718

1819
/** @type {ComponentContext | null} */
1920
export let component_context = null;
@@ -145,7 +146,7 @@ export function push(props, runes = false, fn) {
145146
var teardown_props = ctx.tp;
146147
// Apply the latest known props before teardown over existing props
147148
for (var key in teardown_props) {
148-
Object.defineProperty(props, key, {
149+
define_property(props, key, {
149150
value: teardown_props[key],
150151
configurable: true
151152
});

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
PROPS_IS_RUNES,
88
PROPS_IS_UPDATED
99
} from '../../../constants.js';
10-
import { get_descriptor, is_function } from '../../shared/utils.js';
10+
import { define_property, get_descriptor, is_function } from '../../shared/utils.js';
1111
import { mutable_source, set, source, update } from './sources.js';
1212
import { derived, derived_safe_equal } from './deriveds.js';
1313
import {
@@ -201,6 +201,18 @@ const spread_props_handler = {
201201
}
202202
return false;
203203
},
204+
defineProperty(target, key, descriptor) {
205+
let i = target.props.length;
206+
while (i--) {
207+
let p = target.props[i];
208+
if (is_function(p)) p = p();
209+
if (typeof p === 'object' && p !== null && key in p) {
210+
define_property(p, key, descriptor);
211+
return true;
212+
}
213+
}
214+
return false;
215+
},
204216
getOwnPropertyDescriptor(target, key) {
205217
let i = target.props.length;
206218
while (i--) {

packages/svelte/tests/runtime-runes/samples/ondestroy-prop-access/_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export default test({
6161
true,
6262
2,
6363
true,
64-
2,
65-
false
64+
1,
65+
true
6666
]);
6767
}
6868
});

0 commit comments

Comments
 (0)