Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
25a8e82
Fix API docs generation (#33384)
nosolosw Jul 13, 2021
728dcd7
Docs: use markdown headings instead of links for API declarations (#3…
juanmaguitar Jul 14, 2021
6537d4e
Docs: Run Prettier after updating API in documentation (#33498)
gziolo Jul 19, 2021
98779bf
Use tabs instead of spaces in block transform doc example (#33549)
jblz Jul 20, 2021
c985f56
Fix metabox reordering (#30617).
ribaricplusplus Aug 30, 2021
404619f
Block editor: don't render layout and duotone styles in between block…
ellatrix Jul 13, 2021
bdaa7b6
Widgets: Allow HTML tags in description (#33814)
Aug 9, 2021
336aa2a
Editor: Set 'hide_empty' for the most used terms query (#33457)
Mamaduka Jul 16, 2021
d9c56de
Update widget editor help links to point to the new support article (…
talldan Jul 16, 2021
455de81
If select-all fires in .editor-post-title__input, end the process.. (…
torounit Jul 22, 2021
891de6a
Writing flow: select all: remove early return for post title (#33699)
ellatrix Jul 26, 2021
5180b56
Call onChangeSectionExpanded conditionally (#33618)
kevin940726 Jul 22, 2021
a122eb8
FontSizePicker: Use number values when the initial value is a number …
Mamaduka Jul 30, 2021
20eb111
Fix justification for button block when selected (#33739)
mkaz Aug 2, 2021
b4c5c94
Add error boundaries to widget screens (#33771)
talldan Aug 2, 2021
466c9e3
Fix insertion point in Widgets editors (#33802)
kevin940726 Aug 2, 2021
40fa01a
Default batch processor: Respect the batch endpoint's maxItems (#34280)
noisysocks Aug 25, 2021
d888f1c
Fix button block focus trap after a URL has been added (#34314)
talldan Aug 27, 2021
c388f23
Text for dropdown fields within legacy widgets in the Customizer is o…
anton-vlasenko Aug 19, 2021
95dc1fd
Fix ESLint errors reported
gziolo Sep 1, 2021
4cf5f60
Regenerate autogenerated docs
gziolo Sep 1, 2021
90ac898
Update the `INSERTER_SEARCH_SELECTOR` path.
desrosj Sep 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add error boundaries to widget screens (#33771)
* Add error boundary to edit widgets screen

* Add error boundary to customize widgets

* Refactor sidebar controls provider to application level so that its state is not lost when re-initializing

* Revert "Refactor sidebar controls provider to application level so that its state is not lost when re-initializing"

This reverts commit 7d607ff.

* Remove rebootability from customize widgets

* Remove debug code
  • Loading branch information
talldan authored and desrosj committed Aug 30, 2021
commit b4c5c94851cc2a774c073d3cd6f40f9bebb8f6ef
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SlotFillProvider, Popover } from '@wordpress/components';
/**
* Internal dependencies
*/
import ErrorBoundary from '../error-boundary';
import SidebarBlockEditor from '../sidebar-block-editor';
import FocusControl from '../focus-control';
import SidebarControls from '../sidebar-controls';
Expand Down Expand Up @@ -42,13 +43,15 @@ export default function CustomizeWidgets( {
const activeSidebar =
activeSidebarControl &&
createPortal(
<SidebarBlockEditor
key={ activeSidebarControl.id }
blockEditorSettings={ blockEditorSettings }
sidebar={ activeSidebarControl.sidebarAdapter }
inserter={ activeSidebarControl.inserter }
inspector={ activeSidebarControl.inspector }
/>,
<ErrorBoundary>
<SidebarBlockEditor
key={ activeSidebarControl.id }
blockEditorSettings={ blockEditorSettings }
sidebar={ activeSidebarControl.sidebarAdapter }
inserter={ activeSidebarControl.inserter }
inspector={ activeSidebarControl.inspector }
/>
</ErrorBoundary>,
activeSidebarControl.container[ 0 ]
);

Expand Down
50 changes: 50 additions & 0 deletions packages/customize-widgets/src/components/error-boundary/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { Warning } from '@wordpress/block-editor';
import { useCopyToClipboard } from '@wordpress/compose';

function CopyButton( { text, children } ) {
const ref = useCopyToClipboard( text );
return (
<Button variant="secondary" ref={ ref }>
{ children }
</Button>
);
}

export default class ErrorBoundary extends Component {
constructor() {
super( ...arguments );
this.state = {
error: null,
};
}

componentDidCatch( error ) {
this.setState( { error } );
}

render() {
const { error } = this.state;
if ( ! error ) {
return this.props.children;
}

return (
<Warning
className="customize-widgets-error-boundary"
actions={ [
<CopyButton key="copy-error" text={ error.stack }>
{ __( 'Copy Error' ) }
</CopyButton>,
] }
>
{ __( 'The editor has encountered an unexpected error.' ) }
</Warning>
);
}
}
64 changes: 64 additions & 0 deletions packages/edit-widgets/src/components/error-boundary/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { Warning } from '@wordpress/block-editor';
import { useCopyToClipboard } from '@wordpress/compose';

function CopyButton( { text, children } ) {
const ref = useCopyToClipboard( text );
return (
<Button variant="secondary" ref={ ref }>
{ children }
</Button>
);
}

export default class ErrorBoundary extends Component {
constructor() {
super( ...arguments );

this.reboot = this.reboot.bind( this );

this.state = {
error: null,
};
}

componentDidCatch( error ) {
this.setState( { error } );
}

reboot() {
this.props.onError();
}

render() {
const { error } = this.state;
if ( ! error ) {
return this.props.children;
}

return (
<Warning
className="edit-widgets-error-boundary"
actions={ [
<Button
key="recovery"
onClick={ this.reboot }
variant="secondary"
>
{ __( 'Attempt Recovery' ) }
</Button>,
<CopyButton key="copy-error" text={ error.stack }>
{ __( 'Copy Error' ) }
</CopyButton>,
] }
>
{ __( 'The editor has encountered an unexpected error.' ) }
</Warning>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.edit-widgets-error-boundary {
margin: auto;
max-width: 780px;
padding: 20px;
margin-top: 60px;
box-shadow: $shadow-modal;
}
25 changes: 14 additions & 11 deletions packages/edit-widgets/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ import { PluginArea } from '@wordpress/plugins';
/**
* Internal dependencies
*/
import ErrorBoundary from '../error-boundary';
import WidgetAreasBlockEditorProvider from '../widget-areas-block-editor-provider';
import Sidebar from '../sidebar';
import Interface from './interface';
import UnsavedChangesWarning from './unsaved-changes-warning';
import WelcomeGuide from '../welcome-guide';

function Layout( { blockEditorSettings } ) {
function Layout( { blockEditorSettings, onError } ) {
return (
<WidgetAreasBlockEditorProvider
blockEditorSettings={ blockEditorSettings }
>
<Interface blockEditorSettings={ blockEditorSettings } />
<Sidebar />
<Popover.Slot />
<PluginArea />
<UnsavedChangesWarning />
<WelcomeGuide />
</WidgetAreasBlockEditorProvider>
<ErrorBoundary onError={ onError }>
<WidgetAreasBlockEditorProvider
blockEditorSettings={ blockEditorSettings }
>
<Interface blockEditorSettings={ blockEditorSettings } />
<Sidebar />
<Popover.Slot />
<PluginArea />
<UnsavedChangesWarning />
<WelcomeGuide />
</WidgetAreasBlockEditorProvider>
</ErrorBoundary>
);
}

Expand Down
25 changes: 22 additions & 3 deletions packages/edit-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase
setFreeformContentHandlerName,
} from '@wordpress/blocks';
import { render } from '@wordpress/element';
import { render, unmountComponentAtNode } from '@wordpress/element';
import {
registerCoreBlocks,
__experimentalGetCoreBlocks,
Expand Down Expand Up @@ -36,13 +36,32 @@ const disabledBlocks = [
...( ! ALLOW_REUSABLE_BLOCKS && [ 'core/block' ] ),
];

/**
* Reinitializes the editor after the user chooses to reboot the editor after
* an unhandled error occurs, replacing previously mounted editor element using
* an initial state from prior to the crash.
*
* @param {Element} target DOM node in which editor is rendered.
* @param {?Object} settings Editor settings object.
*/
export function reinitializeEditor( target, settings ) {
unmountComponentAtNode( target );
const reboot = reinitializeEditor.bind( null, target, settings );
render(
<Layout blockEditorSettings={ settings } onError={ reboot } />,
target
);
}

/**
* Initializes the block editor in the widgets screen.
*
* @param {string} id ID of the root element to render the screen in.
* @param {Object} settings Block editor settings.
*/
export function initialize( id, settings ) {
const target = document.getElementById( id );
const reboot = reinitializeEditor.bind( null, target, settings );
const coreBlocks = __experimentalGetCoreBlocks().filter( ( block ) => {
return ! (
disabledBlocks.includes( block.name ) ||
Expand Down Expand Up @@ -70,8 +89,8 @@ export function initialize( id, settings ) {
// see: https://github.com/WordPress/gutenberg/issues/33097
setFreeformContentHandlerName( 'core/html' );
render(
<Layout blockEditorSettings={ settings } />,
document.getElementById( id )
<Layout blockEditorSettings={ settings } onError={ reboot } />,
target
);
}

Expand Down
1 change: 1 addition & 0 deletions packages/edit-widgets/src/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "../../interface/src/style.scss";

@import "./blocks/widget-area/editor.scss";
@import "./components/error-boundary/style.scss";
@import "./components/header/style.scss";
@import "./components/keyboard-shortcut-help-modal/style.scss";
@import "./components/more-menu/style.scss";
Expand Down