Context
Neo.selection.grid.BaseModel#applyCellSelection writes a selection model's answer for one cell onto the cell's vdom node. Its summary promises: "It withdraws only what it put on the node." But it records every class it wanted, including one the cell already carried, so a deselect removes that class too.
Found in the review of PR #20701 (comment 6759192652). Measured on dev 05390906ea on 2026-11-14 with a throwaway unit spec; both arms below fail.
The Problem
- Direct call. Take a cell node
{cls: ['neo-grid-cell', 'neo-selected']} and a model whose isSelectedCell() answers true, then false. After the second applyCellSelection() the node reads ['neo-grid-cell']: the neo-selected it carried before the selection is gone.
- Through a grid. Take a model that selects cells by a rule (the
RectangleModel of test/playwright/unit/grid/CellSelectionByRule.spec.mjs), configured with selectedColumns: ['col2'] and no selectedColumnCellCls. grid.Row paints every col2 cell with its fallback class neo-selected (src/grid/Row.mjs:281). Clearing the rule's rectangle (rows 1–2, col2 and col3) strips neo-selected from the col2 cells of records 1 and 2, while selectedColumns still reads ['col2']. Rendered col2 cells, recordId:hasClass, before: 0:true 1:true 2:true 3:true …; after: 0:true 1:false 2:false 3:true ….
The shipped CellColumnModel and CellColumnRowModel set selectedColumnCellCls: 'selected-column-cell', so they do not collide today. Two cases do collide: a model in an outside package that selects cells and columns, and a column whose cellCls adds a class the model also returns from getCellCls().
The Architectural Reality
src/selection/grid/BaseModel.mjs:112 applyCellSelection(cell, record, dataField): for a selected cell, cls = [selectedCls, ...getCellCls()]; then NeoArray.add(cell.cls, cls) and #cellCls.set(cell, cls). The next call runs NeoArray.remove(cell.cls, applied) with that whole list.
#cellCls (:70) is a WeakMap keyed by the cell's vdom node.
- Callers:
grid.Row calls it for every cell it renders (src/grid/Row.mjs:310), after the row has put its own classes on the node, such as column.cellCls and the selected-column class.
- The granular repaints
updateBodyCells (:268) and updateRenderedCells (:776) revisit the existing node.
- The early return compares what was wanted last time with what is wanted now (
Neo.isEqual(applied, cls)), so the record must keep what was wanted as well as what was added.
Design authority: the method's summary, "It withdraws only what it put on the node.", and the #cellCls JSDoc, "The classes {@link #applyCellSelection} put on each cell vdom node, so a repaint withdraws exactly those."
The Fix
In applyCellSelection, record what it added beside what it wanted:
- add only the wanted classes the node does not carry yet:
added = cls.filter(item => !cell.cls.includes(item));
- store
{added, cls} in #cellCls;
- compare
applied.cls with cls for the early return, and remove applied.added (not the wanted list) before it re-applies or on deselect.
Update the #cellCls JSDoc to name both lists.
A maintainer tried this change locally and reverted it:
- both arms above pass;
- a repeat call on an unchanged answer still returns
false;
test/playwright/unit/grid and test/playwright/unit/selection stay green, apart from one load-timing failure (AnimateRowsSteps.spec.mjs:184) that passes 24 of 24 when run alone, with and without the change.
Acceptance Criteria
Out of Scope
aria-selected on a node that carried it before its selection (no renderer sets it on cells today).
- The
neo-selected fallback for selected columns in grid.Row.
- Row selection (
updateBodyRows), which toggles selectedCls on the row node.
Avoided Traps
- Storing only the added list. The early return would then compare the added list with the wanted list. They differ whenever the cell carried a class, so every repaint would report a change and update the row.
- Skipping the remove when a class was already there. The wanted list can shrink (
getCellCls() stops returning a class), and that class must still leave the cell.
Related
- Parent: #20667 (a package's own selection model builds on this method's contract).
- PR #20701, where the review found it.
test/playwright/unit/grid/CellSelectionByRule.spec.mjs: the rig for the grid arm.
Live latest-open + closed sweep: checked latest 20 open + open and closed search (applyCellSelection selection class cell; the closed hit #20698 introduced the method's contract, and the review of its PR found this defect) at 2026-11-14T23:59Z; no equivalent or prior exclusion found. Backlog: 46 open (orange); the owner is #20667, which this joins as a sub.
A2A sweep: the last 30 lane-claims up to 23:24Z; none on cell selection.
MC sweep: "a cell's selected class is stripped on deselect even though the cell carried it before the selection", 5 results; no decision on it.
Own-assignment sweep: 2 open (#20925, #20667); #20667 is the parent.
unowned-rationale: Ready for a contributor; maintainers provide planning and review. The filer reviews the PR it draws.
Origin Session ID: 0f917040-8b12-4dc3-9a7d-69961f23226d
Retrieval Hint: "applyCellSelection withdraws a class the cell already carried"
Context
Neo.selection.grid.BaseModel#applyCellSelectionwrites a selection model's answer for one cell onto the cell's vdom node. Its summary promises: "It withdraws only what it put on the node." But it records every class it wanted, including one the cell already carried, so a deselect removes that class too.Found in the review of PR #20701 (comment 6759192652). Measured on
dev05390906eaon 2026-11-14 with a throwaway unit spec; both arms below fail.The Problem
{cls: ['neo-grid-cell', 'neo-selected']}and a model whoseisSelectedCell()answerstrue, thenfalse. After the secondapplyCellSelection()the node reads['neo-grid-cell']: theneo-selectedit carried before the selection is gone.RectangleModeloftest/playwright/unit/grid/CellSelectionByRule.spec.mjs), configured withselectedColumns: ['col2']and noselectedColumnCellCls.grid.Rowpaints everycol2cell with its fallback classneo-selected(src/grid/Row.mjs:281). Clearing the rule's rectangle (rows 1–2,col2andcol3) stripsneo-selectedfrom thecol2cells of records 1 and 2, whileselectedColumnsstill reads['col2']. Renderedcol2cells,recordId:hasClass, before:0:true 1:true 2:true 3:true …; after:0:true 1:false 2:false 3:true ….The shipped
CellColumnModelandCellColumnRowModelsetselectedColumnCellCls: 'selected-column-cell', so they do not collide today. Two cases do collide: a model in an outside package that selects cells and columns, and a column whosecellClsadds a class the model also returns fromgetCellCls().The Architectural Reality
src/selection/grid/BaseModel.mjs:112applyCellSelection(cell, record, dataField): for a selected cell,cls = [selectedCls, ...getCellCls()]; thenNeoArray.add(cell.cls, cls)and#cellCls.set(cell, cls). The next call runsNeoArray.remove(cell.cls, applied)with that whole list.#cellCls(:70) is aWeakMapkeyed by the cell's vdom node.grid.Rowcalls it for every cell it renders (src/grid/Row.mjs:310), after the row has put its own classes on the node, such ascolumn.cellClsand the selected-column class.updateBodyCells(:268) andupdateRenderedCells(:776) revisit the existing node.Neo.isEqual(applied, cls)), so the record must keep what was wanted as well as what was added.Design authority: the method's summary, "It withdraws only what it put on the node.", and the
#cellClsJSDoc, "The classes {@link #applyCellSelection} put on each cell vdom node, so a repaint withdraws exactly those."The Fix
In
applyCellSelection, record what it added beside what it wanted:added = cls.filter(item => !cell.cls.includes(item));{added, cls}in#cellCls;applied.clswithclsfor the early return, and removeapplied.added(not the wanted list) before it re-applies or on deselect.Update the
#cellClsJSDoc to name both lists.A maintainer tried this change locally and reverted it:
false;test/playwright/unit/gridandtest/playwright/unit/selectionstay green, apart from one load-timing failure (AnimateRowsSteps.spec.mjs:184) that passes 24 of 24 when run alone, with and without the change.Acceptance Criteria
devfirst: a cell node that carriesneo-selectedbefore its selection still carries it after the deselect, and a node that did not carry it ends without it.devfirst, through a grid: a cell-selecting model withselectedColumnsand noselectedColumnCellClskeeps the selected-column class on the cells its rule deselects.applyCellSelection()returnfalse, so the row is not updated again.#cellClsJSDoc names what it holds, and the summary ofapplyCellSelectionstays true.npx playwright test -c test/playwright/playwright.config.unit.mjs test/playwright/unit/grid test/playwright/unit/selectionis green.Out of Scope
aria-selectedon a node that carried it before its selection (no renderer sets it on cells today).neo-selectedfallback for selected columns ingrid.Row.updateBodyRows), which togglesselectedClson the row node.Avoided Traps
getCellCls()stops returning a class), and that class must still leave the cell.Related
test/playwright/unit/grid/CellSelectionByRule.spec.mjs: the rig for the grid arm.Live latest-open + closed sweep: checked latest 20 open + open and closed search (
applyCellSelection selection class cell; the closed hit #20698 introduced the method's contract, and the review of its PR found this defect) at 2026-11-14T23:59Z; no equivalent or prior exclusion found. Backlog: 46 open (orange); the owner is #20667, which this joins as a sub. A2A sweep: the last 30 lane-claims up to 23:24Z; none on cell selection. MC sweep: "a cell's selected class is stripped on deselect even though the cell carried it before the selection", 5 results; no decision on it. Own-assignment sweep: 2 open (#20925, #20667); #20667 is the parent.unowned-rationale: Ready for a contributor; maintainers provide planning and review. The filer reviews the PR it draws.
Origin Session ID: 0f917040-8b12-4dc3-9a7d-69961f23226d Retrieval Hint: "applyCellSelection withdraws a class the cell already carried"