algolia / react-instantsearch

⚡️ Lightning-fast search for React and React Native applications, by Algolia.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/react/
MIT License
1.97k stars 386 forks source link

feat(getServerState): allow users to inject renderToString #3658

Closed Haroenv closed 1 year ago

Haroenv commented 1 year ago

Summary

There are some cases where the combination of trying to make sure renderToString doesn't end up in a browser bundle, being runnable on esm + cjs, react 17 and 18, .js extension etc. blows up.

One of those is pnpm/vercel removing "unused" packages.

Result

This PR introduces a new argument renderToString to getServerState so you can inject the dependency yourself, meaning the import is within your own code and won't be purged.

import { renderToString } from 'react-dom/server';
await getServerState(<App/>, renderToString);
await getServerState(<App/>, import('react-dom/server').then(mod => mod.renderToString));

fixes #3633 closes #3618 see vercel/next.js#40067 FX-1869

codesandbox-ci[bot] commented 1 year ago

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.

Latest deployment of this branch, based on commit 8a21a6fbf2d376a894455845be8762ba2d30a13d:

Sandbox Source
react-instantsearch-app Configuration
hooks-example Configuration
hooks-next-example Issue #3633
netlify[bot] commented 1 year ago

Deploy Preview for react-instantsearch ready!

Name Link
Latest commit 8a21a6fbf2d376a894455845be8762ba2d30a13d
Latest deploy log https://app.netlify.com/sites/react-instantsearch/deploys/63510a599181f20007de96c6
Deploy Preview https://deploy-preview-3658--react-instantsearch.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

francoischalifour commented 1 year ago

Don't we want to be more cautious and have it in a param object?

await getServerState(<App/>, { renderToString });