fix: prevent component pre-mounting in async boundaries

pull/16633/head
harshmandan 3 weeks ago
parent 7b2d774627
commit 1ac643f1ee

@ -4,7 +4,7 @@ import { EFFECT_TRANSPARENT } from '#client/constants';
import { block, branch, pause_effect } from '../../reactivity/effects.js'; import { block, branch, pause_effect } from '../../reactivity/effects.js';
import { current_batch } from '../../reactivity/batch.js'; import { current_batch } from '../../reactivity/batch.js';
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js'; import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
import { create_text, should_defer_append } from '../operations.js'; import { should_defer_append } from '../operations.js';
/** /**
* @template P * @template P
@ -27,19 +27,13 @@ export function component(node, get_component, render_fn) {
/** @type {Effect | null} */ /** @type {Effect | null} */
var effect; var effect;
/** @type {DocumentFragment | null} */
var offscreen_fragment = null;
/** @type {Effect | null} */ /** @type {Effect | null} */
var pending_effect = null; var pending_effect = null;
function commit() { function commit() {
if (offscreen_fragment) { if (effect) {
// remove the anchor pause_effect(effect);
/** @type {Text} */ (offscreen_fragment.lastChild).remove(); effect = null;
anchor.before(offscreen_fragment);
offscreen_fragment = null;
} }
effect = pending_effect; effect = pending_effect;
@ -51,25 +45,23 @@ export function component(node, get_component, render_fn) {
var defer = should_defer_append(); var defer = should_defer_append();
if (effect) {
pause_effect(effect);
effect = null;
}
if (component) { if (component) {
var target = anchor;
if (defer) { if (defer) {
offscreen_fragment = document.createDocumentFragment();
offscreen_fragment.append((target = create_text()));
if (effect) { if (effect) {
/** @type {Batch} */ (current_batch).skipped_effects.add(effect); /** @type {Batch} */ (current_batch).skipped_effects.add(effect);
} }
/** @type {Batch} */ (current_batch).add_callback(() => {
if (effect) {
pause_effect(effect);
effect = null;
} }
pending_effect = branch(() => render_fn(target, component)); effect = branch(() => render_fn(anchor, component));
});
} else {
pending_effect = branch(() => render_fn(anchor, component));
commit();
} }
} else if (defer) {
if (defer) {
/** @type {Batch} */ (current_batch).add_callback(commit); /** @type {Batch} */ (current_batch).add_callback(commit);
} else { } else {
commit(); commit();

Loading…
Cancel
Save