Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

ToggleRefinement not working with Routing URLs example #2689

Closed
yannickcr opened this issue Jul 19, 2019 · 1 comment · Fixed by #2701
Closed

ToggleRefinement not working with Routing URLs example #2689

yannickcr opened this issue Jul 19, 2019 · 1 comment · Fixed by #2701

Comments

@yannickcr
Copy link
Contributor

Describe the bug 🐛

When using the ToggleRefinement widget with the routing enabled (following the Routing URLs
guide
in the documentation) then the toggle parameter is passed as a string to the widget instead of a boolean.

We got this warning from React:

Warning: Failed prop type: Invalid prop `currentRefinement` of type `string` supplied to `ToggleRefinement`, expected `boolean`.

And when refreshing the page the checkbox is always checked (since we receive the "false" string which is truthy).

This is because the qs module parses the url parameters as string by default (ljharb/qs#91). You can fix this by using qs.decoder (ljharb/qs#91 (comment)) but this is not very convenient (and not precised in the documentation).

To Reproduce 🔍

Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/example-react-router-b3u4m
  2. Click on 'Free shipping'
  3. See warning in console.

Expected behavior 💭

The toggle parameter should be correctly passed to the widget as a boolean.

Environment:

  • OS: Linux
  • Browser: Chrome
  • Version: 75
@samouss
Copy link
Collaborator

samouss commented Jul 19, 2019

This is something that we are already doing for a couple of widgets e.g. RefinementList. We can implement the logic inside the getCurrentRefinement function of the ToggleRefinement connector.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants