-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
BelongsTo PromiseProxy unchanged from null #5575
Comments
I just tested canary and it does not fix this issue. Too bad ember-twiddle does not work with canary (or beta) at the moment. I could try making a failing test for this. --edit I think the problem here is that while the property does fire a change event, if you use it as a parameter to a component the value is checked versus the old value. So only if the |
ftr we've never officially supported adding still-initially-loading records to relationships, and I don't believe we intend on doing so now. This may not be what is happening here but the |
The twiddle provided works when ember-data |
* Added failing test for #5575 * add integration and acceptance tests for editing an async belongsTo
It was actually to make sure it works when the promise has already settled. In that case the proxy can already have been used/read. So making sure the else is taken there will make sure the proxy will be recreated.
I'm testing the twiddle offline now and have inconsistent results myself too. Will let you know when I figure out what is happening here. |
It looks like I can trigger the bug again by using ember-power-select-blockless The twiddle is updated to show the bug again. --edit Otherwise you can't build components that rely on attributes being set like ember-power-select does here: https://github.com/cibernox/ember-power-select/blob/296c978a8e23144b54617d8bb385ee3852a7b6ce/addon/components/power-select.js#L147 I also think that observers on the proxy wont work. Listening to properties on the proxy does work, but that is one level deeper and not necessarily always the case like the scenario above shows. BTW it works after the first choice because |
That's a bug, but it might also point me at the real bug |
I don't really see how that is a bug. Should it not be possible to observe a proxied object and be able to see changes a few components down? I don't see how that would be possible without actually special typing the observing code to listen to the If you want I can build a simpler twiddle that shows that |
Posting this comment here for visibility: #5584 (comment) |
Closing this as ultimately the issue here does not seem to be with ember-data but an issue with how ember-power-select chose to listen for updates not being compatible with Proxies, by nature, are meant to be a stable wrapper around the content they proxy to. In the case of power-select, the library had accidentally come to rely on that proxy being torn down and re-created in situations it should not have been. There are a few ways that power-select and/or users of power-select can resolve this:
|
I don't entirely agree that this is outside the scope of ember-data. While it can be a design decision to make proxies stable, it is just that: a decision. As far as I know there is nothing inherently stable about proxies. Power select is probably not alone in expecting belongsTo to change. It is just the first that brings this to light in a more obvious way. I think this change will break a lot more code. And it feels bad to just say that it is their own fault for using something the way normal Ember usage would make you expect it to work. I can't even find anything related to Proxies being stable in the documentation. So how would anybody be expected to know this? I for one have built computed properties that only want to know whether a belongsTo has been set or not. If this code where used inside a component 2 levels deep I would run into the same problem.
A better alternative in my mind might be to make all of ember-data Promise based. Also the sync part. But I don't think that is in the cards. (While you could probably make the same setup where the promise returned by 'belongsTo' would stay stable longer than I would want. It is probably more natural there to make code that will return different promises when the belongsTo has changed content.) Maybe we have run into a missing feature of Ember itself. It looks like |
* Added failing test for emberjs#5575 * add integration and acceptance tests for editing an async belongsTo
https://ember-twiddle.com/8699e6c887c9eb2cb4344fb1d2551dbe?openFiles=templates.application.hbs%2C
The problem exists with ember-data 3.2+ and power-select
It seems that I can fix it by changing one line in
_updateLoadingPromise
in 3.3:https://github.com/emberjs/data/blob/master/addon/-legacy-private/system/relationships/state/relationship.js#L631
if (this._promiseProxy) {
to
if (this._promiseProxy && this._promiseProxy.get('isPending')) {
Which makes sure that the resulting object from
getData
is updated when changed and not just the.content
part is changed.https://github.com/cibernox/ember-power-select/blob/master/addon/templates/components/power-select/trigger.hbs#L1
This
if
directly checks the belongsTo attribute, and thus uses the result fromgetData
. This starts atnull
for an empty record. But setting it to anything else will not change the return value and thus not update anything.The text was updated successfully, but these errors were encountered: