-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Allow legitimate 0 positions to update popover position #51320
Conversation
y: Math.round( y ?? 0 ) || undefined, | ||
x: | ||
x === null || Number.isNaN( x ) | ||
? 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thoughts, perhaps this side of the ternary should be undefined
as prior to this PR, the ||
meant that nullish or NaN
values resulted in undefined
... I can give that a try tomorrow, as that might potentially resolve the issue with the failing snapshot tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To sum up, here are the different versions for this algorithm tried so far:
- this pr:
c === null || Number.isNaN( c ) ? 0 : Math.round( c )
- trunk (which introduced the regression):
Math.round( c ?? 0 ) || undefined
- old version:
Number.isNaN( c ) ? 0 : c ?? undefined
I guess we need to understand exactly in which scenario we'd need to have undefined
instead of 0
. @corentin-gautier maybe can also help, since he worked on #46187 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for outlining each of the different options. To try to be more conservative about it, I've updated this logic in this PR to c === null || Number.isNaN( c ) ? undefined : Math.round( c )
so that we're only outputting a number when we have a real value. I think that might get us to a smaller potential change? Happy to revert if need be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good to me. Looking at the snapshot changes, it's interesting that motion stops applying a transform on the Z
axis — it must be some internal framer motion optimisation. From past experience, usually the reason for having translateZ(0)
would be to promote an element to a separate composite layer, thus reducing the amount of times it needs to be re-painted to screen. But I can see that we're already applying the will-change: transform
style, which also achieves the same goal, so we should also be fine under that point of view.
Thank you for working on this! I pushed a couple of commits that refactor the logic to a separate function and add unit tests, so that we can use those tests to spec out exactly what behavior we'd like to achieve for this logic. |
Excellent, thank you @ciampo, that makes things much neater! I've just pushed a tiny change and added a comment. I've updated the snapshot tests for While manually testing |
Flaky tests detected in 463041f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5218630409
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes LGTM, although I've been struggling to repro the bug and therefore to test the fix specifically in the list view. It would be great if we'd get one final confirmation that the bug is indeed fixed the current set of changes from this PR before merging :)
Wonderful, thanks for the collaboration @ciampo and for the review @apeatling! 🙇 |
…dPress#51320) * Popover: Allow legitmate 0 positions to update popover position * Add changelog entry * Refactor to utility function * Add unit tests * Switch to undefined fallback for null and NaN cases, update snapshots --------- Co-authored-by: Marco Ciampini <[email protected]>
What?
Fix an issue with the Popover component where
0
values forleft
(ortop
) would not update the position of the popover component, as the final value was treated asundefined
instead of0
.Why?
This resolves a tricky edge case that sometimes occurs with the list view drop indicator line under specific conditions (more info in the testing instructions). But the idea behind this PR is that we most likely don't want to be passing
undefined
for the final style of the popover, or we risk persisting stale positions, as occurs in the list view drop indicator.How?
Ensure that
0
values are always applied to the style output of the popover component.It looks like the issue was introduced in #46187 with some discussion occurring in https://github.com/WordPress/gutenberg/pull/46187/files#r1036857416. The fix here borrows from the idea in #45545 (comment) but doesn't include an
undefined
fallback, asMath.round()
never returnsnull
orundefined
, as far I can tell.Testing Instructions
These testing instructions are quire specific, as it's a tricky to reproduce issue:
To test, in a fresh post or page, add the following markup:
Some heavily nested block markup
Prior to applying this PR, test the following (it might be easier to watch the steps in the screengrabs below):
0
for the left position, but the drop indicator is retaining the previousx
position styling.Note: if you are finding the issue difficult to reproduce, make sure that prior to adding the paragraph blocks, the list view is short enough that it does not yet have a vertical scrollbar. Changing the horizontal position of the list view is likely to make the list view items slightly off from flush with the left edge of the screen, so the issue won't appear.
Screenshots or screencast
Before
2023-06-08.16.45.35.mp4
After
2023-06-08.16.44.53.mp4