From 7272d58258fd0ff02a1dad11c11f3b07e58505c9 Mon Sep 17 00:00:00 2001 From: Macbook Date: Tue, 2 Jun 2026 04:05:06 +0900 Subject: [PATCH] =?UTF-8?q?useAppSettings:=20loadStrategies=20await=20?= =?UTF-8?q?=EC=A4=91=20cache=20null=20=EB=B0=98=ED=99=98=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit loadStrategies() await 중 invalidateAppSettingsCache() 호출로 _cache가 null로 초기화되면 ensureLoaded()가 null을 반환. useAppSettings에서 null.displayTimezone 접근으로 TypeError 발생. - ensureLoaded(): return _cache → return _cache ?? {} - useAppSettings .then(): data 대신 data ?? {} 사용 Co-authored-by: Cursor --- frontend/src/hooks/useAppSettings.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frontend/src/hooks/useAppSettings.ts b/frontend/src/hooks/useAppSettings.ts index d26ab11..fe1736c 100644 --- a/frontend/src/hooks/useAppSettings.ts +++ b/frontend/src/hooks/useAppSettings.ts @@ -119,7 +119,9 @@ function ensureLoaded(): Promise { if (generation === _loadGeneration) { notifyAppSettingsListeners(); } - return _cache; + // loadStrategies() 등 await 중 invalidateAppSettingsCache()가 호출되면 + // _cache 가 null 로 초기화될 수 있으므로 ?? {} 로 null 반환 방지 + return _cache ?? {}; }); return _loadPromise; } @@ -234,11 +236,12 @@ export function useAppSettings(sessionKey = 0) { } ensureLoaded().then(data => { + const safe = data ?? {}; if (mountedRef.current) { - setSettings(data); - setDisplayTimezone(normalizeTimezone(data.displayTimezone ?? DEFAULT_DISPLAY_TIMEZONE)); - setChartTimeFormat(normalizeChartTimeFormat(data.chartTimeFormat ?? DEFAULT_CHART_TIME_FORMAT)); - setTradeAlertTimeFormat(normalizeChartTimeFormat(data.tradeAlertTimeFormat ?? DEFAULT_TRADE_ALERT_TIME_FORMAT)); + setSettings(safe); + setDisplayTimezone(normalizeTimezone(safe.displayTimezone ?? DEFAULT_DISPLAY_TIMEZONE)); + setChartTimeFormat(normalizeChartTimeFormat(safe.chartTimeFormat ?? DEFAULT_CHART_TIME_FORMAT)); + setTradeAlertTimeFormat(normalizeChartTimeFormat(safe.tradeAlertTimeFormat ?? DEFAULT_TRADE_ALERT_TIME_FORMAT)); setIsLoaded(true); } }).catch(err => {