Skip to content

Commit 4536297

Browse files
committed
fix(runtime): replace broken React UMD vendor + unblock JSX previews
The shipped `packages/runtime/vendor/{react,react-dom}.umd.js` were broken builds containing `if (n) let g = !0;` — invalid JS that V8 rejects with "Lexical declaration cannot appear in a single-statement context". Every JSX-era design therefore failed to execute inside the preview iframe: React never defined `window.ReactDOM`, Babel then raised `ReferenceError: ReactDOM is not defined`, and the hub thumbnails + main PreviewPane showed as blank / "brokenJsx". - Replace vendor with clean React 18.3.1 production UMDs from unpkg (react 10.7 KB, react-dom 131.8 KB). - Scope DesignCardPreview's `transform: scale` to a wrapper div so Chromium doesn't defer script scheduling when the iframe itself has a heavy transform + tiny post-transform visible area. - Add the missing i18n keys `preview.error.brokenJsx` / `preview.error.undefinedRef` (zh-CN + en) so CanvasErrorBar surfaces a readable message instead of the dev `⟦key⟧` fallback.
1 parent 4cc21df commit 4536297

5 files changed

Lines changed: 301 additions & 8681 deletions

File tree

apps/desktop/src/renderer/src/views/hub/DesignCardPreview.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,28 @@ export function DesignCardPreview({ design }: DesignCardPreviewProps) {
180180
return (
181181
<div ref={rootRef} className="absolute inset-0 overflow-hidden bg-white">
182182
{srcDoc ? (
183-
<iframe
184-
title={design.name}
185-
srcDoc={srcDoc}
186-
sandbox={isJsx ? 'allow-scripts' : ''}
187-
className="pointer-events-none border-0"
183+
// Scale wrapper → iframe strategy: Chromium may defer script execution
184+
// for iframes with a direct CSS `transform: scale(...)` when the
185+
// post-transform visible size is tiny (hub thumbnails post-scale look
186+
// like ~280x211). Putting transform on a PARENT and letting the iframe
187+
// keep its natural 1280x960 matches PreviewPane's layout and lets the
188+
// renderer treat the iframe as full-size for execution scheduling.
189+
<div
188190
style={{
189191
width: '1280px',
190192
height: '960px',
191193
transform: `scale(${scale})`,
192194
transformOrigin: 'top left',
193195
}}
194-
/>
196+
>
197+
<iframe
198+
title={design.name}
199+
srcDoc={srcDoc}
200+
sandbox={isJsx ? 'allow-scripts' : ''}
201+
className="pointer-events-none border-0"
202+
style={{ width: '1280px', height: '960px' }}
203+
/>
204+
</div>
195205
) : failed ? (
196206
<div className="absolute inset-0 flex flex-col items-center justify-center gap-[var(--space-2)] bg-[var(--color-background-secondary)] text-[var(--color-text-muted)]">
197207
<Plus className="w-5 h-5 opacity-40" strokeWidth={1.5} aria-hidden />

packages/i18n/src/locales/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
"commentMode": "Comment mode",
7171
"commentModeHint": "Click any element to comment",
7272
"runtimeError": "Preview runtime error",
73+
"error": {
74+
"brokenJsx": "This design has a syntax error, likely an incomplete early save. Regenerate or edit to fix.",
75+
"undefinedRef": "The design references an undefined variable or component. Likely a mid-run abort — try regenerating."
76+
},
7377
"dismissErrors": "Dismiss preview errors",
7478
"zoom": "Zoom"
7579
},

packages/i18n/src/locales/zh-CN.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
"commentMode": "评论模式",
7373
"commentModeHint": "点击任意元素留评",
7474
"runtimeError": "预览运行时错误",
75+
"error": {
76+
"brokenJsx": "此设计的代码有语法错误,可能是早期版本保存的不完整内容。重新生成或编辑修复即可。",
77+
"undefinedRef": "设计引用了未定义的变量或组件。可能是生成中途中断——尝试重新生成。"
78+
},
7579
"dismissErrors": "关闭预览错误",
7680
"zoom": "缩放"
7781
},

0 commit comments

Comments
 (0)