77 * @flow
88 */
99
10+ import type { Fiber } from './ReactInternalTypes' ;
1011import type { LazyComponent } from 'react/src/ReactLazy' ;
12+ import type { Effect } from './ReactFiberHooks' ;
1113
1214import { isRendering , setIsRendering } from './ReactCurrentFiber' ;
15+ import { captureCommitPhaseError } from './ReactFiberWorkLoop' ;
1316
1417// These indirections exists so we can exclude its stack frame in DEV (and anything below it).
1518// TODO: Consider marking the whole bundle instead of these boundaries.
@@ -42,6 +45,13 @@ export const callComponentInDEV: <Props, Arg, R>(
4245
4346interface ClassInstance < R > {
4447 render ( ) : R ;
48+ componentDidMount ( ) : void ;
49+ componentDidUpdate (
50+ prevProps : Object ,
51+ prevState : Object ,
52+ snaphot : Object ,
53+ ) : void ;
54+ componentWillUnmount ( ) : void ;
4555}
4656
4757const callRender = {
@@ -63,6 +73,121 @@ export const callRenderInDEV: <R>(instance: ClassInstance<R>) => R => R =
6373 ( callRender [ 'react-stack-bottom-frame' ] . bind ( callRender ) : any )
6474 : ( null : any ) ;
6575
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+
66191const callLazyInit = {
67192 'react-stack-bottom-frame' : function ( lazy : LazyComponent < any , any > ) : any {
68193 const payload = lazy . _payload ;
0 commit comments