From c5a7ca6d35b4daffdf8d34bf6e185b20a65e4fa5 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 30 Sep 2026 07:05:26 +0800 Subject: [PATCH] fix: refresh announcements whenever drawer opens --- web/public/cloud/announcements.js | 7 ++-- web/resources/views/venix/layout_assets.tpl | 2 +- web/tests/AnnouncementDrawerBehaviorTest.mjs | 44 ++++++++++++++++---- web/tests/UserAnnouncementDrawerViewTest.php | 2 + 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/web/public/cloud/announcements.js b/web/public/cloud/announcements.js index 6aec472a..4d8e432a 100644 --- a/web/public/cloud/announcements.js +++ b/web/public/cloud/announcements.js @@ -240,10 +240,9 @@ function open(opener) { dialog.showModal(); byId('panel-announcements-close').focus({ preventScroll: true }); document.querySelectorAll('[data-announcements-open]').forEach(button => button.setAttribute('aria-expanded', 'true')); - // Opening an existing snapshot only resumes the timer. It must not flash a - // refresh state or throw away content merely because the drawer was reopened. - if (state.pagination) scheduleRefresh(); - else void load(1, 'initial'); + // Every open checks for current publications immediately. Existing content + // remains visible and this revalidation stays silent until new data arrives. + void load(1, state.pagination ? 'auto' : 'initial'); } if (dialog) { diff --git a/web/resources/views/venix/layout_assets.tpl b/web/resources/views/venix/layout_assets.tpl index 637796fd..b64cdb4a 100644 --- a/web/resources/views/venix/layout_assets.tpl +++ b/web/resources/views/venix/layout_assets.tpl @@ -1,2 +1,2 @@ {* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *} -{assign var=venix_asset_version value='2026093010' scope='global'} +{assign var=venix_asset_version value='2026093011' scope='global'} diff --git a/web/tests/AnnouncementDrawerBehaviorTest.mjs b/web/tests/AnnouncementDrawerBehaviorTest.mjs index dbe71589..8b09ce5b 100644 --- a/web/tests/AnnouncementDrawerBehaviorTest.mjs +++ b/web/tests/AnnouncementDrawerBehaviorTest.mjs @@ -141,24 +141,54 @@ function assertQuiet(test) { assert.equal(test.nodes.list.replacements, renders, 'Server generation timestamps alone do not redraw content.'); assert.equal(test.nodes.scroll.scrollWrites, scrollWrites, 'Unchanged data must not move the scroll position.'); await test.click('close'); await test.advance(90000); assert.equal(test.requests.length, 2); - await test.click('open'); assert.equal(test.requests.length, 2, 'Reopening a loaded drawer uses its snapshot.'); - await test.advance(30000); assert.equal(test.requests.length, 3); + const snapshot = test.nodes.list.textContent; const readTime = test.nodes['read-time'].textContent; + await test.click('open'); assert.equal(test.requests.length, 3, 'Reopening immediately revalidates the existing snapshot.'); + assert.equal(test.nodes.list.textContent, snapshot); assert.equal(test.nodes['read-time'].textContent, readTime); + assert.equal(test.nodes.refresh.disabled, false); assert.equal(test.nodes.list.getAttribute('aria-busy'), 'false'); assertQuiet(test); + await test.click('open'); await test.click('refresh'); + assert.equal(test.requests.length, 3, 'Repeated clicks while refresh is pending do not create concurrent requests.'); + await test.advance(5000); await test.respond(page([unsafe])); + assert.equal(test.nodes['read-time'].textContent, '读取于 06:30:55'); + assert.equal(test.nodes.list.replacements, renders); assert.equal(test.nodes.scroll.scrollWrites, scrollWrites); assertQuiet(test); + await test.advance(29999); assert.equal(test.requests.length, 3, 'Polling resumes thirty seconds after completion, not opening.'); + await test.advance(1); assert.equal(test.requests.length, 4); await test.respond(page([announcement(1, { body: '已更新' })])); assert.match(test.nodes.list.textContent, /已更新/); assert.equal(test.nodes.scroll.scrollTop, 173); assertQuiet(test); } -// Empty responses are valid snapshots, not a reason to refetch on every opening. +// Empty responses remain visible snapshots while reopening silently revalidates them. { const test = fixture(); await test.click('open'); await test.respond(page([])); assert.match(test.nodes.list.textContent, /暂无已发布/); assertQuiet(test); - await test.click('close'); await test.click('open'); assert.equal(test.requests.length, 1); - await test.advance(30000); await test.respond(page([])); assert.equal(test.requests.length, 2); assertQuiet(test); + const renders = test.nodes.list.replacements; + await test.click('close'); await test.click('open'); assert.equal(test.requests.length, 2); + assert.match(test.nodes.list.textContent, /暂无已发布/); assert.equal(test.nodes.refresh.disabled, false); assertQuiet(test); + await test.respond(page([])); assert.equal(test.nodes.list.replacements, renders); assertQuiet(test); await test.advance(30000); await test.respond(page([announcement(1)])); assert.equal(articles(test).length, 1); await test.advance(30000); await test.respond(page([])); assert.equal(articles(test).length, 0); assert.match(test.nodes.list.textContent, /暂无已发布/); assertQuiet(test); } +// A fast close aborts an opening refresh; reopening can complete before its late response. +{ + const test = fixture(); await test.click('open'); await test.respond(page([announcement(1)])); + const readTime = test.nodes['read-time'].textContent; + await test.click('close'); await test.click('open'); assert.equal(test.requests.length, 2); + const cancelled = test.requests.at(-1); await test.click('close'); + assert.equal(cancelled.options.signal.aborted, true); + await test.advance(1000); await test.click('open'); assert.equal(test.requests.length, 3); + assert.equal(test.nodes['read-time'].textContent, readTime); assertQuiet(test); + await test.respond(page([announcement(2)]), 200, test.requests.at(-1)); + assert.equal(articles(test)[0].dataset.announcementId, '2'); + assert.equal(test.nodes['read-time'].textContent, '读取于 06:27:21'); + const renders = test.nodes.list.replacements; + await test.advance(1000); await test.respond(page([announcement(3)]), 200, cancelled); + assert.equal(articles(test)[0].dataset.announcementId, '2'); + assert.equal(test.nodes['read-time'].textContent, '读取于 06:27:21'); + assert.equal(test.nodes.list.replacements, renders); assertQuiet(test); +} + // Only a complete successful read updates the independent timestamp, never status text. { const test = fixture(); const readTime = test.nodes['read-time']; @@ -284,12 +314,12 @@ function assertQuiet(test) { const closeRequest = test.requests.at(-1); await test.click('close'); assert.equal(closeRequest.options.signal.aborted, true); await test.advance(90000); assert.equal(test.requests.length, 4); - await test.click('open'); + await test.click('open'); assert.equal(test.requests.length, 5); // It is open again when the old response arrives, so the serial/abort guard // (not merely dialog.open) must reject that response. await test.respond(page([announcement(3)]), 200, closeRequest); assert.equal(articles(test)[0].dataset.announcementId, '2'); - await test.advance(30000); + await test.advance(1000); const pagehideRequest = test.requests.at(-1); await test.lifecycle('pagehide'); assert.equal(pagehideRequest.options.signal.aborted, true); await test.respond(page([announcement(4)]), 200, pagehideRequest); diff --git a/web/tests/UserAnnouncementDrawerViewTest.php b/web/tests/UserAnnouncementDrawerViewTest.php index d6f04730..b43cbc4e 100644 --- a/web/tests/UserAnnouncementDrawerViewTest.php +++ b/web/tests/UserAnnouncementDrawerViewTest.php @@ -100,6 +100,8 @@ $assert(str_contains($script, '/api/v1/announcements?page=') && !str_contains($s && !str_contains($script, 'from \'./runtime.js\''), 'Announcements must not depend on a VM session.'); $assert(str_contains($script, "item.status !== 'published'") && str_contains($script, 'visibilitychange'), 'Visible drawers must revalidate published content without background polling when hidden.'); +$assert(str_contains($script, "void load(1, state.pagination ? 'auto' : 'initial');"), + 'Every drawer open must immediately revalidate existing content without displaying progress.'); foreach (['旧内容', '正在刷新', '正在读取最新公告', '正在加载更多公告'] as $retiredMessage) { $assert(!str_contains($script, $retiredMessage), 'Retired announcement status message remains: ' . $retiredMessage); }