From 7b6fc5cbc7d4036399b29a0e601d64769d6e0dab Mon Sep 17 00:00:00 2001 From: Vitali Zaidman Date: Sun, 15 Sep 2024 17:58:33 +0100 Subject: [PATCH] update isReactElement to comply with React 19 --- src/calculateDeepEqualDiffs.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/calculateDeepEqualDiffs.js b/src/calculateDeepEqualDiffs.js index da2b0d9..06988dd 100644 --- a/src/calculateDeepEqualDiffs.js +++ b/src/calculateDeepEqualDiffs.js @@ -14,10 +14,16 @@ import { diffTypes } from './consts'; const hasElementType = typeof Element !== 'undefined'; -// copied from https://github.com/facebook/react/packages/shared/ReactSymbols.js +// copied from https://github.com/facebook/react/blob/fc5ef50da8e975a569622d477f1fed54cb8b193d/packages/react-devtools-shared/src/backend/shared/ReactSymbols.js#L26 const hasSymbol = typeof Symbol === 'function' && Symbol.for; -const REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7; -const isReactElement = object => object.$$typeof === REACT_ELEMENT_TYPE; + +const LEGACY_ELEMENT_NUMBER = 0xeac7; +const LEGACY_ELEMENT_SYMBOL_STRING = hasSymbol && Symbol.for('react.element'); +const ELEMENT_SYMBOL_STRING = hasSymbol && Symbol.for('react.transitional.element'); +const isReactElement = object => [ + ...(hasSymbol ? [ELEMENT_SYMBOL_STRING, LEGACY_ELEMENT_SYMBOL_STRING] : []), + LEGACY_ELEMENT_NUMBER, +].includes(object.$$typeof); // end function trackDiff(a, b, diffsAccumulator, pathString, diffType) {