React-draft-wysiwyg: variable declaration causes handlePastedText function error after js minified

Created on 26 Feb 2018  路  4Comments  路  Source: jpuri/react-draft-wysiwyg

check out var o below:
before minified:

this.handlePastedText = function(t, n) {
    if (e.props.handlePastedText && e.props.handlePastedText(t, n, o, e.onChange))
         return !0;
    var o = e.state.editorState;
    return (0,
    x.handlePastedText)(t, n, o, e.onChange)
 }    

after minified:

 this.handlePastedText = function(t, n) {
    return e.props.handlePastedText ? e.props.handlePastedText(t, n, editorState, 
    e.onChange) : !e.props.stripPastedStyles && (0,
    O.handlePastedText)(t, n, e.state.editorState, e.onChange)
}

this leads to be unable pasting texts and a console error:

react.sns2_bundle.js:formatted:81317 Uncaught ReferenceError: editorState is not defined
    at Object.Q.handlePastedText (react.sns2_bundle.js:formatted:81317)
    at r (react.sns2_bundle.js:formatted:76245)
    at react.sns2_bundle.js:formatted:74574
    at Object.r (react.sns2_bundle.js:formatted:19538)
    at a (react.sns2_bundle.js:formatted:19327)
    at Object.s [as executeDispatchesInOrder] (react.sns2_bundle.js:formatted:19337)
    at p (react.sns2_bundle.js:formatted:15367)
    at m (react.sns2_bundle.js:formatted:15374)
    at Array.forEach (<anonymous>)
    at r (react.sns2_bundle.js:formatted:24598)

All 4 comments

Same here.

Uncaught ReferenceError: editorState is not defined
    at Object.J.handlePastedText (bundle.js?v=release-1.37.0:formatted:76224)

I solved. I created a pull request.
If you want to solve it by yourself, the bug is in Editor/index.js
Just move up editorState variable declaration, as @june50232 suggested.

In src/Editor/index.js handlePastedText function has to be like this:

handlePastedText = (text, html) => {
    const { editorState } = this.state;

    if (this.props.handlePastedText) {
      return this.props.handlePastedText(
        text,
        html,
        editorState,
        this.onChange
      );
    }
    if (!this.props.stripPastedStyles) {
      return handlePastedText(text, html, editorState, this.onChange);
    }
    return false;
  };

Or clone from here: https://github.com/Huespal/react-draft-wysiwyg. Without any guarantees. I will delete this fork when bug is solved in @jpuri repo.

Change has been released [email protected]. Thanks again 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trongbang86 picture trongbang86  路  3Comments

DiegoGallegos4 picture DiegoGallegos4  路  4Comments

gyarasu picture gyarasu  路  4Comments

volkandkaya picture volkandkaya  路  3Comments

Fireprufe15 picture Fireprufe15  路  4Comments