From 7d1392b704ff59f9e41c98307bf6ea26c029e3f0 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 27 Sep 2019 16:30:12 -0700 Subject: [PATCH] Replaced === check with Object.is() to support values like NaN --- .../src/__tests__/useEditableValue-test.js | 18 ++++++++++++++++++ .../src/devtools/views/hooks.js | 3 +-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/react-devtools-shared/src/__tests__/useEditableValue-test.js b/packages/react-devtools-shared/src/__tests__/useEditableValue-test.js index cdca311cb84fe..db22d2813e401 100644 --- a/packages/react-devtools-shared/src/__tests__/useEditableValue-test.js +++ b/packages/react-devtools-shared/src/__tests__/useEditableValue-test.js @@ -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(, 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; diff --git a/packages/react-devtools-shared/src/devtools/views/hooks.js b/packages/react-devtools-shared/src/devtools/views/hooks.js index 430d2472eeb4a..693f72535bbe5 100644 --- a/packages/react-devtools-shared/src/devtools/views/hooks.js +++ b/packages/react-devtools-shared/src/devtools/views/hooks.js @@ -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',