NGRX/Store is super difficult to adopt in real projects when Signal is used internally #3903
Replies: 13 comments 19 replies
-
Related: |
Beta Was this translation helpful? Give feedback.
-
Let me drop my opinion on this.
Hope this helps |
Beta Was this translation helpful? Give feedback.
-
The problém Is, angular team came with something marked as "optional" And in "developer preview" And IT breaks 100% working code FOR YEARS WITHOUT ANY problem. And as we can see in all of these issues, they Are not trying to find Real solution, but they are rather going to MARK ALL OF THOSE WORKING SOLUTIONS as "bad practice" And malé them stop working at all. |
Beta Was this translation helpful? Give feedback.
-
This Is 100% legit code with no issues:
And the reality IT throws error Is really not "optional signals" And "non-breaking" developer preview. There Is a problém with hidden effect() from framework side. IT is used somewhere to wrap template even though,.there Is NOT any signál used in template This Is what i am talking about. Signals And their leaky implementation. |
Beta Was this translation helpful? Give feedback.
-
Moving to a discussion as its a duplicate of #3892 |
Beta Was this translation helpful? Give feedback.
-
@montella1507 so you mean the fact that internally the state is stored as a signal? I made a small demo without zero usage of signals and dispatching action via However, your next example mentions setting a signal inside the |
Beta Was this translation helpful? Give feedback.
-
@montella1507 upon further investigation I noticed that your issue really is only reproducible when setting a signal from "inside" of an observable (any observable, not just NgRx). While this is a bug, it doesn't really "force" you to use signals - you can still build with NgRx and Angular without them quite easily; also, this could be avoided by proper rxjs-interop usage (use |
Beta Was this translation helpful? Give feedback.
-
But why are you mutating the state in a selector?? |
Beta Was this translation helpful? Give feedback.
-
The real example behind this is easy. For the instance:
LoadA -> when loaded (data in store) -> dispatch load of child entity based on parent entity data (And set loading state to store). Please do not suggest workarounds... Of course IT could Have been.rewriten in another way.. but IT Will také hundreds of Hours because And ONLY because there Is somewhere unneccessary effect() in angular (even when there is no signal used in template at all) in "optional signals" and signal () Is Now used in store.... |
Beta Was this translation helpful? Give feedback.
-
Signal support won't be dropped in order to support bad practices that worked before. I shared the quick fix in this comment which is pretty straightforward => schedule @Component({
template: 'slice$ | async'
})
export class MyComponent {
private store = inject(Store);
slice$ = this.store.select(selectSlice).pipe(
tap(() => {
- this.store.dispatch(myAction());
+ asapScheduler.schedule(() => this.store.dispatch(myAction()));
})
);
} |
Beta Was this translation helpful? Give feedback.
-
Not sure if you @montella1507 have tried that, using *LetDirective ngrxLet, runtime error is gone, I´m wondering why. (#3892 (comment) thanks @hoi4) I work on a really large application, with tons of obs.pipe(tap(() => this.store.dispatch(someAction))) and the fix that @marko-jobcloud proposed above, it does not feel safe to me, I might be wrong though. EDIT: I´ve updated your Stackblitz sample https://stackblitz.com/edit/angular-ardhq7 |
Beta Was this translation helpful? Give feedback.
-
This may resolve the issue we're seeing with the select/dispatch/async pipe combination. Will try it out after the PR lands |
Beta Was this translation helpful? Give feedback.
-
Angular v16.0.4 has been released, including the fix to resolve the original issue. We've also released NgRx 16.0.1, including the fix for the @ngrx/component package. |
Beta Was this translation helpful? Give feedback.
-
Which @ngrx/* package(s) are the source of the bug?
store
Minimal reproduction of the bug/regression with instructions
I know everyone is super-hyped about signals, the problem is, NGRX/STORE@16 is forcing developers to use signals with all of their disadvantages without actual usage of the signals from developers themselves.
In every second application the developer is doing something like:
this.store.select(a).pipe(
tap(()=> this.store.dispatch(ActionChangingB())
)
Specially when defining observables async pipe is subscribing to.
so it is almost impossible to mirgate to NGRX16 without hundreds of hours invetsed to migration.
You are basically forcing developers to follow signal ideas and their problems.
Minimal reproduction of the bug/regression with instructions
Just modify the state in tap() action...
this.store.select(x => x).pipe(
tap(()=> this.store.dispatch())
);
And Subscribe to this observable in template.
you can find this code in every bigger than demo Angular applicaiton.
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)
Latest NGRX/STORE.
Other information
Please, let the developers decide if they want to use Signals internally.... They ARE NOT "drop-in" replacement.
There could be lot of time spent to mke it working atleast in @effects, with that toggle boolean.. but this is only one place and it is still SO huge amount of work.
I would be willing to submit a PR to fix this issue
Beta Was this translation helpful? Give feedback.
All reactions