-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Unwanted client-side query after SSR with Remix/Shopify-Hydrogen #5839
Comments
This issue remix-run/react-router#10579 shares some good insights about why some apps struggle with React-router 6.13.0 also provided a feature flag but recommended apps to adopt it sooner to better support concurrent mode. Unfortunately Remix opt-in to this flat automatically and doesn't provide the Remix users a feature flat to opt-out. |
Hi @steve-jiang, I think probably the only reason we want to run I think what it does is that it's still the same Is there a way to ignore running the loader when you change routes ? I know Next.js had a |
Hey @aymeric-giraudet, I see where you're coming from, but I have some reservations. Your suggestion seems to diverge from Remix's design philosophy around the loader's functionality for data fetching. Your point on performance stands valid only if the entire route solely fetches from Algolia, which isn't always the case. In e-commerce scenarios, we frequently fetch metadata from the e-commerce platform before or alongside Algolia's product fetch. Think about category pages: there's often a mix of content, some of which isn't even housed in Algolia. The beauty of Remix's loader, particularly with its defer and streaming capabilities, lies in its ability to smartly prioritise fetches based on content relevance. If we push Algolia's fetch to the client-side, it inevitably ends up being the last fetch of the waterfall. This is mainly because the client-side fetch is waiting for the loader to wrap up, and only then does In a nutshell, moving the Algolia query to the client-side tacks on an extra network request since the loader's still got to grab non-Algolia content. With the loader, I can await the Algolia fetch and put the rest on defer, while client-side Algolia's request ends up at the end of the queue. |
Hey @steve-jiang, I've had another look by running it locally as CodeSandbox makes Remix have hydration problems (which I pointed out here codesandbox/codesandbox-client#7959) Seems like even on initial request, the server gives the markup but we still send a request for nothing. And I was wrong about it being the same instance of You made a great point about request waterfalls. Since we're currently working on Next.js app dir support, one thing we're about to resolve is to populate the algolia client cache with the initial results rather than changing the search function to a I'll keep you updated when this is resolved ! |
@aymeric-giraudet I saw you guys released a package for Next.js. Is that going to help Remix as well? Any suggestions to my original problem? Thank you! |
Hi @steve-jiang, it should be fixed whenever #5854 is merged. |
@aymeric-giraudet can confirm the SSR works with the patch and no more duplicated Client-side queries. When do you reckon #5854 can be merged? |
The code is solid, so you can use a patched version, but testing it proves not to be easy, so to keep correct expectations, I'd expect that patch to land in a couple weeks |
@Haroenv and @aymeric-giraudet now I tested on 7.3.0 and it is not working. I don't know what changed. Please see the minimum setup to replicate the issue: Not workingRemix: 1.19.3 WorkingRemix: 1.16.1 |
Hi @steve-jiang, Thanks a lot for the reproductions ! This is because all pages are using the same instance of In your case this can be fixed by having each page have their own Note that it doesn't seem to work on CodeSandbox, but that's because there's a hydration error as I've mentioned before. It should work well locally. |
@aymeric-giraudet I downloaded your sandbox and ran locally and it still has the extra client-side query for each route change. Running it on local also uncovered another issue where if you refresh a search you see 2 duplicated client side queries. The demo is done in a way where each route has its own InstantSearchSSR and InstantSearch instance, where normally you would have a dynamic route, e.g. I made another reproduce now including cached and non-cached searchClient, as well as dynamic routes and running them in local all have client-side query when navigating, sometimes more duplicated ones for routes using new search client on render. https://codesandbox.io/p/sandbox/happy-fire-2qrqwk?file=%2Fcomponents%2FNavs.tsx%3A18%2C27 Really keen to get this resolved and any help will be appraciated! |
Ah yes sorry @steve-jiang, I forgot that I had also removed I think this is due to the generated anonymous insight token as it doesn't happen when you provide a user token yourself. |
I fixed your examples there too (the ones where we initialize a new client) : https://x4lyps-3000.csb.app/ Works with dynamic routes too. Here's what I did :
I'll look into the insights and shared client issue on my end, but please tell me if you were able to fix it on your end 🙏 |
@aymeric-giraudet Thank you so much for helping! I can confirm it works if we use Algolia's demo index including However, it just doesn't work for our appId/Index and it took me a while to test but I still don't understand why. Is there a setting in the Algolia dashboard that we need to turn on to enable caching? You can replicate it by downloading the codesandbox here: https://codesandbox.io/p/sandbox/happy-fire-2qrqwk?file=%2Fapp%2Falgolia.ts. I created a temp appkey for the codesandbox and if you can let me know when you done testing so I can remove it. |
Good news, with the latest versions of InstantSearch and React InstantSearch this is solved: https://codesandbox.io/p/devbox/serene-wu-69wlhw?file=%2Fpackage.json%3A23%2C24 through #5946 |
🐛 Current behavior
Using the latest Remix (or any version above 1.17.0) and Algolia's official SSR example for Remix, if we add a few more routes, navigating between the routes will trigger additional/unwanted client-side query. The page should be SSRed as the
serverState
is already in the loader, so the client-side query is not needed.If you compare the
queryId
from theserverState
with the client-side query, thequeryIDs
are different which will cause problems ifClickAnalytics
is enabled.After some research, we found that the issue is impacting all Remix apps that use 1.17.0 and above. Remix 1.17.0 uses the updated React-router that now supports React's Transaction API. For the transition-enabled router, it seems to cause unwanted fetches when the InstantSeach component hydrates after SSR
🔍 Steps to reproduce
Live reproduction
https://codesandbox.io/p/sandbox/shy-leftpad-7lylvl
💭 Expected behavior
https://codesandbox.io/p/sandbox/broken-resonance-dwtqf2
Here is another minimum setup that uses Algolia's official Remix SSR example, but the remix version is 1.16.1 which doesn't uses the
startTransition
enabled router. If you click around the navigation, you can only see Remix's loader data fetches which contain theserverState
that Algolia needs to render the pagehttps://dwtqf2-3000.csb.app/
Package version
"react-instantsearch": "7.0.2"
Operating system
macOs 13.4.1
Browser
Chrome 116.0.5845.140
Code of Conduct
The text was updated successfully, but these errors were encountered: