function render() const html = state.items.map(item => <div class="item">$item</div> ).join(''); state.frameElement.innerHTML = html;
let state = mode: 'view', // 'view', 'refreshing' items: [], frameElement: document.getElementById('viewerframe'), ; async function fetchData() // Simulate API call return Array.from( length: 50 , (_, i) => Item $i + 1: Updated at $new Date().toLocaleTimeString() ); viewerframe mode refresh top
We need a state machine to track the "mode." function render() const html = state
// Initial load fetchData().then(data => state.items = data; render(); ); Cause: Asynchronous rendering
/* Ensure fresh renders start at top */ .viewerframe:mode-refresh scroll-behavior: auto; scroll-snap-type: none;
setInterval(() => if (dashboardMode === 'auto_refresh_top') refreshTop(); , 5000); Even with a solid pattern, problems arise. Here is your troubleshooting guide. Issue 1: The "Scroll Flash" Symptoms: The viewerframe scrolls to top, then visually jumps down, then back up. Cause: Asynchronous rendering. The scrollTop = 0 runs before the new content is fully painted. Fix: Use requestAnimationFrame or setTimeout(..., 0) .
.viewerframe > :first-child margin-top: 0;