Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/AI chat: keep the sidebar AI chat mounted while its right pane section is collapsed
Adorian Doran52d3efa30637
diff --git a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx b/apps/client/src/widgets/sidebar/RightPanelWidget.tsxindex 3b05f24627..355a056e70 100644--- a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx+++ b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx@@ -15,9 +15,16 @@ interface RightPanelWidgetProps {containerRef?: RefObject<HTMLDivElement>;contextMenuItems?: MenuItem<unknown>[];grow?: boolean;+ /**+ * Keep the body in the DOM when collapsed (hidden via CSS) instead of unmounting it. Use for a+ * stateful widget whose content shouldn't be rebuilt on every collapse — e.g. the sidebar chat,+ * whose live conversation, draft input, and DOM-attached listeners would otherwise be torn down+ * and (because its hooks live in the always-mounted parent) not re-wired on expand.+ */+ keepMounted?: boolean;}-export default function RightPanelWidget({ id, title, buttons, children, containerRef: externalContainerRef, contextMenuItems, grow }: RightPanelWidgetProps) {+export default function RightPanelWidget({ id, title, buttons, children, containerRef: externalContainerRef, contextMenuItems, grow, keepMounted }: RightPanelWidgetProps) {const [ rightPaneCollapsedItems, setRightPaneCollapsedItems ] = useTriliumOptionJson<string[]>("rightPaneCollapsedItems");const [ expanded, setExpanded ] = useState(!rightPaneCollapsedItems.includes(id));const containerRef = useSyncedRef<HTMLDivElement>(externalContainerRef, null);@@ -73,7 +80,9 @@ export default function RightPanelWidget({ id, title, buttons, children, contain</div><div id={parentComponent?.componentId} class="body-wrapper">- {expanded && <div class="card-body">+ {/* keepMounted widgets stay in the DOM when collapsed and hide via `hidden` (display:none),+ so their state and DOM-attached listeners survive a collapse; others unmount as before. */}+ {(expanded || keepMounted) && <div class="card-body" hidden={!expanded}>{children}</div>}</div>diff --git a/apps/client/src/widgets/sidebar/SidebarChat.tsx b/apps/client/src/widgets/sidebar/SidebarChat.tsxindex c93a19715c..61bfeea7d1 100644--- a/apps/client/src/widgets/sidebar/SidebarChat.tsx+++ b/apps/client/src/widgets/sidebar/SidebarChat.tsx@@ -298,6 +298,10 @@ export default function SidebarChat() {id="sidebar-chat"title={chatTitle}grow+ // Keep the chat mounted when collapsed: it holds live conversation state and its context-menu /+ // highlight / scroll listeners are wired in this (always-mounted) component, so unmounting the+ // body on collapse would orphan them and they wouldn't re-attach on expand.+ keepMountedbuttons={<><ActionButton