Skip to content

Commit f134542

Browse files
committed
Add special placeholder for unknown owners
Not sure about this one. It'll point into React code i.e. node_modules and should be ignore-listed by modern frameworks.
1 parent edcfcb8 commit f134542

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ describe('ReactOwnerStacks', () => {
9494
let i = 0;
9595
i <
9696
siblingsBeforeStackOne -
97+
// One built-in JSX callsite for the unknown Owner Stack
98+
1 -
9799
// Number of JSX callsites before this render
98100
1 -
99101
// Stop so that OwnerStackOne will be right before cutoff
@@ -139,7 +141,7 @@ describe('ReactOwnerStacks', () => {
139141
stackOne: '\n in App (at **)',
140142
stackTwo: __VARIANT__
141143
? // captured right after cutoff
142-
''
144+
'\n in UnknownOwner (at **)'
143145
: '\n in App (at **)',
144146
});
145147

packages/react/src/jsx/ReactJSXElement.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,20 @@ function getOwner() {
7272
let specialPropKeyWarningShown;
7373
let didWarnAboutElementRef;
7474
let didWarnAboutOldJSXRuntime;
75+
let unknownOwnerDebugStack;
76+
let unknownOwnerDebugTask;
7577

7678
if (__DEV__) {
7779
didWarnAboutElementRef = {};
80+
const unknownOwnerElement = {
81+
'react-stack-bottom-frame': () => {
82+
return (function UnknownOwner() {
83+
return jsxDEV(() => null, {}, null);
84+
})();
85+
},
86+
}['react-stack-bottom-frame']();
87+
unknownOwnerDebugStack = unknownOwnerElement._debugStack;
88+
unknownOwnerDebugTask = unknownOwnerElement._debugTask;
7889
}
7990

8091
function hasValidRef(config) {
@@ -396,12 +407,12 @@ export function jsxProdSignatureRunningInDevWithDynamicChildren(
396407
__DEV__ &&
397408
(recentlyCreatedOwnerStacks++ < ownerStackLimit
398409
? Error('react-stack-top-frame')
399-
: null),
410+
: unknownOwnerDebugStack),
400411
// TODO: If task.run is not the bottleneck, reuse a placeholder task to indicate the deop.
401412
__DEV__ &&
402413
(recentlyCreatedDebugTasks++ < debugTaskLimit
403414
? createTask(getTaskName(type))
404-
: null),
415+
: unknownOwnerDebugTask),
405416
);
406417
}
407418
}
@@ -426,12 +437,12 @@ export function jsxProdSignatureRunningInDevWithStaticChildren(
426437
__DEV__ &&
427438
(recentlyCreatedOwnerStacks++ < ownerStackLimit
428439
? Error('react-stack-top-frame')
429-
: null),
440+
: unknownOwnerDebugStack),
430441
// TODO: If task.run is not the bottleneck, reuse a placeholder task to indicate the deop.
431442
__DEV__ &&
432443
(recentlyCreatedDebugTasks++ < debugTaskLimit
433444
? createTask(getTaskName(type))
434-
: null),
445+
: unknownOwnerDebugTask),
435446
);
436447
}
437448
}
@@ -456,12 +467,12 @@ export function jsxDEV(type, config, maybeKey, isStaticChildren, source, self) {
456467
__DEV__ &&
457468
(recentlyCreatedOwnerStacks++ < ownerStackLimit
458469
? Error('react-stack-top-frame')
459-
: null),
470+
: unknownOwnerDebugStack),
460471
// TODO: If task.run is not the bottleneck, reuse a placeholder task to indicate the deop.
461472
__DEV__ &&
462473
(recentlyCreatedDebugTasks++ < debugTaskLimit
463474
? createTask(getTaskName(type))
464-
: null),
475+
: unknownOwnerDebugTask),
465476
);
466477
}
467478

@@ -740,12 +751,12 @@ export function createElement(type, config, children) {
740751
__DEV__ &&
741752
(recentlyCreatedOwnerStacks++ < ownerStackLimit
742753
? Error('react-stack-top-frame')
743-
: null),
754+
: unknownOwnerDebugStack),
744755
// TODO: If task.run is not the bottleneck, reuse a placeholder task to indicate the deop.
745756
__DEV__ &&
746757
(recentlyCreatedDebugTasks++ < debugTaskLimit
747758
? createTask(getTaskName(type))
748-
: null),
759+
: unknownOwnerDebugTask),
749760
);
750761
}
751762

0 commit comments

Comments
 (0)