From 8338b3ce21f3dd2d849d289156b220dfd1cb96cc Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 30 Sep 2026 01:31:35 +0800 Subject: [PATCH] fix: prevent stale admin page flash --- web/public/theme/venix/css/admin-home.css | 17 +++++++++ .../views/venix/admin/static_footer.tpl | 37 ++++++++++++++++++- web/resources/views/venix/layout_assets.tpl | 2 +- web/tests/AdminOverviewContractTest.php | 13 +++++-- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/web/public/theme/venix/css/admin-home.css b/web/public/theme/venix/css/admin-home.css index 97517214..8a1c617f 100644 --- a/web/public/theme/venix/css/admin-home.css +++ b/web/public/theme/venix/css/admin-home.css @@ -2151,6 +2151,23 @@ body.billing-detail-open { background: rgba(0, 8, 26, 0.48); } + .admin-template-body.admin-sidebar-navigating .admin-sidebar-backdrop { + background: #7e838e; + cursor: progress; + transition: none !important; + } + + .admin-template-body.admin-sidebar-navigating .app-sidebar-menu { + pointer-events: none; + transition: none !important; + } + + .admin-template-body.admin-sidebar-navigating .topbar-custom, + .admin-template-body.admin-sidebar-navigating .content-page { + visibility: hidden !important; + transition: none !important; + } + .admin-summary-grid, .admin-report-grid, .admin-day-strip, diff --git a/web/resources/views/venix/admin/static_footer.tpl b/web/resources/views/venix/admin/static_footer.tpl index a15d6144..3b0df988 100644 --- a/web/resources/views/venix/admin/static_footer.tpl +++ b/web/resources/views/venix/admin/static_footer.tpl @@ -26,6 +26,7 @@ var sidebarToggle = document.querySelector('.button-toggle-menu'); var sidebarBackdrop = document.querySelector('.admin-sidebar-backdrop'); var sidebarLinks = document.querySelectorAll('.app-sidebar-menu a'); + var sidebarNavigationPending = false; function closeSidebar() { document.body.classList.remove('admin-sidebar-open'); @@ -41,6 +42,25 @@ }); } + function resetSidebarNavigation() { + sidebarNavigationPending = false; + document.body.classList.remove('admin-sidebar-navigating'); + document.body.removeAttribute('aria-busy'); + } + + function startSidebarNavigation(target) { + if (sidebarNavigationPending) return; + + sidebarNavigationPending = true; + document.body.classList.add('admin-sidebar-navigating'); + document.body.setAttribute('aria-busy', 'true'); + window.requestAnimationFrame(function () { + window.requestAnimationFrame(function () { + window.location.assign(target.href); + }); + }); + } + if (sidebarToggle) { sidebarToggle.addEventListener('click', function () { document.body.classList.toggle('admin-sidebar-open'); @@ -48,7 +68,9 @@ } if (sidebarBackdrop) { - sidebarBackdrop.addEventListener('click', closeSidebar); + sidebarBackdrop.addEventListener('click', function () { + if (!sidebarNavigationPending) closeSidebar(); + }); } sidebarLinks.forEach(function (link) { @@ -65,8 +87,16 @@ return; } + if (sidebarNavigationPending) { + event.preventDefault(); + return; + } + var target = new URL(link.href, window.location.href); var current = new URL(window.location.href); + if (target.protocol !== 'http:' && target.protocol !== 'https:') { + return; + } if (target.origin === current.origin && target.pathname === current.pathname && target.search === current.search) { @@ -74,12 +104,17 @@ event.preventDefault(); } closeSidebar(); + return; } + + event.preventDefault(); + startSidebarNavigation(target); }); }); window.addEventListener('pageshow', function (event) { if (event.persisted) { + resetSidebarNavigation(); closeSidebarImmediately(); } }); diff --git a/web/resources/views/venix/layout_assets.tpl b/web/resources/views/venix/layout_assets.tpl index 703b773d..95740926 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='2026093002' scope='global'} +{assign var=venix_asset_version value='2026093003' scope='global'} diff --git a/web/tests/AdminOverviewContractTest.php b/web/tests/AdminOverviewContractTest.php index 288f99da..d06cecbb 100644 --- a/web/tests/AdminOverviewContractTest.php +++ b/web/tests/AdminOverviewContractTest.php @@ -121,6 +121,9 @@ $assert(preg_match('/\.admin-template-body\s*\{(?=[^}]*min-height:\s*100dvh)(?=[ && preg_match('/\.admin-template \.app-sidebar-menu\s*\{(?=[^}]*position:\s*fixed)(?=[^}]*inset:\s*0 auto 0 0)(?=[^}]*height:\s*auto)(?=[^}]*overflow-y:\s*auto)[^}]*\}/s', $styles) && preg_match('/\.admin-template-body\.admin-sidebar-open \.admin-sidebar-backdrop\s*\{(?=[^}]*position:\s*fixed)(?=[^}]*inset:\s*0\s*;)(?=[^}]*height:\s*auto)[^}]*\}/s', $styles) && str_contains($styles, '.admin-template-body.admin-sidebar-no-transition .app-sidebar-menu') + && preg_match('/\.admin-template-body\.admin-sidebar-navigating \.admin-sidebar-backdrop\s*\{(?=[^}]*background:\s*#7e838e)(?=[^}]*transition:\s*none\s*!important)[^}]*\}/s', $styles) + && preg_match('/\.admin-template-body\.admin-sidebar-navigating \.app-sidebar-menu\s*\{(?=[^}]*pointer-events:\s*none)(?=[^}]*transition:\s*none\s*!important)[^}]*\}/s', $styles) + && preg_match('/\.admin-template-body\.admin-sidebar-navigating \.topbar-custom,\s*\.admin-template-body\.admin-sidebar-navigating \.content-page\s*\{(?=[^}]*visibility:\s*hidden\s*!important)(?=[^}]*transition:\s*none\s*!important)[^}]*\}/s', $styles) && !str_contains($footer, 'measureViewportHeight') && !str_contains($footer, 'scheduleViewportHeight') && !str_contains($footer, 'window.visualViewport') @@ -134,13 +137,17 @@ $assert(preg_match('/\.admin-template-body\s*\{(?=[^}]*min-height:\s*100dvh)(?=[ && str_contains($footer, 'target.search === current.search') && str_contains($footer, 'target.hash === current.hash') && str_contains($footer, 'event.preventDefault();') + && preg_match('/function startSidebarNavigation\(target\).*?classList\.add\(\'admin-sidebar-navigating\'\).*?requestAnimationFrame\(function \(\) \{.*?requestAnimationFrame\(function \(\) \{.*?window\.location\.assign\(target\.href\);/s', $footer) + && str_contains($footer, 'if (sidebarNavigationPending)') + && str_contains($footer, "document.body.classList.remove('admin-sidebar-navigating');") + && preg_match('/window\.addEventListener\(\'pageshow\'.*?event\.persisted.*?resetSidebarNavigation\(\);.*?closeSidebarImmediately\(\);/s', $footer) && !preg_match('/link\.addEventListener\(\'click\'.*?window\.innerWidth <= 991.*?closeSidebar\(\);/s', $footer), - 'Mobile administrator navigation must cover the viewport without stale measurements and keep its overlay during cross-page navigation.'); + 'Mobile administrator navigation must cover the viewport, paint an opaque leaving state, and preserve BFCache behavior.'); $assetVersion = []; $assert(preg_match("/venix_asset_version value='([0-9]+)'/", $assets, $assetVersion) === 1 - && (int) $assetVersion[1] >= 2026093002 + && (int) $assetVersion[1] >= 2026093003 && str_contains($assets, 'cache key'), - 'This administrator asset release must use cache key 2026093002 or newer.'); + 'This administrator asset release must use cache key 2026093003 or newer.'); echo 'Administrator operational overview contracts passed.' . PHP_EOL;