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', () => {
23
23
useEditableValue = require ( '../devtools/views/hooks' ) . useEditableValue ;
24
24
} ) ;
25
25
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
+
26
44
it ( 'should override editable state when external props are updated' , ( ) => {
27
45
let state ;
28
46
Original file line number Diff line number Diff line change @@ -87,8 +87,7 @@ export function useEditableValue(
87
87
isValid : true ,
88
88
parsedValue : externalValue ,
89
89
} ) ;
90
-
91
- if ( state . externalValue !== externalValue ) {
90
+ if ( ! Object . is ( state . externalValue , externalValue ) ) {
92
91
if ( ! state . hasPendingChanges ) {
93
92
dispatch ( {
94
93
type : 'RESET' ,
You can’t perform that action at this time.
0 commit comments