Correctly initialize oldProps so it's not null even if it's never read

pull/16140/head
Matei-Paul Trandafir 3 months ago
parent 144d3ccf63
commit 3b9fdf982e
No known key found for this signature in database
GPG Key ID: BC96CA77836E14F8

@ -17,7 +17,6 @@ import { LEGACY_DERIVED_PROP, LEGACY_PROPS, STATE_SYMBOL } from '#client/constan
import { proxy } from '../proxy.js'; import { proxy } from '../proxy.js';
import { capture_store_binding } from './store.js'; import { capture_store_binding } from './store.js';
import { legacy_mode_flag } from '../../flags/index.js'; import { legacy_mode_flag } from '../../flags/index.js';
import { component_context } from '../context.js';
import { teardown } from './effects.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 * The proxy handler for spread props. Handles the incoming array of props
* that looks like `() => { dynamic: props }, { static: prop }, ..` and wraps * that looks like `() => { dynamic: props }, { static: prop }, ..` and wraps
* them so that the whole thing is passed to the component as the `$$props` argument. * them so that the whole thing is passed to the component as the `$$props` argument.
* @typedef {Record<string | symbol, unknown>} T * @typedef {Record<string | symbol, unknown>} AnyProps
* @type {ProxyHandler<{ props: Array<T | (() => T)>, oldProps: T, destroyed: boolean }>}} * @type {ProxyHandler<{ props: Array<AnyProps | (() => AnyProps)>, oldProps: AnyProps, destroyed: boolean }>}}
*/ */
const spread_props_handler = { const spread_props_handler = {
get(target, key) { get(target, key) {
@ -242,13 +241,18 @@ const spread_props_handler = {
*/ */
export function spread_props(...props) { export function spread_props(...props) {
let destroyed = false; let destroyed = false;
teardown(() => { teardown(() => (destroyed = true));
destroyed = true;
});
return new Proxy( return new Proxy(
{ {
props, 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() { get destroyed() {
return destroyed; return destroyed;
} }

Loading…
Cancel
Save