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

Commit

Permalink
chore(release): 6.0.0-beta.1 (#2861)
Browse files Browse the repository at this point in the history
* refactor(DOMMaps): use new React Context API (#2023)

* fix(maps): migrate to new React Context API

* refactor(maps): update context props to TypeScript

* refactor(maps): rename context types

* fix(maps): provide default context values

* fix(maps): remove `displayName`s

* test(maps): remove getStateContext function uses

* fix(maps): use React ref API

* fix(maps): update context usage

- Pass state from provider
- Pass context as props to children

* test(maps): implement Connected tests

* style(maps): lint files

* test(maps): test withGoogleMaps

* test(maps): update GoogleMaps tests

* fix(maps): set the state only once

* fix(maps): add ref to map element

* fix(maps): use static field for state

* test(maps): inline props in test

* fix(maps): use class field in Provider

* fix(maps): render provider when map is ready

* fix(maps): memoize values passed to context in Provider

* test(maps): test GoogleMaps context

* fix(maps): return undefined in GeoSearchContext

* revert: fix(maps): return undefined in GeoSearchContext

This reverts commit 3733602.

* chore(tslint): disable no-empty rule

* test(maps): inline props in Redo test

* fix(maps): apply changes

* fix(maps): cast default GoogleMapsContext values

* test(maps): test Provider mapValue reference

* fix(maps): add comment on GoogleMapsContext

* test(maps): update GoogleMaps tests

* feat(context): migrate to new React context (#2178)

This PR is quite long, but is split up in these steps

- [x] **STEP 1**: migrate createConnector (#2178, this PR)
- [x] **STEP 2**: first PR with connectors (searchbox, configure, hits, pagination) (#2179)
- [x] **STEP 3**: other connectors (#2180)
- [x] **STEP 4**: Multi index core (#2181)
- [x] **STEP 5**: Multi index connectors (#2185)
- [x] **STEP 6**: SSR (#2192)
- [ ] **STEP 7**: TypeScript completion (#2189) (merged later)
- [x] **STEP 8**: documentation change (#2190)

* feat(context): migrate core [STEP 1]

This includes:

1. change to createConnector
2. change to createStore
3. skip failing tests
4. small nits found while coding

After this to do:

STEP 2: first PR with connectors (searchbox, configure, hits, pagination)
STEP 3+: other connectors
STEP 4: Multi index core
STEP 5+: Multi index connectors
STEP 6: SSR
STEP 7: TypeScript completion
STEP 8: documentation change

* chore: remove context cache

* chore(tslint): add back accidentally removed prettier

* fix(connector): call gPP with correct "this"

* chore(TS): ReactType for Root

* test(connector): swap mount for shallow where possible

* chore(InstantSearch): refactor branch

* test(InstantSearch): avoid mutation

* chore(connector): remove unused

* chore(createConnector): warn on creation instead of mount

* fix(connector): remove unused variable

* chore(connector): consistent if

* chore(store): simplify typing

* chore(stories): better display name

* chore(TS): fix typing of results

* chore: remove useless comments

* consistent naming

* fix(InstantSearch): update index name when it changes

* prettier

* chore: remove old comment

* chore: fix merge

* ci: remove no-empty rule

* fix: make TS work in new connectors

* chore: fix bundlesize

* feedback from review (remove comments & warning)

* more review comments

* Update packages/react-instantsearch-core/src/components/InstantSearch.tsx

Co-Authored-By: Haroenv <fingebimus@me.com>

* feat(context): migrate base connector [STEP 2] (#2179)

* feat(context): migrate core [STEP 1]

This includes:

1. change to createConnector
2. change to createStore
3. skip failing tests
4. small nits found while coding

After this to do:

STEP 2: first PR with connectors (searchbox, configure, hits, pagination)
STEP 3+: other connectors
STEP 4: Multi index core
STEP 5+: Multi index connectors
STEP 6: SSR
STEP 7: TypeScript completion
STEP 8: documentation change

* feat(context): migrate base connector [STEP 2]

This is enough changes to be able to look at the storybook without errors again (only pagination, hits, searchbox of course, and nothing multi-index)

For full roadmap, see #2178

* test(configure): test with non-global this

* chore: from merge

* chore: updat bundle size

* chore: remove stuff from bad merge

* feedback from review

* feat(context): migrate remaining connectors [STEP 3] (#2180)

* feat(context): migrate remaining connectors [STEP 3]

chore: remove wrong import

test(currentRefinements): remove unused context

chore(range): fix typo

fix(geoSearch): gSP

test: call connectors with unique context where possible

feedback from review

chore(infiniteHits): cleaner test

refactor: migrate new connectors

chore: prettier

fix context

default props

fix TS

chore: small fix

* feat(context): multi-index [STEP 4] (#2181)

* feat(context): migrate remaining connectors [STEP 3]

* chore: remove wrong import

* test(currentRefinements): remove unused context

* chore(range): fix typo

* fix(geoSearch): gSP

* test: call connectors with unique context where possible

* feedback from review

* chore(infiniteHits): cleaner test

* refactor: migrate new connectors

* chore: prettier

* fix context

* default props

* fix TS

* chore: small fix

* feat(context): multi-index [STEP 4]

  test(Index): re-enable and make work

  fix(Index): allow context to be empty initially

  fix(Index): onSearchParameters with correct context

  fix(connector): onSearchParameters with correct context

  chore(Index): remove else

  chore(Index): consistent integration test

  chore: clarify test

  chore: fix life cycle

  fix(ts): index context can be undefined

  feedback from review

  fix(index): correct life cycles

  fix TS on Index

  connectorWrapper

  chore: update snapshots

* feat(context): apply multi-index [STEP 5] (#2185)

Co-Authored-By: samouss <samouss@users.noreply.github.com>

  * feat(context): modify Index to use modern context

  * test(Index): re-enable and make work

  * fix(Index): allow context to be empty initially

  * fix(Index): onSearchParameters with correct context

  * fix(connector): onSearchParameters with correct context

  * chore(Index): remove else

  * chore(Index): consistent integration test

  * chore: clarify test

  * chore: fix life cycle

  * fix(ts): index context can be undefined

  * feedback from review

  * fix(index): correct life cycles

  * fix TS on Index

  * connectorWrapper

  * chore: update snapshots

  * feat(context): modify Index to use modern context

  * feat(context): apply multi-index [STEP 5]

  1. connectMenu

  * connectAutoComplete

  * connectBreadcrumb

  * connectConfigure

  * connectGeoSearch

  * connectHierarchicalMenu

  * connectHits

  * connectHitsPerPage

  * connectInfiniteHits

  * connectNumericMenu

  * connectPagination

  * connectStats

  * connectRange

  * connectRefinementList

  * connectScrollTo

  * connectSearchBox

  * test(hierarchical): remove shadowing

  * connectSortBy

  * connectStateResults

  * connectToggleRefinement

  * fix(configure): use multi-index context

  * chore(configure): replace lodash.omit by spreading

  * test(connectors): call changing context

  * chore(configure): less lodash

  * test(configure): more detailed test

  * chore(test): rename ctx to instance

  * chore: move test

  * suggestions from review (mainly making multi-index tests more interesting)

  * chore: fix bundlesize

  * wrong conflict

  * migrate connectQueryRules

  * Feedback from review

  * fix(hitInsights): re-enable multi-index tests

* feat(context): re-enable SSR [STEP 6] (#2192)

  * chore(ssr): unskip tests

  * test(ssr): better test implem

  * chore: remove unused file

  * test: more consistent mock

* docs(connectors): fix spelling [STEP 8] (#2190)

  These are misc fixes in spelling that didn't exactly fit in a different PR

  remove small typo

* chore(context): migrate Panel (#2203)

* chore(context): migrate Panel

This migration is fairly straightforward, and has no impact on how the PanelCallbackHandler is used, although it adds a new component in that tree so it can read the context

IFW-485

* refactor(lodash): pick (#2432)

* refactor(lodash): pick

replaced by destructuring

* chore: remove isEmpty variable

* chore(utils): rename to TS

* chore(TS): rename dom utils

* chore(TS): add minor types to dom utils

* chore(TS): ignore lint rule

* refactor(lodash): range (#2444)

IFW-739

* fix(createConnector): new life cycles (#2357)

* fix(createConnector): new life cycles

- move willMount -> constructor
- move willReceiveProps -> didUpdate

This didn't have an impact on more requests, but did cause one more render if you update a prop

IFW-671

* remove comment

* test(sCU): shouldComponentUpdate is called two separate times now

* refactor(lodash): remove fill (#2454)

I replaced this by the `range` utility merged earlier, since it's basically what was needed here.

IFW-741

* refactor(lodash): remove difference (#2455)

Both are arrays & always defined, so it's really enough to find all props in this._props (prevProps), but not in `props`

* refactor(lodash): remove zipWith (#2459)

* refactor(lodash): remove zipWith

IFW-737

* chore: add comment back

* refactor(lodash): replace isFinite (#2458)

* refactor(lodash): replace isFinite

lodash.isFinite is just `typeof value == 'number' && nativeIsFinite(value);`, so that's what I implemented

IFW-745

* chore: remove needless typeof

* refactor(lodash): isPlainObject (#2460)

* refactor(lodash): isPlainObject

The values this function was used for seemed like they can only be arrays or objects to me.

We will only want to empty out "breadth-first", so empty objects will stay in the output if they became empty because of the function itself.

isEmpty here is removed in #2442, and still works the same (but will need a rebase)

The newly added tests also pass with the previous implementation

The function is only used in `onSearchStateChange` as a response to a `cleanUp` (caused by unmount) on a widget

IFW-743

* test: remove only

* chore(ts): use `unknown`

* refactor(lodash): replace find (#2446)

Chosen to duplicate the funciton in core & dom, because we have no good way to share functionality otherwise

IFW-740

* refactor(lodash): has (#2434)

* refactor(lodash): has

replace mostly by item[key] === undefined, which isn't completely the same, but close enough in our case, since rendering undefined would be quite weird.

BREAKING CHANGE:
translation will render default value if passed undefined as value

* chore(lodash): remove imports

* fix(translation): allow undefined value to be passed on purpose

*  refactor(lodash): replace isEqual (#2467)

* refactor(lodash): replace isEqual

1. specified function for maps

IFW-735

* refactor(lodash): replace isEqual with fast-deep-equal

* refactor(lodash): replace omit (#2466)

* refactor(lodash): omit (dom)

In this case, you can simply override a prop, which will take preference, like in any other object.

* refactor(omit): use internal (babel) replacement

* refactor(omit): use destructuring replacement

* refactor(indexUtils): use new omit where possible

* refactor(indexutils): remove omit with path

* chore: fix merge

* chore(size): update

* chore(life cycle): add comments where change is necessary

* fix(compat): upgrade SearchBox lifecycle (#2288)

* fix(compat): upgrade RangeSlider lifecycle (#2290)

* fix(compat): upgrade RangeInput lifecycle (#2289)

* fix(compat): upgrade Tourism example lifecycles (#2305)

* feat(client): remove algoliaClient, appId & apiKey (#2338)

* feat(client): remove algoliaClient alias

* chore(error): remove duplicate colon

* docs(examples): use searchClient everywhere

* feat(searchClient): remove other options

* adds back user agent tests & remove defaultAlgoliaClient

* remove algoliasearch from dependencies

* remove algoliasearch usage

* chore: update max size

* fix(propTypes): more strict searchClient type

* chore(examples): add algoliasearch as dependency

* chore(stories): memoize search client

* chore: update proptype

* refactor(lodash): get (#2461)

* refactor(lodash): get

IFW-742

BREAKING CHANGE: no longer do we allow paths like `attribute[5].something`, or other indexed forms, only `.` is allowed as special key.

All existing tests still pass, and we never documented you could use `lodash.get` patterns other than `.`.

* feat(get): accept array & bracked-separated string

moved to utils at the same time

* fix typo

* feedback: test for undefined behaviour

* chore(size): update expectation

this will go down afterwards, but for now there's some more duplication

* refactor(lodash): isEmpty (#2442)

* refactor(lodash): isEmpty

reusing objectHasKeys strategy from the helper

IFW-736

* refactor(lodash): remove isEmpty from server

* chore(TS): clearer type

* feedback: don't use objectHasKeys for array

* fix implementation

* refactor(example): remove lodash

* fix(numeric): correct reimplementation of !isEmpty

* chore(size): update expectation

somewhat bigger for now, but in the long run it'll shrink

* fix(compat): upgrade React Router example lifecycles (#2307)

* fix(compat): upgrade React Router v3 example lifecycles (#2314)

* fix(compat): upgrade React Native example and its lifecycles (#2304)

* fix(compat): upgrade Next.js example lifecycles (#2379)

* fix(compat): update Next example

* fix(compat): use last Next router

* fix(createInstantSearchManager): do not trigger search on index update (#2552)

* fix(createInstantSearchManager): do not trigger search on index update

* fix(createInstantSearchManager): add comment in updateIndex

* feat(ssr): update the SSR API (#2555)

* feat(ssr): only expose findResultsState [PART-1] (#2536)

* feat(ssr): hydrate client [PART-2] (#2537)

* feat(ssr): update usage of the API [PART-3]

* refactor(root): remove createIndex & createInstantSearch (#2339)

* refactor(InstantSearch): migrate life cycles (#2349)

*  fix(createInstantSearchManager): fix multi-index search  (#2570)

* fix(createInstantSearchManager): fix multi-index search

* Fix tests

* Update bundlesize

* Map indexName prop to indexId when indexId is not defined

* Add tests

* Pass indexName through variable for clarity

* Simplify test

* Simplify other tests

* refactor(lodash): orderBy (#2462)

* refactor(lodash): orderBy

The utility is copied from the helper (which passed all lodash tests), I put it inline in the connector, since it's not used in any other spot.

IFW-746

* refactor(menu): remove orderBy & use helper method

These tests provide no security at all, but this change in behaviour can be confirmed in the stories.

* chore(indexUtils): make usage simpler

I caught this when trying to refactor the tests to use a real helper, but eventually decided not to do that

* chore: update test name

* chore: different if style

* chore(test): simplify

* chore: update sizes

* chore(size): looser limit

* simplify code

* chore: update bundlesize

* chore(lint): remove wrong merges

* chore(react-native): roll back react version

* chore(lint): small fix

* chore(ssr): fix example build

* chore(lodash): remove dependencies (#2600)

- lodash from packages
- babel-plugin-lodash from root
- swap out isEqual from connectInfiniteHits

IFW-778

closes #2468

* fix(peerDependencies): update React (#2626)

* fix(peerDependencies): update React

We are now relying on React 16.3 features like `static getDerivedStateFromProps` in the library, which thus won't work with lower versions.

The lowest version of React Native which requires React 16.3 (albeit an alpha) is 0.54.0.

* !fixup

* refactor(helper): replace Helper usage (#2621)

* docs(MIGRATION): migrate to v6 (#2627)

* docs(MIGRATION): migrate to v6

* docs(MIGRATION): update wording

Co-Authored-By: Haroen Viaene <fingebimus@me.com>
Co-Authored-By: François Chalifour <francoischalifour@users.noreply.github.com>

* docs(MIGRATION): add snippet for appID & apiKey

* docs(MIGRATION): add algoliasearchHelper section

* fix(geo): remove lifecycle compat (#2644)

This is no longer necessary, since we now require React 16.3 as a peer dependency (#2626)

* docs(stories): remove stories whoich highlight a custom root (#2645)

This has been removed in #2339, so no longer works (nor necessary)

* fix(geo): check for undefined in isEqual (#2643)

issue introduced in #2467

IFW-851

* fix(highlight): switch to index as key (#2690)

the reason is that the full value could be duplicate, so we added the index; but the index can't be duplicate within the list.

* feat(autocomplete): add queryID & position to provided hits (#2687)

* feat(autocomplete): add queryID to provided hits if defined

This was accidentally forgotten when we added the queryID to hits & infinite hits.

IFW-902

* feat(autocomplete): add absolute position too

* Update packages/react-instantsearch-core/src/connectors/__tests__/connectAutoComplete.js

* fix(core): searchState can be non-Object object (#2722)

* fix(core): searchState can be non-Object object

If someone calls `Object.create(null)` and then adds the expected properties, `hasOwnProperty` will not be available on the object itself. 

fixes #2568

* fix(ssr): avoid duplicate serializing (#2726)

* fix(ssr): avoid duplicate serializing

Response of `findResultsState` (and `resultsState` prop) before:

```js
const resultsState = {
  content: SearchResults(state: searchParameters, results: rawResults),
  state: searchParameters,
  _originalResponse: {
    results: rawResults
  },
};
```

Note that `SearchResults` has the properties `_rawResults` & `_state`. This means that when we serialize, we are retrieving the original response and state twice.

Then on further searching, I also find that we don't need to serialize the `SearchResults` object at all, since only the raw response and state is used.

I modified this to be more consistent and no longer have duplication:

```js
const resultsState = {
  state: searchParameters,
  rawResults,
};
```

The `SearchParameters` object gets serialized without issue, as before.

This change in shape has of course also an impact on the shape of `resultsState`, the prop, but that is fine, since it was previously typed as `any`.

To be able to type it correctly, I had to add `@types/algoliasearch` & update `algoliasearch-helper` for typescript though.

This was initially noticed by @cloakedninjas, thanks!

* empty commit for CI

* chore: fix linting for next

* chore: fix lint again 🤔

* chore(examples): downgrade react in rn example

* v6.0.0-beta.0

# [6.0.0-beta.0](v5.7.0...v6.0.0-beta.0) (2019-08-21)

### Bug Fixes

* **compat:** upgrade Next.js example lifecycles ([#2379](#2379)) ([45939bc](45939bc))
* **compat:** upgrade RangeInput lifecycle ([#2289](#2289)) ([110b1af](110b1af))
* **compat:** upgrade RangeSlider lifecycle ([#2290](#2290)) ([69a7f53](69a7f53))
* **compat:** upgrade React Native example and its lifecycles ([#2304](#2304)) ([f390c17](f390c17))
* **compat:** upgrade React Router example lifecycles ([#2307](#2307)) ([ab828b0](ab828b0))
* **compat:** upgrade React Router v3 example lifecycles ([#2314](#2314)) ([3647154](3647154))
* **compat:** upgrade SearchBox lifecycle ([#2288](#2288)) ([c3ba42d](c3ba42d))
* **compat:** upgrade Tourism example lifecycles ([#2305](#2305)) ([fff5aa6](fff5aa6))
* **connectToggleRefinement:** cast currentRefinement to boolean ([#2701](#2701)) ([db934fd](db934fd))
* **core:** searchState can be non-Object object ([#2722](#2722)) ([dea493c](dea493c)), closes [#2568](#2568)
* **createConnector:** new life cycles ([#2357](#2357)) ([fc10640](fc10640))
* **createInstantSearchManager:** do not trigger search on index update ([#2552](#2552)) ([e209362](e209362))
* **deps:** update dependency antd to v3.19.3 ([#2530](#2530)) ([73636c5](73636c5))
* **deps:** update dependency antd to v3.19.4 ([#2559](#2559)) ([c3e8267](c3e8267))
* **deps:** update dependency antd to v3.19.5 ([#2560](#2560)) ([72efd31](72efd31))
* **deps:** update dependency antd to v3.19.6 ([#2564](#2564)) ([654f986](654f986))
* **deps:** update dependency antd to v3.19.7 ([#2573](#2573)) ([7e963ad](7e963ad))
* **deps:** update dependency antd to v3.19.8 ([#2584](#2584)) ([34dd9b2](34dd9b2))
* **deps:** update dependency antd to v3.20.0 ([#2611](#2611)) ([b976c67](b976c67))
* **deps:** update dependency antd to v3.20.1 ([#2635](#2635)) ([792ad9c](792ad9c))
* **deps:** update dependency antd to v3.20.2 ([#2655](#2655)) ([301c2d8](301c2d8))
* **deps:** update dependency antd to v3.20.3 ([#2658](#2658)) ([d078e70](d078e70))
* **deps:** update dependency antd to v3.20.5 ([#2686](#2686)) ([42ef821](42ef821))
* **deps:** update dependency antd to v3.20.6 ([#2711](#2711)) ([927fbfe](927fbfe))
* **deps:** update dependency antd to v3.20.7 ([#2712](#2712)) ([1830952](1830952))
* **deps:** update dependency antd to v3.21.1 ([#2736](#2736)) ([39a51a6](39a51a6))
* **deps:** update dependency antd to v3.21.2 ([#2738](#2738)) ([a7a998a](a7a998a))
* **deps:** update dependency antd to v3.21.4 ([#2747](#2747)) ([60012be](60012be))
* **deps:** update dependency antd to v3.22.0 ([#2758](#2758)) ([9cda468](9cda468))
* **deps:** update dependency lodash to v4.17.13 ([c4974cf](c4974cf))
* **deps:** update dependency lodash to v4.17.14 ([#2647](#2647)) ([a2d2dd5](a2d2dd5))
* **deps:** update dependency lodash to v4.17.15 ([#2684](#2684)) ([354143f](354143f))
* **deps:** update dependency next to v9 ([#2638](#2638)) ([d22f61d](d22f61d))
* **deps:** update dependency next to v9.0.1 ([#2652](#2652)) ([2c2dab9](2c2dab9))
* **deps:** update dependency next to v9.0.2 ([#2662](#2662)) ([6fa4c5e](6fa4c5e))
* **deps:** update dependency next to v9.0.3 ([#2724](#2724)) ([f51b04b](f51b04b))
* **deps:** update dependency next to v9.0.4 ([#2767](#2767)) ([9af9180](9af9180))
* **deps:** update dependency qs to v6.8.0 ([#2757](#2757)) ([8bffb87](8bffb87))
* **deps:** update dependency react-compound-slider to v2.1.0 ([#2610](#2610)) ([3389ee5](3389ee5))
* **deps:** update dependency react-compound-slider to v2.2.0 ([#2649](#2649)) ([7b81af1](7b81af1))
* **deps:** update dependency react-native-vector-icons to v6.5.0 ([#2520](#2520)) ([5f7f5b6](5f7f5b6))
* **deps:** update dependency react-native-vector-icons to v6.6.0 ([#2599](#2599)) ([b6bb199](b6bb199))
* **deps:** update dependency react-router-dom to v5.0.1 ([#2506](#2506)) ([d762230](d762230))
* **geo:** check for undefined in isEqual ([#2643](#2643)) ([a544231](a544231)), closes [#2467](#2467)
* **geo:** remove lifecycle compat ([#2644](#2644)) ([2b2b898](2b2b898)), closes [#2626](#2626)
* **highlight:** switch to index as key ([#2690](#2690)) ([51de682](51de682))
* **highlight:** switch to index as key ([#2691](#2691)) ([17e75d1](17e75d1)), closes [#2688](#2688)
* **peerDependencies:** update React ([#2626](#2626)) ([6ccad49](6ccad49))
* **ssr:** avoid duplicate serializing ([#2726](#2726)) ([c768b1a](c768b1a))
* **voiceSearch:** fix incorrect status on stop ([#2535](#2535)) ([824dc22](824dc22))

### Code Refactoring

* **lodash:** get ([#2461](#2461)) ([527b879](527b879))
* **lodash:** has ([#2434](#2434)) ([75a4a15](75a4a15))

### Features

* **autocomplete:** add queryID & position to provided hits ([#2687](#2687)) ([e453dab](e453dab))
* **client:** remove algoliaClient, appId & apiKey ([#2338](#2338)) ([b84a0b5](b84a0b5))
* **context:** migrate to new React context ([#2178](#2178)) ([0a1abea](0a1abea)), closes [#2179](#2179) [#2180](#2180) [#2181](#2181) [#2185](#2185) [#2192](#2192) [#2189](#2189) [#2190](#2190) [#2179](#2179) [#2180](#2180) [#2181](#2181) [#2185](#2185) [#2192](#2192) [#2190](#2190)
* **ssr:** update the SSR API ([#2555](#2555)) ([925bdb8](925bdb8)), closes [#2536](#2536) [#2537](#2537)

### BREAKING CHANGES

* **lodash:** no longer do we allow paths like `attribute[5].something`, or other indexed forms, only `.` is allowed as special key.

All existing tests still pass, and we never documented you could use `lodash.get` patterns other than `.`.

* feat(get): accept array & bracked-separated string

moved to utils at the same time

* fix typo

* feedback: test for undefined behaviour

* chore(size): update expectation

this will go down afterwards, but for now there's some more duplication
* **lodash:** translation will render default value if passed undefined as value

* chore(lodash): remove imports

* fix(translation): allow undefined value to be passed on purpose

* chore(deps): update examples to react-instantsearch v6.0.0-beta.0

* chore(index): don't require `indexId` on `IndexWrapper` (#2834)

* Don't require `indexId` proptype on Index widget wrapper

* Use unique type for IndexWrapper props

* merge branch master into next

* test(examples): update snapshots (#2845)

* fix(ssr): add error when no indexName is passed (#2842)

* fix(InstantSearch): update the searchState on props update (#2852)

**Summary**

This PR fixes an issue where an infinite loop occurs with the controlled mode. The update of the `searchState` was done too late. With V5 the update was done inside `cWRP` but with V6 we move the update inside `cDU`. This change has an impact on when the `searchState` is updated. With `cWRP` it was executed before the `render` of the children, it's not the case anymore with `cDU`. It's done after.

Those children can read the `searchState` provided by the manager. When it's not up to date they alter the previous version of the state. With an `onSearchStateChange` function that relies on the value of `searchState` to add remove parameters, it can lead to infinite loop because the props are changes/reverted at each render.

The fix uses `getDerivedStateFromProps` to keep the `searchState` up to date. The issue with this solution (on V5 too) is that we might trigger one useless request when the props change. It's because the update and the search are tied together inside `onExternalStateUpdate`. One solution to this would be to decouple the two. Apply the `searchState` update as soon as possible but trigger the search on `cDU` once we've computed the state from the children.

**Before**

![before](https://user-images.githubusercontent.com/6513513/66131368-9c15d180-e5f3-11e9-9aad-c46ea6fca340.gif)

**After**

![after](https://user-images.githubusercontent.com/6513513/66131378-9f10c200-e5f3-11e9-8980-e6a6e5d626a4.gif)

* refactor(example): remove usage of aroundLatLng (#2853)

**Summary**

This PR removes the usage of `aroundLatLng` inside the geo-search example. The logic to apply the parameter was present, but the App doesn't expose a way to use it. We don't have to support it since it uses either the IP of the user of the bounding box of the map.
  • Loading branch information
tkrugg authored Oct 18, 2019
1 parent 4906170 commit cb56ca0
Show file tree
Hide file tree
Showing 240 changed files with 24,700 additions and 17,389 deletions.
22 changes: 21 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
module.exports = {
/**
* @type {import('eslint').Linter.Config}
*/
const config = {
extends: ['algolia', 'algolia/jest', 'algolia/react', 'algolia/typescript'],
rules: {
'no-param-reassign': 'off',
// @TODO: to remove once `eslint-config-algolia` ships the change
'valid-jsdoc': 'off',
// @TODO: remove once this is in `eslint-config-algolia`
'@typescript-eslint/explicit-member-accessibility': 'off',
// @TODO: re-enable this once the code base is made for it
'@typescript-eslint/consistent-type-assertions': 'off',
// @TODO: re-enable once the rule is properly setup for monorepos
// https://github.com/benmosher/eslint-plugin-import/issues/1103
// https://github.com/benmosher/eslint-plugin-import/issues/1174
Expand All @@ -23,4 +30,17 @@ module.exports = {
},
},
},
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
// This rule has issues with the TypeScript parser, but tsc catches
// these sorts of errors anyway.
// See: https://github.com/typescript-eslint/typescript-eslint/issues/342
'no-undef': 'off',
}
}
]
};

module.exports = config;
77 changes: 77 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
# [6.0.0-beta.0](https://github.com/algolia/react-instantsearch/compare/v5.7.0...v6.0.0-beta.0) (2019-08-21)

[Migration guide](MIGRATION.md)

### Bug Fixes

* **react 17 compat:** upgrade RangeInput lifecycle ([#2289](https://github.com/algolia/react-instantsearch/issues/2289)) ([110b1af](https://github.com/algolia/react-instantsearch/commit/110b1af))
* **react 17 compat:** upgrade RangeSlider lifecycle ([#2290](https://github.com/algolia/react-instantsearch/issues/2290)) ([69a7f53](https://github.com/algolia/react-instantsearch/commit/69a7f53))
* **connectToggleRefinement:** cast currentRefinement to boolean ([#2701](https://github.com/algolia/react-instantsearch/issues/2701)) ([db934fd](https://github.com/algolia/react-instantsearch/commit/db934fd))
* **core:** searchState can be non-Object object ([#2722](https://github.com/algolia/react-instantsearch/issues/2722)) ([dea493c](https://github.com/algolia/react-instantsearch/commit/dea493c)), closes [#2568](https://github.com/algolia/react-instantsearch/issues/2568)
* **createConnector:** new React life cycles ([#2357](https://github.com/algolia/react-instantsearch/issues/2357)) ([fc10640](https://github.com/algolia/react-instantsearch/commit/fc10640))
* **createInstantSearchManager:** do not trigger search on index update ([#2552](https://github.com/algolia/react-instantsearch/issues/2552)) ([e209362](https://github.com/algolia/react-instantsearch/commit/e209362))
* **geo:** check for undefined in isEqual ([#2643](https://github.com/algolia/react-instantsearch/issues/2643)) ([a544231](https://github.com/algolia/react-instantsearch/commit/a544231)), closes [#2467](https://github.com/algolia/react-instantsearch/issues/2467)
* **geo:** remove lifecycle compat ([#2644](https://github.com/algolia/react-instantsearch/issues/2644)) ([2b2b898](https://github.com/algolia/react-instantsearch/commit/2b2b898)), closes [#2626](https://github.com/algolia/react-instantsearch/issues/2626)
* **highlight:** switch to index as key ([#2690](https://github.com/algolia/react-instantsearch/issues/2690)) ([51de682](https://github.com/algolia/react-instantsearch/commit/51de682)), closes [#2688](https://github.com/algolia/react-instantsearch/issues/2688)
* **peerDependencies:** update React ([#2626](https://github.com/algolia/react-instantsearch/issues/2626)) ([6ccad49](https://github.com/algolia/react-instantsearch/commit/6ccad49))
* **ssr:** avoid duplicate serializing ([#2726](https://github.com/algolia/react-instantsearch/issues/2726)) ([c768b1a](https://github.com/algolia/react-instantsearch/commit/c768b1a))
* **voiceSearch:** fix incorrect status on stop ([#2535](https://github.com/algolia/react-instantsearch/issues/2535)) ([824dc22](https://github.com/algolia/react-instantsearch/commit/824dc22))


### Code Refactoring

* **lodash:** get ([#2461](https://github.com/algolia/react-instantsearch/issues/2461)) ([527b879](https://github.com/algolia/react-instantsearch/commit/527b879))
* **lodash:** has ([#2434](https://github.com/algolia/react-instantsearch/issues/2434)) ([75a4a15](https://github.com/algolia/react-instantsearch/commit/75a4a15))
* **lodash:** has been fully removed

### Features

* **autocomplete:** add queryID & position to provided hits ([#2687](https://github.com/algolia/react-instantsearch/issues/2687)) ([e453dab](https://github.com/algolia/react-instantsearch/commit/e453dab))
* **client:** remove algoliaClient, appId & apiKey ([#2338](https://github.com/algolia/react-instantsearch/issues/2338)) ([b84a0b5](https://github.com/algolia/react-instantsearch/commit/b84a0b5)) (use searchClient exclusively now)
* **context:** migrate to new React context ([#2178](https://github.com/algolia/react-instantsearch/issues/2178)) ([0a1abea](https://github.com/algolia/react-instantsearch/commit/0a1abea)), closes [#2179](https://github.com/algolia/react-instantsearch/issues/2179) [#2180](https://github.com/algolia/react-instantsearch/issues/2180) [#2181](https://github.com/algolia/react-instantsearch/issues/2181) [#2185](https://github.com/algolia/react-instantsearch/issues/2185) [#2192](https://github.com/algolia/react-instantsearch/issues/2192) [#2189](https://github.com/algolia/react-instantsearch/issues/2189) [#2190](https://github.com/algolia/react-instantsearch/issues/2190) [#2179](https://github.com/algolia/react-instantsearch/issues/2179) [#2180](https://github.com/algolia/react-instantsearch/issues/2180) [#2181](https://github.com/algolia/react-instantsearch/issues/2181) [#2185](https://github.com/algolia/react-instantsearch/issues/2185) [#2192](https://github.com/algolia/react-instantsearch/issues/2192) [#2190](https://github.com/algolia/react-instantsearch/issues/2190)
* **ssr:** update the SSR API ([#2555](https://github.com/algolia/react-instantsearch/issues/2555)) ([925bdb8](https://github.com/algolia/react-instantsearch/commit/925bdb8)), closes [#2536](https://github.com/algolia/react-instantsearch/issues/2536) [#2537](https://github.com/algolia/react-instantsearch/issues/2537)


### BREAKING CHANGES

* **searchClient:** argument is the only option now.

Previously there were three options to pass a search client: searchClient, appId & apiKey, algoliaClient. The latter two have been removed, and now only `searchClient` is accepted. This searchClient is an instance of the `algoliasearch` module:

```js
import algoliasearch from 'algoliasearch/lite';

const searchClient = algoliasearch(
'myAppId',
'myApiKey',
{ _useRequestCache: true }
);

// ...
<InstantSearch searchClient={searchClient} />
```

If you were relying on duplicate requests not being fired when using appId & apiKey before, you need to enable the `_useRequestCache` option now.

* **SSR:** imports have changed

In the server, you now directly import `findResultsState`, which now requires a `searchClient` in the second argument.

In the App, you now use a regular `InstantSearch` component.

* **Index & InstantSearch:** Remove `root` DOM element

These elements now are pure containers for their children, and don't add a `div` to the DOM anymore. If you were relying on those for styling, wrap the `InstantSearch` and `Index` element with a `div` with an appropriate class.

* **Index & InstantSearch:** Remove support for `root` prop

Since these two arguments now no longer wrap their children in an element, they no longer accept a `root` prop.

* **Highlight:** some paths will no longer be accepted

We only accept paths separated with a dot or bracket now, like before. It's possible that a different type of path worked undocumented, but no longer does.

* **algoliasearch-helper:** updating to the next major version

This library is mostly internal, but it has had a major refactor (including removing lodash). This has no impact, unless you are dealing with it using `createConnector`. See the [migration guide](https://github.com/algolia/algoliasearch-helper-js/blob/next/documentation-src/metalsmith/content/upgrade.md) for the v3 of algoliasearch-helper for more information.

# [5.7.0](https://github.com/algolia/react-instantsearch/compare/v5.6.0...v5.7.0) (2019-06-04)


Expand Down
156 changes: 156 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
## Upgrade to 6.x.x

This new major version of React InstantSearch leverages the [`Context`](https://reactjs.org/docs/context.html) API that has been released part of React 16.3.0. It means that now the **minimal required version for React InstantSearch is React 16.3.0**. We took this opportunity to make React InstantSearch compliant with the [`Strict`](https://reactjs.org/docs/strict-mode.html) mode too. Prior to this version, the library was not working with those constraints. Here is the list of APIs that have breaking changes:

### SSR

We made changes to the SSR API to use the `server` module only on the server. It was previously used on both client and server. Those changes in the API also simplify the flow of information and makes the SSR simpler to reason about. The neat addition that we've made to the API is the `searchClient` hydration. The request was done on the server, but also on the client when the app was mounted. Since the state is passed from the server to the client, the initial request on the client was useless. We're now able to avoid this initial request by re-using the results retrieved on the server.

```diff
// server.js

import React from 'react';
import { renderToString } from "react-dom/server";
+import { findResultsState } from "react-instantsearch-dom/server";
-import { App, findResultsState } from "./App";
+import { App } from "./App";

+const indexName = "instant_search";
+const searchClient = algoliasearch(
+ "latency",
+ "6be0576ff61c053d5f9a3225e2a90f76"
+);

server.get("/", async (req, res) => {
const initialState = {
- resultsState: await findResultsState(App)
+ resultsState: await findResultsState(App, {
+ indexName,
+ searchClient
+ })
};


const plainHTML = renderToString(<App {...initialState} />);

// ...
});
```

```diff
// browser.js

import React from 'react';
import { hydrate } from 'react-dom';
import { App } from './App';

+const indexName = "instant_search";
+const searchClient = algoliasearch(
+ "latency",
+ "6be0576ff61c053d5f9a3225e2a90f76"
+);

hydrate(
<App
{...window.__APP_INITIAL_STATE__}
+ indexName={indexName}
+ searchClient={searchClient}
/>,
document.getElementById("root")
);
```

```diff
// App.js

import React from "react";
-import algoliasearch from "algoliasearch/lite";
-import { createInstantSearch } from "react-instantsearch-dom/server";
-import { SearchBox } from "react-instantsearch-dom";
+import { InstantSearch, SearchBox } from "react-instantsearch-dom";

-const { InstantSearch, findResultsState } = createInstantSearch();

-const searchClient = algoliasearch(
- "latency",
- "6be0576ff61c053d5f9a3225e2a90f76"
-);

-const App = ({ resultsState }) => (
+const App = ({ indexName, searchClient, resultsState }) => (
<InstantSearch
- indexName="instant_search"
+ indexName={indexName}
searchClient={searchClient}
resultsState={resultsState}
>
<SearchBox />
</InstantSearch>
);

-export { App, findResultsState };
+export { App };
```

You can notice that we have some duplication inside the module `server` and `browser`. We have duplicated the declaration of `indexName` and `searchClient`. We can avoid this easily with a `createApp` function that returns the `App` and the `props` that we have to provide. You can find this pattern applied inside the complete example on [GitHub](https://github.com/algolia/react-instantsearch/tree/fbc89aa7a7c02e572081444ab4b5039e7b1df1a9/examples/server-side-rendering).

### Remove support for `appId` and `apiKey`

We've removed the support for `appId` & `apiKey` on `InstantSearch`. Those props were not documented anymore but they were still supported. The preferred solution is to use the prop [`searchClient`](https://www.algolia.com/doc/api-reference/widgets/instantsearch/react/#widget-param-searchclient) with the package the [`algoliasearch`](https://www.algolia.com/doc/api-client/getting-started/install/javascript/). The benefit of this change is that we don't ship `algoliasearch` anymore with React InstantSearch. When the `searchClient` used is not the Algolia one you don't pay the cost of it anymore.

```diff
import React from "react";
+import algoliasearch from "algoliasearch/lite";
import { InstantSearch, SearchBox } from "react-instantsearch-dom";

+const searchClient = algoliasearch(
+ "latency",
+ "6be0576ff61c053d5f9a3225e2a90f76"
+);

const App = () => (
<InstantSearch
- appId="latency"
- apiKey="6be0576ff61c053d5f9a3225e2a90f76"
indexName="instant_search"
+ searchClient={searchClient}
>
<SearchBox />
</InstantSearch>
);
```

### Remove support for `root` in `InstantSearch` and `Index`

We have introduced the support of the prop `root` in `InstantSearch` & `Index` to be able to render a specific element, with specific props at the root. Its usage is not useful anymore because we don't have a root element. The top-level element is the `Context.Provider` which does not render anything. You can move the element provided to `root` directly around `InstantSearch`. This is great news for our React Native users!

```diff
// ...

const App = () => (
+ <section style={{ display: 'flex' }}>
<InstantSearch
indexName="instant_search"
searchClient={searchClient}
- root={{
- Root: 'section',
- props: {
- style: {
- display: 'flex',
- },
- },
- }}
>
<SearchBox />
</InstantSearch>
+ <section>
);
```

### `algoliasearch-helper` 3.x.x

In this major release we also migrate to the next major release of the `algoliasearch-helper`. This means if at any point you interact with a `SearchResults` or `SearchParameters` object, the breaking changes there will also take effect here. For use in React InstantSearch this should be only when creating a custom connector using `createConnector`.

There will no longer be the default value of page (0) or query ('') in `SearchParameters`. Both of those will now be undefined if no value is given.

The function `getQueryParameter` has been removed in favor of simply calling the getter for that parameter.
1 change: 0 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = api => {
],
plugins: clean([
'@babel/plugin-proposal-class-properties',
'babel-plugin-lodash',
isRollup && 'babel-plugin-transform-react-remove-prop-types',
]),
overrides: [
Expand Down
3 changes: 2 additions & 1 deletion examples/autocomplete/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
"react-test-renderer": "16.8.6"
},
"dependencies": {
"algoliasearch": "3.32.1",
"antd": "3.23.2",
"lodash": "4.17.15",
"prop-types": "15.6.0",
"react": "16.8.6",
"react-autosuggest": "9.4.3",
"react-dom": "16.8.6",
"react-instantsearch-dom": "5.7.0"
"react-instantsearch-dom": "6.0.0-beta.0"
},
"browserslist": [
">0.2%",
Expand Down
12 changes: 7 additions & 5 deletions examples/autocomplete/src/App-Mentions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import Mention from 'antd/lib/mention';
import algoliasearch from 'algoliasearch/lite';
import { InstantSearch, connectAutoComplete } from 'react-instantsearch-dom';
import 'antd/lib/mention/style/css';

Expand All @@ -22,12 +23,13 @@ AsyncMention.propTypes = {

const ConnectedAsyncMention = connectAutoComplete(AsyncMention);

const searchClient = algoliasearch(
'latency',
'6be0576ff61c053d5f9a3225e2a90f76'
);

const App = () => (
<InstantSearch
appId="latency"
apiKey="6be0576ff61c053d5f9a3225e2a90f76"
indexName="actors"
>
<InstantSearch searchClient={searchClient} indexName="actors">
<ConnectedAsyncMention />
</InstantSearch>
);
Expand Down
12 changes: 7 additions & 5 deletions examples/autocomplete/src/App-Multi-Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import {
Highlight,
connectAutoComplete,
} from 'react-instantsearch-dom';
import algoliasearch from 'algoliasearch/lite';

const searchClient = algoliasearch(
'latency',
'6be0576ff61c053d5f9a3225e2a90f76'
);

const App = () => (
<InstantSearch
appId="latency"
apiKey="6be0576ff61c053d5f9a3225e2a90f76"
indexName="instant_search"
>
<InstantSearch searchClient={searchClient} indexName="instant_search">
<AutoComplete />
<Configure hitsPerPage={1} />
<Index indexName="bestbuy" />
Expand Down
8 changes: 7 additions & 1 deletion examples/autocomplete/src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import MultiIndex from './App-Multi-Index';
import Mentions from './App-Mentions';
import renderer from 'react-test-renderer';

jest.mock('antd/lib/mention');
jest.mock('antd/lib/mention', () => {
return ({ placeholder, suggestions }) =>
`<Mention>
${placeholder}
${suggestions.join('\n')}
</Mention>`;
});

describe('autocomplete recipe', () => {
it('MultiIndex renders without crashing', () => {
Expand Down
Loading

0 comments on commit cb56ca0

Please sign in to comment.