algolia / instantsearch

⚡️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/
MIT License
3.73k stars 525 forks source link

Circular dependency in `react-instantsearch-core` #6292

Closed andrewgaun closed 4 months ago

andrewgaun commented 4 months ago

🐛 Current behavior

Found a circular dependency in your dist code when rolling up a project.

(!) Circular dependency
node_modules/react-instantsearch/node_modules/react-instantsearch-core/dist/es/index.js -> node_modules/react-instantsearch/node_modules/react-instantsearch-core/dist/es/server/index.js -> node_modules/react-instantsearch/node_modules/react-instantsearch-core/dist/es/server/getServerState.js -> node_modules/react-instantsearch/node_modules/react-instantsearch-core/dist/es/index.js

🔍 Steps to reproduce

1) npm install react-instantsearch 2) create a js file with import * from 'react-instantsearch' 3) compile with rollup

Live reproduction

N/A

💭 Expected behavior

The code would ideally not have a circular dependency. I believe if the imports in getServerState.js were updated to point directly to the composites, this issue would be resolved.

import type { InstantSearchServerState, InstantSearchSSRProvider } from '../component/InstantSearchSSRProvider';
import type { InstantSearchServerContextApi, InstantSearchServerContext } from '../component/InstantSearchServerContext';

^ Not sure if this is valid but figure it is something along these lines :)

Package version

react-instantsearch-core 7.12.2

Operating system

No response

Browser

No response

Code of Conduct

Haroenv commented 4 months ago

Good catch, we didn't have code to prevent circles in those packages, only in InstantSearch.js apparently. I just fixed the circular dependency and ensured we can't accidentally add the loop later in https://github.com/algolia/instantsearch/pull/6294

Haroenv commented 4 months ago

This will be released when we next do a release, thanks