Skip to content

Commit

Permalink
fix(Search): withClient provoked Minified React Error
Browse files Browse the repository at this point in the history
you have to use client coming from prop because with hoc or hooks
it might cause this Minified React Error
  • Loading branch information
trollepierre committed Sep 2, 2022
1 parent 4c8b1ff commit 9ce1dee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/components/Bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ export class Bar extends Component {
{barLeft || this.renderLeft()}
{barCenter || this.renderCenter()}
<div className="u-flex-grow">
{barSearch || (searchBarEnabled ? <SearchBar /> : null)}
{barSearch ||
(searchBarEnabled ? (
<SearchBar client={this.props.cozyClient} />
) : null)}
</div>
{barRight || this.renderRight()}
{!isPublic ? (
Expand Down
6 changes: 3 additions & 3 deletions src/components/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Autosuggest from 'react-autosuggest'
import debounce from 'lodash.debounce'
import { fetchRawIntent } from 'lib/intents'
import logger from 'lib/logger'
import { models, withClient } from 'cozy-client'
import { models } from 'cozy-client'

const INTENT_VERB = 'OPEN'
const INTENT_DOCTYPE = 'io.cozy.suggestions'
Expand Down Expand Up @@ -234,7 +234,7 @@ class SearchBar extends Component {
const { onSelect } = suggestion
// `onSelect` is a string that describes what should happen when the suggestion is selected. Currently, the only format we're supporting is `open:http://example.com` to change the url of the current page.

if (/^id_note:/.test(onSelect)) {
if (/^id_note:/.test(onSelect) && client) {
const url = await models.note.fetchURL(client, { id: onSelect.substr(8) })
window.location.href = url
} else if (/^open:/.test(onSelect)) {
Expand Down Expand Up @@ -358,4 +358,4 @@ class SearchBar extends Component {
}
}

export default translate()(withClient(SearchBar))
export default translate()(SearchBar)
8 changes: 7 additions & 1 deletion src/components/__snapshots__/Bar.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ exports[`Bar should display the Searchbar 1`] = `
<div
className="u-flex-grow"
>
<Wrapper />
<Wrapper
client={
CozyClient {
"uri": undefined,
}
}
/>
</div>
<Wrapper
toggleSupport={[Function]}
Expand Down

0 comments on commit 9ce1dee

Please sign in to comment.