Skip to content

Commit

Permalink
Image: Don't create an external image 'blob' when a user can't upload…
Browse files Browse the repository at this point in the history
… files (#49300)
  • Loading branch information
Mamaduka authored Mar 23, 2023
1 parent c29cdc7 commit 4674c47
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,18 @@ export default function Image( {
( { slug } ) => image?.media_details?.sizes?.[ slug ]?.source_url
)
.map( ( { name, slug } ) => ( { value: slug, label: name } ) );
const canUploadMedia = !! mediaUpload;

// If an image is externally hosted, try to fetch the image data. This may
// fail if the image host doesn't allow CORS with the domain. If it works,
// we can enable a button in the toolbar to upload the image.
useEffect( () => {
if ( ! isExternalImage( id, url ) || ! isSelected || externalBlob ) {
if (
! isExternalImage( id, url ) ||
! isSelected ||
! canUploadMedia ||
externalBlob
) {
return;
}

Expand All @@ -185,7 +191,7 @@ export default function Image( {
.then( ( blob ) => setExternalBlob( blob ) )
// Do nothing, cannot upload.
.catch( () => {} );
}, [ id, url, isSelected, externalBlob ] );
}, [ id, url, isSelected, externalBlob, canUploadMedia ] );

// We need to show the caption when changes come from
// history navigation(undo/redo).
Expand Down

1 comment on commit 4674c47

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 4674c47.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4500303580
📝 Reported issues:

Please sign in to comment.