@@ -175,13 +175,13 @@ class DeserializationHandler implements ProxyHandler<object> {
175
175
*/
176
176
export const _eagerDeserializeArray = (
177
177
container : DeserializeContainer ,
178
- data : unknown [ ]
178
+ data : unknown [ ] ,
179
+ output : unknown [ ] = Array ( data . length / 2 )
179
180
) : unknown [ ] => {
180
- const out = Array ( data . length / 2 ) ;
181
181
for ( let i = 0 ; i < data . length ; i += 2 ) {
182
- out [ i / 2 ] = deserializeData ( container , data [ i ] as TypeIds , data [ i + 1 ] ) ;
182
+ output [ i / 2 ] = deserializeData ( container , data [ i ] as TypeIds , data [ i + 1 ] ) ;
183
183
}
184
- return out ;
184
+ return output ;
185
185
} ;
186
186
187
187
const resolvers = new WeakMap < Promise < any > , [ Function , Function ] > ( ) ;
@@ -196,16 +196,14 @@ const inflate = (
196
196
// Already processed
197
197
return ;
198
198
}
199
- // Restore the complex data
200
- if ( Array . isArray ( data ) ) {
199
+ // Restore the complex data, special case for Array
200
+ if ( typeId !== TypeIds . Array && Array . isArray ( data ) ) {
201
201
data = _eagerDeserializeArray ( container , data ) ;
202
202
}
203
203
switch ( typeId ) {
204
204
case TypeIds . Array :
205
- for ( let i = 0 ; i < ( target as any [ ] ) . length ; i ++ ) {
206
- // read the value to trigger lazy deserialization
207
- ( target as any [ ] ) [ i ] ;
208
- }
205
+ // Arrays are special, we need to fill the array in place
206
+ _eagerDeserializeArray ( container , data as unknown [ ] , target as unknown [ ] ) ;
209
207
break ;
210
208
case TypeIds . Object :
211
209
for ( let i = 0 ; i < ( data as any [ ] ) . length ; i += 2 ) {
@@ -480,8 +478,7 @@ const allocate = (container: DeserializeContainer, typeId: number, value: unknow
480
478
case TypeIds . Constant :
481
479
return _constants [ value as Constants ] ;
482
480
case TypeIds . Array :
483
- // Wrap while inflating so we can handle cyclic references
484
- return wrapDeserializerProxy ( container as any , value as any [ ] ) ;
481
+ return Array ( ( value as any [ ] ) . length / 2 ) ;
485
482
case TypeIds . Object :
486
483
return { } ;
487
484
case TypeIds . QRL :
0 commit comments