Skip to content

Commit

Permalink
fix(www): search not initializing after client-side routing (#9230)
Browse files Browse the repository at this point in the history
Fixes #8567
  • Loading branch information
fk authored and pieh committed Oct 23, 2018
1 parent 09e447c commit a9796aa
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion www/src/components/search-form.js
Expand Up @@ -273,6 +273,10 @@ class SearchForm extends Component {
navigate(`${a.pathname}${a.hash}`)
}
init() {
if (this.algoliaInitialized) {
return
}

window.addEventListener(
`autocomplete:selected`,
this.autocompleteSelected,
Expand All @@ -290,6 +294,7 @@ class SearchForm extends Component {
keyboardShortcuts: [`s`],
},
})
this.algoliaInitialized = true
}
componentDidMount() {
if (
Expand All @@ -306,13 +311,23 @@ class SearchForm extends Component {
document.head.appendChild(link)
}
}
componentWillUnmount() {
window.removeEventListener(
`autocomplete:selected`,
this.autocompleteSelected,
true
)
}
loadAlgoliaJS() {
!loadedJs &&
if (!loadedJs) {
loadJS().then(a => {
loadedJs = true
window.docsearch = a.default
this.init()
})
} else {
this.init()
}
}
render() {
const { focussed } = this.state
Expand Down

0 comments on commit a9796aa

Please sign in to comment.