-
-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: Optimize StaticHtml component for React js 🚀 #14917
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
base: main
Are you sure you want to change the base?
feat: Optimize StaticHtml component for React js 🚀 #14917
Conversation
Refactors the StaticHtml component to use React.memo for efficient static HTML rendering, improving performance and compatibility.
🦋 Changeset detectedLatest 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 |
florian-lefebvre
left a comment
There was a problem hiding this 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that
memois 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
There was a problem hiding this comment.
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
This PR optimizes the StaticHtml component, addressing the limitations of the previous implementation (which relied on an incorrect
shouldComponentUpdatestrategy). It now correctly usesReact.memoto prevent unnecessary re-renders of the static HTML content. This approach is more performant and is the correct way to memoize function components.shouldComponentUpdateimplementation.shouldComponentUpdatewithReact.memousing custom comparison function to prevent re-renders.https://react.dev/reference/react/memo