From 09d23f8fc18322d682202fe78c21ef4f97e70db7 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Fri, 27 Feb 2026 16:12:55 -0800 Subject: [PATCH] fix: rApp shapes auto-derive space context and load as applets directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - folk-rapp now auto-derives spaceSlug from the current URL path (/{space}/canvas → space) so embedded rApps always know their space - Fixed race condition where createRenderRoot overwrote moduleId that was already set via JS property setter (showed picker instead of loading the module directly) - newShapeElement always passes communitySlug as fallback spaceSlug when restoring folk-rapp shapes from sync Co-Authored-By: Claude Opus 4.6 --- lib/folk-rapp.ts | 17 ++++++++++++++--- website/canvas.html | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/folk-rapp.ts b/lib/folk-rapp.ts index 3fd51c1..2b3a4b4 100644 --- a/lib/folk-rapp.ts +++ b/lib/folk-rapp.ts @@ -340,8 +340,15 @@ export class FolkRApp extends FolkShape { override createRenderRoot() { const root = super.createRenderRoot(); - this.#moduleId = this.getAttribute("module-id") || ""; - this.#spaceSlug = this.getAttribute("space-slug") || ""; + // Prefer JS-set properties (from newShape props); fall back to HTML attributes + if (!this.#moduleId) this.#moduleId = this.getAttribute("module-id") || ""; + if (!this.#spaceSlug) this.#spaceSlug = this.getAttribute("space-slug") || ""; + + // Auto-derive spaceSlug from current URL if not explicitly provided (/{space}/canvas → space) + if (!this.#spaceSlug) { + const pathParts = window.location.pathname.split("/").filter(Boolean); + if (pathParts.length >= 1) this.#spaceSlug = pathParts[0]; + } const meta = MODULE_META[this.#moduleId]; const headerColor = meta?.color || "#475569"; @@ -530,7 +537,11 @@ export class FolkRApp extends FolkShape { `; - // Create iframe + // Auto-derive space from URL if still missing + if (!this.#spaceSlug) { + const pathParts = window.location.pathname.split("/").filter(Boolean); + if (pathParts.length >= 1) this.#spaceSlug = pathParts[0]; + } const space = this.#spaceSlug || "demo"; const iframeUrl = `/${space}/${this.#moduleId}`; diff --git a/website/canvas.html b/website/canvas.html index d9e02f8..1e5c4ce 100644 --- a/website/canvas.html +++ b/website/canvas.html @@ -1395,7 +1395,7 @@ case "folk-rapp": shape = document.createElement("folk-rapp"); if (data.moduleId) shape.moduleId = data.moduleId; - if (data.spaceSlug) shape.spaceSlug = data.spaceSlug; + shape.spaceSlug = data.spaceSlug || communitySlug; break; case "folk-feed": shape = document.createElement("folk-feed");