fix(control-ui): preserve URL session parameter over localStorage defaults

When opening the dashboard with a ?session= URL parameter, the session
was being overwritten by applySessionDefaults() after the gateway
connected. This broke direct links to specific sessions (e.g., from
external tools like Kanban boards with per-project sessions).

The fix adds a sessionFromUrl flag that's set when a session is
explicitly provided via URL. applySessionDefaults() now checks for
this flag and skips overriding URL-provided sessions.

Fixes #4150
This commit is contained in:
Joey Frasier 2026-01-29 14:36:50 -05:00
parent 4583f88626
commit a75d939cb0
2 changed files with 12 additions and 0 deletions

View File

@ -84,6 +84,16 @@ function normalizeSessionKeyForDefaults(
function applySessionDefaults(host: GatewayHost, defaults?: SessionDefaultsSnapshot) {
if (!defaults?.mainSessionKey) return;
// If session was explicitly set from URL, don't override with defaults
// This ensures direct links to specific sessions work correctly
const hostWithFlag = host as GatewayHost & { sessionFromUrl?: boolean };
if (hostWithFlag.sessionFromUrl) {
// Clear the flag after first connection so future reconnects can apply defaults if needed
hostWithFlag.sessionFromUrl = false;
return;
}
const resolvedSessionKey = normalizeSessionKeyForDefaults(host.sessionKey, defaults);
const resolvedSettingsSessionKey = normalizeSessionKeyForDefaults(
host.settings.sessionKey,

View File

@ -88,6 +88,8 @@ export function applySettingsFromUrl(host: SettingsHost) {
const session = sessionRaw.trim();
if (session) {
host.sessionKey = session;
// Mark that this session was explicitly set from URL to prevent override by defaults
(host as { sessionFromUrl?: boolean }).sessionFromUrl = true;
applySettings(host, {
...host.settings,
sessionKey: session,