#Experiencing Jank with setSearchParams? Are my expectations wrong?

1 messages · Page 1 of 1 (latest)

cosmic mirage
#

I'm running into some behavior I don't understand (or have wrong expectation).

Navigating to a deferred route behaves as expected. Setting a search param on a deferred routed is followed by a delay which feels a bit janky.

I'm wondering if it's possible to get the snappy filter UI without having to useState for all the filters then setSearchParam in a useEffect?

https://gist.github.com/keepforever/18743d59e3580427b01c4e41f4297b5c

https://www.loom.com/share/2722f9fbc33b4d46a03a13d4b52e6401?sid=979cda32-518e-4b10-b9f6-fa1c1eb21fe4

Gist

Trying to figure out why there's a delay after setSearchParams runs on a route with deferred loading - DeferredRoute.tsx

ancient hawk
#

Use shouldRevalidate on all your routes up to and including the root route. It should return false when just changing the search params. Then you shouldn't see any of your loaders be queried over the network

cosmic mirage
ancient hawk
#

If you already have all the content in the browser and want to re-filter or re-sort it, then the loaders don't need to run or you could use cached data in a clientLoader. If you need to fetch more data from the server, then I'm not sure why you would expect no delay...

#

For a cache while re-validate, maybe a clientLoader can respond with two responses, one with the cached results, and a second with a Promise that resolves on the response from the server?

cosmic mirage
#

I don’t have all the data in browser. This is a paginated fetch against thousands of records that returns 10 items per page.

It sounds like you’re right in that my expectations are off between the paradigms.

I want the behavior of the client side rendering stale-while-revalidate/react-query patterns, but in SSR Remix.

Thank you for taking the time to respond.

ancient hawk
#

I personally haven't used deferred responses from loader, but the responses have been what I expect in terms of delay. I have used clientLoader though, and the responses are pretty much instantaneous since it runs in the browser.