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:
Maurice
2026-10-08 00:01:33 +00:00
parent 254a214b7d
commit 0126ef3401
10 changed files with 117 additions and 37 deletions
@@ -18,9 +18,17 @@ const BUILT = __TREK_UI_VERSION__
const NEXT = `${BUILT}-next`
beforeEach(() => {
useServerVersionStore.setState({ reported: null })
useServerVersionStore.setState({ first: null, reported: null })
})
/** The page starts on this build's version; then the server reports `version`. */
function deploy(version: string) {
act(() => {
useServerVersionStore.getState().note(BUILT)
useServerVersionStore.getState().note(version)
})
}
afterEach(() => {
switchToServerVersion.mockClear()
sessionStorage.removeItem('trek_app_version_reload')
@@ -38,7 +46,7 @@ describe('NewVersionNotice', () => {
it('FE-LAYOUT-NEWVER-002: offers the reload once the server reports a newer build', async () => {
render(<NewVersionNotice />)
act(() => useServerVersionStore.getState().note(NEXT))
deploy(NEXT)
expect(screen.getByRole('status')).toHaveTextContent('A new version is available')
await userEvent.click(screen.getByRole('button', { name: 'Reload page' }))
@@ -50,7 +58,7 @@ describe('NewVersionNotice', () => {
it('FE-LAYOUT-NEWVER-003: closing it hides that version, and the next release asks again', async () => {
render(<NewVersionNotice />)
act(() => useServerVersionStore.getState().note(NEXT))
deploy(NEXT)
await userEvent.click(screen.getByRole('button', { name: 'Close' }))
expect(screen.queryByRole('status')).toBeNull()
@@ -62,13 +70,20 @@ describe('NewVersionNotice', () => {
it('FE-LAYOUT-NEWVER-004: stays away offline, where a reload could not fetch the new build', () => {
setForcedOffline(true)
render(<NewVersionNotice />)
act(() => useServerVersionStore.getState().note(NEXT))
deploy(NEXT)
expect(screen.queryByRole('status')).toBeNull()
})
it('FE-LAYOUT-NEWVER-005: stays away once this session reloaded for that version without getting it', () => {
sessionStorage.setItem('trek_app_version_reload', NEXT)
render(<NewVersionNotice />)
deploy(NEXT)
expect(screen.queryByRole('status')).toBeNull()
})
it('FE-LAYOUT-NEWVER-006: a different version from the start is the launch handover\'s, not the notice\'s', () => {
// Also an install whose server never reports the bundle's version: no notice every session.
render(<NewVersionNotice />)
act(() => useServerVersionStore.getState().note(NEXT))
expect(screen.queryByRole('status')).toBeNull()
})
@@ -5,7 +5,8 @@
* restarts it, so every open client hears of a new release within seconds. A
* launch brings an outdated page onto the current build by itself
* (versionHandover); a page in use is never reloaded under the user's hands, so
* this offers the reload instead, and the reload goes through the same handover.
* this offers the reload instead, for a version that changed while the page was
* open, and the reload goes through the same handover.
*
* One notice for both shells, rendered once in App. Hidden offline, where a
* reload could not fetch the new build, and once dismissed for that version.
@@ -22,11 +23,15 @@ import { useTranslation } from '../../i18n'
export default function NewVersionNotice(): React.ReactElement | null {
const { t } = useTranslation()
const reported = useServerVersionStore(s => s.reported)
const first = useServerVersionStore(s => s.first)
const { offline } = useNetworkMode()
const [dismissed, setDismissed] = useState<string | null>(null)
const [switching, setSwitching] = useState(false)
if (offline || !reported || reported === dismissed || !offersNewBuild(reported)) return null
// Only a version that changed while this page was open: a different build at
// launch is the launch handover's to fix, and an install whose server never
// reports the bundle's version would otherwise be asked every session.
if (offline || !reported || reported === first || reported === dismissed || !offersNewBuild(reported)) return null
const reload = (): void => {
setSwitching(true)