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

[Bug] String injection with instantiate: false no longer works on ember 3.27.0 #19532

Closed
romgere opened this issue May 6, 2021 · 6 comments
Closed

Comments

@romgere
Copy link
Contributor

romgere commented May 6, 2021

🐞 Describe the Bug

Injecting a string via dependency injection raise an error.

🔬 Minimal Reproduction

Minimal reproduction on fresh app : https://github.com/romgere/test-ember-string-injection

To sum-up
Try to inject a string into a service with an initializer :

// initializer.js
export function initialize(application) {
  application.register('config:a-string', 'My great injected string', {
    instantiate: false,
  });

  application.inject(
    'service:test-injection',
    'injectedString',
    'config:a-string'
  );
}

export default {
  initialize,
};
// service.js
import Service from '@ember/service';

export default class TestInjectionService extends Service {
  injectedString = null; // injected by initializer
}

😕 Actual Behavior

When trying to use the service property got the following error :

Uncaught TypeError: Cannot create property 'Symbol(INIT_FACTORY)' on string 'My great injected string'

🤔 Expected Behavior

The property is setted with injected string.

🌍 Environment

  • Ember: 3.27.0
  • Node.js/npm: v12.20.2 (npm v6.14.11)
  • OS: ubuntu
  • Browser: chrome

➕ Additional Context

Related to what is done in https://github.com/yapplabs/ember-modal-dialog, see yapplabs/ember-modal-dialog#320.

@lifeart
Copy link
Contributor

lifeart commented May 6, 2021

as workaround,

 application.register('config:a-string', { toString() => 'My great injected string' }, {
    instantiate: false,
  });

may work

@makepanic
Copy link
Contributor

The mentioned workaround fixes the issue in modal-dialog for me

@CvX
Copy link
Contributor

CvX commented May 14, 2021

The same issue affects ember-model-validator.

@andsmedeiros
Copy link

I have the same issue with 3.28.0, but while trying to inject some numeric constants in components.
Cannot create property 'Symbol(INIT_FACTORY)' on number '6.375'

@lifeart
Copy link
Contributor

lifeart commented Sep 23, 2021

@andsmedeiros your case will be:

 application.register('config:a-number', { [Symbol.toPrimitive]() { return 42 } }, {
    instantiate: false,
  });

@andsmedeiros
Copy link

Thanks @lifeart, this does the trick.

@locks locks closed this as not planned Won't fix, can't repro, duplicate, stale Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants