File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed
packages/react-devtools-shared/src Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -607,3 +607,8 @@ exports[`Store should properly handle a root with no visible nodes: 1: mount 1`]
607607`;
608608
609609exports[`Store should properly handle a root with no visible nodes: 2: add host nodes 1`] = `[root]`;
610+
611+ exports[`Store should properly serialize non-string key values: 1: mount 1`] = `
612+ [root]
613+ <Child key="123">
614+ `;
Original file line number Diff line number Diff line change @@ -837,4 +837,15 @@ describe('Store', () => {
837837 act ( ( ) => ReactDOM . unmountComponentAtNode ( containerB ) ) ;
838838 expect ( store . supportsProfiling ) . toBe ( false ) ;
839839 } ) ;
840+
841+ it ( 'should properly serialize non-string key values' , ( ) => {
842+ const Child = ( ) => null ;
843+
844+ // Bypass React element's automatic stringifying of keys intentionally.
845+ // This is pretty hacky.
846+ const fauxElement = Object . assign ( { } , < Child /> , { key : 123 } ) ;
847+
848+ act ( ( ) => ReactDOM . render ( [ fauxElement ] , document . createElement ( 'div' ) ) ) ;
849+ expect ( store ) . toMatchSnapshot ( '1: mount' ) ;
850+ } ) ;
840851} ) ;
Original file line number Diff line number Diff line change @@ -1157,7 +1157,12 @@ export function attach(
11571157 : 0 ;
11581158
11591159 let displayNameStringID = getStringID ( displayName ) ;
1160- let keyStringID = getStringID ( key ) ;
1160+
1161+ // This check is a guard to handle a React element that has been modified
1162+ // in such a way as to bypass the default stringification of the "key" property.
1163+ let keyString = key === null ? null : '' + key ;
1164+ let keyStringID = getStringID ( keyString ) ;
1165+
11611166 pushOperation ( TREE_OPERATION_ADD ) ;
11621167 pushOperation ( id ) ;
11631168 pushOperation ( elementType ) ;
You can’t perform that action at this time.
0 commit comments