@@ -53,6 +53,11 @@ export function describeBuiltInComponentFrame(
53
53
}
54
54
55
55
let reentry = false ;
56
+ let componentFrameCache ;
57
+ if ( __DEV__ ) {
58
+ const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map ;
59
+ componentFrameCache = new PossiblyWeakMap ( ) ;
60
+ }
56
61
57
62
export function describeNativeComponentFrame (
58
63
fn : Function ,
@@ -63,6 +68,13 @@ export function describeNativeComponentFrame(
63
68
return '' ;
64
69
}
65
70
71
+ if ( __DEV__ ) {
72
+ const frame = componentFrameCache . get ( fn ) ;
73
+ if ( frame !== undefined ) {
74
+ return frame ;
75
+ }
76
+ }
77
+
66
78
const control = Error ( ) ;
67
79
68
80
reentry = true ;
@@ -119,7 +131,13 @@ export function describeNativeComponentFrame(
119
131
if ( sampleLines [ s ] !== controlLines [ c ] ) {
120
132
// Return the line we found.
121
133
// 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
+ if ( typeof fn === 'function' ) {
137
+ componentFrameCache . set ( fn , frame ) ;
138
+ }
139
+ }
140
+ return frame ;
123
141
}
124
142
}
125
143
}
@@ -132,7 +150,13 @@ export function describeNativeComponentFrame(
132
150
}
133
151
// Fallback to just using the name if we couldn't make it throw.
134
152
const name = fn ? fn . displayName || fn . name : '' ;
135
- return name ? describeBuiltInComponentFrame ( name ) : '' ;
153
+ const syntheticFrame = name ? describeBuiltInComponentFrame ( name ) : '' ;
154
+ if ( __DEV__ ) {
155
+ if ( typeof fn === 'function' ) {
156
+ componentFrameCache . set ( fn , syntheticFrame ) ;
157
+ }
158
+ }
159
+ return syntheticFrame ;
136
160
}
137
161
138
162
const BEFORE_SLASH_RE = / ^ ( . * ) [ \\\/] / ;
0 commit comments