@@ -712,7 +712,7 @@ export const createSerializationContext = (
712
712
} as StreamWriter ;
713
713
}
714
714
const seenObjsMap = new Map < unknown , SeenRef > ( ) ;
715
- const pathMap = new Map < unknown , string | number > ( ) ;
715
+ const rootsPathMap = new Map < unknown , string | number > ( ) ;
716
716
const syncFnMap = new Map < string , number > ( ) ;
717
717
const syncFns : string [ ] = [ ] ;
718
718
const roots : unknown [ ] = [ ] ;
@@ -723,14 +723,13 @@ export const createSerializationContext = (
723
723
} ;
724
724
725
725
const $addRootPath$ = ( obj : unknown ) => {
726
- const rootPath = pathMap . get ( obj ) ;
726
+ const rootPath = rootsPathMap . get ( obj ) ;
727
727
if ( rootPath ) {
728
728
return rootPath ;
729
729
}
730
730
const seen = seenObjsMap . get ( obj ) ;
731
731
if ( ! seen ) {
732
- // TODO:
733
- throw qError ( QError . serializeErrorMissingRootId ) ;
732
+ throw qError ( QError . serializeErrorMissingRootId , [ obj ] ) ;
734
733
}
735
734
const path = [ ] ;
736
735
let current : typeof seen | undefined = seen ;
@@ -745,7 +744,7 @@ export const createSerializationContext = (
745
744
}
746
745
747
746
const pathStr = path . length > 1 ? path . join ( ' ' ) : path . length ? path [ 0 ] : seen . $index$ ;
748
- pathMap . set ( obj , pathStr ) ;
747
+ rootsPathMap . set ( obj , pathStr ) ;
749
748
return pathStr ;
750
749
} ;
751
750
@@ -818,7 +817,7 @@ export const createSerializationContext = (
818
817
$getProp$ : getProp ,
819
818
$setProp$ : setProp ,
820
819
$prepVNodeData$ : prepVNodeData ,
821
- $pathMap$ : pathMap ,
820
+ $pathMap$ : rootsPathMap ,
822
821
} ;
823
822
} ;
824
823
@@ -1296,7 +1295,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
1296
1295
1297
1296
function $resolvePromise$ (
1298
1297
promise : Promise < unknown > ,
1299
- $addRoot$ : ( obj : unknown ) => string | number ,
1298
+ $addRoot$ : ( obj : unknown ) => number ,
1300
1299
classCreator : ( resolved : boolean , resolvedValue : unknown ) => PromiseResult
1301
1300
) {
1302
1301
const forwardRefId = forwardRefsId ++ ;
@@ -1315,44 +1314,50 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
1315
1314
return forwardRefId ;
1316
1315
}
1317
1316
1318
- $writer$ . write ( '[' ) ;
1317
+ const outputRoots = async ( ) => {
1318
+ $writer$ . write ( '[' ) ;
1319
1319
1320
- let lastRootsLength = 0 ;
1321
- let rootsLength = serializationContext . $roots$ . length ;
1322
- while ( lastRootsLength < rootsLength || promises . size ) {
1323
- if ( lastRootsLength !== 0 ) {
1324
- $writer$ . write ( ',' ) ;
1325
- }
1326
- for ( let i = lastRootsLength ; i < rootsLength ; i ++ ) {
1327
- const root = serializationContext . $roots$ [ i ] ;
1328
- writeValue ( root ) ;
1329
- const isLast = i === rootsLength - 1 ;
1330
- if ( ! isLast ) {
1320
+ let lastRootsLength = 0 ;
1321
+ let rootsLength = serializationContext . $roots$ . length ;
1322
+ while ( lastRootsLength < rootsLength || promises . size ) {
1323
+ if ( lastRootsLength !== 0 ) {
1331
1324
$writer$ . write ( ',' ) ;
1332
1325
}
1333
- }
1334
1326
1335
- if ( promises . size ) {
1336
- try {
1337
- await Promise . race ( promises ) ;
1338
- } catch {
1339
- // ignore rejections, they will be serialized as rejected promises
1327
+ let separator = false ;
1328
+ for ( let i = lastRootsLength ; i < rootsLength ; i ++ ) {
1329
+ if ( separator ) {
1330
+ $writer$ . write ( ',' ) ;
1331
+ } else {
1332
+ separator = true ;
1333
+ }
1334
+ writeValue ( serializationContext . $roots$ [ i ] ) ;
1335
+ }
1336
+
1337
+ if ( promises . size ) {
1338
+ try {
1339
+ await Promise . race ( promises ) ;
1340
+ } catch {
1341
+ // ignore rejections, they will be serialized as rejected promises
1342
+ }
1340
1343
}
1344
+
1345
+ lastRootsLength = rootsLength ;
1346
+ rootsLength = serializationContext . $roots$ . length ;
1341
1347
}
1342
1348
1343
- lastRootsLength = rootsLength ;
1344
- rootsLength = serializationContext . $roots$ . length ;
1345
- }
1349
+ if ( forwardRefs . length ) {
1350
+ $writer$ . write ( ',' ) ;
1351
+ $writer$ . write ( TypeIds . ForwardRefs + ',' ) ;
1352
+ outputArray ( forwardRefs , ( value ) => {
1353
+ $writer$ . write ( String ( value ) ) ;
1354
+ } ) ;
1355
+ }
1346
1356
1347
- if ( forwardRefs . length ) {
1348
- $writer$ . write ( ',' ) ;
1349
- $writer$ . write ( TypeIds . ForwardRefs + ',' ) ;
1350
- outputArray ( forwardRefs , ( value ) => {
1351
- $writer$ . write ( String ( value ) ) ;
1352
- } ) ;
1353
- }
1357
+ $writer$ . write ( ']' ) ;
1358
+ } ;
1354
1359
1355
- $writer$ . write ( ']' ) ;
1360
+ await outputRoots ( ) ;
1356
1361
}
1357
1362
1358
1363
function $getCustomSerializerPromise$ < T , S > ( signal : SerializerSignalImpl < T , S > , value : any ) {
0 commit comments