From ae1443e01d1399150e101df1123295bf30b86f0a Mon Sep 17 00:00:00 2001 From: Dave Berzack Date: Wed, 2 Sep 2026 10:33:53 -0400 Subject: [PATCH] bustin makes me feel good --- .github/workflows/deploy.yml | 4 ++++ src/main.jsx | 4 ++++ src/version-check.js | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 src/version-check.js diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5309b3f..48fd4cb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -48,6 +48,10 @@ jobs: echo "VITE_GLOBAL_PROGRESS_BAR=false" >> .env echo "VITE_REQUIRES_GITHUB_AUTHENTICATION=false" >> .env echo "BASE_URL=${{ secrets.WORKSHOP_BASE_URL }}" >> .env + echo "VITE_BUILD_ID=${{ github.sha }}" >> .env + + - name: Write version file + run: echo '{"build":"${{ github.sha }}"}' > public/version.json - name: Install dependencies run: npm ci diff --git a/src/main.jsx b/src/main.jsx index a25a03f..ec852be 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -2,6 +2,10 @@ import React from 'react' import ReactDOM from 'react-dom/client' import App from './App' import './index.css' +import { checkVersion } from './version-check' + +//this runs a browser reload if we have an older version; make sure it never breaks things +try { checkVersion() } catch { /* ignore */ } // Create root and render ReactDOM.createRoot(document.getElementById('root')).render( diff --git a/src/version-check.js b/src/version-check.js new file mode 100644 index 0000000..cbf635d --- /dev/null +++ b/src/version-check.js @@ -0,0 +1,19 @@ + +//this busts Github Pages 10 minute cache scheme +//if browser is running stale code, versions won't match and we reload once. +const BUILD = import.meta.env.VITE_BUILD_ID; +const RELOAD_KEY = 'version-check:reloaded-for'; + +export function checkVersion() { + if (!BUILD) return; // local build, nothing to compare against + + fetch(`${import.meta.env.BASE_URL}version.json?_=${Date.now()}`, { cache: 'no-store' }) + .then((r) => r.json()) + .then(({ build }) => { + if (!build || build === BUILD) return; + if (sessionStorage.getItem(RELOAD_KEY) === build) return; // already reloaded for this one + sessionStorage.setItem(RELOAD_KEY, build); + location.reload(); + }) + .catch(() => {}); +}