Skip to content

Commit

Permalink
Editor: Run block-editor's setup before editor's so that settings are…
Browse files Browse the repository at this point in the history
… available for parse-time validation.
  • Loading branch information
epiqueras committed Jul 9, 2019
1 parent ceacc10 commit 6ae631d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ class BlockEditorProvider extends Component {
}

render() {
const { children } = this.props;
const { isReady, children } = this.props;

return children;
return isReady && children;
}
}

Expand Down
53 changes: 25 additions & 28 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,12 @@ const fetchLinkSuggestions = async ( search ) => {
};

class EditorProvider extends Component {
constructor( props ) {
constructor() {
super( ...arguments );

this.getBlockEditorSettings = memize( this.getBlockEditorSettings, {
maxSize: 1,
} );

// Assume that we don't need to initialize in the case of an error recovery.
if ( props.recovery ) {
return;
}

props.updatePostLock( props.settings.postLock );
props.setupEditor( props.post, props.initialEdits, props.settings.template );

if ( props.settings.autosave ) {
props.createWarningNotice(
__( 'There is an autosave of this post that is more recent than the version below.' ),
{
id: 'autosave-exists',
actions: [
{
label: __( 'View the autosave' ),
url: props.settings.autosave.editLink,
},
],
}
);
}
}

getBlockEditorSettings( settings, meta, onMetaChange, reusableBlocks, hasUploadPermissions ) {
Expand Down Expand Up @@ -106,6 +83,29 @@ class EditorProvider extends Component {
}

componentDidMount() {
// Assume that we don't need to initialize in the case of an error recovery.
if ( this.props.recovery ) {
return;
}

this.props.updatePostLock( this.props.settings.postLock );
this.props.setupEditor( this.props.post, this.props.initialEdits, this.props.settings.template );

if ( this.props.settings.autosave ) {
this.props.createWarningNotice(
__( 'There is an autosave of this post that is more recent than the version below.' ),
{
id: 'autosave-exists',
actions: [
{
label: __( 'View the autosave' ),
url: this.props.settings.autosave.editLink,
},
],
}
);
}

this.props.updateEditorSettings( this.props.settings );

if ( ! this.props.settings.styles ) {
Expand Down Expand Up @@ -143,10 +143,6 @@ class EditorProvider extends Component {
hasUploadPermissions,
} = this.props;

if ( ! isReady ) {
return null;
}

const editorSettings = this.getBlockEditorSettings(
settings, meta, onMetaChange, reusableBlocks, hasUploadPermissions
);
Expand All @@ -158,6 +154,7 @@ class EditorProvider extends Component {
onChange={ resetEditorBlocks }
settings={ editorSettings }
useSubRegistry={ false }
isReady={ isReady }
>
{ children }
<ReusableBlocksButtons />
Expand Down

0 comments on commit 6ae631d

Please sign in to comment.