vue-instantsearch 4.0.0-beta.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,50 +1,35 @@
1
- # [4.0.0-beta.2](https://github.com/algolia/vue-instantsearch/compare/v4.0.0-beta.1...v4.0.0-beta.2) (2021-08-19)
1
+ # [4.1.0](https://github.com/algolia/vue-instantsearch/compare/v4.0.1...v4.1.0) (2021-10-26)
2
2
 
3
3
 
4
- ### Bug Fixes
5
-
6
- * **range-input:** remove default min and max values from `ais-range-input` (BREAKING CHANGE) ([#1036](https://github.com/algolia/vue-instantsearch/issues/1036)) ([38987ac](https://github.com/algolia/vue-instantsearch/commit/38987ac74548baf239a7ca25d34743b4027704cd))
7
- * **Server-side rendering:** let users pass renderToString to createServerRootMixin (BREAKING CHANGE) ([#1035](https://github.com/algolia/vue-instantsearch/issues/1035)) ([bc5f58a](https://github.com/algolia/vue-instantsearch/commit/bc5f58a81a205e856207e6cf1e45bc8d11605efd))
8
-
9
-
10
-
11
- # [4.0.0-beta.1](https://github.com/algolia/vue-instantsearch/compare/v3.8.1...v4.0.0-beta.1) (2021-07-29)
4
+ ### Features
12
5
 
6
+ * **dependencies:** update downstream ([#1075](https://github.com/algolia/vue-instantsearch/issues/1075)) ([ede11a5](https://github.com/algolia/vue-instantsearch/commit/ede11a5aa907f33123df7f19013680633228d0cf))
13
7
 
14
- Vue InstantSearch now supports Vue 3.
15
8
 
16
- ## Breaking Change for Vue 2 users with SSR
17
9
 
18
- From now on, Vue InstantSearch [dynamically imports](https://github.com/algolia/vue-instantsearch/blob/b3ad4a3fc49e1e7470a0e6dd383c24b1dcb0b5bd/src/util/vue-compat/index-2.js#L23:L23) `vue-server-renderer/basic` instead of `require()`.
10
+ ## [4.0.1](https://github.com/algolia/vue-instantsearch/compare/v4.0.0...v4.0.1) (2021-09-15)
19
11
 
20
- * If you're using CJS output of Vue InstantSearch, it doesn't change anything for you because it gets transpiled to `require` for CJS output.
21
- * If you're using ESM output, it should probably be okay. We've tested "dynamic import" with Vue 2 (vue-cli) and Nuxt and it worked fine.
22
12
 
23
- If you have different setup or use different bundler, you may check if it still works for you. If not, please [create an issue](https://github.com/algolia/vue-instantsearch/issues/new/choose) with a reproducible example.
13
+ ### Bug Fixes
24
14
 
25
- ## For Vue 3 users
15
+ * **dynamic-widgets:** use non-experimental connector ([5629957](https://github.com/algolia/vue-instantsearch/commit/56299575f1fdd1d8cd777358f77543d5b0211b18))
16
+ * **ssr:** pass parent index to render in __forceRender ([25284aa](https://github.com/algolia/vue-instantsearch/commit/25284aafdb95f4684387744953c2a38241da7ad1))
26
17
 
27
- Vue InstantSearch includes two packages, one for vue 2 and another one for vue 3. So for vue 3, you need to import with this path:
28
18
 
29
- ```js
30
- import InstantSearch from 'vue-instantsearch/vue3/es';
31
- ```
32
19
 
33
- ## Regarding vue-router@v4
20
+ # [4.0.0](https://github.com/algolia/vue-instantsearch/compare/v3.8.1...v4.0.0) (2021-08-23)
34
21
 
35
- If you migrate your `vue-router` to v4 along with vue 3, you need to replace
22
+ Vue InstantSearch now supports Vue 3 ([#990](https://github.com/algolia/vue-instantsearch/issues/990)).
36
23
 
37
- ```js
38
- vueRouter.currentRoute.query
39
- ```
24
+ It has a few breaking changes that you can easily migrate. You can read [the upgrade guide](https://www.algolia.com/doc/guides/building-search-ui/upgrade-guides/vue/#upgrade-from-v3-to-v4).
40
25
 
41
- with
26
+ You can try these examples:
42
27
 
43
- ```js
44
- vueRouter.currentRoute.value.query
45
- ```
28
+ * Vue 3 + Vue CLI: [GitHub](https://github.com/algolia/doc-code-samples/tree/master/Vue%20InstantSearch/vue3-vue-cli) | [CodeSandbox](codesandbox.io/s/github/algolia/doc-code-samples/tree/master/Vue%20InstantSearch/vue3-vue-cli)
29
+ * Vue 3 + Vite: [GitHub](https://github.com/algolia/doc-code-samples/tree/master/Vue%20InstantSearch/vue3-vite)
30
+ * Vue 3 + SSR + Vue CLI: [GitHub](https://github.com/algolia/doc-code-samples/tree/master/Vue%20InstantSearch/vue3-ssr-vue-cli)
31
+ * Vue 3 + SSR + Vite: [GitHub](https://github.com/algolia/doc-code-samples/tree/master/Vue%20InstantSearch/vue3-ssr-vite)
46
32
 
47
- due to [its change](https://next.router.vuejs.org/api/#currentroute).
48
33
 
49
34
  ## [3.8.1](https://github.com/algolia/vue-instantsearch/compare/v3.8.0...v3.8.1) (2021-07-12)
50
35
 
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "autocomplete"
17
17
  ],
18
18
  "license": "MIT",
19
- "version": "4.0.0-beta.2",
19
+ "version": "4.1.0",
20
20
  "files": [
21
21
  "vue2",
22
22
  "vue3",
@@ -48,8 +48,8 @@
48
48
  "release": "shipjs prepare"
49
49
  },
50
50
  "dependencies": {
51
- "algoliasearch-helper": "^3.1.0",
52
- "instantsearch.js": "^4.27.2",
51
+ "algoliasearch-helper": "^3.6.2",
52
+ "instantsearch.js": "^4.32.0",
53
53
  "mitt": "^2.1.0"
54
54
  },
55
55
  "peerDependencies": {
@@ -132,15 +132,15 @@
132
132
  "bundlesize": [
133
133
  {
134
134
  "path": "./vue2/umd/index.js",
135
- "maxSize": "55.00 kB"
135
+ "maxSize": "55.25 kB"
136
136
  },
137
137
  {
138
- "path": "./vue2/cjs/index.js",
139
- "maxSize": "17.00 kB"
138
+ "path": "./vue3/umd/index.js",
139
+ "maxSize": "56.75 kB"
140
140
  },
141
141
  {
142
- "path": "./vue3/umd/index.js",
143
- "maxSize": "56.50 kB"
142
+ "path": "./vue2/cjs/index.js",
143
+ "maxSize": "17.00 kB"
144
144
  },
145
145
  {
146
146
  "path": "./vue3/cjs/index.js",
@@ -1,5 +1,5 @@
1
1
  import { createWidgetMixin } from '../mixins/widget';
2
- import { EXPERIMENTAL_connectDynamicWidgets } from 'instantsearch.js/es/connectors';
2
+ import { connectDynamicWidgets } from 'instantsearch.js/es/connectors';
3
3
  import { createSuitMixin } from '../mixins/suit';
4
4
  import { _objectSpread } from '../util/polyfills';
5
5
  import { isVue3, renderCompat, getDefaultSlot } from '../util/vue-compat';
@@ -42,7 +42,7 @@ function getWidgetAttribute(vnode) {
42
42
  export default {
43
43
  name: 'AisExperimentalDynamicWidgets',
44
44
  mixins: [
45
- createWidgetMixin({ connector: EXPERIMENTAL_connectDynamicWidgets }),
45
+ createWidgetMixin({ connector: connectDynamicWidgets }),
46
46
  createSuitMixin({ name: 'DynamicWidgets' }),
47
47
  ],
48
48
  props: {
@@ -52,7 +52,6 @@ describe('createServerRootMixin', () => {
52
52
  createSSRApp({
53
53
  mixins: [
54
54
  createServerRootMixin({
55
- renderToString,
56
55
  searchClient: undefined,
57
56
  indexName: 'lol',
58
57
  }),
@@ -68,7 +67,6 @@ describe('createServerRootMixin', () => {
68
67
  createSSRApp({
69
68
  mixins: [
70
69
  createServerRootMixin({
71
- renderToString,
72
70
  searchClient: createFakeClient(),
73
71
  indexName: undefined,
74
72
  }),
@@ -79,26 +77,10 @@ describe('createServerRootMixin', () => {
79
77
  );
80
78
  });
81
79
 
82
- it('requires renderToString', () => {
83
- expect(() =>
84
- createSSRApp({
85
- mixins: [
86
- createServerRootMixin({
87
- searchClient: createFakeClient(),
88
- indexName: 'yup',
89
- }),
90
- ],
91
- })
92
- ).toThrowErrorMatchingInlineSnapshot(
93
- `"createServerRootMixin requires \`renderToString: (app) => Promise<string>\` in the first argument"`
94
- );
95
- });
96
-
97
80
  it('creates an instantsearch instance on "data"', () => {
98
81
  const App = {
99
82
  mixins: [
100
83
  createServerRootMixin({
101
- renderToString,
102
84
  searchClient: createFakeClient(),
103
85
  indexName: 'lol',
104
86
  }),
@@ -118,7 +100,6 @@ describe('createServerRootMixin', () => {
118
100
  const App = {
119
101
  mixins: [
120
102
  createServerRootMixin({
121
- renderToString,
122
103
  searchClient: createFakeClient(),
123
104
  indexName: 'myIndexName',
124
105
  }),
@@ -164,7 +145,6 @@ describe('createServerRootMixin', () => {
164
145
  mixins: [
165
146
  forceIsServerMixin,
166
147
  createServerRootMixin({
167
- renderToString,
168
148
  searchClient: createFakeClient(),
169
149
  indexName: 'hello',
170
150
  }),
@@ -179,6 +159,44 @@ describe('createServerRootMixin', () => {
179
159
  await renderToString(app);
180
160
  });
181
161
 
162
+ it('requires renderToString', async () => {
163
+ const searchClient = createFakeClient();
164
+
165
+ const app = {
166
+ mixins: [
167
+ forceIsServerMixin,
168
+ createServerRootMixin({
169
+ searchClient,
170
+ indexName: 'hello',
171
+ }),
172
+ ],
173
+ render: renderCompat(h =>
174
+ h(InstantSearchSsr, {}, [
175
+ h(Configure, {
176
+ attrs: {
177
+ hitsPerPage: 100,
178
+ },
179
+ }),
180
+ h(SearchBox),
181
+ ])
182
+ ),
183
+ serverPrefetch() {
184
+ expect(() =>
185
+ this.instantsearch.findResultsState({ component: this })
186
+ ).toThrowErrorMatchingInlineSnapshot(
187
+ `"findResultsState requires \`renderToString: (component) => Promise<string>\` in the first argument."`
188
+ );
189
+ },
190
+ };
191
+
192
+ const wrapper = createSSRApp({
193
+ mixins: [forceIsServerMixin],
194
+ render: renderCompat(h => h(app)),
195
+ });
196
+
197
+ await renderToString(wrapper);
198
+ });
199
+
182
200
  it('detects child widgets', async () => {
183
201
  const searchClient = createFakeClient();
184
202
  let mainIndex;
@@ -187,7 +205,6 @@ describe('createServerRootMixin', () => {
187
205
  mixins: [
188
206
  forceIsServerMixin,
189
207
  createServerRootMixin({
190
- renderToString,
191
208
  searchClient,
192
209
  indexName: 'hello',
193
210
  }),
@@ -214,7 +231,10 @@ describe('createServerRootMixin', () => {
214
231
  ])
215
232
  ),
216
233
  serverPrefetch() {
217
- return this.instantsearch.findResultsState(this);
234
+ return this.instantsearch.findResultsState({
235
+ component: this,
236
+ renderToString,
237
+ });
218
238
  },
219
239
  created() {
220
240
  mainIndex = this.instantsearch.mainIndex;
@@ -261,7 +281,6 @@ Array [
261
281
  mixins: [
262
282
  forceIsServerMixin,
263
283
  createServerRootMixin({
264
- renderToString,
265
284
  searchClient,
266
285
  indexName: 'hello',
267
286
  }),
@@ -277,7 +296,10 @@ Array [
277
296
  ])
278
297
  ),
279
298
  async serverPrefetch() {
280
- const state = await this.instantsearch.findResultsState(this);
299
+ const state = await this.instantsearch.findResultsState({
300
+ component: this,
301
+ renderToString,
302
+ });
281
303
  expect(state).toEqual({
282
304
  __identifier: 'stringified',
283
305
  hello: {
@@ -339,7 +361,6 @@ Array [
339
361
  mixins: [
340
362
  forceIsServerMixin,
341
363
  createServerRootMixin({
342
- renderToString,
343
364
  searchClient,
344
365
  indexName: 'hello',
345
366
  }),
@@ -359,7 +380,10 @@ Array [
359
380
  ])
360
381
  ),
361
382
  serverPrefetch() {
362
- return this.instantsearch.findResultsState(this);
383
+ return this.instantsearch.findResultsState({
384
+ component: this,
385
+ renderToString,
386
+ });
363
387
  },
364
388
  };
365
389
 
@@ -390,7 +414,6 @@ Array [
390
414
  mixins: [
391
415
  forceIsServerMixin,
392
416
  createServerRootMixin({
393
- renderToString,
394
417
  searchClient,
395
418
  indexName: 'hello',
396
419
  }),
@@ -410,7 +433,10 @@ Array [
410
433
  ])
411
434
  ),
412
435
  serverPrefetch() {
413
- return this.instantsearch.findResultsState(this);
436
+ return this.instantsearch.findResultsState({
437
+ component: this,
438
+ renderToString,
439
+ });
414
440
  },
415
441
  };
416
442
 
@@ -440,7 +466,6 @@ Array [
440
466
  mixins: [
441
467
  forceIsServerMixin,
442
468
  createServerRootMixin({
443
- renderToString,
444
469
  searchClient,
445
470
  indexName: 'hello',
446
471
  }),
@@ -466,7 +491,10 @@ Array [
466
491
  ])
467
492
  ),
468
493
  serverPrefetch() {
469
- return this.instantsearch.findResultsState(this);
494
+ return this.instantsearch.findResultsState({
495
+ component: this,
496
+ renderToString,
497
+ });
470
498
  },
471
499
  };
472
500
 
@@ -487,7 +515,6 @@ Array [
487
515
  mixins: [
488
516
  forceIsServerMixin,
489
517
  createServerRootMixin({
490
- renderToString,
491
518
  searchClient,
492
519
  indexName: 'hello',
493
520
  }),
@@ -501,7 +528,7 @@ Array [
501
528
  serverPrefetch() {
502
529
  return (
503
530
  this.instantsearch
504
- .findResultsState(this)
531
+ .findResultsState({ component: this, renderToString })
505
532
  .then(res => {
506
533
  expect(
507
534
  this.instantsearch.mainIndex.getWidgets().map(w => w.$$type)
@@ -541,7 +568,6 @@ Array [
541
568
  mixins: [
542
569
  forceIsServerMixin,
543
570
  createServerRootMixin({
544
- renderToString,
545
571
  searchClient,
546
572
  indexName: 'hello',
547
573
  }),
@@ -552,7 +578,7 @@ Array [
552
578
  serverPrefetch() {
553
579
  return (
554
580
  this.instantsearch
555
- .findResultsState(this)
581
+ .findResultsState({ component: this, renderToString })
556
582
  .then(res => {
557
583
  expect(
558
584
  this.instantsearch.mainIndex.getWidgets().map(w => w.$$type)
@@ -600,7 +626,6 @@ Array [
600
626
  mixins: [
601
627
  forceIsServerMixin,
602
628
  createServerRootMixin({
603
- renderToString,
604
629
  searchClient,
605
630
  indexName: 'hello',
606
631
  }),
@@ -617,7 +642,10 @@ Array [
617
642
  ]);
618
643
  }),
619
644
  serverPrefetch() {
620
- return this.instantsearch.findResultsState(this);
645
+ return this.instantsearch.findResultsState({
646
+ component: this,
647
+ renderToString,
648
+ });
621
649
  },
622
650
  };
623
651
 
@@ -638,7 +666,6 @@ Array [
638
666
  const app = {
639
667
  mixins: [
640
668
  createServerRootMixin({
641
- renderToString,
642
669
  searchClient: createFakeClient(),
643
670
  indexName: 'hello',
644
671
  }),
@@ -685,7 +712,6 @@ Array [
685
712
  const app = {
686
713
  mixins: [
687
714
  createServerRootMixin({
688
- renderToString,
689
715
  searchClient: createFakeClient(),
690
716
  indexName: 'movies',
691
717
  }),
@@ -724,7 +750,6 @@ Array [
724
750
  const app = {
725
751
  mixins: [
726
752
  createServerRootMixin({
727
- renderToString,
728
753
  searchClient: createFakeClient(),
729
754
  indexName: 'hello',
730
755
  }),
@@ -763,7 +788,6 @@ Array [
763
788
  const app = {
764
789
  mixins: [
765
790
  createServerRootMixin({
766
- renderToString,
767
791
  searchClient: createFakeClient(),
768
792
  indexName: 'hello',
769
793
  }),
@@ -803,7 +827,6 @@ Array [
803
827
  mount({
804
828
  mixins: [
805
829
  createServerRootMixin({
806
- renderToString,
807
830
  searchClient: createFakeClient(),
808
831
  indexName: 'lol',
809
832
  }),
@@ -843,6 +866,7 @@ Array [
843
866
  results: expect.anything(),
844
867
  }),
845
868
  ]),
869
+ parent: expect.anything(),
846
870
  state: expect.anything(),
847
871
  instantSearchInstance: expect.anything(),
848
872
  },
@@ -851,6 +875,7 @@ Object {
851
875
  "createURL": [Function],
852
876
  "helper": Anything,
853
877
  "instantSearchInstance": Anything,
878
+ "parent": Anything,
854
879
  "results": Anything,
855
880
  "scopedResults": ArrayContaining [
856
881
  ObjectContaining {
@@ -875,7 +900,6 @@ Object {
875
900
  mount({
876
901
  mixins: [
877
902
  createServerRootMixin({
878
- renderToString,
879
903
  searchClient: createFakeClient(),
880
904
  indexName: 'lol',
881
905
  }),
@@ -909,7 +933,6 @@ Object {
909
933
  mount({
910
934
  mixins: [
911
935
  createServerRootMixin({
912
- renderToString,
913
936
  searchClient: createFakeClient(),
914
937
  indexName: 'lol',
915
938
  }),
@@ -80,8 +80,7 @@ function augmentInstantSearch(
80
80
  instantSearchOptions,
81
81
  searchClient,
82
82
  indexName,
83
- cloneComponent,
84
- renderToString
83
+ cloneComponent
85
84
  ) {
86
85
  /* eslint-disable no-param-reassign */
87
86
 
@@ -92,21 +91,29 @@ function augmentInstantSearch(
92
91
 
93
92
  /**
94
93
  * main API for SSR, called in serverPrefetch of a root component which contains instantsearch
95
- * @param {object} componentInstance the calling component's `this`
94
+ * @param {Object} props the object including `component` and `renderToString`
95
+ * @param {Object} props.component the calling component's `this`
96
+ * @param {Function} props.renderToString the function to render componentInstance to string
96
97
  * @returns {Promise} result of the search, to save for .hydrate
97
98
  */
98
- search.findResultsState = function(componentInstance) {
99
+ search.findResultsState = function({ component, renderToString }) {
100
+ if (!renderToString) {
101
+ throw new Error(
102
+ 'findResultsState requires `renderToString: (component) => Promise<string>` in the first argument.'
103
+ );
104
+ }
105
+
99
106
  let app;
100
- let renderedComponentInstance;
107
+ let renderedComponent;
101
108
 
102
109
  return Promise.resolve()
103
110
  .then(() => {
104
- app = cloneComponent(componentInstance, {
111
+ app = cloneComponent(component, {
105
112
  mixins: [
106
113
  {
107
114
  created() {
108
115
  // eslint-disable-next-line consistent-this
109
- renderedComponentInstance = this;
116
+ renderedComponent = this;
110
117
  this.instantsearch.helper = helper;
111
118
  this.instantsearch.mainHelper = helper;
112
119
 
@@ -124,7 +131,7 @@ function augmentInstantSearch(
124
131
  .then(() => searchOnlyWithDerivedHelpers(helper))
125
132
  .then(() => {
126
133
  const results = {};
127
- walkIndex(renderedComponentInstance.instantsearch.mainIndex, widget => {
134
+ walkIndex(renderedComponent.instantsearch.mainIndex, widget => {
128
135
  results[widget.getIndexId()] = widget.getResults();
129
136
  });
130
137
 
@@ -201,6 +208,7 @@ function augmentInstantSearch(
201
208
  results: search.__initialSearchResults[result.indexId],
202
209
  })
203
210
  ),
211
+ parent,
204
212
  state,
205
213
  templatesConfig: {},
206
214
  createURL: parent.createURL,
@@ -258,7 +266,6 @@ export function createServerRootMixin(instantSearchOptions = {}) {
258
266
  const {
259
267
  searchClient,
260
268
  indexName,
261
- renderToString,
262
269
  $cloneComponent = defaultCloneComponent,
263
270
  } = instantSearchOptions;
264
271
 
@@ -268,18 +275,11 @@ export function createServerRootMixin(instantSearchOptions = {}) {
268
275
  );
269
276
  }
270
277
 
271
- if (!renderToString) {
272
- throw new Error(
273
- 'createServerRootMixin requires `renderToString: (app) => Promise<string>` in the first argument'
274
- );
275
- }
276
-
277
278
  const search = augmentInstantSearch(
278
279
  instantSearchOptions,
279
280
  searchClient,
280
281
  indexName,
281
- $cloneComponent,
282
- renderToString
282
+ $cloneComponent
283
283
  );
284
284
 
285
285
  // put this in the user's root Vue instance