Skip to content

Fix dashboard sandbox compile errors and switch smart model to Grok#1476

Open
mantrakp04 wants to merge 2 commits into
devfrom
fix/dashboard-sandbox-errors-and-grok-model
Open

Fix dashboard sandbox compile errors and switch smart model to Grok#1476
mantrakp04 wants to merge 2 commits into
devfrom
fix/dashboard-sandbox-errors-and-grok-model

Conversation

@mantrakp04
Copy link
Copy Markdown
Collaborator

@mantrakp04 mantrakp04 commented May 22, 2026

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

Summary by CodeRabbit

  • Bug Fixes

    • Dashboard compilation failures now show a clear “Dashboard failed to compile” message instead of a blank iframe.
    • Runtime errors and unhandled promise rejections from embedded dashboards are now surfaced and reported to the parent for visibility.
  • Updates

    • The authenticated AI model used for the "smart" quality has been changed, affecting model selection for authenticated requests.

Review Change Stack

Copilot AI review requested due to automatic review settings May 22, 2026 23:25
@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment May 23, 2026 12:21am
stack-auth-mcp Ready Ready Preview, Comment May 23, 2026 12:21am
stack-auth-skills Ready Ready Preview, Comment May 23, 2026 12:21am
stack-backend Ready Ready Preview, Comment May 23, 2026 12:21am
stack-dashboard Ready Ready Preview, Comment May 23, 2026 12:21am
stack-demo Ready Ready Preview, Comment May 23, 2026 12:21am
stack-docs Ready Ready Preview, Comment May 23, 2026 12:21am
stack-preview-backend Ready Ready Preview, Comment May 23, 2026 12:21am
stack-preview-dashboard Ready Ready Preview, Comment May 23, 2026 12:21am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

Switch authenticated smart-quality backend model IDs to x-ai/grok-build-0.1 and refactor the dashboard iframe sandbox to load Babel with crossorigin, install an early error bridge, embed AI source in a text/plain script, compile with Babel.transform, and execute compiled code with scoped globals and a compile-failure UI.

Changes

AI Model and Sandbox Execution

Layer / File(s) Summary
Backend AI model selection
apps/backend/src/lib/ai/models.ts
MODEL_SELECTION_MATRIX.smart authenticated modelId entries changed from moonshotai/kimi-k2.6:nitro to x-ai/grok-build-0.1 for both slow and fast modes; unauthenticated entries unchanged.
Sandbox bootstrap and source embedding
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx
Sandbox HTML now loads Babel with crossorigin="anonymous", installs window.__postDashboardError to forward runtime/parse failures to the parent, and embeds the AI runtime source in a <script type="text/plain" id="ai-dashboard-source"> block.
Remove duplicate later handlers
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx
Deleted later in-body error/unhandledrejection listeners and left a comment since an early global listener already forwards these events.
Sandbox compile-then-execute flow
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx
Boot reads ai-dashboard-source, compiles via window.Babel.transform(..., { presets: ['react'] }) in a try/catch, posts compile errors to parent and renders a fallback UI on failure, and on success executes the compiled output with new Function(...) using explicit scoped globals to obtain and run the Dashboard export.

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers:

  • N2D4

"I hopped to swap a model, tidy the nest,
Babel arrives with crossorigin dressed,
Errors I send so they don't hide,
I compile, I run — dashboard's pride.
— 🐰"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the two main changes: fixing dashboard sandbox compile errors and switching the authenticated smart model to Grok.
Description check ✅ Passed The description provides a clear summary of changes, technical details, and a comprehensive test plan covering all major aspects of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dashboard-sandbox-errors-and-grok-model

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 22, 2026

Greptile Summary

This PR improves AI dashboard sandbox error visibility and switches the smart authenticated model to x-ai/grok-build-0.1. Previously, Babel parse errors and runtime throws in the iframe produced a blank preview; now they are caught and forwarded to the parent composer via postMessage.

  • Error pipeline: An early plain-<script> block installs window.error and unhandledrejection listeners before Babel loads. AI source is stored in a <script type=\"text/plain\"> block (with </script> escaping), compiled explicitly via Babel.transform inside a try/catch, and executed through new Function — ensuring compile failures surface as actionable messages instead of silent blank iframes.
  • Duplicate listener cleanup: The now-redundant error listeners inside the <script type=\"text/babel\"> block have been removed, eliminating the double-reporting path.
  • Model swap: moonshotai/kimi-k2.6:nitro replaced by x-ai/grok-build-0.1 for smart/authenticated (slow + fast); ALLOWED_MODEL_IDS updates automatically via the matrix enumeration.

Confidence Score: 4/5

Safe to merge; the sandbox changes are well-isolated to the iframe document string and handle the main error paths correctly.

