Skip to content

Commit

Permalink
Replaced === check with Object.is() to support values like NaN (#16934)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn authored Sep 27, 2019
1 parent d1121c0 commit d427866
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ describe('useEditableValue', () => {
useEditableValue = require('../devtools/views/hooks').useEditableValue;
});

it('should not cause a loop with values like NaN', () => {
let state;

function Example({value = NaN}) {
const tuple = useEditableValue(value);
state = tuple[0];
return null;
}

const container = document.createElement('div');
ReactDOM.render(<Example />, container);
expect(state.editableValue).toEqual('NaN');
expect(state.externalValue).toEqual(NaN);
expect(state.parsedValue).toEqual(NaN);
expect(state.hasPendingChanges).toBe(false);
expect(state.isValid).toBe(true);
});

it('should override editable state when external props are updated', () => {
let state;

Expand Down
3 changes: 1 addition & 2 deletions packages/react-devtools-shared/src/devtools/views/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ export function useEditableValue(
isValid: true,
parsedValue: externalValue,
});

if (state.externalValue !== externalValue) {
if (!Object.is(state.externalValue, externalValue)) {
if (!state.hasPendingChanges) {
dispatch({
type: 'RESET',
Expand Down

0 comments on commit d427866

Please sign in to comment.