Skip to content

Commit

Permalink
Avoid unnecessary Post Formats re-renders (#38285)
Browse files Browse the repository at this point in the history
* Editor: Avoid Post Formats re-renders

* Add inline comment
  • Loading branch information
Mamaduka committed Jan 28, 2022
1 parent a31fe85 commit 1194689
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/editor/src/components/post-format/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { find, get, includes, union } from 'lodash';
import { find, includes } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -57,20 +57,19 @@ export default function PostFormat() {
return {
postFormat: _postFormat ?? 'standard',
suggestedFormat: getSuggestedPostFormat(),
// Ensure current format is always in the set.
// The current format may not be a format supported by the theme.
supportedFormats: union(
[ _postFormat ],
get( themeSupports, [ 'formats' ], [] )
),
supportedFormats: themeSupports.formats,
};
},
[]
);

const formats = POST_FORMATS.filter( ( format ) =>
includes( supportedFormats, format.id )
);
const formats = POST_FORMATS.filter( ( format ) => {
// Ensure current format is always in the set.
// The current format may not be a format supported by the theme.
return (
includes( supportedFormats, format.id ) || postFormat === format.id
);
} );
const suggestion = find(
formats,
( format ) => format.id === suggestedFormat
Expand Down

0 comments on commit 1194689

Please sign in to comment.