ChannelBuilder library-browse "Load more": cross-page sort order and an overclaimed totalCount permit no-op requests #665

Open
opened 2026-07-26 23:37:45 +02:00 by timothy · 0 comments
Owner

Background

A cold cross-family (Codex) review of #650's fix (commit 9763fdca, PR follow-up work in
fix/650-at-cap-truncation) found two pre-existing defects in web/src/builder/ChannelBuilder.tsx's
useLibraryBrowse hook / its loadCollections/loadLibraryItems fan-out helpers. Both already existed
for the 'library' source before #650; #650's fix newly makes them reachable from the 'collections'
source too (by summing the real per-kind totalCount and no longer gating canLoadMore to
source === 'library' only). They are separate, pre-existing concerns from #650's own truncation bug,
so they're tracked here rather than re-opening #650.

F1 — cross-page sort order

loadCollections/loadLibraryItems each sort the MERGED per-kind results of one page
(results.flatMap(...).sort(...)), then the caller appends that page's sorted batch onto the
previously-accumulated (and separately sorted) items array on "Load more":

items: append ? [...prev.items, ...result.page] : result.page,

Each page is sorted WITHIN itself, but never re-sorted against the accumulated list. So page 2's
A101 (title-sorts before Zzz) lands AFTER page 1's Zzz in the rendered grid — the overall list is
not globally title-sorted once more than one page has been loaded.

Failure scenario: a library/collections search with >100 results split across kinds; click "Load
more" once; the rendered grid shows page 1 (title-sorted A→Z) followed by page 2 (also title-sorted
A→Z), i.e. two locally-sorted runs instead of one globally-sorted list.

Affected files: web/src/builder/ChannelBuilder.tsx (loadCollections, loadLibraryItems, and the
runFetch/useLibraryBrowse append logic).

F7 — an overclaimed totalCount leaves "Load more" permanently actionable

If the summed totalCount overclaims relative to what additional pages can actually deliver (e.g. a
per-kind totalCount that drifts stale between the initiating request and a later page, or a kind whose
totalCount legitimately exceeds what HydrateMediaItems can return — see the existing loadAllPages
doc comment on the same class of staleness), canLoadMore's items.length < totalCount comparison can
stay true even once every kind has actually been exhausted. This does not auto-loop (it requires a user
click each time), but it does mean the "Load more" button can remain visible and clickable indefinitely,
permitting unlimited no-op requests that return nothing new.

Affected files: same as F1 — web/src/builder/ChannelBuilder.tsx's useLibraryBrowse /
canLoadMore.

Done-when

  • F1: the merged item list stays globally sorted (by title) across page boundaries, not just
    within each individually-fetched page — either by re-sorting the full accumulated list on every
    append, or by another approach that gives the same guarantee.
  • F7: an exhausted-but-still-canLoadMore-true state (further "Load more" clicks return nothing
    new) is handled — either by detecting a no-progress response and disabling "Load more", or another
    approach that stops the permanently-actionable button.
  • Tests pin both boundaries (a >1-page cross-boundary sort assertion for F1; a no-progress response
    for F7) rather than a non-empty/status-only check.
  • Adversarial review passed.
## Background A cold cross-family (Codex) review of #650's fix (commit `9763fdca`, PR follow-up work in `fix/650-at-cap-truncation`) found two pre-existing defects in `web/src/builder/ChannelBuilder.tsx`'s `useLibraryBrowse` hook / its `loadCollections`/`loadLibraryItems` fan-out helpers. Both already existed for the `'library'` source before #650; #650's fix newly makes them reachable from the `'collections'` source too (by summing the real per-kind `totalCount` and no longer gating `canLoadMore` to `source === 'library'` only). They are separate, pre-existing concerns from #650's own truncation bug, so they're tracked here rather than re-opening #650. ## F1 — cross-page sort order `loadCollections`/`loadLibraryItems` each sort the MERGED per-kind results of one page (`results.flatMap(...).sort(...)`), then the caller appends that page's sorted batch onto the previously-accumulated (and separately sorted) `items` array on "Load more": ```ts items: append ? [...prev.items, ...result.page] : result.page, ``` Each page is sorted WITHIN itself, but never re-sorted against the accumulated list. So page 2's `A101` (title-sorts before `Zzz`) lands AFTER page 1's `Zzz` in the rendered grid — the overall list is not globally title-sorted once more than one page has been loaded. **Failure scenario:** a library/collections search with >100 results split across kinds; click "Load more" once; the rendered grid shows page 1 (title-sorted A→Z) followed by page 2 (also title-sorted A→Z), i.e. two locally-sorted runs instead of one globally-sorted list. **Affected files:** `web/src/builder/ChannelBuilder.tsx` (`loadCollections`, `loadLibraryItems`, and the `runFetch`/`useLibraryBrowse` append logic). ## F7 — an overclaimed totalCount leaves "Load more" permanently actionable If the summed `totalCount` overclaims relative to what additional pages can actually deliver (e.g. a per-kind `totalCount` that drifts stale between the initiating request and a later page, or a kind whose `totalCount` legitimately exceeds what `HydrateMediaItems` can return — see the existing `loadAllPages` doc comment on the same class of staleness), `canLoadMore`'s `items.length < totalCount` comparison can stay true even once every kind has actually been exhausted. This does not auto-loop (it requires a user click each time), but it does mean the "Load more" button can remain visible and clickable indefinitely, permitting unlimited no-op requests that return nothing new. **Affected files:** same as F1 — `web/src/builder/ChannelBuilder.tsx`'s `useLibraryBrowse` / `canLoadMore`. ## Done-when - [ ] F1: the merged item list stays globally sorted (by title) across page boundaries, not just within each individually-fetched page — either by re-sorting the full accumulated list on every append, or by another approach that gives the same guarantee. - [ ] F7: an exhausted-but-still-`canLoadMore`-true state (further "Load more" clicks return nothing new) is handled — either by detecting a no-progress response and disabling "Load more", or another approach that stops the permanently-actionable button. - [ ] Tests pin both boundaries (a >1-page cross-boundary sort assertion for F1; a no-progress response for F7) rather than a non-empty/status-only check. - [ ] Adversarial review passed.
timothy added the bugpriority: lowfrontend labels 2026-07-26 23:37:45 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#665