File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
packages/react-server/src Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -152,11 +152,27 @@ function defaultFilterStackFrame(
152
152
) ;
153
153
}
154
154
155
+ // DEV-only cache of parsed and filtered stack frames.
156
+ const stackTraceCache: WeakMap< Error , ReactStackTrace > = __DEV__
157
+ ? new WeakMap()
158
+ : (null: any);
159
+
155
160
function filterStackTrace(
156
161
request: Request,
157
162
error: Error,
158
163
skipFrames: number,
159
164
): ReactStackTrace {
165
+ const existing = stackTraceCache . get ( error ) ;
166
+ if ( existing !== undefined ) {
167
+ // Return a clone because the Flight protocol isn't yet resilient to deduping
168
+ // objects in the debug info. TODO: Support deduping stacks.
169
+ const clone = existing . slice ( 0 ) ;
170
+ for ( let i = 0 ; i < clone . length ; i ++ ) {
171
+ // $FlowFixMe[invalid-tuple-arity]
172
+ clone [ i ] = clone [ i ] . slice ( 0 ) ;
173
+ }
174
+ return clone ;
175
+ }
160
176
// Since stacks can be quite large and we pass a lot of them, we filter them out eagerly
161
177
// to save bandwidth even in DEV. We'll also replay these stacks on the client so by
162
178
// stripping them early we avoid that overhead. Otherwise we'd normally just rely on
@@ -183,6 +199,7 @@ function filterStackTrace(
183
199
i -- ;
184
200
}
185
201
}
202
+ stackTraceCache . set ( error , stack ) ;
186
203
return stack ;
187
204
}
188
205
You can’t perform that action at this time.
0 commit comments