Renders twice with latest nextjs
See original GitHub issueThe default implementation renders twice using nextjs.
I used this example: https://github.com/unlayer/react-email-editor
and got this outcome

package.json
{
"name": "polyma",
"version": "2.0.0",
"private": true,
"license": "The Unlicense",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"fauna": "fgu"
},
"dependencies": {
"@apollo/client": "^3.5.10",
"@nivo/bar": "^0.79.1",
"@nivo/core": "^0.79.0",
"@nivo/line": "^0.79.1",
"@tailwindcss/line-clamp": "^0.4.0",
"framer-motion": "^6.3.0",
"graphql": "^16.3.0",
"next": "12.1.6",
"react": "^18.0.0",
"react-dnd": "^16.0.0",
"react-dnd-html5-backend": "^16.0.0",
"react-dom": "^18.0.0",
"react-email-editor": "^1.6.0",
"react-hook-form": "^7.30.0",
"react-ranger": "^2.1.0",
"react-use-copy-to-clipboard": "^1.0.1",
"uuid": "^8.3.2"
},
"devDependencies": {
"@fortawesome/fontawesome-svg-core": "^6.1.1",
"@fortawesome/free-brands-svg-icons": "^6.1.1",
"@fortawesome/free-regular-svg-icons": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.1.18",
"autoprefixer": "^10.4.4",
"eslint": "^8.12.0",
"eslint-config-next": "12.1.6",
"fauna-gql-upload": "^2.4.3",
"faunadb": "^4.5.4",
"postcss": "^8.4.12",
"sharp": "^0.30.3",
"tailwind-scrollbar": "^1.3.1",
"tailwindcss": "^3.0.24",
"vercel": "^24.1.0"
}
}
Full code Email.js
import { useRef } from "react";
import dynamic from "next/dynamic";
const EmailEditor = dynamic(() => import("react-email-editor"), {
ssr: false,
});
export default function Email() {
const emailEditorRef = useRef(null);
function saveDesign() {
emailEditorRef.current.editor.saveDesign((design) => {
console.log("saveDesign", design);
});
}
function exportHtml() {
emailEditorRef.current.editor.exportHtml((data) => {
const { design, html } = data;
console.log("exportHtml", html);
});
}
function onLoad() {
// editor instance is created
// you can load your template here;
// const templateJson = {};
// emailEditorRef.current.editor.loadDesign(templateJson);
}
function onReady() {
// editor is ready
console.log("onReady");
}
return (
<div className="">
<div>
<button onClick={saveDesign}>Save Design</button>
<button onClick={exportHtml}>Export HTML</button>
</div>
<div className="h-screen overflow-hidden">
<EmailEditor
ref={emailEditorRef}
onLoad={onLoad}
onReady={onReady}
// works for now, the second email builder gets hidden.
// minHeight="100vh"
/>
</div>
</div>
);
}
Issue Analytics
- State:
- Created a year ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Next dev with React 18, Always render twice #35822 - GitHub
Hi. When use next dev with react 18, page always rendered twice. ... even lazy state intialize twice, and unmount last. So I...
Read more >Why my nextjs component is rendering twice? - Stack Overflow
I found the answer in this thread. https://github.com/vercel/next.js/issues/35822. In shortly, This issue is about React 18 Strict Mode.
Read more >What is Rendering? - How Next.js Works
This process is called rendering. Rendering can take place on the server or on the client. It can happen either ahead of time...
Read more >Anyone had elements randomly render twice on page? : r/nextjs
On each render of the app component, the function will change, therefore react will think you're trying to render a new component. Try...
Read more >Solving the React 18 Double Render problem on useEffect
React 18's useEffect hook now double renders (with the empty dependency array) which has caused a stir in the React community.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hello, I was having the same problem in React V18. And I saw that the problem was caused by the fact that Strict Mode causes the element to be rendered twice in React. I solved the problem by removing the StricMode tag in index.js.
Having the same issue today, I really feel like turning off
StrictModeis not a good workaround though.For anyone that does not mind this, turning it off does indeed fix the issue.
In case anyone is wondering why turning of
StrictModefixes the issue https://stackoverflow.com/a/61897567/12035491