Repository navigation
Expand file tree
/
Copy pathcomponentError.js
More file actions
96 lines (81 loc) · 2.38 KB
/
Copy pathcomponentError.js
File metadata and controls
96 lines (81 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const FunctionComponent = 0
const ClassComponent = 1
const IndeterminateComponent = 2 // Before we know whether it is function or class
const HostComponent = 5
const ForwardRef = 11
const SuspenseComponent = 13
const SimpleMemoComponent = 15
const LazyComponent = 16
const SuspenseListComponent = 19
const HostHoistable = 26
const HostSingleton = 27
let stopWhile = false
function describeComponentFrame(name, ownerName) {
let sourceInfo = ''
if (ownerName) {
sourceInfo = ` (created by ${ownerName})`
}
if (name === 'MpxPage') {
stopWhile = true
}
return `\n in (${name || 'Unknown'}) ${sourceInfo}`
}
function describeFunctionComponentFrame(fn, ownerFn) {
if (!fn) {
return ''
}
const name = fn.displayName || fn.name || null
let ownerName = null
if (ownerFn) {
ownerName = ownerFn.displayName || ownerFn.name || null
}
return describeComponentFrame(name, ownerName)
}
function describeBuiltInComponentFrame(name, ownerFn) {
let ownerName = null
if (ownerFn) {
ownerName = ownerFn.displayName || ownerFn.name || null
}
return describeComponentFrame(name, ownerName)
}
function describeFiber(fiber) {
const owner = fiber._debugOwner ? fiber._debugOwner.type : null
switch (fiber.tag) {
case HostHoistable:
case HostSingleton:
case HostComponent:
return describeBuiltInComponentFrame(fiber.type, owner)
case LazyComponent:
return describeBuiltInComponentFrame('Lazy', owner)
case SuspenseComponent:
return describeBuiltInComponentFrame('Suspense', owner)
case SuspenseListComponent:
return describeBuiltInComponentFrame('SuspenseList', owner)
case FunctionComponent:
case IndeterminateComponent:
case SimpleMemoComponent:
return describeFunctionComponentFrame(fiber.type, owner)
case ForwardRef:
return describeFunctionComponentFrame(fiber.type.render, owner)
case ClassComponent:
return describeFunctionComponentFrame(fiber.type, owner)
default:
return ''
}
}
function getStackByFiberInDevAndProd(workInProgress) {
try {
let info = ''
let node = workInProgress
do {
info += describeFiber(node)
node = node.return
// eslint-disable-next-line no-unmodified-loop-condition
} while (node && !stopWhile)
stopWhile = false
return info
} catch (x) {
return `\nError generating stack: ${x.message} \n ${x.stack}`
}
}
export { getStackByFiberInDevAndProd }