Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`render_block_query` overwrites the `core/query` namespace, breaking context for enhanced pagination

Aperta Adatta ai principianti
#72 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, php, wordpress
Ambito
frontend

Direzione di ricerca

Inizia in inc/namespace.php a render_block_query() e confronta gli attributi che imposta con l'output del wrapper di query di core stesso. Riproduci con un Query Loop che usa enhancedPagination e apri la console, poi conferma che il wrapper mantiene il namespace data-wp-interactive che core ha già impostato mentre data-wp-router-region è ancora applicato. Fatto significa nessun TypeError di prefetch/navigate e filtro, ricerca e paginazione avanzata funzionano ancora.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Plugin version: humanmade/query-filter v0.5.0
Tested on: WordPress 7.1.3, PHP 8.4
Relevant code: inc/namespace.php, render_block_query()

Summary

render_block_query() sets data-wp-interactive="query-filter" on every core/query wrapper. When the query has enhancedPagination: true, core has already marked that same element with data-wp-interactive="core/query" and data-wp-context="{}". Overwriting the namespace shifts the unprefixed data-wp-context under query-filter, so no element provides a core/query context any more and Core's pagination links that still carry core/query:: directives now get undefined back when they look for context.

Console on page load, whenever a previous/next pagination link renders:

view.min.js?ver=7a4ec5bfb61a7137cf4b:1 Uncaught (in promise) TypeError: Cannot destructure property 'url' of 'c(...)' as it is undefined.
    at prefetch (view.min.js?ver=7a4ec5bfb61a7137cf4b:1:795)

Steps to reproduce

  1. Activate query-filter with no other query-related customisations.

  2. Add a Query Loop with enhanced pagination and more than one page of results:

    <!-- wp:query {"enhancedPagination":true,"queryId":1,"query":{"perPage":1,"postType":"post","inherit":false}} -->
    <div class="wp-block-query">
    <!-- 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 -->
    
  3. Load the page on the front end with the console open.

Expected

No console error. The core/query data-wp-watch prefetch callback reads { url } from its own namespace's context.

Actual

The error above. Rendered wrapper:

<div data-wp-context="{}" data-wp-interactive="query-filter" data-wp-key="1" data-wp-router-region="query-1" class="wp-block-query ...">
  ...
  <a data-wp-key="query-pagination-next"
     data-wp-on--click="core/query::actions.navigate"
     data-wp-on--mouseenter="core/query::actions.prefetch"
     data-wp-watch="core/query::callbacks.prefetch"
     href="/?query-1-page=2" class="wp-block-query-pagination-next">

Core's callbacks.prefetch (wp-includes/js/dist/script-modules/block-library/query/view.js):

*prefetch() {
    const { url } = getContext(); // undefined: no `core/query` context provider
    const { ref } = getElement();
    ...
}

actions.navigate also assigns ctx.url = ref.href after routing, so clicking Next/Previous throws a second TypeError once navigation completes. Navigation itself still works, which is why this reads as benign.

Cause

render_block_query():

$block_content->set_attribute( 'data-wp-interactive', 'query-filter' );
$block_content->set_attribute( 'data-wp-router-region', 'query-' . ( $block['attrs']['queryId'] ?? 0 ) );

data-wp-context without a namespace prefix is scoped to the element's data-wp-interactive namespace. Replacing core/query with query-filter on the wrapper moves core's empty context into the wrong namespace.

Nothing in query-filter's view scripts depends on the wrapper being in the query-filter namespace. The query-filter store's toggleAllTerms, toggleChildren and search actions all read context from the filter/search blocks' own elements, which set data-wp-interactive="query-filter" and their own data-wp-context themselves.

Suggested fix

Only set data-wp-interactive on the wrapper when core has not already set one, and keep setting data-wp-router-region unconditionally:

if ( null === $block_content->get_attribute( 'data-wp-interactive' ) ) {
    $block_content->set_attribute( 'data-wp-interactive', 'query-filter' );
}
AI use disclaimer

I encountered this issue on a project and manually traced it to this plugin, but I have not specifically validated in a clean environment outside of my current project. The description and test steps above were claude-generated following our initial identification and tracing of the error to something about this plugin. Filter, search and enhanced pagination navigation should be re-checked after the change, since all three share the same router region.

Lingua principale
PHP
Stelle
124
Fork
33
Merge medio
20h 58m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di humanmade/query-filter

Tutte le issue di humanmade/query-filter

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.