fix(designer): remove StrictMode so amis-editor mounts (was blank screen)

页面设计器(editor.html)整片空白:amis-editor 用 mobx-state-tree 维护 EditorRoot
store,而 src/editor/main.tsx 用 <React.StrictMode> 包裹——dev 下 StrictMode 故意
mount→unmount→remount,销毁第一个 EditorRoot,其 pending 异步(markReady/
calculateHighlightBox)随后打到已死实例 → 抛「[mobx-state-tree] object no longer
part of a state tree」→ 编辑器不渲染。

移除编辑器入口的 StrictMode(主应用 main.tsx 跑 amis SDK 运行时渲染器、容忍
StrictMode,不动)。实测:三栏(组件库/画布/属性面板)+画布真渲业务页全部恢复,
mobx-state-tree 报错消失(剩 Monaco worker/React 弃用警告均良性、不阻塞)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-19 22:05:16 +08:00
parent 4b564c6316
commit 2278cbce4b

View File

@@ -1,14 +1,15 @@
// F4-L1 设计器独立入口(editor.html 多页应用) // F4-L1 设计器独立入口(editor.html 多页应用)
// 与主应用 React 实例完全隔离,amis 用 npm 包版,不依赖 sdk-local // 与主应用 React 实例完全隔离,amis 用 npm 包版,不依赖 sdk-local
import React from 'react'; //
// ⚠️ 不能包 <React.StrictMode>:amis-editor 用 mobx-state-tree 维护 EditorRoot store,
// StrictMode 在 dev 下故意 mount→unmount→remount,会销毁第一个 EditorRoot,而其 pending
// 异步(markReady / calculateHighlightBox)随后打到已死实例 → 抛
// 「[mobx-state-tree] object no longer part of a state tree」→ 编辑器整片空白。
// 主应用 main.tsx 跑 amis SDK(运行时渲染器,容忍 StrictMode),唯独 amis-editor 不行。
import { createRoot } from 'react-dom/client'; import { createRoot } from 'react-dom/client';
import { DesignerPage } from './DesignerPage'; import { DesignerPage } from './DesignerPage';
const root = document.getElementById('editor-root'); const root = document.getElementById('editor-root');
if (root) { if (root) {
createRoot(root).render( createRoot(root).render(<DesignerPage />);
<React.StrictMode>
<DesignerPage />
</React.StrictMode>,
);
} }