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

Add an explicit error message if an image block fails to load the image #40982

Merged
merged 2 commits into from
May 12, 2022
Merged
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useEffect, useRef, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { image as icon } from '@wordpress/icons';

/**
Expand Down Expand Up @@ -156,6 +156,16 @@ export function ImageEdit( {
has been deleted.
*/
function onImageError( isReplaced = false ) {
noticeOperations.removeAllNotices();
noticeOperations.createErrorNotice(
sprintf(
/* translators: %s url or missing image */
__(
'There was an error loading the image for this block. The image was: %s'
),
url
)
);
// If the image block was not replaced with an embed,
// clear the attributes and trigger the placeholder.
if ( ! isReplaced ) {
Expand Down