LearnNewsExamplesConnect
Frontmatter
assigneesbfs2021
createdAtNov 15, 2026, 1:00 AM
updatedAtNov 15, 2026, 2:22 AM
githubUrlhttps://github.com/neomjs/neo/issues/20980
authorneo-opus-vega
commentsCount2
parentIssue20667
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined1
signals[]
blockedBy[]
blocking[]
closedAtNov 15, 2026, 2:22 AM
milestonev14.0

applyCellSelection strips a class the cell carried before its selection

Closed v14.0.0/archive-v14-0-0-chunk-2 bughelp wantedgood first issueaigrid
neo-opus-vega
neo-opus-vega commented on Nov 15, 2026, 1:00 AM

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

  1. 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.
  2. 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

  • A unit arm, red on dev first: a cell node that carries neo-selected before its selection still carries it after the deselect, and a node that did not carry it ends without it.
  • A unit arm, red on dev first, through a grid: a cell-selecting model with selectedColumns and no selectedColumnCellCls keeps the selected-column class on the cells its rule deselects.
  • A unit arm: a selected cell whose answer did not change makes applyCellSelection() return false, so the row is not updated again.
  • The #cellCls JSDoc names what it holds, and the summary of applyCellSelection stays true.
  • npx playwright test -c test/playwright/playwright.config.unit.mjs test/playwright/unit/grid test/playwright/unit/selection is green.

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"

bfs2021
bfs2021 Nov 15, 2026, 1:09 AM

Claiming this one. The fix follows the issue's design ({added, cls} in #cellCls), and test/playwright/unit/grid + test/playwright/unit/selection are green locally.

  • 2026-11-15T00:09:37Z @github-actions assigned to @bfs2021

@github-actions - 2026-11-15T00:09:38Z

Thanks for claiming this, @bfs2021, and welcome! Assigned to you — you can start now.

Your claim reserves this issue for 3 days (any comment here resets the clock; we still merge the first approve-worthy PR if another lands first or a claim goes quiet).

An automatic reply. How claims work [QUARANTINED_URL: github.com]

bfs2021 cross-referenced by PR #20981 on Nov 15, 2026, 1:14 AM
tobiu referenced in commit c78adac - "fix(selection): withdraw only the classes applyCellSelection added (#20980) (#20981)" on Nov 15, 2026, 2:22 AM
tobiu closed this issue on Nov 15, 2026, 2:22 AM