1
- /** @import { Effect, TemplateNode, } from '#client' */
2
-
1
+ /** @import { Effect, Source, TemplateNode, } from '#client' */
3
2
import { BOUNDARY_EFFECT , EFFECT_PRESERVED , EFFECT_TRANSPARENT } from '#client/constants' ;
4
3
import { component_context , set_component_context } from '../../context.js' ;
5
4
import { invoke_error_boundary } from '../../error-handling.js' ;
@@ -25,8 +24,9 @@ import * as e from '../../../shared/errors.js';
25
24
import { DEV } from 'esm-env' ;
26
25
import { from_async_derived , set_from_async_derived } from '../../reactivity/deriveds.js' ;
27
26
import { Batch } from '../../reactivity/batch.js' ;
28
- import { source , update } from '../../reactivity/sources.js' ;
27
+ import { internal_set , source } from '../../reactivity/sources.js' ;
29
28
import { tag } from '../../dev/tracing.js' ;
29
+ import { createSubscriber } from '../../../../reactivity/create-subscriber.js' ;
30
30
31
31
/**
32
32
* @typedef {{
@@ -85,7 +85,22 @@ export class Boundary {
85
85
#pending_count = 0 ;
86
86
#is_creating_fallback = false ;
87
87
88
- effect_pending = source ( 0 ) ;
88
+ /**
89
+ * @type {Source<number> | null }
90
+ */
91
+ #effect_pending = null ;
92
+
93
+ #effect_pending_subscriber = createSubscriber ( ( ) => {
94
+ this . #effect_pending = source ( this . #pending_count) ;
95
+
96
+ if ( DEV ) {
97
+ tag ( this . #effect_pending, '$effect.pending()' ) ;
98
+ }
99
+
100
+ return ( ) => {
101
+ this . #effect_pending = null ;
102
+ } ;
103
+ } ) ;
89
104
90
105
/**
91
106
* @param {TemplateNode } node
@@ -103,10 +118,6 @@ export class Boundary {
103
118
104
119
this . pending = ! ! this . #props. pending ;
105
120
106
- if ( DEV ) {
107
- tag ( this . effect_pending , '$effect.pending()' ) ;
108
- }
109
-
110
121
this . #effect = block ( ( ) => {
111
122
/** @type {Effect } */ ( active_effect ) . b = this ;
112
123
@@ -237,10 +248,17 @@ export class Boundary {
237
248
}
238
249
239
250
queueMicrotask ( ( ) => {
240
- update ( this . effect_pending , d ) ;
251
+ if ( this . #effect_pending) {
252
+ internal_set ( this . #effect_pending, this . #pending_count) ;
253
+ }
241
254
} ) ;
242
255
}
243
256
257
+ get_effect_pending ( ) {
258
+ this . #effect_pending_subscriber( ) ;
259
+ return get ( /** @type {Source<number> } */ ( this . #effect_pending) ) ;
260
+ }
261
+
244
262
/** @param {unknown } error */
245
263
error ( error ) {
246
264
var onerror = this . #props. onerror ;
@@ -429,5 +447,5 @@ export function pending() {
429
447
return 0 ; // TODO eventually we will need this to be global
430
448
}
431
449
432
- return get ( boundary . effect_pending ) ;
450
+ return boundary . get_effect_pending ( ) ;
433
451
}
0 commit comments