Skip to content
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

[EuiCodeBlock] Minimize subcomponent remounting #6077

Merged
merged 7 commits into from
Jul 28, 2022

Conversation

thompsongl
Copy link
Contributor

@thompsongl thompsongl commented Jul 26, 2022

Summary

During an investigation of unrelated hook performance, it was found that the copy and fullscreen icons inside EuiCodeBlock would be remounted on every rerender. This is because the CopyButton, FullScreenButton components returned by their respective hooks were not memoized and were being recreated (and therefore unmounted/mounted) every rerender. Similarly, optionalStyles and codeBlockControls would unset and recreate their values on every rerender.

The net effect of the useMemo additions is that CopyButton, FullScreenButton, FullScreenDisplay, optionalStyles and codeBlockControls now only update on intentional state or prop changes.

Checklist

  • Checked in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Props have proper autodocs and playground toggles
  • Checked Code Sandbox works for any docs examples
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6077/

@thompsongl thompsongl marked this pull request as ready for review July 26, 2022 17:51
src/components/code/code_block.tsx Show resolved Hide resolved
src/components/code/code_block.tsx Outdated Show resolved Hide resolved
src/components/code/code_block.tsx Outdated Show resolved Hide resolved
src/components/code/code_block.tsx Outdated Show resolved Hide resolved
src/components/code/code_block.tsx Outdated Show resolved Hide resolved
src/components/code/code_block.tsx Outdated Show resolved Hide resolved
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6077/

Copy link
Member

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

Very nice!!! 👏

upcoming_changelogs/6077.md Outdated Show resolved Hide resolved
@thompsongl thompsongl enabled auto-merge (squash) July 28, 2022 13:34
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6077/

@thompsongl thompsongl merged commit b17a335 into elastic:main Jul 28, 2022
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.

3 participants