fix(webui): reuse preview tabs for resolved file aliases

This commit is contained in:
Xubin Ren committed 2026-10-18 00:14:36 +08:00
1 parent 0869c928a2
commit 61666c495a
5 files changed
+95 -4

No files matched your search

+7 -1
View File
@@ -10,6 +10,7 @@ interface FilePreviewPanelProps {
loadPreview?: (path: string) => Promise<FilePreviewPayload>;
initialPreview?: FilePreviewPayload;
onOpenFilePreview?: (path: string) => void;
onResolvePath?: (path: string, canonicalPath: string) => void;
}
export function FilePreviewPanel({
@@ -19,6 +20,7 @@ export function FilePreviewPanel({
loadPreview,
initialPreview,
onOpenFilePreview,
onResolvePath,
}: FilePreviewPanelProps) {
const [state, setState] = useState<FilePreviewPanelState>(() => initialPreview
? { status: "ready", payload: initialPreview } : { status: "loading" });
@@ -30,6 +32,8 @@ export function FilePreviewPanel({
// when a session/path/loader change actually starts another request.
const tokenRef = useRef(token);
tokenRef.current = token;
const onResolvePathRef = useRef(onResolvePath);
onResolvePathRef.current = onResolvePath;
useEffect(() => {
let cancelled = false;
@@ -40,8 +44,10 @@ export function FilePreviewPanel({
: (previous.status === "loading" ? previous : { status: "loading" }));
(loadPreview?.(path) ?? fetchFilePreview(tokenRef.current, sessionKey, path))
.then((payload) => {
if (!cancelled) setState(previous => previous.status === "ready" && previous.payload === payload
if (cancelled) return;
setState(previous => previous.status === "ready" && previous.payload === payload
? previous : { status: "ready", payload });
onResolvePathRef.current?.(path, payload.path);
})
.catch((error: unknown) => {
if (!cancelled) setState({ status: "error",
+2 -1
View File
@@ -843,7 +843,7 @@ export function ThreadShell({
} | null>(null);
const [heroGreetingKey, setHeroGreetingKey] = useState(randomHeroGreetingKey);
const [submittedViewportTurnId, setSubmittedViewportTurnId] = useState<string | null>(null);
const { state: previewState, openFile, openWeb, selectTab, closeTab, close: closePreview, setWidth: setFilePreviewWidth } =
const { state: previewState, openFile, resolveFile, openWeb, selectTab, closeTab, close: closePreview, setWidth: setFilePreviewWidth } =
useFilePreviewState(previewSessionKey, filePreviewStore);
const [closingPreview, setClosingPreview] = useState<{ key: string; state: FilePreviewState } | null>(null);
const filePreviewClosing = closingPreview?.key === previewSessionKey;
@@ -2135,6 +2135,7 @@ export function ThreadShell({
loadPreview={filePreviews.load}
initialPreview={filePreviews.peek(activePreview.value)}
onOpenFilePreview={openFilePreview}
onResolvePath={resolveFile}
/>
) : <WebPreviewPanel key={activePreview.id} url={activePreview.value} />}
</PreviewPane>