7
7
* @flow
8
8
*/
9
9
10
+ import type { Fiber } from './ReactInternalTypes' ;
10
11
import type { LazyComponent } from 'react/src/ReactLazy' ;
12
+ import type { Effect } from './ReactFiberHooks' ;
13
+ import type { CapturedValue } from './ReactCapturedValue' ;
11
14
12
15
import { isRendering , setIsRendering } from './ReactCurrentFiber' ;
16
+ import { captureCommitPhaseError } from './ReactFiberWorkLoop' ;
13
17
14
18
// These indirections exists so we can exclude its stack frame in DEV (and anything below it).
15
19
// TODO: Consider marking the whole bundle instead of these boundaries.
@@ -42,6 +46,14 @@ export const callComponentInDEV: <Props, Arg, R>(
42
46
43
47
interface ClassInstance < R > {
44
48
render ( ) : R ;
49
+ componentDidMount ( ) : void ;
50
+ componentDidUpdate (
51
+ prevProps : Object ,
52
+ prevState : Object ,
53
+ snaphot : Object ,
54
+ ) : void ;
55
+ componentDidCatch ( error : mixed , errorInfo : { componentStack : string } ) : void ;
56
+ componentWillUnmount ( ) : void ;
45
57
}
46
58
47
59
const callRender = {
@@ -63,6 +75,144 @@ export const callRenderInDEV: <R>(instance: ClassInstance<R>) => R => R =
63
75
( callRender [ 'react-stack-bottom-frame' ] . bind ( callRender ) : any )
64
76
: ( null : any ) ;
65
77
78
+ const callComponentDidMount = {
79
+ 'react-stack-bottom-frame' : function (
80
+ finishedWork : Fiber ,
81
+ instance : ClassInstance < any > ,
82
+ ) : void {
83
+ try {
84
+ instance . componentDidMount( ) ;
85
+ } catch ( error ) {
86
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
87
+ }
88
+ } ,
89
+ } ;
90
+
91
+ export const callComponentDidMountInDEV : (
92
+ finishedWork : Fiber ,
93
+ instance : ClassInstance < any > ,
94
+ ) => void = __DEV__
95
+ ? // We use this technique to trick minifiers to preserve the function name.
96
+ ( callComponentDidMount [ 'react-stack-bottom-frame' ] . bind (
97
+ callComponentDidMount ,
98
+ ) : any )
99
+ : ( null : any ) ;
100
+
101
+ const callComponentDidUpdate = {
102
+ 'react-stack-bottom-frame' : function (
103
+ finishedWork : Fiber ,
104
+ instance : ClassInstance < any > ,
105
+ prevProps : Object ,
106
+ prevState : Object ,
107
+ snapshot : Object ,
108
+ ) : void {
109
+ try {
110
+ instance . componentDidUpdate ( prevProps , prevState , snapshot ) ;
111
+ } catch ( error ) {
112
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
113
+ }
114
+ } ,
115
+ } ;
116
+
117
+ export const callComponentDidUpdateInDEV : (
118
+ finishedWork : Fiber ,
119
+ instance : ClassInstance < any > ,
120
+ prevProps : Object ,
121
+ prevState : Object ,
122
+ snaphot : Object ,
123
+ ) => void = __DEV__
124
+ ? // We use this technique to trick minifiers to preserve the function name.
125
+ ( callComponentDidUpdate [ 'react-stack-bottom-frame' ] . bind (
126
+ callComponentDidUpdate ,
127
+ ) : any )
128
+ : ( null : any ) ;
129
+
130
+ const callComponentDidCatch = {
131
+ 'react-stack-bottom-frame' : function (
132
+ instance : ClassInstance < any > ,
133
+ errorInfo : CapturedValue < mixed > ,
134
+ ) : void {
135
+ const error = errorInfo . value ;
136
+ const stack = errorInfo . stack ;
137
+ instance . componentDidCatch ( error , {
138
+ componentStack : stack !== null ? stack : '' ,
139
+ } ) ;
140
+ } ,
141
+ } ;
142
+
143
+ export const callComponentDidCatchInDEV : (
144
+ instance : ClassInstance < any > ,
145
+ errorInfo : CapturedValue < mixed > ,
146
+ ) => void = __DEV__
147
+ ? // We use this technique to trick minifiers to preserve the function name.
148
+ ( callComponentDidCatch [ 'react-stack-bottom-frame' ] . bind (
149
+ callComponentDidCatch ,
150
+ ) : any )
151
+ : ( null : any ) ;
152
+
153
+ const callComponentWillUnmount = {
154
+ 'react-stack-bottom-frame' : function (
155
+ current : Fiber ,
156
+ nearestMountedAncestor : Fiber | null ,
157
+ instance : ClassInstance < any > ,
158
+ ) : void {
159
+ try {
160
+ instance . componentWillUnmount( ) ;
161
+ } catch ( error ) {
162
+ captureCommitPhaseError ( current , nearestMountedAncestor , error ) ;
163
+ }
164
+ } ,
165
+ } ;
166
+
167
+ export const callComponentWillUnmountInDEV : (
168
+ current : Fiber ,
169
+ nearestMountedAncestor : Fiber | null ,
170
+ instance : ClassInstance < any > ,
171
+ ) => void = __DEV__
172
+ ? // We use this technique to trick minifiers to preserve the function name.
173
+ ( callComponentWillUnmount [ 'react-stack-bottom-frame' ] . bind (
174
+ callComponentWillUnmount ,
175
+ ) : any )
176
+ : ( null : any ) ;
177
+
178
+ const callCreate = {
179
+ 'react-stack-bottom-frame' : function ( effect : Effect ) : ( ( ) => void ) | void {
180
+ const create = effect . create ;
181
+ const inst = effect . inst ;
182
+ const destroy = create ( ) ;
183
+ inst . destroy = destroy ;
184
+ return destroy ;
185
+ } ,
186
+ } ;
187
+
188
+ export const callCreateInDEV : ( effect : Effect ) => ( ( ) => void ) | void = __DEV__
189
+ ? // We use this technique to trick minifiers to preserve the function name.
190
+ ( callCreate [ 'react-stack-bottom-frame' ] . bind ( callCreate ) : any )
191
+ : ( null : any ) ;
192
+
193
+ const callDestroy = {
194
+ 'react-stack-bottom-frame' : function (
195
+ current : Fiber ,
196
+ nearestMountedAncestor : Fiber | null ,
197
+ destroy : ( ) => void ,
198
+ ) : void {
199
+ try {
200
+ destroy ( ) ;
201
+ } catch ( error ) {
202
+ captureCommitPhaseError ( current , nearestMountedAncestor , error ) ;
203
+ }
204
+ } ,
205
+ } ;
206
+
207
+ export const callDestroyInDEV : (
208
+ current : Fiber ,
209
+ nearestMountedAncestor : Fiber | null ,
210
+ destroy : ( ) = > void ,
211
+ ) = > void = __DEV__
212
+ ? // We use this technique to trick minifiers to preserve the function name.
213
+ ( callDestroy [ 'react-stack-bottom-frame' ] . bind ( callDestroy ) : any )
214
+ : ( null : any ) ;
215
+
66
216
const callLazyInit = {
67
217
'react-stack-bottom-frame' : function ( lazy : LazyComponent < any , any > ) : any {
68
218
const payload = lazy . _payload ;
0 commit comments