Replaced === check with Object.is() to support values like NaN (#16934)
Brian Vaughn committed
Sep 27, 2019 at 16:54 UTC
d4278663c681ab4b3c3ebb36a19532b43a7c2813
2 files changed
+19
-2
packages/react-devtools-shared/src/__tests__/useEditableValue-test.js
+18
@@ -23,6 +23,24 @@ describe('useEditableValue', () => {
23
useEditableValue = require('../devtools/views/hooks').useEditableValue;
24
});
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
+
44
it('should override editable state when external props are updated', () => {
45
let state;
46
packages/react-devtools-shared/src/devtools/views/hooks.js
+1
-2
@@ -87,8 +87,7 @@ export function useEditableValue(
87
isValid: true,
88
parsedValue: externalValue,
89
});
90
-
91
- if (state.externalValue !== externalValue) {
90
+ if (!Object.is(state.externalValue, externalValue)) {
91
if (!state.hasPendingChanges) {
92
dispatch({
93
type: 'RESET',