mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
fix(client): the version notice asks about a change during the session only
Three gaps in the notice from the previous commit, found in review. A page served from the network and claimed later by its own build's worker counted as already taken over, so Reload went to that worker, got the old build again and spent the session's reload: no notice and no new build until the next start. Only a worker that replaced the one that served the page skips the handover now, as at launch. A reload that came before the new worker could take over (a slow precache, a failed update, an install gone redundant) also spent that guard, so the launch behind it could no longer finish the handover with its own reload. That reload leaves the guard alone now. An install whose server never reports the bundle's version (a hand-set APP_VERSION) showed the notice in every session, and Reload could not clear it. The store keeps the first version a page hears of, from the app config at launch, and the notice only asks when a later report differs: a different build at launch is the launch handover's to fix. The server's wire-envelope test pins the welcome frame's fields and now expects the version beside the socket id. The wiki's update page says what an open tab shows after an update.
This commit is contained in:
@@ -517,16 +517,19 @@ describe('offersNewBuild: whether the notice offers a reload', () => {
|
||||
})
|
||||
|
||||
describe('switchToServerVersion: the reload the user asked for', () => {
|
||||
const guard = () => sessionStorage.getItem('trek_app_version_reload')
|
||||
|
||||
afterEach(() => {
|
||||
sessionStorage.removeItem('trek_app_version_reload')
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('FE-UTIL-VERSION-050: without a worker it reloads at once, under a fresh URL', async () => {
|
||||
it('FE-UTIL-VERSION-050: without a worker it reloads at once, under a fresh URL, and spends the guard', async () => {
|
||||
const { switchToServerVersion } = await loadModule()
|
||||
await switchToServerVersion('4.3.4')
|
||||
expect(reload).toHaveBeenCalledTimes(1)
|
||||
expect(plainReload).not.toHaveBeenCalled()
|
||||
expect(guard()).toBe('4.3.4')
|
||||
})
|
||||
|
||||
it('FE-UTIL-VERSION-051: waits for the new worker to take over, records the version, then reloads', async () => {
|
||||
@@ -543,6 +546,7 @@ describe('switchToServerVersion: the reload the user asked for', () => {
|
||||
await switching
|
||||
expect(marker()).toBe('4.3.4')
|
||||
expect(reload).toHaveBeenCalledTimes(1)
|
||||
expect(guard()).toBe('4.3.4')
|
||||
})
|
||||
|
||||
it('FE-UTIL-VERSION-052: an unchanged sw.js has nothing to wait for, so it reloads and leaves the marker', async () => {
|
||||
@@ -554,9 +558,10 @@ describe('switchToServerVersion: the reload the user asked for', () => {
|
||||
expect(registration.update).toHaveBeenCalled()
|
||||
expect(marker()).toBe('4.3.3')
|
||||
expect(reload).toHaveBeenCalledTimes(1)
|
||||
expect(guard()).toBe('4.3.4')
|
||||
})
|
||||
|
||||
it('FE-UTIL-VERSION-053: an install that goes redundant still ends in the reload', async () => {
|
||||
it('FE-UTIL-VERSION-053: an install that goes redundant still reloads, but leaves the guard to the next launch', async () => {
|
||||
const { registration } = installWorker()
|
||||
const incoming = updateInstalls(registration)
|
||||
const { switchToServerVersion } = await loadModule()
|
||||
@@ -566,6 +571,8 @@ describe('switchToServerVersion: the reload the user asked for', () => {
|
||||
incoming.become('redundant')
|
||||
await switching
|
||||
expect(reload).toHaveBeenCalledTimes(1)
|
||||
// The launch on the other side retries the handover and reloads by itself.
|
||||
expect(guard()).toBeNull()
|
||||
})
|
||||
|
||||
it('FE-UTIL-VERSION-054: a failed update or a worker that never takes over does not leave the user waiting', async () => {
|
||||
@@ -574,8 +581,8 @@ describe('switchToServerVersion: the reload the user asked for', () => {
|
||||
let { switchToServerVersion } = await loadModule()
|
||||
await switchToServerVersion('4.3.4')
|
||||
expect(reload).toHaveBeenCalledTimes(1)
|
||||
expect(guard()).toBeNull()
|
||||
|
||||
sessionStorage.removeItem('trek_app_version_reload')
|
||||
const stuck = installWorker()
|
||||
updateInstalls(stuck.registration)
|
||||
;({ switchToServerVersion } = await loadModule())
|
||||
@@ -584,9 +591,10 @@ describe('switchToServerVersion: the reload the user asked for', () => {
|
||||
await vi.advanceTimersByTimeAsync(20_000)
|
||||
await switching
|
||||
expect(reload).toHaveBeenCalledTimes(2)
|
||||
expect(guard()).toBeNull()
|
||||
})
|
||||
|
||||
it('FE-UTIL-VERSION-055: a worker the browser swapped in already answers the reload, so nothing is asked of it', async () => {
|
||||
it('FE-UTIL-VERSION-055: a worker that replaced the one that served the page already answers the reload', async () => {
|
||||
const { container, registration } = installWorker()
|
||||
const { switchToServerVersion } = await loadModule()
|
||||
container.controller = new FakeWorker('activated')
|
||||
@@ -596,6 +604,25 @@ describe('switchToServerVersion: the reload the user asked for', () => {
|
||||
expect(reload).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('FE-UTIL-VERSION-057: a worker that only claimed a page from the network holds this build, so the handover still runs', async () => {
|
||||
const { container, registration } = installWorker(null)
|
||||
const { switchToServerVersion } = await loadModule()
|
||||
// registerSW installed this build's worker after the page loaded, and it claimed the page.
|
||||
const claimed = new FakeWorker('activated')
|
||||
container.controller = claimed
|
||||
registration.active = claimed
|
||||
updateInstalls(registration)
|
||||
|
||||
const switching = switchToServerVersion('4.3.4')
|
||||
await vi.waitFor(() => expect(registration.update).toHaveBeenCalled())
|
||||
expect(reload).not.toHaveBeenCalled()
|
||||
|
||||
container.takeOver()
|
||||
await switching
|
||||
expect(marker()).toBe('4.3.4')
|
||||
expect(reload).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('FE-UTIL-VERSION-056: a registration lookup that throws still reloads', async () => {
|
||||
const { container } = installWorker()
|
||||
container.getRegistration.mockRejectedValue(new Error('SecurityError'))
|
||||
|
||||
Reference in New Issue
Block a user