Skip to content

Commit f90d10a

Browse files
author
Robert Jackson
committed
Refactor Ember.ApplicationInstance destruction.
Update `EmberApp.prototype.visitRoute` to ensure that the `Ember.ApplicationInstance` instance that we create is _always_ `.destroy()`ed (using `try`/`finally`).
1 parent 089baa5 commit f90d10a

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/ember-app.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,20 @@ class EmberApp {
253253
*/
254254
async visitRoute(path, fastbootInfo, bootOptions, result) {
255255
let instance = await this.buildAppInstance();
256-
257256
result.instance = instance;
258-
registerFastBootInfo(fastbootInfo, instance);
259257

260-
await instance.boot(bootOptions);
261-
await instance.visit(path, bootOptions);
262-
await fastbootInfo.deferredPromise;
258+
try {
259+
registerFastBootInfo(fastbootInfo, instance);
260+
261+
await instance.boot(bootOptions);
262+
await instance.visit(path, bootOptions);
263+
await fastbootInfo.deferredPromise;
264+
} finally {
265+
// ensure we invoke `instance.destroy()`, but use
266+
// `result._destroyAppInstance()` so that the `result` object's internal
267+
// `this._instanceDestroyed` flag is correct
268+
result._destroyAppInstance();
269+
}
263270
}
264271

265272
/**
@@ -328,11 +335,7 @@ class EmberApp {
328335
// eslint-disable-next-line require-atomic-updates
329336
result.error = error;
330337
} finally {
331-
if (result._destroyAppInstance()) {
332-
if (destroyAppInstanceTimer) {
333-
clearTimeout(destroyAppInstanceTimer);
334-
}
335-
}
338+
clearTimeout(destroyAppInstanceTimer);
336339
}
337340

338341
return result;

0 commit comments

Comments
 (0)