From 1061b0794245472410933bb4e8de116a32d5646d Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Mon, 26 Oct 2026 13:45:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A1=B5=E9=9D=A2=E5=88=B7=E6=96=B0=E4=B8=8E?= =?UTF-8?q?=E7=BC=A9=E7=95=A5=E5=9B=BE=E7=AB=9E=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/webui/ofdgo.js | 2 +- assets/webui/ofdgo_view.js | 51 +++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/assets/webui/ofdgo.js b/assets/webui/ofdgo.js index 4b2b478..8335a72 100644 --- a/assets/webui/ofdgo.js +++ b/assets/webui/ofdgo.js @@ -155,6 +155,7 @@ function createDocumentState() { selectedPages: new Set(), documentSelection: null, pageInFlight: new Map(), + pageLoadSeq: 0, pageRenderQueue: [], pagePrefetchIndex: null, pagePrefetchDirection: 1, @@ -170,7 +171,6 @@ function createDocumentState() { thumbnailFrame: 0, pageDragIndex: null, pageListCurrent: null, - thumbnailInFlight: new Set(), thumbnailObserver: null, visibleThumbnails: new Set(), exportFormats: [], diff --git a/assets/webui/ofdgo_view.js b/assets/webui/ofdgo_view.js index 2af42d5..2e934b0 100644 --- a/assets/webui/ofdgo_view.js +++ b/assets/webui/ofdgo_view.js @@ -49,7 +49,7 @@ export function createPageView(context) { } pageView.prunePageRenderQueue(); const page = await pageView.renderFlowPage(index, { throwError: true, openSeq, priority: 0 }); - if (openSeq !== state.openSeq || index !== state.pageIndex) { + if (!page || openSeq !== state.openSeq || index !== state.pageIndex) { return null; } if (options.scroll !== false) { @@ -222,6 +222,7 @@ export function createPageView(context) { }, resetPageLoading() { + context.state.pageLoadSeq++; context.releaseMediaPlayers(); if (context.state.pagePresentFrame) cancelAnimationFrame(context.state.pagePresentFrame); context.state.pagePresentFrame = 0; @@ -306,26 +307,28 @@ export function createPageView(context) { async renderFlowPage(index, options = {}) { const openSeq = options.openSeq || context.state.openSeq; - if (openSeq !== context.state.openSeq) { + const loadSeq = context.state.pageLoadSeq; + const current = () => openSeq === context.state.openSeq && loadSeq === context.state.pageLoadSeq; + if (!current()) { return null; } try { const page = await pageView.loadPageData(index, { openSeq, priority: options.priority ?? 2, view: true, refresh: context.state.editing && context.state.pageCache.get(index)?.previewOnly }); - if (openSeq !== context.state.openSeq) { + if (!current()) { return null; } if (page) { await pageView.queuePagePresentation(index, page, openSeq, true); } - if (openSeq !== context.state.openSeq) return null; + if (!current()) return null; pageView.trimPageCache(); return page; } catch (err) { - if (openSeq === context.state.openSeq) { + if (current()) { pageView.markFlowPageError(index, err); } - if (options.throwError && openSeq === context.state.openSeq) { + if (options.throwError && current()) { throw err; } return null; @@ -334,6 +337,7 @@ export function createPageView(context) { loadPageData(index, options = {}) { const openSeq = options.openSeq || context.state.openSeq; + const loadSeq = context.state.pageLoadSeq; if (openSeq !== context.state.openSeq) { return Promise.resolve(null); } @@ -343,7 +347,7 @@ export function createPageView(context) { if (current) { current.priority = Math.min(current.priority, priority); current.view &&= !!options.view; - if (current.preview && !options.preview) return current.promise.then(page => page && openSeq === context.state.openSeq ? pageView.loadPageData(index, options) : null); + if (current.preview && !options.preview) return current.promise.then(page => page && openSeq === context.state.openSeq && loadSeq === context.state.pageLoadSeq ? pageView.loadPageData(index, options) : null); return current.promise; } if (!options.refresh && context.state.pageCache.has(index) && (options.preview || !context.state.pageCache.get(index).previewOnly)) { @@ -373,16 +377,16 @@ export function createPageView(context) { return; } context.state.pageRenderRunning = true; - const tab = context.documentTab(), openSeq = tab.state.openSeq; + const tab = context.documentTab(), openSeq = tab.state.openSeq, loadSeq = tab.state.pageLoadSeq; requestAnimationFrame(() => { - if (context.activeTab === tab && openSeq === tab.state.openSeq) pageView.processPageRenderQueue(); + if (context.activeTab === tab && openSeq === tab.state.openSeq && loadSeq === tab.state.pageLoadSeq) pageView.processPageRenderQueue(); }); }, async processPageRenderQueue() { - const tab = context.documentTab(), openSeq = tab.state.openSeq; + const tab = context.documentTab(), openSeq = tab.state.openSeq, loadSeq = tab.state.pageLoadSeq; await context.nextFrame(); - if (context.activeTab !== tab || openSeq !== tab.state.openSeq) return; + if (context.activeTab !== tab || openSeq !== tab.state.openSeq || loadSeq !== tab.state.pageLoadSeq) return; const available = (nativeHost?.parallelism || context.wasmWorker?.parallelism || 1) - tab.state.pageRenderWorkers; await Promise.all(Array.from({ length: Math.max(0, available) }, () => pageView.processPageRenderTasks())); }, @@ -598,10 +602,10 @@ export function createPageView(context) { }, schedulePagePresentation() { - const tab = context.documentTab(), state = tab.state, openSeq = state.openSeq; + const tab = context.documentTab(), state = tab.state, openSeq = state.openSeq, loadSeq = state.pageLoadSeq; if (state.pagePresentFrame || !state.pagePresentQueue.size) return; state.pagePresentFrame = requestAnimationFrame(() => { - if (context.activeTab !== tab || openSeq !== state.openSeq) return; + if (context.activeTab !== tab || openSeq !== state.openSeq || loadSeq !== state.pageLoadSeq) return; state.pagePresentFrame = 0; const started = performance.now(); do { @@ -1120,7 +1124,6 @@ export function createPageView(context) { resetThumbnails() { context.state.visibleThumbnails.clear(); - context.state.thumbnailInFlight.clear(); if (context.state.thumbnailObserver) { context.state.thumbnailObserver.disconnect(); context.state.thumbnailObserver = null; @@ -1220,31 +1223,23 @@ export function createPageView(context) { }, async renderThumbnail(index, openSeq = context.state.openSeq) { - if (openSeq !== context.state.openSeq || !context.state.doc) { + const loadSeq = context.state.pageLoadSeq; + const current = () => openSeq === context.state.openSeq && loadSeq === context.state.pageLoadSeq; + if (!current() || !context.state.doc) { return; } - const key = `${openSeq}:${index}`; - if (context.state.thumbnailInFlight.has(key)) { - return; - } - context.state.thumbnailInFlight.add(key); try { const page = await pageView.loadPageData(index, { openSeq, priority: 5, preview: true, view: true }); - if (openSeq !== context.state.openSeq) { - return; - } - if (!page) { + if (!current() || !page) { return; } await pageView.queuePagePresentation(index, page, openSeq); - if (openSeq !== context.state.openSeq) return; + if (!current()) return; pageView.trimPageCache(); } catch { - if (openSeq === context.state.openSeq) { + if (current()) { pageView.markThumbnailError(index); } - } finally { - context.state.thumbnailInFlight.delete(key); } },