Context
Found while shaping #21061: permission-driven navigation filters one Neo.data.TreeStore and lets a Neo.menu.List cascade render it. The menu ignores the filter.
Reproducer (test/playwright/unit/menu/ListTreeStore.spec.mjs fixture: file → (file-new → file-new-f, file-open), edit → edit-copy, about), red on dev @ fbb9c4da19:
- Filter set before the menus exist.
{property: 'text', value: 'Copy'} keeps edit and edit-copy only, yet the root menu lists file, edit, about.
- Filter changed while the menus exist.
{property: 'text', operator: 'included', value: ['New', 'Copy']} leaves the root at file, edit, about and the file level at file-new, file-open.
Note for readers: TreeStore filtering is ancestor-aware. A group that matches a filter itself keeps its whole subtree, so a filter like id !== 'file-open' keeps file-open because file matched. That is intended tree semantics, not this bug. (This body's first version cited exactly that case as a symptom; corrected.)
The Problem
A menu level never consults the tree store's filter mask:
syncLevelRecords() fills a level from TreeStore#getChildren() (src/menu/List.mjs:985-992), which reads the Structural Layer and is documented as independent of filtering (src/data/TreeStore.mjs:750-752).
- A level subscribes to the source store's
mutate, recordChange and sort (src/menu/List.mjs:759-764), not filter, so a filter applied after the menu exists never reaches it.
onSourceStoreMutate() (src/menu/List.mjs:926-943) adds every record that belongs to the level, including ones the active filter hides.
Any app that narrows a menu by data (permissions, feature flags, a search box over a command menu) shows items the store says are gone.
The Architectural Reality
Design authority: #17839, which introduced tree-store menus, states in its Out of Scope that the menu adopts "TreeStore for its structural half (#childrenMap, ancestor-aware filtering)", and menu.List#sourceStore documents "The tree store is the single source of truth and is shared by every level of the cascade" (src/menu/List.mjs:192-199). The levels read the structure but not the filter, so the intent never reached them.
TreeStore#getChildren()'s filter independence is its own contract for structural reads (src/data/TreeStore.mjs:740-766) and stays unchanged; the mask applies at the level. #17839's rejected alternative (each level rendering a filtered subset of the shared store, unsafe for list.Base index math) is not reopened: each level keeps its own flat store and only adopts the tree's mask when deriving it.
TreeStore filtering is ancestor-aware (src/data/TreeStore.mjs:588-713): a node is kept when it matches, when an ancestor matched, or when a descendant matched. _keptNodes holds the mask (null when unfiltered). A level that adopts the mask shows what a tree grid over the store shows at that depth, expansion aside.
The Fix
src/data/TreeStore.mjs: public isKept(nodeOrKey) answers whether the active filters keep a node (record, raw node or key, with the canonical-key fallback get() uses). The internal projection loops (collectVisibleDescendants(), updateSiblingStats()) keep reading the mask directly: they already hold canonical keys on a hot path.
src/menu/List.mjs:
syncLevelRecords() adds only children isKept() keeps.
onConstructed() also subscribes to the source store's filter event (onSourceStoreFilter() re-derives the level, the shape of onSourceStoreSort()); destroy() unsubscribes it symmetrically.
onSourceStoreMutate() skips additions isKept() rejects.
- When a re-derive or a removal takes away the record whose submenu is open, that submenu hides, so no floating level outlives its item.
Contract Ledger
| Surface |
Authority |
Contract / fallback |
Documentation |
Evidence |
TreeStore.isKept(nodeOrKey) |
Existing ancestor-aware filter() mask and Store key resolution |
Record, raw node or key → Boolean; canonical-key fallback; no active mask keeps nodes independently of expansion |
New method JSDoc beside structural getChildren() |
Real TreeStore/menu filter controls |
TreeStore.getChildren(parentId) |
Existing Structural Layer contract |
Still returns all direct children, including filtered-out children; current sibling ordering remains the store's |
Existing method JSDoc |
Structural read assertion under an active filter |
Tree-driven Menu.List levels |
Shared source store; level-owned flat stores |
Adopt the source mask on derive/filter/mutate; hide a cascade whose item leaves; detach the filter listener at destruction; classic items unchanged |
Level derive, event and cleanup methods |
Existing owning spec plus new filter, identity, cascade and teardown controls |
Acceptance Criteria
Out of Scope
- Changing TreeStore's ancestor-aware filter semantics.
- Filtering classic nested-
items submenus (they are built from plain arrays, not from a store).
Related
- Parent: #21061; its permission shell consumes this.
- Origin of tree-store menus: #17839.
Live latest-open + closed sweep: see #21061 (same sweep, 2026-11-15T23:54Z); no equivalent or prior exclusion found.
Origin Session ID: f1b70a0d-406f-4b7d-a69c-20d35c843303
Retrieval Hint: "menu.List TreeStore sourceStore filter syncLevelRecords getChildren isKept"
Context
Found while shaping #21061: permission-driven navigation filters one
Neo.data.TreeStoreand lets aNeo.menu.Listcascade render it. The menu ignores the filter.Reproducer (
test/playwright/unit/menu/ListTreeStore.spec.mjsfixture:file→ (file-new→file-new-f,file-open),edit→edit-copy,about), red ondev@ fbb9c4da19:{property: 'text', value: 'Copy'}keepseditandedit-copyonly, yet the root menu listsfile, edit, about.{property: 'text', operator: 'included', value: ['New', 'Copy']}leaves the root atfile, edit, aboutand thefilelevel atfile-new, file-open.Note for readers: TreeStore filtering is ancestor-aware. A group that matches a filter itself keeps its whole subtree, so a filter like
id !== 'file-open'keepsfile-openbecausefilematched. That is intended tree semantics, not this bug. (This body's first version cited exactly that case as a symptom; corrected.)The Problem
A menu level never consults the tree store's filter mask:
syncLevelRecords()fills a level fromTreeStore#getChildren()(src/menu/List.mjs:985-992), which reads the Structural Layer and is documented as independent of filtering (src/data/TreeStore.mjs:750-752).mutate,recordChangeandsort(src/menu/List.mjs:759-764), notfilter, so a filter applied after the menu exists never reaches it.onSourceStoreMutate()(src/menu/List.mjs:926-943) adds every record that belongs to the level, including ones the active filter hides.Any app that narrows a menu by data (permissions, feature flags, a search box over a command menu) shows items the store says are gone.
The Architectural Reality
Design authority: #17839, which introduced tree-store menus, states in its Out of Scope that the menu adopts "
TreeStorefor its structural half (#childrenMap, ancestor-aware filtering)", andmenu.List#sourceStoredocuments "The tree store is the single source of truth and is shared by every level of the cascade" (src/menu/List.mjs:192-199). The levels read the structure but not the filter, so the intent never reached them.TreeStore#getChildren()'s filter independence is its own contract for structural reads (src/data/TreeStore.mjs:740-766) and stays unchanged; the mask applies at the level. #17839's rejected alternative (each level rendering a filtered subset of the shared store, unsafe forlist.Baseindex math) is not reopened: each level keeps its own flat store and only adopts the tree's mask when deriving it.TreeStore filtering is ancestor-aware (
src/data/TreeStore.mjs:588-713): a node is kept when it matches, when an ancestor matched, or when a descendant matched._keptNodesholds the mask (nullwhen unfiltered). A level that adopts the mask shows what a tree grid over the store shows at that depth, expansion aside.The Fix
src/data/TreeStore.mjs: publicisKept(nodeOrKey)answers whether the active filters keep a node (record, raw node or key, with the canonical-key fallbackget()uses). The internal projection loops (collectVisibleDescendants(),updateSiblingStats()) keep reading the mask directly: they already hold canonical keys on a hot path.src/menu/List.mjs:syncLevelRecords()adds only childrenisKept()keeps.onConstructed()also subscribes to the source store'sfilterevent (onSourceStoreFilter()re-derives the level, the shape ofonSourceStoreSort());destroy()unsubscribes it symmetrically.onSourceStoreMutate()skips additionsisKept()rejects.Contract Ledger
TreeStore.isKept(nodeOrKey)filter()mask and Store key resolutiongetChildren()TreeStore.getChildren(parentId)Menu.ListlevelsAcceptance Criteria
dev, green after.filterlistener on the source store (extends the existing "no listener behind" test intest/playwright/unit/menu/ListTreeStore.spec.mjs).TreeStore#getChildren()still returns filtered-out children; its existing tests stay green.itemsmenus are unchanged (existing classic test stays green).npm run test-unit -- test/playwright/unit/menu test/playwright/unit/datagreen.Out of Scope
itemssubmenus (they are built from plain arrays, not from a store).Related
Live latest-open + closed sweep: see #21061 (same sweep, 2026-11-15T23:54Z); no equivalent or prior exclusion found.
Origin Session ID: f1b70a0d-406f-4b7d-a69c-20d35c843303 Retrieval Hint: "menu.List TreeStore sourceStore filter syncLevelRecords getChildren isKept"