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

[3.1.0] "class" attribute not being recomputed #16505

Closed
boris-petrov opened this issue Apr 12, 2018 · 6 comments · Fixed by #16572
Closed

[3.1.0] "class" attribute not being recomputed #16505

boris-petrov opened this issue Apr 12, 2018 · 6 comments · Fixed by #16572
Milestone

Comments

@boris-petrov
Copy link
Contributor

boris-petrov commented Apr 12, 2018

We have something like this in a template:

{{some-component classNames="some-class fade" class=(if isLoggedIn "in")}}

This used to work fine until 3.1.0 - that is, when isLoggedIn is true, in addition to the classes in classNames, in is added. When isLoggedIn is false, then only the classes from classNames are used. However, in 3.1.0 this doesn't work any more. in is not added even when isLoggedIn is true. It works only if we add a non-empty string to the else clause - (if isLoggedIn "in" "some-non-relevant-class").

@jamesarosen
Copy link

jamesarosen commented Apr 13, 2018

I first ran into this with a ternary if:

{{my-button
  class=(if isSubmitting 'button--in-progress' (if isSubmitted 'button--complete'))
}}

where component:my-button also has classNameBindings.

I converted it to a computed property and found it has the same problem

submitClass: computed('isSubmitted', 'isSubmitting', function() {
  if (this.get('isSubmitting')) return 'button--in-progress'
  if (this.get('isSubmitted')) return 'button--complete'
  return 'cruft' // with this line, it works; without it, it fails
}),

@mydea
Copy link
Contributor

mydea commented Apr 20, 2018

I also ran into this, and this basically prevents us from using Ember 3.1, as it breaks our app in quite a lot of places (and was rather hard to track down!). Would be awesome to get a fix for this :)

@rwjblue
Copy link
Member

rwjblue commented Apr 20, 2018

Does someone have time to put together a repo demonstrating the issue or possibly a failing test case PR here?

@mydea
Copy link
Contributor

mydea commented Apr 20, 2018

Sure! It's pretty easy to reproduce.
See: https://github.com/mydea/ember-issue-reproductions/tree/ember-3-1-class-recomputation

The relevant code is here:
https://github.com/mydea/ember-issue-reproductions/blob/ember-3-1-class-recomputation/app/templates/application.hbs

Also note, interestingly, if hasClass is true by default, the toggling does work for both fields.

@rwjblue rwjblue modified the milestones: 1.13.x, v3.1.x Apr 20, 2018
@rwjblue
Copy link
Member

rwjblue commented Apr 21, 2018

Just to confirm here, this is only an issue with passing class as an argument to a component invocation, right? (E.g. <div class={{if hasClass ‘true’}}></div> is not an issue)

@rwjblue
Copy link
Member

rwjblue commented Apr 21, 2018

I think this is likely similar to #16379 (which is fixed by #16563). Basically somewhere in the pipeline (likely curly component manager) we are doing a truthy check where we shouldn't be...

ef4 added a commit that referenced this issue Apr 21, 2018
ef4 added a commit that referenced this issue Apr 22, 2018
rwjblue pushed a commit that referenced this issue Apr 22, 2018
(cherry picked from commit 6943f8e)
rwjblue pushed a commit that referenced this issue Apr 22, 2018
(cherry picked from commit 6943f8e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants