@@ -49,11 +49,11 @@ export function boundary(node, props, children) {
4949}
5050
5151export class Boundary {
52- pending = false ;
53-
5452 /** @type {Boundary | null } */
5553 parent ;
5654
55+ #pending = false ;
56+
5757 /** @type {TemplateNode } */
5858 #anchor;
5959
@@ -81,6 +81,7 @@ export class Boundary {
8181 /** @type {DocumentFragment | null } */
8282 #offscreen_fragment = null ;
8383
84+ #local_pending_count = 0 ;
8485 #pending_count = 0 ;
8586 #is_creating_fallback = false ;
8687
@@ -95,12 +96,12 @@ export class Boundary {
9596
9697 #effect_pending_update = ( ) => {
9798 if ( this . #effect_pending) {
98- internal_set ( this . #effect_pending, this . #pending_count ) ;
99+ internal_set ( this . #effect_pending, this . #local_pending_count ) ;
99100 }
100101 } ;
101102
102103 #effect_pending_subscriber = createSubscriber ( ( ) => {
103- this . #effect_pending = source ( this . #pending_count ) ;
104+ this . #effect_pending = source ( this . #local_pending_count ) ;
104105
105106 if ( DEV ) {
106107 tag ( this . #effect_pending, '$effect.pending()' ) ;
@@ -125,7 +126,7 @@ export class Boundary {
125126
126127 this . parent = /** @type {Effect } */ ( active_effect ) . b ;
127128
128- this . pending = ! ! this . #props. pending ;
129+ this . # pending = ! ! this . #props. pending ;
129130
130131 this . #effect = block ( ( ) => {
131132 /** @type {Effect } */ ( active_effect ) . b = this ;
@@ -156,7 +157,7 @@ export class Boundary {
156157 this . #pending_effect = null ;
157158 } ) ;
158159
159- this . pending = false ;
160+ this . # pending = false ;
160161 }
161162 } ) ;
162163 } else {
@@ -169,7 +170,7 @@ export class Boundary {
169170 if ( this . #pending_count > 0 ) {
170171 this . #show_pending_snippet( ) ;
171172 } else {
172- this . pending = false ;
173+ this . # pending = false ;
173174 }
174175 }
175176 } , flags ) ;
@@ -179,6 +180,14 @@ export class Boundary {
179180 }
180181 }
181182
183+ /**
184+ * Returns `true` if the effect exists inside a boundary whose pending snippet is shown
185+ * @returns {boolean }
186+ */
187+ is_pending ( ) {
188+ return this . #pending || ( ! ! this . parent && this . parent . is_pending ( ) ) ;
189+ }
190+
182191 has_pending_snippet ( ) {
183192 return ! ! this . #props. pending ;
184193 }
@@ -220,12 +229,25 @@ export class Boundary {
220229 }
221230 }
222231
223- /** @param {1 | -1 } d */
232+ /**
233+ * Updates the pending count associated with the currently visible pending snippet,
234+ * if any, such that we can replace the snippet with content once work is done
235+ * @param {1 | -1 } d
236+ */
224237 #update_pending_count( d ) {
238+ if ( ! this . has_pending_snippet ( ) ) {
239+ if ( this . parent ) {
240+ this . parent . #update_pending_count( d ) ;
241+ return ;
242+ }
243+
244+ e . await_outside_boundary ( ) ;
245+ }
246+
225247 this . #pending_count += d ;
226248
227249 if ( this . #pending_count === 0 ) {
228- this . pending = false ;
250+ this . # pending = false ;
229251
230252 if ( this . #pending_effect) {
231253 pause_effect ( this . #pending_effect, ( ) => {
@@ -240,14 +262,16 @@ export class Boundary {
240262 }
241263 }
242264
243- /** @param {1 | -1 } d */
265+ /**
266+ * Update the source that powers `$effect.pending()` inside this boundary,
267+ * and controls when the current `pending` snippet (if any) is removed.
268+ * Do not call from inside the class
269+ * @param {1 | -1 } d
270+ */
244271 update_pending_count ( d ) {
245- if ( this . has_pending_snippet ( ) ) {
246- this . #update_pending_count( d ) ;
247- } else if ( this . parent ) {
248- this . parent . #update_pending_count( d ) ;
249- }
272+ this . #update_pending_count( d ) ;
250273
274+ this . #local_pending_count += d ;
251275 effect_pending_updates . add ( this . #effect_pending_update) ;
252276 }
253277
@@ -308,7 +332,7 @@ export class Boundary {
308332 } ) ;
309333 }
310334
311- this . pending = true ;
335+ this . # pending = true ;
312336
313337 this . #main_effect = this . #run( ( ) => {
314338 this . #is_creating_fallback = false ;
@@ -318,7 +342,7 @@ export class Boundary {
318342 if ( this . #pending_count > 0 ) {
319343 this . #show_pending_snippet( ) ;
320344 } else {
321- this . pending = false ;
345+ this . # pending = false ;
322346 }
323347 } ;
324348
@@ -384,12 +408,8 @@ function move_effect(effect, fragment) {
384408 }
385409}
386410
387- export function get_pending_boundary ( ) {
388- var boundary = /** @type {Effect } */ ( active_effect ) . b ;
389-
390- while ( boundary !== null && ! boundary . has_pending_snippet ( ) ) {
391- boundary = boundary . parent ;
392- }
411+ export function get_boundary ( ) {
412+ const boundary = /** @type {Effect } */ ( active_effect ) . b ;
393413
394414 if ( boundary === null ) {
395415 e . await_outside_boundary ( ) ;
0 commit comments