fix(native): the app's browser sign-in no longer lands on the dashboard when the browser still holds an older TREK

A browser that ran TREK before 5.1.1 keeps that version's app in its service
worker. When the app opened /native-handoff, the worker answered it from its
cache with an app that has no such page, which sent the user to /, and the
sign-in ended on the dashboard in the browser instead of in the app.

The app now opens /api/auth/native/start, which every TREK service worker
passes to the server. That page takes the workers off the browser and
forwards to the handoff page. Until the sign-in is handed back, the web app
registers no service worker and does not reload for a new version: a tab
still open on the older TREK keeps its worker alive, and a registration or a
reload in the middle of the sign-in brought it back to answer the next page.
This commit is contained in:
Maurice
2026-11-09 22:21:09 +01:00
parent 5420077b98
commit 034cfb539a
14 changed files with 286 additions and 7 deletions
+24
View File
@@ -447,6 +447,30 @@ describe('reconcileAppVersion: a page loaded past an older worker', () => {
})
})
describe('reconcileAppVersion: during the app's sign-in in the browser', () => {
it('FE-UTIL-VERSION-058: leaves version and page alone while the sign-in runs, and acts again after it', async () => {
const { container } = installWorker(null)
container.getRegistration.mockResolvedValue(undefined)
const { reconcileAppVersion } = await loadModule()
localStorage.setItem('trek_app_version', '4.3.0')
// public/native-handoff.js marks the sign-in; a reload now could land on an
// older worker that a tab still open on the old version keeps alive.
localStorage.setItem('trek_native_signin', String(Date.now()))
await reconcileAppVersion('4.3.1')
expect(marker()).toBe('4.3.0')
expect(reload).not.toHaveBeenCalled()
expect(container.getRegistration).not.toHaveBeenCalled()
// A mark older than any sign-in takes counts for nothing.
localStorage.setItem('trek_native_signin', String(Date.now() - 16 * 60 * 1000))
await reconcileAppVersion('4.3.1')
expect(marker()).toBe('4.3.1')
expect(reload).toHaveBeenCalledTimes(1)
})
})
describe('reconcileAppVersion: the reload guard', () => {
it('FE-UTIL-VERSION-030: a marker that cannot be written does not turn into a reload loop', async () => {
const { reconcileAppVersion } = await loadModule()
+4
View File
@@ -17,6 +17,7 @@
* version and session.
*/
import { browserSignInRunning } from '../native/browserSignInFlag'
import { reloadFresh } from './chunkReload'
import { currentController, servingWorker } from './serviceWorkerShell'
@@ -198,6 +199,9 @@ function waitForTakeover(reg: ServiceWorkerRegistration, version: string): Promi
export async function reconcileAppVersion(reported: unknown): Promise<void> {
const version = asReleaseTag(reported)
if (!version) return
// The app's sign-in runs in this browser: a reload now could land on an older
// version's worker that a tab still open keeps alive (native/browserSignInFlag).
if (browserSignInRunning()) return
let storedVersion: string | null
try {