Skip to content

Commit

Permalink
Widget Importer: Avoid rendering when there's nothing to import
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Feb 24, 2023
1 parent 6acbb4b commit 4a8ef09
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions packages/block-library/src/template-part/edit/import-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ export function TemplatePartImportControls( { area, setAttributes } ) {
const [ isBusy, setIsBusy ] = useState( false );

const registry = useRegistry();
const sidebars = useSelect( ( select ) => {
return select( coreStore ).getSidebars( {
per_page: -1,
_fields: 'id,name,description,status,widgets',
} );
const { sidebars, hasResolved } = useSelect( ( select ) => {
const { getSidebars, hasFinishedResolution } = select( coreStore );

return {
sidebars: getSidebars( {
per_page: -1,
_fields: 'id,name,description,status,widgets',
} ),
hasResolved: hasFinishedResolution( 'getSidebars', [
{
per_page: -1,
_fields: 'id,name,description,status,widgets',
},
] ),
};
}, [] );
const { createErrorNotice } = useDispatch( noticesStore );

Expand Down Expand Up @@ -67,6 +77,12 @@ export function TemplatePartImportControls( { area, setAttributes } ) {
];
}, [ sidebars ] );

// Only bailout from rendering after data is loaded, and there is nothing to import,
// to avoid SlotFill re-positioning issue. See: https://github.com/WordPress/gutenberg/issues/15641.
if ( hasResolved && ! options.length ) {
return null;
}

async function createFromWidgets( event ) {
event.preventDefault();

Expand Down

0 comments on commit 4a8ef09

Please sign in to comment.