diff --git a/src/htmx.js b/src/htmx.js index 364b80aa9..94991e131 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -1697,6 +1697,7 @@ var htmx = (() => { } __handleHistoryUpdate(ctx) { + if (!this.config.history) return; let action = this.__resolveHistoryAction(ctx); if (!action) return; diff --git a/test/tests/ext/hx-history-cache.js b/test/tests/ext/hx-history-cache.js index 2e00fa89b..f9b3002fe 100644 --- a/test/tests/ext/hx-history-cache.js +++ b/test/tests/ext/hx-history-cache.js @@ -49,6 +49,21 @@ describe('hx-history-cache extension', function () { // saveCurrentPage / basic read-back // ------------------------------------------------------------------------- + it('does not cache a page when history is disabled', async function () { + let originalHistory = htmx.config.history; + htmx.config.history = false; + mockResponse('GET', '/page2', '

page 2

'); + let button = createProcessedHTML(''); + + try { + button.click(); + await forRequest(); + assert.deepEqual(readCache(), []); + } finally { + htmx.config.history = originalHistory; + } + }); + it('saves current page on htmx:before:history:update', async function () { let savedDetail = null; document.addEventListener('htmx:history:cache:after:save', e => { savedDetail = e.detail; }, { once: true });