Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(instantsearch): make root indexName optional #5590

Merged
merged 6 commits into from
May 3, 2023

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Apr 12, 2023

requires algolia/algoliasearch-helper-js#938

Essentially this allows us to create neat non-inheriting indices like this with only three queries sent:

const App = (
  <InstantSearch>
    <Index indexName="1" indexId="1a" />
    <Index indexName="1" indexId="1b" />
    <Index indexName="2" />
  </InstantSearch>
);

Combined with algolia/react-instantsearch#3690 again, you could also create

// 🚨 this isn't possible yet
const App = (
  <InstantSearch>
    <Index indexName="1">
      {/* other widgets, causing no results */}
      <NoResults>
        <Index indexName="1" parentIndexId={null}>
          {/* display stuff from a separate query,
        without interference of inheritance */}
        </Index>
      </NoResults>
    </Index>
  </InstantSearch>
);

Summary

Allow for more flexible use cases to avoid inheritance of indices, like #5585 (comment), without custom code skipping the root index.

This does mean that if you forget the indexName, there's a new warning, and no rendering.

Result

  • IndexName of InstantSearch is optional
  • No query gets done for the root index if indexName isn't given

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 13, 2023

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 9653948:

Sandbox Source
InstantSearch.js Configuration
react-instantsearch-app Configuration
example-react-instantsearch-hooks-default-theme Configuration
example-vue-instantsearch-default-theme Configuration

requires algolia/algoliasearch-helper-js#938

Essentially this allows us to create neat non-inheriting indices like this with only three queries sent:

```jsx
const App = (
  <InstantSearch>
    <Index indexName="1" indexId="1a" />
    <Index indexName="1" indexId="1b" />
    <Index indexName="2" />
  </InstantSearch>
);
```

Combined with algolia/react-instantsearch#3690 again, you could also create

```jsx
// 🚨 this isn't possible yet
const App = (
  <InstantSearch>
    <Index indexName="1">
      {/* other widgets, causing no results */}
      <NoResults>
        <Index indexName="1" parentIndexId={null}>
          {/* display stuff from a separate query,
        without interference of inheritance */}
        </Index>
      </NoResults>
    </Index>
  </InstantSearch>
);
```
@Haroenv Haroenv force-pushed the feat/indexless-root branch from 45a73ff to 315a589 Compare April 26, 2023 08:36
@@ -33,7 +33,7 @@
"@types/google.maps": "^3.45.3",
"@types/hogan.js": "^3.0.0",
"@types/qs": "^6.5.3",
"algoliasearch-helper": "^3.11.3",
"algoliasearch-helper": "https://pkg.csb.dev/algolia/algoliasearch-helper-js/commit/6ca09d86/algoliasearch-helper",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this and the other references will need to be changed once that version is released

yarn.lock Show resolved Hide resolved
@Haroenv Haroenv marked this pull request as ready for review April 27, 2023 08:22
@Haroenv Haroenv requested review from a team, dhayab and FabienMotte and removed request for a team April 27, 2023 08:22
@Haroenv Haroenv requested a review from dhayab April 27, 2023 08:37
@Haroenv Haroenv merged commit 80f309e into master May 3, 2023
@Haroenv Haroenv deleted the feat/indexless-root branch May 3, 2023 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants