Skip to content

Commit b092864

Browse files
unregister old service worker
1 parent 0d816ec commit b092864

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

docs/.vitepress/theme/components/ExtendedLayout.vue

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { useData } from 'vitepress'
33
import DefaultTheme from 'vitepress/theme'
4-
import { nextTick, provide } from 'vue'
4+
import { nextTick, provide, onMounted } from 'vue'
55
import NotFound from './NotFound.vue'
66
import Annoucement from './Annoucement.vue'
77
@@ -40,6 +40,27 @@ provide('toggle-appearance', async ({ clientX: x, clientY: y }: MouseEvent) => {
4040
}
4141
)
4242
})
43+
44+
async function removeOldServiceWorker() {
45+
try {
46+
if (window.navigator && navigator.serviceWorker) {
47+
navigator.serviceWorker.getRegistrations()
48+
.then((registrations) => {
49+
for (const registration of registrations) {
50+
registration.unregister()
51+
}
52+
})
53+
}
54+
}
55+
catch (error) {
56+
console.error('Failed to remove service worker.')
57+
console.error(error)
58+
}
59+
}
60+
61+
onMounted(() => {
62+
removeOldServiceWorker();
63+
})
4364
</script>
4465

4566
<template>

0 commit comments

Comments
 (0)