Phase 6: Eliminate Duplicate Index Calls
Effort: 30 minutes Risk: Low Priority: Medium Status: Done - #12989 Previous: Phase 5: Restriction Status Next: Phase 7: Cleanup
Goal
Remove duplicated calculations of "which canvas is currently showing" across components.
What this phase originally assumed
As planned, this was a find-and-replace: since currentCanvasIndex was to be on the context, swap every queryParamToArrayIndex(query.canvas) call for it, in Thumbnails.tsx, NoScriptImage.tsx and MultipleManifestList.tsx.
Neither half of that held by the time the phase came round:
currentCanvasIndexwas deliberately never added to the context. It would duplicatequery.canvas, which is already there, and the 1-based canvas number and the 0-based array index are kept as distinct concepts throughout. See the note in README.None of the three named files calculate a canvas index any more.
Thumbnails.tsxcallsqueryParamToArrayIndexonquery.pageandMultipleManifestList.tsxonquery.manifest- different query params, unrelated to the current canvas - andNoScriptImage.tsxdoesn't call it at all, having moved to the sharedgetCanvasesForPagehelper in Phase 3.
So the phase became an audit of the whole refactored/ directory instead.
What the audit found
One genuine duplicate, in GridViewer.tsx: the memoised Cell recalculated queryParamToArrayIndex(query.canvas) for its own aria-current, once per rendered grid cell, while the parent already calculated the identical value for its scroll-to-row effect. Fixed by calculating it once in GridViewer and passing it down through itemData, plus a first test for that component.
Four lookalikes were checked and deliberately left alone, being different logic that happens to read similarly:
GridViewer'sCellandVirtualizedImageViewer'sItemRenderereach have a localcurrentCanvas, but those are per-cell and per-row canvases from iterating the whole list, not the one current canvas on the context.VirtualizedImageViewercallshasRestrictedItem(canvases[0]), which is about the first canvas specifically, for a margin adjustment - not the current one.IIIFViewer.tsxreadsdocument.fullscreenElementdirectly, to skip resize handling while a native video player is fullscreen. That's a different question from the fullscreen toggle state centralised in Phase 3.
Success Criteria
The criteria as originally written, with what actually happened against each:
Time: ~30 minutes
Next: Phase 7: Cleanup
Last updated