eui icon indicating copy to clipboard operation
eui copied to clipboard

[Emotion] Memoize EuiPopover styles

Open weronikaolejniczak opened this issue 1 month ago • 2 comments

Part of https://github.com/elastic/eui/issues/10147

Switch the eui*Styles() calls to useEuiMemoizedStyles. The generator must be a static function of the theme. If it also takes another argument, keep that dynamic part outside the memoized function.

No changelog.

  • src/components/popover/popover.tsx
  • src/components/popover/popover_title.tsx
  • src/components/popover/popover_footer.tsx
  • src/components/popover/popover_panel/_popover_panel.tsx
  • src/components/popover/popover_arrow/_popover_arrow.tsx

weronikaolejniczak avatar Oct 05 '26 10:10 weronikaolejniczak

👋 Thank you for your suggestion or request! While the EUI team agrees that it's valid, it's unlikely that we will prioritize this issue on our roadmap. We'll leave the issue open if you or anyone else in the community wants to implement it by contributing to EUI. If not, this issue will auto close in one year.

github-actions[bot] avatar Oct 05 '26 10:10 github-actions[bot]

Hi, I'd like to take this. I have the change ready: EuiPopoverTitle, EuiPopoverFooter, EuiPopoverArrow, and EuiPopoverPanel use useEuiMemoizedStyles, with the panel's color mode kept outside the memoized generator.

One question on popover.tsx: EuiPopover is a class component, and wrapping it with withEuiStylesMemoizer would change the export (and break EuiPopover['props'], which EuiSplitButtonActions uses). Since euiPopoverStyles() takes no theme, I compute it once at module scope instead. Does that work for you, or would you prefer a different approach?

Popover tests and the snapshots of components that render popovers pass unchanged. I'll open a PR with skip-changelog per the issue.

idhanth avatar Oct 15 '26 21:10 idhanth