@@ -53,6 +53,11 @@ export function describeBuiltInComponentFrame(
5353}
5454
5555let reentry = false ;
56+ let componentFrameCache ;
57+ if ( __DEV__ ) {
58+ const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map ;
59+ componentFrameCache = new PossiblyWeakMap ( ) ;
60+ }
5661
5762export function describeNativeComponentFrame (
5863 fn : Function ,
@@ -63,6 +68,13 @@ export function describeNativeComponentFrame(
6368 return '' ;
6469 }
6570
71+ if ( __DEV__ ) {
72+ const frame = componentFrameCache . get ( fn ) ;
73+ if ( frame !== undefined ) {
74+ return frame ;
75+ }
76+ }
77+
6678 const control = Error ( ) ;
6779
6880 reentry = true ;
@@ -119,7 +131,11 @@ export function describeNativeComponentFrame(
119131 if ( sampleLines [ s ] !== controlLines [ c ] ) {
120132 // Return the line we found.
121133 // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
122- return '\n' + sampleLines [ s - 1 ] . replace ( ' at new ' , ' at ' ) ;
134+ const frame = '\n' + sampleLines [ s - 1 ] . replace ( ' at new ' , ' at ' ) ;
135+ if ( __DEV__ ) {
136+ componentFrameCache . set ( fn , frame ) ;
137+ }
138+ return frame ;
123139 }
124140 }
125141 }
@@ -132,7 +148,11 @@ export function describeNativeComponentFrame(
132148 }
133149 // Fallback to just using the name if we couldn't make it throw.
134150 const name = fn ? fn . displayName || fn . name : '' ;
135- return name ? describeBuiltInComponentFrame ( name ) : '' ;
151+ const syntheticFrame = name ? describeBuiltInComponentFrame ( name ) : '' ;
152+ if ( __DEV__ ) {
153+ componentFrameCache . set ( fn , syntheticFrame ) ;
154+ }
155+ return syntheticFrame ;
136156}
137157
138158const BEFORE_SLASH_RE = / ^ ( . * ) [ \\\/] / ;
0 commit comments