fix(library): resolve main-thread UI freeze and process kill data loss via OPFS payload capping, yield throttling, and UI batching

This commit is contained in:
2026-10-05 12:13:45 +07:00
parent 1e93c8484b
commit 140b4f88b2
4 changed files with 24 additions and 9 deletions
+18 -5
View File
@@ -469,19 +469,32 @@ export function Library() {
fresh = 0;
}
};
// The reading hands its frames over the moment their batch is stored, so the
// strip is the roll arriving rather than the roll being found again — a read
// of the whole catalogue costs every thumbnail in it, and on a folder of RAW
// that read beside a quarter of a gigabyte of decoder is what took the tab.
let pendingRows: LibraryPhoto[] = [];
let updateTimer: ReturnType<typeof setTimeout> | null = null;
const flushPending = () => {
if (pendingRows.length > 0) {
const toAdd = pendingRows;
pendingRows = [];
setPhotos((prev) => [...prev, ...toAdd]);
}
updateTimer = null;
};
watchRows((rows) => {
fresh += rows.length;
setPhotos((prev) => [...prev, ...rows]);
pendingRows.push(...rows);
if (!updateTimer) {
updateTimer = setTimeout(flushPending, 500);
}
});
const unwatch = watchScan(watching);
// A scan already in flight when this screen opens is picked up where it is:
// the reader who left for the studio comes back to the same roll.
watching();
return () => {
if (updateTimer) clearTimeout(updateTimer);
flushPending();
unwatch();
watchRows(null);
};