Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#72 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, php, wordpress
Área
frontend

Línea de trabajo

Empieza en inc/namespace.php en render_block_query() y compara los atributos que establece con la salida del propio wrapper de consulta de core. Reproduce con un Query Loop usando enhancedPagination y abre la consola, luego confirma que el wrapper conserva el namespace de data-wp-interactive que core ya estableció mientras data-wp-router-region sigue aplicándose. Hecho significa que no hay TypeErrors de prefetch/navigate y que el filtro, la búsqueda y la paginación mejorada siguen funcionando.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
PHP
Estrellas
124
Forks
33
Merge medio
20 h 58 min
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de humanmade/query-filter

Todos los issues de humanmade/query-filter

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.