Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Bugs in React-Instantsearch #1950

Closed
zackify opened this issue Feb 6, 2017 · 7 comments
Closed

Configure Bugs in React-Instantsearch #1950

zackify opened this issue Feb 6, 2017 · 7 comments
Assignees

Comments

@zackify
Copy link

zackify commented Feb 6, 2017

Bug: What is the current behavior?

Configure throws errors on page changes when it has no props.

screen shot 2017-02-06 at 1 14 20 pm

Also, when you change the props passed to Configure, it does not call onSearchStateChanged, so the url isn't updated until changing the query or something else happens.

What project are you opening an issue for?

  • react-instantsearch

What is the version you are using? Always use the latest one before opening a bug issue.

v3.0.0

@mthuret
Copy link
Contributor

mthuret commented Feb 6, 2017

Hi @zackify,

I'll fix the cleanUp bug asap. For my understanding does that mean that in your use case, at some point, you have something like this: <Configure />?

Also you're right, changing the props of Configure by modifying the searchState will not trigger onSearchStateChange. But it should trigger an update with the correct parameter? If that's not the case, can you detail your use case?

Also can you confirm that if you change for example the aroundLatLng parameter directly in the URL and reload the page it's correctly taken into account?

Thanks :)

@zackify
Copy link
Author

zackify commented Feb 6, 2017

I have a location field that will set a bounding box or lat / long. When you clear it out, it removes the props on configure. So yes, at some points configure is rendered without anything.

When I am setting a prop on configure, it is not calling onSearchStateChanged until I change the query field, that triggers onSearchStateChanged, and puts the configure params in the url. Hope that helps!

Also can you confirm that if you change for example the aroundLatLng parameter directly in the URL and reload the page it's correctly taken into account?

They are not taken into account. This is probably my fault as the props are not passed to configure on reloading the page

@mthuret
Copy link
Contributor

mthuret commented Feb 7, 2017

Are you using the props searchState on the <InstantSearch/> root component?

Here's a little example with pseudo code:

constructor() {
    super();
    this.state = {searchState: //parse the url here};
  }

  onSearchStateChange = searchState => {
    //change the configure values inside search state
    //update the URL
    this.setState({searchState});
  };

  render() {
    return <InstantSearch
      appId=""
      apiKey=""
      indexName=""
      searchState={this.state.searchState}
      createURL={this.createURL.bind(this)}
      onSearchStateChange={this.onSearchStateChange.bind(this)}
    >
      <Configure aroundLatLng="5, 2.3522" />
    </InstantSearch>;
  }

By doing that, you will first modify the search state according to your needs, then update the url with the new values and then do a setState on the searchState to trigger a new rendering of the page. Can this works for you?

@zackify
Copy link
Author

zackify commented Feb 7, 2017 via email

@mthuret
Copy link
Contributor

mthuret commented Feb 7, 2017

You're right there's been some miscomprehension.
I did develop something for the controlled mode of react-instantsearch. It's the mode I described earlier.
It appears that for the uncontrolled mode, the one you are using, the onSearchStateChange is still not triggered. We're going to fix it.

@vvo vvo closed this as completed in 7e151db Feb 7, 2017
@zackify
Copy link
Author

zackify commented Feb 7, 2017 via email

@zackify
Copy link
Author

zackify commented Feb 7, 2017

Can you let me know when a release is out? You guys are the best

vvo pushed a commit that referenced this issue Feb 8, 2017
<a name="3.1.0"></a>
# [3.1.0](v3.0.0...v3.1.0) (2017-02-08)

### Bug Fixes

* **Configure:** call onSearchStateChange when props are updated (#1953) ([7e151db](7e151db)), closes [#1950](#1950)
* **Configure:** trigger onSearchStateChange with the right data ([11e5af8](11e5af8))
* **createConnector:** updates with latest props on state change (#1951) ([cd3a82c](cd3a82c))

### Features

* **ClearAll:** add withQuery to also clear the search query (#1958) ([c0e695b](c0e695b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants