fix: keep browser tab session navigation stable

Keep the browser pane loaded URL separate from the in-frame current URL so SPA navigation updates the address bar and history without remounting the iframe or resetting the Electron webview src.

Preserve parsed ?session= route params during initial URL normalization and pass a directory hint when applying deep links, preventing embedded OpenChamber sessions from collapsing back to / while bootstrap catches up.
This commit is contained in:
Bohdan Triapitsyn
2026-07-07 20:58:54 +03:00
parent 44f44da212
commit 42e470cefa
2 changed files with 43 additions and 26 deletions
+14 -4
View File
@@ -60,7 +60,8 @@ export function useRouter(): void {
if (route.sessionId) {
const currentSessionId = useSessionUIStore.getState().currentSessionId;
if (route.sessionId !== currentSessionId) {
await setCurrentSession(route.sessionId);
const directoryHint = useSessionUIStore.getState().getDirectoryForSession(route.sessionId);
setCurrentSession(route.sessionId, directoryHint);
}
}
@@ -143,14 +144,23 @@ export function useRouter(): void {
const initializeRoute = async () => {
await applyRoute(route);
// After applying, update URL to normalized form (use replaceState)
// After applying, update URL to normalized form (use replaceState).
// Use the parsed route values instead of an immediate store snapshot so
// deep links do not briefly normalize `?session=...` back to `/` while
// the session's directory/message bootstrap is still catching up.
if (!isVSCode) {
syncURLFromState({ replace: true });
updateBrowserURL({
...getCurrentAppState(),
sessionId: route.sessionId ?? useSessionUIStore.getState().currentSessionId,
tab: route.tab ?? useUIStore.getState().activeMainTab,
settingsPath: route.settingsPath ?? useUIStore.getState().settingsPage,
diffFile: route.diffFile ?? useUIStore.getState().pendingDiffFile,
}, { replace: true, force: true });
}
};
void initializeRoute();
}, [applyRoute, isVSCode, syncURLFromState]);
}, [applyRoute, getCurrentAppState, isVSCode]);
// Subscribe to session changes
React.useEffect(() => {