Unbundle dependencies from `@docsearch/js`
rschristian opened this issue · 0 comments
Description
preact
and @docsearch/react
are listed as dependencies of @docsearch/js
, however, both are inlined into the bundles. This totally breaks any usage of Docsearch on a Preact site as Preact, like React, requires that it be a singleton in order for functionality like hooks to work. Preact being bundled will always result in an additional copy being loaded.
This also introduces an additional issue in that most CDNs will try to (helpfully) provide listed dependencies
of modules. With this setup, that means each of these modules are downloaded twice: once inlined into the bundle, and another time as a separate module. Now this can be worked around in some CDNs, but still isn't ideal, as the default behavior causes wasted network trips.
Steps to reproduce
- Load up NPM's code viewer (which annoyingly doesn't allow for direct links to files): https://www.npmjs.com/package/@docsearch/js?activeTab=code
- Look in the ESM bundle and spot Preact.
- If you don't know what you're looking for,
ctrl + f
forxlink
and you'll spot this line
Live reproduction:
N/A
Expected behavior
They're either dependencies or they're bundled, not both.
Environment
- OS: N/A
- Browser: N/A
- DocSearch version: 3.6.0