ember-fastboot / ember-fastboot/ember-cli-head
Question about setting headData from a component
- Dominant language
- JavaScript
- Stars
- 97
- Forks
- 35
- Avg merge
- 3h 3m
- Merged PRs (30d)
- 6
Description
I'm upgrading `ember-cli-head` from 3.x to 4.x and running into a bug caused by the new `{{head-layout}}` component.
In our app we have a component called `` that we use as a declarative interface to setting properties on `headData`.
We use it like this:
```hbs
{{page-info title='About EmberMap' description='Meet Sam and Ryan'}}
```
and it works by setting data on the `headData` service in `didReceiveAttrs`:
```js
// components/page-info.js
export default Component.extend({
headData: service(),
didReceiveAttrs() {
this._super(...arguments);
let props = {
title: this.get('title'),
description: this.get('description'),
...
};
this.get('headData').setProperties(props);
}
});
```
This works in 3.x but in 4.x, we get a double render error:
> Assertion Failed: You modified "model.description" twice on in a single render. It was rendered in "component:head-content" and modified in "component:page-info". This was unreliable and slow in Ember 1.x and is no longer supported. See https://github.com/emberjs/ember.js/issues/13948 for more details.
I think I understand why this error is thrown – `{{head-content}}` has already rendered ``'s content, and then `{{page-info}}` renders, which updates the already-rendered content.
I know typically the fix for this is to set the data before the render, but in this case we actually want this component interface, which means the data wouldn't be known until render-time.
Questions:
1. Why wasn't this a problem in 3.x? Or, was it happening and we just didn't know about it?
2. Is there a "better" way to have our component set data on `headData`?
3. One "fix" for this is to put the call to `setProperties` inside of a `scheduleOnce('afterRender')`, but I'm wondering if there's a better way to solve this problem.
4. Any other recommendations?
Thanks for any help!
Contributor guide
Assessment
This issue has not been assessed yet.