Skip to content

Build your personal knowledge base with Trilium Notes

client/AI chat: fix some issues

Adorian Dorand0a2f2ce51b0
diff --git a/apps/client/src/widgets/launch_bar/launch_bar_widgets.tsx b/apps/client/src/widgets/launch_bar/launch_bar_widgets.tsx
index a9126143ea..fb9c2523a5 100644
--- a/apps/client/src/widgets/launch_bar/launch_bar_widgets.tsx
+++ b/apps/client/src/widgets/launch_bar/launch_bar_widgets.tsx
@@ -12,6 +12,10 @@ import Icon from "../react/Icon";
const cachedIsMobile = utils.isMobile();
+// Hoisted so the reference is stable across renders — an inline object would change identity
+// every render and defeat Dropdown's tooltip-config memoization, recreating the tooltip each time.
+const DROPDOWN_TITLE_OPTIONS = { animation: false } as const;
+
export const LaunchBarContext = createContext<{
isHorizontalLayout: boolean;
}>({
@@ -58,7 +62,7 @@ export function LaunchBarDropdownButton({ children, icon, dropdownOptions, launc
hideToggleArrow
text={<Icon icon={icon} />}
titlePosition={titlePosition}
- titleOptions={{ animation: false }}
+ titleOptions={DROPDOWN_TITLE_OPTIONS}
dropdownOptions={{
...dropdownOptions,
popperConfig: {
diff --git a/apps/client/src/widgets/sidebar/SidebarChat.tsx b/apps/client/src/widgets/sidebar/SidebarChat.tsx
index 7cd3b8d679..a11eac22e3 100644
--- a/apps/client/src/widgets/sidebar/SidebarChat.tsx
+++ b/apps/client/src/widgets/sidebar/SidebarChat.tsx
@@ -131,7 +131,7 @@ export default function SidebarChat() {
// Custom submit handler that ensures chat note exists first
const handleSubmit = useCallback(async (e: Event) => {
e.preventDefault();
- if (!chat.hasInputText || chat.isStreaming) return;
+ if ((!chat.hasInputText && chat.pendingAttachments.length === 0) || chat.isStreaming) return;
// Snapshot the draft before any await: as soon as this handler suspends, the input
// bar clears the editor, which zeroes the live draft ref the delegated
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/useSmoothStreaming.ts b/apps/client/src/widgets/type_widgets/llm_chat/useSmoothStreaming.ts
index 396950b25e..c2d2adf54b 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/useSmoothStreaming.ts
+++ b/apps/client/src/widgets/type_widgets/llm_chat/useSmoothStreaming.ts
@@ -44,6 +44,14 @@ export function useSmoothStreaming(options: SmoothStreamingOptions = {}): Smooth
const lastTickRef = useRef(0);
const tick = useCallback(() => {
+ // Stop as soon as there's nothing left to reveal, instead of spinning rAF for up to
+ // MIN_COMMIT_INTERVAL_MS after the stream has drained.
+ const backlog = targetRef.current.length - displayedLenRef.current;
+ if (backlog <= 0) {
+ rafRef.current = null;
+ return;
+ }
+
const now = performance.now();
// Cap the commit cadence: every setDisplayedText re-renders the whole chat tree, and
@@ -57,12 +65,6 @@ export function useSmoothStreaming(options: SmoothStreamingOptions = {}): Smooth
const dt = (now - lastTickRef.current) / 1000;
lastTickRef.current = now;
- const backlog = targetRef.current.length - displayedLenRef.current;
- if (backlog <= 0) {
- rafRef.current = null;
- return;
- }
-
// With a small backlog the baseline cadence dominates (calm, readable);
// with a large backlog we accelerate so the lag stays bounded.
const rate = Math.max(baseCharsPerSecond, backlog / maxBacklogSeconds);