ironstar-io / gatsby-plugin-algolia-docsearch

A Gatsby plugin for integrating with Algolia DocSearch
https://community.algolia.com/docsearch/
2 stars 5 forks source link

Breaks if you have any doc search that isn't on every page #2

Open pimterry opened 4 years ago

pimterry commented 4 years ago

Because this plugin only runs once, it breaks if you have a search box that isn't on every single page (e.g. in the header), as it never spots new search boxes that appear later.

When you first load the page with the search box it's ok, but if you go to another page without the search box and then go back, your search won't work. This is because Gatsby turns all those page transitions into JS transformations instead of real page loads.

haritonasty commented 4 years ago

the same problem

pimterry commented 4 years ago

@haritonasty in the end, I use this plugin to globally inject the docsearch script & manage all that and then I use my own component to create each search input & activate it, which works. You can see the component source here: https://github.com/httptoolkit/httptoolkit.tech/blob/master/src/components/docsearch.jsx.

There's probably better ways to do this, but it's working well enough for me for now.

haritonasty commented 4 years ago

@pimterry thank you very much for saving my day 🤗