TypeError: stateSource[STATE_SOURCE].update is not a function in NgRx Signals #4511
-
DescriptionI'm encountering an issue when attempting to patch the state using NgRx Signals. The error message I'm receiving is:
The error is pointing to the patchState function, specifically at the following line: function patchState(stateSource, ...updaters) {
stateSource[STATE_SOURCE].update(currentState => updaters.reduce((nextState, updater) => ({
...nextState,
...(typeof updater === ‘function’ ? updater(nextState) : updater)
}), currentState));
notifyWatchers(stateSource);
} Below are two screenshots, showing the difference between a successful and unsuccessful patchState (Please note that in the former, there is no Context
Any insights into what might be causing this error or suggestions for how to resolve it would be greatly appreciated! Thank you for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
My first guess is that you updated to 18.0.0 without running It would be extremely helpful, if you also provide the lines of code where you run |
Beta Was this translation helpful? Give feedback.
-
Uff, that's a lot of code. Try to unset the protectedState like this: export const GroupRatingStore = signalStore(
{ providedIn: 'root', protectedState: false },
withEntitiesAndDBMethods<GroupRating>('groupRatings'),
); If everything works, you tried to patch outside of the SignalStore which is disabled since the stable release: https://dev.to/ngrx/announcing-ngrx-signals-v18-state-encapsulation-private-store-members-enhanced-entity-management-and-more-2lo6 You can leave your If there are still some uncertainties, would it be possible to come up with a reproducible example on StackBlitz? https://stackblitz.com/github/ngrx/signal-store-starter?file=src%2Fmain.ts |
Beta Was this translation helpful? Give feedback.
Uff, that's a lot of code. Try to unset the protectedState like this:
If everything works, you tried to patch outside of the SignalStore which is disabled since the stable release: https://dev.to/ngrx/announcing-ngrx-signals-v18-state-encapsulation-private-store-members-enhanced-entity-management-and-more-2lo6
You can leave your
GroupRatingStore
state unprotected, but we recommend that every state update, i.e., callingpatchState
, happens inside the SignalStore. That might require some refactoring on your side.If there are still some un…