From bfb10ad20449471955a6424ecda82028b10ab47f Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Thu, 21 Aug 2025 03:57:47 +0200 Subject: [PATCH] Fix app storage "null" and "undefined" value handling --- src/base/hooks/useStorage.tsx | 8 +++++++- src/lib/storage/AppStorage.ts | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/base/hooks/useStorage.tsx b/src/base/hooks/useStorage.tsx index 0a565a59..bac98234 100644 --- a/src/base/hooks/useStorage.tsx +++ b/src/base/hooks/useStorage.tsx @@ -52,7 +52,13 @@ function useStorage( return initialState; } - return jsonSaveParse(storedValueRaw) ?? storedValueRaw; + const parsedValue = jsonSaveParse(storedValueRaw); + + if (storedValueRaw === 'null' || storedValueRaw === 'undefined') { + return parsedValue; + } + + return parsedValue ?? storedValueRaw; }, [storedValueRaw, key]); return [storedValue, setValue]; diff --git a/src/lib/storage/AppStorage.ts b/src/lib/storage/AppStorage.ts index d9fd085a..b3c8e079 100644 --- a/src/lib/storage/AppStorage.ts +++ b/src/lib/storage/AppStorage.ts @@ -17,7 +17,13 @@ export class Storage { return defaultValue; } - return jsonSaveParse(value) ?? (value as T); + const parsedValue = jsonSaveParse(value); + + if (value === 'null' || value === 'undefined') { + return parsedValue; + } + + return parsedValue ?? (value as T); } getItem(key: string): string | null {