@@ -30,19 +30,48 @@ cd "$REPO_ROOT"
3030echo " ==> Building production assets"
3131npm run build
3232
33+ # spatie/laravel-responsecache caches full HTML responses independently of
34+ # the Vite dev/prod check below — a page cached while dev mode was active
35+ # (or vice versa) keeps serving that stale snapshot forever, immune to the
36+ # worker warm-up loop further down. Always start from a clean slate.
37+ echo " ==> Clearing response cache"
38+ php artisan responsecache:clear
39+
40+ HOT_STASH=" ${TMPDIR:-/ tmp} /web-codebar-hot.$$ "
3341HOT_MOVED=0
3442if [ -f public/hot ]; then
35- mv public/hot public/hot.disabled-for-lighthouse
43+ mv public/hot " $HOT_STASH "
3644 HOT_MOVED=1
3745fi
3846
3947restore_hot () {
40- if [ " $HOT_MOVED " = " 1" ] && [ -f public/hot.disabled-for-lighthouse ]; then
41- mv public/hot.disabled-for-lighthouse public/hot
48+ if [ " $HOT_MOVED " = " 1" ] && [ -f " $HOT_STASH " ]; then
49+ mv " $HOT_STASH " public/hot
4250 fi
4351}
4452trap restore_hot EXIT
4553
54+ # Herd's PHP-FPM workers each cache file_exists(public/hot) independently, so a
55+ # worker that served requests before the mv above may keep reporting dev mode
56+ # for a while after. Hammer the homepage until every worker in the pool has
57+ # picked up the change before trusting any Lighthouse run against this build.
58+ echo " ==> Waiting for all PHP-FPM workers to see the production build"
59+ stale=1
60+ for _ in $( seq 1 40) ; do
61+ stale=0
62+ for _ in $( seq 1 8) ; do
63+ if curl -sk " $BASE_URL /en-ch" | grep -q ' vite/client' ; then
64+ stale=1
65+ break
66+ fi
67+ done
68+ [ " $stale " = " 0" ] && break
69+ sleep 0.5
70+ done
71+ if [ " $stale " = " 1" ]; then
72+ echo " !! Still seeing dev-mode markup after retries — results may be unreliable. Consider 'herd restart'."
73+ fi
74+
4675# Filter pages.json down to requested names (all, if none given)
4776if [ " $# " -gt 0 ]; then
4877 FILTER_JSON=$( printf ' %s\n' " $@ " | jq -R . | jq -s .)
@@ -58,6 +87,10 @@ echo "$PAGES" | jq -c '.[]' | while read -r page; do
5887 name=$( echo " $page " | jq -r ' .name' )
5988 path=$( echo " $page " | jq -r ' .path' )
6089 echo " >>> $name -> $path "
90+ # Same stale-worker guard, scoped to this page's own URL.
91+ for _ in $( seq 1 8) ; do
92+ curl -sk " ${BASE_URL}${path} " | grep -q ' vite/client' || break
93+ done
6194 npx --yes lighthouse " ${BASE_URL}${path} " \
6295 --output=json --output-path=" $OUT_DIR /${name} .json" \
6396 --chrome-flags=" --headless=new --ignore-certificate-errors" \
0 commit comments