emberjs / emberjs/ember-render-modifiers

will-destroy does not invoke re-rendering

Open
#18 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
86
Forks
34
PR merge metrics
No merged PRs in 30d

Description

This happened when I tried to write a HOC with a parent passing a function to its child, and the function gets called when the child is inserted and going to be destroyed. I made an integration test to demonstrate the issue.

```javascript
import Component from '@glimmer/component';
import { click, find, render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { action } from '@ember/object';
import hbs from 'htmlbars-inline-precompile';
import { setupRenderingTest } from 'ember-qunit';
import { tracked } from '@glimmer/tracking';

module('Integration | Modifier | will-destroy', hooks => {
setupRenderingTest(hooks);

test('it should invoke UI re-rendering when changing tracked properties', async function(assert) {
this.owner.register(
'component:parent-component',
class extends Component {
@tracked text = '';

get message() {
return this.text;
}

@action changeText(text) {
this.text = text;
}
}
);

this.owner.register(
'template:components/parent-component',
hbs`

{{this.message}}

{{yield (hash changeText=this.changeText)}}
`
);

this.set('show', true);

await render(
hbs`

{{#if show}}



{{/if}}
Change Text

`
);

// did-insert invokes re-rendering correctly, now the message is "Hello".
assert.strictEqual(find('[data-dummy]').innerText, 'Hello');

// trigger destroying. should change text.
this.set('show', false);

// will-destroy does not invoke re-rendering. message supposed to be "World".
assert.strictEqual(find('[data-dummy]').innerText, 'Hello');

await click('[data-button]');
// if the changeText function is called by other ways, it works seamlessly.
assert.strictEqual(find('[data-dummy]').innerText, 'World');
});
});

```

Also attached some dependencies info here.
```json
"devDependencies": {
"@ember/optional-features": "^0.7.0",
"@ember/render-modifiers": "^1.0.2",
"@glimmer/component": "^0.14.0-alpha.13",
"ember-cli": "~3.13.1",
"ember-cli-babel": "^7.7.3",
"ember-source": "~3.13.2"
},

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.