[NextJS 14 Error] - Internal Error: do not use legacy react-dom/server APIs #58305
Replies: 11 comments 9 replies
-
If this is whole, within a server component, you could: export default async function Home() {
const { renderToString } = await import("react-dom/server");
return (
<div
dangerouslySetInnerHTML={{
__html: `${renderToString(<h1>Hello world 2</h1>)}`,
}}
/>
);
} |
Beta Was this translation helpful? Give feedback.
-
I am facing the same issue, but in react docs, this is not legacy. I have no idea why would they decide to make this kind of breaking change without any alternative. |
Beta Was this translation helpful? Give feedback.
-
would love some guidance from the next team related to this 👀 |
Beta Was this translation helpful? Give feedback.
-
I have the same issue with |
Beta Was this translation helpful? Give feedback.
-
Same here. Working perfectly on 13.5.x but now failing with Next 14.
Even replacing the renderToString with simple string manipulation fails.
In this case, setting rendered HTML to polygons within Google Maps. The only way I've got around this, and this is very annoying, is to use the "use client" component prefix. As the map is core functionality, a lot of the SSR value is now lost as a result. |
Beta Was this translation helpful? Give feedback.
-
Might be this will help https://react.dev/reference/react-dom/server/renderToString#alternatives |
Beta Was this translation helpful? Give feedback.
-
From the reference that @Yf102 provided the following worked just fine for me: Replace stuff like:
with new react root:
Thanks @Yf102 ! |
Beta Was this translation helpful? Give feedback.
-
Hey all, took a deep dive and found the cause of this (presumed) bug, and a workaround. The causeNext.js actually generates compiler aliases so that any references to "legacy" browser code in the (The "legacy" designation comes from React, not Next.js - basically all The workaroundWe must bypass the alias. Rewrite your import to the following: // import ReactDom from 'react-dom/server';
import ReactDom from 'next/dist/compiled/react-dom/cjs/react-dom-server-legacy.browser.development'; I simply used the path described by the compiler aliases script linked above. To get TypeScript types on it: declare module 'next/dist/compiled/react-dom/cjs/react-dom-server-legacy.browser.development' {
import ReactDOMServer from 'react-dom/server';
export = ReactDOMServer;
} You can now use the |
Beta Was this translation helpful? Give feedback.
-
Check out a workaround I posted in another discussion: |
Beta Was this translation helpful? Give feedback.
-
The workaround for me was to reintroduce the Pages Router, which is less than ideal. I don't have direct control on the Since I didn't want to start monkey patching or go completing off course by opening PRs on foreign libraries, I tried by using the Pages Router and it worked. Given that the migration path for when this will be fixed is quite straightforward, I am satisfied with what I have for now. But let me repeat it, it's less than ideal. |
Beta Was this translation helpful? Give feedback.
-
Hey all, 👋 just dropping a quick note about my recent adventure with renderToString for Google Maps. It was a bit of a struggle – tried the flushAsync, but MUI styles were acting like divas, and the context wasn't really feeling the vibe. My Workaround: const YourComponent = ({ children }) => {
}; And that did the job. If you're facing similar style tantrums from MUI and context not working (if needed), give this a shot. It's not fireworks, but it might just get the job done! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I have a FaqSchema.js code to render Schema from Markdown as a schema.org:
Up to this point, the code was working properly, but in NextJS 14 I have an error.
Error: Internal Error: do not use legacy react-dom/server APIs. If you encountered this error, please open an issue on the Next.js repo.
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions