镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

change event and re-render on state change #76

Open

Description

@dougnorton

Periodically I update some state which causes the CKEditor to re-render. If I'm typing into the editor at the same time the state update happens, I loose text and the cursor jumps to the beginning of the text.

I have a change to the example.js (below) that causes the issue. Just run the example and start typing in the CKEditor.

Is this an issue or is it just the way I have it coded?

const React = require('react');
const ReactDOM = require('react-dom');
import CKEditor from "../src";

class Example extends React.Component {
  constructor(props){
    super(props);

    //State initialization
    this.state = {
	  content: "Hello World",
	  periodic: 'b'
    };
	this.setContent = this.setContent.bind(this)
	this.onChange = this.onChange.bind(this);
	
	setInterval(() => this.cycleUpdate(), 1000);
  }

  cycleUpdate() {
	this.setState({
		periodic: this.state.periodic + 'a'
	});
  }

  //------ Test for race condition ------ //
  setContent(){
    console.log("Setting content");
    this.setState({
      content: "Hello World " + Math.random()
    })
  }

  onChange(evt){
	this.setState({
		content: evt.editor.getData()
	});
    console.log("onChange fired with event info: ",evt, "and data: ",evt.editor.getData());
  }

  onBlur(evt){
    console.log("onBlur fired with event info: ",evt);
  }

  afterPaste(evt){
    console.log("afterPaste fired with event info: ",evt);
  }

  render() {
    return (
      <div>
        <button onClick={() => this.setContent()} children='Set content' />
        <CKEditor
          content={this.state.content}
          events={{
            blur: this.onBlur,
            afterPaste: this.afterPaste,
            change: this.onChange
          }}
        />
      </div>
    );
  }
}

ReactDOM.render(
  <Example />,
  document.getElementById('example')
);

Activity

  1. pmonty commented on Dec 18, 2019

    @pmonty

    Having a similar issue, if i type the character i entered disappears and it goes to the start of the editor. Any idea? If i use 1.0.5 instead of @latest and use the onChange event it works though.

  2. offaxis commented on Apr 23, 2020

    @offaxis

    +1
    I experienced this bug on receiving WebSocket MessageEvent !

  3. sagarguhe commented on Oct 8, 2021

    @sagarguhe

    +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions