Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: stop re-rendering the brain graph on pointer moves that can't show a tooltip (#4116)
[._.]/ Adam Eivyaff03c8869c9
diff --git a/.changelog/next/fixed-issue-4116.md b/.changelog/next/fixed-issue-4116.mdnew file mode 100644index 0000000000..6f70bbb688--- /dev/null+++ b/.changelog/next/fixed-issue-4116.md@@ -0,0 +1 @@+- Brain graph no longer re-renders on every pointer move over the 3D canvas — the tooltip position now updates only while a node is actually hovered, and never for touch input (where the tooltip is hidden)diff --git a/client/src/components/brain/tabs/BrainGraph.jsx b/client/src/components/brain/tabs/BrainGraph.jsxindex 4eebac626d..8449fdefa2 100644--- a/client/src/components/brain/tabs/BrainGraph.jsx+++ b/client/src/components/brain/tabs/BrainGraph.jsx@@ -12,6 +12,7 @@ import { pushFocus, popFocus, currentFocusId } from '../../../lib/brainGraphFocuimport EntityCombobox from '../../EntityCombobox';import InlineConfirmRow from '../../ui/InlineConfirmRow';import BrailleSpinner from '../../BrailleSpinner';+import useHoverTooltip from '../../../hooks/useHoverTooltip';import { formatDateNumeric } from '../../../utils/formatters';const EDGE_COLORS = {@@ -102,9 +103,9 @@ function GraphEdges({ simEdges, selectedId }) {}// Memoized: the container's onPointerMove re-renders BrainGraph on every mouse-// move over the canvas (it tracks the tooltip position), and every prop here is-// already identity-stable across that render — so without memo each move-// reconciles a <mesh> per node for nothing.+// move over the canvas WHILE A NODE IS HOVERED (it tracks the tooltip position),+// and every prop here is already identity-stable across that render — so without+// memo each move reconciles a <mesh> per node for nothing.const GraphScene = memo(function GraphScene({ graph, selectedId, adjacentIds, onSelect, onFocus, onHover, pickRef, touchGestureRef }) {const sphereGeo = useMemo(() => new THREE.SphereGeometry(1, 16, 12), []);const { camera, size } = useThree();@@ -165,7 +166,10 @@ const GraphScene = memo(function GraphScene({ graph, selectedId, adjacentIds, ononSelect(node);}}onDoubleClick={(e) => { e.stopPropagation(); onFocus(node); }}- onPointerOver={(e) => { e.stopPropagation(); onHover(node); }}+ // Pass the enter event's coordinates up: the wrapper's onPointerMove+ // only tracks the cursor WHILE a node is hovered, so the tooltip's+ // first frame has to be placed from this event.+ onPointerOver={(e) => { e.stopPropagation(); onHover(node, { x: e.clientX, y: e.clientY }); }}onPointerOut={() => onHover(null)}><meshStandardMaterial@@ -194,8 +198,9 @@ export default function BrainGraph() {const [subLoading, setSubLoading] = useState(false);const [selectedNode, setSelectedNode] = useState(null);const [fullRecord, setFullRecord] = useState(null);- const [hoveredNode, setHoveredNode] = useState(null);- const [tooltipPos, setTooltipPos] = useState({ x: 0, y: 0 });+ // Hover tooltip state + the ref-gated pointer tracking that keeps a plain+ // mouse move from re-rendering this component when nothing can paint.+ const { hoveredNode, tooltipPos, handleHover, handlePointerMove } = useHoverTooltip();const [layoutKey, setLayoutKey] = useState(0);const [syncing, setSyncing] = useState(false);const [confirmingRefresh, setConfirmingRefresh] = useState(false);@@ -335,10 +340,6 @@ export default function BrainGraph() {setSelectedNode(prev => (node && prev?.id !== node.id ? node : null));}, []);- const handleHover = useCallback((node) => {- setHoveredNode(node);- }, []);-// Escape always clears selection. Clicking "empty space" is unreliable for// un-isolating: unselected nodes are only dimmed (not removed), so they still// capture clicks, and onPointerMissed ignores any orbit drag — leaving the@@ -605,7 +606,7 @@ export default function BrainGraph() {className="relative bg-port-card border border-port-border rounded-lg overflow-hidden h-[clamp(240px,45vh,500px)]"onPointerDown={handlePointerDown}onPointerUp={handlePointerUp}- onPointerMove={(e) => setTooltipPos({ x: e.clientX, y: e.clientY })}+ onPointerMove={handlePointerMove}>{graph && (<Canvasdiff --git a/client/src/hooks/README.md b/client/src/hooks/README.mdindex fd0a16113c..742c9d9a16 100644--- a/client/src/hooks/README.md+++ b/client/src/hooks/README.md@@ -96,6 +96,7 @@ grep -i "what you want to do" client/src/hooks/README.md| `useClickOutside` | Fire `onOutside` on mousedown outside a ref — or outside *every* ref in an array. | Popovers, menus, drawers. Pass `[triggerRef, panelRef]` for a portaled panel, which is outside the trigger's subtree. || `useConfirmDelete` | Single-at-a-time `{ confirmingId, isConfirming, requestDelete, cancelDelete, confirmDelete }` for arming one list/card row at a time. | New destructive list action — pair with `<InlineConfirmRow>` / `<ConfirmButtonPair>` instead of deleting on the raw trash click. || `useEscapeKey` | `useEscapeKey(active, handler)` — call `handler` on Escape while `active`. | Non-modal dismissables (in-context popovers/cards); Modal owns Esc for true modals. |+| `useHoverTooltip` | `{ hoveredNode, tooltipPos, handleHover, handlePointerMove }` for a canvas hover tooltip. `handlePointerMove` drops any move that cannot paint a tooltip (nothing hovered, or a touch pointer, where the tooltip is `pointer-coarse:hidden`), so idle cursor motion stops re-rendering the page. The gate reads a ref, not the hovered state — r3f raycasts on the Canvas' inner div while React delegates the container's move handler, so the enter event's own move still sees the pre-flush `null`. | Any 3D graph/canvas view with a cursor-following hover tooltip (BrainGraph) — pass `{ x: e.clientX, y: e.clientY }` to `handleHover` from the mesh's `onPointerOver` so the first frame is placed. || `useFocusTrap` | `useFocusTrap(active, containerRef, { initialFocusRef? })` — moves focus into the container on open, traps Tab/Shift+Tab so it can't escape to the page behind, and restores focus to the opener on close (WCAG 2.4.3 / 2.1.2). | Modal surfaces (dialogs, drawers, lightboxes). Already wired into `Modal` and `Drawer` — reach for it when hand-rolling a new overlay. || `useNoteSave` | `useNoteSave({ vaultId, notePath, content })` → `{ saving, save({ force }), forceOffered, dismissForce }` — writes an Obsidian note and owns the iCloud force-save escape hatch: `forceOffered` turns on only after the server has twice refused the SAME note with a `stalled` (retrying-cannot-help) verdict. | Any editor that saves a vault note. Render `<ForceSaveNoteRow offered={forceOffered}>` next to the editor; never call `save({ force: true })` from anything but that row's confirm. || `useCmdKSearch` | `⌘K` open/close state. | Anywhere that needs to toggle the palette. |diff --git a/client/src/hooks/index.js b/client/src/hooks/index.jsindex 221995eb4f..095ccec7c2 100644--- a/client/src/hooks/index.js+++ b/client/src/hooks/index.js@@ -24,6 +24,7 @@ export { default as useEscapeKey } from './useEscapeKey.js';export { default as useFieldDraft } from './useFieldDraft.js';export { default as useFocusTrap } from './useFocusTrap.js';export { default as useNoteSave } from './useNoteSave.js';+export { default as useHoverTooltip } from './useHoverTooltip.js';export { default as useImageGenQueue } from './useImageGenQueue.js';export { default as useImageRenderSettings } from './useImageRenderSettings.js';export { default as useUserTimezone } from './useUserTimezone.js';diff --git a/client/src/hooks/useHoverTooltip.js b/client/src/hooks/useHoverTooltip.jsnew file mode 100644index 0000000000..bb29996d0b--- /dev/null+++ b/client/src/hooks/useHoverTooltip.js@@ -0,0 +1,47 @@+import { useCallback, useRef, useState } from 'react';++/**+ * Hover-tooltip bookkeeping for a 3D graph canvas: which node is hovered, and+ * where its floating tooltip should sit.+ *+ * The point of the hook is the *gate*. A canvas container that tracks the+ * cursor with a bare `onPointerMove={(e) => setTooltipPos(...)}` re-renders its+ * owner on every pixel of movement, even though no tooltip is showing for the+ * overwhelming majority of those moves — and on a coarse pointer the tooltip is+ * hidden outright (`pointer-coarse:hidden`), so the work is 100% waste on the+ * weakest hardware. `handlePointerMove` drops any move that cannot paint.+ *+ * The gate reads a REF, not the `hoveredNode` state, and that is load-bearing:+ * react-three-fiber raycasts on the Canvas' own inner div while React delegates+ * the container's `onPointerMove` at the app root, so on the very event where+ * the pointer enters a node the move handler's closure still sees the PREVIOUS+ * render's state (`null`) and would skip the position update the tooltip needs+ * on its first frame — stranding it wherever it last painted. `handleHover`+ * writes the ref synchronously, so the same event that enters a node also opens+ * the gate. It also seeds `tooltipPos` from the enter event's own coordinates,+ * so the first frame is correctly placed even if no move follows.+ */+export default function useHoverTooltip() {+ const [hoveredNode, setHoveredNode] = useState(null);+ const [tooltipPos, setTooltipPos] = useState({ x: 0, y: 0 });+ // Mirrors hoveredNode for the pointer-move gate, which runs before state flushes.+ const hoveredRef = useRef(null);++ // `point` is optional: pass `{ x, y }` (client coords) from the enter event so+ // the tooltip's first paint lands under the cursor.+ const handleHover = useCallback((node, point) => {+ hoveredRef.current = node;+ setHoveredNode(node);+ if (node && point) setTooltipPos({ x: point.x, y: point.y });+ }, []);++ const handlePointerMove = useCallback((e) => {+ if (!hoveredRef.current) return;+ // A touch move can never show the tooltip — it is `pointer-coarse:hidden`,+ // and a finger has no hover to preview with.+ if (e.pointerType === 'touch') return;+ setTooltipPos({ x: e.clientX, y: e.clientY });+ }, []);++ return { hoveredNode, tooltipPos, handleHover, handlePointerMove };+}diff --git a/client/src/hooks/useHoverTooltip.test.jsx b/client/src/hooks/useHoverTooltip.test.jsxnew file mode 100644index 0000000000..c21ba93978--- /dev/null+++ b/client/src/hooks/useHoverTooltip.test.jsx@@ -0,0 +1,86 @@+import { describe, it, expect } from 'vitest';+import { renderHook, act } from '@testing-library/react';+import useHoverTooltip from './useHoverTooltip';++const move = (x, y, pointerType = 'mouse') => ({ clientX: x, clientY: y, pointerType });+const NODE = { id: 'n1', label: 'Alpha' };++describe('useHoverTooltip', () => {+ it('ignores pointer moves while nothing is hovered', () => {+ const { result } = renderHook(() => useHoverTooltip());+ const before = result.current.tooltipPos;++ act(() => result.current.handlePointerMove(move(120, 240)));++ // Same object identity: no setState ran, so no re-render was queued.+ expect(result.current.tooltipPos).toBe(before);+ });++ it('tracks pointer moves once a node is hovered', () => {+ const { result } = renderHook(() => useHoverTooltip());++ act(() => result.current.handleHover(NODE));+ act(() => result.current.handlePointerMove(move(120, 240)));++ expect(result.current.hoveredNode).toBe(NODE);+ expect(result.current.tooltipPos).toEqual({ x: 120, y: 240 });+ });++ it('opens the gate on the SAME event that enters a node, before state flushes', () => {+ // The bug the ref exists for: r3f raycasts on the Canvas' inner div while+ // React delegates the container's onPointerMove at the app root, so both+ // fire for one physical move. A gate reading `hoveredNode` would still see+ // the pre-flush `null` here and strand the tooltip at a stale position.+ const { result } = renderHook(() => useHoverTooltip());++ act(() => {+ result.current.handleHover(NODE, { x: 50, y: 60 });+ result.current.handlePointerMove(move(51, 61));+ });++ expect(result.current.tooltipPos).toEqual({ x: 51, y: 61 });+ });++ it('seeds the position from the enter event so the first frame is placed', () => {+ const { result } = renderHook(() => useHoverTooltip());++ act(() => result.current.handleHover(NODE, { x: 300, y: 400 }));++ expect(result.current.tooltipPos).toEqual({ x: 300, y: 400 });+ });++ it('closes the gate again when the pointer leaves the node', () => {+ const { result } = renderHook(() => useHoverTooltip());++ act(() => result.current.handleHover(NODE, { x: 10, y: 20 }));+ act(() => result.current.handleHover(null));+ const settled = result.current.tooltipPos;+ act(() => result.current.handlePointerMove(move(999, 999)));++ expect(result.current.hoveredNode).toBeNull();+ expect(result.current.tooltipPos).toBe(settled);+ });++ it('ignores touch moves — the tooltip is pointer-coarse:hidden', () => {+ const { result } = renderHook(() => useHoverTooltip());++ act(() => result.current.handleHover(NODE, { x: 10, y: 20 }));+ const seeded = result.current.tooltipPos;+ act(() => result.current.handlePointerMove(move(700, 800, 'touch')));++ expect(result.current.tooltipPos).toBe(seeded);+ });++ it('keeps its handlers identity-stable across renders', () => {+ // BrainGraph passes handleHover into a memo()'d scene; a new identity per+ // render would defeat the memo the whole optimization rests on.+ const { result, rerender } = renderHook(() => useHoverTooltip());+ const first = result.current;++ act(() => result.current.handleHover(NODE, { x: 1, y: 2 }));+ rerender();++ expect(result.current.handleHover).toBe(first.handleHover);+ expect(result.current.handlePointerMove).toBe(first.handlePointerMove);+ });+});