fix(ui): companion rail loads current space on initial page load

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-01 19:39:18 +10:00
parent f49282b00c
commit 15d45a8fd6
2 changed files with 16 additions and 13 deletions

View File

@@ -35,6 +35,10 @@ async function renderView(ctx) {
} else { } else {
state.view = null; state.view = null;
} }
// Notify subscribers (right rail) of the active Space. The state bus replays
// the last value on subscribe, so this covers both the initial route() call
// and every subsequent navigation with one path.
emit('space-active', state.spaceId);
const main = document.getElementById('main'); const main = document.getElementById('main');
const loader = VIEWS[ctx.name] || VIEWS.home; const loader = VIEWS[ctx.name] || VIEWS.home;

View File

@@ -3,7 +3,7 @@ import { el, mount, clear } from '../dom.js';
import { api } from '../api.js'; import { api } from '../api.js';
import { streamTurn } from '../sse.js'; import { streamTurn } from '../sse.js';
import { renderMarkdown } from '../markdown.js'; import { renderMarkdown } from '../markdown.js';
import { state } from '../state.js'; import { state, on } from '../state.js';
const COLLAPSE_KEY = 'void_rail_collapsed'; const COLLAPSE_KEY = 'void_rail_collapsed';
@@ -118,17 +118,16 @@ export async function renderRightrail(root) {
input.addEventListener('keydown', handler); input.addEventListener('keydown', handler);
} }
// Initial render — state.spaceId may be null if route hasn't fired yet. // Load (and re-load) the chat whenever the active Space changes. The state
await initChat(state.spaceId); // bus replays its last value on subscribe, so this fires for the initial
// route() call (covering hard loads to #/space/<id>) as well as every later
// Re-init when navigation brings a new Space into focus. // navigation. We only re-init when the id actually changes so navigating
let lastSpaceId = state.spaceId; // within a Space (page/ref/etc.) doesn't wipe the conversation.
window.addEventListener('hashchange', async () => { let lastSpaceId; let inited = false;
// Wait a tick so app.js's renderView can update state first. on('space-active', (spaceId) => {
await Promise.resolve(); if (inited && spaceId === lastSpaceId) return;
if (state.spaceId !== lastSpaceId) { inited = true;
lastSpaceId = state.spaceId; lastSpaceId = spaceId;
await initChat(state.spaceId); initChat(spaceId);
}
}); });
} }