fix: set deferreds on initial suspense, too (#17884)

The combination of #17873 and #17805 resulted in a bad merge of the
latter because it wasn't up to date with main. This fixes it. No
changeset because not released yet.

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/17854/head
Simon H 4 months ago committed by GitHub
parent 6fb7b4d265
commit 1304208970
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,5 +1,6 @@
/** @import { Derived, Effect, Source } from '#client' */
/** @import { Batch } from './batch.js'; */
/** @import { Boundary } from '../dom/blocks/boundary.js'; */
import { DEV } from 'esm-env';
import {
ERROR_VALUE,
@ -145,11 +146,13 @@ export function async_derived(fn, label, location) {
var batch = /** @type {Batch} */ (current_batch);
// we only increment the batch's pending state for updates, not creation, otherwise
// we will decrement to zero before the work that depends on this promise (e.g. a
// template effect) has initialized, causing the batch to resolve prematurely
if (should_suspend && (effect.f & REACTION_RAN) !== 0) {
var decrement_pending = increment_pending();
if (should_suspend) {
// we only increment the batch's pending state for updates, not creation, otherwise
// we will decrement to zero before the work that depends on this promise (e.g. a
// template effect) has initialized, causing the batch to resolve prematurely
if ((effect.f & REACTION_RAN) !== 0) {
var decrement_pending = increment_pending();
}
if (/** @type {Boundary} */ (parent.b).is_rendered()) {
deferreds.get(batch)?.reject(STALE_REACTION);

Loading…
Cancel
Save