WebDevStudios / wp-search-with-algolia

Improve search on your site. Autocomplete is included, along with full control over look, feel and relevance.
https://wordpress.org/plugins/wp-search-with-algolia/
145 stars 54 forks source link

"Uncaught ReferenceError: algoliasearch is not defined" after upgrading to 2.0.0 #165

Closed amrutadotorg closed 3 years ago

amrutadotorg commented 3 years ago

Hi, after upgrading the plugin to 2.0.0 In the console I'm getting the error "Uncaught ReferenceError: algoliasearch is not defined" my page is www.amruta.org I'm using default instantsearch.php template.

If possible please guide how to fix the issue.

Option Use Algolia in the backend works fine.

amrutadotorg commented 3 years ago

I'm not sure if my solution is a proper one, but following the instruction on https://www.algolia.com/doc/guides/building-search-ui/installation/js/ I added:

to the head, which solved the issue.

aiiddqd commented 3 years ago

I have the same problem

aiiddqd commented 3 years ago

there is a problem with the condition for the load scripts. if we use only search page without autocomplete - we get this error. Algolia_Template_Loader::enqueue_autocomplete_scripts() - started only if enable autocomplete. but the script for the search page is loaded in the same place

richaber commented 3 years ago

I have not encountered this in either my local development environment, nor on my own personal blog where I run WPSWA as a "remote" testing environment to ensure that the zip delivered from WPORG functions as expected.

My local development environment is running PHP 8, WordPress 5.8, and the Twenty Twenty-One theme.

My personal blog is running PHP 7.4.21, WordPress 5.8, and the Twenty Twenty theme.

I have no customizations in either environment, and use the default templates delivered with the plugin.

I tested autocomplete, PHP based search, and instantsearch, without issue in both environments.

From any page in my personal blog, if I enter algoliasearch in the browser console, I see it returns the function. From any page in my personal blog, if I enter algoliaAutocomplete in the browser console, I see it returns the function.

Screen Shot 2021-07-26 at 8 50 51 AM

On the search results page, if I enter instantsearch in the browser console, I see it returns the function.

Screen Shot 2021-07-26 at 8 49 37 AM

@uptimizt so that I understand, you are saying that if you have instantsearch.js enabled, but autocomplete disabled, then you encounter the issue?

@amrutadotorg do you also have instantsearch.js enabled, but autocomplete disabled?

aiiddqd commented 3 years ago

@richaber yes, if I enable a search page with Instantsearch.js and autocomplete, everything is fine.

but, if I disabling autocomplete

2021-07-26-17-43-49-50a9r

I get the error on the search page and the search page stops working

richaber commented 3 years ago

Thank you for verifying that @uptimizt.

I've tagged 2.0.1 here in Github, and am working on pushing it out to WPORG's SVN repo.

richaber commented 3 years ago

2.0.1 update has been pushed to WPORG

Screen Shot 2021-07-26 at 10 33 01 AM

Screen Shot 2021-07-26 at 10 36 35 AM

Tested on my personal blog, and it appears to resolve the issue if I enable instantsearch and disable autocomplete.