From fb06fb8c38f8578597e28c861824ad5e0004c34e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8F=E6=99=93?= Date: Mon, 27 Mar 2023 16:58:53 +0800 Subject: [PATCH 1/2] fix: resolve hydration error --- app/api/chat-stream/route.ts | 1 - app/components/home.tsx | 12 +++++++++++- app/components/settings.tsx | 2 +- app/components/userRole.tsx | 0 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 app/components/userRole.tsx diff --git a/app/api/chat-stream/route.ts b/app/api/chat-stream/route.ts index 8803a4252..ad40c6be1 100644 --- a/app/api/chat-stream/route.ts +++ b/app/api/chat-stream/route.ts @@ -1,4 +1,3 @@ -import type { ChatRequest } from "../chat/typing"; import { createParser } from "eventsource-parser"; import { NextRequest } from "next/server"; diff --git a/app/components/home.tsx b/app/components/home.tsx index 1265149a1..ffe813e0d 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -465,6 +465,16 @@ function showMemoryPrompt(session: ChatSession) { }); } +const useHasHydrated = () => { + const [hasHydrated, setHasHydrated] = useState(false); + + useEffect(() => { + setHasHydrated(true); + }, []); + + return hasHydrated; +}; + export function Home() { const [createNewSession, currentIndex, removeSession] = useChatStore( (state) => [ @@ -473,7 +483,7 @@ export function Home() { state.removeSession, ] ); - const loading = !useChatStore?.persist?.hasHydrated(); + const loading = !useHasHydrated(); const [showSideBar, setShowSideBar] = useState(true); // setting diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 56165daa2..eb9bc6d49 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -354,7 +354,7 @@ export function Settings(props: { closeSettings: () => void }) { updateConfig( diff --git a/app/components/userRole.tsx b/app/components/userRole.tsx new file mode 100644 index 000000000..e69de29bb From 9570691d5b9eec83b4d6bb66716409039054d68e Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Mon, 27 Mar 2023 21:52:50 +0800 Subject: [PATCH 2/2] Delete userRole.tsx --- app/components/userRole.tsx | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/components/userRole.tsx diff --git a/app/components/userRole.tsx b/app/components/userRole.tsx deleted file mode 100644 index e69de29bb..000000000