Make WordPress Core


Ignore:
Timestamp:
10/24/2023 09:02:02 AM (16 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.
Merges [56994] to the 6.4 branch.
Fixes #59681.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/6.4/src/wp-includes/block-supports/layout.php

    r56709 r56995  
    631631    $class_names        = array();
    632632    $layout_definitions = wp_get_layout_definitions();
    633     $container_class    = wp_unique_id( 'wp-container-' );
     633
     634    /*
     635     * Uses an incremental ID that is independent per prefix to make sure that
     636     * rendering different numbers of blocks doesn't affect the IDs of other
     637     * blocks. Makes the CSS class names stable across paginations
     638     * for features like the enhanced pagination of the Query block.
     639     */
     640    $container_class = wp_unique_prefixed_id(
     641        'wp-container-' . sanitize_title( $block['blockName'] ) . '-layout-'
     642    );
    634643
    635644    // Set the correct layout type for blocks using legacy content width.
Note: See TracChangeset for help on using the changeset viewer.