@@ -4,11 +4,17 @@ import { assertTrue } from '../shared/error/assert';
4
4
import { QError , qError } from '../shared/error/error' ;
5
5
import { ERROR_CONTEXT , isRecoverable } from '../shared/error/error-handling' ;
6
6
import { getPlatform } from '../shared/platform/platform' ;
7
- import { emitEvent } from '../shared/qrl/qrl-class' ;
7
+ import { emitEvent , type QRLInternal } 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
+ getObjectById ,
13
+ inflateQRL ,
14
+ parseQRL ,
15
+ preprocessState ,
16
+ wrapDeserializerProxy ,
17
+ } from '../shared/shared-serialization' ;
12
18
import { QContainerValue , type HostElement , type ObjToProxyMap } from '../shared/types' ;
13
19
import { EMPTY_ARRAY } from '../shared/utils/flyweight' ;
14
20
import {
@@ -112,6 +118,8 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
112
118
public $storeProxyMap$ : ObjToProxyMap = new WeakMap ( ) ;
113
119
public $qFuncs$ : Array < ( ...args : unknown [ ] ) => unknown > ;
114
120
public $instanceHash$ : string ;
121
+ public $forwardRefs$ : Array < number > | null = null ;
122
+ public $initialQRLsIndexes$ : Array < number > | null = null ;
115
123
public vNodeLocate : ( id : string | Element ) => VNode = ( id ) => vnode_locate ( this . rootVNode , id ) ;
116
124
117
125
private $stateData$ : unknown [ ] ;
@@ -159,7 +167,9 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
159
167
if ( qwikStates . length !== 0 ) {
160
168
const lastState = qwikStates [ qwikStates . length - 1 ] ;
161
169
this . $rawStateData$ = JSON . parse ( lastState . textContent ! ) ;
170
+ preprocessState ( this . $rawStateData$ , this ) ;
162
171
this . $stateData$ = wrapDeserializerProxy ( this , this . $rawStateData$ ) as unknown [ ] ;
172
+ this . $scheduleInitialQRLs$ ( ) ;
163
173
}
164
174
}
165
175
@@ -316,14 +326,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
316
326
}
317
327
318
328
$getObjectById$ = ( id : number | string ) : unknown => {
319
- if ( typeof id === 'string' ) {
320
- id = parseFloat ( id ) ;
321
- }
322
- assertTrue (
323
- id < this . $rawStateData$ . length / 2 ,
324
- `Invalid reference: ${ id } >= ${ this . $rawStateData$ . length / 2 } `
325
- ) ;
326
- return this . $stateData$ [ id ] ;
329
+ return getObjectById ( id , this . $stateData$ ) ;
327
330
} ;
328
331
329
332
getSyncFn ( id : number ) : ( ...args : unknown [ ] ) => unknown {
@@ -371,4 +374,17 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
371
374
}
372
375
this . $serverData$ = { containerAttributes } ;
373
376
}
377
+
378
+ private $scheduleInitialQRLs$ ( ) : void {
379
+ if ( this . $initialQRLsIndexes$ ) {
380
+ for ( const index of this . $initialQRLsIndexes$ ) {
381
+ this . $scheduler$ (
382
+ ChoreType . QRL_RESOLVE ,
383
+ null ,
384
+ this . $getObjectById$ ( index ) as QRLInternal < ( ...args : unknown [ ] ) => unknown >
385
+ ) ;
386
+ }
387
+ this . $initialQRLsIndexes$ = null ;
388
+ }
389
+ }
374
390
}
0 commit comments