Skip to content

Commit 2f98cb4

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 2ce3e7a commit 2f98cb4

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

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

+3-1
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

+19-16
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) {
@@ -392,16 +403,14 @@ export function jsxProdSignatureRunningInDevWithDynamicChildren(
392403
isStaticChildren,
393404
source,
394405
self,
395-
// TODO: Reuse a placeholder stack to indicate the deopt.
396406
__DEV__ &&
397407
(recentlyCreatedOwnerStacks++ < ownerStackLimit
398408
? Error('react-stack-top-frame')
399-
: null),
400-
// TODO: If task.run is not the bottleneck, reuse a placeholder task to indicate the deop.
409+
: unknownOwnerDebugStack),
401410
__DEV__ &&
402411
(recentlyCreatedDebugTasks++ < debugTaskLimit
403412
? createTask(getTaskName(type))
404-
: null),
413+
: unknownOwnerDebugTask),
405414
);
406415
}
407416
}
@@ -422,16 +431,14 @@ export function jsxProdSignatureRunningInDevWithStaticChildren(
422431
isStaticChildren,
423432
source,
424433
self,
425-
// TODO: Reuse a placeholder stack to indicate the deopt.
426434
__DEV__ &&
427435
(recentlyCreatedOwnerStacks++ < ownerStackLimit
428436
? Error('react-stack-top-frame')
429-
: null),
430-
// TODO: If task.run is not the bottleneck, reuse a placeholder task to indicate the deop.
437+
: unknownOwnerDebugStack),
431438
__DEV__ &&
432439
(recentlyCreatedDebugTasks++ < debugTaskLimit
433440
? createTask(getTaskName(type))
434-
: null),
441+
: unknownOwnerDebugTask),
435442
);
436443
}
437444
}
@@ -452,16 +459,14 @@ export function jsxDEV(type, config, maybeKey, isStaticChildren, source, self) {
452459
isStaticChildren,
453460
source,
454461
self,
455-
// TODO: Reuse a placeholder stack to indicate the deopt.
456462
__DEV__ &&
457463
(recentlyCreatedOwnerStacks++ < ownerStackLimit
458464
? Error('react-stack-top-frame')
459-
: null),
460-
// TODO: If task.run is not the bottleneck, reuse a placeholder task to indicate the deop.
465+
: unknownOwnerDebugStack),
461466
__DEV__ &&
462467
(recentlyCreatedDebugTasks++ < debugTaskLimit
463468
? createTask(getTaskName(type))
464-
: null),
469+
: unknownOwnerDebugTask),
465470
);
466471
}
467472

@@ -736,16 +741,14 @@ export function createElement(type, config, children) {
736741
undefined,
737742
getOwner(),
738743
props,
739-
// TODO: Reuse a placeholder stack to indicate the deopt.
740744
__DEV__ &&
741745
(recentlyCreatedOwnerStacks++ < ownerStackLimit
742746
? Error('react-stack-top-frame')
743-
: null),
744-
// TODO: If task.run is not the bottleneck, reuse a placeholder task to indicate the deop.
747+
: unknownOwnerDebugStack),
745748
__DEV__ &&
746749
(recentlyCreatedDebugTasks++ < debugTaskLimit
747750
? createTask(getTaskName(type))
748-
: null),
751+
: unknownOwnerDebugTask),
749752
);
750753
}
751754

0 commit comments

Comments
 (0)