Skip to content

Commit

Permalink
Refactor Ember.ApplicationInstance destruction.
Browse files Browse the repository at this point in the history
Update `EmberApp.prototype.visitRoute` to ensure that the
`Ember.ApplicationInstance` instance that we create is _always_
`.destroy()`ed (using `try`/`finally`).
  • Loading branch information
rwjblue committed Oct 30, 2019
1 parent 089baa5 commit f90d10a
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/ember-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,20 @@ class EmberApp {
*/
async visitRoute(path, fastbootInfo, bootOptions, result) {
let instance = await this.buildAppInstance();

result.instance = instance;
registerFastBootInfo(fastbootInfo, instance);

await instance.boot(bootOptions);
await instance.visit(path, bootOptions);
await fastbootInfo.deferredPromise;
try {
registerFastBootInfo(fastbootInfo, instance);

await instance.boot(bootOptions);
await instance.visit(path, bootOptions);
await fastbootInfo.deferredPromise;
} finally {
// ensure we invoke `instance.destroy()`, but use
// `result._destroyAppInstance()` so that the `result` object's internal
// `this._instanceDestroyed` flag is correct
result._destroyAppInstance();
}
}

/**
Expand Down Expand Up @@ -328,11 +335,7 @@ class EmberApp {
// eslint-disable-next-line require-atomic-updates
result.error = error;
} finally {
if (result._destroyAppInstance()) {
if (destroyAppInstanceTimer) {
clearTimeout(destroyAppInstanceTimer);
}
}
clearTimeout(destroyAppInstanceTimer);
}

return result;
Expand Down

0 comments on commit f90d10a

Please sign in to comment.