From 10df9b2b7bf7077b45ced4fe57bb5e6dac4fe10a Mon Sep 17 00:00:00 2001 From: Mantra <87142457+mantrakp04@users.noreply.github.com> Date: Sat, 23 May 2026 12:34:37 -0700 Subject: [PATCH] Fix dashboard sandbox compile errors and switch smart model to Grok (#1476) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Forward Babel/JSX compile errors, runtime throws, and unhandled rejections from the AI dashboard sandbox iframe to the parent composer via `postMessage`, so users see actionable errors instead of a blank preview - Compile AI-generated dashboard source explicitly with `Babel.transform` + try/catch (stored in `text/plain` to avoid Babel's auto-handler swallowing parse errors) and add `crossorigin="anonymous"` on the Babel script for readable cross-origin error messages - Switch authenticated smart-tier model from `moonshotai/kimi-k2.6:nitro` to `x-ai/grok-build-0.1` ## Test plan - [ ] Generate a dashboard with valid AI code and confirm the preview still renders - [ ] Generate a dashboard with invalid JSX and confirm the composer shows the compile error (not a blank iframe) - [ ] Trigger a runtime error in generated dashboard code and confirm it reaches the parent error boundary - [ ] Verify authenticated smart-tier requests route to `x-ai/grok-build-0.1` Made with [Cursor](https://cursor.com) ## Summary by CodeRabbit * **Bug Fixes** * Embedded dashboards now show a clear “Dashboard failed to compile” message on compilation errors instead of a blank iframe. * Dashboard runtime errors and unhandled promise rejections are captured earlier and forwarded to the parent for improved visibility. * **Updates** * The authenticated AI model used for the "smart" quality has been changed, affecting model selection for authenticated requests. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/hexclave/stack-auth/pull/1476?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) --- apps/backend/src/lib/ai/models.ts | 4 +- .../dashboard-sandbox-host.tsx | 153 ++++++++++++------ 2 files changed, 104 insertions(+), 53 deletions(-) diff --git a/apps/backend/src/lib/ai/models.ts b/apps/backend/src/lib/ai/models.ts index 34e8df13a..d73391a50 100644 --- a/apps/backend/src/lib/ai/models.ts +++ b/apps/backend/src/lib/ai/models.ts @@ -28,11 +28,11 @@ const MODEL_SELECTION_MATRIX: Record< }, smart: { slow: { - authenticated: { modelId: "moonshotai/kimi-k2.6:nitro" }, + authenticated: { modelId: "x-ai/grok-build-0.1" }, unauthenticated: { modelId: "deepseek/deepseek-v4-flash" }, }, fast: { - authenticated: { modelId: "moonshotai/kimi-k2.6:nitro" }, + authenticated: { modelId: "x-ai/grok-build-0.1" }, unauthenticated: { modelId: "deepseek/deepseek-v4-flash:nitro" }, }, }, diff --git a/apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx b/apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx index ff3a4dc3e..9b5bf0e0c 100644 --- a/apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx +++ b/apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx @@ -179,15 +179,12 @@ function getDependencyScripts(esmVersion: string, esmFallbackVersion: string, da `; } -function escapeScriptContent(code: string): string { - return code - .replace(/<\/script/gi, "<\\/script") - .replace(//g, "--\\>"); +function encodeSourceForJsonScript(code: string): string { + return JSON.stringify(code).replace(/
- - - + + + + + + ${getDependencyScripts(esmVersion, esmFallbackVersion, dashboardUrl)} - + + +