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]: Injecting Actions and piping into other dispatches in a @State constructor causes Angular 19 ssr vite to crash during page load #2281

Open
kewur opened this issue Dec 19, 2024 · 1 comment

Comments

@kewur
Copy link

kewur commented Dec 19, 2024

Affected Package

The issue is caused by package @ngxs/store

Is this a regression?

Yes.

This works with angular version 18, not with 19.

Issue does not happen on Angular 18. Happens on Angular 19. Forcing a previous ngxs package does not resolve this issue. Seems like something within Angular changing is causing it.

Description

Injecting the Actions action stream into a state and using it to pipe actions causes the following error, crashing the "ng serve" instance. The error below is what I'm getting in my real project. I will include the exception that's being thrown from the reproduction repo below

~/projectpath/vite/deps_ssr/chunk-GQAMDO2A.js:629
      throw error;
      ^

RuntimeError: NG0205: Injector has already been destroyed.
    at assertNotDestroyed (/home/projectpath/.angular/cache/19.0.6/myproject-web/vite/deps_ssr/chunk-QDCVPNZZ.js:2205:11)
    at Module.runInInjectionContext (/home/projectpath/.angular/cache/19.0.6/myproject-web/vite/deps_ssr/chunk-QDCVPNZZ.js:2237:5)
    at eval (/home/projectpath/.angular/cache/19.0.6/myproject-web/vite/deps_ssr/chunk-GQAMDO2A.js:789:10)
    at _InternalDispatcher.dispatchSingle (/home/projectpath/.angular/cache/19.0.6/myproject-web/vite/deps_ssr/chunk-GQAMDO2A.js:746:8)
    at _InternalDispatcher.dispatchByEvents (/home/projectpath/.angular/cache/19.0.6/myproject-web/vite/deps_ssr/chunk-GQAMDO2A.js:721:19)
    at eval (/home/projectpath/.angular/cache/19.0.6/myproject-web/vite/deps_ssr/chunk-GQAMDO2A.js:713:65)
    at _NoopNgxsExecutionStrategy.enter (/home/projectpath/.angular/cache/19.0.6/myproject-web/vite/deps_ssr/chunk-GQAMDO2A.js:325:12)
    at _InternalNgxsExecutionStrategy.enter (/home/projectpath/.angular/cache/19.0.6/myproject-web/vite/deps_ssr/chunk-GQAMDO2A.js:465:36)
    at _InternalDispatcher.dispatch (/home/projectpath/.angular/cache/19.0.6/myproject-web/vite/deps_ssr/chunk-GQAMDO2A.js:713:48)
    at Object.dispatch (/home/projectpath/.angular/cache/19.0.6/myproject-web/vite/deps_ssr/chunk-GQAMDO2A.js:870:55) {
  code: 205
}

Node.js v20.18.1

🔬 Minimal Reproduction

https://github.com/kewur/ngxs-ssr-actions-dispatch-bug

🔥 Exception or Error


9:33:16 AM [vite] Internal server error: Cannot read properties of undefined (reading 'type')
      at eval (/home/kewur/workspace/ngxs-bug/.angular/cache/19.0.6/ngxs-ssr-bug/vite/deps_ssr/chunk-CE73NRQK.js:2167:27)
      at Module.__decorate (/home/kewur/workspace/ngxs-bug/.angular/cache/19.0.6/ngxs-ssr-bug/vite/deps_ssr/tslib.js:44:108)
      at eval (/home/kewur/workspace/ngxs-bug/src/app/state.ts:66:10)
      at async instantiateModule (file:///home/kewur/workspace/ngxs-bug/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:52972:5) (x3)

Environment


Libs:
- @angular/core version: ^19.0.5
- @ngxs/store version: 19.0.0



Only happens on the most recent version of Angular (19+, does not happen with 18)

Browser:
- [X] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [X] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 18.19.1  
- Platform:  Linux

@kewur kewur changed the title 🐞[BUG]: Injecting Actions in a @State constructor causes anguler 19 ssr vite to crash during page load 🐞[BUG]: Injecting Actions in a @State constructor causes Angular 19 ssr vite to crash during page load Dec 19, 2024
@kewur kewur changed the title 🐞[BUG]: Injecting Actions in a @State constructor causes Angular 19 ssr vite to crash during page load 🐞[BUG]: Injecting Actions and piping into other dispatches in a @State constructor causes Angular 19 ssr vite to crash during page load Dec 19, 2024
@arturovt
Copy link
Member

First of all, what I noticed is that there's a circular dependency between your modules. Actions should always be in a separate file. When I move the actions from the state file to actions.ts, it renders successfully:

image


image

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

No branches or pull requests

2 participants