@cfp-studio/plugin-react 17.3.3 → 17.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfp-studio/plugin-react",
3
- "version": "17.3.3",
3
+ "version": "17.3.4",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -16,10 +16,10 @@
16
16
  "esbuild-plugin-polyfill-node": "0.3.0",
17
17
  "typescript": "5.9.3",
18
18
  "@cfp-studio/serializable-values": "9.0.8",
19
- "@cfp-studio/analyzer-api": "0.1.14",
20
- "@cfp-studio/type-analyzer": "10.1.8",
21
19
  "@cfp-studio/storybook-helpers": "6.0.2",
22
- "@cfp-studio/vfs": "2.1.8"
20
+ "@cfp-studio/vfs": "2.1.8",
21
+ "@cfp-studio/analyzer-api": "0.1.15",
22
+ "@cfp-studio/type-analyzer": "10.1.8"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@playwright/test": "1.64.1",
@@ -33,9 +33,9 @@
33
33
  "react-dom": "18.3.1",
34
34
  "vite": "6.4.5",
35
35
  "vitest": "5.0.5",
36
- "@cfp-studio/iframe": "18.4.4",
37
- "@cfp-studio/testing": "14.0.1",
38
- "@cfp-studio/core": "1.0.9"
36
+ "@cfp-studio/core": "1.0.10",
37
+ "@cfp-studio/iframe": "18.4.5",
38
+ "@cfp-studio/testing": "14.0.1"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=20"
@@ -37,6 +37,9 @@ export async function expectErrorBoundary(renderId: number, shouldAbortRender: (
37
37
  *
38
38
  * 面板只占**渲染区域内部的这块地方**;外层 UI(工具栏、Runtime Tree 等)不受影响。
39
39
  *
40
+ * 面板挂在 `document.body` 的独立覆盖层上(**不在 `#root` 里**),生命周期也不跟随本
41
+ * 组件的挂载/卸载 —— 原因见 `mountPanel` 与 `componentWillUnmount`。
42
+ *
40
43
  * ## 仍然会向上抛
41
44
  *
42
45
  * `index.tsx` 的 `render()` 会读 `state.error` 并 `throw`,让 `runNewRender` 的 catch
@@ -64,33 +67,36 @@ export class ErrorBoundary extends Component<ErrorBoundaryProps> {
64
67
  componentDidCatch(error: Error, errorInfo: { componentStack?: string | null }) {
65
68
  // `componentStack` 是定位「哪个组件抛的错」最直接的线索(React 16.6+ 提供)。
66
69
  this.setState({ componentStack: errorInfo?.componentStack ?? null });
67
- this.mountPanel();
70
+ this.mountPanel(error, errorInfo?.componentStack ?? null);
68
71
  }
69
72
 
70
73
  componentWillUnmount() {
71
- this.cleanupPanel?.();
72
- this.cleanupPanel = null;
74
+ // **故意不清面板**:面板现在挂在 `document.body` 的覆盖层上,生命周期与 React 无关。
75
+ //
76
+ // 之前在这里 `cleanupPanel()`,实测症状是「错误页面闪现一下就没了」:
77
+ // HMR / 重新渲染会卸载这个 Boundary,顺手把刚画出来的面板抹掉。
78
+ //
79
+ // 清面板的责任归于两处:下游重新渲染成功时由 `index.tsx` 调 `clearErrorPanel()`;
80
+ // 整个 iframe 重载时页面本来就从空白开始。
73
81
  }
74
82
 
75
83
  /**
76
- * 把错误面板画进 `#root`。
84
+ * 把错误面板画成预览页的覆盖层(见 `analyzer-api` 的 `renderErrorPanel`)。
77
85
  *
78
- * 为什么是声明式 render 之外的地方:面板要显示的是**渲染失败**这件事本身,
79
- * 而失败的子树已经被 React 卸载了。这里直接操作 DOM,位置固定在预览容器里,
80
- * 与 `renderErrorPanel` 的实现(纯 DOM)一致。
86
+ * 不再写进 `#root`:那个容器归 ReactDOM 管,React 一重渲染就会清掉非托管的子节点。
81
87
  */
82
- private mountPanel() {
83
- const container = typeof document === "undefined" ? null : document.getElementById("root");
84
- if (!container) {
88
+ private mountPanel(error: unknown, componentStack: string | null) {
89
+ if (typeof document === "undefined") {
85
90
  return;
86
91
  }
87
92
  const options: RenderErrorPanelOptions = {
88
- error: this.state.error,
93
+ error,
89
94
  previewableName: this.props.previewableName,
90
- componentStack: this.state.componentStack,
95
+ componentStack,
91
96
  };
97
+ // 先清旧的(防止连续抛错时叠层),再画新的。
92
98
  this.cleanupPanel?.();
93
- this.cleanupPanel = renderErrorPanel(container, options);
99
+ this.cleanupPanel = renderErrorPanel(document.body, options);
94
100
  }
95
101
 
96
102
  render() {