Skip to content

Commit 4ae84ff

Browse files
authored
fix Glitch in the sidebar during navigation (#163)
1 parent 5a2165b commit 4ae84ff

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

app/javascript/controllers/sidebar_menu_controller.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { Controller } from "@hotwired/stimulus"
33
// Connects to data-controller="sidebar-menu"
44
export default class extends Controller {
55
connect() {
6-
window.addEventListener("turbo:before-visit", () => {
6+
window.addEventListener("turbo:before-cache", () => {
77
localStorage.setItem("menuScrollPositon", this.element.scrollTop);
88
});
99

10-
window.addEventListener("turbo:load", () => {
10+
window.addEventListener("turbo:before-render", () => {
11+
this.element.scrollTop = localStorage.getItem("menuScrollPositon") || 0;
12+
});
13+
window.addEventListener("turbo:render", () => {
1114
this.element.scrollTop = localStorage.getItem("menuScrollPositon") || 0;
1215
});
1316
}

app/views/components/shared/head.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def view_template
1414
csrf_meta_tags
1515
stylesheet_link_tag "https://api.fontshare.com/v2/css?f[]=general-sans@1&display=swap", data_turbo_track: "reload"
1616
stylesheet_link_tag "application", data_turbo_track: "reload"
17-
javascript_include_tag "application", data_turbo_track: "reload", defer: true
17+
javascript_include_tag "application", data_turbo_track: "reload", type: "module"
1818
end
1919
end
2020
end

0 commit comments

Comments
 (0)