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

Popover: fix inserter glitch #18955

Merged
merged 3 commits into from
Dec 6, 2019
Merged

Popover: fix inserter glitch #18955

merged 3 commits into from
Dec 6, 2019

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Dec 5, 2019

Description

Fixes #18953.

Since #18813, the popover content height it calculated with scrollHeight, but this doesn't work properly if the content itself contains another scroll container. As a result, if you open the sibling inserter, the content height will continuously change, causing the content to move up and down every half second.

The solution is to revert to using getBoundingClientRect without maxHeight set. This can be done right at the start, and for performance reasons at every interval after that because we have to remove maxHeight first to get the bounding client rect.

How has this been tested?

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. .

Copy link
Contributor

@epiqueras epiqueras left a comment

Choose a reason for hiding this comment

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

As a result, if you open the sibling inserter, the content height will continuously change, causing the content to move up and down every half second.

I can't seem to reproduce this. Is this browser specific?

@ellatrix
Copy link
Member Author

ellatrix commented Dec 6, 2019

@epiqueras No, I think it's for all browsers. It just got reported here: #18953.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

This fixes that particular issue but there's still other glitches, for example, if you open the "More Menu" (top right) in a screen with a small height and then scroll to the bottom of the menu, you'll notice that it will jump to the top again.

@ellatrix
Copy link
Member Author

ellatrix commented Dec 6, 2019

@youknowriad Ah, I see what you mean. It looks like we cannot measure the height after the first time, then, so I'll revert it back to the old behaviour of only measuring once at the start. This will introduce the problem with the "Block Settings" ellipsis menu again though. We have to figure out why the height is not measured correctly at the start.

@youknowriad
Copy link
Contributor

yeah, hard problem. Maybe the content is not ready on first render for some reason for these popovers.

@ellatrix
Copy link
Member Author

ellatrix commented Dec 6, 2019

@youknowriad It should be fixed now. Looks like at the animation frame the height is good for both popovers.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

This is magic

@ellatrix
Copy link
Member Author

ellatrix commented Dec 6, 2019

Ugh, this makes a number of jest tests fail that rely on having the popover visible immediately.

@ellatrix
Copy link
Member Author

ellatrix commented Dec 6, 2019

I'm not sure what to do about the tests here. For the tests, a later refresh fails them. I don't have a good understanding of the react DOM test utils and I'm not sure what they fail...

@youknowriad
Copy link
Contributor

Maybe @gziolo can help here :)

@ellatrix
Copy link
Member Author

ellatrix commented Dec 6, 2019

The refresh on animation frame is somehow confusing the tests. If I use setTimeout it works fine.

@youknowriad
Copy link
Contributor

@ellatrix there's some tricks here jestjs/jest#5147

@ellatrix ellatrix force-pushed the fix/popover-height-calc-bug branch from c4f047b to 52e73b9 Compare December 6, 2019 10:19
@ellatrix
Copy link
Member Author

ellatrix commented Dec 6, 2019

It looks like a timeout (0) works just fine as well and leaves the tests working. Let's go for that then. I suspect the underlying height problem is the same as:

/*
* Without the setTimeout, the dom node is not being focused. Related:
* https://stackoverflow.com/questions/35522220/react-ref-with-focus-doesnt-work-without-settimeout-my-example
*
* TODO: Treat the cause, not the symptom.
*/
const focusTimeout = setTimeout( () => {

Hopefully we find can figure out a proper solution in a follow up PR. Cc @aduth since you created #11430.

@ellatrix ellatrix merged commit bd8436f into master Dec 6, 2019
@ellatrix ellatrix deleted the fix/popover-height-calc-bug branch December 6, 2019 10:44
@epiqueras
Copy link
Contributor

Nice work!

Interestingly, I was never able to replicate #18953 on my machine.

@youknowriad
Copy link
Contributor

@epiqueras I did reproduce before this PR, i think it was related to viewport size somehow.

@epiqueras
Copy link
Contributor

Ah, that could be it!

@youknowriad youknowriad added this to the Gutenberg 7.1 milestone Dec 9, 2019
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.

Sibling inserter block library keeps resizing itself
3 participants