@@ -8,7 +8,12 @@ import { emitEvent } from '../shared/qrl/qrl-class';
8
8
import type { QRL } from '../shared/qrl/qrl.public' ;
9
9
import { ChoreType } from '../shared/util-chore-type' ;
10
10
import { _SharedContainer } from '../shared/shared-container' ;
11
- import { inflateQRL , parseQRL , wrapDeserializerProxy } from '../shared/shared-serialization' ;
11
+ import {
12
+ TypeIds ,
13
+ inflateQRL ,
14
+ parseQRL ,
15
+ wrapDeserializerProxy ,
16
+ } from '../shared/shared-serialization' ;
12
17
import { QContainerValue , type HostElement , type ObjToProxyMap } from '../shared/types' ;
13
18
import { EMPTY_ARRAY } from '../shared/utils/flyweight' ;
14
19
import {
@@ -155,11 +160,16 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
155
160
element . setAttribute ( QContainerAttr , QContainerValue . RESUMED ) ;
156
161
element . qContainer = this ;
157
162
163
+ this . $qFuncs$ = getQFuncs ( document , this . $instanceHash$ ) || EMPTY_ARRAY ;
164
+ this . $setServerData$ ( ) ;
165
+ element . setAttribute ( QContainerAttr , QContainerValue . RESUMED ) ;
166
+ element . qContainer = this ;
158
167
const qwikStates = element . querySelectorAll ( 'script[type="qwik/state"]' ) ;
159
168
if ( qwikStates . length !== 0 ) {
160
169
const lastState = qwikStates [ qwikStates . length - 1 ] ;
161
170
this . $rawStateData$ = JSON . parse ( lastState . textContent ! ) ;
162
171
this . $stateData$ = wrapDeserializerProxy ( this , this . $rawStateData$ ) as unknown [ ] ;
172
+ this . $scheduleQRLs$ ( ) ;
163
173
}
164
174
}
165
175
@@ -371,4 +381,23 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
371
381
}
372
382
this . $serverData$ = { containerAttributes } ;
373
383
}
384
+
385
+ /**
386
+ * Schedule all computed signals to be inflated. This is done after at the time of DomContainer
387
+ * creation to ensure that all computed signals are inflated and QRLs are resolved before any
388
+ * signals are used. This is necessary because if a computed QRL is not resolved, it will throw a
389
+ * promise and we will have to rerun the entire function, which we want to avoid.
390
+ */
391
+ private $scheduleQRLs$ ( ) : void {
392
+ const deserializeValue = < T > ( i : number ) => {
393
+ return this . $stateData$ [ i / 2 ] as T ;
394
+ } ;
395
+ for ( let i = 0 ; i < this . $rawStateData$ . length ; i += 2 ) {
396
+ const type = this . $rawStateData$ [ i ] ;
397
+ if ( type === TypeIds . ComputedSignal ) {
398
+ // use deserializer proxy to inflate the computed signal and schedule computed QRL
399
+ deserializeValue ( i ) ;
400
+ }
401
+ }
402
+ }
374
403
}
0 commit comments