Skip to content
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,31 @@ describe('ReactDOMFizzShellHydration', () => {
]);
expect(container.textContent).toBe('New screen');
});

test('TODO: A large component stack causes SSR to stack overflow', async () => {
spyOnDevAndProd(console, 'error');

function createNestedComponent(depth: number) {
if (depth <= 0) {
return function Leaf() {
return <AsyncText text="Shell" />;
};
}
const NextComponent = createNestedComponent(depth - 1);
function Component() {
return <NextComponent />;
}
return Component;
}
const NestedComponent = createNestedComponent(1500);
Copy link
Copy Markdown
Member

@kassens kassens Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just make this a single component. Your current implementation returns a different instance on every re-render even for the same depth which is maybe not ideal.

Suggested change
function createNestedComponent(depth: number) {
if (depth <= 0) {
return function Leaf() {
return <AsyncText text="Shell" />;
};
}
const NextComponent = createNestedComponent(depth - 1);
function Component() {
return <NextComponent />;
}
return Component;
}
const NestedComponent = createNestedComponent(1500);
function NestedComponent({depth}: {depth: number}) {
if (depth <= 0) {
return null;
}
return <NestedComponent depth={depth - 1} />;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch!


// Server render
await serverAct(async () => {
ReactDOMFizzServer.renderToPipeableStream(<NestedComponent />);
});
expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error.calls.argsFor(0)[0].toString()).toBe(
'RangeError: Maximum call stack size exceeded',
);
});
});