From 5f265344964a2a017b968872475b11d8613884fc Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 12 Jan 2023 15:17:46 +0000 Subject: [PATCH 1/3] Use IndexedDB storage in dev mode, just without the worker As per comment, we can't use workers in Vite dev mode. We previously fell back to the memory store but this ends up with it working significantly differently in dev mode to production, eg. dev mode would always start by doing an initial sync, so old to-device messages would arrive again. There's no need to fall all the way back to the memory store though, we can use the IndexedDB store without the worker. --- src/matrix-utils.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/matrix-utils.ts b/src/matrix-utils.ts index 3e01d162..dc557027 100644 --- a/src/matrix-utils.ts +++ b/src/matrix-utils.ts @@ -94,12 +94,17 @@ export async function initClient( const storeOpts = {} as ICreateClientOpts; - if (indexedDB && localStorage && !import.meta.env.DEV) { + if (indexedDB && localStorage) { storeOpts.store = new IndexedDBStore({ indexedDB: window.indexedDB, localStorage, dbName: SYNC_STORE_NAME, - workerFactory: () => new IndexedDBWorker(), + // We can't use the worker in dev mode because Vite simply doesn't bundle workers + // in dev mode: it expects them to use native modules. Ours don't, and even then only + // Chrome supports it. (It bundles them fine in production mode.) + workerFactory: import.meta.env.DEV + ? undefined + : () => new IndexedDBWorker(), }); } else if (localStorage) { storeOpts.store = new MemoryStore({ localStorage }); From d9b0e08ea2a3cb87f79f4507ece3f4bc147d5380 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 12 Jan 2023 16:20:37 +0000 Subject: [PATCH 2/3] Fix caching headers on Docker image --- config/nginx.conf | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/config/nginx.conf b/config/nginx.conf index 2af6c30c..f7253465 100644 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -2,9 +2,24 @@ server { listen 8080; server_name localhost; + root /app; + location / { - root /app; + # disable cache entriely by default (apart from Etag which is accurate enough) + add_header Cache-Control 'private no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; + if_modified_since off; + expires off; + # also turn off last-modified since they are just the timestamps of the file in the docker image + # and may or may not bear any resemblance to when the resource changed + add_header Last-Modified ""; + try_files $uri /$uri /index.html; } + + # assets can be cached because they have hashed filenames + location /assets { + expires 1w; + add_header Cache-Control "public, no-transform"; + } } From a5977fc9924235ff007c88ad201b3baf6e6609df Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 13 Jan 2023 11:52:40 +0000 Subject: [PATCH 3/3] Rename to useCallViewKeyboardShortcuts --- src/room/InCallView.tsx | 4 ++-- ...seKeyboardShortcuts.ts => useCallViewKeyboardShortcuts.ts} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/{useKeyboardShortcuts.ts => useCallViewKeyboardShortcuts.ts} (98%) diff --git a/src/room/InCallView.tsx b/src/room/InCallView.tsx index 2969c9a8..22145012 100644 --- a/src/room/InCallView.tsx +++ b/src/room/InCallView.tsx @@ -63,7 +63,7 @@ import { usePrefersReducedMotion } from "../usePrefersReducedMotion"; import { ParticipantInfo } from "./useGroupCall"; import { TileDescriptor } from "../video-grid/TileDescriptor"; import { AudioSink } from "../video-grid/AudioSink"; -import { useKeyboardShortcuts } from "../useKeyboardShortcuts"; +import { useCallViewKeyboardShortcuts } from "../useCallViewKeyboardShortcuts"; const canScreenshare = "getDisplayMedia" in (navigator.mediaDevices ?? {}); // There is currently a bug in Safari our our code with cloning and sending MediaStreams @@ -144,7 +144,7 @@ export function InCallView({ const { hideScreensharing } = useUrlParams(); - useKeyboardShortcuts( + useCallViewKeyboardShortcuts( !feedbackModalState.isOpen, toggleMicrophoneMuted, toggleLocalVideoMuted, diff --git a/src/useKeyboardShortcuts.ts b/src/useCallViewKeyboardShortcuts.ts similarity index 98% rename from src/useKeyboardShortcuts.ts rename to src/useCallViewKeyboardShortcuts.ts index b9d69ec8..ccad6a8e 100644 --- a/src/useKeyboardShortcuts.ts +++ b/src/useCallViewKeyboardShortcuts.ts @@ -19,7 +19,7 @@ import { useCallback, useState } from "react"; import { getSetting } from "./settings/useSetting"; import { useEventTarget } from "./useEvents"; -export function useKeyboardShortcuts( +export function useCallViewKeyboardShortcuts( enabled: boolean, toggleMicrophoneMuted: () => void, toggleLocalVideoMuted: () => void,