From 110063871cf988d825fee834c25d6e2ded3006fc Mon Sep 17 00:00:00 2001 From: Stephen Zhou Date: Wed, 4 Mar 2026 18:18:20 +0800 Subject: [PATCH] chore: clean up sw file (#32973) --- web/app/sw.ts | 58 --------------------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 web/app/sw.ts diff --git a/web/app/sw.ts b/web/app/sw.ts deleted file mode 100644 index e01ad21004..0000000000 --- a/web/app/sw.ts +++ /dev/null @@ -1,58 +0,0 @@ -/// -/// - -import type { PrecacheEntry, SerwistGlobalConfig } from 'serwist' -import { defaultCache } from '@serwist/turbopack/worker' -import { Serwist } from 'serwist' -import { withLeadingSlash } from 'ufo' - -declare global { - // eslint-disable-next-line ts/consistent-type-definitions - interface WorkerGlobalScope extends SerwistGlobalConfig { - __SW_MANIFEST: (PrecacheEntry | string)[] | undefined - } -} - -declare const self: ServiceWorkerGlobalScope - -const scopePathname = new URL(self.registration.scope).pathname -const basePath = scopePathname.replace(/\/serwist\/$/, '').replace(/\/$/, '') -const offlineUrl = `${basePath}/_offline.html` - -const normalizeManifestUrl = (url: string): string => { - if (url.startsWith('/serwist/')) - return url.replace(/^\/serwist\//, '/') - - return withLeadingSlash(url) -} - -const manifest = self.__SW_MANIFEST?.map((entry) => { - if (typeof entry === 'string') - return normalizeManifestUrl(entry) - - return { - ...entry, - url: normalizeManifestUrl(entry.url), - } -}) - -const serwist = new Serwist({ - precacheEntries: manifest, - skipWaiting: true, - disableDevLogs: true, - clientsClaim: true, - navigationPreload: true, - runtimeCaching: defaultCache, - fallbacks: { - entries: [ - { - url: offlineUrl, - matcher({ request }) { - return request.destination === 'document' - }, - }, - ], - }, -}) - -serwist.addEventListeners()