typesense / typesense-instantsearch-adapter

A JS adapter library to build rich search interfaces with Typesense and InstantSearch.js
MIT License
361 stars 62 forks source link

Adapter causes Remix bundle bloat #180

Closed grinkus-adapt closed 10 months ago

grinkus-adapt commented 11 months ago

Description

I am not sure if it's the adapter or Remix doing something funky, but it seems that crypto is being polyfilled because of it's use in the typesense-instantsearch-adapter.

I've created two repositories to reproduce the issue. One uses Next.js, the other uses Remix. They have three pages each: a simple page without search, a page that uses algolia's instantsearch using algolia and a page that uses algolia's instantsearch using typesense via the adapter. The largest bundle on the adapter-search page on Next.js is at about 300 kb, while on Remix the largest bundle is at a whopping 1.7 mb. I've added screenshots of the Coverage panel of each of the pages in the readme files on each of the repro repositories.

Behavior

Looking at the bundle analyzer chart that's generated by uploading the metafile it seems that crypto is being polyfilled because of it's use in the typesense-instantsearch-adapter

image

image

Coverage of Next.js version

image

Coverage of Remix version

image

grinkus-adapt commented 11 months ago

kiliman went around the issue by using crypto-js instead of crypto in a comment on https://github.com/remix-run/remix/issues/7095#issuecomment-1668355646. Maybe that's the way to go?

markdalgleish commented 10 months ago

This is an issue in Remix due to our Node polyfills plugin overriding esbuild's package.json browser field support. I've submitted a PR fixing this upstream: https://github.com/imranbarbhuiya/esbuild-plugins-node-modules-polyfill/pull/150. I think this PR can be closed.

grinkus-adapt commented 10 months ago

This is an issue in Remix due to our Node polyfills plugin overriding esbuild's package.json browser field support. I've submitted a PR fixing this upstream: imranbarbhuiya/esbuild-plugins-node-modules-polyfill#150. I think this PR can be closed.

Using v1.5 of esbuild-plugins-node-modules-polyfill fixes the issue and crypto is no longer included in the browser bundle.