Skip to content

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

fix: encode Wiki vault selection in the URL (#2544)

Adam Eivy5d6979c5020e
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 4cb3eaebb2..df244df40f 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -7,6 +7,7 @@
## Fixed
+- **[issue-2544] Wiki vault selection now lives in the URL.** The selected Obsidian vault was local `useState`, so a reload, shared link, ⌘K jump, or voice nav always landed you back on the first vault. The vault is now encoded as a `?vault=<id>` search param (the tab route param is preserved when switching tabs), selection is driven from the URL, and a stale/deleted vault id renders a "Vault not found" fallback with a one-click "Show default vault" recovery.
- **POST Digit Span: the form no longer jumps up as digits flash on and off.** During the show phase the visible-digit slot collapsed to zero height in the blank gaps between digits, so the container (padding + `min-h`) oscillated and the recall form/progress bar below shifted up on every flash. The slot now reserves its line box with a non-breaking space in the gaps, keeping the layout steady while digits flash.
## Security
diff --git a/client/src/pages/Wiki.jsx b/client/src/pages/Wiki.jsx
index 549b39946b..ea6d0331e7 100644
--- a/client/src/pages/Wiki.jsx
+++ b/client/src/pages/Wiki.jsx
@@ -1,5 +1,5 @@
import { useState, useEffect, useCallback, useMemo } from 'react';
-import { useParams, useNavigate } from 'react-router-dom';
+import { useParams, useNavigate, useSearchParams } from 'react-router-dom';
import * as api from '../services/api';
import { BookOpen, Search, Network, FileText, BarChart3, Activity } from 'lucide-react';
import BrailleSpinner from '../components/BrailleSpinner';
@@ -24,22 +24,47 @@ export const TABS = [
export default function Wiki() {
const { tab } = useParams();
const navigate = useNavigate();
+ const [searchParams, setSearchParams] = useSearchParams();
const activeTab = tab || 'overview';
+ // The selected vault lives in the URL (?vault=<id>) so reload/share/⌘K/voice restore it.
+ const vaultParam = searchParams.get('vault');
const [vaults, setVaults] = useState([]);
- const [selectedVaultId, setSelectedVaultId] = useState(null);
const [loading, setLoading] = useState(true);
const [notes, setNotes] = useState([]);
const loadVaults = useCallback(async () => {
const data = await api.getNotesVaults().catch(() => []);
setVaults(data);
- if (data.length > 0) {
- setSelectedVaultId(prev => prev || data[0].id);
- }
setLoading(false);
}, []);
+ // Selection is derived FROM the URL: an explicit ?vault= wins, otherwise fall
+ // back to the first vault. A param that matches no vault is a stale/deleted id.
+ const selectedVault = useMemo(
+ () => (vaultParam ? vaults.find(v => v.id === vaultParam) : vaults[0]) || null,
+ [vaultParam, vaults]
+ );
+ const selectedVaultId = selectedVault?.id || null;
+ const vaultNotFound = !loading && vaults.length > 0 && !!vaultParam && !selectedVault;
+
+ // Selection handler writes the id to the URL; the tab route param is untouched.
+ const selectVault = useCallback((id) => {
+ setSearchParams(prev => {
+ const next = new URLSearchParams(prev);
+ next.set('vault', id);
+ return next;
+ }, { replace: true });
+ }, [setSearchParams]);
+
+ const clearVaultParam = useCallback(() => {
+ setSearchParams(prev => {
+ const next = new URLSearchParams(prev);
+ next.delete('vault');
+ return next;
+ }, { replace: true });
+ }, [setSearchParams]);
+
const loadNotes = useCallback(async () => {
if (!selectedVaultId) return;
const data = await api.scanNotesVault(selectedVaultId, { limit: 1000 }).catch(() => null);
@@ -100,6 +125,23 @@ export default function Wiki() {
);
}
+ if (vaultNotFound) {
+ return (
+ <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">Vault not found</p>
+ <p className="text-xs mt-1">The selected vault is no longer available.</p>
+ <button
+ type="button"
+ onClick={clearVaultParam}
+ className="mt-3 text-xs text-port-accent hover:underline"
+ >
+ Show default vault
+ </button>
+ </div>
+ );
+ }
+
const renderTabContent = () => {
switch (activeTab) {
case 'overview':
@@ -130,7 +172,7 @@ export default function Wiki() {
{vaults.length > 1 && (
<select
value={selectedVaultId || ''}
- onChange={e => setSelectedVaultId(e.target.value)}
+ onChange={e => selectVault(e.target.value)}
className="bg-port-bg border border-port-border rounded px-2 py-1 text-sm text-white"
>
{vaults.map(v => (
@@ -142,7 +184,7 @@ export default function Wiki() {
}
/>
- <TabPills tabs={TABS} activeTab={activeTab} onChange={(id) => navigate(`/wiki/${id}`)} ariaLabel="Wiki sections" />
+ <TabPills tabs={TABS} activeTab={activeTab} onChange={(id) => navigate({ pathname: `/wiki/${id}`, search: searchParams.toString() })} ariaLabel="Wiki sections" />
{/* Tab content */}
<div className="flex-1 overflow-auto p-4">
diff --git a/client/src/pages/Wiki.test.jsx b/client/src/pages/Wiki.test.jsx
new file mode 100644
index 0000000000..3fe20a2248
--- /dev/null
+++ b/client/src/pages/Wiki.test.jsx
@@ -0,0 +1,77 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { render, screen, waitFor, fireEvent } from '@testing-library/react';
+import { MemoryRouter, Routes, Route, useLocation } from 'react-router-dom';
+
+vi.mock('../services/api', () => ({
+ getNotesVaults: vi.fn(),
+ scanNotesVault: vi.fn(),
+}));
+
+// Stub the tab bodies — this suite only exercises vault selection + URL wiring.
+vi.mock('../components/wiki/tabs/OverviewTab', () => ({
+ default: ({ vaultId }) => <div data-testid="overview">overview:{vaultId || 'none'}</div>,
+}));
+vi.mock('../components/wiki/tabs/BrowseTab', () => ({ default: () => <div>browse</div> }));
+vi.mock('../components/wiki/tabs/SearchTab', () => ({ default: () => <div>search</div> }));
+vi.mock('../components/wiki/tabs/GraphTab', () => ({ default: () => <div>graph</div> }));
+vi.mock('../components/wiki/tabs/LogTab', () => ({ default: () => <div>log</div> }));
+
+import Wiki from './Wiki';
+import { getNotesVaults, scanNotesVault } from '../services/api';
+
+function LocationProbe() {
+ const loc = useLocation();
+ return <div data-testid="location">{loc.pathname + loc.search}</div>;
+}
+
+const renderWiki = (initialEntry) =>
+ render(
+ <MemoryRouter initialEntries={[initialEntry]}>
+ <LocationProbe />
+ <Routes>
+ <Route path="/wiki/:tab" element={<Wiki />} />
+ </Routes>
+ </MemoryRouter>,
+ );
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ getNotesVaults.mockResolvedValue([
+ { id: 'vault-a', name: 'Vault A' },
+ { id: 'vault-b', name: 'Vault B' },
+ ]);
+ scanNotesVault.mockResolvedValue({ notes: [] });
+});
+
+describe('Wiki vault URL wiring', () => {
+ it('defaults to the first vault when no ?vault= param is present', async () => {
+ renderWiki('/wiki/overview');
+ await waitFor(() => expect(screen.getByTestId('overview')).toHaveTextContent('overview:vault-a'));
+ expect(scanNotesVault).toHaveBeenCalledWith('vault-a', { limit: 1000 });
+ });
+
+ it('restores the selected vault from the ?vault= param', async () => {
+ renderWiki('/wiki/overview?vault=vault-b');
+ await waitFor(() => expect(screen.getByTestId('overview')).toHaveTextContent('overview:vault-b'));
+ expect(scanNotesVault).toHaveBeenCalledWith('vault-b', { limit: 1000 });
+ });
+
+ it('writes the chosen vault to the URL when selecting from the dropdown', async () => {
+ renderWiki('/wiki/overview');
+ await waitFor(() => expect(screen.getByTestId('overview')).toHaveTextContent('overview:vault-a'));
+ fireEvent.change(screen.getByRole('combobox'), { target: { value: 'vault-b' } });
+ await waitFor(() =>
+ expect(screen.getByTestId('location')).toHaveTextContent('/wiki/overview?vault=vault-b'),
+ );
+ await waitFor(() => expect(screen.getByTestId('overview')).toHaveTextContent('overview:vault-b'));
+ });
+
+ it('renders a not-found fallback for a stale/deleted vault id', async () => {
+ renderWiki('/wiki/overview?vault=deleted');
+ await waitFor(() => expect(screen.getByText('Vault not found')).toBeInTheDocument());
+ expect(screen.queryByTestId('overview')).not.toBeInTheDocument();
+ // Clearing the param recovers the default vault.
+ fireEvent.click(screen.getByRole('button', { name: /show default vault/i }));
+ await waitFor(() => expect(screen.getByTestId('overview')).toHaveTextContent('overview:vault-a'));
+ });
+});