fix: forum anchor scroll — retry to override browser native scroll
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

Browser's native anchor scroll races with JS. Run doScroll at 50ms,
300ms, and 600ms after load to ensure it wins regardless of timing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-04-09 21:58:08 +02:00
parent 6ba5910c26
commit f7db1aafa0

View File

@ -1504,27 +1504,29 @@
{% block extra_js %}
// Scroll to reply anchor (e.g. from notification link #reply-55)
function scrollToReplyAnchor() {
(function() {
var hash = window.location.hash;
if (!hash || !hash.startsWith('#reply-')) return;
var target = document.getElementById(hash.substring(1));
if (!target) return;
// Disable native browser scroll-to-anchor
if ('scrollRestoration' in history) history.scrollRestoration = 'manual';
window.scrollTo(0, 0);
var headerH = document.querySelector('header');
var offset = headerH ? headerH.offsetHeight + 16 : 80;
var top = target.getBoundingClientRect().top + window.pageYOffset - offset;
window.scrollTo({ top: top, behavior: 'smooth' });
target.style.transition = 'box-shadow 0.3s ease';
target.style.boxShadow = '0 0 0 3px var(--primary-light, #4a6999)';
setTimeout(function() { target.style.boxShadow = ''; }, 3000);
}
if (document.readyState === 'complete') {
setTimeout(scrollToReplyAnchor, 100);
} else {
window.addEventListener('load', function() { setTimeout(scrollToReplyAnchor, 100); });
}
function doScroll() {
var target = document.getElementById(hash.substring(1));
if (!target) return;
var headerEl = document.querySelector('header');
var offset = headerEl ? headerEl.offsetHeight + 16 : 80;
var top = target.getBoundingClientRect().top + window.pageYOffset - offset;
window.scrollTo(0, top);
target.style.transition = 'box-shadow 0.3s ease';
target.style.boxShadow = '0 0 0 3px var(--primary-light, #4a6999)';
setTimeout(function() { target.style.boxShadow = ''; }, 3000);
}
// Run multiple times to fight browser native anchor scroll
window.addEventListener('load', function() {
setTimeout(doScroll, 50);
setTimeout(doScroll, 300);
setTimeout(doScroll, 600);
});
})();
function showToast(message, type = 'info', duration = 4000) {
const container = document.getElementById('toastContainer');