element-react
element-react copied to clipboard
Popover: Unnecessary re-renders when document clicked
Description
All Popovers in the page re-render on document clicked, even if none are visible. Should only render Popovers which are open and have a true state change.
Reproduce Steps
- Wrap a button with a Popover
- In React DevTools enable the Highlight updates when components render option.
- Click anywhere in the page and watch the button be re-rendered, regardles of whether the Popover is visible.
- For extra proof use the Profiler flamegraph to record this action.
Error Trace (if possible)
Not error; optimisation.
Solution
Within document click listener, add early return if showPopper
is already false in order to prevent setting state to false again.
Additional Information
ElementReact version: 1.4.34