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 report] Dragula service is provided multiple times instead of as a singleton #1082

Open
5 tasks done
RGunning opened this issue Jan 10, 2023 · 3 comments
Open
5 tasks done

Comments

@RGunning
Copy link

RGunning commented Jan 10, 2023

REQUIRED: Before filing a bug report

Change each [ ] to [x] when you have done it.

Describe the bug (required)

With v3 of this library, the DragulaService is provided multiple times instead of just when importing DragulaModule.forRoot().

  1. It is now providedIn: root https://github.com/valor-software/ng2-dragula/pull/1044/files#diff-845f2a393c0ade2f75831cff246267c8b1c96691d81d2d710c47f20eb14ef6d9R31
  2. provided on import of the DragulaModule imports: [DragulaModule] https://github.com/valor-software/ng2-dragula/pull/1044/files#diff-77b8912947381f081ed7f9efbc418716a1dcdfac9c5ebc2d5e6539cad507878fR8
  3. provided on calling DragulaModule.forRoot() imports: [DragulaModule.forRoot()]

As such it is easy to get inject the wrong instance of the DragulaService leading to incorrect behaviour. In my application I have a service (providedIn: Root) that injects the DragulaService. However, because it is providedIn root, since the v3 update it is now getting a different instance of the DragulaService to that injected into the DragulaDirective. As such calls of createGroup made in my root service are being ignored.

*** Expected:
importing DragulaModule does not provide an instance of the DragulaService and instead the DragulaService is either provided by providedIn: root or DragulaModule.forRoot(). My preferred solution would be to remove the forRoot and rely solely on providedIn: root, but this would be a breaking change.

Versions (required)

Please state which versions of the following packages you have installed:

  • @angular/core: 14.2.12
  • ng2-dragula: 3.2.0
@dino-laktasic
Copy link

I can confirm that I run into the same issue and it's definitely BUG. You should either provide DragulaService in root and remove it from providers list in DragulaModule and remove forRoot function or keep forRoot function and remove it from providers list in DragulaModule and remove providedIn from DragulaService service decorator. I tried fixes locally and they were working as expected.

@kunajs
Copy link

kunajs commented Jul 31, 2024

Hi,
I prepared an example which is probably related to the described problem:
https://stackblitz.com/edit/angular-18-ng2-dragula-511

I am dynamically creating the inner components which should use the same dragulaService, but it seems that it is different instance.
Check the console where is logged for each dynamic component and for root component:

  • container name, just for identification
  • groups within injected dragulaService instance (should be always 'wysiwyg')
  • containers (or their css classes) of drake for group called 'wysiwyg'

As you can see, each dynamic component has only containers inside themselves, so it is not connected to each other and to root container.

Compare it with old version where I do the same dynamic loading (just in a bit different way because of angular 9) and in console all the containers are connected. And it is because there is only 1 instance od dragulaService accross the whole project.
https://stackblitz.com/edit/angular-9-ng2-dragula-211

Please, check it. I think the solutions suggested above should resolve this issue.

@kunajs
Copy link

kunajs commented Sep 13, 2024

Are you going to repair it soon?

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

4 participants