xdan / jodit

Jodit - Best WYSIWYG Editor for You
https://xdsoft.net/jodit/
MIT License
1.66k stars 350 forks source link

Uncaught TypeError: Cannot read property 'set' of undefined #402

Open sagar-gavhane opened 4 years ago

sagar-gavhane commented 4 years ago

Jodit Version:

{
  "jodit-react": "~1.0.42",
}

Browser:

Chrome Version 83.0.4103.61 (Official Build) (64-bit)

OS: Mac

Code

import React, { Component } from 'react'
import dynamic from 'next/dynamic'

import toolbarConfig from './toolbarConfig'

import { StyledEditorPanel } from './styles'

class RichText extends Component {
  state = {
    isEditorLoaded: false,
  }

  Editor = null

  componentDidMount() {
    if (typeof window !== 'undefined') {
      // Documentation: https://xdsoft.net/jodit/examples/intergration/react-jodit.html
      this.Editor = dynamic(import('jodit-react'))
      this.setState({ isEditorLoaded: true })
    }
  }

  render() {
    const { value } = this.props
    const RichEditor = this.Editor

    return (
      <StyledEditorPanel>
        {RichEditor && (
          <RichEditor
            value={value}
            config={{
                toolbarAdaptive: false,
                showCharsCounter: false,
                showWordsCounter: false,
                showXPathInStatusbar: false,
                height: 500,
                buttons: 'bold,strikethrough,underline,italic,|,superscript,subscript,|,ul,ol,|,outdent,indent,|,font,fontsize,brush,paragraph,|,image,file,video,table,link,|,align,undo,redo,copyformat,hr',
            }}
            tabIndex={1}
            onChange={newContent => {
              onEdit({
                value: newContent,
              })
            }}
          />
        )}
      </StyledEditorPanel>
    )
  }
}

export default RichText

Expected behavior:

When I trying to copy-paste text from somewhere else it's throwing me Uncaught TypeError: Cannot read property 'set' of undefined error. I don't why I'm getting this issue. Maybe currently, jodit not support SSR.

Actual behavior:

It should just copy-paste the text.

Error Stack:

jodit.min.js:9 Uncaught TypeError: Cannot read property 'set' of undefined
    at n (jodit.min.js:9)
    at c (jodit.min.js:9)
    at jodit.min.js:9
    at HTMLAnchorElement.<anonymous> (jodit.min.js:9)
    at HTMLAnchorElement.p (jodit.min.js:9)
xdan commented 4 years ago

Need more information, is it repeated in play https://xdsoft.net/jodit/play.html ?

sagar-gavhane commented 4 years ago

it's not repeated on xdsoft.net/jodit/play.html.

JClackett commented 4 years ago

Also have this issue, only trace I could get was in the minified code

Cannot read property 'set' of undefined:

_TEXT:e=s.htmlspecialchars(e)}"string"==typeof e&&t.buffer.set(d.pluginKey,e),t.selection.insertHTML(e)},u=function(e,a){var l=t.buffer.get

Potentially could be a browser specific issue, super hard to replicate unfortunately :(

sagar-gavhane commented 4 years ago

The way I see things that above issue occurring due to I'm dynamically importing and rendering jodit-react component on the server-side and while rendering jodit-react component doesn't have access to window or document object.

I want to understand for library maintainer that did we tried to render the jodit-react component on the server-side? Do we've any example or test suite for SSR?

CarlosOrozc commented 2 years ago

I have this error when I call the two-sided component different from my application image

IgorGeorgioski commented 2 years ago

@CarlosOrozc did you find a solution? I am struggling with the same at this point, when I'm using jodit in a modal.

tobychidi-zz commented 2 years ago

I have the same issue. I am dynamically importing the editor in Next.Js