Skip to content

Commit 18b062c

Browse files
committed
simplify pending boundary detection
1 parent 7631403 commit 18b062c

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

packages/svelte/src/internal/client/dom/blocks/boundary.js

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,12 @@ export function boundary(node, props, boundary_fn) {
7676
var async_fragment = null;
7777
var async_count = 0;
7878

79-
/** @type {Effect | null} */
80-
var parent_boundary = /** @type {Effect} */ (active_effect).parent;
81-
82-
while (parent_boundary !== null && (parent_boundary.f & BOUNDARY_EFFECT) === 0) {
83-
parent_boundary = parent_boundary.parent;
84-
}
85-
8679
block(() => {
8780
var boundary = /** @type {Effect} */ (active_effect);
8881
var hydrate_open = hydrate_node;
8982
var is_creating_fallback = false;
9083

91-
const render_snippet = (/** @type { () => void } */ snippet_fn) => {
84+
var render_snippet = (/** @type { () => void } */ snippet_fn) => {
9285
with_boundary(boundary, () => {
9386
is_creating_fallback = true;
9487

@@ -107,18 +100,9 @@ export function boundary(node, props, boundary_fn) {
107100

108101
// @ts-ignore We re-use the effect's fn property to avoid allocation of an additional field
109102
boundary.fn = (/** @type {unknown} */ input) => {
110-
let pending = props.pending;
103+
let pending = /** @type {(anchor: Node) => void} */ (props.pending);
111104

112105
if (input === ASYNC_INCREMENT) {
113-
if (!pending) {
114-
if (!parent_boundary) {
115-
e.await_outside_boundary();
116-
}
117-
118-
// @ts-ignore
119-
return parent_boundary.fn(input);
120-
}
121-
122106
if (async_count++ === 0) {
123107
queue_boundary_micro_task(() => {
124108
if (async_effect || !boundary_effect) {
@@ -159,15 +143,6 @@ export function boundary(node, props, boundary_fn) {
159143
}
160144

161145
if (input === ASYNC_DECREMENT) {
162-
if (!pending) {
163-
if (!parent_boundary) {
164-
e.await_outside_boundary();
165-
}
166-
167-
// @ts-ignore
168-
return parent_boundary.fn(input);
169-
}
170-
171146
if (--async_count === 0) {
172147
queue_boundary_micro_task(() => {
173148
if (!async_effect) {
@@ -229,6 +204,11 @@ export function boundary(node, props, boundary_fn) {
229204
}
230205
};
231206

207+
if (props.pending) {
208+
// @ts-ignore
209+
boundary.fn.pending = true;
210+
}
211+
232212
if (hydrating) {
233213
hydrate_next();
234214
}
@@ -285,11 +265,19 @@ export function capture() {
285265
};
286266
}
287267

268+
/**
269+
* @param {Effect} boundary
270+
*/
271+
export function is_pending_boundary(boundary) {
272+
// @ts-ignore
273+
return boundary.fn.pending;
274+
}
275+
288276
export function suspend() {
289277
var boundary = active_effect;
290278

291279
while (boundary !== null) {
292-
if ((boundary.f & BOUNDARY_EFFECT) !== 0) {
280+
if ((boundary.f & BOUNDARY_EFFECT) !== 0 && is_pending_boundary(boundary)) {
293281
break;
294282
}
295283

packages/svelte/src/internal/client/runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { lifecycle_outside_component } from '../shared/errors.js';
4343
import { FILENAME } from '../../constants.js';
4444
import { legacy_mode_flag, tracing_mode_flag } from '../flags/index.js';
4545
import { tracing_expressions, get_stack } from './dev/tracing.js';
46+
import { is_pending_boundary } from './dom/blocks/boundary.js';
4647

4748
const FLUSH_MICROTASK = 0;
4849
const FLUSH_SYNC = 1;
@@ -873,8 +874,7 @@ function process_effects(effect, collected_effects) {
873874
if (effect === parent) {
874875
break main_loop;
875876
}
876-
// TODO: we need to know that this boundary has a valid `pending`
877-
if (suspended && (parent.f & BOUNDARY_EFFECT) !== 0) {
877+
if (suspended && (parent.f & BOUNDARY_EFFECT) !== 0 && is_pending_boundary(parent)) {
878878
suspended = false;
879879
}
880880
var parent_sibling = parent.next;

0 commit comments

Comments
 (0)