Skip to content

fix(react): Memoize wrapped component to prevent rerenders #17230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2025

Conversation

chargome
Copy link
Member

Cursor failed me on this one so fixing here.

closes #17183

@chargome chargome self-assigned this Jul 30, 2025
@chargome chargome requested a review from andreiborza July 30, 2025 14:29
@@ -96,6 +96,122 @@ describe('withErrorBoundary', () => {
const Component = withErrorBoundary(() => <h1>Hello World</h1>, { fallback: <h1>fallback</h1> });
expect(Component.displayName).toBe(`errorBoundary(${UNKNOWN_COMPONENT})`);
});

it('does not rerender when props are identical', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Tbh I think these tests are useless, you're just testing react api here. I think we don't need tests for this at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd leave them in still, since they'll make sure we keep this memoized. But good point indeed

@chargome chargome merged commit 5652282 into develop Jul 30, 2025
163 of 165 checks passed
@chargome chargome deleted the cg-react-error-boundary-memo branch July 30, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

withErrorBoundary create unnecessary rerenders
2 participants