GithubHelp home page GithubHelp logo

Comments (13)

haench avatar haench commented on June 1, 2024 5

Hi,

I ran into the same issue: I think it is realted to componentDidUpdate this part

    if (
      !this.state.keyChange &&
      this.props.value !== this.state.value && // This is somehow fixes moving cursor for controlled case
      this.props.value !== prevProps.value // This one fixes no value change for uncontrolled input. If it's uncontrolled prevProps will be the same
    ) {
      this.simpleMde!.value(this.props.value || "");
    }

the state is not correctly updated when props change.

A simple trick solved the issue: I provided a key attribute with a unique id. Thats makes sure the component is rerendered on props change (I think):
<SimpleMDEReact key={unique_id} value={my_value} onChange={value => onChange} />

from react-simplemde-editor.

patmood avatar patmood commented on June 1, 2024 1

This bug depends if the component is controlled or uncontrolled and any solutions should test both cases.

I'm using it as a controlled component and fixed the issue by removing all references to state, since it's not required. I'll try creating a PR that handles both cases.

from react-simplemde-editor.

RIP21 avatar RIP21 commented on June 1, 2024

Hey, @fabriceci thanks for a filled issue.
Can you please make a reproduction using codesandbox.io? Because it's really hard to get what's the issue from the screenshot and this code.
Repro will make it way easier for me to investigate the bug.

from react-simplemde-editor.

fabriceci avatar fabriceci commented on June 1, 2024

Yes of course: here is the codesandbox

  • Click on Article 1 , then Article 2 and then Article 1. You will see the desc value will disappear (value of article 2)
  • Click on Article 2, then Article 1 then Article 2. You will see the desc value will be the value of Article 1 desc.

As you can see here, the value is updated in the component but not displayed properly.

from react-simplemde-editor.

RIP21 avatar RIP21 commented on June 1, 2024

@fabriceci still had no time to take a look at this one. Hopefully next weekend will investigate it further.

from react-simplemde-editor.

fabriceci avatar fabriceci commented on June 1, 2024

@RIP21 Thank you! I regret not to be able to do more.

from react-simplemde-editor.

AlexanderLapshin avatar AlexanderLapshin commented on June 1, 2024

Any update?

from react-simplemde-editor.

RIP21 avatar RIP21 commented on June 1, 2024

@haench yes. If you change key prop it forces component to remount from scratch. It's one of the recommended ways of hard reloading components.
I don't know whether I will have time to fix that. Hopefully soon :( Sorry guys, I have life and a lot of work at Revolut and I just don't have any time now for investigating this particular issue.

from react-simplemde-editor.

crivera avatar crivera commented on June 1, 2024

Hi

i have a similar issue when I set the value to be empty from extraKeys it will break after the first time.

Here is an example

https://codesandbox.io/s/stoic-wright-tn4l7?fontsize=14&hidenavigation=1&theme=dark

Type something and hit enter... the editor will empty out the field. Now type something again and hit enter and you will see nothing happens

from react-simplemde-editor.

crivera avatar crivera commented on June 1, 2024

it seems this line in componentDidUpdate is the problem:

this.props.value !== prevProps.value

can we remove this?

from react-simplemde-editor.

RIP21 avatar RIP21 commented on June 1, 2024

from react-simplemde-editor.

crivera avatar crivera commented on June 1, 2024

actually my codesandbox was not on the latest version... at the latest version it works fine

https://codesandbox.io/s/stoic-wright-tn4l7?fontsize=14&hidenavigation=1&theme=dark

from react-simplemde-editor.

RIP21 avatar RIP21 commented on June 1, 2024

This one is I'm sure is sorted by the latest changes I did in version 5.0.0. Please check it out! It's totally rewritten and uses hooks now.
Mind breaking changes!

from react-simplemde-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.