Changeset 6b8afb1 in Klonkt for src/views/shell.ejs


Ignore:
Timestamp:
06/19/2026 07:23:36 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
e9cfa3c
Parents:
0beafed
Message:

fix: address bar not updating on post click (htmx history off + hx-push-url no-op)

Links with their own hx-get + hx-push-url (post-card/post-tile/topnav) do not go
through the plain-link-boost and hx-push-url does nothing now that
htmx.config.historyEnabled=false. New global htmx:beforeSwap listener does its own
history.pushState based on hx-push-url of the triggering element. Programmatic
htmx.ajax (boost/popstate) has no elt with hx-push-url -> no double push.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/views/shell.ejs

    r0beafed r6b8afb1  
    498498    window.htmx.ajax('GET', here, { target: '#pcms-main', swap: 'innerHTML' });
    499499  });
     500
     501  // Links MÉT eigen hx-get + hx-push-url (post-card/post-tile/topnav/…) lopen NIET
     502  // via de boost hierboven, en hx-push-url is een no-op nu htmx-history uitstaat.
     503  // Doe daarom de adresbalk-update hier zelf zodra htmx swapt. Programmatische
     504  // htmx.ajax-calls (boost/popstate) hebben geen elt met hx-push-url → geen dubbel.
     505  document.body.addEventListener('htmx:beforeSwap', function (evt) {
     506    try {
     507      var elt = evt.detail && evt.detail.elt;
     508      if (!elt || !elt.getAttribute) return;
     509      var u = elt.getAttribute('hx-push-url');
     510      if (!u || u === 'false') return;
     511      if (u !== lastPath) history.pushState({ b: 1 }, '', u);
     512      lastPath = u;
     513    } catch (_) {}
     514  });
    500515})();
    501516</script>
Note: See TracChangeset for help on using the changeset viewer.