i take it back, opencode didn't get it to work at all. revert revert revert

defer-effects-in-pending-boundary
Rich Harris 5 months ago
parent 439ef8bb57
commit a3d46fc362

@ -37,7 +37,7 @@ import { queue_micro_task } from '../task.js';
import * as e from '../../errors.js';
import * as w from '../../warnings.js';
import { DEV } from 'esm-env';
import { Batch, flushSync, schedule_effect } from '../../reactivity/batch.js';
import { Batch, schedule_effect } from '../../reactivity/batch.js';
import { internal_set, source } from '../../reactivity/sources.js';
import { tag } from '../../dev/tracing.js';
import { createSubscriber } from '../../../../reactivity/create-subscriber.js';
@ -164,9 +164,7 @@ export class Boundary {
} else {
this.#hydrate_resolved_content();
// Match the non-hydrating logic: only stay pending if there's
// actual pending async work
if (this.#local_pending_count === 0) {
if (this.#pending_count === 0) {
this.is_pending = false;
}
}
@ -263,14 +261,6 @@ export class Boundary {
return !!this.#props.pending;
}
/**
* Returns true if there's pending async work in this boundary
* @returns {boolean}
*/
has_pending_async() {
return this.#local_pending_count > 0;
}
/**
* @param {() => Effect | null} fn
*/
@ -374,12 +364,6 @@ export class Boundary {
this.#local_pending_count += d;
// async work completed — if we don't have a pending snippet,
// we need to reschedule deferred effects here
if (this.#local_pending_count === 0 && !this.has_pending_snippet()) {
this.#reschedule_deferred_effects();
}
if (!this.#effect_pending || this.#pending_count_update_queued) return;
this.#pending_count_update_queued = true;

@ -1,4 +1,3 @@
/** @import { Boundary } from '../dom/blocks/boundary' */
/** @import { Blocker, ComponentContext, ComponentContextLegacy, Derived, Effect, TemplateNode, TransitionManager } from '#client' */
import {
is_dirty,
@ -42,8 +41,6 @@ import { define_property } from '../../shared/utils.js';
import { get_next_sibling } from '../dom/operations.js';
import { component_context, dev_current_component_function, dev_stack } from '../context.js';
import { Batch, current_batch, schedule_effect } from './batch.js';
import { hydrating } from '../dom/hydration.js';
import { async_mode_flag } from '../../flags/index.js';
import { flatten } from './async.js';
import { without_reactive_context } from '../dom/elements/bindings/shared.js';
import { set_signal_status } from './status.js';
@ -122,18 +119,7 @@ function create_effect(type, fn, sync) {
effect.component_function = dev_current_component_function;
}
// During hydration, defer template effects until local promises have resolved
var should_defer =
async_mode_flag &&
hydrating &&
fn !== null &&
(type & RENDER_EFFECT) !== 0 &&
effect.b?.has_pending_async();
if (should_defer) {
// Store the effect in the boundary so it can be rescheduled when async work completes
/** @type {Boundary} */ (effect.b).defer_effect(effect);
} else if (sync) {
if (sync) {
try {
update_effect(effect);
} catch (e) {
@ -150,10 +136,8 @@ function create_effect(type, fn, sync) {
// if an effect has already ran and doesn't need to be kept in the tree
// (because it won't re-run, has no DOM, and has no teardown etc)
// then we skip it and go to its child (if any)
// NOTE: We only do this pruning if the effect actually ran (!should_defer)
if (
sync &&
!should_defer &&
e.deps === null &&
e.teardown === null &&
e.nodes === null &&

Loading…
Cancel
Save