@@ -1305,7 +1305,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
1305
1305
1306
1306
function $resolvePromise$ (
1307
1307
promise : Promise < unknown > ,
1308
- $addRoot$ : ( obj : unknown ) => string | number ,
1308
+ $addRoot$ : ( obj : unknown ) => number ,
1309
1309
classCreator : ( resolved : boolean , resolvedValue : unknown ) => PromiseResult
1310
1310
) {
1311
1311
const forwardRefId = forwardRefsId ++ ;
@@ -1324,44 +1324,50 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
1324
1324
return forwardRefId ;
1325
1325
}
1326
1326
1327
- $writer$ . write ( '[' ) ;
1327
+ const outputRoots = async ( ) => {
1328
+ $writer$ . write ( '[' ) ;
1328
1329
1329
- let lastRootsLength = 0 ;
1330
- let rootsLength = serializationContext . $roots$ . length ;
1331
- while ( lastRootsLength < rootsLength || promises . size ) {
1332
- if ( lastRootsLength !== 0 ) {
1333
- $writer$ . write ( ',' ) ;
1334
- }
1335
- for ( let i = lastRootsLength ; i < rootsLength ; i ++ ) {
1336
- const root = serializationContext . $roots$ [ i ] ;
1337
- writeValue ( root ) ;
1338
- const isLast = i === rootsLength - 1 ;
1339
- if ( ! isLast ) {
1330
+ let lastRootsLength = 0 ;
1331
+ let rootsLength = serializationContext . $roots$ . length ;
1332
+ while ( lastRootsLength < rootsLength || promises . size ) {
1333
+ if ( lastRootsLength !== 0 ) {
1340
1334
$writer$ . write ( ',' ) ;
1341
1335
}
1342
- }
1343
1336
1344
- if ( promises . size ) {
1345
- try {
1346
- await Promise . race ( promises ) ;
1347
- } catch {
1348
- // ignore rejections, they will be serialized as rejected promises
1337
+ let separator = false ;
1338
+ for ( let i = lastRootsLength ; i < rootsLength ; i ++ ) {
1339
+ if ( separator ) {
1340
+ $writer$ . write ( ',' ) ;
1341
+ } else {
1342
+ separator = true ;
1343
+ }
1344
+ writeValue ( serializationContext . $roots$ [ i ] ) ;
1345
+ }
1346
+
1347
+ if ( promises . size ) {
1348
+ try {
1349
+ await Promise . race ( promises ) ;
1350
+ } catch {
1351
+ // ignore rejections, they will be serialized as rejected promises
1352
+ }
1349
1353
}
1354
+
1355
+ lastRootsLength = rootsLength ;
1356
+ rootsLength = serializationContext . $roots$ . length ;
1350
1357
}
1351
1358
1352
- lastRootsLength = rootsLength ;
1353
- rootsLength = serializationContext . $roots$ . length ;
1354
- }
1359
+ if ( forwardRefs . length ) {
1360
+ $writer$ . write ( ',' ) ;
1361
+ $writer$ . write ( TypeIds . ForwardRefs + ',' ) ;
1362
+ outputArray ( forwardRefs , ( value ) => {
1363
+ $writer$ . write ( String ( value ) ) ;
1364
+ } ) ;
1365
+ }
1355
1366
1356
- if ( forwardRefs . length ) {
1357
- $writer$ . write ( ',' ) ;
1358
- $writer$ . write ( TypeIds . ForwardRefs + ',' ) ;
1359
- outputArray ( forwardRefs , ( value ) => {
1360
- $writer$ . write ( String ( value ) ) ;
1361
- } ) ;
1362
- }
1367
+ $writer$ . write ( ']' ) ;
1368
+ } ;
1363
1369
1364
- $writer$ . write ( ']' ) ;
1370
+ await outputRoots ( ) ;
1365
1371
}
1366
1372
1367
1373
function $getCustomSerializerPromise$ < T , S > ( signal : SerializerSignalImpl < T , S > , value : any ) {
0 commit comments