From a8b08f3a45d99324a29b6521b4a97c23c0e85439 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 1 Apr 2026 08:21:15 -0700 Subject: [PATCH] fix: prevent Vue-nav reload loop when running without Caddy proxy sync_ui_cookie() was calling window.parent.location.reload() on every render when user.yaml has ui_preference=vue, but no Caddy is in the traffic path (test instances, bare Docker). This caused an infinite reload loop because the reload just came back to Streamlit. Gate the reload on PEREGRINE_CADDY_PROXY=1. Without it, the cookie is still written silently but no reload is attempted. Add the env var to compose.yml and compose.cloud.yml (both are behind Caddy); omit from compose.test-cfcore.yml so test instances stay stable. --- app/components/ui_switcher.py | 15 +++++++++++++-- compose.cloud.yml | 1 + compose.test-cfcore.yml | 5 +---- compose.yml | 1 + 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/components/ui_switcher.py b/app/components/ui_switcher.py index 2fb4a02..8526e6b 100644 --- a/app/components/ui_switcher.py +++ b/app/components/ui_switcher.py @@ -32,6 +32,13 @@ _DEMO_MODE = os.environ.get("DEMO_MODE", "").lower() in ("1", "true", "yes") # Example: PEREGRINE_VUE_URL=http://localhost:8506 _VUE_URL = os.environ.get("PEREGRINE_VUE_URL", "").strip().rstrip("/") +# When True, a window.location.reload() after setting prgn_ui=vue will be +# intercepted by Caddy and routed to the Vue SPA. When False (no Caddy in the +# traffic path — e.g. test instances, direct Docker exposure), reloading just +# comes back to Streamlit and creates an infinite loop. Only set this in +# production/staging compose files where Caddy is actually in front. +_CADDY_PROXY = os.environ.get("PEREGRINE_CADDY_PROXY", "").lower() in ("1", "true", "yes") + _COOKIE_JS = """