File tree Expand file tree Collapse file tree
packages/react-client/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4031,11 +4031,24 @@ const createFakeJSXCallStackInDEV: (
40314031 ) as any )
40324032 : ( null as any ) ;
40334033
4034+ // v8 (Chromium, Node.js) defaults to 10
4035+ // SpiderMonkey (Firefox) does not support Error.stackTraceLimit
4036+ // JSC (Safari) defaults to 100
4037+ // The lower the limit, the more likely we'll not reach react_stack_bottom_frame
4038+ // The higher the limit, the slower Error() is when not inspecting with a debugger.
4039+ // When inspecting with a debugger, Error.stackTraceLimit has no impact on Error() performance (in v8).
4040+ const ownerStackTraceLimit = 10 ;
4041+
40344042/** @noinline */
40354043function fakeJSXCallSite ( ) {
40364044 // This extra call frame represents the JSX creation function. We always pop this frame
40374045 // off before presenting so it needs to be part of the stack.
4038- return new Error ( 'react-stack-top-frame' ) ;
4046+ let error ;
4047+ const previousStackTraceLimit = Error . stackTraceLimit ;
4048+ Error . stackTraceLimit = ownerStackTraceLimit ;
4049+ error = Error ( 'react-stack-top-frame' ) ; // eslint-disable-line prefer-const
4050+ Error . stackTraceLimit = previousStackTraceLimit ;
4051+ return error ;
40394052}
40404053
40414054function initializeFakeStack(
Original file line number Diff line number Diff line change @@ -3915,6 +3915,25 @@ describe('ReactFlight', () => {
39153915 expect ( ReactNoop ) . toMatchRenderedOutput ( < span > Hello, Seb</ span > ) ;
39163916 } ) ;
39173917
3918+ it ( 'restores the stack trace limit after recreating JSX call sites' , async ( ) => {
3919+ function Component ( ) {
3920+ return ReactServer . createElement ( 'div' ) ;
3921+ }
3922+
3923+ const transport = ReactNoopFlightServer . render (
3924+ ReactServer . createElement ( Component ) ,
3925+ ) ;
3926+ const previousStackTraceLimit = Error . stackTraceLimit ;
3927+ Error . stackTraceLimit = 50 ;
3928+ try {
3929+ await ReactNoopFlightClient . read ( transport ) ;
3930+
3931+ expect ( Error . stackTraceLimit ) . toBe ( 50 ) ;
3932+ } finally {
3933+ Error . stackTraceLimit = previousStackTraceLimit ;
3934+ }
3935+ } ) ;
3936+
39183937 // @gate __DEV__
39193938 it ( 'can get the component owner stacks during rendering in dev' , ( ) => {
39203939 let stack ;
You can’t perform that action at this time.
0 commit comments