Summary
When a core/search block is nested inside a core/query block with "inherit": true (the typical setup for a dedicated Search Results page — the block reads/filters the site's main query), clearing the search field does nothing: the displayed results/title never update, and the URL doesn't change.
Root cause
render_block_search() (inc/namespace.php) always names this field's query var query-s for the inherited case:
$query_var = empty( $instance->context['query']['inherit'] )
? sprintf( 'query-%d-s', $instance->context['queryId'] ?? 0 )
: 'query-s';
But the bundled client-side action (src/taxonomy/view.js's updateURL()) has a special case that only takes effect when the field's name is literally s:
const updateURL = async ( action, value, name ) => {
const url = new URL( action );
if ( value || name === 's' ) {
url.searchParams.set( name, value );
} else {
url.searchParams.delete( name );
}
const { actions } = await import( '@wordpress/interactivity-router' );
await actions.navigate( url.toString() );
};
Since the inherited case is actually named query-s, clearing the field (an empty value) always falls into the delete branch — deleting a query-s key that was never present in the URL to begin with (a page reached via a native ?s= link — e.g. any ordinary sitewide search box — has the real term in WordPress's own native s param, since that's what makes is_search()/routing resolve to the search results template at all). The resulting "new" URL is identical to the current one, so actions.navigate() effectively does nothing — no fetch, no update.
Reproduction
- Add a
core/search block inside a core/query block with query.inherit: true, on a real Search Results template (search.html).
- Land on the results page via a native
?s=term URL (e.g. a plain, non-block search form elsewhere on the site).
- Clear the search field via the wired input (or type a value then clear it again).
- Expected: results/title update to reflect the empty search. Actual: nothing changes — same term, same results, same URL.
Suggested fix
Either:
- Name the inherited-query field literally
s instead of query-s in render_block_search() (matches what updateURL()'s own special case already assumes), or
- Change
updateURL()'s special case to match whatever name the PHP side actually computes for the inherited query, rather than hardcoding 's'.
We worked around this on our end with a theme-side render_block_core/search filter that renames the field for the is_search() case specifically, but it'd be good to fix at the source so other consumers don't have to do the same.
Environment
humanmade/query-filter v0.3.2
- WordPress 7.0.2, PHP 8.4
Happy to open a PR if that's useful.
Disclosure
This issue was AI generated based on the findings in a long debugging session.
Summary
When a
core/searchblock is nested inside acore/queryblock with"inherit": true(the typical setup for a dedicated Search Results page — the block reads/filters the site's main query), clearing the search field does nothing: the displayed results/title never update, and the URL doesn't change.Root cause
render_block_search()(inc/namespace.php) always names this field's query varquery-sfor the inherited case:But the bundled client-side action (
src/taxonomy/view.js'supdateURL()) has a special case that only takes effect when the field's name is literallys:Since the inherited case is actually named
query-s, clearing the field (an emptyvalue) always falls into thedeletebranch — deleting aquery-skey that was never present in the URL to begin with (a page reached via a native?s=link — e.g. any ordinary sitewide search box — has the real term in WordPress's own nativesparam, since that's what makesis_search()/routing resolve to the search results template at all). The resulting "new" URL is identical to the current one, soactions.navigate()effectively does nothing — no fetch, no update.Reproduction
core/searchblock inside acore/queryblock withquery.inherit: true, on a real Search Results template (search.html).?s=termURL (e.g. a plain, non-block search form elsewhere on the site).Suggested fix
Either:
sinstead ofquery-sinrender_block_search()(matches whatupdateURL()'s own special case already assumes), orupdateURL()'s special case to match whatevernamethe PHP side actually computes for the inherited query, rather than hardcoding's'.We worked around this on our end with a theme-side
render_block_core/searchfilter that renames the field for theis_search()case specifically, but it'd be good to fix at the source so other consumers don't have to do the same.Environment
humanmade/query-filterv0.3.2Happy to open a PR if that's useful.
Disclosure
This issue was AI generated based on the findings in a long debugging session.