Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
instantsearch-hooks-server: use literal imports
Browse files Browse the repository at this point in the history
Next.js build process (using pnpm) ends up not seeing these import
statements cause the import statements didn't have string literals.

The result was that it didn't put these dependencies in the nested
`node_modules` directory and thus this whole package breaks. Notably
this only fails in the production build and not the dev build.

This change is equivalent, we're just reformatting the code so the
literal import statements can be found by whatever tool Next.js is
using.
  • Loading branch information
danielbeardsley committed Sep 9, 2022
1 parent 93ee9d0 commit 54dc34c
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,13 @@ function getInitialResults(rootIndex: IndexWidget): InitialResults {
function importRenderToString() {
// React pre-18 doesn't use `exports` in package.json, requiring a fully resolved path
// Thus, only one of these imports is correct
const modules = ['react-dom/server.js', 'react-dom/server'];
const modules = [
import('react-dom/server.js').catch(() => {}),
import('react-dom/server').catch(() => {}),
];

// import is an expression to make sure https://github.com/webpack/webpack/issues/13865 does not kick in
return Promise.all(modules.map((mod) => import(mod).catch(() => {}))).then(
return Promise.all(modules).then(
(imports: unknown[]) => {
const ReactDOMServer = imports.find(
(mod): mod is { renderToString: typeof reactRenderToString } =>
Expand Down

0 comments on commit 54dc34c

Please sign in to comment.