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: share vault note detail and retry failed wiki reads (#8214)
[._.]/ Adam Eivyd3bd9c230149
diff --git a/client/src/components/brain/tabs/NotesTab.jsx b/client/src/components/brain/tabs/NotesTab.jsxindex 873b180045..f8b1977c36 100644--- a/client/src/components/brain/tabs/NotesTab.jsx+++ b/client/src/components/brain/tabs/NotesTab.jsx@@ -5,30 +5,27 @@ import {FolderOpen,Search,Plus,- Trash2,- Save,ChevronRight,ChevronDown,ArrowLeft,Tag,Link2,RefreshCw,- Edit3,- X,FileText,+ X,Settings} from 'lucide-react';import BrailleSpinner from '../../BrailleSpinner';import toast from '../../ui/Toast';-import InlineConfirmRow from '../../ui/InlineConfirmRow';import FolderPicker from '../../FolderPicker';-import { timeAgo, formatBytes, formatCount } from '../../../utils/formatters';+import { formatCount } from '../../../utils/formatters';import { useConfirmDelete } from '../../../hooks/useConfirmDelete';import { useNoteSave } from '../../../hooks/useNoteSave.js';import useUrlParams from '../../../hooks/useUrlParams';import { clickableProps, onActivateKeyDown } from '../../../lib/a11yKeyboard.js';import OfflineNotesNotice from '../../OfflineNotesNotice.jsx';-import ForceSaveNoteRow from '../../ForceSaveNoteRow.jsx';+import NoteDetailPane from '../../notes/NoteDetailPane.jsx';+import useVaultNote from '../../../hooks/useVaultNote.js';function UnavailableState({ title, message, onRetry }) {return (@@ -74,12 +71,20 @@ export default function NotesTab() {const [scanError, setScanError] = useState(false);// Note viewer/editor state- const [selectedNote, setSelectedNote] = useState(null);const [noteContent, setNoteContent] = useState('');const [editing, setEditing] = useState(false);- const [loadingNote, setLoadingNote] = useState(false);- const [noteError, setNoteError] = useState(false);- const [noteRetry, setNoteRetry] = useState(0);+ const {+ note: selectedNote, setNote: setSelectedNote, loading: loadingNote,+ error: noteError, retry: retryNote, clear: clearNote, sequenceRef: selectSeqRef,+ } = useVaultNote(selectedVaultId, selectedNotePath, {+ onReset: () => {+ setNoteContent('');+ setEditing(false);+ dismissForce();+ cancelDelete();+ },+ onLoad: note => setNoteContent(note.content),+ });// Search stateconst [searchInput, setSearchInput] = useState(searchQuery);@@ -109,24 +114,17 @@ export default function NotesTab() {});const searchRef = useRef(null);- const editorRef = useRef(null);// Invalidate work at the interaction boundary, including A → B → A switches.const vaultScopeRef = useRef(0);const scopedVaultRef = useRef(selectedVaultId);- const selectSeqRef = useRef(0);const scanSeqRef = useRef(0);const searchSeqRef = useRef(0);const mountedRef = useRef(false);const isCurrentScope = scope => mountedRef.current && vaultScopeRef.current === scope;const clearSelection = () => {- selectSeqRef.current += 1;- setSelectedNote(null);- setNoteContent('');- setEditing(false);- setLoadingNote(false);- setNoteError(false);+ clearNote();dismissForce();cancelDelete();};@@ -256,34 +254,6 @@ export default function NotesTab() {if (isCurrentScope(scope) && data?.tags) setTags(data.tags);};- const loadNote = async () => {- if (!selectedVaultId || !selectedNotePath) return;- const scope = vaultScopeRef.current;- const sequence = ++selectSeqRef.current;- setSelectedNote(null);- setNoteContent('');- setEditing(false);- setNoteError(false);- setLoadingNote(true);- dismissForce();- cancelDelete();- const data = await api.getNote(selectedVaultId, selectedNotePath, { silent: true }).catch(() => null);- if (!isCurrentScope(scope) || sequence !== selectSeqRef.current) return;- if (data) {- setSelectedNote(data);- setNoteContent(data.content);- } else setNoteError(true);- setLoadingNote(false);- };-- useEffect(() => {- if (!selectedVaultId || !selectedNotePath) {- clearSelection();- return;- }- loadNote();- }, [selectedVaultId, selectedNotePath, noteRetry]);-const loadSearch = useCallback(async (query = searchQuery) => {if (!query.trim() || !selectedVaultId) return;const scope = vaultScopeRef.current;@@ -329,7 +299,7 @@ export default function NotesTab() {const handleSelectNote = (notePath) => {clearSelection();- setNoteRetry(value => value + 1);+ retryNote();updateParams({ note: notePath });};@@ -682,195 +652,33 @@ export default function NotesTab() {{/* Right panel: note viewer/editor — hidden on mobile until a note isopened so the list owns the small-screen viewport; always shown on md+. */}<div className={`flex-col min-w-0 min-h-0 overflow-hidden ${selectedNotePath || loadingNote || noteError ? 'flex' : 'hidden md:flex'}`}>- {loadingNote ? (- <div className="flex items-center justify-center h-full">- <BrailleSpinner text="Loading" />- </div>- ) : noteError ? (- <div className="flex flex-col items-center justify-center gap-3 h-full p-4">- <button- type="button"- onClick={closeNote}- className="inline-flex min-h-[44px] items-center gap-2 rounded px-3 text-sm text-port-accent hover:text-white"- >- <ArrowLeft size={16} aria-hidden="true" /> Back to notes- </button>- <UnavailableState- title="Note is unavailable"- message="This note could not be read, so its contents were not replaced with an empty view."- onRetry={() => setNoteRetry(value => value + 1)}- />- </div>- ) : selectedNote ? (- <>- {/* Note header */}- <div className="px-4 py-3 border-b border-port-border flex items-center gap-3">- <button- onClick={closeNote}- aria-label="Back"- className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1 rounded hover:bg-port-card text-gray-400 hover:text-white md:hidden"- >- <ArrowLeft size={16} />- </button>- <div className="flex-1 min-w-0">- <h2 className="text-white font-medium truncate">{selectedNote.name}</h2>- <div className="flex items-center gap-3 text-xs text-gray-500">- {selectedNote.folder && (- <span className="flex items-center gap-1">- <FolderOpen size={10} />- {selectedNote.folder}- </span>- )}- <span>Modified {timeAgo(selectedNote.modifiedAt)}</span>- <span>{formatBytes(selectedNote.size)}</span>- </div>- </div>- <div className="flex items-center gap-1">- {editing ? (- <>- <button- onClick={() => handleSaveNote()}- disabled={saving}- className="flex items-center gap-1 px-3 py-1.5 rounded bg-port-accent text-white text-sm hover:bg-port-accent/80 disabled:opacity-50"- >- <Save size={14} />- {saving ? 'Saving...' : 'Save'}- </button>- <button- onClick={() => { setEditing(false); setNoteContent(selectedNote.content); }}- aria-label="Close editor"- className="p-1.5 rounded hover:bg-port-card text-gray-400 hover:text-white min-h-[44px] min-w-[44px] flex items-center justify-center"- >- <X size={16} />- </button>- </>- ) : (- <button- onClick={() => setEditing(true)}- className="flex items-center gap-1 px-3 py-1.5 rounded bg-port-card text-gray-300 text-sm hover:text-white hover:bg-port-border"- >- <Edit3 size={14} />- Edit- </button>- )}- <button- onClick={() => requestDelete(selectedNote.path)}- className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1.5 rounded hover:bg-port-card text-gray-400 hover:text-port-error"- title="Delete note" aria-label="Delete note"- >- <Trash2 size={14} />- </button>- </div>- </div>-- {/* Delete confirmation */}- {isConfirmingDelete(selectedNote.path) && (- <InlineConfirmRow- variant="separator"- question="Delete this note permanently?"- onConfirm={() => handleDeleteNote(selectedNote.path)}- onCancel={cancelDelete}- />- )}-- {/* Editor-only: outside edit mode there is no buffer the user meant to- write, and a stray "Save anyway" click would still issue the risky- forced write. */}- <ForceSaveNoteRow- offered={editing && forceOffered}- onConfirm={() => handleSaveNote({ force: true })}- onCancel={dismissForce}- />-- {/* Note content */}- <div className="flex-1 min-h-0 overflow-auto flex">- {/* Main content area */}- <div className="flex-1 min-w-0">- {editing ? (- <textarea- aria-label="Note content"- ref={editorRef}- value={noteContent}- onChange={e => setNoteContent(e.target.value)}- className="w-full h-full p-4 bg-port-bg text-gray-200 font-mono text-sm resize-none focus:outline-none"- spellCheck={false}- onKeyDown={e => {- if ((e.metaKey || e.ctrlKey) && e.key === 's') {- e.preventDefault();- handleSaveNote();- }- }}- />- ) : (- <div className="p-4">- <MarkdownPreview content={selectedNote.body || selectedNote.content} onLinkClick={handleSelectNote} />- </div>- )}- </div>-- {!editing && (- <div className="w-56 border-l border-port-border p-3 space-y-4 shrink-0 overflow-auto hidden lg:block">- {selectedNote.frontmatter && Object.keys(selectedNote.frontmatter).length > 0 && (- <div>- <h4 className="text-xs font-medium text-gray-400 uppercase mb-1">Properties</h4>- <div className="space-y-1">- {Object.entries(selectedNote.frontmatter).map(([key, val]) => (- <div key={key} className="text-xs">- <span className="text-gray-500">{key}:</span>{' '}- <span className="text-gray-300">- {Array.isArray(val) ? val.join(', ') : String(val)}- </span>- </div>- ))}- </div>- </div>- )}-- {selectedNote.tags?.length > 0 && (- <div>- <h4 className="text-xs font-medium text-gray-400 uppercase mb-1">Tags</h4>- <div className="flex flex-wrap gap-1">- {selectedNote.tags.map(tag => (- <span key={tag} className="px-1.5 py-0.5 rounded text-xs bg-port-accent/20 text-port-accent">- #{tag}- </span>- ))}- </div>- </div>- )}-- <LinkSection- icon={<Link2 size={10} />}- label="Links"- items={selectedNote.wikilinks}- getKey={link => link}- getLabel={link => link}- onClickItem={link => {- const match = notes.find(n => n.name.toLowerCase() === link.toLowerCase());- if (match) handleSelectNote(match.path);- else toast.warn(`Note "${link}" not found in vault`);- }}- />-- <LinkSection- icon={<ArrowLeft size={10} />}- label="Backlinks"- items={selectedNote.backlinks}- getKey={bl => bl.path}- getLabel={bl => bl.name}- onClickItem={bl => handleSelectNote(bl.path)}- />- </div>- )}- </div>- </>- ) : (- <div className="flex flex-col items-center justify-center h-full text-gray-500">- <BookOpen size={48} className="mb-3 opacity-30" />- <p className="text-sm">Select a note to view</p>- <p className="text-xs mt-1">or press + to create a new one</p>- </div>- )}+ <NoteDetailPane+ selectedNote={selectedNote} loading={loadingNote} error={noteError}+ onRetry={retryNote} onBack={closeNote} backLabel="Back to notes"+ headerBackLabel="Back"+ editing={editing} onSetEditing={setEditing} noteContent={noteContent}+ onSetContent={setNoteContent} saving={saving} onSave={handleSaveNote}+ confirmingDelete={selectedNote ? isConfirmingDelete(selectedNote.path) : false}+ onRequestDelete={requestDelete} onDelete={handleDeleteNote}+ onCancelDelete={cancelDelete} forceOffered={forceOffered}+ dismissForce={dismissForce}+ renderPreview={content => <MarkdownPreview content={content} onLinkClick={handleSelectNote} />}+ renderLinks={note => (+ <>+ <LinkSection icon={<Link2 size={10} />} label="Links" items={note.wikilinks}+ getKey={link => link} getLabel={link => link}+ onClickItem={link => {+ const match = notes.find(n => n.name.toLowerCase() === link.toLowerCase());+ if (match) handleSelectNote(match.path);+ else toast.warn(`Note "${link}" not found in vault`);+ }} />+ <LinkSection icon={<ArrowLeft size={10} />} label="Backlinks" items={note.backlinks}+ getKey={bl => bl.path} getLabel={bl => bl.name}+ onClickItem={bl => handleSelectNote(bl.path)} />+ </>+ )}+ emptyHint="or press + to create a new one"+ /></div></div>);diff --git a/client/src/components/brain/tabs/NotesTab.test.jsx b/client/src/components/brain/tabs/NotesTab.test.jsxindex 96ac8ffbc8..a0b11f4ab8 100644--- a/client/src/components/brain/tabs/NotesTab.test.jsx+++ b/client/src/components/brain/tabs/NotesTab.test.jsx@@ -476,7 +476,7 @@ describe('NotesTab URL state and unavailable reads', () => {it('replays note selection through browser back and forward', async () => {const rootNote = { ...note, path: 'first.md', folder: '' };api.scanNotesVault.mockResolvedValueOnce({ notes: [rootNote], total: 1 });- api.getNote.mockResolvedValueOnce(rootNote);+ api.getNote.mockResolvedValue(rootNote);await renderTab();await act(async () => { fireEvent.click(screen.getByText('first')); });diff --git a/client/src/components/notes/NoteDetailPane.jsx b/client/src/components/notes/NoteDetailPane.jsxnew file mode 100644index 0000000000..8b4ab51987--- /dev/null+++ b/client/src/components/notes/NoteDetailPane.jsx@@ -0,0 +1,187 @@+import { useRef } from 'react';+import { FolderOpen, ArrowLeft, Edit3, Save, Trash2, X, BookOpen } from 'lucide-react';+import BrailleSpinner from '../BrailleSpinner.jsx';+import InlineConfirmRow from '../ui/InlineConfirmRow.jsx';+import ForceSaveNoteRow from '../ForceSaveNoteRow.jsx';+import { timeAgo, formatBytes } from '../../utils/formatters.js';++export default function NoteDetailPane({+ selectedNote, loading, error, onRetry, onBack, backLabel = 'Back', headerBackLabel = backLabel,+ editing, onSetEditing, noteContent, onSetContent, saving, onSave,+ confirmingDelete, onRequestDelete, onDelete, onCancelDelete,+ forceOffered, dismissForce, renderPreview, renderLinks,+ emptyIcon: EmptyIcon = BookOpen, emptyLabel = 'Select a note to view',+ emptyHint, cancelLabel = 'Close editor',+}) {+ const editorRef = useRef(null);+ if (loading) return (+ <div className="flex items-center justify-center h-full">+ <BrailleSpinner text="Loading" />+ </div>+ );+ if (error) return (+ <div className="flex flex-col items-center justify-center gap-3 h-full p-4">+ <button type="button" onClick={onBack}+ className="inline-flex min-h-[44px] items-center gap-2 rounded px-3 text-sm text-port-accent hover:text-white">+ <ArrowLeft size={16} aria-hidden="true" /> {backLabel}+ </button>+ <div role="alert" className="rounded-lg border border-port-error/40 bg-port-error/10 p-4 text-sm text-gray-300">+ <p className="font-medium text-port-error">Note is unavailable</p>+ <p className="mt-1 text-gray-400">This note could not be read, so its contents were not replaced with an empty view.</p>+ <button type="button" onClick={onRetry}+ className="mt-3 min-h-[44px] rounded bg-port-card px-3 text-port-accent hover:text-white">Retry</button>+ </div>+ </div>+ );+ if (!selectedNote) return (+ <div className="flex flex-col items-center justify-center h-full text-gray-500">+ <EmptyIcon size={48} className="mb-3 opacity-30" />+ <p className="text-sm">{emptyLabel}</p>+ {emptyHint && <p className="text-xs mt-1">{emptyHint}</p>}+ </div>+ );+ return (+ <>+ {/* Note header */}+ <div className="px-4 py-3 border-b border-port-border flex items-center gap-3">+ <button+ onClick={onBack}+ aria-label={headerBackLabel}+ className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1 rounded hover:bg-port-card text-gray-400 hover:text-white md:hidden"+ >+ <ArrowLeft size={16} />+ </button>+ <div className="flex-1 min-w-0">+ <h2 className="text-white font-medium truncate">{selectedNote.name}</h2>+ <div className="flex items-center gap-3 text-xs text-gray-500">+ {selectedNote.folder && (+ <span className="flex items-center gap-1">+ <FolderOpen size={10} />+ {selectedNote.folder}+ </span>+ )}+ <span>Modified {timeAgo(selectedNote.modifiedAt)}</span>+ <span>{formatBytes(selectedNote.size)}</span>+ </div>+ </div>+ <div className="flex items-center gap-1">+ {editing ? (+ <>+ <button+ onClick={() => onSave()}+ disabled={saving}+ className="flex items-center gap-1 px-3 py-1.5 rounded bg-port-accent text-white text-sm hover:bg-port-accent/80 disabled:opacity-50"+ >+ <Save size={14} />+ {saving ? 'Saving...' : 'Save'}+ </button>+ <button+ onClick={() => { onSetEditing(false); onSetContent(selectedNote.content); }}+ aria-label={cancelLabel}+ className="p-1.5 rounded hover:bg-port-card text-gray-400 hover:text-white min-h-[44px] min-w-[44px] flex items-center justify-center"+ >+ <X size={16} />+ </button>+ </>+ ) : (+ <button+ onClick={() => onSetEditing(true)}+ className="flex items-center gap-1 px-3 py-1.5 rounded bg-port-card text-gray-300 text-sm hover:text-white hover:bg-port-border"+ >+ <Edit3 size={14} />+ Edit+ </button>+ )}+ <button+ onClick={() => onRequestDelete(selectedNote.path)}+ className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1.5 rounded hover:bg-port-card text-gray-400 hover:text-port-error"+ title="Delete note" aria-label="Delete note"+ >+ <Trash2 size={14} />+ </button>+ </div>+ </div>++ {/* Delete confirmation */}+ {confirmingDelete && (+ <InlineConfirmRow+ variant="separator"+ question="Delete this note permanently?"+ onConfirm={() => onDelete(selectedNote.path)}+ onCancel={onCancelDelete}+ />+ )}++ {/* Editor-only: outside edit mode there is no buffer the user meant to+ write, and a stray "Save anyway" click would still issue the risky+ forced write. */}+ <ForceSaveNoteRow+ offered={editing && forceOffered}+ onConfirm={() => onSave({ force: true })}+ onCancel={dismissForce}+ />++ {/* Note content */}+ <div className="flex-1 min-h-0 overflow-auto flex">+ {/* Main content area */}+ <div className="flex-1 min-w-0">+ {editing ? (+ <textarea+ aria-label="Note content"+ ref={editorRef}+ value={noteContent}+ onChange={e => onSetContent(e.target.value)}+ className="w-full h-full p-4 bg-port-bg text-gray-200 font-mono text-sm resize-none focus:outline-none"+ spellCheck={false}+ onKeyDown={e => {+ if ((e.metaKey || e.ctrlKey) && e.key === 's') {+ e.preventDefault();+ onSave();+ }+ }}+ />+ ) : (+ <div className="p-4">+ {renderPreview(selectedNote.body || selectedNote.content)}+ </div>+ )}+ </div>++ {!editing && (+ <div className="w-56 border-l border-port-border p-3 space-y-4 shrink-0 overflow-auto hidden lg:block">+ {selectedNote.frontmatter && Object.keys(selectedNote.frontmatter).length > 0 && (+ <div>+ <h4 className="text-xs font-medium text-gray-400 uppercase mb-1">Properties</h4>+ <div className="space-y-1">+ {Object.entries(selectedNote.frontmatter).map(([key, val]) => (+ <div key={key} className="text-xs">+ <span className="text-gray-500">{key}:</span>{' '}+ <span className="text-gray-300">+ {Array.isArray(val) ? val.join(', ') : String(val)}+ </span>+ </div>+ ))}+ </div>+ </div>+ )}++ {selectedNote.tags?.length > 0 && (+ <div>+ <h4 className="text-xs font-medium text-gray-400 uppercase mb-1">Tags</h4>+ <div className="flex flex-wrap gap-1">+ {selectedNote.tags.map(tag => (+ <span key={tag} className="px-1.5 py-0.5 rounded text-xs bg-port-accent/20 text-port-accent">+ #{tag}+ </span>+ ))}+ </div>+ </div>+ )}++ {renderLinks(selectedNote)}+ </div>+ )}+ </div>+ </>+ );+}diff --git a/client/src/components/wiki/tabs/BrowseTab.jsx b/client/src/components/wiki/tabs/BrowseTab.jsxindex a30ba2d321..a1669c6eb1 100644--- a/client/src/components/wiki/tabs/BrowseTab.jsx+++ b/client/src/components/wiki/tabs/BrowseTab.jsx@@ -1,18 +1,15 @@-import { useState, useEffect, useCallback, useRef } from 'react';+import { useState, useCallback } from 'react';import { useSearchParams } from 'react-router';import * as api from '../../../services/api';import {FileText, FolderOpen,- ChevronDown, ChevronRight, ArrowLeft, Tag, Link2, Edit3, Save,- Trash2, X} from 'lucide-react';+ ChevronDown, ChevronRight, ArrowLeft, Tag, Link2} from 'lucide-react';import toast from '../../ui/Toast';-import InlineConfirmRow from '../../ui/InlineConfirmRow';-import { timeAgo, formatBytes } from '../../../utils/formatters';import { WIKI_CATEGORIES } from '../constants.jsx';-import BrailleSpinner from '../../BrailleSpinner';import OfflineNotesNotice from '../../OfflineNotesNotice.jsx';import { useNoteSave } from '../../../hooks/useNoteSave.js';import useMounted from '../../../hooks/useMounted';-import ForceSaveNoteRow from '../../ForceSaveNoteRow.jsx';+import NoteDetailPane from '../../notes/NoteDetailPane.jsx';+import useVaultNote from '../../../hooks/useVaultNote.js';const WIKI_FOLDERS = WIKI_CATEGORIES.map(c => ({ key: c.folder, label: c.label, icon: c.icon, color: c.textClass }));const RAW_FOLDERS = [{ key: 'raw', label: 'Raw Sources', icon: FolderOpen, color: 'text-gray-400' }];@@ -20,12 +17,15 @@ const RAW_FOLDERS = [{ key: 'raw', label: 'Raw Sources', icon: FolderOpen, colorexport default function BrowseTab({ vaultId, notes, rawNotes, allNotes, onRefresh }) {const [searchParams, setSearchParams] = useSearchParams();const noteParam = searchParams.get('note');- const [loadedNote, setSelectedNote] = useState(null);- const selectedNote = loadedNote?.path === noteParam ? loadedNote : null;const [noteContent, setNoteContent] = useState('');const [editing, setEditing] = useState(false);- const [loadingNote, setLoadingNote] = useState(false);- const [noteUnavailable, setNoteUnavailable] = useState(false);+ const {+ note: selectedNote, setNote: setSelectedNote, loading: loadingNote,+ error: noteUnavailable, retry: retryNote, sequenceRef: noteSequence,+ } = useVaultNote(vaultId, noteParam, {+ onReset: () => { setNoteContent(''); setEditing(false); setConfirmDelete(null); },+ onLoad: note => setNoteContent(note.content),+ });const [expandedFolders, setExpandedFolders] = useState(new Set(['wiki/sources', 'wiki/entities', 'wiki/concepts']));const [activeSection, setActiveSection] = useState('wiki');const [tags, setTags] = useState([]);@@ -33,9 +33,7 @@ export default function BrowseTab({ vaultId, notes, rawNotes, allNotes, onRefresconst [skippedTagNotes, setSkippedTagNotes] = useState(0);const [showTags, setShowTags] = useState(false);const [confirmDelete, setConfirmDelete] = useState(null);- const editorRef = useRef(null);const mountedRef = useMounted();- const noteSequence = useRef(0);// Owns the write plus the iCloud force-save escape hatch (#3717).const { saving, save, forceOffered, dismissForce } = useNoteSave({@@ -54,31 +52,6 @@ export default function BrowseTab({ vaultId, notes, rawNotes, allNotes, onRefres}, options);};- // URL identity owns the read. Loading/error state must not re-trigger it, or- // a missing note retries forever. Cleanup also invalidates pending saves.- useEffect(() => {- const sequence = ++noteSequence.current;- setSelectedNote(null);- setNoteContent('');- setEditing(false);- setConfirmDelete(null);- setNoteUnavailable(false);- setLoadingNote(!!noteParam);- if (noteParam) {- api.getNote(vaultId, noteParam).catch(() => null).then(data => {- if (!mountedRef.current || sequence !== noteSequence.current) return;- if (data && !data.error) {- setSelectedNote(data);- setNoteContent(data.content);- } else {- setNoteUnavailable(true);- }- setLoadingNote(false);- });- }- return () => { ++noteSequence.current; };- }, [vaultId, noteParam, mountedRef]);-const handleSelectNote = (notePath) => updateNoteParam(notePath);// `force` is ONLY ever passed by <ForceSaveNoteRow>'s confirm (#3717) — never@@ -243,204 +216,56 @@ export default function BrowseTab({ vaultId, notes, rawNotes, allNotes, onRefres{/* Right panel: note viewer. Hidden on mobile until a note is opened. */}<div className={`flex-col min-w-0 min-h-0 overflow-hidden ${noteParam ? 'flex' : 'hidden md:flex'}`}>- {loadingNote ? (- <div className="flex items-center justify-center h-full">- <BrailleSpinner text="Loading" />- </div>- ) : noteUnavailable ? (- <div className="flex flex-col items-center justify-center h-full gap-3 p-4 text-gray-500">- <p className="text-sm">Page unavailable in this vault</p>- <button type="button" onClick={() => updateNoteParam(null, { replace: true })} className="text-sm text-port-accent hover:underline">- Back to list- </button>- </div>- ) : selectedNote ? (- <>- {/* Note header */}- <div className="px-4 py-3 border-b border-port-border flex items-center gap-3">- <button- onClick={() => { setSelectedNote(null); updateNoteParam(null, { replace: true }); }}- aria-label="Back to list"- className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1 rounded hover:bg-port-card text-gray-400 hover:text-white md:hidden"- >- <ArrowLeft size={16} />- </button>- <div className="flex-1 min-w-0">- <h2 className="text-white font-medium truncate">{selectedNote.name}</h2>- <div className="flex items-center gap-3 text-xs text-gray-500">- {selectedNote.folder && (- <span className="flex items-center gap-1">- <FolderOpen size={10} />- {selectedNote.folder}- </span>- )}- <span>Modified {timeAgo(selectedNote.modifiedAt)}</span>- <span>{formatBytes(selectedNote.size)}</span>- </div>- </div>- <div className="flex items-center gap-1">- {editing ? (- <>- <button- onClick={() => handleSaveNote()}- disabled={saving}- className="flex items-center gap-1 px-3 py-1.5 rounded bg-port-accent text-white text-sm hover:bg-port-accent/80 disabled:opacity-50"- >- <Save size={14} />- {saving ? 'Saving...' : 'Save'}- </button>- <button- onClick={() => { setEditing(false); setNoteContent(selectedNote.content); }}- aria-label="Cancel"- className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1.5 rounded hover:bg-port-card text-gray-400 hover:text-white"- >- <X size={16} />- </button>- </>- ) : (- <button- onClick={() => setEditing(true)}- className="flex items-center gap-1 px-3 py-1.5 rounded bg-port-card text-gray-300 text-sm hover:text-white hover:bg-port-border"- >- <Edit3 size={14} />- Edit- </button>- )}- <button- onClick={() => setConfirmDelete(selectedNote.path)}- className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1.5 rounded hover:bg-port-card text-gray-400 hover:text-port-error"- title="Delete note" aria-label="Delete note"- >- <Trash2 size={14} />- </button>- </div>+ <NoteDetailPane+ selectedNote={selectedNote} loading={loadingNote} error={noteUnavailable}+ onRetry={retryNote} onBack={() => updateNoteParam(null, { replace: true })}+ backLabel="Back to list" cancelLabel="Cancel"+ editing={editing} onSetEditing={setEditing} noteContent={noteContent}+ onSetContent={setNoteContent} saving={saving} onSave={handleSaveNote}+ confirmingDelete={selectedNote ? confirmDelete === selectedNote.path : false}+ onRequestDelete={setConfirmDelete} onDelete={handleDeleteNote}+ onCancelDelete={() => setConfirmDelete(null)}+ forceOffered={forceOffered} dismissForce={dismissForce}+ renderPreview={content => (+ <div className="prose prose-invert prose-sm max-w-none">+ <pre className="whitespace-pre-wrap break-words text-sm text-gray-300 font-mono leading-relaxed">{content}</pre></div>-- {/* Delete confirmation */}- {confirmDelete === selectedNote.path && (- <InlineConfirmRow- variant="separator"- question="Delete this note permanently?"- onConfirm={() => handleDeleteNote(selectedNote.path)}- onCancel={() => setConfirmDelete(null)}- />- )}-- {/* Editor-only: outside edit mode there is no buffer the user meant to- write, and a stray "Save anyway" click would still issue the risky- forced write. */}- <ForceSaveNoteRow- offered={editing && forceOffered}- onConfirm={() => handleSaveNote({ force: true })}- onCancel={dismissForce}- />-- {/* Note content */}- <div className="flex-1 min-h-0 overflow-auto flex">- <div className="flex-1 min-w-0">- {editing ? (- <textarea- aria-label="Note content"- ref={editorRef}- value={noteContent}- onChange={e => setNoteContent(e.target.value)}- className="w-full h-full p-4 bg-port-bg text-gray-200 font-mono text-sm resize-none focus:outline-none"- spellCheck={false}- onKeyDown={e => {- if ((e.metaKey || e.ctrlKey) && e.key === 's') {- e.preventDefault();- handleSaveNote();- }- }}- />- ) : (- <div className="p-4 prose prose-invert prose-sm max-w-none">- <pre className="whitespace-pre-wrap break-words text-sm text-gray-300 font-mono leading-relaxed">- {selectedNote.body || selectedNote.content}- </pre>+ )}+ renderLinks={note => (+ <>+ {note.wikilinks?.length > 0 && (+ <div>+ <h4 className="text-xs font-medium text-gray-400 uppercase mb-1 flex items-center gap-1">+ <Link2 size={10} /> Links ({note.wikilinks.length})+ </h4>+ <div className="space-y-0.5">+ {note.wikilinks.map(link => (+ <button key={link} onClick={() => {+ const match = allNotes.find(n => n.name.toLowerCase() === link.toLowerCase());+ if (match) handleSelectNote(match.path);+ else toast.error(`"${link}" not found`);+ }} className="block w-full text-left text-xs text-port-accent hover:text-white truncate">{link}</button>+ ))}</div>- )}- </div>-- {/* Sidebar: metadata */}- {!editing && (- <div className="w-56 border-l border-port-border p-3 space-y-4 shrink-0 overflow-auto hidden lg:block">- {selectedNote.frontmatter && Object.keys(selectedNote.frontmatter).length > 0 && (- <div>- <h4 className="text-xs font-medium text-gray-400 uppercase mb-1">Properties</h4>- <div className="space-y-1">- {Object.entries(selectedNote.frontmatter).map(([key, val]) => (- <div key={key} className="text-xs">- <span className="text-gray-500">{key}:</span>{' '}- <span className="text-gray-300">{Array.isArray(val) ? val.join(', ') : String(val)}</span>- </div>- ))}- </div>- </div>- )}-- {selectedNote.tags?.length > 0 && (- <div>- <h4 className="text-xs font-medium text-gray-400 uppercase mb-1">Tags</h4>- <div className="flex flex-wrap gap-1">- {selectedNote.tags.map(tag => (- <span key={tag} className="px-1.5 py-0.5 rounded text-xs bg-port-accent/20 text-port-accent">#{tag}</span>- ))}- </div>- </div>- )}-- {selectedNote.wikilinks?.length > 0 && (- <div>- <h4 className="text-xs font-medium text-gray-400 uppercase mb-1 flex items-center gap-1">- <Link2 size={10} /> Links ({selectedNote.wikilinks.length})- </h4>- <div className="space-y-0.5">- {selectedNote.wikilinks.map(link => (- <button- key={link}- onClick={() => {- const match = allNotes.find(n => n.name.toLowerCase() === link.toLowerCase());- if (match) handleSelectNote(match.path);- else toast.error(`"${link}" not found`);- }}- className="block w-full text-left text-xs text-port-accent hover:text-white truncate"- >- {link}- </button>- ))}- </div>- </div>- )}-- {selectedNote.backlinks?.length > 0 && (- <div>- <h4 className="text-xs font-medium text-gray-400 uppercase mb-1 flex items-center gap-1">- <ArrowLeft size={10} /> Backlinks ({selectedNote.backlinks.length})- </h4>- <div className="space-y-0.5">- {selectedNote.backlinks.map(bl => (- <button- key={bl.path}- onClick={() => handleSelectNote(bl.path)}- className="block w-full text-left text-xs text-port-accent hover:text-white truncate"- >- {bl.name}- </button>- ))}- </div>- </div>- )}</div>)}- </div>- </>- ) : (- <div className="flex flex-col items-center justify-center h-full text-gray-500">- <FileText size={48} className="mb-3 opacity-30" />- <p className="text-sm">Select a page to view</p>- </div>- )}+ {note.backlinks?.length > 0 && (+ <div>+ <h4 className="text-xs font-medium text-gray-400 uppercase mb-1 flex items-center gap-1">+ <ArrowLeft size={10} /> Backlinks ({note.backlinks.length})+ </h4>+ <div className="space-y-0.5">+ {note.backlinks.map(bl => (+ <button key={bl.path} onClick={() => handleSelectNote(bl.path)}+ className="block w-full text-left text-xs text-port-accent hover:text-white truncate">{bl.name}</button>+ ))}+ </div>+ </div>+ )}+ </>+ )}+ emptyIcon={FileText} emptyLabel="Select a page to view"+ /></div></div>);diff --git a/client/src/components/wiki/tabs/BrowseTab.test.jsx b/client/src/components/wiki/tabs/BrowseTab.test.jsxindex bd9541f495..8df56192ea 100644--- a/client/src/components/wiki/tabs/BrowseTab.test.jsx+++ b/client/src/components/wiki/tabs/BrowseTab.test.jsx@@ -62,7 +62,7 @@ describe('BrowseTab responsive list/detail', () => {it('selecting a note loads it and exposes a mobile back control that clears selection', async () => {renderTab();fireEvent.click(screen.getByText('Example Source'));- await waitFor(() => expect(api.getNote).toHaveBeenCalledWith('v1', 'wiki/sources/example.md'));+ await waitFor(() => expect(api.getNote).toHaveBeenCalledWith('v1', 'wiki/sources/example.md', { silent: true }));const back = await screen.findByLabelText('Back to list');// Back control is mobile-only (hidden from md+).@@ -76,12 +76,26 @@ describe('BrowseTab responsive list/detail', () => {it('opens a note from the URL and removes the note param when closed', async () => {renderTab(['/wiki/browse?vault=v1¬e=wiki%2Fsources%2Fexample.md']);- await waitFor(() => expect(api.getNote).toHaveBeenCalledWith('v1', 'wiki/sources/example.md'));+ await waitFor(() => expect(api.getNote).toHaveBeenCalledWith('v1', 'wiki/sources/example.md', { silent: true }));expect(await screen.findByRole('heading', { name: 'Example Source' })).toBeInTheDocument();fireEvent.click(screen.getByRole('button', { name: 'Back to list' }));await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/wiki/browse?vault=v1'));});++ it('keeps a failed read selected and retries it without calling the page missing', async () => {+ api.getNote.mockRejectedValueOnce(new Error('temporary vault failure'));+ renderTab(['/wiki/browse?vault=v1¬e=wiki%2Fsources%2Fexample.md']);++ expect(await screen.findByText('Note is unavailable')).toBeInTheDocument();+ expect(screen.queryByText('Page unavailable in this vault')).toBeNull();+ expect(screen.getByTestId('location')).toHaveTextContent('note=wiki%2Fsources%2Fexample.md');++ api.getNote.mockResolvedValueOnce(sampleNote);+ fireEvent.click(screen.getByRole('button', { name: 'Retry' }));+ expect(await screen.findByRole('heading', { name: 'Example Source' })).toBeInTheDocument();+ expect(api.getNote).toHaveBeenCalledTimes(2);+ });});/**diff --git a/client/src/hooks/README.md b/client/src/hooks/README.mdindex 757662c803..abe6600885 100644--- a/client/src/hooks/README.md+++ b/client/src/hooks/README.md@@ -120,6 +120,7 @@ grep -i "what you want to do" client/src/hooks/README.md| `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 (`initialFocusRef` if given, else the first focusable), traps Tab/Shift+Tab so it can't escape to the page behind — including from an `initialFocusRef` aimed at a `tabIndex={-1}` element, which is outside the tab order and would otherwise fall through to the browser — 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. |+| `useVaultNote` | Reads a URL-selected vault note with a sequence guard; returns `{ note, setNote, loading, error, retry, clear, sequenceRef }` and reports failed reads separately from empty selection. | Brain Notes and Wiki Browse detail panes. || `useCmdKSearch` | `⌘K` open/close state. | Anywhere that needs to toggle the palette. || `useContainerWidth` | `[ref, width]` via ResizeObserver. | Layout responds to a specific container's width. || `useCooldownTick` | 1-second ticker over a `{ id: epochMs }` cooldown map; fires `onAllExpired` once when every deadline passes. | Rate-limit countdown labels that need to refetch when the last cooldown clears (agents tabs pattern). |diff --git a/client/src/hooks/index.js b/client/src/hooks/index.jsindex abb567870b..fb471244c1 100644--- a/client/src/hooks/index.js+++ b/client/src/hooks/index.js@@ -32,6 +32,7 @@ export { default as useGallerySidecars } from './useGallerySidecars.js';export { default as useGalleryPreviewResolver } from './useGalleryPreviewResolver.js';export { default as useImageVariants } from './useImageVariants.js';export { default as useNoteSave } from './useNoteSave.js';+export { default as useVaultNote } from './useVaultNote.js';export { default as useHoverTooltip } from './useHoverTooltip.js';export { default as useHydratedPreviewRoute } from './useHydratedPreviewRoute.js';export { default as useImageGenQueue } from './useImageGenQueue.js';diff --git a/client/src/hooks/useVaultNote.js b/client/src/hooks/useVaultNote.jsnew file mode 100644index 0000000000..55beec98af--- /dev/null+++ b/client/src/hooks/useVaultNote.js@@ -0,0 +1,49 @@+import { useCallback, useEffect, useRef, useState } from 'react';+import * as api from '../services/api';++/** Read the note named by the URL, discarding responses from older selections. */+export default function useVaultNote(vaultId, notePath, { onReset, onLoad } = {}) {+ const [loadedNote, setLoadedNote] = useState(null);+ const [loading, setLoading] = useState(false);+ const [error, setError] = useState(false);+ const [attempt, setAttempt] = useState(0);+ const sequenceRef = useRef(0);+ const callbacks = useRef({ onReset, onLoad });+ callbacks.current = { onReset, onLoad };++ const clear = useCallback(() => {+ sequenceRef.current += 1;+ setLoadedNote(null);+ setLoading(false);+ setError(false);+ callbacks.current.onReset?.();+ }, []);++ const retry = useCallback(() => setAttempt(value => value + 1), []);++ useEffect(() => {+ const sequence = ++sequenceRef.current;+ setLoadedNote(null);+ setError(false);+ setLoading(Boolean(vaultId && notePath));+ callbacks.current.onReset?.();+ if (vaultId && notePath) {+ api.getNote(vaultId, notePath, { silent: true }).then(data => {+ if (sequence !== sequenceRef.current) return;+ if (data && !data.error && data.path === notePath) {+ setLoadedNote(data);+ callbacks.current.onLoad?.(data);+ } else setError(true);+ setLoading(false);+ }).catch(() => {+ if (sequence !== sequenceRef.current) return;+ setError(true);+ setLoading(false);+ });+ }+ return () => { ++sequenceRef.current; };+ }, [vaultId, notePath, attempt]);++ const note = loadedNote?.path === notePath ? loadedNote : null;+ return { note, setNote: setLoadedNote, loading, error, retry, clear, sequenceRef };+}