diff --git a/packages/block-library/src/gallery/test/use-get-media.native.js b/packages/block-library/src/gallery/test/use-get-media.native.js new file mode 100644 index 0000000000000..67c7a8d0b5df2 --- /dev/null +++ b/packages/block-library/src/gallery/test/use-get-media.native.js @@ -0,0 +1,24 @@ +/** + * External dependencies + */ +import { render } from 'test/helpers'; + +/** + * Internal dependencies + */ +import useGetMedia from '../use-get-media'; + +describe( 'useGetMedia', () => { + // TODO: Explore why a Gallery block would ever be without inner blocks. + // This test and the associated default function parameter might be unnecessary. + it( 'should not error when receiving zero images', () => { + // Arrange + const TestSubject = () => { + useGetMedia( undefined ); + return null; + }; + + // Assert + expect( () => render( ) ).not.toThrow(); + } ); +} ); diff --git a/packages/block-library/src/gallery/use-get-media.native.js b/packages/block-library/src/gallery/use-get-media.native.js index b03defbdb49d5..6adb9d0c63ffd 100644 --- a/packages/block-library/src/gallery/use-get-media.native.js +++ b/packages/block-library/src/gallery/use-get-media.native.js @@ -14,7 +14,7 @@ const EMPTY_IMAGE_MEDIA = []; * * @return {Array} An array of media info options for each gallery image. */ -export default function useGetMedia( innerBlockImages ) { +export default function useGetMedia( innerBlockImages = [] ) { return useSelect( ( select ) => { const imagesUploading = innerBlockImages.some( diff --git a/packages/react-native-editor/CHANGELOG.md b/packages/react-native-editor/CHANGELOG.md index e81537a8c0609..e425af19ec089 100644 --- a/packages/react-native-editor/CHANGELOG.md +++ b/packages/react-native-editor/CHANGELOG.md @@ -10,7 +10,8 @@ For each user feature we should also add a importance categorization label to i --> ## Unreleased -- [*] Support POST requests [#49371] +- [*] Support POST requests [#49371] +- [*] Avoid empty Gallery block error [#49557] ## 1.92.0 * No User facing changes *