data icon indicating copy to clipboard operation
data copied to clipboard

Attempted to call store.adapterFor() but store destroyed

Open amk221 opened this issue 2 years ago • 1 comments

Reproduction

Github repository with failing test: https://github.com/amk221/-ember-willdestroy-promiseproxy/blob/main/app/components/my-component.js#L9

Description

When a component is destroyed, this error happens (in the test suite only).

Attempted to call store.adapterFor(), but the store instance has already been destroyed

Further info:

isDestroyed is true on a hasMany promise array in the test environment But that same boolean is false when run through the same scenario in the dev environment.

Versions

Run the following command and paste the output below: yarn list ember-source && yarn list ember-cli && yarn list --pattern ember-data.

▶ yarn list ember-source && yarn list ember-cli && yarn list --pattern ember-data
yarn list v1.22.19
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ [email protected]
✨  Done in 1.35s.
yarn list v1.22.19
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ [email protected]
✨  Done in 1.49s.
yarn list v1.22.19
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ @ember-data/[email protected]
├─ [email protected]
└─ [email protected]
✨  Done in 1.45s.

amk221 avatar Aug 08 '22 08:08 amk221

I haven't run the code in the project above, but reading it a couple of things stand out to me. But first, to lay out an expectation:

I wouldn't ever expect you to his this error in a running app, for 2 reasons.

  1. it would only be possible in tests or fastboot to hit this error (the only contexts in which an app is destroyed)
  2. it is not possible to hit this in prod or dev. so production fastboot would also not hit this.

Based on reading the code I believe this is fully expected. In willDestroy you attempt to access an async relationship (this.foo.bars). This would trigger an async fetch, and thus the assertion.

I think iirc this started being more of an issue for you in 3.28). I suspect the reason for that is that PromiseManyArray no longer extends EmberObject/ArrayProxy and ergo no longer uses computed for its values and no longer does a two-pass destroy. This is something that might get better / might get worse with coming changes in 4.8 where I've had to do a lot of special things to try to keep access of relationships post-destroy of the record from blowing up (since this was sadly a safe thing to do using ember classic even though it should not have been safe).

runspired avatar Aug 08 '22 23:08 runspired

Closing as user code that may make network requests during destroy should guard for app destroy. This said post-5.0 we may want to redesign our teardown experience.

runspired avatar Dec 07 '22 18:12 runspired