From 3b9fdf982ec95c1a121ef6dd453020c5f1d3d34d Mon Sep 17 00:00:00 2001 From: Matei-Paul Trandafir Date: Thu, 12 Jun 2025 20:50:26 +0300 Subject: [PATCH] Correctly initialize oldProps so it's not null even if it's never read --- .../src/internal/client/reactivity/props.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/props.js b/packages/svelte/src/internal/client/reactivity/props.js index dd9a17c0e3..525fb955d0 100644 --- a/packages/svelte/src/internal/client/reactivity/props.js +++ b/packages/svelte/src/internal/client/reactivity/props.js @@ -17,7 +17,6 @@ import { LEGACY_DERIVED_PROP, LEGACY_PROPS, STATE_SYMBOL } from '#client/constan import { proxy } from '../proxy.js'; import { capture_store_binding } from './store.js'; import { legacy_mode_flag } from '../../flags/index.js'; -import { component_context } from '../context.js'; import { teardown } from './effects.js'; /** @@ -161,8 +160,8 @@ export function legacy_rest_props(props, exclude) { * The proxy handler for spread props. Handles the incoming array of props * that looks like `() => { dynamic: props }, { static: prop }, ..` and wraps * them so that the whole thing is passed to the component as the `$$props` argument. - * @typedef {Record} T - * @type {ProxyHandler<{ props: Array T)>, oldProps: T, destroyed: boolean }>}} + * @typedef {Record} AnyProps + * @type {ProxyHandler<{ props: Array AnyProps)>, oldProps: AnyProps, destroyed: boolean }>}} */ const spread_props_handler = { get(target, key) { @@ -242,13 +241,18 @@ const spread_props_handler = { */ export function spread_props(...props) { let destroyed = false; - teardown(() => { - destroyed = true; - }); + teardown(() => (destroyed = true)); return new Proxy( { props, - oldProps: {}, + oldProps: untrack(() => { + const oldProps = {}; + for (let p of props) { + if (typeof p === 'function') p = p(); + Object.assign(oldProps, p); + } + return oldProps; + }), get destroyed() { return destroyed; }