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:
@@ -35,6 +35,10 @@ async function renderView(ctx) {
|
||||
} else {
|
||||
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 loader = VIEWS[ctx.name] || VIEWS.home;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { el, mount, clear } from '../dom.js';
|
||||
import { api } from '../api.js';
|
||||
import { streamTurn } from '../sse.js';
|
||||
import { renderMarkdown } from '../markdown.js';
|
||||
import { state } from '../state.js';
|
||||
import { state, on } from '../state.js';
|
||||
|
||||
const COLLAPSE_KEY = 'void_rail_collapsed';
|
||||
|
||||
@@ -118,17 +118,16 @@ export async function renderRightrail(root) {
|
||||
input.addEventListener('keydown', handler);
|
||||
}
|
||||
|
||||
// Initial render — state.spaceId may be null if route hasn't fired yet.
|
||||
await initChat(state.spaceId);
|
||||
|
||||
// Re-init when navigation brings a new Space into focus.
|
||||
let lastSpaceId = state.spaceId;
|
||||
window.addEventListener('hashchange', async () => {
|
||||
// Wait a tick so app.js's renderView can update state first.
|
||||
await Promise.resolve();
|
||||
if (state.spaceId !== lastSpaceId) {
|
||||
lastSpaceId = state.spaceId;
|
||||
await initChat(state.spaceId);
|
||||
}
|
||||
// Load (and re-load) the chat whenever the active Space changes. The state
|
||||
// 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
|
||||
// navigation. We only re-init when the id actually changes so navigating
|
||||
// within a Space (page/ref/etc.) doesn't wipe the conversation.
|
||||
let lastSpaceId; let inited = false;
|
||||
on('space-active', (spaceId) => {
|
||||
if (inited && spaceId === lastSpaceId) return;
|
||||
inited = true;
|
||||
lastSpaceId = spaceId;
|
||||
initChat(spaceId);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user