Make WordPress Core

Opened 10 months ago

Closed 9 months ago

Last modified 9 months ago

#59559 closed defect (bug) (reported-upstream)

The Image block lightbox introduces an undocumented exception on how the render_block_{$this->name} filter is supposed to work

Reported by: afercia's profile afercia Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.4
Component: Editor Keywords: gutenberg-merge
Focuses: docs Cc:

Description

When an Image block is set to open the image in the lighbox, the actual lightbox markup is added to the block via the render_block_{$this->name} filter.

The filter runs at priority 15. See in the related code in the github repo:

I see two issues with this implementation:

1
The implementation actually introduces an exception on how the render_block_{$this->name} is supposed to work. Or, better, on the actual content the filter will receive.

Using the filter like one would normally do with the default priority will only filter the original block content, regardless of whether lightbox is enabled or not:

add_filter( 'render_block_core/image', 'my_custom_html' )

As a developer, I would expect this filter to always receive the _actual_ block content:

  • When lightbox ie disabled: I'd expect the normal Image block content.
  • When lightbox ie enabled: I'd expect the Image block content including the lightbox markup.

Instead, to be able to get the lightbox markup, I'd need to change priority. This will return the actual markup including the lightbox one:

add_filter( 'render_block_core/image', 'my_custom_html', 15 )

As said, this is an undocumented exception at the very lest:

In any case, I'm not sure altering the expected behavior of a filter in this way is ideal.

2
The way the lightbox markup is added to the block markup is, in my opinion, inherently fragile. The code assumes to find a figure element. If for any reason plugins are replacing the figure element by using the filter with normal priority, the lightbox will simply not work.

Marking this ticket for 6.4 consideration because at least the documentation part should be addressed soon.

Change History (4)

This ticket was mentioned in Slack in #core by oglekler. View the logs.


10 months ago

#2 @oglekler
10 months ago

  • Keywords gutenberg-merge added

This looks like it should be addressed on the Gutenberg side, so, I am marking this as gutenberg-merge.

#3 @hellofromTonya
10 months ago

Indeed. The affected code is the packages that Gutenberg maintains. The issue needs to be reported upstream in Gutenberg. Once resolved, the fixes are introduced into Core through package version updates in Core's package.json file. Package updates are being tracked in #59411 for 6.4.

@afercia can you please report this upstream by creating an issue in Gutenberg? Then copy the issue here to wire them together.

Once the issue is opened, it'll be tracked in Gutenberg. Thus, this Trac ticket can be closed as reported-upstream.

#4 @afercia
9 months ago

  • Milestone 6.4 deleted
  • Resolution set to reported-upstream
  • Status changed from new to closed

@hellofromTonya Reported upstream at https://github.com/WordPress/gutenberg/issues/55407

Last edited 9 months ago by afercia (previous) (diff)
Note: See TracTickets for help on using tickets.