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 rerendering outlet state during router destruction. #14123

Merged
merged 1 commit into from
Aug 24, 2016
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ const EmberRouter = EmberObject.extend(Evented, {
this._engineInstances = new EmptyObject();
this._engineInfoByRoute = new EmptyObject();
}

// avoid shaping issues with checks during `_setOutlets`
this.isDestroyed = false;
this.isDestroying = false;
},

/*
Expand Down Expand Up @@ -266,6 +270,11 @@ const EmberRouter = EmberObject.extend(Evented, {
},

_setOutlets() {
// This is triggered async during Ember.Route#willDestroy.
// If the router is also being destroyed we do not want to
// to create another this._toplevelView (and leak the renderer)
if (this.isDestroying || this.isDestroyed) { return; }

let handlerInfos = this.router.currentHandlerInfos;
let route;
let defaultParentState;
Expand Down
28 changes: 28 additions & 0 deletions packages/ember/tests/application_lifecycle_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,34 @@ QUnit.test('Destroying the application resets the router before the appInstance
equal(controllerFor(appInstance, 'application').get('selectedMenuItem'), null);
});

QUnit.test('Destroying a route after the router does create an undestroyed `toplevelView`', function() {
App.Router.map(function() {
this.route('home', { path: '/' });
});

setTemplates({
index: compile('Index!'),
application: compile('Application! {{outlet}}')
});

App.IndexRoute = Route.extend();
run(App, 'advanceReadiness');

handleURL('/');

let router = appInstance.lookup('router:main');
let route = appInstance.lookup('route:index');

run(router, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was cleared');

run(route, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was not reinitialized');

run(App, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was not reinitialized');
});

QUnit.test('initializers can augment an applications customEvents hash', function(assert) {
assert.expect(1);

Expand Down
44 changes: 44 additions & 0 deletions packages/ember/tests/routing/basic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3742,4 +3742,48 @@ if (isEnabled('ember-application-engines')) {

throws(() => router.transitionTo('blog.post'), /Defining a custom serialize method on an Engine route is not supported/);
});

QUnit.test('App.destroy does not leave undestroyed views after clearing engines', function() {
expect(4);

let engineInstance;
// Register engine
let BlogEngine = Engine.extend();
registry.register('engine:blog', BlogEngine);
let EngineIndexRoute = Route.extend({
init() {
this._super(...arguments);
engineInstance = getOwner(this);
}
});

// Register engine route map
let BlogMap = function() {
this.route('post');
};
registry.register('route-map:blog', BlogMap);

Router.map(function() {
this.mount('blog');
});

bootApplication();

let engine = container.lookup('engine:blog');
engine.register('route:index', EngineIndexRoute);
engine.register('template:index', compile('Engine Post!'));

handleURL('/blog');

let route = engineInstance.lookup('route:index');

run(router, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was cleared');

run(route, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was not reinitialized');

run(App, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was not reinitialized');
});
}