From aa0bf59872379da5f55201a9d1d62125642d5c8f Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 10 Feb 2025 19:09:48 +0000 Subject: [PATCH] is pending --- packages/svelte/src/index-client.js | 1 + .../internal/client/dom/blocks/boundary.js | 25 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/svelte/src/index-client.js b/packages/svelte/src/index-client.js index ca29d5bfbe..af155f1112 100644 --- a/packages/svelte/src/index-client.js +++ b/packages/svelte/src/index-client.js @@ -219,3 +219,4 @@ export { getContext, getAllContexts, hasContext, setContext } from './internal/c export { hydrate, mount, unmount } from './internal/client/render.js'; export { tick, untrack } from './internal/client/runtime.js'; export { createRawSnippet } from './internal/client/dom/blocks/snippet.js'; +export { isPending } from './internal/client/dom/blocks/boundary.js'; diff --git a/packages/svelte/src/internal/client/dom/blocks/boundary.js b/packages/svelte/src/internal/client/dom/blocks/boundary.js index 2698ec5408..ee7369c0c8 100644 --- a/packages/svelte/src/internal/client/dom/blocks/boundary.js +++ b/packages/svelte/src/internal/client/dom/blocks/boundary.js @@ -19,7 +19,8 @@ import { set_active_reaction, reset_is_throwing_error, schedule_effect, - increment_write_version + increment_write_version, + get } from '../../runtime.js'; import { hydrate_next, @@ -36,7 +37,7 @@ import { DEV } from 'esm-env'; import { from_async_derived, set_from_async_derived } from '../../reactivity/deriveds.js'; import { raf } from '../../timing.js'; import { loop } from '../../loop.js'; -import { internal_set, mark_reactions } from '../../reactivity/sources.js'; +import { internal_set, mark_reactions, source } from '../../reactivity/sources.js'; const ASYNC_INCREMENT = Symbol(); const ASYNC_DECREMENT = Symbol(); @@ -84,6 +85,8 @@ export function boundary(node, props, children) { var parent_boundary = find_boundary(active_effect); + var is_pending = source(false); + block(() => { /** @type {Effect | null} */ var main_effect = null; @@ -177,6 +180,7 @@ export function boundary(node, props, children) { } } forks.clear(); + internal_set(is_pending, false); for (const fn of callbacks) fn(); callbacks.clear(); @@ -252,6 +256,8 @@ export function boundary(node, props, children) { boundary.f |= BOUNDARY_SUSPENDED; async_count++; + internal_set(is_pending, true); + return; } @@ -323,7 +329,10 @@ export function boundary(node, props, children) { boundary.fn.forks = new Map(); // @ts-ignore - boundary.fn.is_pending = () => props.pending; + boundary.fn.props = props; + + // @ts-ignore + boundary.fn.is_pending = is_pending; if (hydrating) { hydrate_next(); @@ -408,7 +417,7 @@ export function capture(track = true) { */ export function is_pending_boundary(boundary) { // @ts-ignore - return boundary.fn.is_pending(); + return boundary.fn.props.pending; } /** @@ -488,3 +497,11 @@ export function add_boundary_callback(boundary, fn) { // @ts-ignore boundary.fn(ADD_CALLBACK, fn); } + +export function isPending() { + var effect = active_effect; + var boundary = get_boundary(effect); + // @ts-ignore + var is_pending = boundary.fn.is_pending; + return get(is_pending); +}