Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/taxonomy/view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import { store, getContext, getElement } from '@wordpress/interactivity';
import {
store,
getContext,
getElement,
withSyncEvent,
} from '@wordpress/interactivity';

/**
* How long the router may spend fetching a navigation before giving up, in
* milliseconds.
*
* The router's default is 10s, after which it falls back to a full-page
* `window.location.assign()`. Slow uncached renders (WP_DEBUG local
* environments, cold caches) regularly brush against that default, turning
* in-place filter updates into full reloads. The extended window keeps slow
* responses on the in-place path; genuinely dead requests still fall back.
*/
const NAVIGATION_TIMEOUT = 30000;

const updateURL = async ( action, value, name ) => {
const url = new URL( action );
Expand All @@ -8,23 +25,25 @@ const updateURL = async ( action, value, name ) => {
url.searchParams.delete( name );
}
const { actions } = await import( '@wordpress/interactivity-router' );
await actions.navigate( url.toString() );
await actions.navigate( url.toString(), { timeout: NAVIGATION_TIMEOUT } );
};

store( 'query-filter', {
actions: {
*navigate( e ) {
navigate: withSyncEvent( function* ( e ) {
e.preventDefault();
const { actions } = yield import(
'@wordpress/interactivity-router'
);
yield actions.navigate( e.target.value );
},
yield actions.navigate( e.target.value, {
timeout: NAVIGATION_TIMEOUT,
} );
} ),
toggleAllTerms() {
const context = getContext();
context.showAllTerms = ! context.showAllTerms;
},
*search( e ) {
search: withSyncEvent( function* ( e ) {
e.preventDefault();
// Scope search to block context so multiple searchable query loops may coexist.
const context = getContext();
Expand All @@ -47,6 +66,6 @@ store( 'query-filter', {
context.searchValue = value;

yield updateURL( action, value, name );
},
} ),
},
} );