Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 19 additions & 0 deletions src/version-check.js
Original file line number Diff line number Diff line change
@@ -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(() => {});
}
Loading