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`]
607
607
`;
608
608
609
609
exports[`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', () => {
837
837
act ( ( ) => ReactDOM . unmountComponentAtNode ( containerB ) ) ;
838
838
expect ( store . supportsProfiling ) . toBe ( false ) ;
839
839
} ) ;
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
+ } ) ;
840
851
} ) ;
Original file line number Diff line number Diff line change @@ -1157,7 +1157,12 @@ export function attach(
1157
1157
: 0 ;
1158
1158
1159
1159
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
+
1161
1166
pushOperation ( TREE_OPERATION_ADD ) ;
1162
1167
pushOperation ( id ) ;
1163
1168
pushOperation ( elementType ) ;
You can’t perform that action at this time.
0 commit comments