fix: collab overlay stuck on 'Connecting' in demo/standalone pages

The offline runtime is not created for demo space (spaceSlug==="demo"),
so the collab overlay polled forever waiting for it. Now gives up after
~10s and transitions to connected state for standalone display.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-03-31 09:55:23 -07:00
parent 81d8102f69
commit 3be0fb6eed
1 changed files with 9 additions and 12 deletions

View File

@ -180,7 +180,7 @@ export class RStackCollabOverlay extends HTMLElement {
if (runtime?.isInitialized) {
this.#onRuntimeReady(runtime);
} else {
// Poll until runtime is ready (no timeout — WS connect can take 30s+)
// Poll until runtime is ready, give up after ~10s (demo/standalone pages have no runtime)
let polls = 0;
this.#runtimePollInterval = setInterval(() => {
const rt = (window as any).__rspaceOfflineRuntime;
@ -188,19 +188,16 @@ export class RStackCollabOverlay extends HTMLElement {
clearInterval(this.#runtimePollInterval!);
this.#runtimePollInterval = null;
this.#onRuntimeReady(rt);
return;
}
// Slow down after 15s (30 polls × 500ms) to reduce overhead
polls++;
if (polls === 30 && this.#runtimePollInterval) {
clearInterval(this.#runtimePollInterval);
this.#runtimePollInterval = setInterval(() => {
const rt2 = (window as any).__rspaceOfflineRuntime;
if (rt2?.isInitialized) {
clearInterval(this.#runtimePollInterval!);
this.#runtimePollInterval = null;
this.#onRuntimeReady(rt2);
}
}, 2000);
if (polls >= 20) {
// No runtime after ~10s — standalone/demo mode
clearInterval(this.#runtimePollInterval!);
this.#runtimePollInterval = null;
this.#connState = 'connected';
this.#renderBadge();
if (this.#panelOpen) this.#renderPanel();
}
}, 500);
}