Fix popover positioning and optimize rendering logic #202
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using the
ArrowContainer
component, a bug in the underlyingPopover
component is displayed, specifically, in how thepopoverRect
data is calculated. When opening a popover, thepopoverRect
is briefly set (and subsequently, passed to thecontent(..)
function, as the prior value. This causes the arrow to visibly flash as it updates from the prior to the next value ofpopoverRect
.The code to reproduce this bug is relatively simple, and I provide it below, but the only real trick is changing the size of the
popoverRect
(otherwise it'll only appear on first render).Code to reproduce the above gif
This PR fixes this issue by simplifying and cleaning up the logic used in the
useLayoutEffect
hook, and generally the logic used to compute the layout, specifically by simplifying theuseLayoutEffect
hook, removing any use of animation frames and rather just directly checking for changes in relevant properties and callpositionPopover
when needed.These changes resolve the flickering issue with the arrow while also simplifying the logic to be less prone to edge cases like this.
The same code as above with the fixes:
Also confirmed things continue to work when resizing the window. Generally this seems like a safe/good change to me, and was fixing the issues I was hitting, but if there are hidden issues with this let me know and I'm happy to iterate/add some documentation to this code, since it's fairly gnarly right now.