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

Ember 2.12 action handlers can fire twice for IE and Edge #15076

Closed
workmanw opened this issue Mar 27, 2017 · 8 comments
Closed

Ember 2.12 action handlers can fire twice for IE and Edge #15076

workmanw opened this issue Mar 27, 2017 · 8 comments

Comments

@workmanw
Copy link

workmanw commented Mar 27, 2017

Here is a JSBin: http://jsbin.com/cufupaw/edit?html,js,console,output

(JSBin instead of ember-twiddle because of IE)

If you click 'red', 'yellow' or 'blue' in chrome you'll notice the color of the text changes to green to reflect the "selected state", if you try this fiddle in IE it will not change. If you look at the JSBin console pane you'll see that the event handle logged that it was invoked twice. The first time toggled selected: true, the second back to false.

So why did this happen? The reason it happens is because the element with the action handler, also has a class="{{if item.selected 'selected'}}". To understand what's happening you'll need to first look at: event_dispatcher.js. Notice how it's looping over the element's attributes looking for an action handler. So here is the exact order of what happens:

  1. Click
  2. event_dispatcher finds the element and the action handler at attributes.item(2)
  3. action handler is invoked and toggles state, which then changes the DOM by adding a class.
  4. That DOM change shifts the action handlers position from attributes.item(2) to attributes.item(3).
  5. The action handler returns, the next loop moves to attributes.item(3) finding the exact same handler, and recalls it.

Here is screenshot of the first invocation of the action handler:
image

Here is a screenshot of the second invocation of the action handler:
image

This works with Ember 2.11. So somewhere along the way something changed.

@workmanw
Copy link
Author

So I bisected this and it turns out to that it was caused by this commit: ce35e6c . Reading my original description and looking at the commit, it's obvious why it broke. But it was also a little bit of a coincidence that it just worked before.

Honestly, I'm not sure why the loop over the element attributes continues after it finds a handler? I guess it's because you could have multiple {{action}} handlers? If that's the case it seems like the list be first filtered to matching action handlers, then each handler should be called.

CC: @GavinJoyce

@rwjblue
Copy link
Member

rwjblue commented Mar 27, 2017

I think the simplest fix would be to track the actions that have already been called during the single loop and if a given action were already ran, noop it.

@workmanw
Copy link
Author

@rwjblue I'm 👍 on that. Shall I open a PR?

@rwjblue
Copy link
Member

rwjblue commented Mar 27, 2017

Yep, if you don't mind. Will need a test to help ensure we don't regress again in the future. I believe it should at least be [BUGFIX release].

@workmanw
Copy link
Author

@rwjblue Roger that! I'm on it, you'll have a PR tonight because it's an upgrade blocker for us.

Side note, a test would be very easy to write, but does ember.js CI process test IE / Edge? Either way I'll test it, just curious.

@rwjblue
Copy link
Member

rwjblue commented Mar 27, 2017

Yes, we test in IE9, IE10, IE11, and Edge (as well as Chrome, Firefox, Safari, and phantom) in CI.

workmanw pushed a commit to workmanw/ember.js that referenced this issue Mar 27, 2017
workmanw pushed a commit to workmanw/ember.js that referenced this issue Mar 27, 2017
workmanw pushed a commit to workmanw/ember.js that referenced this issue Mar 27, 2017
workmanw pushed a commit to workmanw/ember.js that referenced this issue Mar 27, 2017
workmanw pushed a commit to workmanw/ember.js that referenced this issue Mar 28, 2017
workmanw pushed a commit to workmanw/ember.js that referenced this issue Mar 28, 2017
workmanw pushed a commit to workmanw/ember.js that referenced this issue Mar 28, 2017
@Serabe
Copy link
Member

Serabe commented Apr 7, 2017

@workmanw your PR has been merged. Can this be closed or is there anything left to do? Thank you!

@workmanw
Copy link
Author

workmanw commented Apr 7, 2017

@Serabe Ooops, I thought it was auto closed with the merge. Sorry about that.

@workmanw workmanw closed this as completed Apr 7, 2017
rwjblue pushed a commit that referenced this issue Apr 7, 2017
…n handlers to be fired twice.

(cherry picked from commit 00e95be)
rwjblue pushed a commit that referenced this issue Apr 7, 2017
…n handlers to be fired twice.

(cherry picked from commit 00e95be)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants