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

fix(server side rendering): return a value from mock currentRefinement/metadata #3078

Merged
merged 3 commits into from
Jul 30, 2021

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Jul 7, 2021

This is required, as transitionState gets called with the return of value in a createURL.

Without this fix, an error happens if there is:

  • dynamic configure
  • currentRefinements + createURL
  • something is refined
  • SSR
  • first client render

The error is TypeError: Cannot read properties of undefined (reading 'configure') as the transitionState argument is given the result of createURL/currentRefinements, but that's undefined instead of an object. The state isn't actually transitioned, so an empty object works as a solution.

Here's a sandbox showing the existing state: https://codesandbox.io/s/charming-williamson-bifbf?file=/components/app.js:1158-1167
And that same sandbox fixed in this PR: https://codesandbox.io/s/bold-brook-gdyri

This is required, as transitionState gets called with the return of this; while the value isn't used anywhere really, it will cause an error if configure + currentRefinements is used in SSR context.

(longer description to come once test is written)
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 7, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 096ea23:

Sandbox Source
react-instantsearch-app Configuration
routing-basic Configuration
stupefied-bird-cdtor PR
musing-dust-t1qe0 PR

@algobot
Copy link
Contributor

algobot commented Jul 7, 2021

✔️ Deploy Preview for react-instantsearch ready!

🔨 Explore the source changes: 096ea23

🔍 Inspect the deploy log: https://app.netlify.com/sites/react-instantsearch/deploys/6102c5481aff360008d3f82e

😎 Browse the preview: https://deploy-preview-3078--react-instantsearch.netlify.app

@Haroenv Haroenv changed the title WIP: return a value from mock currentRefinement fix(server side rendering): return a value from mock currentRefinement/metadata Jul 29, 2021
@Haroenv Haroenv marked this pull request as ready for review July 29, 2021 15:12
@Haroenv Haroenv requested review from a team, tkrugg and shortcuts and removed request for a team July 29, 2021 15:12
Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix make sense to me

@Haroenv Haroenv merged commit 09f802b into master Jul 30, 2021
@Haroenv Haroenv deleted the fix/ssr-transitionstate branch July 30, 2021 12:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants