`render_block_query` overwrites the `core/query` namespace, breaking context for enhanced pagination
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
-
Activate query-filter with no other query-related customisations.
-
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 --> -
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
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di humanmade/query-filter
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
humanmade/query-filter#67 ·
-
Selected Filters BlockAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
humanmade/query-filter#66 ·
-
Reset blockAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
humanmade/query-filter#65 ·
-
Order blockAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
humanmade/query-filter#64 ·
-
bug
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
humanmade/query-filter#62 ·
Tutte le issue di humanmade/query-filter
Issue simili
-
Impact: Medium Level: Easy Type: Bug Value: Users
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
vigetlabs/wordpress-site-starter#315 ·
I maintainer di solito rispondono entro 15 giorni
-
PHP 8.6: bundled guzzlehttp/promises loads class `Is` → "Using "is" as a class name is deprecated"Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
google/site-kit-wp#14004 ·
I maintainer di solito rispondono entro 2 giorni
-
Awaiting Triage bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
jwage/phpamqplib-messenger#159 ·