Skip to content

Commit

Permalink
Block Library: Don't fetch media details if the block doesn't use a f…
Browse files Browse the repository at this point in the history
…eatured image (#68299)


Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: youknowriad <[email protected]>
  • Loading branch information
3 people authored Dec 25, 2024
1 parent 63f211b commit 887243c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 12 additions & 5 deletions packages/block-library/src/cover/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,18 @@ function CoverEdit( {

const { __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );
const media = useSelect(
( select ) =>
featuredImage &&
select( coreStore ).getMedia( featuredImage, { context: 'view' } ),
[ featuredImage ]
const { media } = useSelect(
( select ) => {
return {
media:
featuredImage && useFeaturedImage
? select( coreStore ).getMedia( featuredImage, {
context: 'view',
} )
: undefined,
};
},
[ featuredImage, useFeaturedImage ]
);
const mediaUrl =
media?.media_details?.sizes?.[ sizeSlug ]?.source_url ??
Expand Down
17 changes: 12 additions & 5 deletions packages/block-library/src/media-text/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,18 @@ function MediaTextEdit( {
postId
);

const featuredImageMedia = useSelect(
( select ) =>
featuredImage &&
select( coreStore ).getMedia( featuredImage, { context: 'view' } ),
[ featuredImage ]
const { featuredImageMedia } = useSelect(
( select ) => {
return {
featuredImageMedia:
featuredImage && useFeaturedImage
? select( coreStore ).getMedia( featuredImage, {
context: 'view',
} )
: undefined,
};
},
[ featuredImage, useFeaturedImage ]
);

const featuredImageURL = useFeaturedImage
Expand Down

1 comment on commit 887243c

@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 887243c.
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/12494457251
📝 Reported issues:

Please sign in to comment.