From 18a240cfd835a48d27ad56916077946138b16989 Mon Sep 17 00:00:00 2001 From: Yao Cai <67412196+cy948@users.noreply.github.com> Date: Tue, 24 Sep 2024 20:09:15 +0800 Subject: [PATCH] :bug: fix: fix url config import after user state init (#4072) * :bug: fix: settings import * :recycle: refactor: remove selctor * :recycle: refactor: add pr ref --- .../GlobalProvider/StoreInitialization.tsx | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/layout/GlobalProvider/StoreInitialization.tsx b/src/layout/GlobalProvider/StoreInitialization.tsx index 462b4b483a25..24345ef8ec8b 100644 --- a/src/layout/GlobalProvider/StoreInitialization.tsx +++ b/src/layout/GlobalProvider/StoreInitialization.tsx @@ -20,12 +20,14 @@ const StoreInitialization = memo(() => { useTranslation('error'); const router = useRouter(); - const [isLogin, isSignedIn, useInitUserState, importUrlShareSettings] = useUserStore((s) => [ - authSelectors.isLogin(s), - s.isSignedIn, - s.useInitUserState, - s.importUrlShareSettings, - ]); + const [isLogin, isSignedIn, useInitUserState, importUrlShareSettings, isUserStateInit] = + useUserStore((s) => [ + authSelectors.isLogin(s), + s.isSignedIn, + s.useInitUserState, + s.importUrlShareSettings, + s.isUserStateInit, + ]); const { serverConfig } = useServerConfigStore(); @@ -74,8 +76,10 @@ const StoreInitialization = memo(() => { // Import settings from the url const searchParam = useSearchParams().get(LOBE_URL_IMPORT_NAME); useEffect(() => { - importUrlShareSettings(searchParam); - }, [searchParam]); + // Why use `usUserStateInit`, + // see: https://github.com/lobehub/lobe-chat/pull/4072 + if (searchParam && isUserStateInit) importUrlShareSettings(searchParam); + }, [searchParam, isUserStateInit]); useEffect(() => { if (mobile) {