You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PanelMenu#model requires an array of MenuItem elements, but if this array is coming from an immutable source (signalState) the component will not update the state on user interactions, and it will try to mutate the object, which causes a TypeError
I forked the repo, but at the moment can't submit a PR, I sincerely apologize. I will revisit this issue later and will contribute if it is still open.
Hacky Patch
This should be a temporary patch for consumers that are required to use immutable objects
If you cannot change the component and are required to use reactive state, or any other immutable object, you can use this patch
// excerpt from Myservice.tsprivatestate=signalState<TState>({//...other propsmenu: navItems,// default value});readonlyopened=this.state.opened;// readonly menu = this.state.menu; // replace to this once the bug is fixedgetmenu(){returnJSON.parse(JSON.stringify(this.state.menu()));}setmenu(menu: TState['menu']){patchState(this.state,{ menu });}
then in the component
exportclassMyComponent{
#nav =inject(MyService);readonlymenu=this.#nav.menu;//MenuItem[]//...rest of the code}
Why
signalState objects have been frozen recursively, so the only "easy" way to defrost them is to create a new object. Spread operator create shallow copies (won't work)
Important
do not create that getter/setter in the component because signals trigger change detection cycles and that would cause an infinite loop. This is expected to happen in the data layer.
Describe the bug
PanelMenu#model
requires an array ofMenuItem
elements, but if this array is coming from an immutable source (signalState) the component will not update the state on user interactions, and it will try to mutate the object, which causes aTypeError
I forked the repo, but at the moment can't submit a PR, I sincerely apologize. I will revisit this issue later and will contribute if it is still open.
Hacky Patch
If you cannot change the component and are required to use reactive state, or any other immutable object, you can use this patch
then in the component
Why
signalState objects have been frozen recursively, so the only "easy" way to defrost them is to create a new object. Spread operator create shallow copies (won't work)
Important
do not create that getter/setter in the component because signals trigger change detection cycles and that would cause an infinite loop. This is expected to happen in the data layer.
Pull Request Link
No response
Reason for not contributing a PR
Other Reason
No response
Reproducer
https://stackblitz.com/edit/github-tamhkczt
Environment
nx workspace +
angular19 + ngrx/signals@19
Angular version
19.x.x
PrimeNG version
v19
Node version
22.x.x
Browser(s)
Chrome
Steps to reproduce the behavior
TypeError
Expected behavior
When the user clicks the options, the menu should open if it has children
The text was updated successfully, but these errors were encountered: