Berry: Website: Documentation search is somewhat broken

Created on 3 May 2020  路  7Comments  路  Source: yarnpkg/berry

  • [ ] I'd be willing to implement a fix

Describe the bug

The search seems to work only after a "real" page load. it's broken after following a link in the header (where Gatsby does a client-side SPA-style page change)

To Reproduce

  1. Go to https://yarnpkg.com/ (the doc search bar works)
  2. Click on "Getting Started" in the header, typing in the search bar has no effect
bug

Most helpful comment

Nice鈥擨'll keep you posted by next week. Feel free to DM me in the mean time if you have any questions 馃檪

All 7 comments

I suspect Gatsby rerenders the whole page between navigation, causing Algolia to be detached from the original dom element.

cc @Haroenv, does that sound coherent? Shouldn't the wrapper detect that the element disappeared, and wait for the selector to be active again?

Should be fixed 馃憤

@Haroenv yep, I fixed it here. That said, I feel like the Algolia API could be tweaked to allow for slightly more idiomatic React integration. Something like this would be nice:

const inputRef = useRef();

useDocSearch(inputRef, {
  apiKey: '...',
});

return <input ref={inputRef}/>;

At the moment it's awkward to implement in userland, because there's no way to pass a HTML element to the docsearch function (we have to use page-global selectors, so we need to set unique class names).

My 2 cents!

cc @francoischalifour, who's working on the next version of docsearch, which uses react behind the scenes, so these things would be more efficient

@arcanis Let me know if you want to give a try at the new DocSearch beta on the Yarn website. We entirely rethought the experience and it exposes a React component. You can try it on the DocSearch website.

Oh, it looks slick! For sure, if you're looking for projects to beta test, we're always open! 馃槉

Nice鈥擨'll keep you posted by next week. Feel free to DM me in the mean time if you have any questions 馃檪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dzintars picture dzintars  路  3Comments

chrisands picture chrisands  路  3Comments

joshmeads picture joshmeads  路  4Comments

IanVS picture IanVS  路  4Comments

kiprasmel picture kiprasmel  路  3Comments