From dc7f91b9f65587f1b1a401d8c4cc9fcf1b429c94 Mon Sep 17 00:00:00 2001 From: viettranx Date: Mon, 23 Mar 2026 17:50:01 +0700 Subject: [PATCH] refactor(ui): simplify setup-skip storage logic Remove side-effect migration code, unnecessary encodeURIComponent, and implicit localStorage fallbacks from setup-skip utilities. --- ui/web/src/lib/setup-skip.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/ui/web/src/lib/setup-skip.ts b/ui/web/src/lib/setup-skip.ts index 4e465446..5bbcb272 100644 --- a/ui/web/src/lib/setup-skip.ts +++ b/ui/web/src/lib/setup-skip.ts @@ -14,27 +14,16 @@ function getScopePart(value: string | null | undefined, fallback: string) { } function getScopedSetupSkipKey(scope: SetupSkipScope) { - const tenantScope = getScopePart( - scope.tenantId ?? scope.tenantSlug ?? localStorage.getItem(LOCAL_STORAGE_KEYS.TENANT_ID), - "default", - ); - const userScope = getScopePart( - scope.userId ?? localStorage.getItem(LOCAL_STORAGE_KEYS.USER_ID), - "anonymous", - ); - - return `${SETUP_SKIPPED_PREFIX}${encodeURIComponent(tenantScope)}:${encodeURIComponent(userScope)}`; + const tenantScope = getScopePart(scope.tenantId ?? scope.tenantSlug, "default"); + const userScope = getScopePart(scope.userId, "anonymous"); + return `${SETUP_SKIPPED_PREFIX}${tenantScope}:${userScope}`; } export function isSetupSkipped(scope: SetupSkipScope) { - if (localStorage.getItem(LOCAL_STORAGE_KEYS.SETUP_SKIPPED) !== null) { - localStorage.removeItem(LOCAL_STORAGE_KEYS.SETUP_SKIPPED); - } return localStorage.getItem(getScopedSetupSkipKey(scope)) === "1"; } export function markSetupSkipped(scope: SetupSkipScope) { - localStorage.removeItem(LOCAL_STORAGE_KEYS.SETUP_SKIPPED); localStorage.setItem(getScopedSetupSkipKey(scope), "1"); } @@ -43,7 +32,7 @@ export function clearSetupSkippedState() { for (let i = 0; i < localStorage.length; i += 1) { const key = localStorage.key(i); if (!key) continue; - if (key === LOCAL_STORAGE_KEYS.SETUP_SKIPPED || key.startsWith(SETUP_SKIPPED_PREFIX)) { + if (key.startsWith(SETUP_SKIPPED_PREFIX)) { keysToRemove.push(key); } }