Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'charCounter') - NextJS - suneditor 2.45.1 - suneditor-react 3.6.1 #1286

Closed
dharyel opened this issue Aug 4, 2023 · 1 comment
Milestone

Comments

@dharyel
Copy link

dharyel commented Aug 4, 2023

Greetings, @JiHong88 . First I need to say that I LOVE your rich text editor. I had a lot of headache with the popular ones, but neither of them work as I needed. Suneditor is a bless. Thank you very much.

Describe the bug
I am facing an error that prints on console only about charCounter funcionallity. But if you close the error, it is working normal(great).
It looks that 'context.element' is undefined, but I didnt understand why because you already did a condicional check for its existance before:
image

I am using these versions(I believe its the latest ones):

  • "suneditor": "^2.45.1",
  • "suneditor-react": "^3.6.1",

To Reproduce
I am using nextjs with react-hook-form.
The value its recieved is an useState variable from the component that is using RichTextEditor

my editor code:
`
//start
export const RichTextEditor = ({ value, onChange }: RichTextProps) => {
const handleEditorChange = (content: string) => {
onChange({ text: getContentText(content), html: content });
};

const getContentText = (content: string) => {
const tempDiv = document.createElement("div");
tempDiv.innerHTML = content;
return tempDiv.innerText;
};

return
<SunEditor
onLoad={() => {
const editorLabels = document.querySelectorAll(".sun-editor label");

    editorLabels.forEach((label) =>
      label.setAttribute("class", "sun-editor__label")
    );
  }}
  lang={"pt_br"}
  onImageUploadBefore={(data) => {
    console.log("imageUploadBefore", data);
    return false;
  }}
  onAudioUploadBefore={(data) => {
    console.log("onAudioUploadBefore", data);
    return false;
  }}
  onVideoUploadBefore={(data) => {
    console.log("onVideoUploadBefore", data);
    return false;
  }}
  setOptions={{
    maxCharCount: 5000,
    charCounterType: "char",
    charCounter: true,
    templates: [
      {
        name: "Template-1",
        html: "<p>HTML source1</p>",
      },
      {
        name: "Template-2",
        html: "<p>HTML source2</p>",
      },
    ],
    buttonList,
  }}
  onChange={handleEditorChange}
  setContents={value}
/>

//end
`

Expected behavior
there is no need to this console error be displayed, because its working normal.

Screenshots
image

Observation: the suneditor is inside a Drawer(ChakraUI drawer)
image

@JiHong88 JiHong88 added this to the 2.45.2 milestone Jan 14, 2024
@JiHong88
Copy link
Owner

It's an incomprehensible bug.
For now, I did my best to handle the exception..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants