From d5e5662cbd3942da20ff1c9582940bce4164f921 Mon Sep 17 00:00:00 2001 From: Adrien Siami Date: Mon, 15 Jan 2024 15:18:18 +0100 Subject: [PATCH] Clear turbo cache before visiting to avoid unwanted snapshot restoration --- app/assets/javascripts/hotwire-livereload-turbo-stream.js | 1 + app/assets/javascripts/hotwire-livereload.js | 1 + app/javascript/lib/hotwire-livereload-received.js | 1 + 3 files changed, 3 insertions(+) diff --git a/app/assets/javascripts/hotwire-livereload-turbo-stream.js b/app/assets/javascripts/hotwire-livereload-turbo-stream.js index b39bc37..b6362aa 100644 --- a/app/assets/javascripts/hotwire-livereload-turbo-stream.js +++ b/app/assets/javascripts/hotwire-livereload-turbo-stream.js @@ -115,6 +115,7 @@ } else { console.log("[Hotwire::Livereload] Files changed. Reloading.."); hotwire_livereload_scroll_position_default.save(); + Turbo.cache.clear(); Turbo.visit(window.location.href, { action: "replace" }); } }, 300); diff --git a/app/assets/javascripts/hotwire-livereload.js b/app/assets/javascripts/hotwire-livereload.js index 2d35afd..43ec921 100644 --- a/app/assets/javascripts/hotwire-livereload.js +++ b/app/assets/javascripts/hotwire-livereload.js @@ -697,6 +697,7 @@ } else { console.log("[Hotwire::Livereload] Files changed. Reloading.."); hotwire_livereload_scroll_position_default.save(); + Turbo.cache.clear(); Turbo.visit(window.location.href, { action: "replace" }); } }, 300); diff --git a/app/javascript/lib/hotwire-livereload-received.js b/app/javascript/lib/hotwire-livereload-received.js index 6aee6da..de8c373 100644 --- a/app/javascript/lib/hotwire-livereload-received.js +++ b/app/javascript/lib/hotwire-livereload-received.js @@ -10,6 +10,7 @@ export default debounce(({force_reload}) => { } else { console.log("[Hotwire::Livereload] Files changed. Reloading..") scrollPosition.save() + Turbo.cache.clear() Turbo.visit(window.location.href, { action: 'replace' }) } }, 300)