Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid empty Gallery block error #49557

Merged
merged 3 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/block-library/src/gallery/test/use-get-media.native.js
Original file line number Diff line number Diff line change
@@ -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( <TestSubject /> ) ).not.toThrow();
} );
} );
2 changes: 1 addition & 1 deletion packages/block-library/src/gallery/use-get-media.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down