Compare commits

...
2 Commits
Author SHA1 Message Date
lukaszraczylo 527c1759f9 fix(frontend): revalidate index.html on every load
nginx sent index.html without Cache-Control, so browsers cached it heuristically. After a deploy, a browser kept loading the previous hashed bundle until the cache expired, and fixes did not appear. The SPA location now sends Cache-Control: no-cache. Hashed assets stay immutable. scripts/check_frontend_html_cache.sh checks both.
2026-11-23 16:36:10 +00:00
lukaszraczylo 933b5a75c0 fix(ui): read nested stats from stats_update events
The server sends stats_update as {stats, timestamp}, but the realtime store read the counters from the top level of the payload. About 30 seconds after load, the first broadcast replaced the polled stats with undefined values, and the dashboard tiles showed 0. The store now unwraps the nested stats object.
2026-11-23 16:30:22 +00:00
4 changed files with 69 additions and 1 deletions
+2
View File
@@ -147,6 +147,8 @@ server {
# Frontend SPA - serve index.html for all other routes
location / {
# index.html names the hashed bundles; a cached copy keeps serving the previous release.
add_header Cache-Control "no-cache" always;
try_files $uri $uri/ /index.html;
}
}
+16
View File
@@ -53,6 +53,22 @@ describe('useRealtimeStore', () => {
expect(store.lastStats).toMatchObject({ total_packages: 42, total_size: 1024 })
})
it('unwraps the server stats_update shape {stats, timestamp}', () => {
const store = useRealtimeStore()
store.ingest(
makeEvent('stats_update', {
stats: { total_packages: 1454, total_size: 980870617, total_downloads: 5376, scanned_packages: 1451 },
timestamp: '2026-11-23T16:00:00Z',
}),
)
expect(store.lastStats).toMatchObject({
total_packages: 1454,
total_size: 980870617,
total_downloads: 5376,
scanned_packages: 1451,
})
})
it('exposes filtered computed slices', () => {
const store = useRealtimeStore()
store.ingest(makeEvent('package_cached'))
+3 -1
View File
@@ -55,7 +55,9 @@ export const useRealtimeStore = defineStore('realtime', () => {
events.value.splice(0, events.value.length - EVENTS_CAP)
}
if (event.type === 'stats_update') {
lastStats.value = event.payload as RealtimeStats
// The server nests the counters under `stats`; reading the payload flat shows zeros.
const nested = event.payload.stats
lastStats.value = (nested && typeof nested === 'object' ? nested : event.payload) as RealtimeStats
}
}
+48
View File
@@ -0,0 +1,48 @@
#!/bin/sh
# Builds the frontend image from a Dockerfile and checks that the SPA HTML is revalidated on every
# load while hashed assets stay immutable. A cached index.html keeps old bundles after a deploy.
# Usage: scripts/check_frontend_html_cache.sh [Dockerfile]
set -eu
dockerfile="${1:-Dockerfile.frontend}"
root="$(git rev-parse --show-toplevel)"
work="$(mktemp -d)"
tag="gohoarder-frontend-cache-check:$$"
front="gohoarder-cache-check-$$"
cleanup() {
docker rm -f "$front" >/dev/null 2>&1 || true
docker rmi "$tag" >/dev/null 2>&1 || true
rm -rf "$work"
}
trap cleanup EXIT
mkdir -p "$work/frontend/dist/assets"
echo '<html></html>' >"$work/frontend/dist/index.html"
echo 'console.log(1)' >"$work/frontend/dist/assets/index-abc123.js"
cp "$root/$dockerfile" "$work/Dockerfile"
docker build -q --load -t "$tag" "$work" >/dev/null
docker run -d --name "$front" -e BACKEND_HOST=127.0.0.1 -e BACKEND_PORT=8080 "$tag" >/dev/null
headers() {
for _ in 1 2 3 4 5 6 7 8 9 10; do
out="$(docker exec "$front" wget -S -qO /dev/null "http://127.0.0.1$1" 2>&1 || true)"
case "$out" in *"HTTP/"*) printf '%s' "$out" | grep -i 'cache-control' || true; return ;; esac
sleep 1
done
}
status=0
for path in / /index.html /packages /package/go/example.com/mod/v1.0.0; do
cc="$(headers "$path")"
case "$cc" in
*no-cache*) echo "ok: $path is revalidated" ;;
*) echo "FAIL: $path Cache-Control [$cc], want no-cache"; status=1 ;;
esac
done
cc="$(headers /assets/index-abc123.js)"
case "$cc" in
*immutable*) echo "ok: hashed asset is immutable" ;;
*) echo "FAIL: asset Cache-Control [$cc], want immutable"; status=1 ;;
esac
exit "$status"