Skip to content

Tiled Gallery: editor crashes converting Gallery → Tiled Gallery after a Tiled→Gallery round-trip ("Cannot read properties of undefined (reading 'filter')") #49606

Description

@davemac

Impact

Crashes the whole block editor — the full-screen "The editor has encountered an unexpected error" boundary. Reproducible 100% of the time on the round-trip described below. In the non-crashing case the same code path silently drops the gallery's images.

Steps to reproduce

  1. New post. Add a Tiled Gallery block with a few images.
  2. Select it → block switcher → Transform to → Gallery. (works fine)
  3. Select the resulting Gallery block and open the block-type switcher (or Transform to → Tiled Gallery).
  4. The editor crashes immediately — it throws as soon as the switcher renders the Tiled Gallery transform preview.

Expected

The Gallery converts back to a Tiled Gallery, preserving its images.

Actual

Full-screen "The editor has encountered an unexpected error".

Console / stack

TypeError: Cannot read properties of undefined (reading 'filter')
    at f         (jetpack/_inc/blocks/editor.js)   // image filter helper
    at transform (jetpack/_inc/blocks/editor.js)   // tiled-gallery "from: core/gallery"
    at switchToBlockType → block-switcher preview → React render

Root cause

The Tiled Gallery from: ['core/gallery', 'jetpack/slideshow'] transform (extensions/blocks/tiled-gallery/transforms.js) does roughly:

transform: ( { images } ) => {
    const filtered = images.filter( ( { id, url } ) => id && url );
    ...
}

After Tiled → Gallery, the intermediate v2 core/gallery stores its images in nested core/image inner blocks and leaves the top-level images attribute undefined, so images.filter() throws.

The same root assumption means the transform silently produces an empty Tiled Gallery for any modern (v2) gallery whose top-level images array is empty.

Suggested fix

Default images, and recover it from innerBlocks (the transform already receives them) so the images survive the round-trip:

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.link, alt: attributes.alt,
            } ) );
    }
    const filtered = images.filter( ( { id, url } ) => id && url );
    ...
}

Environment

  • Jetpack 15.9
  • WordPress 7.0
  • Reproduces with only Jetpack active (no other plugins needed)
  • Workaround: reload the post between the Tiled→Gallery and Gallery→Tiled steps. A freshly parsed gallery has images: [] rather than undefined, so it no longer crashes (though images are still dropped).

Metadata

Metadata

Assignees

Labels

BugWhen a feature is broken and / or not performing as intended[Block] Tiled Gallery[Feature] Tiled GalleryA different way to display image galleries on your site, in different organizations and shapes.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions