fix(mainHelper): allow a mainHelper to be set before start #4790
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
In Vue InstantSearch server side rendering, we set a mainHelper https://github.com/algolia/vue-instantsearch/blob/118e0a39b8a047930520220da757ff0175cec12d/src/util/createServerRootMixin.js#L234-L235 before the instance is started.
This worked fine with existing fixes done, except for in routing, because every place that changes the state uses helper from the index, which is derived of the helper that's created before start. Routing and middleware however uses the helper which gets created in start, and thus don't trigger a search on the helper that actually searches.
To avoid these issues, we prevent recreation of the main helper if it's already set (by Vue InstantSearch for example). Whenever we will add the proper API for server side rendering in InstantSearch, we can rethink this part and probably remove it on a major.
Result
mainHelper doesn't get recreated if there's already one present