fix(auth): stabilize hydration-dependent UI

This commit is contained in:
2026-07-14 13:27:41 +08:00
parent b6551b6a5a
commit 8eaea17156
8 changed files with 175 additions and 66 deletions
@@ -1,8 +1,9 @@
"use client";
import { useEffect, useState, useSyncExternalStore } from "react";
import { useEffect, useState } from "react";
import type { LoginStatus } from "@/data/dto/auth";
import { useHasHydrated } from "@/hooks/use-has-hydrated";
import { loadSplashLatestMessagePreview } from "@/lib/chat/splash_latest_message";
import { useSplashLatestMessageCache } from "@/providers/splash-latest-message-provider";
import { Logger, Result } from "@/utils";
@@ -26,21 +27,13 @@ interface SplashLatestMessageState {
message: string | null;
}
const subscribeToHydration = () => () => undefined;
const getClientHydrationSnapshot = () => true;
const getServerHydrationSnapshot = () => false;
export function useSplashLatestMessage({
hasInitialized,
isAuthLoading,
loginStatus,
}: UseSplashLatestMessageInput): UseSplashLatestMessageOutput {
const cache = useSplashLatestMessageCache();
const hasHydrated = useSyncExternalStore(
subscribeToHydration,
getClientHydrationSnapshot,
getServerHydrationSnapshot,
);
const hasHydrated = useHasHydrated();
const [state, setState] = useState<SplashLatestMessageState>({
key: "",
loaded: false,