pull/16197/head
Rich Harris 8 months ago
parent 14330bd770
commit f77df36ff1

@ -140,7 +140,7 @@ export class Boundary {
// the pending or main block was rendered for a given // the pending or main block was rendered for a given
// boundary, and hydrate accordingly // boundary, and hydrate accordingly
queueMicrotask(() => { queueMicrotask(() => {
destroy_effect(/** @type {Effect} */ (this.#pending_effect)); // destroy_effect(/** @type {Effect} */ (this.#pending_effect));
this.#main_effect = this.#run(() => { this.#main_effect = this.#run(() => {
return branch(() => this.#children(this.#anchor)); return branch(() => this.#children(this.#anchor));

@ -105,6 +105,12 @@ export function async_derived(fn, location) {
// only suspend in async deriveds created on initialisation // only suspend in async deriveds created on initialisation
var should_suspend = !active_reaction; var should_suspend = !active_reaction;
var boundary = /** @type {Effect} */ (active_effect).b;
while (boundary !== null && !boundary.has_pending_snippet()) {
boundary = boundary.parent;
}
render_effect(() => { render_effect(() => {
if (DEV) from_async_derived = active_effect; if (DEV) from_async_derived = active_effect;
promise = fn(); promise = fn();
@ -115,8 +121,16 @@ export function async_derived(fn, location) {
var fork = active_fork; var fork = active_fork;
if (should_suspend) { if (should_suspend) {
// TODO if nearest pending boundary is not ready, attach to the boundary if (fork !== null) {
fork?.increment(); fork.increment();
} else {
if (boundary === null) {
throw new Error('TODO');
}
// if nearest pending boundary is not ready, attach to the boundary
boundary.increment();
}
} }
promise.then( promise.then(
@ -129,7 +143,15 @@ export function async_derived(fn, location) {
from_async_derived = null; from_async_derived = null;
if (should_suspend) { if (should_suspend) {
fork?.decrement(); if (fork !== null) {
fork.decrement();
} else {
if (boundary === null) {
throw new Error('TODO');
}
boundary.decrement();
}
} }
if (fork !== null) { if (fork !== null) {

@ -26,6 +26,7 @@ export default test({
await Promise.resolve(); await Promise.resolve();
await Promise.resolve(); await Promise.resolve();
await Promise.resolve(); await Promise.resolve();
await Promise.resolve();
flushSync(); flushSync();
await tick(); await tick();
assert.htmlEqual(target.innerHTML, '<p>42</p>'); assert.htmlEqual(target.innerHTML, '<p>42</p>');

Loading…
Cancel
Save