From ed2ae3a25b876532f76d56a449e9e7bd7a5d5912 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sun, 5 Nov 2023 12:39:49 +0530 Subject: [PATCH] chore: clear local search cache on hmr --- src/client/theme-default/components/VPLocalSearchBox.vue | 5 +++++ src/client/theme-default/support/lru.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/client/theme-default/components/VPLocalSearchBox.vue b/src/client/theme-default/components/VPLocalSearchBox.vue index 07b1bd15..24dac640 100644 --- a/src/client/theme-default/components/VPLocalSearchBox.vue +++ b/src/client/theme-default/components/VPLocalSearchBox.vue @@ -148,6 +148,11 @@ const cache = new LRUCache>(16) // 16 files debouncedWatch( () => [searchIndex.value, filterText.value, showDetailedList.value] as const, async ([index, filterTextValue, showDetailedListValue], old, onCleanup) => { + + if (old?.[0] !== index) { // in case of hmr + cache.clear() + } + let canceled = false onCleanup(() => { canceled = true diff --git a/src/client/theme-default/support/lru.ts b/src/client/theme-default/support/lru.ts index bad3f2b4..b6673512 100644 --- a/src/client/theme-default/support/lru.ts +++ b/src/client/theme-default/support/lru.ts @@ -30,4 +30,8 @@ export class LRUCache { first(): K | undefined { return this.cache.keys().next().value } + + clear(): void { + this.cache.clear() + } }