Skip to content

fix: ensure #if blocks correctly guard against nullable prop values #16140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Lint & format
  • Loading branch information
rChaoz committed Jun 12, 2025
commit 8072ab5b44a2f9916ca5b786986ff571a0219bf8
16 changes: 8 additions & 8 deletions packages/svelte/src/internal/client/reactivity/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ export function legacy_rest_props(props, exclude) {
* 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<string | symbol, unknown>} AnyProps
* @type {ProxyHandler<{ props: Array<AnyProps | (() => AnyProps)>, oldProps: AnyProps, destroyed: boolean }>}}
* @type {ProxyHandler<{ props: Array<AnyProps | (() => AnyProps)>, old_props: AnyProps, destroyed: boolean }>}}
*/
const spread_props_handler = {
get(target, key) {
if (target.destroyed && key in target.oldProps) return target.oldProps[key];
if (target.destroyed && key in target.old_props) return target.old_props[key];
let i = target.props.length;
while (i--) {
let p = target.props[i];
if (is_function(p)) p = p();
if (typeof p === 'object' && p !== null && key in p) return (target.oldProps[key] = p[key]);
if (typeof p === 'object' && p !== null && key in p) return (target.old_props[key] = p[key]);
}
},
set(target, key, value) {
Expand All @@ -180,7 +180,7 @@ const spread_props_handler = {
if (is_function(p)) p = p();
const desc = get_descriptor(p, key);
if (desc && desc.set) {
desc.set((target.oldProps[key] = value));
desc.set((target.old_props[key] = value));
return true;
}
}
Expand Down Expand Up @@ -259,13 +259,13 @@ export function props(...props) {
return new Proxy(
{
props,
oldProps: untrack(() => {
const oldProps = {};
old_props: untrack(() => {
const old_props = {};
for (let p of props) {
if (typeof p === 'function') p = p();
Object.assign(oldProps, p);
Object.assign(old_props, p);
}
return oldProps;
return old_props;
}),
get destroyed() {
return destroyed;
Expand Down
Loading