Content-Length: 511828 | pFad | http://github.com/sveltejs/svelte/pull/16140/commits/bb239fb965e6f6ce45f8a25db105a6a3f2a5dbcd

22 fix: ensure #if blocks correctly guard against nullable prop values by rChaoz · Pull Request #16140 · sveltejs/svelte · GitHub
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
Revert #15469
  • Loading branch information
rChaoz committed Jun 12, 2025
commit bb239fb965e6f6ce45f8a25db105a6a3f2a5dbcd
9 changes: 2 additions & 7 deletions packages/svelte/src/internal/client/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,15 @@ export function getAllContexts() {
* @returns {void}
*/
export function push(props, runes = false, fn) {
var ctx = (component_context = {
component_context = {
p: component_context,
c: null,
d: false,
e: null,
m: false,
s: props,
x: null,
l: null
});
};

if (legacy_mode_flag && !runes) {
component_context.l = {
Expand All @@ -121,10 +120,6 @@ export function push(props, runes = false, fn) {
};
}

teardown(() => {
/** @type {ComponentContext} */ (ctx).d = true;
});

if (DEV) {
// component function
component_context.function = fn;
Expand Down
32 changes: 5 additions & 27 deletions packages/svelte/src/internal/client/reactivity/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,19 @@ const spread_props_handler = {
* @returns {any}
*/
export function props(...props) {
let paused = false;
const context = component_context;
let destroyed = false;
if (active_effect) {
(active_effect.transitions ??= []).push({
is_global: true,
in() {
paused = false;
destroyed = false;
},
out(callback) {
paused = true;
destroyed = true;
callback?.();
},
stop() {
paused = true;
destroyed = true;
}
});
}
Expand All @@ -269,21 +268,13 @@ export function props(...props) {
return oldProps;
}),
get destroyed() {
return (context?.d ?? false) || paused;
return destroyed;
}
},
spread_props_handler
);
}

/**
* @param {Derived} current_value
* @returns {boolean}
*/
function has_destroyed_component_ctx(current_value) {
return current_value.ctx?.d ?? false;
}

/**
* This function is responsible for synchronizing a possibly bound prop with the inner component state.
* It is used whenever the compiler sees that the component writes to the prop, or when it has a default prop_value.
Expand Down Expand Up @@ -417,11 +408,6 @@ export function prop(props, key, flags, fallback) {
return (inner_current_value.v = parent_value);
});

// Ensure we eagerly capture the initial value if it's bindable
if (bindable) {
get(current_value);
}

if (!immutable) current_value.equals = safe_equals;

return function (/** @type {any} */ value, /** @type {boolean} */ mutation) {
Expand Down Expand Up @@ -449,20 +435,12 @@ export function prop(props, key, flags, fallback) {
fallback_value = new_value;
}

if (has_destroyed_component_ctx(current_value)) {
return value;
}

untrack(() => get(current_value)); // force a synchronisation immediately
}

return value;
}

if (has_destroyed_component_ctx(current_value)) {
return current_value.v;
}

return get(current_value);
};
}
12 changes: 0 additions & 12 deletions packages/svelte/src/internal/client/reactivity/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
reaction_sources,
check_dirtiness,
untracking,
is_destroying_effect,
push_reaction_value
} from '../runtime.js';
import { equals, safe_equals } from './equality.js';
Expand All @@ -38,9 +37,6 @@ import { execute_derived } from './deriveds.js';

export let inspect_effects = new Set();

/** @type {Map<Source, any>} */
export const old_values = new Map();

/**
* @param {Set<any>} v
*/
Expand Down Expand Up @@ -160,14 +156,6 @@ export function set(source, value, should_proxy = false) {
*/
export function internal_set(source, value) {
if (!source.equals(value)) {
var old_value = source.v;

if (is_destroying_effect) {
old_values.set(source, value);
} else {
old_values.set(source, old_value);
}

source.v = value;

if (DEV && tracing_mode_flag) {
Expand Down
7 changes: 1 addition & 6 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
EFFECT_IS_UPDATING
} from './constants.js';
import { flush_tasks } from './dom/task.js';
import { internal_set, old_values } from './reactivity/sources.js';
import { internal_set } from './reactivity/sources.js';
import { destroy_derived_effects, update_derived } from './reactivity/deriveds.js';
import * as e from './errors.js';

Expand Down Expand Up @@ -535,7 +535,6 @@ function flush_queued_root_effects() {
var collected_effects = process_effects(root_effects[i]);
flush_queued_effects(collected_effects);
}
old_values.clear();
}
} finally {
is_flushing = false;
Expand Down Expand Up @@ -800,10 +799,6 @@ export function get(signal) {
}
}

if (is_destroying_effect && old_values.has(signal)) {
return old_values.get(signal);
}

return signal.v;
}

Expand Down
2 changes: 0 additions & 2 deletions packages/svelte/src/internal/client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export type ComponentContext = {
p: null | ComponentContext;
/** context */
c: null | Map<unknown, unknown>;
/** destroyed */
d: boolean;
/** deferred effects */
e: null | Array<{
fn: () => void | (() => void);
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/sveltejs/svelte/pull/16140/commits/bb239fb965e6f6ce45f8a25db105a6a3f2a5dbcd

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy