Skip to content

Commit 51a4d00

Browse files
committed
Scope htmx history to .main-container so menu survives Back
Previously, htmx cached the entire HTML body for browser back-and-forth navigation. On a history-cache miss (for example, after a historyCacheError caused by exceeding the localStorage quota), it re-fetches the page. However, for htmx requests, this re-fetch omits the top menu, effectively wiping it. Mark .main-container with hx-history-elt so htmx caches and restores only the content area. This also reduces the localStorage quota pressure. Since historyElt is limited to .main-container, it no longer contains .ck-body-wrapper. The cleanup is redundant anyway, as fa61ab1 fixed the underlying CKEditor teardown.
1 parent a019b28 commit 51a4d00

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

share/html/Elements/Header

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,15 @@
119119
hx-target="this"
120120
hx-select=".main-container"
121121
hx-swap="outerHTML"
122+
hx-history-elt
122123
<% $id && qq[id="comp-$id"] |n %>
123124
>
124125
<& /Widgets/Spinner &>
125126
<div id='rt-header-container'>
126127
<& Footer &>
127128
% $m->abort;
128129
% } else {
129-
<div class="<% join( ' ', @{$ARGS{'MainContainerClass'}} ) %>" <% $id && qq[id="comp-$id"] |n %>>
130+
<div class="<% join( ' ', @{$ARGS{'MainContainerClass'}} ) %>" hx-history-elt <% $id && qq[id="comp-$id"] |n %>>
130131

131132
%# To refresh main container, here we create a separated div so its hx-* attributes are not inherited.
132133
<div

share/static/js/init.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ document.addEventListener('htmx:beforeHistorySave', function(evt) {
7676
}
7777

7878
evt.detail.historyElt.querySelector('#hx-boost-spinner').classList.add('invisible');
79-
evt.detail.historyElt.querySelector('.main-container').classList.remove('refreshing');
79+
// historyElt is the .main-container itself, so clear .refreshing on it directly.
80+
evt.detail.historyElt.classList.remove('refreshing');
8081
evt.detail.historyElt.querySelectorAll('textarea.richtext').forEach(function(elt) {
8182
RT.CKEditor.instances[elt.name]?.destroy();
8283
});
83-
evt.detail.historyElt.querySelector('.ck-body-wrapper')?.remove();
8484

8585
evt.detail.historyElt.querySelectorAll('.tomselected').forEach(elt => elt.tomselect?.destroy());
8686
evt.detail.historyElt.querySelectorAll('.dropzone-init').forEach(elt => elt.dropzone?.destroy());

0 commit comments

Comments
 (0)