From daa0b9728bfb676609cfa220d4746d1eab2b4d03 Mon Sep 17 00:00:00 2001 From: DeepReef11 <17586546+DeepReef11@users.noreply.github.com> Date: Mon, 13 Apr 2026 11:46:28 -0400 Subject: [PATCH] fix: prevent stale SPA shell after container rebuild (#7344) Co-authored-by: Docker User Co-authored-by: Claude Opus 4.6 (1M context) Co-authored-by: Michael Genson Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> --- mealie/routes/spa/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mealie/routes/spa/__init__.py b/mealie/routes/spa/__init__.py index c6fa832e5..16ff82993 100644 --- a/mealie/routes/spa/__init__.py +++ b/mealie/routes/spa/__init__.py @@ -33,14 +33,22 @@ class MetaTag: class SPAStaticFiles(StaticFiles): async def get_response(self, path: str, scope): try: - return await super().get_response(path, scope) + response = await super().get_response(path, scope) except HTTPException as ex: if ex.status_code == 404: - return await super().get_response("index.html", scope) + response = await super().get_response("index.html", scope) else: raise ex - except Exception as e: - raise e + + # Hashed assets (_nuxt/*) are safe to cache forever since new builds produce new filenames. + # HTML must revalidate so browsers always fetch the correct bundle references after a + # container rebuild (prevents blank white page from stale index.html in HA iframes, etc). + if path.startswith("_nuxt/"): + response.headers["Cache-Control"] = "public, max-age=31536000, immutable" + elif path == "." or response.media_type == "text/html": + response.headers["Cache-Control"] = "no-cache" + + return response __app_settings = get_app_settings()