Skip to content

Commit

Permalink
Blocks: Try to fix rerender issue for custom class name
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Nov 16, 2017
1 parent 74b8cfa commit 3d54d33
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
8 changes: 3 additions & 5 deletions blocks/block-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ function BlockEdit( props ) {
// `edit` and `save` are functions or components describing the markup
// with which a block is displayed. If `blockType` is valid, assign
// them preferencially as the render value for the block.
let Edit;
if ( blockType ) {
Edit = blockType.edit || blockType.save;
}
const Edit = blockType.edit || blockType.save;
Edit.displayName = 'Edit';

return applyFilters( 'BlockEdit', <Edit { ...editProps } />, props );
return applyFilters( 'BlockEdit', <Edit key="edit" { ...editProps } />, props );
}

export default BlockEdit;
9 changes: 5 additions & 4 deletions blocks/hooks/anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { assign } from 'lodash';
/**
* WordPress dependencies
*/
import { concatChildren } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -54,9 +55,9 @@ export function addAttribute( settings ) {
*/
export function addInspectorControl( element, props ) {
if ( hasBlockSupport( props.name, 'anchor' ) && props.focus ) {
element = [
element = concatChildren(
element,
<InspectorControls key="inspector-anchor">
<InspectorControls>
<InspectorControls.TextControl
label={ __( 'HTML Anchor' ) }
help={ __( 'Anchors lets you link directly to a section on a page.' ) }
Expand All @@ -68,8 +69,8 @@ export function addInspectorControl( element, props ) {
anchor: nextValue,
} );
} } />
</InspectorControls>,
];
</InspectorControls>
);
}

return element;
Expand Down
9 changes: 5 additions & 4 deletions blocks/hooks/custom-class-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { concatChildren } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -45,9 +46,9 @@ export function addAttribute( settings ) {
*/
export function addInspectorControl( element, props ) {
if ( hasBlockSupport( props.name, 'customClassName', true ) && props.focus ) {
element = [
element = concatChildren(
element,
<InspectorControls key="inspector-custom-classname">
<InspectorControls force>
<InspectorControls.TextControl
label={ __( 'Additional CSS Class' ) }
value={ props.attributes.className || '' }
Expand All @@ -57,8 +58,8 @@ export function addInspectorControl( element, props ) {
} );
} }
/>
</InspectorControls>,
];
</InspectorControls>
);
}

return element;
Expand Down
4 changes: 2 additions & 2 deletions blocks/inspector-controls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import TextControl from './text-control';
import TextareaControl from './textarea-control';
import ToggleControl from './toggle-control';

export default function InspectorControls( { children } ) {
export default function InspectorControls( { force = false, children } ) {
return (
<Fill name="Inspector.Controls">
<Fill name="Inspector.Controls" force={ force }>
{ children }
</Fill>
);
Expand Down
4 changes: 2 additions & 2 deletions components/slot-fill/fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class Fill extends Component {
}

componentWillReceiveProps( nextProps ) {
const { name } = nextProps;
const { name, force } = nextProps;
const {
unregisterFill = noop,
registerFill = noop,
} = this.context;

if ( this.props.name !== name ) {
if ( this.props.name !== name || force ) {
unregisterFill( this.props.name, this );
registerFill( name, this );
}
Expand Down

0 comments on commit 3d54d33

Please sign in to comment.