@wordpress/edit-widgets 6.54.2-next.v.202608281122.0 → 6.55.1-next.v.202609031004.0

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/CHANGELOG.md CHANGED
@@ -2,10 +2,15 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- ## 6.54.1-next.0 (2026-08-28)
5
+ ## 6.55.0-next.0 (2026-09-03)
6
+
7
+ ### Enhancements
8
+
9
+ - Error boundary: Surface debugging details ([#{TODO}](https://github.com/WordPress/gutenberg/pull/{TODO})).
6
10
 
7
11
  ### Bug Fixes
8
12
 
13
+ - `WelcomeGuide`: Keep the modal close icon white on hover now that it is stroke-based. ([#78812](https://github.com/WordPress/gutenberg/pull/78812))
9
14
  - Prevent an error in `canInsertBlockInWidgetArea` when no widget area blocks are present.
10
15
 
11
16
  ### Internal
@@ -24,45 +24,138 @@ __export(error_boundary_exports, {
24
24
  module.exports = __toCommonJS(error_boundary_exports);
25
25
  var import_element = require("@wordpress/element");
26
26
  var import_i18n = require("@wordpress/i18n");
27
- var import_components = require("@wordpress/components");
28
- var import_block_editor = require("@wordpress/block-editor");
27
+ var import_ui = require("@wordpress/ui");
29
28
  var import_compose = require("@wordpress/compose");
30
29
  var import_hooks = require("@wordpress/hooks");
31
30
  var import_jsx_runtime = require("react/jsx-runtime");
32
- function CopyButton({ text, children }) {
33
- const ref = (0, import_compose.useCopyToClipboard)(text);
34
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, { __next40pxDefaultSize: true, variant: "secondary", ref, children });
31
+ function getErrorName(error) {
32
+ return error instanceof Error && error.name || "Error";
33
+ }
34
+ function getErrorMessage(error) {
35
+ if (typeof error === "string" && error) {
36
+ return error;
37
+ }
38
+ if (typeof error?.message === "string" && error.message) {
39
+ return error.message;
40
+ }
41
+ return "An unknown error occurred.";
35
42
  }
36
- function ErrorBoundaryWarning({ message, error }) {
37
- const actions = [
38
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CopyButton, { text: error.stack, children: (0, import_i18n.__)("Copy Error") }, "copy-error")
43
+ function getErrorSections(error, componentStack) {
44
+ const sections = [
45
+ { label: getErrorName(error), content: getErrorMessage(error) }
39
46
  ];
40
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.Warning, { className: "edit-widgets-error-boundary", actions, children: message });
47
+ if (error?.stack) {
48
+ sections.push({
49
+ label: "Stack",
50
+ content: error.stack.trim(),
51
+ preformatted: true
52
+ });
53
+ }
54
+ if (componentStack) {
55
+ sections.push({
56
+ label: "Component stack",
57
+ content: componentStack.trim(),
58
+ preformatted: true
59
+ });
60
+ }
61
+ sections.push({
62
+ label: "Environment",
63
+ content: `User agent: ${window.navigator.userAgent}`,
64
+ preformatted: true
65
+ });
66
+ return sections;
67
+ }
68
+ function getErrorReport(error, componentStack) {
69
+ const sections = getErrorSections(error, componentStack).map(
70
+ ({ label, content, preformatted }) => `**${label}**
71
+
72
+ ${preformatted ? `\`\`\`
73
+ ${content}
74
+ \`\`\`` : content}`
75
+ );
76
+ return ["### Error report", ...sections].join("\n\n");
77
+ }
78
+ function CopyButton({ text, children, variant = "outline" }) {
79
+ const ref = (0, import_compose.useCopyToClipboard)(text);
80
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Notice.ActionButton, { variant, ref, children });
81
+ }
82
+ function ErrorReport({ error, componentStack }) {
83
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
84
+ import_ui.Stack,
85
+ {
86
+ className: "edit-widgets-error-boundary__report",
87
+ direction: "column",
88
+ gap: "md",
89
+ children: getErrorSections(error, componentStack).map(
90
+ ({ label, content }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Stack, { direction: "column", gap: "xs", children: [
91
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Text, { variant: "heading-md", children: label }),
92
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "edit-widgets-error-boundary__report-section", children: content })
93
+ ] }, label)
94
+ )
95
+ }
96
+ );
97
+ }
98
+ function ErrorDetails({ error, componentStack }) {
99
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.CollapsibleCard.Root, { className: "edit-widgets-error-boundary__details", children: [
100
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.CollapsibleCard.Header, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Card.Title, { children: (0, import_i18n.__)("Error details") }) }),
101
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.CollapsibleCard.Content, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
102
+ ErrorReport,
103
+ {
104
+ error,
105
+ componentStack
106
+ }
107
+ ) })
108
+ ] });
41
109
  }
42
110
  var ErrorBoundary = class extends import_element.Component {
43
111
  constructor() {
44
112
  super(...arguments);
45
113
  this.state = {
46
- error: null
114
+ error: null,
115
+ componentStack: null
47
116
  };
48
117
  }
49
- componentDidCatch(error) {
50
- (0, import_hooks.doAction)("editor.ErrorBoundary.errorLogged", error);
118
+ componentDidCatch(error, errorInfo) {
119
+ this.setState({ componentStack: errorInfo?.componentStack });
120
+ (0, import_hooks.doAction)("editor.ErrorBoundary.errorLogged", error, errorInfo);
51
121
  }
52
122
  static getDerivedStateFromError(error) {
53
123
  return { error };
54
124
  }
55
125
  render() {
56
- if (!this.state.error) {
126
+ const { error, componentStack } = this.state;
127
+ if (!error) {
57
128
  return this.props.children;
58
129
  }
59
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
60
- ErrorBoundaryWarning,
130
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
131
+ import_ui.Stack,
61
132
  {
62
- message: (0, import_i18n.__)(
63
- "The editor has encountered an unexpected error."
64
- ),
65
- error: this.state.error
133
+ className: "edit-widgets-error-boundary",
134
+ direction: "column",
135
+ gap: "lg",
136
+ children: [
137
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Notice.Root, { intent: "error", children: [
138
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Notice.Title, { children: (0, import_i18n.__)("The editor has crashed") }),
139
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Notice.Description, { children: (0, import_i18n.__)(
140
+ "An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search."
141
+ ) }),
142
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.Notice.Actions, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
143
+ CopyButton,
144
+ {
145
+ variant: "solid",
146
+ text: () => getErrorReport(error, componentStack),
147
+ children: (0, import_i18n.__)("Copy error")
148
+ }
149
+ ) })
150
+ ] }),
151
+ globalThis.SCRIPT_DEBUG ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
152
+ ErrorDetails,
153
+ {
154
+ error,
155
+ componentStack
156
+ }
157
+ ) : null
158
+ ]
66
159
  }
67
160
  );
68
161
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/error-boundary/index.jsx"],
4
- "sourcesContent": ["import { Component } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { Warning } from '@wordpress/block-editor';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { doAction } from '@wordpress/hooks';\n\nfunction CopyButton( { text, children } ) {\n\tconst ref = useCopyToClipboard( text );\n\treturn (\n\t\t<Button __next40pxDefaultSize variant=\"secondary\" ref={ ref }>\n\t\t\t{ children }\n\t\t</Button>\n\t);\n}\n\nfunction ErrorBoundaryWarning( { message, error } ) {\n\tconst actions = [\n\t\t<CopyButton key=\"copy-error\" text={ error.stack }>\n\t\t\t{ __( 'Copy Error' ) }\n\t\t</CopyButton>,\n\t];\n\n\treturn (\n\t\t<Warning className=\"edit-widgets-error-boundary\" actions={ actions }>\n\t\t\t{ message }\n\t\t</Warning>\n\t);\n}\n\nexport default class ErrorBoundary extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.state = {\n\t\t\terror: null,\n\t\t};\n\t}\n\n\tcomponentDidCatch( error ) {\n\t\tdoAction( 'editor.ErrorBoundary.errorLogged', error );\n\t}\n\n\tstatic getDerivedStateFromError( error ) {\n\t\treturn { error };\n\t}\n\n\trender() {\n\t\tif ( ! this.state.error ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\treturn (\n\t\t\t<ErrorBoundaryWarning\n\t\t\t\tmessage={ __(\n\t\t\t\t\t'The editor has encountered an unexpected error.'\n\t\t\t\t) }\n\t\t\t\terror={ this.state.error }\n\t\t\t/>\n\t\t);\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA0B;AAC1B,kBAAmB;AACnB,wBAAuB;AACvB,0BAAwB;AACxB,qBAAmC;AACnC,mBAAyB;AAKvB;AAHF,SAAS,WAAY,EAAE,MAAM,SAAS,GAAI;AACzC,QAAM,UAAM,mCAAoB,IAAK;AACrC,SACC,4CAAC,4BAAO,uBAAqB,MAAC,SAAQ,aAAY,KAC/C,UACH;AAEF;AAEA,SAAS,qBAAsB,EAAE,SAAS,MAAM,GAAI;AACnD,QAAM,UAAU;AAAA,IACf,4CAAC,cAA4B,MAAO,MAAM,OACvC,8BAAI,YAAa,KADJ,YAEhB;AAAA,EACD;AAEA,SACC,4CAAC,+BAAQ,WAAU,+BAA8B,SAC9C,mBACH;AAEF;AAEA,IAAqB,gBAArB,cAA2C,yBAAU;AAAA,EACpD,cAAc;AACb,UAAO,GAAG,SAAU;AAEpB,SAAK,QAAQ;AAAA,MACZ,OAAO;AAAA,IACR;AAAA,EACD;AAAA,EAEA,kBAAmB,OAAQ;AAC1B,+BAAU,oCAAoC,KAAM;AAAA,EACrD;AAAA,EAEA,OAAO,yBAA0B,OAAQ;AACxC,WAAO,EAAE,MAAM;AAAA,EAChB;AAAA,EAEA,SAAS;AACR,QAAK,CAAE,KAAK,MAAM,OAAQ;AACzB,aAAO,KAAK,MAAM;AAAA,IACnB;AAEA,WACC;AAAA,MAAC;AAAA;AAAA,QACA,aAAU;AAAA,UACT;AAAA,QACD;AAAA,QACA,OAAQ,KAAK,MAAM;AAAA;AAAA,IACpB;AAAA,EAEF;AACD;",
4
+ "sourcesContent": ["import { Component } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n// eslint-disable-next-line @wordpress/use-recommended-components -- The fallback UI renders outside the editor's notice system.\nimport { Card, CollapsibleCard, Notice, Stack, Text } from '@wordpress/ui';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { doAction } from '@wordpress/hooks';\n\n// A boundary catches whatever was thrown, which is not always an `Error`.\nfunction getErrorName( error ) {\n\treturn ( error instanceof Error && error.name ) || 'Error';\n}\n\nfunction getErrorMessage( error ) {\n\tif ( typeof error === 'string' && error ) {\n\t\treturn error;\n\t}\n\n\tif ( typeof error?.message === 'string' && error.message ) {\n\t\treturn error.message;\n\t}\n\n\treturn 'An unknown error occurred.';\n}\n\n// The sections of the report, shared by the copied Markdown and the details\n// panel so that the two cannot drift apart. Deliberately untranslated: both\n// are developer-facing, and the report is pasted into a bug report.\nfunction getErrorSections( error, componentStack ) {\n\tconst sections = [\n\t\t{ label: getErrorName( error ), content: getErrorMessage( error ) },\n\t];\n\n\tif ( error?.stack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Stack',\n\t\t\tcontent: error.stack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tif ( componentStack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Component stack',\n\t\t\tcontent: componentStack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tsections.push( {\n\t\tlabel: 'Environment',\n\t\tcontent: `User agent: ${ window.navigator.userAgent }`,\n\t\tpreformatted: true,\n\t} );\n\n\treturn sections;\n}\n\n// Markdown, so the report stays readable as plain text and renders when pasted\n// into a bug report.\nfunction getErrorReport( error, componentStack ) {\n\tconst sections = getErrorSections( error, componentStack ).map(\n\t\t( { label, content, preformatted } ) =>\n\t\t\t`**${ label }**\\n\\n${\n\t\t\t\tpreformatted ? `\\`\\`\\`\\n${ content }\\n\\`\\`\\`` : content\n\t\t\t}`\n\t);\n\n\treturn [ '### Error report', ...sections ].join( '\\n\\n' );\n}\n\nfunction CopyButton( { text, children, variant = 'outline' } ) {\n\tconst ref = useCopyToClipboard( text );\n\treturn (\n\t\t<Notice.ActionButton variant={ variant } ref={ ref }>\n\t\t\t{ children }\n\t\t</Notice.ActionButton>\n\t);\n}\n\nfunction ErrorReport( { error, componentStack } ) {\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"edit-widgets-error-boundary__report\"\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"md\"\n\t\t>\n\t\t\t{ getErrorSections( error, componentStack ).map(\n\t\t\t\t( { label, content } ) => (\n\t\t\t\t\t<Stack key={ label } direction=\"column\" gap=\"xs\">\n\t\t\t\t\t\t<Text variant=\"heading-md\">{ label }</Text>\n\t\t\t\t\t\t<pre className=\"edit-widgets-error-boundary__report-section\">\n\t\t\t\t\t\t\t{ content }\n\t\t\t\t\t\t</pre>\n\t\t\t\t\t</Stack>\n\t\t\t\t)\n\t\t\t) }\n\t\t</Stack>\n\t);\n}\n\nfunction ErrorDetails( { error, componentStack } ) {\n\treturn (\n\t\t<CollapsibleCard.Root className=\"edit-widgets-error-boundary__details\">\n\t\t\t<CollapsibleCard.Header>\n\t\t\t\t<Card.Title>{ __( 'Error details' ) }</Card.Title>\n\t\t\t</CollapsibleCard.Header>\n\t\t\t<CollapsibleCard.Content>\n\t\t\t\t<ErrorReport\n\t\t\t\t\terror={ error }\n\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t/>\n\t\t\t</CollapsibleCard.Content>\n\t\t</CollapsibleCard.Root>\n\t);\n}\n\nexport default class ErrorBoundary extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.state = {\n\t\t\terror: null,\n\t\t\tcomponentStack: null,\n\t\t};\n\t}\n\n\tcomponentDidCatch( error, errorInfo ) {\n\t\tthis.setState( { componentStack: errorInfo?.componentStack } );\n\t\tdoAction( 'editor.ErrorBoundary.errorLogged', error, errorInfo );\n\t}\n\n\tstatic getDerivedStateFromError( error ) {\n\t\treturn { error };\n\t}\n\n\trender() {\n\t\tconst { error, componentStack } = this.state;\n\t\tif ( ! error ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\treturn (\n\t\t\t<Stack\n\t\t\t\tclassName=\"edit-widgets-error-boundary\"\n\t\t\t\tdirection=\"column\"\n\t\t\t\tgap=\"lg\"\n\t\t\t>\n\t\t\t\t<Notice.Root intent=\"error\">\n\t\t\t\t\t<Notice.Title>\n\t\t\t\t\t\t{ __( 'The editor has crashed' ) }\n\t\t\t\t\t</Notice.Title>\n\t\t\t\t\t<Notice.Description>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Notice.Description>\n\t\t\t\t\t<Notice.Actions>\n\t\t\t\t\t\t<CopyButton\n\t\t\t\t\t\t\tvariant=\"solid\"\n\t\t\t\t\t\t\ttext={ () =>\n\t\t\t\t\t\t\t\tgetErrorReport( error, componentStack )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Copy error' ) }\n\t\t\t\t\t\t</CopyButton>\n\t\t\t\t\t</Notice.Actions>\n\t\t\t\t</Notice.Root>\n\t\t\t\t{ globalThis.SCRIPT_DEBUG ? (\n\t\t\t\t\t<ErrorDetails\n\t\t\t\t\t\terror={ error }\n\t\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t\t/>\n\t\t\t\t) : null }\n\t\t\t</Stack>\n\t\t);\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAA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,MAAM;AAAA,IACnB;AAEA,WACC;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,WAAU;AAAA,QACV,KAAI;AAAA,QAEJ;AAAA,uDAAC,iBAAO,MAAP,EAAY,QAAO,SACnB;AAAA,wDAAC,iBAAO,OAAP,EACE,8BAAI,wBAAyB,GAChC;AAAA,YACA,4CAAC,iBAAO,aAAP,EACE;AAAA,cACD;AAAA,YACD,GACD;AAAA,YACA,4CAAC,iBAAO,SAAP,EACA;AAAA,cAAC;AAAA;AAAA,gBACA,SAAQ;AAAA,gBACR,MAAO,MACN,eAAgB,OAAO,cAAe;AAAA,gBAGrC,8BAAI,YAAa;AAAA;AAAA,YACpB,GACD;AAAA,aACD;AAAA,UACE,WAAW,eACZ;AAAA,YAAC;AAAA;AAAA,cACA;AAAA,cACA;AAAA;AAAA,UACD,IACG;AAAA;AAAA;AAAA,IACL;AAAA,EAEF;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,45 +1,138 @@
1
1
  // packages/edit-widgets/src/components/error-boundary/index.jsx
2
2
  import { Component } from "@wordpress/element";
3
3
  import { __ } from "@wordpress/i18n";
4
- import { Button } from "@wordpress/components";
5
- import { Warning } from "@wordpress/block-editor";
4
+ import { Card, CollapsibleCard, Notice, Stack, Text } from "@wordpress/ui";
6
5
  import { useCopyToClipboard } from "@wordpress/compose";
7
6
  import { doAction } from "@wordpress/hooks";
8
- import { jsx } from "react/jsx-runtime";
9
- function CopyButton({ text, children }) {
10
- const ref = useCopyToClipboard(text);
11
- return /* @__PURE__ */ jsx(Button, { __next40pxDefaultSize: true, variant: "secondary", ref, children });
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ function getErrorName(error) {
9
+ return error instanceof Error && error.name || "Error";
10
+ }
11
+ function getErrorMessage(error) {
12
+ if (typeof error === "string" && error) {
13
+ return error;
14
+ }
15
+ if (typeof error?.message === "string" && error.message) {
16
+ return error.message;
17
+ }
18
+ return "An unknown error occurred.";
12
19
  }
13
- function ErrorBoundaryWarning({ message, error }) {
14
- const actions = [
15
- /* @__PURE__ */ jsx(CopyButton, { text: error.stack, children: __("Copy Error") }, "copy-error")
20
+ function getErrorSections(error, componentStack) {
21
+ const sections = [
22
+ { label: getErrorName(error), content: getErrorMessage(error) }
16
23
  ];
17
- return /* @__PURE__ */ jsx(Warning, { className: "edit-widgets-error-boundary", actions, children: message });
24
+ if (error?.stack) {
25
+ sections.push({
26
+ label: "Stack",
27
+ content: error.stack.trim(),
28
+ preformatted: true
29
+ });
30
+ }
31
+ if (componentStack) {
32
+ sections.push({
33
+ label: "Component stack",
34
+ content: componentStack.trim(),
35
+ preformatted: true
36
+ });
37
+ }
38
+ sections.push({
39
+ label: "Environment",
40
+ content: `User agent: ${window.navigator.userAgent}`,
41
+ preformatted: true
42
+ });
43
+ return sections;
44
+ }
45
+ function getErrorReport(error, componentStack) {
46
+ const sections = getErrorSections(error, componentStack).map(
47
+ ({ label, content, preformatted }) => `**${label}**
48
+
49
+ ${preformatted ? `\`\`\`
50
+ ${content}
51
+ \`\`\`` : content}`
52
+ );
53
+ return ["### Error report", ...sections].join("\n\n");
54
+ }
55
+ function CopyButton({ text, children, variant = "outline" }) {
56
+ const ref = useCopyToClipboard(text);
57
+ return /* @__PURE__ */ jsx(Notice.ActionButton, { variant, ref, children });
58
+ }
59
+ function ErrorReport({ error, componentStack }) {
60
+ return /* @__PURE__ */ jsx(
61
+ Stack,
62
+ {
63
+ className: "edit-widgets-error-boundary__report",
64
+ direction: "column",
65
+ gap: "md",
66
+ children: getErrorSections(error, componentStack).map(
67
+ ({ label, content }) => /* @__PURE__ */ jsxs(Stack, { direction: "column", gap: "xs", children: [
68
+ /* @__PURE__ */ jsx(Text, { variant: "heading-md", children: label }),
69
+ /* @__PURE__ */ jsx("pre", { className: "edit-widgets-error-boundary__report-section", children: content })
70
+ ] }, label)
71
+ )
72
+ }
73
+ );
74
+ }
75
+ function ErrorDetails({ error, componentStack }) {
76
+ return /* @__PURE__ */ jsxs(CollapsibleCard.Root, { className: "edit-widgets-error-boundary__details", children: [
77
+ /* @__PURE__ */ jsx(CollapsibleCard.Header, { children: /* @__PURE__ */ jsx(Card.Title, { children: __("Error details") }) }),
78
+ /* @__PURE__ */ jsx(CollapsibleCard.Content, { children: /* @__PURE__ */ jsx(
79
+ ErrorReport,
80
+ {
81
+ error,
82
+ componentStack
83
+ }
84
+ ) })
85
+ ] });
18
86
  }
19
87
  var ErrorBoundary = class extends Component {
20
88
  constructor() {
21
89
  super(...arguments);
22
90
  this.state = {
23
- error: null
91
+ error: null,
92
+ componentStack: null
24
93
  };
25
94
  }
26
- componentDidCatch(error) {
27
- doAction("editor.ErrorBoundary.errorLogged", error);
95
+ componentDidCatch(error, errorInfo) {
96
+ this.setState({ componentStack: errorInfo?.componentStack });
97
+ doAction("editor.ErrorBoundary.errorLogged", error, errorInfo);
28
98
  }
29
99
  static getDerivedStateFromError(error) {
30
100
  return { error };
31
101
  }
32
102
  render() {
33
- if (!this.state.error) {
103
+ const { error, componentStack } = this.state;
104
+ if (!error) {
34
105
  return this.props.children;
35
106
  }
36
- return /* @__PURE__ */ jsx(
37
- ErrorBoundaryWarning,
107
+ return /* @__PURE__ */ jsxs(
108
+ Stack,
38
109
  {
39
- message: __(
40
- "The editor has encountered an unexpected error."
41
- ),
42
- error: this.state.error
110
+ className: "edit-widgets-error-boundary",
111
+ direction: "column",
112
+ gap: "lg",
113
+ children: [
114
+ /* @__PURE__ */ jsxs(Notice.Root, { intent: "error", children: [
115
+ /* @__PURE__ */ jsx(Notice.Title, { children: __("The editor has crashed") }),
116
+ /* @__PURE__ */ jsx(Notice.Description, { children: __(
117
+ "An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search."
118
+ ) }),
119
+ /* @__PURE__ */ jsx(Notice.Actions, { children: /* @__PURE__ */ jsx(
120
+ CopyButton,
121
+ {
122
+ variant: "solid",
123
+ text: () => getErrorReport(error, componentStack),
124
+ children: __("Copy error")
125
+ }
126
+ ) })
127
+ ] }),
128
+ globalThis.SCRIPT_DEBUG ? /* @__PURE__ */ jsx(
129
+ ErrorDetails,
130
+ {
131
+ error,
132
+ componentStack
133
+ }
134
+ ) : null
135
+ ]
43
136
  }
44
137
  );
45
138
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/error-boundary/index.jsx"],
4
- "sourcesContent": ["import { Component } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { Warning } from '@wordpress/block-editor';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { doAction } from '@wordpress/hooks';\n\nfunction CopyButton( { text, children } ) {\n\tconst ref = useCopyToClipboard( text );\n\treturn (\n\t\t<Button __next40pxDefaultSize variant=\"secondary\" ref={ ref }>\n\t\t\t{ children }\n\t\t</Button>\n\t);\n}\n\nfunction ErrorBoundaryWarning( { message, error } ) {\n\tconst actions = [\n\t\t<CopyButton key=\"copy-error\" text={ error.stack }>\n\t\t\t{ __( 'Copy Error' ) }\n\t\t</CopyButton>,\n\t];\n\n\treturn (\n\t\t<Warning className=\"edit-widgets-error-boundary\" actions={ actions }>\n\t\t\t{ message }\n\t\t</Warning>\n\t);\n}\n\nexport default class ErrorBoundary extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.state = {\n\t\t\terror: null,\n\t\t};\n\t}\n\n\tcomponentDidCatch( error ) {\n\t\tdoAction( 'editor.ErrorBoundary.errorLogged', error );\n\t}\n\n\tstatic getDerivedStateFromError( error ) {\n\t\treturn { error };\n\t}\n\n\trender() {\n\t\tif ( ! this.state.error ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\treturn (\n\t\t\t<ErrorBoundaryWarning\n\t\t\t\tmessage={ __(\n\t\t\t\t\t'The editor has encountered an unexpected error.'\n\t\t\t\t) }\n\t\t\t\terror={ this.state.error }\n\t\t\t/>\n\t\t);\n\t}\n}\n"],
5
- "mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AACnB,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,0BAA0B;AACnC,SAAS,gBAAgB;AAKvB;AAHF,SAAS,WAAY,EAAE,MAAM,SAAS,GAAI;AACzC,QAAM,MAAM,mBAAoB,IAAK;AACrC,SACC,oBAAC,UAAO,uBAAqB,MAAC,SAAQ,aAAY,KAC/C,UACH;AAEF;AAEA,SAAS,qBAAsB,EAAE,SAAS,MAAM,GAAI;AACnD,QAAM,UAAU;AAAA,IACf,oBAAC,cAA4B,MAAO,MAAM,OACvC,aAAI,YAAa,KADJ,YAEhB;AAAA,EACD;AAEA,SACC,oBAAC,WAAQ,WAAU,+BAA8B,SAC9C,mBACH;AAEF;AAEA,IAAqB,gBAArB,cAA2C,UAAU;AAAA,EACpD,cAAc;AACb,UAAO,GAAG,SAAU;AAEpB,SAAK,QAAQ;AAAA,MACZ,OAAO;AAAA,IACR;AAAA,EACD;AAAA,EAEA,kBAAmB,OAAQ;AAC1B,aAAU,oCAAoC,KAAM;AAAA,EACrD;AAAA,EAEA,OAAO,yBAA0B,OAAQ;AACxC,WAAO,EAAE,MAAM;AAAA,EAChB;AAAA,EAEA,SAAS;AACR,QAAK,CAAE,KAAK,MAAM,OAAQ;AACzB,aAAO,KAAK,MAAM;AAAA,IACnB;AAEA,WACC;AAAA,MAAC;AAAA;AAAA,QACA,SAAU;AAAA,UACT;AAAA,QACD;AAAA,QACA,OAAQ,KAAK,MAAM;AAAA;AAAA,IACpB;AAAA,EAEF;AACD;",
4
+ "sourcesContent": ["import { Component } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n// eslint-disable-next-line @wordpress/use-recommended-components -- The fallback UI renders outside the editor's notice system.\nimport { Card, CollapsibleCard, Notice, Stack, Text } from '@wordpress/ui';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { doAction } from '@wordpress/hooks';\n\n// A boundary catches whatever was thrown, which is not always an `Error`.\nfunction getErrorName( error ) {\n\treturn ( error instanceof Error && error.name ) || 'Error';\n}\n\nfunction getErrorMessage( error ) {\n\tif ( typeof error === 'string' && error ) {\n\t\treturn error;\n\t}\n\n\tif ( typeof error?.message === 'string' && error.message ) {\n\t\treturn error.message;\n\t}\n\n\treturn 'An unknown error occurred.';\n}\n\n// The sections of the report, shared by the copied Markdown and the details\n// panel so that the two cannot drift apart. Deliberately untranslated: both\n// are developer-facing, and the report is pasted into a bug report.\nfunction getErrorSections( error, componentStack ) {\n\tconst sections = [\n\t\t{ label: getErrorName( error ), content: getErrorMessage( error ) },\n\t];\n\n\tif ( error?.stack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Stack',\n\t\t\tcontent: error.stack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tif ( componentStack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Component stack',\n\t\t\tcontent: componentStack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tsections.push( {\n\t\tlabel: 'Environment',\n\t\tcontent: `User agent: ${ window.navigator.userAgent }`,\n\t\tpreformatted: true,\n\t} );\n\n\treturn sections;\n}\n\n// Markdown, so the report stays readable as plain text and renders when pasted\n// into a bug report.\nfunction getErrorReport( error, componentStack ) {\n\tconst sections = getErrorSections( error, componentStack ).map(\n\t\t( { label, content, preformatted } ) =>\n\t\t\t`**${ label }**\\n\\n${\n\t\t\t\tpreformatted ? `\\`\\`\\`\\n${ content }\\n\\`\\`\\`` : content\n\t\t\t}`\n\t);\n\n\treturn [ '### Error report', ...sections ].join( '\\n\\n' );\n}\n\nfunction CopyButton( { text, children, variant = 'outline' } ) {\n\tconst ref = useCopyToClipboard( text );\n\treturn (\n\t\t<Notice.ActionButton variant={ variant } ref={ ref }>\n\t\t\t{ children }\n\t\t</Notice.ActionButton>\n\t);\n}\n\nfunction ErrorReport( { error, componentStack } ) {\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"edit-widgets-error-boundary__report\"\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"md\"\n\t\t>\n\t\t\t{ getErrorSections( error, componentStack ).map(\n\t\t\t\t( { label, content } ) => (\n\t\t\t\t\t<Stack key={ label } direction=\"column\" gap=\"xs\">\n\t\t\t\t\t\t<Text variant=\"heading-md\">{ label }</Text>\n\t\t\t\t\t\t<pre className=\"edit-widgets-error-boundary__report-section\">\n\t\t\t\t\t\t\t{ content }\n\t\t\t\t\t\t</pre>\n\t\t\t\t\t</Stack>\n\t\t\t\t)\n\t\t\t) }\n\t\t</Stack>\n\t);\n}\n\nfunction ErrorDetails( { error, componentStack } ) {\n\treturn (\n\t\t<CollapsibleCard.Root className=\"edit-widgets-error-boundary__details\">\n\t\t\t<CollapsibleCard.Header>\n\t\t\t\t<Card.Title>{ __( 'Error details' ) }</Card.Title>\n\t\t\t</CollapsibleCard.Header>\n\t\t\t<CollapsibleCard.Content>\n\t\t\t\t<ErrorReport\n\t\t\t\t\terror={ error }\n\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t/>\n\t\t\t</CollapsibleCard.Content>\n\t\t</CollapsibleCard.Root>\n\t);\n}\n\nexport default class ErrorBoundary extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.state = {\n\t\t\terror: null,\n\t\t\tcomponentStack: null,\n\t\t};\n\t}\n\n\tcomponentDidCatch( error, errorInfo ) {\n\t\tthis.setState( { componentStack: errorInfo?.componentStack } );\n\t\tdoAction( 'editor.ErrorBoundary.errorLogged', error, errorInfo );\n\t}\n\n\tstatic getDerivedStateFromError( error ) {\n\t\treturn { error };\n\t}\n\n\trender() {\n\t\tconst { error, componentStack } = this.state;\n\t\tif ( ! error ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\treturn (\n\t\t\t<Stack\n\t\t\t\tclassName=\"edit-widgets-error-boundary\"\n\t\t\t\tdirection=\"column\"\n\t\t\t\tgap=\"lg\"\n\t\t\t>\n\t\t\t\t<Notice.Root intent=\"error\">\n\t\t\t\t\t<Notice.Title>\n\t\t\t\t\t\t{ __( 'The editor has crashed' ) }\n\t\t\t\t\t</Notice.Title>\n\t\t\t\t\t<Notice.Description>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Notice.Description>\n\t\t\t\t\t<Notice.Actions>\n\t\t\t\t\t\t<CopyButton\n\t\t\t\t\t\t\tvariant=\"solid\"\n\t\t\t\t\t\t\ttext={ () =>\n\t\t\t\t\t\t\t\tgetErrorReport( error, componentStack )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Copy error' ) }\n\t\t\t\t\t\t</CopyButton>\n\t\t\t\t\t</Notice.Actions>\n\t\t\t\t</Notice.Root>\n\t\t\t\t{ globalThis.SCRIPT_DEBUG ? (\n\t\t\t\t\t<ErrorDetails\n\t\t\t\t\t\terror={ error }\n\t\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t\t/>\n\t\t\t\t) : null }\n\t\t\t</Stack>\n\t\t);\n\t}\n}\n"],
5
+ "mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AAEnB,SAAS,MAAM,iBAAiB,QAAQ,OAAO,YAAY;AAC3D,SAAS,0BAA0B;AACnC,SAAS,gBAAgB;AAoEvB,cAeG,YAfH;AAjEF,SAAS,aAAc,OAAQ;AAC9B,SAAS,iBAAiB,SAAS,MAAM,QAAU;AACpD;AAEA,SAAS,gBAAiB,OAAQ;AACjC,MAAK,OAAO,UAAU,YAAY,OAAQ;AACzC,WAAO;AAAA,EACR;AAEA,MAAK,OAAO,OAAO,YAAY,YAAY,MAAM,SAAU;AAC1D,WAAO,MAAM;AAAA,EACd;AAEA,SAAO;AACR;AAKA,SAAS,iBAAkB,OAAO,gBAAiB;AAClD,QAAM,WAAW;AAAA,IAChB,EAAE,OAAO,aAAc,KAAM,GAAG,SAAS,gBAAiB,KAAM,EAAE;AAAA,EACnE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AAA;AAAA,UACD,IACG;AAAA;AAAA;AAAA,IACL;AAAA,EAEF;AACD;",
6
6
  "names": []
7
7
  }
@@ -590,11 +590,24 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
590
590
  }
591
591
 
592
592
  .edit-widgets-error-boundary {
593
+ font-family: var(--wpds-typography-font-family-body, -apple-system, system-ui, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif);
593
594
  margin: auto;
594
- max-width: 780px;
595
- padding: 20px;
595
+ width: 100%;
596
+ max-width: var(--wpds-dimension-surface-width-lg, 560px);
597
+ padding: var(--wpds-dimension-padding-xl, 20px);
596
598
  margin-top: 64px;
597
- box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08), 0 15px 27px rgba(0, 0, 0, 0.07), 0 30px 36px rgba(0, 0, 0, 0.04), 0 50px 43px rgba(0, 0, 0, 0.02);
599
+ }
600
+
601
+ .edit-widgets-error-boundary__report {
602
+ max-height: 420px;
603
+ overflow: auto;
604
+ overflow-anchor: none;
605
+ }
606
+
607
+ .edit-widgets-error-boundary__report-section {
608
+ margin: 0;
609
+ white-space: pre-wrap;
610
+ overflow-wrap: break-word;
598
611
  }
599
612
 
600
613
  .edit-widgets-header {
@@ -851,8 +864,7 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
851
864
  .edit-widgets-welcome-guide__image > img {
852
865
  display: block;
853
866
  max-width: 100%;
854
- -o-object-fit: cover;
855
- object-fit: cover;
867
+ object-fit: cover;
856
868
  }
857
869
  .edit-widgets-welcome-guide__heading {
858
870
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
@@ -872,7 +884,7 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
872
884
  vertical-align: text-top;
873
885
  }
874
886
  .edit-widgets-welcome-guide .components-button:hover svg {
875
- fill: #fff;
887
+ color: #fff;
876
888
  }
877
889
 
878
890
  .edit-widgets-block-editor {
@@ -590,11 +590,24 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
590
590
  }
591
591
 
592
592
  .edit-widgets-error-boundary {
593
+ font-family: var(--wpds-typography-font-family-body, -apple-system, system-ui, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif);
593
594
  margin: auto;
594
- max-width: 780px;
595
- padding: 20px;
595
+ width: 100%;
596
+ max-width: var(--wpds-dimension-surface-width-lg, 560px);
597
+ padding: var(--wpds-dimension-padding-xl, 20px);
596
598
  margin-top: 64px;
597
- box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08), 0 15px 27px rgba(0, 0, 0, 0.07), 0 30px 36px rgba(0, 0, 0, 0.04), 0 50px 43px rgba(0, 0, 0, 0.02);
599
+ }
600
+
601
+ .edit-widgets-error-boundary__report {
602
+ max-height: 420px;
603
+ overflow: auto;
604
+ overflow-anchor: none;
605
+ }
606
+
607
+ .edit-widgets-error-boundary__report-section {
608
+ margin: 0;
609
+ white-space: pre-wrap;
610
+ overflow-wrap: break-word;
598
611
  }
599
612
 
600
613
  .edit-widgets-header {
@@ -851,8 +864,7 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
851
864
  .edit-widgets-welcome-guide__image > img {
852
865
  display: block;
853
866
  max-width: 100%;
854
- -o-object-fit: cover;
855
- object-fit: cover;
867
+ object-fit: cover;
856
868
  }
857
869
  .edit-widgets-welcome-guide__heading {
858
870
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
@@ -872,7 +884,7 @@ body.is-dragging-components-draggable .wp-block[data-type="core/widget-area"] .c
872
884
  vertical-align: text-top;
873
885
  }
874
886
  .edit-widgets-welcome-guide .components-button:hover svg {
875
- fill: #fff;
887
+ color: #fff;
876
888
  }
877
889
 
878
890
  .edit-widgets-block-editor {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/edit-widgets",
3
- "version": "6.54.2-next.v.202608281122.0",
3
+ "version": "6.55.1-next.v.202609031004.0",
4
4
  "description": "Widgets Page module for WordPress..",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -47,41 +47,42 @@
47
47
  ]
48
48
  },
49
49
  "dependencies": {
50
- "@wordpress/admin-ui": "^2.9.1-next.v.202608281122.0",
51
- "@wordpress/api-fetch": "^7.54.1-next.v.202608281122.0",
52
- "@wordpress/base-styles": "^13.0.1-next.v.202608281122.0",
53
- "@wordpress/block-editor": "^17.0.2-next.v.202608281122.0",
54
- "@wordpress/block-library": "^10.5.2-next.v.202608281122.0",
55
- "@wordpress/blocks": "^16.0.1-next.v.202608281122.0",
56
- "@wordpress/components": "^40.1.1-next.v.202608281122.0",
57
- "@wordpress/compose": "^8.7.2-next.v.202608281122.0",
58
- "@wordpress/core-data": "^7.54.2-next.v.202608281122.0",
59
- "@wordpress/data": "^10.54.2-next.v.202608281122.0",
60
- "@wordpress/deprecated": "^4.54.1-next.v.202608281122.0",
61
- "@wordpress/dom": "^4.54.1-next.v.202608281122.0",
62
- "@wordpress/element": "^8.6.2-next.v.202608281122.0",
63
- "@wordpress/hooks": "^4.54.1-next.v.202608281122.0",
64
- "@wordpress/i18n": "^6.27.1-next.v.202608281122.0",
65
- "@wordpress/icons": "^15.5.1-next.v.202608281122.0",
66
- "@wordpress/interface": "^10.0.2-next.v.202608281122.0",
67
- "@wordpress/keyboard-shortcuts": "^5.54.1-next.v.202608281122.0",
68
- "@wordpress/keycodes": "^4.54.1-next.v.202608281122.0",
69
- "@wordpress/media-utils": "^5.54.1-next.v.202608281122.0",
70
- "@wordpress/notices": "^5.54.1-next.v.202608281122.0",
71
- "@wordpress/patterns": "^2.54.2-next.v.202608281122.0",
72
- "@wordpress/plugins": "^7.54.1-next.v.202608281122.0",
73
- "@wordpress/preferences": "^4.54.2-next.v.202608281122.0",
74
- "@wordpress/private-apis": "^1.54.1-next.v.202608281122.0",
75
- "@wordpress/theme": "^2.1.1-next.v.202608281122.0",
76
- "@wordpress/ui": "^0.22.1-next.v.202608281122.0",
77
- "@wordpress/url": "^4.54.1-next.v.202608281122.0",
78
- "@wordpress/widgets": "^4.54.2-next.v.202608281122.0",
50
+ "@wordpress/admin-ui": "^2.9.1-next.v.202609031004.0",
51
+ "@wordpress/api-fetch": "^7.54.1-next.v.202609031004.0",
52
+ "@wordpress/base-styles": "^13.1.1-next.v.202609031004.0",
53
+ "@wordpress/block-editor": "^17.1.1-next.v.202609031004.0",
54
+ "@wordpress/block-library": "^10.6.1-next.v.202609031004.0",
55
+ "@wordpress/blocks": "^16.0.1-next.v.202609031004.0",
56
+ "@wordpress/components": "^40.1.1-next.v.202609031004.0",
57
+ "@wordpress/compose": "^8.7.2-next.v.202609031004.0",
58
+ "@wordpress/core-data": "^8.0.1-next.v.202609031004.0",
59
+ "@wordpress/data": "^10.54.2-next.v.202609031004.0",
60
+ "@wordpress/deprecated": "^4.54.1-next.v.202609031004.0",
61
+ "@wordpress/dom": "^4.54.1-next.v.202609031004.0",
62
+ "@wordpress/element": "^8.6.2-next.v.202609031004.0",
63
+ "@wordpress/hooks": "^4.54.1-next.v.202609031004.0",
64
+ "@wordpress/i18n": "^6.27.1-next.v.202609031004.0",
65
+ "@wordpress/icons": "^16.0.1-next.v.202609031004.0",
66
+ "@wordpress/interface": "^10.0.2-next.v.202609031004.0",
67
+ "@wordpress/keyboard-shortcuts": "^5.54.1-next.v.202609031004.0",
68
+ "@wordpress/keycodes": "^4.54.1-next.v.202609031004.0",
69
+ "@wordpress/media-utils": "^5.54.1-next.v.202609031004.0",
70
+ "@wordpress/notices": "^5.54.1-next.v.202609031004.0",
71
+ "@wordpress/patterns": "^2.54.2-next.v.202609031004.0",
72
+ "@wordpress/plugins": "^7.54.1-next.v.202609031004.0",
73
+ "@wordpress/preferences": "^4.54.2-next.v.202609031004.0",
74
+ "@wordpress/private-apis": "^1.54.2-next.v.202609031004.0",
75
+ "@wordpress/theme": "^2.1.1-next.v.202609031004.0",
76
+ "@wordpress/ui": "^0.22.1-next.v.202609031004.0",
77
+ "@wordpress/url": "^4.54.1-next.v.202609031004.0",
78
+ "@wordpress/widgets": "^4.54.2-next.v.202609031004.0",
79
79
  "clsx": "^2.1.1"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@testing-library/dom": "^10.4.1",
83
83
  "@testing-library/react": "^16.3.2",
84
- "deep-freeze": "^0.0.1"
84
+ "deep-freeze": "^0.0.1",
85
+ "vitest": "^4.1.10"
85
86
  },
86
87
  "peerDependencies": {
87
88
  "react": "^18 || ^19",
@@ -90,5 +91,5 @@
90
91
  "publishConfig": {
91
92
  "access": "public"
92
93
  },
93
- "gitHead": "de479d415171765f7b573c81aeec5334ff506a12"
94
+ "gitHead": "7275d6c6d93b542fca3cd98cdb9c7344ddd11e19"
94
95
  }
@@ -1,30 +1,116 @@
1
1
  import { Component } from '@wordpress/element';
2
2
  import { __ } from '@wordpress/i18n';
3
- import { Button } from '@wordpress/components';
4
- import { Warning } from '@wordpress/block-editor';
3
+ // eslint-disable-next-line @wordpress/use-recommended-components -- The fallback UI renders outside the editor's notice system.
4
+ import { Card, CollapsibleCard, Notice, Stack, Text } from '@wordpress/ui';
5
5
  import { useCopyToClipboard } from '@wordpress/compose';
6
6
  import { doAction } from '@wordpress/hooks';
7
7
 
8
- function CopyButton( { text, children } ) {
8
+ // A boundary catches whatever was thrown, which is not always an `Error`.
9
+ function getErrorName( error ) {
10
+ return ( error instanceof Error && error.name ) || 'Error';
11
+ }
12
+
13
+ function getErrorMessage( error ) {
14
+ if ( typeof error === 'string' && error ) {
15
+ return error;
16
+ }
17
+
18
+ if ( typeof error?.message === 'string' && error.message ) {
19
+ return error.message;
20
+ }
21
+
22
+ return 'An unknown error occurred.';
23
+ }
24
+
25
+ // The sections of the report, shared by the copied Markdown and the details
26
+ // panel so that the two cannot drift apart. Deliberately untranslated: both
27
+ // are developer-facing, and the report is pasted into a bug report.
28
+ function getErrorSections( error, componentStack ) {
29
+ const sections = [
30
+ { label: getErrorName( error ), content: getErrorMessage( error ) },
31
+ ];
32
+
33
+ if ( error?.stack ) {
34
+ sections.push( {
35
+ label: 'Stack',
36
+ content: error.stack.trim(),
37
+ preformatted: true,
38
+ } );
39
+ }
40
+
41
+ if ( componentStack ) {
42
+ sections.push( {
43
+ label: 'Component stack',
44
+ content: componentStack.trim(),
45
+ preformatted: true,
46
+ } );
47
+ }
48
+
49
+ sections.push( {
50
+ label: 'Environment',
51
+ content: `User agent: ${ window.navigator.userAgent }`,
52
+ preformatted: true,
53
+ } );
54
+
55
+ return sections;
56
+ }
57
+
58
+ // Markdown, so the report stays readable as plain text and renders when pasted
59
+ // into a bug report.
60
+ function getErrorReport( error, componentStack ) {
61
+ const sections = getErrorSections( error, componentStack ).map(
62
+ ( { label, content, preformatted } ) =>
63
+ `**${ label }**\n\n${
64
+ preformatted ? `\`\`\`\n${ content }\n\`\`\`` : content
65
+ }`
66
+ );
67
+
68
+ return [ '### Error report', ...sections ].join( '\n\n' );
69
+ }
70
+
71
+ function CopyButton( { text, children, variant = 'outline' } ) {
9
72
  const ref = useCopyToClipboard( text );
10
73
  return (
11
- <Button __next40pxDefaultSize variant="secondary" ref={ ref }>
74
+ <Notice.ActionButton variant={ variant } ref={ ref }>
12
75
  { children }
13
- </Button>
76
+ </Notice.ActionButton>
14
77
  );
15
78
  }
16
79
 
17
- function ErrorBoundaryWarning( { message, error } ) {
18
- const actions = [
19
- <CopyButton key="copy-error" text={ error.stack }>
20
- { __( 'Copy Error' ) }
21
- </CopyButton>,
22
- ];
80
+ function ErrorReport( { error, componentStack } ) {
81
+ return (
82
+ <Stack
83
+ className="edit-widgets-error-boundary__report"
84
+ direction="column"
85
+ gap="md"
86
+ >
87
+ { getErrorSections( error, componentStack ).map(
88
+ ( { label, content } ) => (
89
+ <Stack key={ label } direction="column" gap="xs">
90
+ <Text variant="heading-md">{ label }</Text>
91
+ <pre className="edit-widgets-error-boundary__report-section">
92
+ { content }
93
+ </pre>
94
+ </Stack>
95
+ )
96
+ ) }
97
+ </Stack>
98
+ );
99
+ }
23
100
 
101
+ function ErrorDetails( { error, componentStack } ) {
24
102
  return (
25
- <Warning className="edit-widgets-error-boundary" actions={ actions }>
26
- { message }
27
- </Warning>
103
+ <CollapsibleCard.Root className="edit-widgets-error-boundary__details">
104
+ <CollapsibleCard.Header>
105
+ <Card.Title>{ __( 'Error details' ) }</Card.Title>
106
+ </CollapsibleCard.Header>
107
+ <CollapsibleCard.Content>
108
+ <ErrorReport
109
+ error={ error }
110
+ componentStack={ componentStack }
111
+ />
112
+ </CollapsibleCard.Content>
113
+ </CollapsibleCard.Root>
28
114
  );
29
115
  }
30
116
 
@@ -34,11 +120,13 @@ export default class ErrorBoundary extends Component {
34
120
 
35
121
  this.state = {
36
122
  error: null,
123
+ componentStack: null,
37
124
  };
38
125
  }
39
126
 
40
- componentDidCatch( error ) {
41
- doAction( 'editor.ErrorBoundary.errorLogged', error );
127
+ componentDidCatch( error, errorInfo ) {
128
+ this.setState( { componentStack: errorInfo?.componentStack } );
129
+ doAction( 'editor.ErrorBoundary.errorLogged', error, errorInfo );
42
130
  }
43
131
 
44
132
  static getDerivedStateFromError( error ) {
@@ -46,17 +134,44 @@ export default class ErrorBoundary extends Component {
46
134
  }
47
135
 
48
136
  render() {
49
- if ( ! this.state.error ) {
137
+ const { error, componentStack } = this.state;
138
+ if ( ! error ) {
50
139
  return this.props.children;
51
140
  }
52
141
 
53
142
  return (
54
- <ErrorBoundaryWarning
55
- message={ __(
56
- 'The editor has encountered an unexpected error.'
57
- ) }
58
- error={ this.state.error }
59
- />
143
+ <Stack
144
+ className="edit-widgets-error-boundary"
145
+ direction="column"
146
+ gap="lg"
147
+ >
148
+ <Notice.Root intent="error">
149
+ <Notice.Title>
150
+ { __( 'The editor has crashed' ) }
151
+ </Notice.Title>
152
+ <Notice.Description>
153
+ { __(
154
+ 'An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.'
155
+ ) }
156
+ </Notice.Description>
157
+ <Notice.Actions>
158
+ <CopyButton
159
+ variant="solid"
160
+ text={ () =>
161
+ getErrorReport( error, componentStack )
162
+ }
163
+ >
164
+ { __( 'Copy error' ) }
165
+ </CopyButton>
166
+ </Notice.Actions>
167
+ </Notice.Root>
168
+ { globalThis.SCRIPT_DEBUG ? (
169
+ <ErrorDetails
170
+ error={ error }
171
+ componentStack={ componentStack }
172
+ />
173
+ ) : null }
174
+ </Stack>
60
175
  );
61
176
  }
62
177
  }
@@ -1,9 +1,22 @@
1
1
  @use "@wordpress/base-styles/variables" as *;
2
2
 
3
3
  .edit-widgets-error-boundary {
4
+ font-family: var(--wpds-typography-font-family-body);
4
5
  margin: auto;
5
- max-width: 780px;
6
- padding: 20px;
6
+ width: 100%;
7
+ max-width: var(--wpds-dimension-surface-width-lg);
8
+ padding: var(--wpds-dimension-padding-xl);
7
9
  margin-top: $header-height;
8
- box-shadow: $elevation-large;
10
+ }
11
+
12
+ .edit-widgets-error-boundary__report {
13
+ max-height: 420px;
14
+ overflow: auto;
15
+ overflow-anchor: none;
16
+ }
17
+
18
+ .edit-widgets-error-boundary__report-section {
19
+ margin: 0;
20
+ white-space: pre-wrap;
21
+ overflow-wrap: break-word;
9
22
  }
@@ -10,7 +10,7 @@ const ChildComponent = () => {
10
10
 
11
11
  describe( 'Error Boundary', () => {
12
12
  describe( 'when error is thrown from a Child component', () => {
13
- it( 'calls the `editor.ErrorBoundary.errorLogged` hook action with the error object', () => {
13
+ it( 'calls the `editor.ErrorBoundary.errorLogged` hook action with the error object and error info', () => {
14
14
  const doAction = jest.spyOn( wpHooks, 'doAction' );
15
15
 
16
16
  render(
@@ -21,7 +21,10 @@ describe( 'Error Boundary', () => {
21
21
 
22
22
  expect( doAction ).toHaveBeenCalledWith(
23
23
  'editor.ErrorBoundary.errorLogged',
24
- theError
24
+ theError,
25
+ expect.objectContaining( {
26
+ componentStack: expect.any( String ),
27
+ } )
25
28
  );
26
29
  expect( console ).toHaveErrored();
27
30
  } );
@@ -36,7 +36,7 @@
36
36
  .components-button {
37
37
  &:hover {
38
38
  svg {
39
- fill: $white;
39
+ color: $white;
40
40
  }
41
41
  }
42
42
  }
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import deepFreeze from 'deep-freeze';
2
3
  import { widgetSavingLock } from '../reducer';
3
4