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
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
Context
The Gallery arm of
StoreLoadingNL.spec.mjsfailed in PR #20406's hosted shard while its HTTP request was deliberately held open. This is pre-existing:Gallery.mjsis byte-identical between that PR's base8d70e70a27and headd37da9ecba; the PR changes ComboBox ownership only.The Problem
Gallery#afterSetMountedwaits 300 ms, reads dimensions, then chooses an initial record. For an empty Store, its index calculation yields zero andgetRecordId(store.getAt(0))receivesundefined: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 throughview._mounted = true, so it cannot catch this.The same formula computes
index=countforamountRows:1. The current falsey-key test also fails to distinguish an existing business key0from no selection.The Architectural Reality
Design authority: Gallery's existing
selectOnMountconfig requests initial selection;onStoreLoadrebuilds 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#afterSetMountedowns the delayed measurement and initial-selection request.onStoreLoadis where newly available records can fulfill that one-time request.Store#getInternalIdis 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
selectOnMountwith empty/late dataAcceptance Criteria
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.amountRows:1, one visible record and an existing business key0never cause an invalid lookup or replacement.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