@mui/internal-docs-infra 0.12.1-canary.11 → 0.12.1-canary.12

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": "@mui/internal-docs-infra",
3
- "version": "0.12.1-canary.11",
3
+ "version": "0.12.1-canary.12",
4
4
  "author": "MUI Team",
5
5
  "description": "MUI Infra - internal documentation creation tools.",
6
6
  "license": "MIT",
@@ -804,5 +804,5 @@
804
804
  "bin": {
805
805
  "docs-infra": "./cli/index.mjs"
806
806
  },
807
- "gitSha": "bdd286eb27de9a0b2494f66b1b5b4712b28e2b1b"
807
+ "gitSha": "cd265618d793d94a8126db916013526ce860e836"
808
808
  }
@@ -49,7 +49,9 @@ async function transpileModule(module, nested, transpile, signal) {
49
49
  compiledFiles.set(module.file, {
50
50
  kind: 'moduleError',
51
51
  nested,
52
- error: error instanceof Error ? error.message : String(error)
52
+ // `toString()` (not `.message`) keeps the error name (e.g. `SyntaxError:`) in the
53
+ // surfaced message — the transpile paths reject with a live, named error.
54
+ error: error instanceof Error ? error.toString() : String(error)
53
55
  });
54
56
  }
55
57
  }
@@ -77,7 +77,7 @@ export function createTranspileWorkerClient(onFatal) {
77
77
  if (data.ok) {
78
78
  entry.resolve(data.code);
79
79
  } else {
80
- entry.reject(new Error(data.error));
80
+ entry.reject(data.error);
81
81
  }
82
82
  });
83
83
  worker.addEventListener('error', event => {
@@ -35,7 +35,7 @@ workerScope.addEventListener('message', event => {
35
35
  type: 'transpile',
36
36
  id: data.id,
37
37
  ok: false,
38
- error: error instanceof Error ? error.message : String(error)
38
+ error
39
39
  });
40
40
  }
41
41
  });
@@ -64,7 +64,7 @@ export function useDemoController(options = {}) {
64
64
  }
65
65
  return `mui-docs-infra:demo-controller:${window.location.pathname}\u0000${url ?? ''}`;
66
66
  }, [crossTabSync, url]);
67
- const [code, setCode] = useCrossTabState(syncChannel, undefined);
67
+ const [code, setControlledCode] = useCrossTabState(syncChannel, undefined);
68
68
  // Build errors (transpile/CSS failures) and render errors (the entry throwing) live
69
69
  // in SEPARATE maps so they never clobber each other: a build error is owned by
70
70
  // `useVariantBuilds` (set on failure, cleared on the next good build); a render
@@ -95,6 +95,21 @@ export function useDemoController(options = {}) {
95
95
  });
96
96
  }, []);
97
97
 
98
+ // Reset (the toolbar button clears `code` to `undefined`) must also drop any stale
99
+ // build/render error, so a prior syntax error's overlay doesn't linger over the
100
+ // restored original — nothing rebuilds after a reset to clear it otherwise. Do it in
101
+ // the setter that performs the reset rather than reacting to the `code` change in an
102
+ // effect; the length guards keep each clear a no-op once its map is empty.
103
+ const setCode = React.useCallback(action => {
104
+ setControlledCode(action);
105
+ // A reset passes the cleared value directly (never a functional update), so a
106
+ // falsy argument is the reset — drop stale errors alongside it.
107
+ if (typeof action !== 'function' && !action) {
108
+ setBuildErrors(previous => Object.keys(previous).length > 0 ? {} : previous);
109
+ setRenderErrors(previous => Object.keys(previous).length > 0 ? {} : previous);
110
+ }
111
+ }, [setControlledCode]);
112
+
98
113
  // Resolve the page-shared transpile (worker, or main-thread fallback) into state once
99
114
  // there's code to build — a local first edit, or a cross-tab edit that arrives without
100
115
  // this tab engaging its own editor. `onActivate` below has usually already spun the
@@ -168,12 +183,15 @@ export function useDemoController(options = {}) {
168
183
  // Merge the two channels: a build failure takes precedence (the preview is stale
169
184
  // until it builds), otherwise the render error, else `null`.
170
185
  const errors = React.useMemo(() => {
186
+ if (!code) {
187
+ return {};
188
+ }
171
189
  const merged = {};
172
190
  for (const variant of new Set([...Object.keys(buildErrors), ...Object.keys(renderErrors)])) {
173
191
  merged[variant] = buildErrors[variant] || renderErrors[variant] || null;
174
192
  }
175
193
  return merged;
176
- }, [buildErrors, renderErrors]);
194
+ }, [code, buildErrors, renderErrors]);
177
195
  return {
178
196
  code,
179
197
  setCode,