11/** @import { TemplateNode, Dom, Effect } from '#client' */
22import { EFFECT_TRANSPARENT } from '../../constants.js' ;
33import { block , branch , pause_effect } from '../../reactivity/effects.js' ;
4+ import { active_effect } from '../../runtime.js' ;
45import { hydrate_next , hydrate_node , hydrating } from '../hydration.js' ;
6+ import { should_defer_append } from '../operations.js' ;
7+ import { add_boundary_callback , find_boundary } from './boundary.js' ;
58
69/**
710 * @template P
@@ -24,16 +27,47 @@ export function component(node, get_component, render_fn) {
2427 /** @type {Effect | null } */
2528 var effect ;
2629
27- block ( ( ) => {
28- if ( component === ( component = get_component ( ) ) ) return ;
30+ /** @type {DocumentFragment | null } */
31+ var offscreen_fragment = null ;
32+
33+ /** @type {Effect | null } */
34+ var pending_effect = null ;
2935
36+ var boundary = find_boundary ( active_effect ) ;
37+
38+ function commit ( ) {
3039 if ( effect ) {
3140 pause_effect ( effect ) ;
3241 effect = null ;
3342 }
3443
44+ if ( offscreen_fragment ) {
45+ anchor . before ( offscreen_fragment ) ;
46+ offscreen_fragment = null ;
47+ }
48+
49+ effect = pending_effect ;
50+ }
51+
52+ block ( ( ) => {
53+ if ( component === ( component = get_component ( ) ) ) return ;
54+
3555 if ( component ) {
36- effect = branch ( ( ) => render_fn ( anchor , component ) ) ;
56+ var defer = boundary !== null && should_defer_append ( ) ;
57+ var target = anchor ;
58+
59+ if ( defer ) {
60+ offscreen_fragment = document . createDocumentFragment ( ) ;
61+ offscreen_fragment . append ( ( target = document . createComment ( '' ) ) ) ;
62+ }
63+
64+ pending_effect = branch ( ( ) => render_fn ( anchor , component ) ) ;
65+
66+ if ( defer ) {
67+ add_boundary_callback ( boundary , commit ) ;
68+ } else {
69+ commit ( ) ;
70+ }
3771 }
3872 } , EFFECT_TRANSPARENT ) ;
3973
0 commit comments