-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 release] don’t leak last destroyedComponents #14987
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ export default class Environment extends GlimmerEnvironment { | |
this.isInteractive = owner.lookup('-environment:main').isInteractive; | ||
|
||
// can be removed once https://github.com/tildeio/glimmer/pull/305 lands | ||
this.destroyedComponents = undefined; | ||
this.destroyedComponents = []; | ||
|
||
installPlatformSpecificProtocolForURL(this); | ||
|
||
|
@@ -275,16 +275,16 @@ export default class Environment extends GlimmerEnvironment { | |
this.inTransaction = true; | ||
|
||
super.begin(); | ||
|
||
this.destroyedComponents = []; | ||
} | ||
|
||
commit() { | ||
let destroyedComponents = this.destroyedComponents; | ||
this.destroyedComponents = []; | ||
// components queued for destruction must be destroyed before firing | ||
// `didCreate` to prevent errors when removing and adding a component | ||
// with the same name (would throw an error when added to view registry) | ||
for (let i = 0; i < this.destroyedComponents.length; i++) { | ||
this.destroyedComponents[i].destroy(); | ||
for (let i = 0; i < destroyedComponents.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you want to cache length here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tell me more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol stop messing with the old guy... |
||
destroyedComponents[i].destroy(); | ||
} | ||
|
||
super.commit(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { set } from 'ember-metal'; | ||
import { Component } from '../../utils/helpers'; | ||
import { moduleFor, RenderingTest } from '../../utils/test-case'; | ||
|
||
moduleFor('Component destroy', class extends RenderingTest { | ||
['@test it correctly releases the destroyed components'](assert) { | ||
let FooBarComponent = Component.extend({}); | ||
|
||
this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); | ||
|
||
this.render('{{#if switch}}{{#foo-bar}}{{foo-bar}}{{/foo-bar}}{{/if}}', { switch: true }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. foobar inception... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
this.assertComponentElement(this.firstChild, { content: 'hello' }); | ||
|
||
this.runTask(() => set(this.context, 'switch', false)); | ||
|
||
this.assertText(''); | ||
|
||
assert.equal(this.env.destroyedComponents.length, 0, 'enviroment.destroyedComponents should be empty'); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do this assignment here. Why not just reassign to an empty array after the subsequent loop? More of a stylistic thing I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the loop fails (
destroy
could throw), we still want to release the contents of the originaldestroyedComponents
. So this way, we ensure they are released before we invoke any further code.