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]: Actions triggered Twice #2277

Closed
Squixx opened this issue Dec 5, 2024 · 4 comments · Fixed by #2278
Closed

🐞[BUG]: Actions triggered Twice #2277

Squixx opened this issue Dec 5, 2024 · 4 comments · Fixed by #2278

Comments

@Squixx
Copy link

Squixx commented Dec 5, 2024

Affected Package

@ngxs/store 18.1.6

Is this a regression?

Yes, this was working fine on 18.1.5

Description

When I update to 18.1.6 within our repo all my actions seem to be triggered twice. When debbugging i can see the dispatch function is only called once, but the action method executes twice. (if the first action within the action is a console log i'll also see this in my logs

🔬 Minimal Reproduction

I haven't yet been able to reproduce this outside of our repo. But one thing to note is: it is still module based. We're using (lazy loaded) for feature modules, and it happens both when using provideStore([state]) and ngxsmodule.forRoot([state]), forFeature() or provideStates([])

If i can provide a smaller reproduction I'll update this.

Environment


Libs:
    "@angular/animations": "18.2.13",
    "@angular/cdk": "18.2.14",
    "@angular/cdk-experimental": "18.2.14",
    "@angular/common": "18.2.13",
    "@angular/compiler": "18.2.13",
    "@angular/core": "18.2.13",
    "@angular/elements": "18.2.13",
    "@angular/forms": "18.2.13",
    "@angular/material": "18.2.14",
    "@angular/platform-browser": "18.2.13",
    "@angular/platform-browser-dynamic": "18.2.13",
    "@angular/router": "18.2.13",
    "@angular/service-worker": "18.2.13",

    "@ngxs/devtools-plugin": "18.1.6",
    "@ngxs/form-plugin": "18.1.6",
    "@ngxs/logger-plugin": "18.1.6",
    "@ngxs/router-plugin": "18.1.6",
    "@ngxs/storage-plugin": "18.1.6",
    "@ngxs/store": "18.1.6",
@markwhitfeld
Copy link
Member

@Squixx The only think I can think is that you are possibly adding a state twice and therefore the handlers are being registered twice.
If this is the case, then it is definitely something we should guard against, but also something that you can fix in your app by making sure that the state is added only once.

@Squixx
Copy link
Author

Squixx commented Dec 9, 2024

@markwhitfeld you are 100% right, there was a provideStore() implementation somewhere hidden in a submodule.

However this was working correctly on 18.1.5 (we've been running like this for +3 months).

I guess it's not as much 'broken' per se, but it is really unintuitive.

If you were to do something about this, my opinion would be that it should break when adding the state twice, but actually throwing somewhere so you'll have some way of pinpointing the error.

Thanks for your pointer, would have taken me a way longer time to find this otherwise.

@bonnie-gaggle
Copy link

In case it helps for others searching for similar issues, we were seeing this behavior because we were using provideStore rather than provideStates in our routes.

@arturovt arturovt linked a pull request Dec 17, 2024 that will close this issue
@Gillesf31
Copy link

Thanks for this issue and answers !

We had the same problem, we used a forRoot (we should migrate to provideStore and provideStates) on a feature and some actions were dispatched twice since 18.1.16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants