Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/fix-tiled-gallery-crash
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Tiled Gallery: prevent editor crash when transforming a core gallery block.
14 changes: 12 additions & 2 deletions projects/plugins/jetpack/extensions/blocks/tiled-gallery/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const exampleAttributes = {
* @param {Array} images - Array of image objects
* @return {Array} Array of image objects which have id and url
*/
function getValidImages( images ) {
function getValidImages( images = [] ) {
return images.filter( ( { id, url } ) => id && url );
}
registerJetpackBlockFromMetadata( metadata, {
Expand Down Expand Up @@ -98,7 +98,17 @@ registerJetpackBlockFromMetadata( metadata, {
{
type: 'block',
blocks: [ 'core/gallery', 'jetpack/slideshow' ],
transform: ( { images } ) => {
transform: ( { images = [] }, innerBlocks ) => {
if ( ! images.length && innerBlocks?.length ) {
images = innerBlocks
.filter( b => b.name === 'core/image' && b.attributes?.url )
.map( ( { attributes } ) => ( {
id: attributes.id,
url: attributes.url,
link: attributes.href,
alt: attributes.alt,
} ) );
}
const validImages = getValidImages( images );
if ( validImages.length > 0 ) {
return createBlock( metadata.name, {
Expand Down
Loading