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] Avoid run.next in app.visit resolve handler. #14591

Merged
merged 1 commit into from
Nov 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions packages/ember-application/lib/system/application-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,22 +239,31 @@ const ApplicationInstance = EngineInstance.extend({
visit(url) {
this.setupRouter();

let bootOptions = this.__container__.lookup('-environment:main');

let router = get(this, 'router');

let handleResolve = () => {
// Resolve only after rendering is complete
return new RSVP.Promise((resolve) => {
// TODO: why is this necessary? Shouldn't 'actions' queue be enough?
// Also, aren't proimses supposed to be async anyway?
run.next(null, resolve, this);
});
let handleTransitionResolve = () => {
if (!bootOptions.options.shouldRender) {
// No rendering is needed, and routing has completed, simply return.
return this;
} else {
return new RSVP.Promise((resolve) => {
// Resolve once rendering is completed. `router.handleURL` returns the transition (as a thennable)
// which resolves once the transition is completed, but the transition completion only queues up
// a scheduled revalidation (into the `render` queue) in the Renderer.
//
// This uses `run.schedule('afterRender', ....)` to resolve after that rendering has completed.
run.schedule('afterRender', null, resolve, this);
});
}
};

let handleReject = (error) => {
let handleTransitionReject = (error) => {
if (error.error) {
throw error.error;
} else if (error.name === 'TransitionAborted' && router.router.activeTransition) {
return router.router.activeTransition.then(handleResolve, handleReject);
return router.router.activeTransition.then(handleTransitionResolve, handleTransitionReject);
} else if (error.name === 'TransitionAborted') {
throw new Error(error.message);
} else {
Expand All @@ -268,7 +277,7 @@ const ApplicationInstance = EngineInstance.extend({
location.setURL(url);

// getURL returns the set url with the rootURL stripped off
return router.handleURL(location.getURL()).then(handleResolve, handleReject);
return router.handleURL(location.getURL()).then(handleTransitionResolve, handleTransitionReject);
}
});

Expand Down