Skip to content

Conversation

@sanjaiyan-dev
Copy link
Contributor

This PR optimizes the StaticHtml component, addressing the limitations of the previous implementation (which relied on an incorrect shouldComponentUpdate strategy). It now correctly uses React.memo to prevent unnecessary re-renders of the static HTML content. This approach is more performant and is the correct way to memoize function components.

  • Fixes: Incorrect shouldComponentUpdate implementation.
  • Impact: Improves the performance of rendering static HTML content in React.
  • Why: Makes use of modern react patterns, improves performance and fixes errors.
  • Implementation Details: Replaced shouldComponentUpdate with React.memo using custom comparison function to prevent re-renders.

https://react.dev/reference/react/memo

Refactors the StaticHtml component to use React.memo for efficient static HTML rendering, improving performance and compatibility.
@changeset-bot
Copy link

changeset-bot bot commented Nov 27, 2025

🦋 Changeset detected

Latest commit: b39a4f9

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: react Related to React (scope) pkg: integration Related to any renderer integration (scope) labels Nov 27, 2025
Copy link
Member

@florian-lefebvre florian-lefebvre left a comment

Choose a reason for hiding this comment

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

I don't feel confident approving this given how sensitive it is (react is one of our most uses integrations), I'll wait for someone else. Anyways, can you add a patch changeset? Thank you!

StaticHtml.shouldComponentUpdate = () => false;

export default StaticHtml;
export default memo(StaticHtml, () => true);
Copy link
Member

Choose a reason for hiding this comment

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

Just noting that memo is indeed noted as the equivalent at the end of https://react.dev/reference/react/Component#shouldcomponentupdate. Memo docs: https://react.dev/reference/react/memo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just noting that memo is indeed noted as the equivalent at the end of https://react.dev/reference/react/Component#shouldcomponentupdate. Memo docs: https://react.dev/reference/react/memo

Thanks for checking! You are correct that they serve the same purpose. But actually, shouldComponentUpdate is only for Class components, so it gets ignored here. The old code wasn't really running. Switching to memo ensures it works properly.

Sorry if I am wrong

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't be surprised if it worked, undocumented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope) pkg: react Related to React (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants