LearnNewsExamplesServices
Frontmatter
id19800
titleSorting by a field named index empties the collection
stateClosed
labels
bugaicore
assigneesneo-opus-grace
createdAtOct 16, 2026, 1:18 PM
updatedAtOct 16, 2026, 1:57 PM
githubUrlhttps://github.com/neomjs/neo/issues/19800
authorneo-opus-grace
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtOct 16, 2026, 1:57 PM
milestonev13.3

Sorting by a field named index empties the collection

neo-opus-grace
neo-opus-grace commented on Oct 16, 2026, 1:18 PM

Context

Found during the v13.3 manual sweep on dev af81fc0f86. In examples/grid/covid, one click on the sortable # header empties the grid. That column's dataField is index, which is a real Integer model field. The console then shows TypeError: Cannot read properties of undefined for 'country', 'colspan', 'cases' and 'annotations.selected'. apps/covid and apps/sharedcovid declare the same index field.

The Problem

Neo.collection.Base#doSort sorts through a map whenever a sorter has useTransformValue, and Sorter defaults that to true (src/collection/Sorter.mjs:77). So the map path is the default for every property sort. Each mapped entry starts as {index}, the item's position, and then takes each sort property as a key (src/collection/Base.mjs:769–782). A sort property named index overwrites the position with the item's own value. The map back, items[el.index] (:805), then looks items up by field value instead of position. An out-of-range value yields undefined, and an in-range one yields the wrong item. The covid data never sets index, so every entry becomes undefined, and every later read of the collection throws.

The Architectural Reality

  • The map is the "sorting with map" pattern cited at :768. Its position key shares one namespace with the sort properties.
  • The direct path (mappedItems = items, when no sorter transforms) builds no helper object and is unaffected.
  • Store#doSort hydrates and then calls super.doSort, so Stores and plain Collections share the defect.
  • Design authority: a sort reorders a collection and never changes its members. The collection's own sort event reports items beside previousItems as the same set.

The Fix

Key the position with a Symbol, declared beside initialIndexSymbol and isSorted at the top of src/collection/Base.mjs, so no string property can collide with it.

Acceptance Criteria

  • Unit: a Collection sorted by a field named index (ASC, DESC, and as the second of two sorters) is ordered by that field and keeps every item. Red on dev.
  • Unit: the same for a Store with raw items (autoInitRecords: false). Its complex-field hydration runs before super.doSort and only adds properties, so it never reaches the position key (Euclid's review note on #19802).
  • examples/grid/covid: the # header sorts by index and keeps every row.
  • The existing collection and data unit specs stay green.

Out of Scope

  • A sortable: false header that still sorts on click, #19801. That is how apps/covid reaches this defect through its non-sortable # column.

Related

#19007 (sorter ordering, closed) · #19652

Live latest-open sweep: the latest 20 open issues at 2026-10-16T11:18Z, no equivalent. A closed-issue search for sort, index and undefined found #19007 only (ordering, not membership). A2A claim sweep: the latest 12 messages, through 11:17Z. The only grid claims are Emmy's #19794 and Ada's locked-arrow note, which #19798 covers. MC sweep: "sorting by index field empties collection items undefined covid grid rows vanish", 5 results, no prior decision. Own-assignment sweep: 5 open (#19798, #19766, #19765, #19652, #15000), none overlapping.

Origin Session ID: bb2e8968-a6d6-4ef7-a4ed-5ab3157b1ac8 Retrieval Hint: "collection doSort sorting with map index key collision sort property named index items undefined"

tobiu closed this issue on Oct 16, 2026, 1:57 PM
tobiu referenced in commit 09032db - "fix(collection): a sort by a field named index keeps every item (#19800) (#19802) on Oct 16, 2026, 1:57 PM
tobiu referenced in commit ec71256 - "fix(grid): a sortable: false header never sorts on click (#19801) (#19803) on Oct 16, 2026, 1:57 PM