From a1110af6d549e2e3b5cd33912e0a6389d7bdf326 Mon Sep 17 00:00:00 2001 From: Timo Date: Tue, 27 May 2025 17:38:54 +0200 Subject: [PATCH] Fix the actual leaving issue --- src/useLocalStorage.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/useLocalStorage.ts b/src/useLocalStorage.ts index b9ae562b..1394e0d3 100644 --- a/src/useLocalStorage.ts +++ b/src/useLocalStorage.ts @@ -42,6 +42,14 @@ export const useLocalStorage = ( }; export const setLocalStorageItem = (key: string, value: string): void => { + // Avoid unnecessary updates. Not avoiding them so can cause unexpected state updates across hooks. + // For instance: + // - In call view uses useRoomEncryptionSystem + // - This will set the key again. + // - All other instances of useRoomEncryptionSystem will now do a useMemo update of the e2eeSystem + // - because the dependency `storedPassword = useInternalRoomSharedKey(roomId);` would change. + if (localStorage.getItem(key) === value) return; + localStorage.setItem(key, value); localStorageBus.emit(key, value); };