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