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.set & Ember.setProperties fail to set properties "enumerable" #14594

Closed
herom opened this issue Nov 9, 2016 · 9 comments · Fixed by #16735
Closed

Ember.set & Ember.setProperties fail to set properties "enumerable" #14594

herom opened this issue Nov 9, 2016 · 9 comments · Fixed by #16735

Comments

@herom
Copy link

herom commented Nov 9, 2016

I'm currently using Ember 2.4.3 and wanted to upgrade, but the behaviour of Ember.set and Ember.setProperties in 2.7.0 onwards seems a bit buggy to me.

To reproduce the "bad" behaviour, do the following:

const Test = Ember.Object.extend({
  myProp: null,
  didChangeMyProp: Ember.on('init', Ember.observer('myProp', function () {
    console.log('updated');
  })
});

const testInstance = Test.create();
Ember.setProperties(testInstance, {id: 3, myProp: {id: 1}});

// here, I would expect (and did get!) `['id', 'myProp']` in Ember v2.4.3
// from Ember v2.7.0 onwards, it prints `['id']`
console.log(Object.keys(testInstance));

// alternatively, if you just `set` the `myProp` property
// Ember.set(testInstance, 'myProp', {id: 1});
// the console will only print an empty array.

// however, if I don't initialize the `myProp` property in the `extend()` call, the Object.keys are set as usual

It seems, that somewhere - deep in the guts of Ember.set && Ember.setProperties the meta is declaring the property as "not enumerable"?!

I can't reproduce this "bug" at https://ember-twiddle.com as it seems to work over there, if I try these steps in the Chrome DevTools (interesstingly enough, it prints the Ember Version as 2.9.0 but if you call Ember.VERSION in the console, it prints 2.8.0 😸 )

@rwjblue
Copy link
Member

rwjblue commented Nov 9, 2016

interestingly enough, it prints the Ember Version as 2.9.0 but if you call Ember.VERSION in the console, it prints 2.8.0

This is because ember-twiddle.com itself is an Ember app (that runs Ember 2.9.0 ATM), and the app that the twiddle is creating is running in an iframe. So asking the host application Ember.VERSION reports 2.9.0, but asking the app running inside the iframe for Ember.VERSION will report whatever version is being specified in twiddle.json.

Changing the console to use the right context will fix this for you.

host application ember version

iframe application ember version

@rwjblue
Copy link
Member

rwjblue commented Nov 9, 2016

I suspect what is happening is that the set determines that the values are the same and does not actually set the property (because there is no work to be done).

Demo:

const Foo = Ember.Object.extend({
  prop1: null
});

let foo = Foo.create();

log('Keys:', Object.keys(foo));
foo.set('prop1', null);
log('Keys:', Object.keys(foo));
foo.set('prop1', 'value');
log('Keys:', Object.keys(foo));

@rwjblue
Copy link
Member

rwjblue commented Nov 10, 2016

I believe this is a duplicate of #14270, can you review and confirm?

@herom
Copy link
Author

herom commented Nov 10, 2016

Thanks a lot for your response @rwjblue! At first I also thought it may be a duplicate of the issue you mentionend but I think it's slightly different here as the value will be set not enumerable as soon as an Ember.observer is declared for the prop1 property.

See the edited Demo of yours, where I declared an Ember.observer - the Object.keys(bar); call will always return an empty array and bar.hasOwnProperty('prop2') will return false...

So, the value is set correctly, but it's not declared enumerable when set via Object.defineProperty, I guess

@pixelhandler
Copy link
Contributor

@herom I cloned your jsbin, https://jsbin.com/limuki/edit?html,js,output and set the version to 2.4.3 and do see the output that the object's property is available via hasOwnProperty. This looks like a bug to me.

@herom
Copy link
Author

herom commented Nov 12, 2016

Thanks a lot @pixelhandler - I totally forgot about that (a jsbin with the "working" solution) 😃

@herom
Copy link
Author

herom commented Nov 21, 2016

Just a short sumup of the different code samples in order to understand/reproduce this bug for better readability:

WORKING Demo (without Ember.observer) in Ember Canary from @rwjblue (working, does not fully reproduce the issue as it's lacking Ember.observer)

FAILING Demo (with Ember.observer) in Ember Canary from @herom (not working, fully reproduces the issue)

WORKING Demo (with Ember.observer) in Ember v2.4.3 from @pixelhandler (working, fully reproduces the issue)

@pixelhandler
Copy link
Contributor

@herom @rwjblue is this still an issue, perhaps we should close or create a new reproduction of this, what do you think?

@pixelhandler
Copy link
Contributor

Per our triage policy I'll close this out for now, feel free to reopen if the issue persists on the current release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants