Make WordPress Core


Ignore:
Timestamp:
10/24/2023 08:49:38 AM (15 months ago)
Author:
Bernhard Reiter
Message:

Blocks: Fix layout support to be compatible with enhanced pagination.

Make layout support compatible with enhanced pagination by ensuring that generated class names are stable across pagination, even when the number of rendered posts is different.

With the previous implementation of enhanced pagination, the CSS corresponding to each block was not detected. Therefore, for enhanced pagination to work correctly, the CSS of the blocks present in the Post Template must be stable on all pages.

The number of posts rendered by the Query block is always the same, except in the last page, where it can be only a fraction. If any of the blocks rendered by the Post Template used the wp_unique_id function, the ID (which is incremental) would have been different than in the previous pages and the class names would have varied.

This is remediated by this changeset by replacing the usage of wp_unique_id in the layout support (which is used by the Query block) with an implementation that uses IDs that are incremental only for that block. That way, the generated class names are never affected by the number of times wp_unique_id runs.

Props luisherranz, andrewserong, isabel_brison, costdev, mukesh27, cbravobernal, hellofromTonya, jorbin.
Fixes #59681.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/render.php

    r56547 r56994  
    219219        $html = do_blocks( self::strip_r( file_get_contents( $html_path ) ) );
    220220        // If blocks opt into Gutenberg's layout implementation
    221         // the container will receive an added classname of `wp_unique_id( 'wp-container-' )`
     221        // the container will receive an additional, unique classname based on "wp-container-[blockname]-layout"
    222222        // so we need to normalize the random id.
    223         $normalized_html = preg_replace( '/wp-container-\d+/', 'wp-container-1', $html );
     223        $normalized_html = preg_replace( '/wp-container-[a-z-]+\d+/', 'wp-container-1', $html );
    224224
    225225        // The gallery block uses a unique class name of `wp_unique_id( 'wp-block-gallery-' )`
Note: See TracChangeset for help on using the changeset viewer.