From 5c8ae4d6d7afdbe3a8c8c987e89200e424e6f66d Mon Sep 17 00:00:00 2001 From: Octopus Date: Fri, 15 May 2026 09:52:51 +0800 Subject: [PATCH] fix: always re-fetch access code config when settings dialog opens (#816) When ACCESS_CODE_LIST is configured on the server, the settings dialog was not showing the access code input field in two cases: 1. Stale localStorage cache: if a user had previously visited without ACCESS_CODE_LIST enabled, the cached value of accessCodeRequired=false would be used indefinitely, hiding the password input. 2. Race condition on first visit: the dialog could open triggered by an auth error before the async fetch to /api/config completed, showing a blank settings dialog with no access code field. Fix by re-fetching /api/config whenever the dialog opens (on open change) instead of only once on mount with a cache guard. The cached value in localStorage is still updated on success, keeping the fast initial render intact while ensuring the dialog always reflects the server configuration. Fixes #811 Co-authored-by: octo-patch --- components/settings-dialog.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/components/settings-dialog.tsx b/components/settings-dialog.tsx index c065651..75064b1 100644 --- a/components/settings-dialog.tsx +++ b/components/settings-dialog.tsx @@ -134,8 +134,11 @@ function SettingsContent({ const [isApplyingProxy, setIsApplyingProxy] = useState(false) useEffect(() => { - // Only fetch if not cached in localStorage - if (getStoredAccessCodeRequired() !== null) return + // Re-fetch config whenever the dialog opens to ensure we always show + // the access code input if the server requires it. This fixes the case + // where a stale localStorage cache (from before ACCESS_CODE_LIST was + // configured) would hide the access code input. + if (!open) return fetch(getApiEndpoint("/api/config")) .then((res) => { @@ -151,10 +154,9 @@ function SettingsContent({ setAccessCodeRequired(required) }) .catch(() => { - // Don't cache on error - allow retry on next mount - setAccessCodeRequired(false) + // Keep existing cached value on error }) - }, []) + }, [open]) // Detect current language from pathname useEffect(() => {