Skip to content

Commit

Permalink
List View: Fix warning error when the gallery block has the same imag…
Browse files Browse the repository at this point in the history
…e URLs (#53809)

* List View: Fix warning error when the gallery block has the same image URLs

* Use clientId instead of index
  • Loading branch information
t-hamano authored Aug 21, 2023
1 parent 0a0bc06 commit 92c9401
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function ListViewBlockSelectButton(
{ images.map( ( image, index ) => (
<span
className="block-editor-list-view-block-select-button__image"
key={ `img-${ image.url }` }
key={ image.clientId }
style={ {
backgroundImage: `url(${ image.url })`,
zIndex: images.length - index, // Ensure the first image is on top, and subsequent images are behind.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import { store as blockEditorStore } from '../../store';
// Maximum number of images to display in a list view row.
const MAX_IMAGES = 3;

function getImageUrl( block ) {
function getImage( block ) {
if ( block.name !== 'core/image' ) {
return;
}

if ( block.attributes?.url ) {
return { url: block.attributes.url, alt: block.attributes.alt };
return {
url: block.attributes.url,
alt: block.attributes.alt,
clientId: block.clientId,
};
}
}

Expand All @@ -30,7 +34,7 @@ function getImagesFromGallery( block ) {
const images = [];

for ( const innerBlock of block.innerBlocks ) {
const img = getImageUrl( innerBlock );
const img = getImage( innerBlock );
if ( img ) {
images.push( img );
}
Expand All @@ -43,7 +47,7 @@ function getImagesFromGallery( block ) {
}

function getImagesFromBlock( block, isExpanded ) {
const img = getImageUrl( block );
const img = getImage( block );
if ( img ) {
return [ img ];
}
Expand Down

1 comment on commit 92c9401

@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 92c9401.
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/5925981126
📝 Reported issues:

Please sign in to comment.