Ember.js: Non-Singleton registered dependencies not working as expected for components since Ember 2.10

Created on 14 Dec 2016  路  6Comments  路  Source: emberjs/ember.js

The behaviour for component factory caching is inconsistent between the definitionCache in the GlimmerEnvironment and the factoryCache in the container. The container does not cache factories with dynamic injections, whereas the GlimmerEnvironment does.

// initializers.app-init.js
import Ember from 'ember';
var id = 0;
export function initialize(application) {
  application.register('foo:bar', Ember.Object.extend({
    id: Ember.computed(function() {
      return ++id;
    })
  }), { singleton: false });
  application.inject('component', 'foo', 'foo:bar');
}
export default {
  name: 'app-init',
  initialize
};

// my-component.hbs
id: {{foo.id}}

// templates.application.hbs
{{ my-component }}
{{ my-component }}
{{ my-component }}

In Ember 2.9 the output is:
id: 1
id: 2
id: 3

In Ember 2.10 the output is:
id: 1
id: 1
id: 1

See Ember Twiddle

And failing test

We're refactoring our code that uses this pattern, so don't expect this issue to affect us - this is more an FYI

Bug Regression

Most helpful comment

I work with @adamjmcgrath. I can check it out today

All 6 comments

@chancancode this actually seems like we will need to do something regarding the definitionCache to fix.

looks like fixed in 2.13.*

Can you confirm @adamjmcgrath ?

No sorry, I'm in the middle of the Pacific. Back September :)

I work with @adamjmcgrath. I can check it out today

Sorry for delay.
I can confirm it is working in 2.13.*. The twiddle now behaves as it did in 2.9.
Thanks for letting us know 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

QuantumKing picture QuantumKing  路  33Comments

workmanw picture workmanw  路  79Comments

skoryky picture skoryky  路  50Comments

jdenly picture jdenly  路  31Comments

zidjian257 picture zidjian257  路  30Comments