@@ -47,29 +47,38 @@ function sanitizeEvent(event: Object): Object {
4747 const value = event [ key ] ;
4848 if ( typeof value === 'function' || UNUSED_EXPENSIVE_FIELDS . includes ( key ) ) {
4949 continue ;
50- } else if ( value == null || typeof value !== 'object' ) {
51- newEvent [ key ] = value ;
52- } else if ( value instanceof Map ) {
53- newEvent [ key ] = Object . fromEntries ( ( value : Map < mixed , mixed > ) ) ;
54- } else if ( value instanceof Set ) {
55- newEvent [ key ] = Array . from ( value ) ;
56- } else if ( typeof value . toJSON == 'function' ) {
57- // Convert RecordSource to Object, there are arbitary values for resolvers
58- newEvent [ key ] = JSON . parse ( JSON . stringify ( value . toJSON ( ) ) ) ;
59- } else if (
60- ( key === 'info' && event . name === 'network.info' ) ||
61- event . name === 'network.start' ||
62- key === 'cacheConfig'
63- ) {
64- // Some network events contain arbitary data
65- newEvent [ key ] = JSON . parse ( JSON . stringify ( value ) ) ;
66- } else {
67- newEvent [ key ] = value ;
6850 }
51+ newEvent [ key ] = makeCloneable ( value ) ;
6952 }
7053 return newEvent ;
7154}
7255
56+ function makeCloneable ( obj : mixed ) : Object {
57+ if ( obj === null || typeof obj !== 'object' ) return obj ;
58+
59+ if ( Array . isArray ( obj ) ) {
60+ return obj . map ( makeCloneable ) ;
61+ }
62+
63+ if ( typeof obj . toJSON == 'function' ) {
64+ // Convert RecordSource to Object, there are arbitary values for resolvers
65+ // $FlowFixMe[incompatible-use]
66+ return makeCloneable ( obj . toJSON ( ) ) ;
67+ }
68+ const result : Object = { } ;
69+ for ( const [ key , value ] of Object . entries ( obj ) ) {
70+ if (
71+ typeof value === 'function' ||
72+ typeof value === 'symbol' ||
73+ value instanceof Node
74+ ) {
75+ continue ;
76+ }
77+ result [ key ] = makeCloneable ( value ) ;
78+ }
79+ return result ;
80+ }
81+
7382export function attach (
7483 hook : DevToolsHook ,
7584 rendererID : number ,
@@ -80,7 +89,7 @@ export function attach(
8089 const store = environment . getStore ( ) ;
8190
8291 const originalLog = environment . __log ;
83- environment . __log = event => {
92+ environment . __log = ( event ) => {
8493 originalLog ( event ) ;
8594 if ( ! SUPPORTED_EVENTS . has ( event . name ) ) {
8695 return ;
@@ -100,7 +109,7 @@ export function attach(
100109
101110 const storeOriginalLog = store . __log ;
102111 // TODO(damassart): Make this cleaner
103- store . __log = event => {
112+ store . __log = ( event ) => {
104113 if ( storeOriginalLog !== null ) {
105114 storeOriginalLog ( event ) ;
106115 }
@@ -133,7 +142,7 @@ export function attach(
133142 function flushInitialOperations ( ) {
134143 // TODO(damassart): Make this a modular function
135144 if ( pendingEventsQueue != null ) {
136- pendingEventsQueue . forEach ( pendingEvent => {
145+ pendingEventsQueue . forEach ( ( pendingEvent ) => {
137146 hook . emit ( 'environment.event' , {
138147 id : rendererID ,
139148 envName : environment . configName ,
0 commit comments