diff --git a/packages/block-library/src/gallery/edit.js b/packages/block-library/src/gallery/edit.js index 22ca116c92d13d..e0a25548f00f2e 100644 --- a/packages/block-library/src/gallery/edit.js +++ b/packages/block-library/src/gallery/edit.js @@ -97,7 +97,7 @@ function GalleryEdit( props ) { shortCodeTransforms, sizeSlug, } = attributes; - useMobileWarning(); + const { __unstableMarkNextChangeAsNotPersistent, replaceInnerBlocks, @@ -139,6 +139,8 @@ function GalleryEdit( props ) { const newImages = useGetNewImages( images, imageData ); + useMobileWarning( newImages ); + useEffect( () => { newImages?.forEach( ( newImage ) => { updateBlockAttributes( newImage.clientId, { diff --git a/packages/block-library/src/gallery/use-mobile-warning.js b/packages/block-library/src/gallery/use-mobile-warning.js index cefaa26b9f3a2e..6567d8f73349b7 100644 --- a/packages/block-library/src/gallery/use-mobile-warning.js +++ b/packages/block-library/src/gallery/use-mobile-warning.js @@ -6,7 +6,7 @@ import { useDispatch, useSelect } from '@wordpress/data'; import { store as interfaceStore } from '@wordpress/interface'; import { store as noticesStore } from '@wordpress/notices'; -export default function useMobileWarning() { +export default function useMobileWarning( newImages ) { const { createWarningNotice } = useDispatch( noticesStore ); const { toggleFeature } = useDispatch( interfaceStore ); const isMobileWarningActive = useSelect( ( select ) => { @@ -14,7 +14,7 @@ export default function useMobileWarning() { return isFeatureActive( 'core/edit-post', 'mobileGalleryWarning' ); }, [] ); - if ( ! isMobileWarningActive ) { + if ( ! isMobileWarningActive || ! newImages ) { return; }