Skip to content

Commit 9f43236

Browse files
committed
Handle opaque origin in props
1 parent a750c7b commit 9f43236

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

packages/react-reconciler/src/__tests__/ReactPerformanceTrack-test.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -532,12 +532,8 @@ describe('ReactPerformanceTracks', () => {
532532
};
533533

534534
class Window {}
535-
536-
class OpaqueOriginHTMLIFrameElement {
537-
constructor(textContent) {
538-
this.textContent = textContent;
539-
}
540-
contentWindow = new Proxy(new Window(), {
535+
const createOpaqueOriginWindow = () => {
536+
return new Proxy(new Window(), {
541537
get(target, prop) {
542538
if (prop === Symbol.toStringTag) {
543539
return target[Symbol.toStringTag];
@@ -550,14 +546,24 @@ describe('ReactPerformanceTracks', () => {
550546
);
551547
},
552548
});
549+
};
550+
551+
class OpaqueOriginHTMLIFrameElement {
552+
constructor(textContent) {
553+
this.textContent = textContent;
554+
}
555+
contentWindow = createOpaqueOriginWindow();
553556
nodeType = 1;
554557
[Symbol.toStringTag] = 'HTMLIFrameElement';
555558
}
556559

557560
Scheduler.unstable_advanceTime(1);
558561
await act(() => {
559562
ReactNoop.render(
560-
<App container={new OpaqueOriginHTMLIFrameElement('foo')} />,
563+
<App
564+
container={new OpaqueOriginHTMLIFrameElement('foo')}
565+
contentWindow={createOpaqueOriginWindow()}
566+
/>,
561567
);
562568
});
563569

@@ -584,7 +590,10 @@ describe('ReactPerformanceTracks', () => {
584590

585591
await act(() => {
586592
ReactNoop.render(
587-
<App container={new OpaqueOriginHTMLIFrameElement('bar')} />,
593+
<App
594+
container={new OpaqueOriginHTMLIFrameElement('bar')}
595+
contentWindow={createOpaqueOriginWindow()}
596+
/>,
588597
);
589598
});
590599

@@ -605,6 +614,10 @@ describe('ReactPerformanceTracks', () => {
605614
['+   contentWindow', 'Window'],
606615
['+   nodeType', '1'],
607616
['+   textContent', '"bar"'],
617+
[
618+
'  contentWindow',
619+
'Referentially unequal but deeply equal objects. Consider memoization.',
620+
],
608621
],
609622
tooltipText: 'App',
610623
track: 'Components ⚛',

packages/shared/ReactPerformanceTrackProperties.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ export function addObjectToProperties(
8282
}
8383
}
8484

85+
function readTypeof(value: Object): mixed {
86+
return '$$typeof' in value && hasOwnProperty.call(value, '$$typeof')
87+
? value.$$typeof
88+
: undefined;
89+
}
90+
8591
export function addValueToProperties(
8692
propertyName: string,
8793
value: mixed,
@@ -182,11 +188,7 @@ export function addValueToProperties(
182188
return;
183189
}
184190
if (objectName === 'Object') {
185-
if (
186-
'$$typeof' in value &&
187-
hasOwnProperty.call(value, '$$typeof') &&
188-
value.$$typeof === REACT_ELEMENT_TYPE
189-
) {
191+
if (readTypeof(value) === REACT_ELEMENT_TYPE) {
190192
// JSX
191193
const typeName = getComponentNameFromType(value.type) || '\u2026';
192194
const key = value.key;
@@ -360,9 +362,9 @@ export function addObjectDiffToProperties(
360362
typeof nextValue === 'object' &&
361363
prevValue !== null &&
362364
nextValue !== null &&
363-
prevValue.$$typeof === nextValue.$$typeof
365+
readTypeof(prevValue) === readTypeof(nextValue)
364366
) {
365-
if (nextValue.$$typeof === REACT_ELEMENT_TYPE) {
367+
if (readTypeof(nextValue) === REACT_ELEMENT_TYPE) {
366368
if (
367369
prevValue.type === nextValue.type &&
368370
prevValue.key === nextValue.key

0 commit comments

Comments
 (0)