Context
Framing from @tobiu, and it bounds this ticket: "it is not crucial, but a convenience method. good for DX and MX." This is not a correctness or performance defect — nothing is broken today. It is an API-completeness gap that makes the ergonomic spelling of a common operation cost more than the terse one.
Origin: #15202 prescribed migrating application class transitions onto removeCls() / addCls(). I implemented it (#18735 + neomjs/devindex#14) and @tobiu caught that it replaces one vdom update with two. Both PRs are closed and #15202's premise is falsified — the aggregate read-mutate-assign is the engine's own intended idiom, made safe by beforeGetCls returning [...value]. This ticket is the one real thing that lane surfaced.
The Problem
component.Base's class helpers are each get-copy → mutate → assign:
addCls(value) { let {cls} = this; NeoArray.add(cls, value); this.cls = cls }
removeCls(value) { let cls = this.cls; NeoArray.remove(cls, value); this.cls = cls }
toggleCls(value, add) { let cls = this.cls; NeoArray.toggle(cls, value, add); this.cls = cls }afterSetCls ends in me.update(), and the in-flight guard defers rather than merges — needsVdomUpdate = true at mixin/VdomLifecycle.mjs:1090, re-fired at :403. Per the batching model the first config change takes a worker round trip and the rest batch into a second, so composing two helpers costs 2 round trips where one assignment costs 1.
The family is symmetric except for one hole:
| layer |
add |
remove |
toggle |
swap |
util/Array |
add |
remove |
toggle |
removeAdd ✅ |
component.Base |
addCls |
removeCls |
toggleCls |
— missing ❌ |
A swap is the one operation the family cannot express. The compositional test — can a caller build this from existing members at the same cost? — is yes for add/remove/toggle and no for swap. removeAdd exists one layer down; the lift to the component layer was never made, so callers either hand-roll it or pay the extra round trip.
The Architectural Reality
The engine has two established idioms, and only the first is in scope:
- One-shot swap —
component/Icon.mjs:41: let cls = this.cls;
NeoArray.removeAdd(cls, oldValue, value);
this.cls = cls
- Swap plus further config changes —
tab/Container.mjs:251: NeoArray.remove(cls, 'neo-' + oldValue);
NeoArray.add(cls, 'neo-' + value);
me.setSilent({cls});
Form 2 is already correct and must not be touched — set() / setSilent() / the silentVdomUpdate bracket (toolbar/Breadcrumb.mjs:198-229, form/field/Text.mjs:783-791) are the right tool when cls changes alongside other configs, and removeAddCls would not improve them.
NeoArray.remove and .add both accept an item or an array, so the signature must pass through: grid/header/Button.mjs:133 removes two classes and adds one.
The Fix
Add one method to src/component/Base.mjs, beside addCls / removeCls / toggleCls:
removeAddCls(removeItems, addItems) {
let cls = this.cls;
NeoArray.removeAdd(cls, removeItems, addItems);
this.cls = cls
}One assignment, one round trip, arrays accepted on both sides. Then migrate the one-shot this.cls swap sites to it.
Enumerated candidates (from a remove→add-pair sweep across src + apps). Every one needs per-site confirmation at implementation time — the sweep classifies by what the local cls variable points at, which is exactly the check I got wrong twice in the originating lane:
servable — this.cls, one-shot |
|
component/Icon.mjs:41 |
already removeAdd; collapses to one line |
button/Base.mjs:330 · component/StatusBadge.mjs:298 · form/field/FileUpload.mjs:775 |
confirm each |
grid/header/Button.mjs:133,139 · table/header/Button.mjs:136,141 |
multi-remove + single add |
form/field/CheckBox.mjs:333 |
confirm |
apps/portal/view/Viewport.mjs · apps/shareddialog/view/MainContainerController.mjs |
app sites |
| excluded |
why |
tab/Container.mjs:251 |
uses setSilent({cls}) — already one flush |
⚠️ component/IconLink.mjs:68 |
the look-alike trap. Reads identically to Icon.mjs:41 at a glance, but node = me.vdom.cn[0] — it mutates a child node. removeAddCls targets the vdomRoot, so migrating this one would be a defect, not a cleanup. Verified by @neo-opus-ada on #18738. |
button/Base.mjs:242 · container/AccordionItem.mjs:141 · form/field/Text.mjs:544,824 · form/field/CheckBox.mjs:317 |
mutate a child / label / vdom node cls, not this.cls |
form/field/CheckBox.mjs:227 |
operates on iconCls |
layout/Card.mjs |
wrapperCls / childCls |
Accretion Defense — the deletion is named. ~8 engine lines added; each migrated site drops from 3 lines to 1, and sites whose only remaining NeoArray use was the swap drop the import too. Net consumer-line reduction, and the *Cls family becomes complete rather than gaining a special case.
Decision Record impact
none. New public convenience on an existing family, no contract change to cls, afterSetCls, or the update pipeline.
Acceptance Criteria
Out of Scope
- Any migration to
removeCls() + addCls() — that is the retracted #18735 shape and costs an extra round trip.
set() / setSilent() / silentVdomUpdate call sites, and converting anything to them.
- Child-node, label-element,
wrapperCls, childCls and iconCls sites.
NeoArray.removeAdd itself, and the cls reactive-config contract.
- #15202's premise — falsified, addressed on that ticket.
Avoided Traps
A DOM-class-state assertion cannot see this. In #18735 I shipped a MutationObserver spec with a positive control proving no intermediate DOM class state, and cited it as licence. The deferred second cycle mutates no classes, so the instrument agreed and could not have disagreed. A positive control proves the observer can see what it watches; it says nothing about whether that is the right axis. AC-3 is therefore written as an update count.
Do not trust a cls-named local. A remove→add pair on a variable called cls says nothing about whether it is this.cls. In the sweep above, CheckBox.mjs:227 is iconCls and IconLink.mjs:68 is a child node — I asserted both as servable before checking, and had to correct it. Resolve the assignment for every site.
Do not extrapolate cost from a guard. Reading needsVdomUpdate tells you a second cycle exists; it does not tell you how many. I claimed N+1 for loop-shaped call sites and was wrong — batching caps it at 2 regardless of iteration count.
Related
- #15202 — the falsified parent; its AC-8 ("no additional intermediate DOM class state") is satisfiable and misleading.
- #18735 (closed, retracted) ·
neomjs/devindex#14 + neomjs/devindex#13 (closed, retracted) — the two-round-trip shape and the evidence.
component/Icon.mjs:41 — the one-shot precedent · tab/Container.mjs:251 — the setSilent precedent.
Sweeps. Exact-search on removeAddCls: only #15202 returned, which is the falsified parent, not an equivalent. Live latest-open checked at 2026-09-15T13:2x (#18731, #18680, #18532 newest) — no equivalent. A2A in-flight claim sweep over the recent queue: no competing claim on component/Base.mjs's cls helpers. Own-assignment sweep: #18532, #18064, #17918, #16358, #16212, #15202 — none covers this.
Origin Session ID: a2868f57-a008-4abf-b493-b87be1636964
Retrieval Hint: component Base cls helper family swap removeAddCls one update round trip
Context
Framing from @tobiu, and it bounds this ticket: "it is not crucial, but a convenience method. good for DX and MX." This is not a correctness or performance defect — nothing is broken today. It is an API-completeness gap that makes the ergonomic spelling of a common operation cost more than the terse one.
Origin: #15202 prescribed migrating application class transitions onto
removeCls()/addCls(). I implemented it (#18735 +neomjs/devindex#14) and @tobiu caught that it replaces one vdom update with two. Both PRs are closed and #15202's premise is falsified — the aggregate read-mutate-assign is the engine's own intended idiom, made safe bybeforeGetClsreturning[...value]. This ticket is the one real thing that lane surfaced.The Problem
component.Base's class helpers are eachget-copy → mutate → assign:addCls(value) { let {cls} = this; NeoArray.add(cls, value); this.cls = cls } removeCls(value) { let cls = this.cls; NeoArray.remove(cls, value); this.cls = cls } toggleCls(value, add) { let cls = this.cls; NeoArray.toggle(cls, value, add); this.cls = cls }afterSetClsends inme.update(), and the in-flight guard defers rather than merges —needsVdomUpdate = trueatmixin/VdomLifecycle.mjs:1090, re-fired at:403. Per the batching model the first config change takes a worker round trip and the rest batch into a second, so composing two helpers costs 2 round trips where one assignment costs 1.The family is symmetric except for one hole:
util/ArrayaddremovetoggleremoveAdd✅component.BaseaddClsremoveClstoggleClsA swap is the one operation the family cannot express. The compositional test — can a caller build this from existing members at the same cost? — is yes for add/remove/toggle and no for swap.
removeAddexists one layer down; the lift to the component layer was never made, so callers either hand-roll it or pay the extra round trip.The Architectural Reality
The engine has two established idioms, and only the first is in scope:
component/Icon.mjs:41:let cls = this.cls; NeoArray.removeAdd(cls, oldValue, value); this.cls = clstab/Container.mjs:251:NeoArray.remove(cls, 'neo-' + oldValue); NeoArray.add(cls, 'neo-' + value); me.setSilent({cls}); // more configs follow; one flushForm 2 is already correct and must not be touched —
set()/setSilent()/ thesilentVdomUpdatebracket (toolbar/Breadcrumb.mjs:198-229,form/field/Text.mjs:783-791) are the right tool when cls changes alongside other configs, andremoveAddClswould not improve them.NeoArray.removeand.addboth accept an item or an array, so the signature must pass through:grid/header/Button.mjs:133removes two classes and adds one.The Fix
Add one method to
src/component/Base.mjs, besideaddCls/removeCls/toggleCls:removeAddCls(removeItems, addItems) { let cls = this.cls; NeoArray.removeAdd(cls, removeItems, addItems); this.cls = cls }One assignment, one round trip, arrays accepted on both sides. Then migrate the one-shot
this.clsswap sites to it.Enumerated candidates (from a
remove→add-pair sweep acrosssrc+apps). Every one needs per-site confirmation at implementation time — the sweep classifies by what the localclsvariable points at, which is exactly the check I got wrong twice in the originating lane:this.cls, one-shotcomponent/Icon.mjs:41removeAdd; collapses to one linebutton/Base.mjs:330·component/StatusBadge.mjs:298·form/field/FileUpload.mjs:775grid/header/Button.mjs:133,139·table/header/Button.mjs:136,141form/field/CheckBox.mjs:333apps/portal/view/Viewport.mjs·apps/shareddialog/view/MainContainerController.mjstab/Container.mjs:251setSilent({cls})— already one flushcomponent/IconLink.mjs:68Icon.mjs:41at a glance, butnode = me.vdom.cn[0]— it mutates a child node.removeAddClstargets the vdomRoot, so migrating this one would be a defect, not a cleanup. Verified by @neo-opus-ada on #18738.button/Base.mjs:242·container/AccordionItem.mjs:141·form/field/Text.mjs:544,824·form/field/CheckBox.mjs:317cls, notthis.clsform/field/CheckBox.mjs:227iconClslayout/Card.mjswrapperCls/childClsAccretion Defense — the deletion is named. ~8 engine lines added; each migrated site drops from 3 lines to 1, and sites whose only remaining
NeoArrayuse was the swap drop the import too. Net consumer-line reduction, and the*Clsfamily becomes complete rather than gaining a special case.Decision Record impact
none. New public convenience on an existing family, no contract change tocls,afterSetCls, or the update pipeline.Acceptance Criteria
removeAddCls(removeItems, addItems)exists onNeo.component.Basebeside the other*Clshelpers, with JSDoc, and performs exactly oneclsassignment.grid/header/Button.mjs's two-remove-one-add shape).update()perremoveAddClscall — a round-trip/update count, not DOM class state. (See Avoided Traps: a DOM-state assertion passes while the cost doubles.)this.cls+ one-shot before migration; any that is not is moved to the excluded table with its reason recorded in the PR.NeoArrayreference was the swap drop the import; a scoped grep confirms no unused import remains.Out of Scope
removeCls()+addCls()— that is the retracted #18735 shape and costs an extra round trip.set()/setSilent()/silentVdomUpdatecall sites, and converting anything to them.wrapperCls,childClsandiconClssites.NeoArray.removeAdditself, and theclsreactive-config contract.Avoided Traps
A DOM-class-state assertion cannot see this. In #18735 I shipped a
MutationObserverspec with a positive control proving no intermediate DOM class state, and cited it as licence. The deferred second cycle mutates no classes, so the instrument agreed and could not have disagreed. A positive control proves the observer can see what it watches; it says nothing about whether that is the right axis. AC-3 is therefore written as an update count.Do not trust a
cls-named local. Aremove→addpair on a variable calledclssays nothing about whether it isthis.cls. In the sweep above,CheckBox.mjs:227isiconClsandIconLink.mjs:68is a child node — I asserted both as servable before checking, and had to correct it. Resolve the assignment for every site.Do not extrapolate cost from a guard. Reading
needsVdomUpdatetells you a second cycle exists; it does not tell you how many. I claimed N+1 for loop-shaped call sites and was wrong — batching caps it at 2 regardless of iteration count.Related
neomjs/devindex#14+neomjs/devindex#13(closed, retracted) — the two-round-trip shape and the evidence.component/Icon.mjs:41— the one-shot precedent ·tab/Container.mjs:251— thesetSilentprecedent.Sweeps. Exact-search on
removeAddCls: only #15202 returned, which is the falsified parent, not an equivalent. Live latest-open checked at 2026-09-15T13:2x (#18731, #18680, #18532 newest) — no equivalent. A2A in-flight claim sweep over the recent queue: no competing claim oncomponent/Base.mjs's cls helpers. Own-assignment sweep: #18532, #18064, #17918, #16358, #16212, #15202 — none covers this.Origin Session ID: a2868f57-a008-4abf-b493-b87be1636964
Retrieval Hint:
component Base cls helper family swap removeAddCls one update round trip