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
8 changes: 7 additions & 1 deletion inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,14 @@ function render_block_query( $block_content, $block ) {
$block_content = new WP_HTML_Tag_Processor( $block_content );
$block_content->next_tag();

// With enhanced pagination on, core sets `data-wp-interactive="core/query"`
// here and its pagination directives read context from that namespace.
// Replacing it breaks them, so only set ours when core set none.
if ( null === $block_content->get_attribute( 'data-wp-interactive' ) ) {
$block_content->set_attribute( 'data-wp-interactive', 'query-filter' );
}

// Always allow region updates on interactivity, use standard core region naming.
$block_content->set_attribute( 'data-wp-interactive', 'query-filter' );
$block_content->set_attribute( 'data-wp-router-region', 'query-' . ( $block['attrs']['queryId'] ?? 0 ) );

return (string) $block_content;
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Seeding is idempotent, guarded by the `query_filter_e2e_seeded` option.
| `/taxonomy-hierarchy-collapsed/` | 8 | Taxonomy filter (checkboxes, `hierarchy: collapsed`) over `qf_topic` |
| `/taxonomy-hierarchy-select/` | 9 | Taxonomy filter (select, `hierarchy: nested`) over `qf_topic` |
| `/term-counts/` | 10 | Category and `qf_topic` filters (checkboxes, `hideEmpty` and `showCount`) and a core search block |
| `/enhanced-pagination/` | 15 | Taxonomy filter (select) and enhanced pagination, one post to a page |

Posts: `Alpha One` and `Alpha Two` in the `alpha` category, `Beta One` in
`beta`, and `Unfiled Post` in neither — so an active filter is always
Expand Down
54 changes: 54 additions & 0 deletions tests/e2e/enhanced-pagination.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const { test, expect, POSTS } = require( './fixtures' );

test.describe( 'Enhanced pagination', () => {
test( 'the core/query namespace on the loop wrapper is preserved', async ( {
page,
loop,
} ) => {
const errors = [];
page.on( 'pageerror', ( error ) => errors.push( error.message ) );

await page.goto( '/enhanced-pagination/' );
await loop.expectTitles( [ 'Alpha One' ] );

// With enhanced pagination on, core owns the wrapper namespace. The
// plugin only adds the router region.
const wrapper = page.locator( '.wp-block-query' );
await expect( wrapper ).toHaveAttribute(
'data-wp-interactive',
'core/query'
);
await expect( wrapper ).toHaveAttribute(
'data-wp-router-region',
'query-15'
);

await page.locator( '.wp-block-query-pagination-next' ).click();
await loop.expectTitles( [ 'Alpha Two' ] );
expect( page.url() ).toContain( 'query-15-page=2' );

await loop.taxonomySelect().selectOption( { label: 'Beta' } );
await page.waitForURL( /query-15-category=beta/ );
await loop.expectTitles( POSTS.beta );

expect( errors ).toEqual( [] );
} );

test( 'the plugin namespace is applied when core sets none', async ( {
page,
loop,
} ) => {
await page.goto( '/search-pagination/' );
await loop.expectTitles( POSTS.alpha );

const wrapper = page.locator( '.wp-block-query' );
await expect( wrapper ).toHaveAttribute(
'data-wp-interactive',
'query-filter'
);
await expect( wrapper ).toHaveAttribute(
'data-wp-router-region',
'query-5'
);
} );
} );
22 changes: 22 additions & 0 deletions tests/seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,28 @@ function query_loop_markup( int $query_id, string $filters ) : string {
HTML,
] );

// Page 15: enhanced pagination, one post to a page, with a taxonomy filter.
// Core puts the loop wrapper in the `core/query` namespace and the plugin
// must leave it there to avoid breaking core pagination directives (#72).
seed_post( 'Enhanced Pagination', 'page', [
'post_name' => 'enhanced-pagination',
'post_content' => <<<HTML
<!-- wp:query {"queryId":15,"enhancedPagination":true,"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","order":"asc","orderBy":"title","inherit":false}} -->
<div class="wp-block-query">
<!-- wp:query-filter/taxonomy {"taxonomy":"category"} /-->
<!-- wp:post-template -->
<!-- wp:post-title /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->
</div>
<!-- /wp:query -->
HTML,
] );

update_option( 'query_filter_e2e_seeded', 1 );

echo "Seeded query filter e2e fixtures.\n";
Loading