react-froala-wysiwyg icon indicating copy to clipboard operation
react-froala-wysiwyg copied to clipboard

model prop stopped working in 3.1.0

Open Adam-Stomski opened this issue 5 years ago • 9 comments

https://github.com/Adam-Stomski/froala-310-model-doesnt-work

Adam-Stomski avatar Jan 31 '20 11:01 Adam-Stomski

I also had the issue that Froala ignored what I set via model-prop.

Yet I found the following working example: https://codesandbox.io/s/react-froala-initialized-bug-y4hqf?from-embed

The main difference to my version was I had set the prop tag="textarea". Removing this prop solved the issue for me.

In your example the tag is also set, removing it should solve the issue too.

Regards.

moek avatar Feb 14 '20 10:02 moek

Changing model quickly after first render causes ignored model as well. For example if you have instantiated a FroalaEditor with model "" and then immediately rerendered component with actual data, it will stay empty.

Snivik avatar Mar 29 '20 09:03 Snivik

I have the same issue with @Snivik. As a workaround I added a key on the component that was using the editor but it is now causing the editor to flicker.

pmpunzalan avatar Apr 16 '20 04:04 pmpunzalan

I have the same issue with @Snivik. As a workaround I added a key on the component that was using the editor but it is now causing the editor to flicker.

I just use timeout of a 200ms to set the data. Not clean, but works.

Snivik avatar Apr 18 '20 22:04 Snivik

I have to same issue. Where did you set the timeout @Snivik ?

ffjanhoeck avatar Jul 08 '20 10:07 ffjanhoeck

I have to same issue. Where did you set the timeout @Snivik ?

During a useEffect on initial appearance of the component, if you use a class-based approach - then on componentDidMount()

Snivik avatar Jul 08 '20 10:07 Snivik

I found setting the model value after the html.set event resolved the issue:

state = {
   htmlSet: false,
}

render ()  {
    return (
        <FroalaEditorComponent
            model={this.state.htmlSet ? value : undefined}
            config={{
                events: {
                    'html.set': () => {
                        this.setState({ htmlSet: true })
                    },
                }
            }}
        />
    )
}

narehart avatar Jul 09 '20 18:07 narehart

I found setting the model value after the html.set event resolved the issue:

state = {
   htmlSet: false,
}

render ()  {
    return (
        <FroalaEditorComponent
            model={this.state.htmlSet ? value : undefined}
            config={{
                events: {
                    'html.set': () => {
                        this.setState({ htmlSet: true })
                    },
                }
            }}
        />
    )
}

I can confirm that the solution works fine.

jposert avatar Jun 13 '21 13:06 jposert

Can you guys try model={value + ''}

or just setting value =+ '' Before you use it in model={value}

For some reason this is making it work for me in Strapi.

I think the key here is to make sure your value is never an object, only ever a string, before using it inside model={value}

What I think is happening then is it is just converting null to the string 'null'. But then if I set value = 'null' it just sets the model as 'null' and never reloads correctly. I hate not knowing why things are happening. This is super frustrating.

jordankittle avatar Jul 02 '21 03:07 jordankittle