@wordpress/customize-widgets 5.54.2-next.v.202608281122.0 → 5.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 +5 -1
- package/build/components/error-boundary/index.cjs +114 -15
- package/build/components/error-boundary/index.cjs.map +2 -2
- package/build-module/components/error-boundary/index.mjs +115 -16
- package/build-module/components/error-boundary/index.mjs.map +2 -2
- package/build-style/style-rtl.css +17 -0
- package/build-style/style.css +17 -0
- package/package.json +27 -26
- package/src/components/error-boundary/index.jsx +144 -17
- package/src/components/error-boundary/style.scss +16 -0
- package/src/components/error-boundary/test/{error-boundary.jsx → error-boundary.jsdom.test.jsx} +5 -2
- package/src/style.scss +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -24,39 +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
|
|
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
|
|
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.";
|
|
42
|
+
}
|
|
43
|
+
function getErrorSections(error, componentStack) {
|
|
44
|
+
const sections = [
|
|
45
|
+
{ label: getErrorName(error), content: getErrorMessage(error) }
|
|
46
|
+
];
|
|
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" }) {
|
|
33
79
|
const ref = (0, import_compose.useCopyToClipboard)(text);
|
|
34
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
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: "customize-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: "customize-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: "customize-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
|
+
] });
|
|
35
109
|
}
|
|
36
110
|
var ErrorBoundary = class extends import_element.Component {
|
|
37
111
|
constructor() {
|
|
38
112
|
super(...arguments);
|
|
39
113
|
this.state = {
|
|
40
|
-
error: null
|
|
114
|
+
error: null,
|
|
115
|
+
componentStack: null
|
|
41
116
|
};
|
|
42
117
|
}
|
|
43
|
-
componentDidCatch(error) {
|
|
44
|
-
this.setState({
|
|
45
|
-
(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);
|
|
121
|
+
}
|
|
122
|
+
static getDerivedStateFromError(error) {
|
|
123
|
+
return { error };
|
|
46
124
|
}
|
|
47
125
|
render() {
|
|
48
|
-
const { error } = this.state;
|
|
126
|
+
const { error, componentStack } = this.state;
|
|
49
127
|
if (!error) {
|
|
50
128
|
return this.props.children;
|
|
51
129
|
}
|
|
52
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.
|
|
53
|
-
|
|
130
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
131
|
+
import_ui.Stack,
|
|
54
132
|
{
|
|
55
133
|
className: "customize-widgets-error-boundary",
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
]
|
|
60
159
|
}
|
|
61
160
|
);
|
|
62
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';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA0B;AAC1B,kBAAmB;
|
|
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=\"customize-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=\"customize-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=\"customize-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=\"customize-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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AA,EAChB;AAAA,EAEA,SAAS;AACR,UAAM,EAAE,OAAO,eAAe,IAAI,KAAK;AACvC,QAAK,CAAE,OAAQ;AACd,aAAO,KAAK,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,39 +1,138 @@
|
|
|
1
1
|
// packages/customize-widgets/src/components/error-boundary/index.jsx
|
|
2
2
|
import { Component } from "@wordpress/element";
|
|
3
3
|
import { __ } from "@wordpress/i18n";
|
|
4
|
-
import {
|
|
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
|
|
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.";
|
|
19
|
+
}
|
|
20
|
+
function getErrorSections(error, componentStack) {
|
|
21
|
+
const sections = [
|
|
22
|
+
{ label: getErrorName(error), content: getErrorMessage(error) }
|
|
23
|
+
];
|
|
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" }) {
|
|
10
56
|
const ref = useCopyToClipboard(text);
|
|
11
|
-
return /* @__PURE__ */ jsx(
|
|
57
|
+
return /* @__PURE__ */ jsx(Notice.ActionButton, { variant, ref, children });
|
|
58
|
+
}
|
|
59
|
+
function ErrorReport({ error, componentStack }) {
|
|
60
|
+
return /* @__PURE__ */ jsx(
|
|
61
|
+
Stack,
|
|
62
|
+
{
|
|
63
|
+
className: "customize-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: "customize-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: "customize-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
|
+
] });
|
|
12
86
|
}
|
|
13
87
|
var ErrorBoundary = class extends Component {
|
|
14
88
|
constructor() {
|
|
15
89
|
super(...arguments);
|
|
16
90
|
this.state = {
|
|
17
|
-
error: null
|
|
91
|
+
error: null,
|
|
92
|
+
componentStack: null
|
|
18
93
|
};
|
|
19
94
|
}
|
|
20
|
-
componentDidCatch(error) {
|
|
21
|
-
this.setState({
|
|
22
|
-
doAction("editor.ErrorBoundary.errorLogged", error);
|
|
95
|
+
componentDidCatch(error, errorInfo) {
|
|
96
|
+
this.setState({ componentStack: errorInfo?.componentStack });
|
|
97
|
+
doAction("editor.ErrorBoundary.errorLogged", error, errorInfo);
|
|
98
|
+
}
|
|
99
|
+
static getDerivedStateFromError(error) {
|
|
100
|
+
return { error };
|
|
23
101
|
}
|
|
24
102
|
render() {
|
|
25
|
-
const { error } = this.state;
|
|
103
|
+
const { error, componentStack } = this.state;
|
|
26
104
|
if (!error) {
|
|
27
105
|
return this.props.children;
|
|
28
106
|
}
|
|
29
|
-
return /* @__PURE__ */
|
|
30
|
-
|
|
107
|
+
return /* @__PURE__ */ jsxs(
|
|
108
|
+
Stack,
|
|
31
109
|
{
|
|
32
110
|
className: "customize-widgets-error-boundary",
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
]
|
|
37
136
|
}
|
|
38
137
|
);
|
|
39
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';\
|
|
5
|
-
"mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AACnB,SAAS,cAAc;
|
|
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=\"customize-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=\"customize-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=\"customize-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=\"customize-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,SAA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O,MAAP,EAAY,QAAO,SACnB;AAAA,gCAAC,OAAO,OAAP,EACE,aAAI,wBAAyB,GAChC;AAAA,YACA,oBAAC,OAAO,aAAP,EACE;AAAA,cACD;AAAA,YACD,GACD;AAAA,YACA,oBAAC,OAAO,SAAP,EACA;AAAA,cAAC;AAAA;AAAA,gBACA,SAAQ;AAAA,gBACR,MAAO,MACN,eAAgB,OAAO,cAAe;AAAA,gBAGrC,aAAI,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
|
}
|
|
@@ -130,6 +130,23 @@
|
|
|
130
130
|
transform: translateX(100%);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
.customize-widgets-error-boundary {
|
|
134
|
+
font-family: var(--wpds-typography-font-family-body, -apple-system, system-ui, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif);
|
|
135
|
+
padding: var(--wpds-dimension-padding-md, 12px);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.customize-widgets-error-boundary__report {
|
|
139
|
+
max-height: 420px;
|
|
140
|
+
overflow: auto;
|
|
141
|
+
overflow-anchor: none;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.customize-widgets-error-boundary__report-section {
|
|
145
|
+
margin: 0;
|
|
146
|
+
white-space: pre-wrap;
|
|
147
|
+
overflow-wrap: break-word;
|
|
148
|
+
}
|
|
149
|
+
|
|
133
150
|
@media (min-width: 600px) {
|
|
134
151
|
.customize-widgets-header {
|
|
135
152
|
margin-bottom: 44px;
|
package/build-style/style.css
CHANGED
|
@@ -130,6 +130,23 @@
|
|
|
130
130
|
transform: translateX(-100%);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
.customize-widgets-error-boundary {
|
|
134
|
+
font-family: var(--wpds-typography-font-family-body, -apple-system, system-ui, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif);
|
|
135
|
+
padding: var(--wpds-dimension-padding-md, 12px);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.customize-widgets-error-boundary__report {
|
|
139
|
+
max-height: 420px;
|
|
140
|
+
overflow: auto;
|
|
141
|
+
overflow-anchor: none;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.customize-widgets-error-boundary__report-section {
|
|
145
|
+
margin: 0;
|
|
146
|
+
white-space: pre-wrap;
|
|
147
|
+
overflow-wrap: break-word;
|
|
148
|
+
}
|
|
149
|
+
|
|
133
150
|
@media (min-width: 600px) {
|
|
134
151
|
.customize-widgets-header {
|
|
135
152
|
margin-bottom: 44px;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/customize-widgets",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.55.1-next.v.202609031004.0",
|
|
4
4
|
"description": "Widgets blocks in Customizer Module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -39,35 +39,36 @@
|
|
|
39
39
|
},
|
|
40
40
|
"wpScript": true,
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@wordpress/admin-ui": "^2.9.1-next.v.
|
|
43
|
-
"@wordpress/base-styles": "^13.
|
|
44
|
-
"@wordpress/block-editor": "^17.
|
|
45
|
-
"@wordpress/block-library": "^10.
|
|
46
|
-
"@wordpress/blocks": "^16.0.1-next.v.
|
|
47
|
-
"@wordpress/components": "^40.1.1-next.v.
|
|
48
|
-
"@wordpress/compose": "^8.7.2-next.v.
|
|
49
|
-
"@wordpress/core-data": "^
|
|
50
|
-
"@wordpress/data": "^10.54.2-next.v.
|
|
51
|
-
"@wordpress/dom": "^4.54.1-next.v.
|
|
52
|
-
"@wordpress/element": "^8.6.2-next.v.
|
|
53
|
-
"@wordpress/hooks": "^4.54.1-next.v.
|
|
54
|
-
"@wordpress/i18n": "^6.27.1-next.v.
|
|
55
|
-
"@wordpress/icons": "^
|
|
56
|
-
"@wordpress/is-shallow-equal": "^5.54.1-next.v.
|
|
57
|
-
"@wordpress/keyboard-shortcuts": "^5.54.1-next.v.
|
|
58
|
-
"@wordpress/keycodes": "^4.54.1-next.v.
|
|
59
|
-
"@wordpress/media-utils": "^5.54.1-next.v.
|
|
60
|
-
"@wordpress/preferences": "^4.54.2-next.v.
|
|
61
|
-
"@wordpress/private-apis": "^1.54.
|
|
62
|
-
"@wordpress/theme": "^2.1.1-next.v.
|
|
63
|
-
"@wordpress/ui": "^0.22.1-next.v.
|
|
64
|
-
"@wordpress/widgets": "^4.54.2-next.v.
|
|
42
|
+
"@wordpress/admin-ui": "^2.9.1-next.v.202609031004.0",
|
|
43
|
+
"@wordpress/base-styles": "^13.1.1-next.v.202609031004.0",
|
|
44
|
+
"@wordpress/block-editor": "^17.1.1-next.v.202609031004.0",
|
|
45
|
+
"@wordpress/block-library": "^10.6.1-next.v.202609031004.0",
|
|
46
|
+
"@wordpress/blocks": "^16.0.1-next.v.202609031004.0",
|
|
47
|
+
"@wordpress/components": "^40.1.1-next.v.202609031004.0",
|
|
48
|
+
"@wordpress/compose": "^8.7.2-next.v.202609031004.0",
|
|
49
|
+
"@wordpress/core-data": "^8.0.1-next.v.202609031004.0",
|
|
50
|
+
"@wordpress/data": "^10.54.2-next.v.202609031004.0",
|
|
51
|
+
"@wordpress/dom": "^4.54.1-next.v.202609031004.0",
|
|
52
|
+
"@wordpress/element": "^8.6.2-next.v.202609031004.0",
|
|
53
|
+
"@wordpress/hooks": "^4.54.1-next.v.202609031004.0",
|
|
54
|
+
"@wordpress/i18n": "^6.27.1-next.v.202609031004.0",
|
|
55
|
+
"@wordpress/icons": "^16.0.1-next.v.202609031004.0",
|
|
56
|
+
"@wordpress/is-shallow-equal": "^5.54.1-next.v.202609031004.0",
|
|
57
|
+
"@wordpress/keyboard-shortcuts": "^5.54.1-next.v.202609031004.0",
|
|
58
|
+
"@wordpress/keycodes": "^4.54.1-next.v.202609031004.0",
|
|
59
|
+
"@wordpress/media-utils": "^5.54.1-next.v.202609031004.0",
|
|
60
|
+
"@wordpress/preferences": "^4.54.2-next.v.202609031004.0",
|
|
61
|
+
"@wordpress/private-apis": "^1.54.2-next.v.202609031004.0",
|
|
62
|
+
"@wordpress/theme": "^2.1.1-next.v.202609031004.0",
|
|
63
|
+
"@wordpress/ui": "^0.22.1-next.v.202609031004.0",
|
|
64
|
+
"@wordpress/widgets": "^4.54.2-next.v.202609031004.0",
|
|
65
65
|
"clsx": "^2.1.1",
|
|
66
66
|
"fast-deep-equal": "^3.1.3"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@testing-library/dom": "^10.4.1",
|
|
70
|
-
"@testing-library/react": "^16.3.2"
|
|
70
|
+
"@testing-library/react": "^16.3.2",
|
|
71
|
+
"vitest": "^4.1.10"
|
|
71
72
|
},
|
|
72
73
|
"peerDependencies": {
|
|
73
74
|
"react": "^18 || ^19",
|
|
@@ -76,5 +77,5 @@
|
|
|
76
77
|
"publishConfig": {
|
|
77
78
|
"access": "public"
|
|
78
79
|
},
|
|
79
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "7275d6c6d93b542fca3cd98cdb9c7344ddd11e19"
|
|
80
81
|
}
|
|
@@ -1,50 +1,177 @@
|
|
|
1
1
|
import { Component } from '@wordpress/element';
|
|
2
2
|
import { __ } from '@wordpress/i18n';
|
|
3
|
-
|
|
4
|
-
import {
|
|
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
|
-
|
|
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
|
-
<
|
|
74
|
+
<Notice.ActionButton variant={ variant } ref={ ref }>
|
|
12
75
|
{ children }
|
|
13
|
-
</
|
|
76
|
+
</Notice.ActionButton>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function ErrorReport( { error, componentStack } ) {
|
|
81
|
+
return (
|
|
82
|
+
<Stack
|
|
83
|
+
className="customize-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="customize-widgets-error-boundary__report-section">
|
|
92
|
+
{ content }
|
|
93
|
+
</pre>
|
|
94
|
+
</Stack>
|
|
95
|
+
)
|
|
96
|
+
) }
|
|
97
|
+
</Stack>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function ErrorDetails( { error, componentStack } ) {
|
|
102
|
+
return (
|
|
103
|
+
<CollapsibleCard.Root className="customize-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>
|
|
14
114
|
);
|
|
15
115
|
}
|
|
16
116
|
|
|
17
117
|
export default class ErrorBoundary extends Component {
|
|
18
118
|
constructor() {
|
|
19
119
|
super( ...arguments );
|
|
120
|
+
|
|
20
121
|
this.state = {
|
|
21
122
|
error: null,
|
|
123
|
+
componentStack: null,
|
|
22
124
|
};
|
|
23
125
|
}
|
|
24
126
|
|
|
25
|
-
componentDidCatch( error ) {
|
|
26
|
-
this.setState( {
|
|
127
|
+
componentDidCatch( error, errorInfo ) {
|
|
128
|
+
this.setState( { componentStack: errorInfo?.componentStack } );
|
|
129
|
+
doAction( 'editor.ErrorBoundary.errorLogged', error, errorInfo );
|
|
130
|
+
}
|
|
27
131
|
|
|
28
|
-
|
|
132
|
+
static getDerivedStateFromError( error ) {
|
|
133
|
+
return { error };
|
|
29
134
|
}
|
|
30
135
|
|
|
31
136
|
render() {
|
|
32
|
-
const { error } = this.state;
|
|
137
|
+
const { error, componentStack } = this.state;
|
|
33
138
|
if ( ! error ) {
|
|
34
139
|
return this.props.children;
|
|
35
140
|
}
|
|
36
141
|
|
|
37
142
|
return (
|
|
38
|
-
<
|
|
143
|
+
<Stack
|
|
39
144
|
className="customize-widgets-error-boundary"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{ __( 'Copy Error' ) }
|
|
43
|
-
</CopyButton>,
|
|
44
|
-
] }
|
|
145
|
+
direction="column"
|
|
146
|
+
gap="lg"
|
|
45
147
|
>
|
|
46
|
-
|
|
47
|
-
|
|
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>
|
|
48
175
|
);
|
|
49
176
|
}
|
|
50
177
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.customize-widgets-error-boundary {
|
|
2
|
+
font-family: var(--wpds-typography-font-family-body);
|
|
3
|
+
padding: var(--wpds-dimension-padding-md);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.customize-widgets-error-boundary__report {
|
|
7
|
+
max-height: 420px;
|
|
8
|
+
overflow: auto;
|
|
9
|
+
overflow-anchor: none;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.customize-widgets-error-boundary__report-section {
|
|
13
|
+
margin: 0;
|
|
14
|
+
white-space: pre-wrap;
|
|
15
|
+
overflow-wrap: break-word;
|
|
16
|
+
}
|
package/src/components/error-boundary/test/{error-boundary.jsx → error-boundary.jsdom.test.jsx}
RENAMED
|
@@ -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
|
} );
|
package/src/style.scss
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
@use "@wordpress/base-styles/mixins" as *;
|
|
2
2
|
@use "@wordpress/base-styles/default-custom-properties";
|
|
3
3
|
@use "./components/block-inspector-button/style.scss" as *;
|
|
4
|
+
@use "./components/error-boundary/style.scss" as *;
|
|
4
5
|
@use "./components/header/style.scss" as *;
|
|
5
6
|
@use "./components/inserter/style.scss" as *;
|
|
6
7
|
@use "./components/keyboard-shortcut-help-modal/style.scss" as *;
|