@@ -52,7 +52,7 @@ export type Unserializable = {
5252 size ?: number ,
5353 type : string ,
5454 unserializable : boolean ,
55- ...
55+ [ string | number ] : any ,
5656} ;
5757
5858// This threshold determines the depth at which the bridge "dehydrates" nested data.
@@ -248,7 +248,6 @@ export function dehydrate(
248248 // Other types (e.g. typed arrays, Sets) will not spread correctly.
249249 Array . from ( data ) . forEach (
250250 ( item , i ) =>
251- // $FlowFixMe[prop-missing] Unserializable doesn't have an index signature
252251 ( unserializableValue [ i ] = dehydrate (
253252 item ,
254253 cleaned ,
@@ -296,6 +295,7 @@ export function dehydrate(
296295
297296 case 'object ':
298297 isPathAllowedCheck = isPathAllowed ( path ) ;
298+
299299 if ( level >= LEVEL_THRESHOLD && ! isPathAllowedCheck ) {
300300 return createDehydrated ( type , true , data , cleaned , path ) ;
301301 } else {
@@ -316,15 +316,42 @@ export function dehydrate(
316316 return object ;
317317 }
318318
319+ case 'class_instance' :
320+ isPathAllowedCheck = isPathAllowed ( path ) ;
321+
322+ const value : Unserializable = {
323+ unserializable : true ,
324+ type ,
325+ readonly : true ,
326+ preview_short : formatDataForPreview ( data , false ) ,
327+ preview_long : formatDataForPreview ( data , true ) ,
328+ name : data . constructor . name ,
329+ } ;
330+
331+ getAllEnumerableKeys ( data ) . forEach ( key => {
332+ const keyAsString = key . toString ( ) ;
333+
334+ value [ keyAsString ] = dehydrate (
335+ data [ key ] ,
336+ cleaned ,
337+ unserializable ,
338+ path . concat ( [ keyAsString ] ) ,
339+ isPathAllowed ,
340+ isPathAllowedCheck ? 1 : level + 1 ,
341+ ) ;
342+ } ) ;
343+
344+ unserializable . push ( path ) ;
345+
346+ return value ;
347+
319348 case 'infinity ':
320349 case 'nan ':
321350 case 'undefined ':
322351 // Some values are lossy when sent through a WebSocket.
323352 // We dehydrate+rehydrate them to preserve their type.
324353 cleaned . push ( path ) ;
325- return {
326- type ,
327- } ;
354+ return { type} ;
328355
329356 default :
330357 return data ;
0 commit comments