Skip to content

fix(umd): remove chat components from react umd bundle#6714

Merged
Haroenv merged 2 commits intomasterfrom
fix/umd-builds
Sep 25, 2025
Merged

fix(umd): remove chat components from react umd bundle#6714
Haroenv merged 2 commits intomasterfrom
fix/umd-builds

Conversation

@dhayab
Copy link
Copy Markdown
Member

@dhayab dhayab commented Sep 24, 2025

Summary

This PR updates react-instantsearch to not export useChat and Chat on the UMD bundle, since we're not bundling ai. There are also changes to the UMD test file in order to add more in-depths assertions and additionally cover react-instantsearch-core + vue-instantsearch (vue3).

FX-3530

const createConfiguration = ({ name, minify = false } = {}) => ({
input: 'src/index.ts',
input: 'src/index.umd.ts',
external: ['react', 'ai'],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I left 'ai' as external here, otherwise we would have to update all hook imports in widgets, which is not worth it. Marking 'ai' as external has no impact on the UMD bundle.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What change would be needed if ai is not marked as external? and how come this doesn't throw on usage without ai?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You would need to update all hook imports in all widgets, ie:

-import { useBreadcrumb } from 'react-instantsearch-core';
+import { useBreadcrumb } from 'react-instantsearch-core/es/index.umd';

Rollup fails otherwise because, even if it will tree shake the imports, it will still traverse and read them. Because useChat is available from 'react-instantsearch-core', it will reach zod which will fail the process.

It doesn't fail on usage because no export of ai is actually referenced in the bundle.

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Sep 24, 2025

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.

@dhayab dhayab requested review from a team, FabienMotte and aymeric-giraudet and removed request for a team September 24, 2025 12:09
@dhayab dhayab changed the title fix(umd): remove ai components from react umd bundle fix(umd): remove chat components from react umd bundle Sep 24, 2025
Copy link
Copy Markdown
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

thanks!

Comment thread packages/react-instantsearch-core/src/index.umd.ts
Comment thread packages/react-instantsearch/src/widgets/index.umd.ts
Comment on lines +11 to +12
export const SearchIndexToolType = undefined;
export const createDefaultTools = () => {};
Copy link
Copy Markdown
Member Author

@dhayab dhayab Sep 24, 2025

Choose a reason for hiding this comment

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

These should probably move to ui-components or js/lib/chat in the future.

@Haroenv Haroenv merged commit 3d324d0 into master Sep 25, 2025
14 checks passed
@Haroenv Haroenv deleted the fix/umd-builds branch September 25, 2025 15:11
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