Skip to content

fix(graph): keep the focused node highlighted across tab switches - #764

Merged
hamidfzm merged 2 commits into
mainfrom
fix/graph-focus-across-tabs
Sep 16, 2026
Merged

hamidfzm merged 2 commits into
mainfrom
fix/graph-focus-across-tabs

Conversation

@hamidfzm

Copy link
Copy Markdown
Owner

Summary

Clicking a node in the graph highlights it and its neighbourhood. Switching to another tab and back dropped that highlight, because the graph tab unmounts while inactive and the focused node lived only in component state. The camera and layout already survive the switch (#732); this keeps the focused node with them. Follow-up to #733.

Changes

  • graphViewStore: add focusedId to the per-workspace graph view state.
  • useGraphFocus: take an optional persistKey, seed the focused node from the store on mount and write it back when it changes.
  • GraphView: pass the workspace root as persistKey.
  • Test: focus a node, unmount, remount in the same workspace, and the neighbourhood is still highlighted.

Risk classification

  • Persistence / data loss
  • Asynchronous ordering / races
  • Destructive lifecycle (close, unmount, workspace switch, app exit)
  • Filesystem / IPC surface
  • Untrusted rendering (Markdown, plugins, links)
  • Secrets / credentials
  • Network
  • Migrations / persisted-format changes
  • Accessibility
  • Bundle size / startup
  • No risk areas touched

Invariants at stake and evidence

Session-only, in-memory state; nothing reaches disk. The focus rides the existing store lifecycle:

  • Unmount on tab switch: focus restored, covered by GraphView.test.tsx "comes back with the focused node still highlighted" (verified to fail without the fix).
  • Closing the graph tab: pruneGraphViews drops the whole entry, so a reopened graph starts unfocused.
  • A focused note deleted or renamed while the tab is inactive: the existing stale-id check in useGraphFocus clears it on the next mount.
  • Workspaces stay isolated: the store is keyed by workspace root.
  • Pending camera move: still cancelled on unmount, so only the highlight is restored.

Testing

Automated gates only: pnpm typecheck, pnpm check, full pnpm test (3953 tests). No Rust changes. Not yet checked by hand in the running app.

  • Tested on macOS
  • Tested on Windows
  • Tested on Linux

@github-actions github-actions Bot added the bug Something isn't working label Sep 15, 2026
@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.69%. Comparing base (b15f37a) to head (d8e0cd1).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #764   +/-   ##
=======================================
  Coverage   99.69%   99.69%           
=======================================
  Files         548      548           
  Lines       22587    22590    +3     
  Branches     2467     2468    +1     
=======================================
+ Hits        22519    22522    +3     
  Misses         17       17           
  Partials       51       51           
Flag Coverage Δ
frontend 99.41% <100.00%> (+<0.01%) ⬆️
rust 99.92% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/components/graph/GraphView.tsx 100.00% <ø> (ø)
src/hooks/useGraphFocus.ts 100.00% <100.00%> (ø)
src/lib/graphViewStore.ts 100.00% <ø> (ø)

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 111 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
glyph-frontend-esm 19.18MB 111 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: glyph-frontend-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/GraphView-*.js 111 bytes 23.37kB 0.48%

Files in assets/GraphView-*.js:

  • ./src/components/graph/GraphView.tsx → Total Size: 5.31kB

  • ./src/hooks/useGraphFocus.ts → Total Size: 2.06kB

@hamidfzm
hamidfzm enabled auto-merge (squash) September 16, 2026 12:15
@hamidfzm hamidfzm self-assigned this Sep 16, 2026
@hamidfzm
hamidfzm merged commit e013c1b into main Sep 16, 2026
28 checks passed
@hamidfzm
hamidfzm deleted the fix/graph-focus-across-tabs branch September 16, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant