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

Aborting a transition clears the resolved model #14721

Open
btecu opened this issue Dec 15, 2016 · 8 comments
Open

Aborting a transition clears the resolved model #14721

btecu opened this issue Dec 15, 2016 · 8 comments

Comments

@btecu
Copy link
Contributor

btecu commented Dec 15, 2016

When you abort a transition in afterModel and go to an intermediate route, the model for the previous route does not exist, although it was resolved.

https://ember-twiddle.com/db66247a084b6028d31c29ef856d7301 (See the console log)

@pixelhandler
Copy link
Contributor

pixelhandler commented Dec 16, 2016

@locks is it possible that the model is not kept on the application route since setup controller was never reached?

Also I changed the Ember version to 2.9 and the last two LTS releases 2.8, 2.4 (I think) and the behavior was the same.

@btecu
Copy link
Contributor Author

btecu commented Dec 16, 2016

@pixelhandler No, that's not the case. You can test this easily but writing an empty setupController() (don't call super to set the model on the controller). You'll see that modelFor still returns.

@btecu
Copy link
Contributor Author

btecu commented Dec 28, 2017

Any ideas on how to work around this?

btecu added a commit to btecu/ember.js that referenced this issue Jun 4, 2018
btecu added a commit to btecu/ember.js that referenced this issue Jun 4, 2018
@pixelhandler
Copy link
Contributor

@btecu do you still have this issue, or did you find a work around?

@btecu
Copy link
Contributor Author

btecu commented Sep 14, 2018

@pixelhandler still have the issue. See #16716.

@pixelhandler
Copy link
Contributor

Noted that his has a PR for the test, #16716

btecu added a commit to btecu/ember.js that referenced this issue Oct 3, 2018
@btecu
Copy link
Contributor Author

btecu commented Mar 20, 2019

I talked to @rwjblue about this in person and to add a bit more context, in the application model I load some meta data that is only ever going to be loaded once for the lifetime of the application.

The issue appears when a user is loading say /account which is an authenticated route. In beforeModel (routes/account.js) I check whether the session is authenticated or not. If it's not, I abort the transition and put it in the session service to retry it later once the user authenticates, and finally I do a intermediateTransitionTo('login') to allow the user authenticate.

Somehow this causes the application route model to be not resolved.
The model is actually in the store because the workaround (which has it's own issues) is to do something like:

// https://github.com/emberjs/ember.js/issues/14721
// let application = this.modelFor('application');
let application = this.store.peekAll('application-model').get('firstObject');

@pixelhandler
Copy link
Contributor

@btecu glad you found a work around :)

btecu added a commit to btecu/ember.js that referenced this issue Apr 29, 2019
btecu added a commit to btecu/ember.js that referenced this issue Jun 5, 2021
btecu added a commit to btecu/ember.js that referenced this issue Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants