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
Our team had upgraded to using v16.1.0 and noticed a bug with the ContextMenu. It seems like if the ContextMenu's model property is updated after initially being set, it will only render the items for the first time and never any subsequent changes (ex. Array initializes with items 1,2,3 and is rendered as a Context Menu with items 1,2,3. If Array has item 2 removed and is set to the Context Menu, Context Menu continues rendering with items 1,2,3, not 1,3)
The conditional prevents the _processedItems property from being updated after it's initially processed by that getter since it's only allowed if the _processedItems is an empty array or undefined, and unfortunately, there are no other places in the logic that modifies the _processedItems besides those highlighted lines from above.
Workaround:
Since _processedItems is not private, if you store the ContextMenu as a property using ViewChild then whatever array that is being updated and supplying the ContextMenu could be designed so you can call ContextMenu._processedItems = [] to clear it so it'll for a re-processing.
Solution:
ContextMenu should update the _processedItems whenever the model property has been updated.
Environment
Provided a stackblitz below, but it seems the template won't work until the following issue is resolved #13024.
Describe the bug
Problem
Our team had upgraded to using v16.1.0 and noticed a bug with the ContextMenu. It seems like if the ContextMenu's
model
property is updated after initially being set, it will only render the items for the first time and never any subsequent changes (ex. Array initializes with items 1,2,3 and is rendered as a Context Menu with items 1,2,3. If Array has item 2 removed and is set to the Context Menu, Context Menu continues rendering with items 1,2,3, not 1,3)This seems to be due to the
processedItems
change in the following lines of code:https://github.com/primefaces/primeng/blame/1f1cad11a51afa9093e7285455718d81fd674fe1/src/app/components/contextmenu/contextmenu.ts#L499-L504
The conditional prevents the
_processedItems
property from being updated after it's initially processed by that getter since it's only allowed if the_processedItems
is an empty array or undefined, and unfortunately, there are no other places in the logic that modifies the_processedItems
besides those highlighted lines from above.Workaround:
Since
_processedItems
is not private, if you store the ContextMenu as a property usingViewChild
then whatever array that is being updated and supplying the ContextMenu could be designed so you can callContextMenu._processedItems = []
to clear it so it'll for a re-processing.Solution:
ContextMenu should update the
_processedItems
whenever themodel
property has been updated.Environment
Provided a stackblitz below, but it seems the template won't work until the following issue is resolved #13024.
Reproducer
https://stackblitz.com/edit/github-anvazm
Angular version
16.1.8
PrimeNG version
16.1.0
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
v18.15.0
Browser(s)
Chrome
Steps to reproduce the behavior
Expected behavior
Expected the contents of the ContextMenu to change when the
model
property has been provided new or updated lists.The text was updated successfully, but these errors were encountered: