File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -425,7 +425,10 @@ See ${createDocumentationLink({
425
425
// This Helper is used for the queries, we don't care about its state. The
426
426
// states are managed at the `index` level. We use this Helper to create
427
427
// DerivedHelper scoped into the `index` widgets.
428
- const mainHelper = algoliasearchHelper ( this . client , this . indexName ) ;
428
+ // In Vue InstantSearch' hydrate, a main helper gets set before start, so
429
+ // we need to respect this helper as a way to keep all listeners correct.
430
+ const mainHelper =
431
+ this . mainHelper || algoliasearchHelper ( this . client , this . indexName ) ;
429
432
430
433
mainHelper . search = ( ) => {
431
434
// This solution allows us to keep the exact same API for the users but
Original file line number Diff line number Diff line change @@ -850,6 +850,28 @@ describe('start', () => {
850
850
See documentation: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/"
851
851
` ) ;
852
852
} ) ;
853
+
854
+ it ( 'keeps a mainHelper already set on the instance (Vue SSR)' , ( ) => {
855
+ const searchClient = createSearchClient ( ) ;
856
+ const instance = new InstantSearch ( {
857
+ indexName : 'indexName' ,
858
+ searchClient,
859
+ } ) ;
860
+
861
+ const helper = algoliasearchHelper ( searchClient , '' ) ;
862
+
863
+ // explicitly setting the mainHelper before start is used to force render to
864
+ // happen before the results of the first search are done. We need to make
865
+ // sure no extra helper is created, as that can cause certain things (like routing)
866
+ // to be listening to the wrong helper.
867
+ instance . mainHelper = helper ;
868
+
869
+ expect ( instance . mainHelper ) . toBe ( helper ) ;
870
+
871
+ instance . start ( ) ;
872
+
873
+ expect ( instance . mainHelper ) . toBe ( helper ) ;
874
+ } ) ;
853
875
} ) ;
854
876
855
877
describe ( 'dispose' , ( ) => {
You can’t perform that action at this time.
0 commit comments