boundary-batch-nullpointer-fix
Rich Harris 6 days ago
parent dce25638c4
commit 18a790cb64

@ -187,7 +187,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
} }
} }
var b = block(() => { block(() => {
// store a reference to the effect so that we can update the start/end nodes in reconciliation // store a reference to the effect so that we can update the start/end nodes in reconciliation
each_effect ??= /** @type {Effect} */ (active_effect); each_effect ??= /** @type {Effect} */ (active_effect);
@ -310,7 +310,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
} }
} }
batch.add_callback(() => b, commit); batch.add_callback(commit);
} else { } else {
commit(); commit();
} }

@ -124,7 +124,7 @@ export function if_block(node, fn, elseif = false) {
if (active) batch.skipped_effects.delete(active); if (active) batch.skipped_effects.delete(active);
if (inactive) batch.skipped_effects.add(inactive); if (inactive) batch.skipped_effects.add(inactive);
batch.add_callback(() => b, commit); batch.add_callback(commit);
} else { } else {
commit(); commit();
} }
@ -135,7 +135,7 @@ export function if_block(node, fn, elseif = false) {
} }
}; };
var b = block(() => { block(() => {
has_branch = false; has_branch = false;
fn(set_branch); fn(set_branch);
if (!has_branch) { if (!has_branch) {

@ -52,7 +52,7 @@ export function key(node, get_key, render_fn) {
effect = pending_effect; effect = pending_effect;
} }
var b = block(() => { block(() => {
if (changed(key, (key = get_key()))) { if (changed(key, (key = get_key()))) {
var target = anchor; var target = anchor;
@ -66,7 +66,7 @@ export function key(node, get_key, render_fn) {
pending_effect = branch(() => render_fn(target)); pending_effect = branch(() => render_fn(target));
if (defer) { if (defer) {
/** @type {Batch} */ (current_batch).add_callback(() => b, commit); /** @type {Batch} */ (current_batch).add_callback(commit);
} else { } else {
commit(); commit();
} }

@ -51,7 +51,7 @@ export function component(node, get_component, render_fn) {
pending_effect = null; pending_effect = null;
} }
var b = block(() => { block(() => {
if (component === (component = get_component())) return; if (component === (component = get_component())) return;
var defer = should_defer_append(); var defer = should_defer_append();
@ -70,7 +70,7 @@ export function component(node, get_component, render_fn) {
} }
if (defer) { if (defer) {
/** @type {Batch} */ (current_batch).add_callback(() => b, commit); /** @type {Batch} */ (current_batch).add_callback(commit);
} else { } else {
commit(); commit();
} }

@ -97,7 +97,7 @@ export class Batch {
* and append new ones by calling the functions added inside (if/each/key/etc) blocks. * and append new ones by calling the functions added inside (if/each/key/etc) blocks.
* Key is a function that returns the block effect because #callbacks will be called before * Key is a function that returns the block effect because #callbacks will be called before
* the block effect reference exists, so we need to capture it in a closure. * the block effect reference exists, so we need to capture it in a closure.
* @type {Map<() => Effect, () => void>} * @type {Map<Effect, () => void>}
*/ */
#callbacks = new Map(); #callbacks = new Map();
@ -229,7 +229,7 @@ export class Batch {
// is outstanding from a previous flush, commit // is outstanding from a previous flush, commit
if (this.#async_effects.length === 0 && this.#pending === 0) { if (this.#async_effects.length === 0 && this.#pending === 0) {
if (superseded_batches.length > 0) { if (superseded_batches.length > 0) {
const own = [...this.#callbacks.keys()].map((c) => c()); const own = [...this.#callbacks.keys()];
// A superseded batch could have callbacks for e.g. destroying if blocks // A superseded batch could have callbacks for e.g. destroying if blocks
// that are not part of the current batch because it already happened in the prior one, // that are not part of the current batch because it already happened in the prior one,
// and the corresponding block effect therefore returning early because nothing was changed from its // and the corresponding block effect therefore returning early because nothing was changed from its
@ -237,9 +237,9 @@ export class Batch {
// We do it from newest to oldest to ensure the correct callback is applied. // We do it from newest to oldest to ensure the correct callback is applied.
for (const batch of superseded_batches.reverse()) { for (const batch of superseded_batches.reverse()) {
for (const [effect, cb] of batch.#callbacks) { for (const [effect, cb] of batch.#callbacks) {
if (!own.includes(effect())) { if (!own.includes(effect)) {
cb(); cb();
own.push(effect()); own.push(effect);
} }
} }
batch.remove(); batch.remove();
@ -475,11 +475,10 @@ export class Batch {
} }
/** /**
* @param {() => Effect} effect
* @param {() => void} fn * @param {() => void} fn
*/ */
add_callback(effect, fn) { add_callback(fn) {
this.#callbacks.set(effect, fn); this.#callbacks.set(/** @type {Effect} */ (active_effect), fn);
} }
settled() { settled() {

Loading…
Cancel
Save