fix: fix replay loading

This commit is contained in:
Li Xin
2025-05-08 11:53:50 +08:00
parent 1c3c12d543
commit e06fe34fe6

View File

@@ -1,19 +1,25 @@
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates // Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { useEffect, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { useReplay } from "../replay";
import { fetchReplayTitle } from "./chat"; import { fetchReplayTitle } from "./chat";
export function useReplayMetadata() { export function useReplayMetadata() {
const { isReplay } = useReplay();
const [title, setTitle] = useState<string | null>(null); const [title, setTitle] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false); const isLoading = useRef(false);
const [error, setError] = useState<boolean>(false); const [error, setError] = useState<boolean>(false);
useEffect(() => { useEffect(() => {
if (title || isLoading) { if (!isReplay) {
return; return;
} }
setIsLoading(true); if (title || isLoading.current) {
return;
}
isLoading.current = true;
fetchReplayTitle() fetchReplayTitle()
.then((title) => { .then((title) => {
setError(false); setError(false);
@@ -28,8 +34,8 @@ export function useReplayMetadata() {
document.title = "DeerFlow"; document.title = "DeerFlow";
}) })
.finally(() => { .finally(() => {
setIsLoading(false); isLoading.current = false;
}); });
}, [isLoading, title]); }, [isLoading, isReplay, title]);
return { title, isLoading, hasError: error }; return { title, isLoading, hasError: error };
} }