Skip to content

Commit d427866

Browse files
author
Brian Vaughn
authored
Replaced === check with Object.is() to support values like NaN (#16934)
1 parent d1121c0 commit d427866

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/react-devtools-shared/src/__tests__/useEditableValue-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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

packages/react-devtools-shared/src/devtools/views/hooks.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff 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',

0 commit comments

Comments
 (0)