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
  • Loading branch information
Mamaduka committed Dec 25, 2024
1 parent 227fcd8 commit 378b0c0
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

0 comments on commit 378b0c0

Please sign in to comment.