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,121 @@ 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
+ nearestMountedAncestor : Fiber | null ,
132
+ instance : ClassInstance < any > ,
133
+ ) : void {
134
+ try {
135
+ instance . componentWillUnmount( ) ;
136
+ } catch ( error ) {
137
+ captureCommitPhaseError ( current , nearestMountedAncestor , error ) ;
138
+ }
139
+ } ,
140
+ } ;
141
+
142
+ export const callComponentWillUnmountInDEV : (
143
+ current : Fiber ,
144
+ nearestMountedAncestor : Fiber | null ,
145
+ instance : ClassInstance < any > ,
146
+ ) => void = __DEV__
147
+ ? // We use this technique to trick minifiers to preserve the function name.
148
+ ( callComponentWillUnmount [ 'react-stack-bottom-frame' ] . bind (
149
+ callComponentWillUnmount ,
150
+ ) : any )
151
+ : ( null : any ) ;
152
+
153
+ const callCreate = {
154
+ 'react-stack-bottom-frame' : function ( effect : Effect ) : ( ( ) => void ) | void {
155
+ const create = effect . create ;
156
+ const inst = effect . inst ;
157
+ const destroy = create ( ) ;
158
+ inst . destroy = destroy ;
159
+ return destroy ;
160
+ } ,
161
+ } ;
162
+
163
+ export const callCreateInDEV : ( effect : Effect ) => ( ( ) => void ) | void = __DEV__
164
+ ? // We use this technique to trick minifiers to preserve the function name.
165
+ ( callCreate [ 'react-stack-bottom-frame' ] . bind ( callCreate ) : any )
166
+ : ( null : any ) ;
167
+
168
+ const callDestroy = {
169
+ 'react-stack-bottom-frame' : function (
170
+ current : Fiber ,
171
+ nearestMountedAncestor : Fiber | null ,
172
+ destroy : ( ) => void ,
173
+ ) : void {
174
+ try {
175
+ destroy ( ) ;
176
+ } catch ( error ) {
177
+ captureCommitPhaseError ( current , nearestMountedAncestor , error ) ;
178
+ }
179
+ } ,
180
+ } ;
181
+
182
+ export const callDestroyInDEV : (
183
+ current : Fiber ,
184
+ nearestMountedAncestor : Fiber | null ,
185
+ destroy : ( ) = > void ,
186
+ ) = > void = __DEV__
187
+ ? // We use this technique to trick minifiers to preserve the function name.
188
+ ( callDestroy [ 'react-stack-bottom-frame' ] . bind ( callDestroy ) : any )
189
+ : ( null : any ) ;
190
+
66
191
const callLazyInit = {
67
192
'react-stack-bottom-frame' : function ( lazy : LazyComponent < any , any > ) : any {
68
193
const payload = lazy . _payload ;
0 commit comments