The model switch is trivial and correct. The sandbox refactor is thoughtful — early listener, explicit compile, new Function execution, and duplicate-listener removal all work together. The one gap is that window.Babel is accessed without an existence guard, so a CDN load failure produces a generic message rather than pointing to Babel as the culprit.

apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx — the Babel.transform call site would benefit from a window.Babel existence check.

Important Files Changed

Filename Overview
apps/backend/src/lib/ai/models.ts Simple model ID swap for smart/authenticated tier from moonshotai/kimi-k2.6:nitro to x-ai/grok-build-0.1 in both slow and fast slots; the new model ID is automatically included in ALLOWED_MODEL_IDS via the matrix enumeration.
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx Three-part error-handling overhaul: early plain-script error listener installed before Babel loads, AI source stored in a text/plain block to avoid Babel auto-runner swallowing parse errors, and explicit Babel.transform + new Function execution with try/catch. Duplicate event listeners removed from the Babel block. One edge case: window.Babel is accessed without an existence guard, so a CDN load failure surfaces as a generic TypeError rather than a clear diagnostic.

Fix All in Claude Code Fix All in Cursor Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx:551-554
`window.Babel` is accessed without a guard: if the CDN script fails to load (network timeout, unpkg outage), `window.Babel` is `undefined` and `window.Babel.transform(...)` throws a `TypeError: Cannot read properties of undefined (reading 'transform')`. This propagates to the outer `.catch()` and surfaces as the generic "Failed to initialize dashboard" message — with no indication that Babel itself never loaded. A short existence check here would give users an actionable error.

```suggestion
        let compiledSource;
        try {
          if (!window.Babel || typeof window.Babel.transform !== 'function') {
            throw new Error('Babel failed to load — check your network connection and try again.');
          }
          compiledSource = window.Babel.transform(aiSource, { presets: ['react'] }).code;
        } catch (err) {
```

Reviews (2): Last reviewed commit: "Refactor error handling in dashboard san..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the AI dashboard sandbox preview experience by surfacing compilation/runtime failures from the sandboxed srcDoc iframe back to the dashboard composer, and updates the backend “smart” authenticated model routing to use Grok.

Changes:

  • Add iframe → parent error forwarding for compile/runtime errors, and compile AI-generated JSX explicitly via Babel.transform with a try/catch to surface parse errors.
  • Adjust Babel loading to improve cross-origin error readability (crossorigin="anonymous").
  • Switch authenticated smart-tier model selection from moonshotai/kimi-k2.6:nitro to x-ai/grok-build-0.1.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx Enhances sandbox iframe error reporting and changes how AI code is compiled/executed.
apps/backend/src/lib/ai/models.ts Updates smart-tier authenticated model ID selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@vercel vercel Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

Duplicate error event listeners cause duplicate error messages to be sent to parent component

Fix on Vercel

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx (1)

486-501: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Duplicate error/unhandledrejection listeners.

These event listeners are duplicates of the ones installed earlier at lines 362-369 in the IIFE block. Both register handlers for 'error' and 'unhandledrejection' that post the same 'dashboard-error-boundary' message to the parent. This causes each error to be reported twice.

Remove these duplicate listeners since the early IIFE (lines 350-371) already covers this case and runs before any AI code.

