Changeset 389aa99 in Klonkt


Ignore:
Timestamp:
06/20/2026 03:20:00 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
73b41eb
Parents:
2fc9b7f
Message:

fix(nav): no "bare content" on fast/repeated back-forward

The popstate handler fired an htmx.ajax immediately on every back/forward →
on fast repeated navigation requests overlapped and a slow old response could
overwrite a newer page ("bare content"). Now: doNav() aborts any pending
request on #pcms-main first, and popstate is debounced (90ms) so fast
repeated back-forward only fetches the LAST destination. Click navigation
uses the same abort-first doNav().

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/views/shell.ejs

    r2fc9b7f r389aa99  
    478478
    479479  var lastPath = location.pathname + location.search;
     480  var navTimer = null;
     481
     482  // Eén plek voor alle programmatische navigatie-swaps. Annuleert eerst een nog
     483  // lopende request op #pcms-main (anti-race: bij snel klikken/terug-gaan kan een
     484  // trage oude response anders een nieuwe pagina overschrijven → "kale content").
     485  function doNav(dest) {
     486    try { window.htmx.trigger('#pcms-main', 'htmx:abort'); } catch (_) {}
     487    window.htmx.ajax('GET', dest, { target: '#pcms-main', swap: 'innerHTML' });
     488  }
    480489
    481490  document.addEventListener('click', function (e) {
     
    492501    if (dest !== lastPath) history.pushState({ b: 1 }, '', dest);
    493502    lastPath = dest;
    494     window.htmx.ajax('GET', dest, { target: '#pcms-main', swap: 'innerHTML' });
     503    if (navTimer) { clearTimeout(navTimer); navTimer = null; }
     504    doNav(dest);
    495505    try { window.scrollTo(0, 0); } catch (_) {}
    496506  });
     
    500510    if (here === lastPath) return;
    501511    lastPath = here;
    502     window.htmx.ajax('GET', here, { target: '#pcms-main', swap: 'innerHTML' });
     512    // Debounce: bij heel snel/herhaald terug-vooruit niet elke tussenpagina ophalen,
     513    // alleen de LAATSTE bestemming. Voorkomt overlappende swaps ("kale content").
     514    if (navTimer) clearTimeout(navTimer);
     515    navTimer = setTimeout(function () {
     516      navTimer = null;
     517      doNav(location.pathname + location.search);
     518    }, 90);
    503519  });
    504520
Note: See TracChangeset for help on using the changeset viewer.