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

style module: remove when no prop transition happens #712

Open
wclr opened this issue Jun 24, 2020 · 3 comments
Open

style module: remove when no prop transition happens #712

wclr opened this issue Jun 24, 2020 · 3 comments

Comments

@wclr
Copy link
Contributor

wclr commented Jun 24, 2020

So the current version applies remove styles to the element, and wait all transitionEnd events. There is the edge case when the element (before removal) already got to the state where its style is the same with remove's value. And in this case, there will be no transition happen and the element will not be removed from DOM eventually.

It is not theoretical case I actually run into it.

I tried to solve this problem by comparing current (before removal) element actual style with remove props values. This would work in most of the cases, but there are cases where it will not, for example, if you want to set a value on transform: translateX(100px), in dom in computed styles is value will be matrix(...), so you can not directly compare string style values, the same thing for calculated css values like calc(...).

@paldepind I wonder what do you think about the issue, is it needed/worth to handle this case?

@wclr wclr changed the title style module: remove when no transition required style module: remove when no prop transition happens Jun 24, 2020
@wclr
Copy link
Contributor Author

wclr commented Jun 27, 2020

@mightyiam

@mightyiam
Copy link
Contributor

@whitecolor perhaps a re-thinking of the mechanism. Could you please make a PR that adds a failing test for this?

@wclr
Copy link
Contributor Author

wclr commented Jun 27, 2020

@mightyiam

Check, please, this one without PR:

  it.only('handles remove style if no transition happens', function (done) {
    var btn = h('button', {
      style: {
        transition: 'transform 0.1s',
        remove: { transform: 'translateY(100%)' } as any
      }
    }, ['A button'])
    var vnode1 = h('div.parent', {}, [btn])
    var vnode2 = h('div.parent', {}, [null])
    document.body.appendChild(vnode0)
    patch(vnode0, vnode1)
    var button = document.querySelector('button')!
    button.style.transform = 'translateY(100%)'
    let transitionEndCalled = 0
    button.addEventListener('transitionend', function () {
      transitionEndCalled++
    })
    patch(vnode1, vnode2)
    assert.strictEqual(document.querySelector('button'), null)

    setTimeout(() => {
      assert.strictEqual(transitionEndCalled, 0, 'transitionEndCalled')
      done()
    }, 500)
  })

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

No branches or pull requests

2 participants