fix(auth): stabilize hydration-dependent UI
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user