nuxt-modules / algolia

🔎 Algolia module for Nuxt
https://algolia.nuxtjs.org/
MIT License
185 stars 32 forks source link

Broken algolia implementation #152

Closed gitFoxCode closed 1 year ago

gitFoxCode commented 1 year ago

Version

@nuxtjs/algolia: ^1.3.1 nuxt: ^3.5.2

Reproduction Link

https://content.nuxtjs.org/

Steps to reproduce

Use docus docsearch.ts: https://github.com/nuxt-themes/docus/blob/f56cd8d66441f7a60ad19a8644656c925f9f1747/app/integrations/docsearch.ts#L4

What is Expected?

Working search engine

What is actually happening?

entry.9c90eddd.js:7 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'facetFilters')

When click:

TypeError: Cannot read properties of null (reading 'click')
Baroshem commented 1 year ago

Hey,

I dont have that much experience with Nuxt Content but it seems that the implementation of the DocSearch there is not correct.

In order to make it work properly, there should these two envs passed:

algolia: {
    docSearch: {
      indexName: process.env.ALGOLIA_DOCSEARCH_INDEX_NAME ?? 'indexName',
      facetFilters: process.env.ALGOLIA_DOCSEARCH_FACET_FILTERS ?? ''
    },
}

While I was not able to see them there.

I will talk to the Content guys about it.

gitFoxCode commented 1 year ago

@Baroshem I noticed that "userOptions" doesn't work as expected, so I hard-coded the data, and now you can click on the search engine but when typing, this error appears: image

Baroshem commented 1 year ago

It seems that the variables were not properly set as I have explained above :)

Let's wait for the content guys response

gitFoxCode commented 1 year ago

I solved this problem, useRuntimeConfig() contains an object, "public", just refer to it https://github.com/nuxt-themes/docus/blob/f56cd8d66441f7a60ad19a8644656c925f9f1747/app/integrations/docsearch.ts#L23 from: const { algolia } = useRuntimeConfig() to: const { algolia } = useRuntimeConfig().public

Baroshem commented 1 year ago

Ok thanks for letting me know about the result :)