Skip to content

Instantly share code, notes, and snippets.

@MichalBryxi
Last active August 12, 2016 09:19
Show Gist options
  • Save MichalBryxi/1456540706206c715aed31726dd12629 to your computer and use it in GitHub Desktop.
Save MichalBryxi/1456540706206c715aed31726dd12629 to your computer and use it in GitHub Desktop.
PE-16253

PE-16253

Problem:

Uncaught Error: You modified ShouldDisplay(dependencyCycles) twice in a single render. This was unreliable in Ember 1.x and will be removed in Ember 3.0

Upstream discussion:

Possible causes:

  1. In init, didInitAttrs, didReceiveAttrs, willInsertElement or willRender your code calls something that affects already rendered part of template

Live demo:

Possible fixes:

  1. Move your code from willInsertElement to didInsertElement, etc...
  • Maybe this introduces flickering?
  • Causes A property of X was modified inside the didInsertElement hook. You should never change properties on components, services or models during didInsertElement because it causes significant performance degradation.
  1. Do not write code that changes itself on initial render. If you want to send action during inital render, there should be way to rewrite the code to be computed property.
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
export default Ember.Component.extend({
willInsertElement: function () {
console.log('willInsertElement of my-foo is called and fires action to it\'s parent');
this.sendAction('hideIt');
}
// Causes: A property of X was modified inside the didInsertElement hook. You should never change properties on components, services or models during didInsertElement because it causes significant performance degradation.
// didInsertElement: function () {
// console.log('didInsertElement of my-foo is called and fires action to it\'s parent');
// this.sendAction('hideIt');
// }
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
isBarVisible: true,
actions: {
hideBar: function () {
console.log('Parent gets the action and hides my-bar');
this.set('isBarVisible', false);
}
}
});
<h1>Welcome to {{appName}}</h1>
{{log "In our template, we have my-bar rendered first"}}
{{#if isBarVisible}}
{{log "At first my-bar is visible"}}
{{my-bar}}
{{/if}}
{{log "Then we want to render my-foo"}}
{{my-foo hideIt=(action "hideBar")}}
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "1.13.13",
"ember-data": "2.7.0",
"ember-template-compiler": "1.13.13"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment