diff --git a/inc/namespace.php b/inc/namespace.php index 55f8917..ec9ffa8 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -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; diff --git a/tests/e2e/README.md b/tests/e2e/README.md index a12ee11..c057f87 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -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 diff --git a/tests/e2e/enhanced-pagination.spec.js b/tests/e2e/enhanced-pagination.spec.js new file mode 100644 index 0000000..8f8147b --- /dev/null +++ b/tests/e2e/enhanced-pagination.spec.js @@ -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' + ); + } ); +} ); diff --git a/tests/seed.php b/tests/seed.php index f70ec99..8c99c82 100644 --- a/tests/seed.php +++ b/tests/seed.php @@ -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' => << +