-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(getServerState): allow users to inject renderToString (algolia/r…
…eact-instantsearch#3658) **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. <!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. --> <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? Are there any linked issues? --> **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. ```js import { renderToString } from 'react-dom/server'; await getServerState(<App/>, renderToString); await getServerState(<App/>, import('react-dom/server').then(mod => mod.renderToString)); ``` <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. --> fixes algolia/react-instantsearch#3633 closes algolia/react-instantsearch#3618 see vercel/next.jsalgolia/react-instantsearch#40067 FX-1869 Co-authored-by: François Chalifour <francoischalifour@users.noreply.github.com>
- Loading branch information
1 parent
c7f34e1
commit cce66c5
Showing
4 changed files
with
52 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters