A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(app): clear app shell timers, drop unused worker routes
Hampuse2af52ffba6c
diff --git a/fluxer_app/src/features/platform/service_worker/WorkerAppShell.ts b/fluxer_app/src/features/platform/service_worker/WorkerAppShell.tsindex aa2002e65..45ab95cb8 100644--- a/fluxer_app/src/features/platform/service_worker/WorkerAppShell.ts+++ b/fluxer_app/src/features/platform/service_worker/WorkerAppShell.ts@@ -10,7 +10,7 @@ export interface PrecacheEntry {}export interface AppShellRuntime {- readonly caches: CacheStorage | undefined;+ readonly caches: {open(name: string): Promise<Pick<Cache, 'match' | 'put'>>} | undefined;readonly fetch: (request: Request) => Promise<Response>;readonly origin: string;readonly precacheName: string;@@ -23,10 +23,6 @@ export function isCacheableResponse(response: Response): boolean {return response.ok || response.type === 'opaque';}-export function isAppShellResponse(response: Response): boolean {- return response.ok && response.headers.get(APP_SHELL_MARKER_HEADER) === '1';-}-export async function precacheAssets(runtime: AppShellRuntime, manifest: ReadonlyArray<PrecacheEntry>): Promise<void> {if (!runtime.caches) {return;@@ -52,7 +48,7 @@ async function readAppShell(runtime: AppShellRuntime): Promise<Response | undefi}async function storeAppShell(runtime: AppShellRuntime, response: Response): Promise<void> {- if (!runtime.caches || !isAppShellResponse(response)) {+ if (!runtime.caches || !response.ok || response.headers.get(APP_SHELL_MARKER_HEADER) !== '1') {return;}try {@@ -73,27 +69,32 @@ export async function seedAppShell(runtime: AppShellRuntime): Promise<void> {}export async function fetchAppShellNavigation(runtime: AppShellRuntime, request: Request): Promise<Response> {+ let timeoutId: ReturnType<typeof setTimeout> | undefined;const timeout = new Promise<Response | undefined>((resolve) => {- setTimeout(() => resolve(undefined), runtime.networkTimeoutMs);- });- const network = runtime.fetch(request).then(async (response) => {- await storeAppShell(runtime, response);- return response;+ timeoutId = setTimeout(() => resolve(undefined), runtime.networkTimeoutMs);});- let networkResponse: Response | undefined;try {- networkResponse = await Promise.race([network, timeout]);- if (networkResponse && isCacheableResponse(networkResponse)) {+ const network = runtime.fetch(request).then(async (response) => {+ await storeAppShell(runtime, response);+ return response;+ });+ let networkResponse: Response | undefined;+ try {+ networkResponse = await Promise.race([network, timeout]);+ if (networkResponse && isCacheableResponse(networkResponse)) {+ return networkResponse;+ }+ } catch {}+ const cached = await readAppShell(runtime);+ if (cached) {+ network.catch(() => undefined);+ return cached;+ }+ if (networkResponse) {return networkResponse;}- } catch {}- const cached = await readAppShell(runtime);- if (cached) {- network.catch(() => undefined);- return cached;- }- if (networkResponse) {- return networkResponse;+ return network;+ } finally {+ clearTimeout(timeoutId);}- return network;}diff --git a/fluxer_app/src/features/platform/service_worker/WorkerNavigation.ts b/fluxer_app/src/features/platform/service_worker/WorkerNavigation.tsindex 7066e07db..390e10f30 100644--- a/fluxer_app/src/features/platform/service_worker/WorkerNavigation.ts+++ b/fluxer_app/src/features/platform/service_worker/WorkerNavigation.ts@@ -19,9 +19,7 @@ const APP_NAVIGATION_EXACT_PATHS = new Set(['/you','/report','/premium-callback',- '/age-verification-callback','/connection-callback',- '/theme-studio','/__notfound','/invite','/gift',