summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--package.json2
-rw-r--r--src/htmx.js2
-rw-r--r--test/attributes/hx-push-url.js27
-rw-r--r--test/index.html1
4 files changed, 25 insertions, 7 deletions
diff --git a/package.json b/package.json
index 76b5d653..a086fd05 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
"AJAX",
"HTML"
],
- "version": "1.2.0",
+ "version": "1.2.1",
"homepage": "https://htmx.org/",
"bugs": {
"url": "https://github.com/bigskysoftware/htmx/issues"
diff --git a/src/htmx.js b/src/htmx.js
index 4e1a4634..5f91996e 100644
--- a/src/htmx.js
+++ b/src/htmx.js
@@ -1410,7 +1410,7 @@ return (function () {
var historyCache = parseJSON(localStorage.getItem("htmx-history-cache")) || [];
for (var i = 0; i < historyCache.length; i++) {
if (historyCache[i].url === url) {
- historyCache = historyCache.slice(i, 1);
+ historyCache.splice(i, 1);
break;
}
}
diff --git a/test/attributes/hx-push-url.js b/test/attributes/hx-push-url.js
index 80f5f366..a4d7d807 100644
--- a/test/attributes/hx-push-url.js
+++ b/test/attributes/hx-push-url.js
@@ -23,8 +23,7 @@ describe("hx-push-url attribute", function() {
this.server.respond();
getWorkArea().textContent.should.equal("second")
var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME));
- cache.length.should.equal(2);
- cache[1].url.should.equal("/test");
+ cache[cache.length - 1].url.should.equal("/test");
});
it("navigation should push an element into the cache when string", function () {
@@ -78,9 +77,6 @@ describe("hx-push-url attribute", function() {
this.server.respond();
workArea.textContent.should.equal("test2")
- var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME));
-
- cache.length.should.equal(2);
htmx._('restoreHistory')("/test1")
getWorkArea().getElementsByClassName("htmx-request").length.should.equal(0);
});
@@ -149,6 +145,27 @@ describe("hx-push-url attribute", function() {
cache.length.should.equal(1);
});
+ it("does not blow out cache when saving a URL twice", function () {
+ htmx._('saveToHistoryCache')('url1', 'content', 'title', 'scroll');
+ htmx._('saveToHistoryCache')('url2', 'content', 'title', 'scroll');
+ htmx._('saveToHistoryCache')('url3', 'content', 'title', 'scroll');
+ htmx._('saveToHistoryCache')('url2', 'content', 'title', 'scroll');
+ var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME));
+ cache.length.should.equal(3);
+ });
+
+ it("history cache is LRU", function () {
+ htmx._('saveToHistoryCache')('url1', 'content', 'title', 'scroll');
+ htmx._('saveToHistoryCache')('url2', 'content', 'title', 'scroll');
+ htmx._('saveToHistoryCache')('url3', 'content', 'title', 'scroll');
+ htmx._('saveToHistoryCache')('url2', 'content', 'title', 'scroll');
+ htmx._('saveToHistoryCache')('url1', 'content', 'title', 'scroll');
+ var cache = JSON.parse(localStorage.getItem(HTMX_HISTORY_CACHE_NAME));
+ cache.length.should.equal(3);
+ cache[0].url.should.equal("url3");
+ cache[1].url.should.equal("url2");
+ cache[2].url.should.equal("url1");
+ });
it("htmx:afterSettle is called when replacing outerHTML", function () {
var called = false;
diff --git a/test/index.html b/test/index.html
index 52f6fa89..313fc98a 100644
--- a/test/index.html
+++ b/test/index.html
@@ -60,6 +60,7 @@
</ul>
<h2>Mocha Test Suite</h2>
+<a href="index.html">[ALL]</a>
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>