algolia icon indicating copy to clipboard operation
algolia copied to clipboard

fix: use `createNodeHttpRequester` for SSR execution

Open DanielRivers opened this issue 2 years ago • 4 comments

Types of changes

  • [x] Bug fix (a non-breaking change which fixes an issue)
  • [ ] New feature (a non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Description

When using the algolia search on the server a 500 server error was thrown unable to find xmlhttprequest.

This update added a simple switch to the setup of the algoliasearch passing in the correct requester depending on if running on server of browser as detailed here: https://www.algolia.com/doc/api-client/advanced/configure-the-client/javascript/?client=javascript#requester

Checklist:

  • [x] My change requires a change to the documentation.
  • [x] I have updated the documentation accordingly.
  • [ ] I have added tests to cover my changes (if not applicable, please state why)

DanielRivers avatar Apr 26 '22 22:04 DanielRivers

Deploy Preview for nuxt-algolia-module canceled.

Name Link
Latest commit 95d4ab5506e0b562a1bbbfe37f05b909f65d0e1e
Latest deploy log https://app.netlify.com/sites/nuxt-algolia-module/deploys/6279768e2a262500091b36e6

netlify[bot] avatar Apr 26 '22 22:04 netlify[bot]

On building on the playground there some error in the console which are also present on the browser. I was uncertain on how to fix, some guidance here would be appreciated.

[vite] error while updating dependencies:                                                                       
Error: Build failed with 3 errors:
node_modules/@algolia/requester-node-http/dist/requester-node-http.esm.js:2:9: error: No matching export in "browser-external:http" for import "Agent"
node_modules/@algolia/requester-node-http/dist/requester-node-http.esm.js:4:9: error: No matching export in "browser-external:https" for import "Agent"
node_modules/@algolia/requester-node-http/dist/requester-node-http.esm.js:5:9: error: No matching export in "browser-external:url" for import "parse"

DanielRivers avatar Apr 26 '22 22:04 DanielRivers

Thanks @DanielRivers for this PR.

Unfortunately I was not able to make it work. I tried to do some workaround for SSR but was still receiving the issues you mentioned. I will try some more in the upcoming days

Baroshem avatar May 11 '22 12:05 Baroshem

I was not able to make this work. I also found out that SSR does not work with Instantsearch.js.

Baroshem avatar Jun 23 '22 11:06 Baroshem