useAppSettings: loadStrategies await 중 cache null 반환 버그 수정

loadStrategies() await 중 invalidateAppSettingsCache() 호출로
_cache가 null로 초기화되면 ensureLoaded()가 null을 반환.
useAppSettings에서 null.displayTimezone 접근으로 TypeError 발생.

- ensureLoaded(): return _cache → return _cache ?? {}
- useAppSettings .then(): data 대신 data ?? {} 사용

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Macbook
2026-06-02 04:05:06 +09:00
parent 6bd163d072
commit 7272d58258
+8 -5
View File
@@ -119,7 +119,9 @@ function ensureLoaded(): Promise<AppSettingsDto> {
if (generation === _loadGeneration) { if (generation === _loadGeneration) {
notifyAppSettingsListeners(); notifyAppSettingsListeners();
} }
return _cache; // loadStrategies() 등 await 중 invalidateAppSettingsCache()가 호출되면
// _cache 가 null 로 초기화될 수 있으므로 ?? {} 로 null 반환 방지
return _cache ?? {};
}); });
return _loadPromise; return _loadPromise;
} }
@@ -234,11 +236,12 @@ export function useAppSettings(sessionKey = 0) {
} }
ensureLoaded().then(data => { ensureLoaded().then(data => {
const safe = data ?? {};
if (mountedRef.current) { if (mountedRef.current) {
setSettings(data); setSettings(safe);
setDisplayTimezone(normalizeTimezone(data.displayTimezone ?? DEFAULT_DISPLAY_TIMEZONE)); setDisplayTimezone(normalizeTimezone(safe.displayTimezone ?? DEFAULT_DISPLAY_TIMEZONE));
setChartTimeFormat(normalizeChartTimeFormat(data.chartTimeFormat ?? DEFAULT_CHART_TIME_FORMAT)); setChartTimeFormat(normalizeChartTimeFormat(safe.chartTimeFormat ?? DEFAULT_CHART_TIME_FORMAT));
setTradeAlertTimeFormat(normalizeChartTimeFormat(data.tradeAlertTimeFormat ?? DEFAULT_TRADE_ALERT_TIME_FORMAT)); setTradeAlertTimeFormat(normalizeChartTimeFormat(safe.tradeAlertTimeFormat ?? DEFAULT_TRADE_ALERT_TIME_FORMAT));
setIsLoaded(true); setIsLoaded(true);
} }
}).catch(err => { }).catch(err => {