LearnNewsExamplesConnect
Frontmatter
assigneesneo-gpt-sophie
createdAtNov 6, 2026, 1:16 AM
updatedAtNov 6, 2026, 11:51 AM
githubUrlhttps://github.com/neomjs/neo/issues/20409
authorneo-gpt-sophie
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[x] 20437 Workstation feed assertion reads across different ticks
closedAtNov 6, 2026, 11:51 AM

Gallery initial selection crashes while its Store is empty

neo-gpt-sophie
neo-gpt-sophie commented on Nov 6, 2026, 1:16 AM

Context

The Gallery arm of StoreLoadingNL.spec.mjs failed in PR #20406's hosted shard while its HTTP request was deliberately held open. This is pre-existing: Gallery.mjs is byte-identical between that PR's base 8d70e70a27 and head d37da9ecba; the PR changes ComboBox ownership only.

The Problem

Gallery#afterSetMounted waits 300 ms, reads dimensions, then chooses an initial record. For an empty Store, its index calculation yields zero and getRecordId(store.getAt(0)) receives undefined:

Cannot read properties of undefined (reading 'Symbol(Neo.internalId)')
Store.getInternalId → Gallery.getRecordId → Gallery.afterSetMounted callback

A controlled real Gallery/Store probe with an empty Store, the actual 300 ms timer and a resolved native-dimension reply reproduces the error with count:0, selection:[]. Existing loading unit coverage bypasses the hook through view._mounted = true, so it cannot catch this.

The same formula computes index=count for amountRows:1. The current falsey-key test also fails to distinguish an existing business key 0 from no selection.

The Architectural Reality

Design authority: Gallery's existing selectOnMount config requests initial selection; onStoreLoad rebuilds items and preserves existing selection. Empty asynchronous data is already supported by the Store-loading contract delivered for #290.

Prescription checked: src/component/Gallery.mjs#afterSetMounted owns the delayed measurement and initial-selection request. onStoreLoad is where newly available records can fulfill that one-time request. Store#getInternalId is not the repair boundary.

The Fix

Keep initial selection pending until the mounted Gallery has a valid visible record, then consume it once. Preserve the existing nonempty selection choice, clamp it to the visible record range, and distinguish key zero from absence. A completed initial request must not select again on later coarse loads or sorts.

Fence delayed measurement against unmount, destruction and render-window changes. Expected instance/window retirement settles quietly; unexpected native errors remain observable. Reuse the existing Store-load path and selection model.

Contract Ledger

Surface Authority Restored behavior Fallback / docs Evidence
selectOnMount with empty/late data Existing Gallery config and loading support No invalid record lookup; one initial selection when a visible record becomes available False leaves unselected views unselected; method JSDoc Controlled mount/late-load and native held-request cases
Existing selection and default index GalleryModel and current mount formula Valid existing key (including 0) survives; default index stays in range No selection when no visible rows; no repeat on sort/load Zero-key, one-row, normal multi-row and manual-deselect controls
Deferred native read Existing instance-owned timeout / window departure contract Stale completion cannot mutate an unmounted/destroyed/new-window view Genuine failures still reported Deferred-reply and cancellation controls

Acceptance Criteria

  • An empty mounted Gallery can finish its dimension read with no thrown/unhandled error and no selection, while loading feedback remains correct.
  • With selectOnMount:true, the pending initial request selects a valid rendered record once when data arrives; false and later manual deselection are respected across further loads/sorts.
  • Normal populated default selection is preserved; amountRows:1, one visible record and an existing business key 0 never cause an invalid lookup or replacement.
  • Unmount/destroy/window-change before deferred completion prevents stale writes or selection; expected cancellation is quiet and genuine native errors remain visible.
  • Unit coverage exercises the actual mount hook (not a silent mounted assignment), and the held-request Gallery browser arm passes with the dimension-read boundary reached before data is released.

Out of Scope

ComboBox repair #20403 / PR #20406, Calendar drag readiness, Helix redesign, global Store guards, and selecting anew on every load.

Avoided Traps

Do not whitelist the error or weaken workerErrors. A bare null guard would prevent the exception but discard the initial-selection request for slow loads. A longer fixed sleep only moves the race.

Related

#290 / PR #20343 (loading feedback), #16559 (selection preserved across rebuilds), PR #20406 (failure exposure). Self-owned immediate repair; no contributor reservation is displaced.

Live latest-open + closed sweep: latest 20 open plus all-state “Gallery empty selection” and closed “Gallery selectOnMount” searches checked 2026-11-06T00:14Z; no equivalent open leaf. #16559's body and exclusions read: it owns rebuild restoration, not initial empty-mount selection. Three Memory Core framings returned unrelated initialization records; current source and the controlled reproduction carry the claim. Own assignments and recent all-state A2A show no competing Gallery repair.

Decision Record impact: none. Origin Session ID: 2127005d-d2e7-46c1-a8f5-9e1575bc6fae