-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[PopoverOverlay] Fix regression introduced by removal of CSSTransition
#2000
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
Conversation
CSSTransition
CSSTransition
this.focusContent(); | ||
|
||
this.changeTransitionStatus(TransitionStatus.Entered); | ||
this.changeTransitionStatus(TransitionStatus.Entering, () => { |
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.
Setting Entering
ensures onClose
is not fired in handleClick
https://github.com/Shopify/polaris-react/pull/2000/files#diff-f2a2881feff25a3d1e6fad684176b150R221
|
||
this.changeTransitionStatus(TransitionStatus.Entered); | ||
this.changeTransitionStatus(TransitionStatus.Entering, () => { | ||
setTimeout(() => { |
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.
I think we’d need to ensure this timeout gets cleared if the component gets unmounted?
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.
Yeah probably a good practice to do this
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.
Totally. I'll clear the newly added setTimeout
(entering) and the existing one (exiting).
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.
This is a good way of addressing the issue, sorry for not catching it earlier.
Is this urgent? Before we merge I'd really like to have a test for this so that we can avoid having the same issue in the future
A test would be really simple, in Popover.test.tsx
you just need to render the example you have, and use spies to make sure that openPopover
gets called but closePopover
doesn't
What about the mount lifecycle? While there is no bug, it has the same hole where the state will be |
Otherwise looks good! But as @amrocha mentioned needs a test 🤖 |
} | ||
|
||
componentWillUnmount() { | ||
this.clearTransitionTimeout(); |
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.
Now clearing the transition timers when the component unmounts.
expect(spy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('does not call onClose when Popover is opening and trigger was not the activator', () => { |
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.
Added a test replicating the bug we encountered.
@tmlayton Regarding the mount lifecycle, I believe we should not update the transition status all together. The component can be mounted but not visible |
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.
Looks good to me.
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.
Updates UNRELEASED Clears transition timers Adds test Improves release notes
75569f3
to
09f754e
Compare
Fix has been released in |
WHY are these changes introduced?
This PR fixes a regression in
PopoverOverlay
introduced by #1756The
onClose
prop was fired when clicking or touching the element activating thePopover
when that element was not theactivator
received as a prop.In this case, the
Popover
would close right away.It feels like a weird use case but that's how the
ImageEditor
in web is usingPopover
. Theactivator
prop is just an emptydiv
. The real Popover triggers are rendered higher up in the DOM tree.WHAT is this pull request doing?
This PR fixes the regression.
In
handleClick
, we preventonClose
to be called when the source of the click is a descendant of thePopover
or thePopover
is being opened (this one was not working as expected).We are now properly setting the transition status to
Entering
instead ofEntered
when thePopover
is opened. It prevents clicks that are not coming from descendants to fireonClose
while thePopover
is opening.How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Test the Playground code with and without the changes.
Before:
closePopover
is fired when opening thePopover
.After:
closePopover
won't be fired when opening thePopover
(fix)Copy-paste this code in
playground/Playground.tsx
:🎩 In
web
:web
serverpolaris-react
and checkoutpopover-overlay-fix
yarn
then build a consumer for webyarn run build-consumer web
(still inpolaris-react
)<
(back) button in the left panel, theX
of the Modal or the 'Undo all' buttonWeb issue for context: https://github.com/Shopify/web/issues/17477
🎩 checklist
README.md
with documentation changes