Skip to content

Commit 1588365

Browse files
committed
thing
1 parent f0497b1 commit 1588365

File tree

1 file changed

+10
-5
lines changed
  • packages/svelte/src/internal/client/reactivity

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { LEGACY_DERIVED_PROP, LEGACY_PROPS, STATE_SYMBOL } from '#client/constan
1717
import { proxy } from '../proxy.js';
1818
import { capture_store_binding } from './store.js';
1919
import { legacy_mode_flag } from '../../flags/index.js';
20+
import { component_context } from '../context.js';
21+
import { teardown } from './effects.js';
2022

2123
/**
2224
* @param {((value?: number) => number)} fn
@@ -159,16 +161,17 @@ export function legacy_rest_props(props, exclude) {
159161
* The proxy handler for spread props. Handles the incoming array of props
160162
* that looks like `() => { dynamic: props }, { static: prop }, ..` and wraps
161163
* them so that the whole thing is passed to the component as the `$$props` argument.
162-
* @template {Record<string | symbol, unknown>} T
163-
* @type {ProxyHandler<{ props: Array<T | (() => T)> }>}}
164+
* @typedef {Record<string | symbol, unknown>} T
165+
* @type {ProxyHandler<{ props: Array<T | (() => T)>, oldProps: T, destroyed: boolean }>}}
164166
*/
165167
const spread_props_handler = {
166168
get(target, key) {
169+
if (target.destroyed && key in target.oldProps) return target.oldProps[key]
167170
let i = target.props.length;
168171
while (i--) {
169172
let p = target.props[i];
170173
if (is_function(p)) p = p();
171-
if (typeof p === 'object' && p !== null && key in p) return p[key];
174+
if (typeof p === 'object' && p !== null && key in p) return (target.oldProps[key] = p[key]);
172175
}
173176
},
174177
set(target, key, value) {
@@ -178,7 +181,7 @@ const spread_props_handler = {
178181
if (is_function(p)) p = p();
179182
const desc = get_descriptor(p, key);
180183
if (desc && desc.set) {
181-
desc.set(value);
184+
desc.set(target.oldProps[key] = value);
182185
return true;
183186
}
184187
}
@@ -238,7 +241,9 @@ const spread_props_handler = {
238241
* @returns {any}
239242
*/
240243
export function spread_props(...props) {
241-
return new Proxy({ props }, spread_props_handler);
244+
let destroyed = false
245+
teardown(() => { destroyed = true })
246+
return new Proxy({ props, oldProps: {}, get destroyed() { return destroyed } }, spread_props_handler);
242247
}
243248

244249
/**

0 commit comments

Comments
 (0)