fix: thread builder offline runtime race + getDoc method name
Two bugs: - subscribeOffline() bailed if runtime wasn't initialized yet (race with shell.ts init). Now waits for runtime to appear, then awaits init(). - getDoc() called runtime.getDoc() which doesn't exist — method is runtime.get(). Caused "e.getDoc is not a function" crash in listThreads. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3f19fd9c8e
commit
1335c38d48
|
|
@ -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[] {
|
||||
|
|
|
|||
Loading…
Reference in New Issue