From 792d2a4d99ed2f34370b673b5d0d23cbc620ec1b Mon Sep 17 00:00:00 2001 From: awsr <43862868+awsr@users.noreply.github.com> Date: Thu, 12 Feb 2026 14:24:17 -0800 Subject: [PATCH] Add fallback counter --- javascript/gallery.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/javascript/gallery.js b/javascript/gallery.js index a818af54f..70969e0f7 100644 --- a/javascript/gallery.js +++ b/javascript/gallery.js @@ -8,7 +8,6 @@ let outstanding = 0; let lastSort = 0; let lastSortName = 'None'; let gallerySelection = { files: [], index: -1 }; -const galleryHashes = new Set(); let maintenanceController = new AbortController(); const folderStylesheet = new CSSStyleSheet(); const fileStylesheet = new CSSStyleSheet(); @@ -111,7 +110,8 @@ async function awaitForOutstanding(num, signal) { * @param {AbortSignal} signal - AbortController signal */ async function awaitForGallery(expectedSize, signal) { - while (galleryHashes.size < expectedSize && !signal.aborted) await new Promise((resolve) => { setTimeout(resolve, 500); }); // longer interval because it's a low priority check + // eslint-disable-next-line no-use-before-define + while (Math.max(galleryHashes.size, galleryHashes.fallback) < expectedSize && !signal.aborted) await new Promise((resolve) => { setTimeout(resolve, 500); }); // longer interval because it's a low priority check signal.throwIfAborted(); } @@ -185,6 +185,26 @@ function updateGalleryStyles() { // Classes +class HashSet extends Set { + constructor(val) { + super(val); + // Using a variable to store a counter has sometimes been unreliable in the past + this.fallback = 0; + } + + add(value) { + ++this.fallback; + super.add(value); + } + + clear() { + this.fallback = 0; + super.clear(); + } +} + +const galleryHashes = new HashSet(); + class SimpleProgressBar { #container = document.createElement('div'); #progress = document.createElement('div');