File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
packages/react-devtools-shared/src Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,24 @@ describe('useEditableValue', () => {
2323 useEditableValue = require ( '../devtools/views/hooks' ) . useEditableValue ;
2424 } ) ;
2525
26+ it ( 'should not cause a loop with values like NaN' , ( ) => {
27+ let state ;
28+
29+ function Example ( { value = NaN } ) {
30+ const tuple = useEditableValue ( value ) ;
31+ state = tuple [ 0 ] ;
32+ return null ;
33+ }
34+
35+ const container = document . createElement ( 'div' ) ;
36+ ReactDOM . render ( < Example /> , container ) ;
37+ expect ( state . editableValue ) . toEqual ( 'NaN' ) ;
38+ expect ( state . externalValue ) . toEqual ( NaN ) ;
39+ expect ( state . parsedValue ) . toEqual ( NaN ) ;
40+ expect ( state . hasPendingChanges ) . toBe ( false ) ;
41+ expect ( state . isValid ) . toBe ( true ) ;
42+ } ) ;
43+
2644 it ( 'should override editable state when external props are updated' , ( ) => {
2745 let state ;
2846
Original file line number Diff line number Diff line change @@ -87,8 +87,7 @@ export function useEditableValue(
8787 isValid : true ,
8888 parsedValue : externalValue ,
8989 } ) ;
90-
91- if ( state . externalValue !== externalValue ) {
90+ if ( ! Object . is ( state . externalValue , externalValue ) ) {
9291 if ( ! state . hasPendingChanges ) {
9392 dispatch ( {
9493 type : 'RESET' ,
You can’t perform that action at this time.
0 commit comments