Skip to content

Commit 3b9fdf9

Browse files
committed
Correctly initialize oldProps so it's not null even if it's never read
1 parent 144d3cc commit 3b9fdf9

File tree

1 file changed

+11
-7
lines changed
  • packages/svelte/src/internal/client/reactivity

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ 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';
2120
import { teardown } from './effects.js';
2221

2322
/**
@@ -161,8 +160,8 @@ export function legacy_rest_props(props, exclude) {
161160
* The proxy handler for spread props. Handles the incoming array of props
162161
* that looks like `() => { dynamic: props }, { static: prop }, ..` and wraps
163162
* them so that the whole thing is passed to the component as the `$$props` argument.
164-
* @typedef {Record<string | symbol, unknown>} T
165-
* @type {ProxyHandler<{ props: Array<T | (() => T)>, oldProps: T, destroyed: boolean }>}}
163+
* @typedef {Record<string | symbol, unknown>} AnyProps
164+
* @type {ProxyHandler<{ props: Array<AnyProps | (() => AnyProps)>, oldProps: AnyProps, destroyed: boolean }>}}
166165
*/
167166
const spread_props_handler = {
168167
get(target, key) {
@@ -242,13 +241,18 @@ const spread_props_handler = {
242241
*/
243242
export function spread_props(...props) {
244243
let destroyed = false;
245-
teardown(() => {
246-
destroyed = true;
247-
});
244+
teardown(() => (destroyed = true));
248245
return new Proxy(
249246
{
250247
props,
251-
oldProps: {},
248+
oldProps: untrack(() => {
249+
const oldProps = {};
250+
for (let p of props) {
251+
if (typeof p === 'function') p = p();
252+
Object.assign(oldProps, p);
253+
}
254+
return oldProps;
255+
}),
252256
get destroyed() {
253257
return destroyed;
254258
}

0 commit comments

Comments
 (0)