Keep loaded gallery thumbnails mounted to stop scroll-back flicker
The gallery virtualiser removed a tile's <a>/<img> from the DOM whenever it left the viewport ± 1 buffer and rebuilt it from scratch on re-entry, so scrolling back up replayed the thumbhash placeholder and opacity fade on thumbnails that were already loaded - even for small albums where no network fetch happens. Track tile indices whose <img> has fired `load` in a bounded, LRU-ordered `stickyTiles` set. virtualize() keeps those tiles in the "needed" set so syncRendered never unmounts them; not-yet-loaded tiles still get the normal lazy create/remove + data-src treatment, so large albums keep lazy-loading on first scroll-into-view. The set is trimmed to STICKY_TILE_LIMIT (1500) each pass - currently visible tiles are bumped to most-recently-used and the oldest off-screen overflow is released back to normal virtualisation - so a very large album (100k+ photos) cannot accumulate unbounded mounted DOM or retained image memory as the user scrolls. Cleared on a layout recompute since tile geometry changes there. Also adds a fast-path skip in loadVisibleTiles() for finished loads now that the rendered-tile map can be larger. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -73,7 +73,13 @@ export function createTile (index: number): HTMLAnchorElement {
|
||||
// `#gallery img.loaded` fades opacity from 0 to 1 so the thumbhash blurs
|
||||
// into the sharp image instead of snapping (and masks Chrome/Edge's brief
|
||||
// white flash between `img.src` being set and the bytes actually painting).
|
||||
img.onload = () => img.classList.add('loaded')
|
||||
img.onload = () => {
|
||||
img.classList.add('loaded')
|
||||
// Pin this tile: once loaded it is never virtualised out again, so a
|
||||
// scroll back up reuses this exact <img> instead of rebuilding it in a
|
||||
// blank/placeholder state. See state.stickyTiles / virtualize().
|
||||
state.stickyTiles.add(index)
|
||||
}
|
||||
a.appendChild(img)
|
||||
|
||||
if (item.type === 'VIDEO') {
|
||||
|
||||
Reference in New Issue
Block a user