fix(web): navigate (not in-place) when switching from HTTPS to HTTP hub — mixed content blocks in-place calls

This commit is contained in:
2026-08-02 23:59:30 +08:00
parent c87a783b88
commit 35133dff8c
+13 -4
View File
@@ -68,10 +68,19 @@ function ConnectionSwitch() {
<button
type="button"
onClick={() => {
// Switch the hub connection in place — the app
// reconnects to the target origin without a full
// page navigation (same hub, so the token stays
// valid).
// Browsers block in-place requests from an HTTPS
// page to an HTTP hub (mixed content), so an
// HTTPS→HTTP switch must navigate instead. The
// loaded page is then HTTP same-origin and works.
const pageIsHttps = typeof window !== 'undefined'
&& window.location.protocol === 'https:'
const targetIsHttps = target.startsWith('https://')
if (pageIsHttps && !targetIsHttps) {
window.location.href = target
return
}
// Otherwise switch the hub connection in place —
// the app reconnects without a full navigation.
setServerUrl(target)
}}
className="shrink-0 rounded-md border border-[var(--app-border)] bg-[var(--app-subtle-bg)] px-2 py-1.5 text-xs text-[var(--app-fg)] hover:bg-[var(--app-secondary-bg)]"