feat(auto-update): SPA polls _mokosh_config.js build_sha and reloads on mismatch #94
No reviewers
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
psa-systems/mokosh-apps!94
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/auto-reload-on-new-spa-build"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When a fresh mokosh-apps deploy lands, users with open tabs keep running the previous WASM bundle until they Ctrl+Shift+R. They miss bug fixes, run against renamed endpoints, and silently degrade. The fix: a root-level hook that polls the deployed build identifier and reloads the tab at the next safe boundary.
Wiring:
oci-build/Dockerfilenow exposes the existingGIT_SHAbuild arg as a runtime env (it was already being baked in as an OCI label but not visible to the running container).oci-build/entrypoint.shemits it as thebuild_shafield onwindow.__MOKOSH_CONFIG__in/_mokosh_config.js, alongside the existing operator overrides. The Caddyfile already serves that file withCache-Control: no-cache, so a freshly-deployed image immediately advertises its new hash to any client that probes.src/hooks/update_check.rsis the new root-mounted hook. At app start it snapshots the build hash baked into the running bundle (crate::utils::version::GIT_HASH, frombuild.rs). A backgrounduse_futurere-fetches_mokosh_config.jsevery 5 minutes, re-evals it, and compares the livebuild_shaagainst the snapshot. On mismatch it flips apending_reloadsignal and notes when the mismatch was first observed.The actual
location.reload()fires onvisibilitychange: when the user switches tabs (and the reload is invisible to them), or when the tab has been holding a pending reload for more than 30 minutes (catches the always-on dashboard case so users who never leave the tab still update). This avoids the jarring mid-interaction reload that a naive "reload as soon as we detect" would produce.Dev safety: skipped entirely when
GIT_HASHis empty or"unknown"(cargo run dev builds), so a developer iterating on the SPA does not get their tab reloaded out from under them.Performanceweb-sys feature added forperformance.now()timestamping.