You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Search does nothing after a filter has been used #76
Entering text in a search field does nothing after a filter has been used (Invalid URL in updateURL(), regression from #74)
Description
On a page with a Search block and a Taxonomy Filter in the same Query Loop, searching works until a filter has been used. After a filter navigates, the next search does nothing, and the console shows:
TypeError: Failed to construct 'URL': Invalid URL
at updateURL (build/taxonomy/view.js)
Search first and filter second works fine.
Steps to reproduce
Add a Query Loop (own query, inherit: false) containing a Search block and a Taxonomy Filter (select).
Load the page and choose a term in the filter. The loop updates as expected.
Type in the search field or submit it.
Expected: the results are filtered by both the term and the search. Actual: nothing happens, and the console shows the error above.
Cause
The filter options' values are relative URLs (built from remove_query_arg() on the request URI), e.g. /members/?query-0-post_tag=foo. actions.navigate passes e.target.value to the router as-is, so core/router's state.url holds that relative URL afterwards.
Since #74, updateURL() builds the search URL from that state with no base:
new URL() throws on a relative URL without a base. On a fresh page load state.url is not set yet, so it falls back to the absolute window.location.href. That is why the first search works and the #74 tests pass. Before #74 the code used form.action, which the DOM always gives as an absolute URL.
An e2e test that changes a filter and then searches would cover it.
Environment
Query Filter 0.6.1 (the same code is on main)
WordPress 7.1.4
Reproduced in Chrome. It happens with the Taxonomy Filter and with any block that navigates via actions.navigate with a relative URL.
Workaround
Making the filters' option values absolute, with a render_block filter on query-filter/taxonomy and query-filter/post-type, keeps state.url absolute and avoids the error.
Activity