mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-05 05:42:39 +02:00
refactor: fixed forefox rendering issues
- Updated NewChatPage to reset state when switching between chats and search spaces. - Enhanced LayoutDataProvider to reset transient slide-out panels on search space changes. - Refactored RightPanel to simplify rendering logic and remove unnecessary animations. - Cleaned up LayoutShell by removing motion components for improved performance.
This commit is contained in:
parent
d960a065b1
commit
042b42a8a0
5 changed files with 55 additions and 86 deletions
|
|
@ -276,7 +276,7 @@ export default function NewChatPage() {
|
||||||
const initializeThread = useCallback(async () => {
|
const initializeThread = useCallback(async () => {
|
||||||
setIsInitializing(true);
|
setIsInitializing(true);
|
||||||
|
|
||||||
// Reset all state when switching between chats to prevent stale data
|
// Reset all state when switching between chats/search spaces to prevent stale data
|
||||||
setMessages([]);
|
setMessages([]);
|
||||||
setThreadId(null);
|
setThreadId(null);
|
||||||
setCurrentThread(null);
|
setCurrentThread(null);
|
||||||
|
|
@ -284,8 +284,8 @@ export default function NewChatPage() {
|
||||||
setMentionedDocuments([]);
|
setMentionedDocuments([]);
|
||||||
setSidebarDocuments([]);
|
setSidebarDocuments([]);
|
||||||
setMessageDocumentsMap({});
|
setMessageDocumentsMap({});
|
||||||
clearPlanOwnerRegistry(); // Reset plan ownership for new chat
|
clearPlanOwnerRegistry();
|
||||||
closeReportPanel(); // Close report panel when switching chats
|
closeReportPanel();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (urlChatId > 0) {
|
if (urlChatId > 0) {
|
||||||
|
|
@ -346,6 +346,7 @@ export default function NewChatPage() {
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
urlChatId,
|
urlChatId,
|
||||||
|
searchSpaceId,
|
||||||
setMessageDocumentsMap,
|
setMessageDocumentsMap,
|
||||||
setMentionedDocuments,
|
setMentionedDocuments,
|
||||||
setSidebarDocuments,
|
setSidebarDocuments,
|
||||||
|
|
@ -1671,7 +1672,7 @@ export default function NewChatPage() {
|
||||||
<DeleteGoogleDriveFileToolUI />
|
<DeleteGoogleDriveFileToolUI />
|
||||||
<SandboxExecuteToolUI />
|
<SandboxExecuteToolUI />
|
||||||
{/* <WriteTodosToolUI /> Disabled for now */}
|
{/* <WriteTodosToolUI /> Disabled for now */}
|
||||||
<div className="flex h-[calc(100dvh-64px)] overflow-hidden">
|
<div key={searchSpaceId} className="flex h-[calc(100dvh-64px)] overflow-hidden">
|
||||||
<div className="flex-1 flex flex-col min-w-0 overflow-hidden">
|
<div className="flex-1 flex flex-col min-w-0 overflow-hidden">
|
||||||
<Thread messageThinkingSteps={messageThinkingSteps} />
|
<Thread messageThinkingSteps={messageThinkingSteps} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -220,14 +220,14 @@ const ThreadWelcome: FC = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="aui-thread-welcome-root mx-auto flex w-full max-w-(--thread-max-width) grow flex-col items-center px-4 relative">
|
<div className="aui-thread-welcome-root mx-auto flex w-full max-w-(--thread-max-width) grow flex-col items-center px-4 relative">
|
||||||
{/* Greeting positioned above the composer - fixed position */}
|
{/* Greeting positioned above the composer */}
|
||||||
<div className="aui-thread-welcome-message absolute bottom-[calc(50%+5rem)] left-0 right-0 flex flex-col items-center text-center">
|
<div className="aui-thread-welcome-message absolute bottom-[calc(50%+5rem)] left-0 right-0 flex flex-col items-center text-center">
|
||||||
<h1 className="aui-thread-welcome-message-inner fade-in slide-in-from-bottom-2 animate-in text-3xl md:text-5xl delay-100 duration-500 ease-out fill-mode-both">
|
<h1 className="aui-thread-welcome-message-inner text-3xl md:text-5xl">
|
||||||
{greeting}
|
{greeting}
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
{/* Composer - top edge fixed, expands downward only */}
|
{/* Composer - top edge fixed, expands downward only */}
|
||||||
<div className="fade-in slide-in-from-bottom-3 animate-in delay-200 duration-500 ease-out fill-mode-both w-full flex items-start justify-center absolute top-[calc(50%-3.5rem)] left-0 right-0">
|
<div className="w-full flex items-start justify-center absolute top-[calc(50%-3.5rem)] left-0 right-0">
|
||||||
<Composer />
|
<Composer />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -262,6 +262,15 @@ export function LayoutDataProvider({ searchSpaceId, children }: LayoutDataProvid
|
||||||
}
|
}
|
||||||
}, [pendingNewChat, params?.chat_id, router, searchSpaceId, resetCurrentThread]);
|
}, [pendingNewChat, params?.chat_id, router, searchSpaceId, resetCurrentThread]);
|
||||||
|
|
||||||
|
// Reset transient slide-out panels when switching search spaces.
|
||||||
|
// Some browsers can retain overlay/backdrop state across route transitions.
|
||||||
|
useEffect(() => {
|
||||||
|
setIsInboxSidebarOpen(false);
|
||||||
|
setIsAllSharedChatsSidebarOpen(false);
|
||||||
|
setIsAllPrivateChatsSidebarOpen(false);
|
||||||
|
setIsAnnouncementsSidebarOpen(false);
|
||||||
|
}, [searchSpaceId]);
|
||||||
|
|
||||||
const searchSpaces: SearchSpace[] = useMemo(() => {
|
const searchSpaces: SearchSpace[] = useMemo(() => {
|
||||||
if (!searchSpacesData || !Array.isArray(searchSpacesData)) return [];
|
if (!searchSpacesData || !Array.isArray(searchSpacesData)) return [];
|
||||||
return searchSpacesData.map((space) => ({
|
return searchSpacesData.map((space) => ({
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import { useAtom, useAtomValue, useSetAtom } from "jotai";
|
import { useAtom, useAtomValue, useSetAtom } from "jotai";
|
||||||
import { PanelRight, PanelRightClose } from "lucide-react";
|
import { PanelRight, PanelRightClose } from "lucide-react";
|
||||||
import { AnimatePresence, motion } from "motion/react";
|
|
||||||
import { startTransition, useEffect } from "react";
|
import { startTransition, useEffect } from "react";
|
||||||
import { closeReportPanelAtom, reportPanelAtom } from "@/atoms/chat/report-panel.atom";
|
import { closeReportPanelAtom, reportPanelAtom } from "@/atoms/chat/report-panel.atom";
|
||||||
import { documentsSidebarOpenAtom } from "@/atoms/documents/ui.atoms";
|
import { documentsSidebarOpenAtom } from "@/atoms/documents/ui.atoms";
|
||||||
|
|
@ -99,70 +98,35 @@ export function RightPanel({ documentsPanel }: RightPanelProps) {
|
||||||
const targetWidth = PANEL_WIDTHS[effectiveTab];
|
const targetWidth = PANEL_WIDTHS[effectiveTab];
|
||||||
const collapseButton = <CollapseButton onClick={() => setCollapsed(true)} />;
|
const collapseButton = <CollapseButton onClick={() => setCollapsed(true)} />;
|
||||||
|
|
||||||
const contentKey =
|
if (!isVisible) return null;
|
||||||
effectiveTab === "sources" && documentsOpen
|
|
||||||
? "sources"
|
|
||||||
: effectiveTab === "report" && reportOpen
|
|
||||||
? "report"
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatePresence>
|
<aside
|
||||||
{isVisible && (
|
style={{ width: targetWidth }}
|
||||||
<motion.aside
|
className="flex h-full shrink-0 flex-col border-l bg-background overflow-hidden transition-[width] duration-200 ease-out"
|
||||||
key="right-panel"
|
>
|
||||||
initial={{ width: 0, opacity: 0 }}
|
<div className="relative flex-1 min-h-0 overflow-hidden">
|
||||||
animate={{ width: targetWidth, opacity: 1 }}
|
{effectiveTab === "sources" && documentsOpen && documentsPanel && (
|
||||||
exit={{ width: 0, opacity: 0 }}
|
<div className="h-full">
|
||||||
transition={{
|
<DocumentsSidebar
|
||||||
width: { type: "spring", stiffness: 400, damping: 35, mass: 0.8 },
|
open={documentsPanel.open}
|
||||||
opacity: { duration: 0.2, ease: "easeOut" },
|
onOpenChange={documentsPanel.onOpenChange}
|
||||||
}}
|
embedded
|
||||||
style={{ willChange: "width, opacity", contain: "layout style" }}
|
headerAction={collapseButton}
|
||||||
className="flex h-full shrink-0 flex-col border-l bg-background overflow-hidden"
|
/>
|
||||||
>
|
|
||||||
<div className="relative flex-1 min-h-0 overflow-hidden">
|
|
||||||
<AnimatePresence mode="popLayout" initial={false}>
|
|
||||||
{contentKey === "sources" && documentsPanel && (
|
|
||||||
<motion.div
|
|
||||||
key="sources"
|
|
||||||
initial={{ opacity: 0, x: 8 }}
|
|
||||||
animate={{ opacity: 1, x: 0 }}
|
|
||||||
exit={{ opacity: 0, x: -8 }}
|
|
||||||
transition={{ duration: 0.15, ease: "easeOut" }}
|
|
||||||
className="h-full"
|
|
||||||
>
|
|
||||||
<DocumentsSidebar
|
|
||||||
open={documentsPanel.open}
|
|
||||||
onOpenChange={documentsPanel.onOpenChange}
|
|
||||||
embedded
|
|
||||||
headerAction={collapseButton}
|
|
||||||
/>
|
|
||||||
</motion.div>
|
|
||||||
)}
|
|
||||||
{contentKey === "report" && (
|
|
||||||
<motion.div
|
|
||||||
key="report"
|
|
||||||
initial={{ opacity: 0, x: 8 }}
|
|
||||||
animate={{ opacity: 1, x: 0 }}
|
|
||||||
exit={{ opacity: 0, x: -8 }}
|
|
||||||
transition={{ duration: 0.15, ease: "easeOut" }}
|
|
||||||
className="h-full"
|
|
||||||
>
|
|
||||||
<div className="flex h-full flex-col">
|
|
||||||
<ReportPanelContent
|
|
||||||
reportId={reportState.reportId!}
|
|
||||||
title={reportState.title || "Report"}
|
|
||||||
onClose={closeReport}
|
|
||||||
shareToken={reportState.shareToken}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</motion.div>
|
|
||||||
)}
|
|
||||||
</AnimatePresence>
|
|
||||||
</div>
|
</div>
|
||||||
</motion.aside>
|
)}
|
||||||
)}
|
{effectiveTab === "report" && reportOpen && (
|
||||||
</AnimatePresence>
|
<div className="h-full">
|
||||||
|
<ReportPanelContent
|
||||||
|
reportId={reportState.reportId!}
|
||||||
|
title={reportState.title || "Report"}
|
||||||
|
onClose={closeReport}
|
||||||
|
shareToken={reportState.shareToken}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { motion } from "motion/react";
|
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||||
import type { InboxItem } from "@/hooks/use-inbox";
|
import type { InboxItem } from "@/hooks/use-inbox";
|
||||||
|
|
@ -308,27 +307,23 @@ export function LayoutShell({
|
||||||
isResizing={isResizing}
|
isResizing={isResizing}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<motion.main
|
<main className="flex-1 flex flex-col min-w-0">
|
||||||
layout={isResizing ? false : "position"}
|
|
||||||
style={{ contain: "inline-size" }}
|
|
||||||
className="flex-1 flex flex-col min-w-0"
|
|
||||||
>
|
|
||||||
<Header />
|
<Header />
|
||||||
|
|
||||||
<div className={cn("flex-1", isChatPage ? "overflow-hidden" : "overflow-auto")}>
|
<div className={cn("flex-1", isChatPage ? "overflow-hidden" : "overflow-auto")}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</motion.main>
|
</main>
|
||||||
|
|
||||||
{/* Right panel — tabbed Sources/Report (desktop only) */}
|
{/* Right panel — tabbed Sources/Report (desktop only) */}
|
||||||
{documentsPanel && (
|
{documentsPanel && (
|
||||||
<RightPanel
|
<RightPanel
|
||||||
documentsPanel={{
|
documentsPanel={{
|
||||||
open: documentsPanel.open,
|
open: documentsPanel.open,
|
||||||
onOpenChange: documentsPanel.onOpenChange,
|
onOpenChange: documentsPanel.onOpenChange,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Inbox Sidebar - slide-out panel */}
|
{/* Inbox Sidebar - slide-out panel */}
|
||||||
{inbox && (
|
{inbox && (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue