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 release] Ensure user lifecycle hooks are untracked #19193

Merged
merged 1 commit into from
Oct 13, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ export default class CurlyComponentManager
component._transitionTo('hasElement');

if (environment.isInteractive) {
beginUntrackFrame();
component.trigger('willInsertElement');
endUntrackFrame();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { clearElementView, clearViewElement, getViewElement } from '@ember/-inte
import { CapturedNamedArguments } from '@glimmer/interfaces';
import { createConstRef, Reference } from '@glimmer/reference';
import { registerDestructor } from '@glimmer/runtime';
import { Revision, Tag, valueForTag } from '@glimmer/validator';
import { beginUntrackFrame, endUntrackFrame, Revision, Tag, valueForTag } from '@glimmer/validator';
import { EmberVMEnvironment } from '../environment';
import { Renderer } from '../renderer';
import { Factory as TemplateFactory, OwnedTemplate } from '../template';
Expand Down Expand Up @@ -64,8 +64,10 @@ export default class ComponentStateBucket {
let { component, environment } = this;

if (environment.isInteractive) {
beginUntrackFrame();
component.trigger('willDestroyElement');
component.trigger('willClearRender');
endUntrackFrame();

let element = getViewElement(component);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

import { run } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';
import { alias, set, get, observer, on, computed } from '@ember/-internals/metal';
import { alias, set, get, observer, on, computed, tracked } from '@ember/-internals/metal';
import Service, { inject as injectService } from '@ember/service';
import { Object as EmberObject, A as emberA } from '@ember/-internals/runtime';
import { jQueryDisabled } from '@ember/-internals/views';
Expand Down Expand Up @@ -3732,6 +3732,75 @@ moduleFor(

this.assertComponentElement(this.firstChild, { content: 'hello' });
}

'@test lifecycle hooks are not tracked'() {
this.registerComponent('foo-bar', {
ComponentClass: class extends Component {
@tracked foo;

willInsertElement() {
this.foo;
this.foo = 123;
}

willRender() {
this.foo;
this.foo = 123;
}

didRender() {
this.foo;
this.foo = 123;
}

didReceiveAttrs() {
this.foo;
this.foo = 123;
}

didUpdate() {
this.foo;
this.foo = 123;
}

didUpdateAttrs() {
this.foo;
this.foo = 123;
}

didInsertElement() {
this.foo;
this.foo = 123;
}

willClearRender() {
this.foo;
this.foo = 123;
}

willDestroyElement() {
this.foo;
this.foo = 123;
}

didDestroyElement() {
this.foo;
this.foo = 123;
}
},
template: '{{this.baz}}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dumb question when reading the diff, should it be {{this.foo}}?

});

this.render('{{#if cond}}{{foo-bar baz=this.value}}{{/if}}', { cond: true, value: 'hello' });

this.assertComponentElement(this.firstChild, { content: 'hello' });

runTask(() => set(this.context, 'value', 'world'));

this.assertComponentElement(this.firstChild, { content: 'world' });

runTask(() => set(this.context, 'cond', false));
}
}
);

Expand Down