Describe the bug 馃悰
I am unable to inject filters via search state using next SSR example
To Reproduce 馃攳
cd examples/nextyarn installnpm run devExpected behavior 馃挱
I expect to only see products that are categorized as "Appliances"
Additional context
Updated code: https://github.com/bakery/react-instantsearch/blob/search-state-filter-inject-ssr/examples/next/pages/index.js#L34
~Object assign returns a new object~, so you'll need to so something like this and make sure you pass this new object down instead of searchState everywhere:
const customSearchState = Object.assign(searchState, {
configure: {
filters: 'categories:Appliances',
},
});
You'll then need to pass this searchState into the
<Configure {...this.props.searchState.configure} />
Further explanation here: https://github.com/algolia/react-instantsearch/issues/1982#issuecomment-460295364
@rhodimus Object.assign also modifies target object so searchState gets updated properly. gonna try your second suggestion
adding <Configure {...this.props.searchState.configure} /> does a trick on the server side so the original page load arrives with appliances only but it then gets overwritten client side with a new query that pulls all the products again
this is because searchState is updated in componentDidMount() using the current window query string params, causing a client side update: https://github.com/bakery/react-instantsearch/blob/search-state-filter-inject-ssr/examples/next/pages/index.js#L56
For my purposes, I just removed the componentDidMount(), but you might also want to look at these too:
https://github.com/bakery/react-instantsearch/blob/search-state-filter-inject-ssr/examples/next/pages/index.js#L45
https://github.com/bakery/react-instantsearch/blob/search-state-filter-inject-ssr/examples/next/pages/index.js#L60
@rhodimus good point! let me dig a bit deeper
@callmephilip did you manage to fix your issue?
@samouss i did, yes. thanks for your help @rhodimus
Most helpful comment
@samouss i did, yes. thanks for your help @rhodimus