algolia icon indicating copy to clipboard operation
algolia copied to clipboard

Netlify edge build SSR request fails

Open plexus77 opened this issue 1 year ago • 4 comments

Version

@nuxtjs/algolia: 1.10.2 nuxt: 3.11.2

Reproduction Link

Don;t have time to reproduce on netlify and have fixed the issue since then

Steps to reproduce

Use one of the composables useAlgoliaSearch to perform a search, locally works fine. On netlify SSR fails but client side works.

What is Expected?

SSR Works

What is actually happening?

Not sure what is going on internally with the requests but putting the useFetch config option to true fixes the issue.

Wasn't sure if this is a bug in the module or underlying algolia library but it took me a while to figure out so thought I would put it here.

plexus77 avatar Apr 11 '24 22:04 plexus77

Hey Buddy,

Thanks for reporting this issue.

However, I am not sure if I will be able to help. Could you provide more details like reproduction link or at least the error your got?

Then, I will be happy to help :)

Baroshem avatar Apr 13 '24 20:04 Baroshem

I think i'm running into the same issue with Cloudflare workers. useAlgoliaSearch() works fine client side, but not on the server.

Have an app deployed with nuxt hub, which currently doesnt have the best debug experience, so i cant access any errors from server logs.

I thought it migth have something to do with the requester. I know that @algolia/requester-node-http is not available in edge runtimes, but setting runtimeConfig.public.algolia.useFetch = true did not solve the issue

nuxtApp.$algolia.transporter.requester = (await import('@algolia/requester-node-http').then(lib => lib.default || lib)).createNodeHttpRequester()

I'll try to do some more digging into the cause next week

PS. I know algoliasearch v5 has some improvements regarding edge runtimes, upgrading to the latest major version of the client might resolve the issue. I have another project running on CF which uses the algolia client (v5) directly, and the search method works out of the box

remihuigen avatar Nov 01 '24 15:11 remihuigen

Hey there, for the server side usage, I recommend using useAsyncAlgoliaSearch composable that does exactly what you did under the hood :)

Baroshem avatar Nov 04 '24 07:11 Baroshem

Yes, but that one still doesn't work... I think I'm going to switch to the latest algolia client itself, since I'm not really using anything other then searchIndex() and multipleQueries().

remihuigen avatar Nov 04 '24 12:11 remihuigen