Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -4031,11 +4031,24 @@ const createFakeJSXCallStackInDEV: (
) as any)
: (null as any);

// v8 (Chromium, Node.js) defaults to 10
// SpiderMonkey (Firefox) does not support Error.stackTraceLimit
// JSC (Safari) defaults to 100
// The lower the limit, the more likely we'll not reach react_stack_bottom_frame
// The higher the limit, the slower Error() is when not inspecting with a debugger.
// When inspecting with a debugger, Error.stackTraceLimit has no impact on Error() performance (in v8).
const ownerStackTraceLimit = 10;

/** @noinline */
function fakeJSXCallSite() {
// This extra call frame represents the JSX creation function. We always pop this frame
// off before presenting so it needs to be part of the stack.
return new Error('react-stack-top-frame');
let error;
const previousStackTraceLimit = Error.stackTraceLimit;
Error.stackTraceLimit = ownerStackTraceLimit;
error = Error('react-stack-top-frame'); // eslint-disable-line prefer-const
Error.stackTraceLimit = previousStackTraceLimit;
return error;
}

function initializeFakeStack(
Expand Down
19 changes: 19 additions & 0 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3915,6 +3915,25 @@ describe('ReactFlight', () => {
expect(ReactNoop).toMatchRenderedOutput(<span>Hello, Seb</span>);
});

it('restores the stack trace limit after recreating JSX call sites', async () => {
function Component() {
return ReactServer.createElement('div');
}

const transport = ReactNoopFlightServer.render(
ReactServer.createElement(Component),
);
const previousStackTraceLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 50;
try {
await ReactNoopFlightClient.read(transport);

expect(Error.stackTraceLimit).toBe(50);
} finally {
Error.stackTraceLimit = previousStackTraceLimit;
}
});

// @gate __DEV__
it('can get the component owner stacks during rendering in dev', () => {
let stack;
Expand Down
Loading