8000 fix: ensure #if blocks correctly guard against nullable prop values by rChaoz · Pull Request #16140 · sveltejs/svelte · GitHub
[go: up one dir, main page]

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
Next Next commit
thing
  • Loading branch information
rChaoz committed Jun 12, 2025
commit 15883654f38bec87b2db3c7a7fe56ed73c48682b
15 changes: 10 additions & 5 deletions packages/svelte/src/internal/client/reactivity/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ 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';

/**
* @param {((value?: number) => number)} fn
Expand Down Expand Up @@ -159,16 +161,17 @@ 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.
* @template {Record<string | symbol, unknown>} T
* @type {ProxyHandler<{ props: Array<T | (() => T)> }>}}
* @typedef {Record<string | symbol, unknown>} T
* @type {ProxyHandler<{ props: Array<T | (() => T)>, oldProps: T, destroyed: boolean }>}}
*/
const spread_props_handler = {
get(target, key) {
if (target.destroyed && key in target.oldProps) return target.oldProps[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 p[key];
if (typeof p === 'object' && p !== null && key in p) return (target.oldProps[key] = p[key]);
}
},
set(target, key, value) {
Expand All @@ -178,7 +181,7 @@ const spread_props_handler = {
if (is_function(p)) p = p();
const desc = get_descriptor(p, key);
if (desc && desc.set) {
desc.set(value);
desc.set(target.oldProps[key] = value);
return true;
}
}
Expand Down Expand Up @@ -238,7 +241,9 @@ const spread_props_handler = {
* @returns {any}
*/
export function spread_props(...props) {
return new Proxy({ props }, spread_props_handler);
let destroyed = false
teardown(() => { destroyed = true })
return new Proxy({ props, oldProps: {}, get destroyed() { return destroyed } }, spread_props_handler);
}

/**
Expand Down
Loading
0