feat(auto-update): SPA polls _mokosh_config.js build_sha and reloads on mismatch #94

Merged
YousifShkara merged 1 commit from feat/auto-reload-on-new-spa-build into main 2026-06-09 04:51:10 +02:00
Owner

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/Dockerfile now exposes the existing GIT_SHA build 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.sh emits it as the build_sha field on window.__MOKOSH_CONFIG__ in /_mokosh_config.js, alongside the existing operator overrides. The Caddyfile already serves that file with Cache-Control: no-cache, so a freshly-deployed image immediately advertises its new hash to any client that probes.

src/hooks/update_check.rs is the new root-mounted hook. At app start it snapshots the build hash baked into the running bundle (crate::utils::version::GIT_HASH, from build.rs). A background use_future re-fetches _mokosh_config.js every 5 minutes, re-evals it, and compares the live build_sha against the snapshot. On mismatch it flips a pending_reload signal and notes when the mismatch was first observed.

The actual location.reload() fires on visibilitychange: 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_HASH is empty or "unknown" (cargo run dev builds), so a developer iterating on the SPA does not get their tab reloaded out from under them.

Performance web-sys feature added for performance.now() timestamping.

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/Dockerfile` now exposes the existing `GIT_SHA` build 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.sh` emits it as the `build_sha` field on `window.__MOKOSH_CONFIG__` in `/_mokosh_config.js`, alongside the existing operator overrides. The Caddyfile already serves that file with `Cache-Control: no-cache`, so a freshly-deployed image immediately advertises its new hash to any client that probes. `src/hooks/update_check.rs` is the new root-mounted hook. At app start it snapshots the build hash baked into the running bundle (`crate::utils::version::GIT_HASH`, from `build.rs`). A background `use_future` re-fetches `_mokosh_config.js` every 5 minutes, re-evals it, and compares the live `build_sha` against the snapshot. On mismatch it flips a `pending_reload` signal and notes when the mismatch was first observed. The actual `location.reload()` fires on `visibilitychange`: 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_HASH` is empty or `"unknown"` (cargo run dev builds), so a developer iterating on the SPA does not get their tab reloaded out from under them. `Performance` web-sys feature added for `performance.now()` timestamping.
feat(auto-update): SPA polls _mokosh_config.js build_sha and reloads on mismatch
All checks were successful
Create release / Create release from merged PR (pull_request) Has been skipped
Check / clippy + fmt + tests (pull_request) Successful in 2m55s
4725c8c057
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/Dockerfile` now exposes the existing `GIT_SHA` build 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.sh` emits it as the `build_sha` field on `window.__MOKOSH_CONFIG__` in `/_mokosh_config.js`, alongside the existing operator overrides. The Caddyfile already serves that file with `Cache-Control: no-cache`, so a freshly-deployed image immediately advertises its new hash to any client that probes.

`src/hooks/update_check.rs` is the new root-mounted hook. At app start it snapshots the build hash baked into the running bundle (`crate::utils::version::GIT_HASH`, from `build.rs`). A background `use_future` re-fetches `_mokosh_config.js` every 5 minutes, re-evals it, and compares the live `build_sha` against the snapshot. On mismatch it flips a `pending_reload` signal and notes when the mismatch was first observed.

The actual `location.reload()` fires on `visibilitychange`: 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_HASH` is empty or `"unknown"` (cargo run dev builds), so a developer iterating on the SPA does not get their tab reloaded out from under them.

`Performance` web-sys feature added for `performance.now()` timestamping.
YousifShkara deleted branch feat/auto-reload-on-new-spa-build 2026-06-09 04:51:10 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
psa-systems/mokosh-apps!94
No description provided.