Changeset 9b3e12c in Klonkt


Ignore:
Timestamp:
06/19/2026 07:28:25 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
70679063
Parents:
e9cfa3c
Message:

fix: post URL now updates in the address bar — htmx:beforeRequest instead of beforeSwap

In htmx:beforeSwap, detail.elt is the swap TARGET (#pcms-main), not the clicked link,
so hx-push-url was never found. Now using htmx:beforeRequest (detail.elt = the link)
+ closest('[hx-push-url]') for the pushState.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/views/shell.ejs

    re9cfa3c r9b3e12c  
    503503  // Doe daarom de adresbalk-update hier zelf zodra htmx swapt. Programmatische
    504504  // htmx.ajax-calls (boost/popstate) hebben geen elt met hx-push-url → geen dubbel.
    505   document.body.addEventListener('htmx:beforeSwap', function (evt) {
     505  document.body.addEventListener('htmx:beforeRequest', function (evt) {
    506506    try {
    507       var elt = evt.detail && evt.detail.elt;
    508       if (!elt || !elt.getAttribute) return;
    509       var u = elt.getAttribute('hx-push-url');
     507      var elt = evt.detail && evt.detail.elt;       // het TRIGGERENDE element (de link)
     508      if (!elt || !elt.closest) return;
     509      var node = elt.closest('[hx-push-url]');
     510      if (!node) return;
     511      var u = node.getAttribute('hx-push-url');
    510512      if (!u || u === 'false') return;
    511       if (u !== lastPath) history.pushState({ b: 1 }, '', u);
     513      if (u !== (location.pathname + location.search)) history.pushState({ b: 1 }, '', u);
    512514      lastPath = u;
    513515    } catch (_) {}
Note: See TracChangeset for help on using the changeset viewer.