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

Feature - Transition improvements #623

Merged
merged 9 commits into from
Jul 16, 2020

Conversation

SimoTod
Copy link
Collaborator

@SimoTod SimoTod commented Jun 30, 2020

Closes #612
Closes #376
Closes #643

v2.4.1 fixed an issue with x-show directives inside x-for but introduced a regression experienced by a few people in the discord channel and affecting couple of demos:
show animations are re triggered every time a component is repainted so, depending on the effect applied, it could result in element flickering or similar.

2.4.1 also still represented the issue when show and hide overlap (See https://codepen.io/SimoTod/full/XWXzKaQ and try to double click on toggle: show variable will be set to true but the x-show div will be hidden and, from that point, the whole logic will be broken unless you refresh the page).

This PR aims to reinstantiate the fix in 2.4.0 but with support for x-show inside x-for and a few more changes:

  • no logic added to show.js (which was breaking the memory card example)
  • all logic in utils.js which should be easier to follow and understand
  • sensible variables

If this PR is accepted, there will be a follow up PR fixing some additional edge cases with request animation frame.
I kept them separated so it's easier to review and the second bunch of changes doesn't block this first PR which is probably more important.

Memory card game using fixed version: https://codepen.io/SimoTod/full/yLePaLW
Overlapping transition using fixed version: https://codepen.io/SimoTod/pen/gOPXwbv

-- NOTE --
test('transition out not called when item is already hidden') and test('transition in not called when item is already visible) have been updated to catch the regression in 2.4.1. Those tests were written with the original reactivity layer, the salesforce membrane by default does not trigger a repainting if value hasn't changed so those 2 tests were not valid anymore.

I've also added a test to cover the regression in 2.4.0 (it was a bit tricky to strip it down to a minimal state but it happens when x-show directives inside x-for have an x-bind:style directive).

export function once(callback) {
let called = false

return function () {
Copy link
Contributor

@ryangjchandler ryangjchandler Jun 30, 2020

Choose a reason for hiding this comment

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

missing arguments parameter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

@SimoTod SimoTod Jun 30, 2020

Choose a reason for hiding this comment

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

that function is always without arguments anyway, I can pass an empty array if clearer but I just kept the same function as VueJS (https://github.com/vuejs/vue/blob/4de4649d9637262a9b007720b59f80ac72a5620c/src/shared/util.js#L335)

Copy link
Contributor

Choose a reason for hiding this comment

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

omg, I never knew about this weird arguments variable - cheers!

Copy link
Contributor

Choose a reason for hiding this comment

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

could use function(...args) instead but I think the transpiled output would be larger & it probably makes sense to do it the same way Vue does

@MuzafferDede
Copy link
Contributor

Great work @SimoTod!
Quick question, i have a case which i need child elements to finish transitions then parent element do its transition thing. ex:

<div x-data="{show: true}">
  <p>shown: <span x-text="show"></span></p>
  <button @click="show = !show">Toggle</button>
  <div x-show.transition.duration.1000ms="show">
    PARENT
    <div x-show.transition.duration.5000ms="show">
      CHILD
    </div>
  </div>
</div>

What do you expect in this case to happen? child needs 5000ms to complete the transition but parent needs 1000ms.

I am expecting child element finish its transition and parent start once all child element finished. Or am i wrong?

@SimoTod
Copy link
Collaborator Author

SimoTod commented Jul 1, 2020

I need to test it but I believe that, with the current code, they start at the same time when showing but they are sequential when hiding, since the resolve callback is separate for the show part in x-show.
The reason is that you can't show the child element if parent is still hidden.

Yeah, so hide wait for the child component to disappear show doesn't. This only affects the x-show directive, transition effects start together.

It's not linked to this PR (it happens in previous versions since it's been coded in that way) so I would suggest we start a new thread to discuss if it needs fixing.

@MuzafferDede
Copy link
Contributor

Yeah, I was not trying to link it to this PR but want to know if i make sense to expect this behavior. Maybe we should consider this behavior in transitions. Will be great for the component patent - child reactivity

@SimoTod SimoTod force-pushed the feature/transition-improvements branch from e96b31b to af7b662 Compare July 2, 2020 16:35
@SimoTod SimoTod force-pushed the feature/transition-improvements branch from 8461d2c to 5c7eca5 Compare July 2, 2020 18:13
transitionIn(el,() => {
show()
}, component)
if(el.style.display === 'none' || el.__x_transition) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This line removed in v2.4.1 caused a regression experienced by several users.
We need to queue the animation only if the element is hidden or there is a transition running.
We don't check the type of transition and we don't add additional logic here, the low level functions will take care of ensuring that duplicated transition are discarded

@SimoTod SimoTod force-pushed the feature/transition-improvements branch from 42285a2 to 1583d14 Compare July 4, 2020 13:01
@SimoTod
Copy link
Collaborator Author

SimoTod commented Jul 7, 2020

@calebporzio a couple of guys on discord confirmed that it works correctly for them.
It also fixes an issue mentioned in #641
Feel free to have a spin when you have time, thanks.

@calebporzio
Copy link
Collaborator

Thank you so much @SimoTod for all your hard work on this ❤️ ❤️ ❤️

@calebporzio calebporzio merged commit e16ad01 into alpinejs:master Jul 16, 2020
@SimoTod SimoTod deleted the feature/transition-improvements branch November 20, 2021 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants