Could not find a valid element for given id or className.

See original GitHub issue

Hi!!! Hope you guys are doing well.

I have a problem on my setup for this project on the fresh next.js repository.

My stack

"next": "^10.0.7",    
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-email-editor": "^1.1.1"

I’m getting problem when I try to refresh page. And found this problem

react-dom.development.js?61bb:67 Warning: Prop `id` did not match. Server: "editor-7" Client: "editor-1"
    at div
    at div
    at _default (webpack-internal:///./node_modules/react-email-editor/es/index.js:26:5)
    at div
    at HomePage (webpack-internal:///./pages/index.js:18:76)
    at App (webpack-internal:///./node_modules/next/dist/pages/_app.js:76:5)
    at ErrorBoundary (webpack-internal:///./node_modules/@next/react-dev-overlay/lib/internal/ErrorBoundary.js:23:47)
    at ReactDevOverlay (webpack-internal:///./node_modules/@next/react-dev-overlay/lib/internal/ReactDevOverlay.js:73:23)
    at Container (webpack-internal:///./node_modules/next/dist/client/index.js:149:5)
    at AppContainer (webpack-internal:///./node_modules/next/dist/client/index.js:637:24)
    at Root (webpack-internal:///./node_modules/next/dist/client/index.js:768:24)
printWarning @ react-dom.development.js?61bb:67
error @ react-dom.development.js?61bb:43
warnForPropDifference @ react-dom.development.js?61bb:8824
diffHydratedProperties @ react-dom.development.js?61bb:9645
hydrateInstance @ react-dom.development.js?61bb:10400
prepareToHydrateHostInstance @ react-dom.development.js?61bb:14616
completeWork @ react-dom.development.js?61bb:19458
completeUnitOfWork @ react-dom.development.js?61bb:22815
performUnitOfWork @ react-dom.development.js?61bb:22787
workLoopSync @ react-dom.development.js?61bb:22707
renderRootSync @ react-dom.development.js?61bb:22670
performSyncWorkOnRoot @ react-dom.development.js?61bb:22293
scheduleUpdateOnFiber @ react-dom.development.js?61bb:21881
updateContainer @ react-dom.development.js?61bb:25482
eval @ react-dom.development.js?61bb:26021
unbatchedUpdates @ react-dom.development.js?61bb:22431
legacyRenderSubtreeIntoContainer @ react-dom.development.js?61bb:26020
hydrate @ react-dom.development.js?61bb:26086
renderReactElement @ index.tsx?8abf:521
doRender @ index.tsx?8abf:787
_callee2$ @ index.tsx?8abf:416
tryCatch @ runtime.js?96cf:63
invoke @ runtime.js?96cf:293
eval @ runtime.js?96cf:118
asyncGeneratorStep @ asyncToGenerator.js?c973:3
_next @ asyncToGenerator.js?c973:25
eval @ asyncToGenerator.js?c973:32
eval @ asyncToGenerator.js?c973:21
_render @ index.js:514
render @ index.js:451
eval @ next-dev.js?53bc:85
eval @ fouc.js?937a:14
requestAnimationFrame (async)
displayContent @ fouc.js?937a:5
eval @ next-dev.js?53bc:84
Promise.then (async)
eval @ next-dev.js?53bc:31
eval @ next-dev.js?53bc:31
./node_modules/next/dist/client/next-dev.js @ main.js?ts=1614933303898:945
__webpack_require__ @ webpack.js?ts=1614933303898:873
checkDeferredModules @ webpack.js?ts=1614933303898:46
webpackJsonpCallback @ webpack.js?ts=1614933303898:33
(anonymous) @ webpack.js?ts=1614933303898:1015
(anonymous) @ webpack.js?ts=1614933303898:1023
Show 2 more frames
embed.js?2:1 Uncaught Error: Could not find a valid element for given id or className.
    at e.value (embed.js?2:1)
    at e.value (embed.js?2:1)
    at new e (embed.js?2:1)
    at a.value (embed.js?2:1)
    at _this.loadEditor (index.js?50c8:42)
    at runCallbacks (loadScript.js?4f5c:27)
    at HTMLScriptElement.embedScript.onload (loadScript.js?4f5c:40)

I found this code on the file. https://github.com/unlayer/react-email-editor/blob/d1bdf0036ff667c0540f2f4a541dd44da0cec59b/src/index.js#L11

I’m not sure what is intention to count up the id.

Thankyou for help.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:7

github_iconTop GitHub Comments

6reactions
huyha1408commented, Sep 17, 2021

I resolved this error by using dynamic import in Next.

Here is my code:

Editor component:

import React, { useRef } from 'react'

import EmailEditor from 'react-email-editor'

export default function Editor(props) {
  const emailEditorRef = useRef(null)

  const exportHtml = () => {
    emailEditorRef.current.editor.exportHtml((data) => {
      const { design, html } = data
      console.log('exportHtml', html)
    })
  }

  const onLoad = () => {}

  return (
    <div>
      <div>
        <button onClick={exportHtml}>Export HTML</button>
      </div>

      <EmailEditor ref={emailEditorRef} onLoad={onLoad} />
    </div>
  )
}

In the page that use Editor component:

import dynamic from 'next/dynamic'

const Editor = dynamic(() => import('@/components/Editor'), { ssr: false })

export default function EmailPage() {
  return  <Editor />
}
1reaction
LinhGithubcommented, Aug 21, 2022

image

you should add property: editorId - String HTML div id of the container where the editor will be embedded (optional)

Read more comments on GitHub >

github_iconTop Results From Across the Web

unlayer email template editor loadDesign in react function ...
Typescript react - Could not find a declaration file for module ''react-materialize'. 'path/to/module-name.js' implicitly has an any type.
Read more >
react-email-editor / Grant Nestor - Observable
To do. [ ] Fix drag-n-drop issue; [ ] Fix Could not find a valid element for given id or className error when...
Read more >
DOM Elements - React
To specify a CSS class, use the className attribute. This applies to all regular DOM and SVG elements like <div> , <a> ,...
Read more >
should | Cypress Documentation
cy.should('eq', '42') // Should not be chained off 'cy' ... can throw your own errors throw new Error('Did not find 1 element') }...
Read more >
Selectors - W3C
If all conditions in the pattern are true for a certain element, ... UAs do not always read the DTD, and thus may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found