mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
feat(client): offer the new version when a release lands during a session
A tab kept open across a deploy ran the previous build until its next start. The server now names its version in the realtime welcome frame, which every open client reads again when it reconnects after the restart a deploy brings. When that version is not the build the page runs, a notice offers to reload. The reload goes through the same service worker handover a launch uses: it waits for the new worker to take over, or for a short timeout, and records the version only when the takeover happened. The notice reads the error boundary's texts for the same situation, so every language has it already. It is one component for both shells, sits above the offline pill, stays away offline and after a reload for that version that did not bring it, and can be closed for the session.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { create } from 'zustand'
|
||||
import { asReleaseTag } from '../utils/versionHandover'
|
||||
|
||||
/**
|
||||
* The version the server says it runs, as its realtime socket reports it on
|
||||
* every (re)connect. A deploy restarts the server, so a client that stayed open
|
||||
* across one reconnects and learns the new version here (NewVersionNotice).
|
||||
*/
|
||||
interface ServerVersionState {
|
||||
/** The last version the server reported, or null before its first report. */
|
||||
reported: string | null
|
||||
/** Takes what the welcome frame carries; anything but a release tag is ignored. */
|
||||
note: (value: unknown) => void
|
||||
}
|
||||
|
||||
export const useServerVersionStore = create<ServerVersionState>()((set, get) => ({
|
||||
reported: null,
|
||||
note(value) {
|
||||
const version = asReleaseTag(value)
|
||||
if (version && version !== get().reported) set({ reported: version })
|
||||
},
|
||||
}))
|
||||
Reference in New Issue
Block a user