From 4b1f7c260b077a9d90234814ff69a357a2165e04 Mon Sep 17 00:00:00 2001 From: Szymon Nowakowski Date: Fri, 10 Oct 2025 15:30:41 +0200 Subject: [PATCH] Fix infinite render loop, fix repertoire entry removal --- packages/common/src/Cache.ts | 4 ++-- packages/frontend/src/hooks/useCache.ts | 2 +- packages/frontend/src/routes/Repertoire.tsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/common/src/Cache.ts b/packages/common/src/Cache.ts index 2690e7a..9b434db 100644 --- a/packages/common/src/Cache.ts +++ b/packages/common/src/Cache.ts @@ -79,7 +79,7 @@ interface CacheInterface { /** * Retrieve the state currently stored in the cache for a given `key`. */ - readonly getCurrent: (key: K) => Option.Option>; + readonly getCurrent: (key: K) => State | undefined; /** * Set or update the value currently stored in the cache for a given `key` * and return the updated value. Running this effect while the state is @@ -163,7 +163,7 @@ export const make = (fetchFn: FetchFn): Cache => { }); }); - const getCurrent = (key: K) => Option.fromNullable(stateMap.get(key)); + const getCurrent = (key: K) => stateMap.get(key); const update = (key: K, action: Update) => Effect.suspend(() => { const state = stateMap.get(key); diff --git a/packages/frontend/src/hooks/useCache.ts b/packages/frontend/src/hooks/useCache.ts index 5213053..f4ec03f 100644 --- a/packages/frontend/src/hooks/useCache.ts +++ b/packages/frontend/src/hooks/useCache.ts @@ -54,7 +54,7 @@ export function useCache(cache: Cache.Cache, key: NoInfer): const subscribe = useMemo(() => cache.subscribe.bind(undefined, key), [cache.subscribe, key]); const selector = useCallback(() => cache.getCurrent(key), [cache.getCurrent, key]); - const state = useSyncExternalStore(subscribe, selector); + const state = Option.fromNullable(useSyncExternalStore(subscribe, selector)); useLayoutEffect(() => { Effect.runFork(cache.get(key)); }, [cache.get, key]); diff --git a/packages/frontend/src/routes/Repertoire.tsx b/packages/frontend/src/routes/Repertoire.tsx index dbc245f..37ddeb5 100644 --- a/packages/frontend/src/routes/Repertoire.tsx +++ b/packages/frontend/src/routes/Repertoire.tsx @@ -199,7 +199,7 @@ function EntryRow({ const removeAction = (entries: readonly Piece[]) => pipe( entries, - Array.filter((p) => p.pieceId !== piece.pieceId), + Array.remove(no - 1), ); const update = (action: (prev: readonly Piece[]) => readonly Piece[]) => Effect.gen(function* () {