Browse Source
* fix(@vben-core/shared): keep filterTree from mutating the source tree filterTree assigned the filtered child array back onto the source node, so nodes that failed the predicate were dropped from the input tree permanently instead of only from the result. In frontend/mixed access mode generateRoutesByFrontend filters the module-level accessRoutes on every login and role refresh, so routes stripped for a low-privilege user stayed missing for later sessions until a full page reload. filterTree is now pure: matched nodes owning a child array are copied, nodes without children are still returned by reference. * docs(@vben-core/shared): correct filterTree reference-semantics comment filterTree does not write its result back into the input tree, but childless matched nodes are still returned by reference. The previous comment claimed no source node is ever returned, which contradicted the implementation and could mislead callers. * fix(@vben-core/shared): preserve branch references in filterTree filterTree copied every matched branch node, so filtering a tree where nothing changed still returned new branch objects. The previous implementation used Array#filter, which keeps element references, so callers could rely on filterTree(input, () => true)[0] === input[0]. Branch nodes are now shallow-copied only when their child sequence actually changes; unchanged nodes are returned by reference, restoring the reference semantics callers had before. The mutation fix itself is unaffected: the filtered child array is never assigned back onto the source node.pull/8383/head
committed by
GitHub
4 changed files with 198 additions and 8 deletions
@ -0,0 +1,11 @@ |
|||
--- |
|||
'@vben-core/shared': patch |
|||
--- |
|||
|
|||
fix(@vben-core/shared): keep filterTree from mutating the source tree |
|||
|
|||
`filterTree` wrote the filtered child array back onto the source node (`node[childProps] = _filterTree(node[childProps])`), so every node that failed the predicate was permanently dropped from the input tree. |
|||
|
|||
That input is a module-level constant in real apps: `generateRoutesByFrontend` filters `accessRoutes` on every login and role refresh. After a low-privilege user signed in, the routes removed for them were gone for every later session in the same page, so an admin would end up with an empty `/dashboard` submenu until a full page reload. |
|||
|
|||
`filterTree` is now pure: matched nodes that own a child array are copied, nodes without children are still returned by reference. |
|||
Loading…
Reference in new issue