Computed property recalculating on store.unloadAll()

Should computed properties fire when you unload records from the store via unloadAll()?

I’m seeing an issue where an app of mine is re-calculating some computed properties when I unloadAll (on logout).

This recalculation is problematic because it seems to result in a race condition. Specifically in my case, I’m seeing an issue with filterBy computed properties. The unloadAll() triggers a recalculation, but when filterBy tries to get() the property from an item I hit this error.

Assertion Failed: Cannot call get with 'someProperty' on an undefined object.

I feel like I can’t be mad at a property for recomputing when the underlying value changes. I mean, that’s what a computed property is for, right?

But I’m confused because I can’t recreate this issue in a Twiddle. In that recreation Twiddle, the CP does not recalculate when I unload the store.

I can’t tell which behavior is wrong. The twiddle which doesn’t recalculate, or my app which does recalculate. It seems I may not be alone with this confusion.

Maybe a better question, what’s the best way to unload data from the store on logout? Refresh the page? (seems a bit brute force) Unload all, but only after tearing down controllers so properties don’t recalculate? (seems excessive, but would probably solve my issue).

No worries if there’s no clear answer here, but I was curious if anyone had input on this.

Can’t speak to the specific at all but I know unloadAll has been fairly buggy in the past. We typically just refresh to clear the store on logout, and actually I kinda thought ember simple auth does that by default but I could be wrong. Either way I don’t see anything all that bad about refreshing unless it’s causing problems in your use case.

After re-reading the ember-simple-auth docs, I think you’re totally right, and I should just refresh. I was making my life way too complicated by trying to manually clear things out.

ember-simple-auth was one of the first features I added ~a year ago, and I forgot/didn’t realize that it reloaded by default if you don’t override sessionInvalidated, which I was doing. I had overridden that method with the mindset of, “Here’s where I do my clean up”, which was silly since a reload would’ve done that for me with no work.

Once I removed my sessionInvalidated handler for ApplicationRouteMixin, I saw my app reload automatically on logout, and now that I see that behavior in action, I feel like it makes way more sense than clearing out the store on my own.

I don’t have an answer for my computed property behavior mystery, but I’m inclined to say it’s due to some mistakes in my code, and that I’m just going to reload to simplify things.

Thanks!

1 Like