From 08b2228a4319af3e33005b7ecece41328ddf6a1d Mon Sep 17 00:00:00 2001 From: Emile Bangma Date: Thu, 19 Jun 2025 19:45:25 +0000 Subject: [PATCH 1/5] fix(explorer): prevent tree duplication when rapidly navigating --- quartz/components/scripts/explorer.inline.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/quartz/components/scripts/explorer.inline.ts b/quartz/components/scripts/explorer.inline.ts index 9c8341169..e738739a8 100644 --- a/quartz/components/scripts/explorer.inline.ts +++ b/quartz/components/scripts/explorer.inline.ts @@ -263,6 +263,9 @@ document.addEventListener("prenav", async () => { const explorer = document.querySelector(".explorer-ul") if (!explorer) return sessionStorage.setItem("explorerScrollTop", explorer.scrollTop.toString()) + if (!currentExplorerState) return + const stringifiedFileTree = JSON.stringify(currentExplorerState) + localStorage.setItem("fileTree", stringifiedFileTree) }) document.addEventListener("nav", async (e: CustomEventMap["nav"]) => { From b31acc6f0f7d38b64c466b8a8c41cd5a845ae7c8 Mon Sep 17 00:00:00 2001 From: Emile Bangma Date: Thu, 19 Jun 2025 22:12:50 +0200 Subject: [PATCH 2/5] Only write tree to localStorage during prenav event --- quartz/components/scripts/explorer.inline.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/quartz/components/scripts/explorer.inline.ts b/quartz/components/scripts/explorer.inline.ts index e738739a8..d02fc91b9 100644 --- a/quartz/components/scripts/explorer.inline.ts +++ b/quartz/components/scripts/explorer.inline.ts @@ -74,9 +74,6 @@ function toggleFolder(evt: MouseEvent) { collapsed: isCollapsed, }) } - - const stringifiedFileTree = JSON.stringify(currentExplorerState) - localStorage.setItem("fileTree", stringifiedFileTree) } function createFileNode(currentSlug: FullSlug, node: FileTrieNode): HTMLLIElement { From 50b6c217c61236c529a80280f06b02d7a22c6c66 Mon Sep 17 00:00:00 2001 From: Emile Bangma Date: Thu, 19 Jun 2025 22:52:06 +0200 Subject: [PATCH 3/5] Copilot suggestion Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- quartz/components/scripts/explorer.inline.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quartz/components/scripts/explorer.inline.ts b/quartz/components/scripts/explorer.inline.ts index d02fc91b9..4c6717458 100644 --- a/quartz/components/scripts/explorer.inline.ts +++ b/quartz/components/scripts/explorer.inline.ts @@ -262,7 +262,7 @@ document.addEventListener("prenav", async () => { sessionStorage.setItem("explorerScrollTop", explorer.scrollTop.toString()) if (!currentExplorerState) return const stringifiedFileTree = JSON.stringify(currentExplorerState) - localStorage.setItem("fileTree", stringifiedFileTree) + sessionStorage.setItem("fileTree", stringifiedFileTree) }) document.addEventListener("nav", async (e: CustomEventMap["nav"]) => { From 6b05c6ba64d849b492454693421aeda3a9e12dba Mon Sep 17 00:00:00 2001 From: Emile Bangma Date: Thu, 19 Jun 2025 22:55:30 +0200 Subject: [PATCH 4/5] Fixing Copilot suggestion --- quartz/components/scripts/explorer.inline.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quartz/components/scripts/explorer.inline.ts b/quartz/components/scripts/explorer.inline.ts index 4c6717458..f23f4df07 100644 --- a/quartz/components/scripts/explorer.inline.ts +++ b/quartz/components/scripts/explorer.inline.ts @@ -163,7 +163,7 @@ async function setupExplorer(currentSlug: FullSlug) { } // Get folder state from local storage - const storageTree = localStorage.getItem("fileTree") + const storageTree = sessionStorage.getItem("fileTree") const serializedExplorerState = storageTree && opts.useSavedState ? JSON.parse(storageTree) : [] const oldIndex = new Map( serializedExplorerState.map((entry: FolderState) => [entry.path, entry.collapsed]), From b0560711ed5b158622c9b47125b5c2ea072ddfad Mon Sep 17 00:00:00 2001 From: Emile Bangma Date: Thu, 19 Jun 2025 22:57:21 +0200 Subject: [PATCH 5/5] Fix comment --- quartz/components/scripts/explorer.inline.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quartz/components/scripts/explorer.inline.ts b/quartz/components/scripts/explorer.inline.ts index f23f4df07..a8a5065a9 100644 --- a/quartz/components/scripts/explorer.inline.ts +++ b/quartz/components/scripts/explorer.inline.ts @@ -162,7 +162,7 @@ async function setupExplorer(currentSlug: FullSlug) { mapFn: new Function("return " + (dataFns.mapFn || "undefined"))(), } - // Get folder state from local storage + // Get folder state from session storage const storageTree = sessionStorage.getItem("fileTree") const serializedExplorerState = storageTree && opts.useSavedState ? JSON.parse(storageTree) : [] const oldIndex = new Map(