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

[bugfix beta] Fetch cancels unload #5376

Merged
merged 1 commit into from
Mar 14, 2018

Conversation

hjdivad
Copy link
Member

@hjdivad hjdivad commented Mar 13, 2018

When fetching records, cancel internal model destruction if it is
scheduled, ie if the model is dematerializing because it was unloaded.

It is not possible to construct snapshots for dematerializing internal
models. Prior to this commit, this could happen when fetching a record
in the same runloop that it was unloaded. A straightfoward way of
getting into this state was via

store.findRecord('book', 1).then(b => b.unloadRecord())

when the model is already cached in the store. Under these conditions,
the fetch is scheduled, then the promise fulfills with the cached record
and is unloaded and then the scheduled fetch is flushed.

[fix #5343]

@@ -921,6 +925,9 @@ Store = Service.extend({
// will once again convert the records to snapshots for adapter.findMany()
let snapshots = new Array(totalItems);
for (let i = 0; i < totalItems; i++) {
if (internalModels[i].hasScheduledDestroy()) {
internalModels[i].cancelDestroy();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we canceling in two places? Does the test catch both instances where canceling is required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per OOB discussion, moving all cancelation to flush

@sly7-7
Copy link
Contributor

sly7-7 commented Mar 14, 2018

I tested the scenario in which I reproduced #5343, and this seems to work. Thanks a lot @hjdivad

@hjdivad hjdivad force-pushed the hjdivad/cancel-unload-on-fetch branch from 1ae5181 to e9441a5 Compare March 14, 2018 17:58
When fetching records, cancel internal model destruction if it is
scheduled, ie if the model is dematerializing because it was unloaded.

It is not possible to construct snapshots for dematerializing internal
models.  Prior to this commit, this could happen when fetching a record
in the same runloop that it was unloaded.  A straightfoward way of
getting into this state was via

```
store.findRecord('book', 1).then(b => b.unloadRecord)
```

when the model is already cached in the store.  Under these conditions,
the fetch is scheduled, then the promise fulfills with the cached record
and is unloaded and *then* the scheduled fetch is flushed.

[fix emberjs#5343]
@hjdivad hjdivad force-pushed the hjdivad/cancel-unload-on-fetch branch from e9441a5 to 7444444 Compare March 14, 2018 18:02
@hjdivad hjdivad merged commit bae8df9 into emberjs:master Mar 14, 2018
@hjdivad hjdivad deleted the hjdivad/cancel-unload-on-fetch branch March 14, 2018 18:15
@sly7-7
Copy link
Contributor

sly7-7 commented Mar 15, 2018

@bmac A very kindlyi-smoothy-loving ping to ship a new beta... 😺

@bmac
Copy link
Member

bmac commented Mar 15, 2018

@sly7-7 I just published v3.1.0-beta.2.

@sly7-7
Copy link
Contributor

sly7-7 commented Mar 16, 2018

Thank you So much @bmac

@phantomphildius
Copy link

@bmac thank you this also fixes the same issue we were having!

@jaswilli
Copy link

I just tested this on a 2.18.2 app and it fixes it there as well. Any chance of 2.18.3 bugfix release? 😄

@aalasolutions-zz
Copy link

Please release 2.18.4 ember data with this fix. 2.18 is still in LTS branch and we need this fix

@rwjblue
Copy link
Member

rwjblue commented Jul 24, 2018

@aalasolutions - FWIW, there have not been any ember-data versions that are LTS. The only project that has released any LTS versions to date has been Ember itself (ember-source npm package).

@aalasolutions-zz
Copy link

@rwjblue hmm, right. meanwhile I have totally ditched unloadRecord and in my component, i filtered the records which are not required. So I guess I can live with that for now

@bmac
Copy link
Member

bmac commented Jul 24, 2018

I just cherry-picked this commit to the 2.18 branch and release Ember Data 2.18.4.

(Sorry @rwjblue I should have pinged you to give you a heads up first).

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

Successfully merging this pull request may close these issues.

model.unloadRecord causes Uncaught TypeError: Cannot read property 'eachAttribute' of null
8 participants