From 5189e9f91d45a51362791705260ae7557ea3e9e5 Mon Sep 17 00:00:00 2001 From: James Zhan Date: Wed, 15 Oct 2025 09:40:16 +1100 Subject: [PATCH] add readTypeof --- packages/shared/ReactPerformanceTrackProperties.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/shared/ReactPerformanceTrackProperties.js b/packages/shared/ReactPerformanceTrackProperties.js index 87231c20c49..474d83de352 100644 --- a/packages/shared/ReactPerformanceTrackProperties.js +++ b/packages/shared/ReactPerformanceTrackProperties.js @@ -80,6 +80,14 @@ export function addObjectToProperties( } } +function readTypeof(value: any): any { + try { + return value.$$typeof; + } catch (error) { + return undefined; + } +} + export function addValueToProperties( propertyName: string, value: mixed, @@ -94,7 +102,7 @@ export function addValueToProperties( desc = 'null'; break; } else { - if (value.$$typeof === REACT_ELEMENT_TYPE) { + if (readTypeof(value) === REACT_ELEMENT_TYPE) { // JSX const typeName = getComponentNameFromType(value.type) || '\u2026'; const key = value.key; @@ -345,9 +353,9 @@ export function addObjectDiffToProperties( typeof nextValue === 'object' && prevValue !== null && nextValue !== null && - prevValue.$$typeof === nextValue.$$typeof + readTypeof(prevValue) === readTypeof(nextValue) ) { - if (nextValue.$$typeof === REACT_ELEMENT_TYPE) { + if (readTypeof(nextValue) === REACT_ELEMENT_TYPE) { if ( prevValue.type === nextValue.type && prevValue.key === nextValue.key