diff --git a/modules/rsocials/components/folk-thread-builder.ts b/modules/rsocials/components/folk-thread-builder.ts index f7cf162..89df386 100644 --- a/modules/rsocials/components/folk-thread-builder.ts +++ b/modules/rsocials/components/folk-thread-builder.ts @@ -90,8 +90,22 @@ export class FolkThreadBuilder extends HTMLElement { } private async subscribeOffline() { - const runtime = (window as any).__rspaceOfflineRuntime; - if (!runtime?.isInitialized) return; + // Wait for the runtime to be available and initialized + let runtime = (window as any).__rspaceOfflineRuntime; + + // The runtime may not be created yet if shell.ts hasn't run init() + if (!runtime) { + // Wait briefly for shell.ts to create it + await new Promise(r => setTimeout(r, 200)); + runtime = (window as any).__rspaceOfflineRuntime; + } + if (!runtime) return; + + // Wait for init() to complete if still in progress + if (!runtime.isInitialized && runtime.init) { + try { await runtime.init(); } catch { /* init may have been called already */ } + } + if (!runtime.isInitialized) return; try { const docId = socialsDocId(this._space) as DocumentId; @@ -108,8 +122,8 @@ export class FolkThreadBuilder extends HTMLElement { this._thread = updated.threads[this._threadId]; } }); - } catch { - // Working without offline runtime + } catch (e: any) { + console.warn('[thread-builder] Offline subscribe failed:', e.message); } } @@ -160,7 +174,7 @@ export class FolkThreadBuilder extends HTMLElement { const runtime = this.getRuntime(); if (!runtime?.isInitialized) return undefined; const docId = socialsDocId(this._space) as DocumentId; - return runtime.getDoc(docId); + return runtime.get(docId); } private listThreads(): ThreadData[] {