Proposed fix
-      // Forward uncaught runtime errors (async throws, unhandled rejections) that never
-      // reach the React boundary. React ErrorBoundary alone misses these, so without this
-      // the parent has no way to observe e.g. a fetch() that rejected inside useEffect.
-      window.addEventListener('error', (event) => {
-        const err = event?.error;
-        window.parent.postMessage({
-          type: 'dashboard-error-boundary',
-          message: err?.message || event?.message || 'Unknown runtime error',
-          stack: err?.stack,
-        }, '*');
-      });
-      window.addEventListener('unhandledrejection', (event) => {
-        const reason = event?.reason;
-        window.parent.postMessage({
-          type: 'dashboard-error-boundary',
-          message: (reason && (reason.message || String(reason))) || 'Unhandled promise rejection',
-          stack: reason?.stack,
-        }, '*');
-      });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx`
around lines 486 - 501, Remove the duplicate global error handlers that post
'dashboard-error-boundary' to the parent: delete the second pair of
window.addEventListener calls for 'error' and 'unhandledrejection' in
dashboard-sandbox-host.tsx (the handlers that extract event?.error /
event?.reason and call window.parent.postMessage with type
'dashboard-error-boundary'); rely on the existing IIFE-installed listeners (the
earlier IIFE block that already registers 'error' and 'unhandledrejection') so
each runtime error or promise rejection is reported only once.
🧹 Nitpick comments (1)
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx (1)

566-570: 💤 Low value

Add defensive check for missing source element.

If ai-dashboard-source element is somehow missing, aiSource becomes an empty string, which would then fail during execution with a confusing "Dashboard component not found" error rather than a clear message about the missing source.

Proposed improvement
         const aiSourceEl = document.getElementById('ai-dashboard-source');
-        const aiSource = aiSourceEl ? aiSourceEl.textContent : '';
+        if (!aiSourceEl) {
+          throw new Error('AI dashboard source element not found');
+        }
+        const aiSource = aiSourceEl.textContent || '';
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx`
around lines 566 - 570, The code assumes
document.getElementById('ai-dashboard-source') exists; add a defensive check
after retrieving aiSourceEl (and before calling window.Babel.transform) to
handle a missing element or empty source: if aiSourceEl is null or aiSource is
empty, throw or log a clear error like "Missing ai-dashboard-source element or
empty dashboard source" and bail early (so compiledSource isn't attempted);
update the block that references aiSourceEl, aiSource and compiledSource and
ensure any downstream logic that expects compiledSource handles this early-exit
path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx`:
- Around line 486-501: Remove the duplicate global error handlers that post
'dashboard-error-boundary' to the parent: delete the second pair of
window.addEventListener calls for 'error' and 'unhandledrejection' in
dashboard-sandbox-host.tsx (the handlers that extract event?.error /
event?.reason and call window.parent.postMessage with type
'dashboard-error-boundary'); rely on the existing IIFE-installed listeners (the
earlier IIFE block that already registers 'error' and 'unhandledrejection') so
each runtime error or promise rejection is reported only once.

---

Nitpick comments:
In
`@apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx`:
- Around line 566-570: The code assumes
document.getElementById('ai-dashboard-source') exists; add a defensive check
after retrieving aiSourceEl (and before calling window.Babel.transform) to
handle a missing element or empty source: if aiSourceEl is null or aiSource is
empty, throw or log a clear error like "Missing ai-dashboard-source element or
empty dashboard source" and bail early (so compiledSource isn't attempted);
update the block that references aiSourceEl, aiSource and compiledSource and
ensure any downstream logic that expects compiledSource handles this early-exit
path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a00205d3-1555-41e9-8755-7a696aa186dc

📥 Commits

Reviewing files that changed from the base of the PR and between 9355c86 and f2d62da.

📒 Files selected for processing (2)
  • apps/backend/src/lib/ai/models.ts
  • apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx

Forward Babel/JSX parse failures from the AI dashboard iframe to the parent composer instead of showing a blank preview, and use x-ai/grok-build-0.1 for authenticated smart-tier requests.
Updated the dashboard sandbox to replace script closing tags in the source code to prevent parsing issues. Removed redundant global error listeners, as uncaught runtime errors and unhandled rejections are now handled by an early listener installed before Babel loads.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx (1)

486-501: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Duplicate error listeners cause double error reporting.

These error and unhandledrejection listeners duplicate the ones installed earlier (lines 362-369). Both fire for the same event, so onRuntimeError is invoked twice per error. Remove this block since the early listener already covers runtime errors.

Proposed fix: remove duplicate listeners
-      // Forward uncaught runtime errors (async throws, unhandled rejections) that never
-      // reach the React boundary. React ErrorBoundary alone misses these, so without this
-      // the parent has no way to observe e.g. a fetch() that rejected inside useEffect.
-      window.addEventListener('error', (event) => {
-        const err = event?.error;
-        window.parent.postMessage({
-          type: 'dashboard-error-boundary',
-          message: err?.message || event?.message || 'Unknown runtime error',
-          stack: err?.stack,
-        }, '*');
-      });
-      window.addEventListener('unhandledrejection', (event) => {
-        const reason = event?.reason;
-        window.parent.postMessage({
-          type: 'dashboard-error-boundary',
-          message: (reason && (reason.message || String(reason))) || 'Unhandled promise rejection',
-          stack: reason?.stack,
-        }, '*');
-      });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx`
around lines 486 - 501, Remove the duplicate runtime error handlers: delete the
window.addEventListener('error', ...) and
window.addEventListener('unhandledrejection', ...) blocks that post messages
with type 'dashboard-error-boundary' (the block that constructs message/stack
and posts to window.parent). Those listeners duplicate the earlier installed
handlers (which call onRuntimeError), so removing this block will stop
double-reporting; ensure no other code depends on these specific registrations.
🧹 Nitpick comments (1)
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx (1)

566-570: ⚡ Quick win

Add defensive check for Babel.transform result.

window.Babel.transform(...) returns an object with a code property, but if Babel fails to load or the transform returns unexpectedly, accessing .code could throw. A defensive check aligns with the coding guidelines.

