From f7b08a60856dc3fd832d38b50be9fb0edecd96bc Mon Sep 17 00:00:00 2001 From: Shahid Shamim Shah Date: Sun, 1 Nov 2026 01:41:12 +0530 Subject: [PATCH] fix: release the large page preview when closed --- .github/workflows/build.yml | 1 + Source code/server/public/app.js | 1 + Source code/tests/README.md | 2 ++ Source code/tests/t15-page-view.js | 33 ++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 Source code/tests/t15-page-view.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b3c5b68..a723bcc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,6 +40,7 @@ jobs: node t12-remote.js node t13-upload-retry.js node t14-preview-files.js + node t15-page-view.js windows: name: Windows installer diff --git a/Source code/server/public/app.js b/Source code/server/public/app.js index 44d19be..6dabe1e 100644 --- a/Source code/server/public/app.js +++ b/Source code/server/public/app.js @@ -908,6 +908,7 @@ function openPageView(n) { function closePageView() { viewPage = 0; $("pageView").hidden = true; + $("pvStage").innerHTML = ""; } function renderPageView() { diff --git a/Source code/tests/README.md b/Source code/tests/README.md index 9e44124..925f902 100644 --- a/Source code/tests/README.md +++ b/Source code/tests/README.md @@ -18,6 +18,8 @@ websites (`fake-web.js`) on spare ports, so nothing else needs to be running. node t13-upload-retry.js "Print this?" screen: a stuck upload is sent again, then shows an error node t14-preview-files.js the preview library is sent gzipped to browsers that can take it + node t15-page-view.js closing the large page preview frees its image; reopening the same page works + These run on Linux/macOS. The Windows-only parts (the Task Scheduler task, the installer) are covered by manual checks on Windows and Mac. t4, t5 and t6 need a real network card: on a machine with only diff --git a/Source code/tests/t15-page-view.js b/Source code/tests/t15-page-view.js new file mode 100644 index 0000000..c2b013b --- /dev/null +++ b/Source code/tests/t15-page-view.js @@ -0,0 +1,33 @@ +// Closing the large page view releases its image, and the same page can reopen. +const fs = require("fs"), path = require("path"), vm = require("vm"), assert = require("assert"); +let n = 0; const ok = (c, m) => { assert(c, m); n++; console.log(" ok -", m); }; +const src = fs.readFileSync(path.join(__dirname, "../server/public/app.js"), "utf8"); +const code = src.slice(src.indexOf("function openPageView("), src.indexOf("function setupPageView(")); +function element() { + return { + children: [], style: {}, hidden: true, clientWidth: 600, + appendChild(child) { this.children.push(child); }, + set innerHTML(value) { this.children = []; }, + }; +} +const ids = Object.fromEntries(["pageView", "pvStage", "pvTitle", "pvChoose", "pvPrev", "pvNext"].map(id => [id, element()])); +const draws = []; +const box = { + viewPage: 0, MAX_THUMBS: 100, $: id => ids[id], + document: { createElement: element }, window: { innerHeight: 800 }, + activeEntry: () => ({ pdf: {}, pageCount: 2, pageSizes: {}, chosen: new Set([1]) }), + placeOnPaper: () => ({ ratio: 595 / 842, left: 0, top: 0, width: 1, height: 1 }), + drawPageInto(entry, page, holder) { draws.push(page); holder.appendChild(element()); }, +}; +vm.runInNewContext(code, box); +for (const page of [1, 1, 2]) { + box.openPageView(page); + ok(!ids.pageView.hidden && box.viewPage === page, "opens page " + page); + ok(ids.pvStage.children.length === 1 && draws.at(-1) === page, "renders the requested page"); + box.closePageView(); + ok(ids.pageView.hidden && box.viewPage === 0, "hides and resets the view"); + ok(ids.pvStage.children.length === 0, "releases the large preview subtree"); +} +box.closePageView(); +ok(ids.pvStage.children.length === 0, "closing an already closed view is harmless"); +console.log(n + " checks passed");