Skip to content

Commit

Permalink
Gallery block: fix bug with stalled upload when image size too large (#…
Browse files Browse the repository at this point in the history
…34371)

* Flag isTemp to false on upload error to prevent the isTemp effect running again and showing stalled upload

Co-authored-by: Glen Davies <glen.davies@a8c.com>
  • Loading branch information
glendaviesnz and Glen Davies authored Sep 2, 2021
1 parent da052f0 commit 32a370f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
17 changes: 16 additions & 1 deletion packages/block-library/src/gallery/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,24 @@ figure.wp-block-gallery {
flex: 0 0 100%;
}

.components-form-file-upload {
> .components-form-file-upload {
flex-basis: 100%;
}

.wp-block-image {
.components-notice.is-error {
display: block;
}
.components-notice__content {
margin: 4px 0;
}
.components-notice__dismiss {
position: absolute;
top: 0;
right: 5px;
}
}

// @todo: this deserves a refactor, by being moved to the toolbar.
.block-editor-media-placeholder.is-appender {
.components-placeholder__label {
Expand Down
13 changes: 4 additions & 9 deletions packages/block-library/src/gallery/use-get-media.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@ export default function useGetMedia( innerBlockImages ) {

const imageMedia = useSelect(
( select ) => {
if (
! innerBlockImages?.length ||
innerBlockImages.some(
( imageBlock ) => ! imageBlock.attributes.id
)
) {
if ( ! innerBlockImages?.length ) {
return currentImageMedia;
}

const imageIds = innerBlockImages.map(
( imageBlock ) => imageBlock.attributes.id
);
const imageIds = innerBlockImages
.map( ( imageBlock ) => imageBlock.attributes.id )
.filter( ( id ) => id !== undefined );

if ( imageIds.length === 0 ) {
return currentImageMedia;
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export function ImageEdit( {
} );
}

const isTemp = isTemporaryImage( id, url );
let isTemp = isTemporaryImage( id, url );

// Upload a temporary image on mount.
useEffect( () => {
Expand All @@ -264,6 +264,7 @@ export function ImageEdit( {
},
allowedTypes: ALLOWED_MEDIA_TYPES,
onError: ( message ) => {
isTemp = false;
noticeOperations.createErrorNotice( message );
setAttributes( {
src: undefined,
Expand Down

0 comments on commit 32a370f

Please sign in to comment.