appbaseio / reactivesearch

Search UI components for React and Vue
https://opensource.appbase.io/reactivesearch
Apache License 2.0
4.89k stars 468 forks source link

Bug parsing URLParams in ReactiveBase #1475

Closed pcvonz closed 3 years ago

pcvonz commented 4 years ago

Affected Projects

React Library Version: x.y.z

Working off this commit: e2eacff2275c201a5becea71a58996313c2653df Describe the bug

In ReactiveBase in this loop: https://github.com/appbaseio/reactivesearch/blob/e2eacff2275c201a5becea71a58996313c2653df/packages/web/src/components/basic/ReactiveBase.js#L120

If parsedParams.value is undefined when parsing URLParams, the selectedValue.value is set to the parsed params. https://github.com/appbaseio/reactivesearch/blob/e2eacff2275c201a5becea71a58996313c2653df/packages/web/src/components/basic/ReactiveBase.js#L127 If parsed params is an Object (which is the case for the CategorySearch component) then this line: https://github.com/appbaseio/reactivesearch/blob/e2eacff2275c201a5becea71a58996313c2653df/packages/web/src/components/search/CategorySearch.js#L158

Will cause ReactiveSearch to throw an error. To Reproduce

Steps to reproduce the behavior:

  1. Instantiate a CategorySearch component with URLParams set to true
  2. Perform a search on a category
  3. Remove value from the Search object in the URL bar.
  4. Reload

Expected behavior

Only set selectedValue in reactive base if value is a string.

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

I've run into this bug a few times in my app. Sometimes when using the back and forward buttons.

Navigating with back button:

  1. somesearchapp.whatever/?
  2. somesearchapp.whatever/?Search=%7B%22category%22%3A%22%2FRoot%20Catalog%2FDefault%20Category%2FTabletop%22%2C%22value%22%3A%22cup%22%7D

bug

Error being thrown: TypeError: "this.state.currentValue.trim is not a function"

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

sachh185 commented 1 year ago

@pcvonz I faced a similar issue. Was this fixed? Or did you find any workaround?