fix(client): honour the start page on a device that never mirrored it

The mirror answered "dashboard" for a browser that had simply never been
told, and RootRedirect took that as the user's choice - so the setting was
ignored on every device except the one that set it, and on that one too
after a logout cleared the mirror. The setting itself was stored correctly
the whole time, which is what made it look like nothing happened.

readStartDestination now says "unknown" rather than guessing, and a device
in that state waits for the real settings instead. That costs one wait,
once per device; afterwards the mirror answers and the launch is as fast
as before. Bounded by a timeout, because loadSettings deliberately leaves
isLoaded false on a failed request so it can retry - without the floor, a
launch with no backend would sit on the spinner forever.
This commit is contained in:
Maurice
2026-08-08 21:58:42 +02:00
committed by Maurice
parent 0a824cec84
commit e7851e79ff
4 changed files with 103 additions and 22 deletions
+20 -6
View File
@@ -19,6 +19,13 @@ export const DEFAULT_START_TRIP_TAB = 'plan'
*/
export const START_DESTINATION_ROUTE = '/'
/**
* How long a device that has never seen the preference waits for the settings
* before giving up and opening the dashboard. Long enough for a normal request,
* short enough that a launch with no backend isn't stuck staring at a spinner.
*/
export const SETTINGS_WAIT_MS = 2500
export interface StartDestination {
page: StartPage
tab: string
@@ -36,17 +43,24 @@ const TAB_KEY = 'trek_start_trip_tab'
const isStartPage = (value: unknown): value is StartPage =>
value === 'dashboard' || value === 'active_trip'
export function readStartDestination(): StartDestination {
/**
* What this device last knew, or null if it has never been told — a fresh
* browser, another machine, or one that has logged out since.
*
* The null case matters: the preference lives on the server, so "this device
* doesn't know" is not the same as "this user wants the dashboard". Callers
* have to wait for the real settings rather than assume the default, or the
* setting is silently ignored on every device that didn't set it.
*/
export function readStartDestination(): StartDestination | null {
try {
const page = localStorage.getItem(PAGE_KEY)
if (!isStartPage(page)) return null
const tab = localStorage.getItem(TAB_KEY)
return {
page: isStartPage(page) ? page : DEFAULT_START_PAGE,
tab: isTripTabId(tab) ? tab : DEFAULT_START_TRIP_TAB,
}
return { page, tab: isTripTabId(tab) ? tab : DEFAULT_START_TRIP_TAB }
} catch {
// Private-mode Safari and friends throw on access, not just on write.
return { page: DEFAULT_START_PAGE, tab: DEFAULT_START_TRIP_TAB }
return null
}
}