emberjs / emberjs/ember.js

[Bug] Multiple service instances based on invocation syntax

Open
#19,794 3 comments 0 reactions 0 assignees View on GitHub
documentation
Dominant language
TypeScript
Stars
22.6k
Forks
4.2k
Avg merge
3d 12h
Merged PRs (30d)
15

Description

### 🐞 Describe the Bug
Varying service syntaxes can result in separate services rather than one shared service. This came up in an app where an addon component invoked a service from the addon in one way and the app invoked the service in another way. It doesn't seem like the app should need to know how the addon service is invoked in order to function properly.

The various invocations I tested were:
1. @service() - relying on the variable name matching the service name
2. @service('\')
3. @service('$\') - this syntax comes from the ember-holy-futuristic-template-namespacing-batman package
4. @service('@\')

1/2 create one shared instance of a service and 3/4 create a separate shared instance of a service.

### 🔬 Minimal Reproduction
There's a minimal reproduction of this at https://github.com/tcwood/ember-service-repro

It creates a service and then 4 components that use the service with the syntaxes listed above. It creates table cells containing buttons to interact with the service and the value coming from the service for each component. A console.log is also placed in the service's constructor to show how many times it is being instantiated.

### 😕 Actual Behavior
Separate services are created by varying syntaxes. The gif below shows sample usage of the reproduction app.

![service](https://user-images.githubusercontent.com/18245502/138002247-e713b498-3c21-475a-8226-b60386d9807f.gif)

### 🤔 Expected Behavior
Only one service is created regardless of the syntax used. In the gif above that would result in all of the right side values always being synced.

### 🌍 Environment

- Ember: - 3.18.0 (in the repro app), 3.26.2 in the app where I noticed this
- Node.js/npm: - 6.14.10
- OS: - osx
- Browser: - chrome

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.