Proposed fix
         let compiledSource;
         try {
-          compiledSource = window.Babel.transform(aiSource, { presets: ['react'] }).code;
+          const transformResult = window.Babel.transform(aiSource, { presets: ['react'] });
+          if (!transformResult || typeof transformResult.code !== 'string') {
+            throw new Error('Babel transform returned invalid result');
+          }
+          compiledSource = transformResult.code;
         } catch (err) {

Based on coding guidelines: "Use defensive coding with ?? throwErr(...) over non-null assertions and fallback values".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx`
around lines 566 - 570, The code directly accesses
window.Babel.transform(...).code which can throw if Babel is missing or
transform returns unexpectedly; change the block to first capture the transform
result (e.g., const transformResult = window.Babel.transform(aiSource, {
presets: ['react'] })) and then set compiledSource = transformResult.code ??
throwErr('Babel transform returned no code') (or throw a descriptive error) so
you defensively handle a missing transform result; update references to
compiledSource and the window.Babel.transform call in dashboard-sandbox-host.tsx
accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx`:
- Around line 486-501: Remove the duplicate runtime error handlers: delete the
window.addEventListener('error', ...) and
window.addEventListener('unhandledrejection', ...) blocks that post messages
with type 'dashboard-error-boundary' (the block that constructs message/stack
and posts to window.parent). Those listeners duplicate the earlier installed
handlers (which call onRuntimeError), so removing this block will stop
double-reporting; ensure no other code depends on these specific registrations.

---

Nitpick comments:
In
`@apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx`:
- Around line 566-570: The code directly accesses
window.Babel.transform(...).code which can throw if Babel is missing or
transform returns unexpectedly; change the block to first capture the transform
result (e.g., const transformResult = window.Babel.transform(aiSource, {
presets: ['react'] })) and then set compiledSource = transformResult.code ??
throwErr('Babel transform returned no code') (or throw a descriptive error) so
you defensively handle a missing transform result; update references to
compiledSource and the window.Babel.transform call in dashboard-sandbox-host.tsx
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 75da2d4b-f29a-40b2-abfc-9567320469ad

📥 Commits

Reviewing files that changed from the base of the PR and between f2d62da and 8685ca0.

📒 Files selected for processing (2)
  • apps/backend/src/lib/ai/models.ts
  • apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx
✅ Files skipped from review due to trivial changes (1)
  • apps/backend/src/lib/ai/models.ts

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx (1)

380-380: 💤 Low value

Redundant escaping — escapeScriptContent already handles this.

The escapeScriptContent function called at line 190 already replaces </script<\/script. After that transformation, the regex /<\/script>/gi here will never match, making this .replace() a no-op.

You can simplify to just ${sourceCode}:

🔧 Suggested fix
     <script type="text/plain" id="ai-dashboard-source">
-${sourceCode.replace(/<\/script>/gi, '<\\/script>')}
+${sourceCode}
     </script>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx`
at line 380, The replace call on sourceCode is redundant because
escapeScriptContent already escapes "</script"; update the template to use the
raw interpolant `${sourceCode}` instead of `${sourceCode.replace(/<\/script>/gi,
'<\\/script>')}` (locate the usage inside the dashboard sandbox host template
where escapeScriptContent was applied and the template literal contains that
replace) so you remove the no-op regex and simplify the interpolation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx`:
- Line 380: The replace call on sourceCode is redundant because
escapeScriptContent already escapes "</script"; update the template to use the
raw interpolant `${sourceCode}` instead of `${sourceCode.replace(/<\/script>/gi,
'<\\/script>')}` (locate the usage inside the dashboard sandbox host template
where escapeScriptContent was applied and the template literal contains that
replace) so you remove the no-op regex and simplify the interpolation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c211f48d-c8f0-4947-ba5b-cc33fdc4ae68

📥 Commits

Reviewing files that changed from the base of the PR and between 8685ca0 and b5b70a1.

📒 Files selected for processing (1)
  • apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx

<script type="text/babel"> handler does NOT run it — that handler
swallows parse errors. The plumbing script below compiles this with a
try/catch and forwards any SyntaxError to the parent composer. -->
<script type="text/plain" id="ai-dashboard-source">
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escaped script content in text/plain tags includes literal backslashes when read via textContent, breaking Babel compilation

Fix on Vercel

const aiSource = aiSourceEl ? aiSourceEl.textContent : '';
let compiledSource;
try {
compiledSource = window.Babel.transform(aiSource, { presets: ['react'] }).code;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
compiledSource = window.Babel.transform(aiSource, { presets: ['react'] }).code;
compiledSource = window.Babel.transform(aiSource, { presets: ['react'], sourceType: 'script' }).code;

Babel.transform() may output ESM import/export statements that fail execution in new Function() due to missing sourceType: 'script' option

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants