Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate double-rendering in React StrictMode #294

Closed
huy-nguyen opened this issue Mar 22, 2022 · 11 comments · Fixed by #310
Closed

Investigate double-rendering in React StrictMode #294

huy-nguyen opened this issue Mar 22, 2022 · 11 comments · Fixed by #310
Assignees
Labels
squad:devops Issue to be handled by the Devops team. type:bug
Milestone

Comments

@huy-nguyen
Copy link

React StrictMode is a tool provided by React to highlight potential problems in React components. When ckeditor5-react is used within StrictMode, it double-renders the editor like this

Screen Shot 2022-03-22 at 11 24 27 AM

instead of normal appearance like this:

Screen Shot 2022-03-22 at 11 24 53 AM

The reason is most likely that certain render-phase lifecycle methods in ckeditor5-react has unexpected side effects.

Render phase lifecycles include the following class component methods:

constructor
componentWillMount (or UNSAFE_componentWillMount)
componentWillReceiveProps (or UNSAFE_componentWillReceiveProps)
componentWillUpdate (or UNSAFE_componentWillUpdate)
getDerivedStateFromProps
shouldComponentUpdate
render
setState updater functions (the first argument)

Because the above methods might be called more than once, it’s important that they do not contain side-effects. Ignoring this rule can lead to a variety of problems, including memory leaks and invalid application state. Unfortunately, it can be difficult to detect these problems as they can often be non-deterministic.

Strict mode can’t automatically detect side effects for you, but it can help you spot them by making them a little more deterministic. This is done by intentionally double-invoking the following functions:

Class component constructor, render, and shouldComponentUpdate methods
Class component static getDerivedStateFromProps method
Function component bodies
State updater functions (the first argument to setState)
Functions passed to useState, useMemo, or useReducer

If left unaddressed, these problems can lead to subtle bugs in when ckeditor5-react is used in full concurrent mode in React versions starting from 18 (currently in RC) because React 18 enable concurrent rendering.

@pomek pomek added type:bug squad:devops Issue to be handled by the Devops team. labels Mar 22, 2022
@pomek
Copy link
Member

pomek commented Mar 30, 2022

React 18 is live (https://github.com/facebook/react/releases/tag/v18.0.0).

@dilipkumar2k6
Copy link

This is a big issue. How can we fix it?

@alesna97
Copy link

same issue heree

@MuscularSloth
Copy link

Same issue with console error:
editorwatchdog.js:243 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'model') at editorwatchdog.js:243:1

It appears when route switch and disappears after F5 or when direct link using.

@psmyrek psmyrek self-assigned this May 17, 2022
@CKEditorBot CKEditorBot added the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label May 17, 2022
pomek added a commit that referenced this issue May 18, 2022
Fix: Fixed component double rendering in StrictMode. Closes #294.
@CKEditorBot CKEditorBot removed the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label May 18, 2022
@pomek
Copy link
Member

pomek commented May 18, 2022

We fixed the issue, and it should not occur in the latest version of the <CKEDitor> React component => https://github.com/ckeditor/ckeditor5-react/releases/tag/v5.0.1.

@CKEditorBot CKEditorBot added this to the iteration 53 milestone May 18, 2022
@tony
Copy link

tony commented May 24, 2022

Same issue with console error: editorwatchdog.js:243 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'model') at editorwatchdog.js:243:1

It appears when route switch and disappears after F5 or when direct link using.

Was this console message fixed when you upgraded to 5.0.1?

@pomek
Copy link
Member

pomek commented May 24, 2022

@tony, no, this issue wasn't fixed. Would you like to report a new issue for it? Perhaps it's related (somehow) to #241.

@tony
Copy link

tony commented May 24, 2022

@pomek After I updated to ckeditor5-react 5.0.0 -> 5.0.1 I stopped getting the Cannot read properties of null (reading 'model') error in sentry.

Maybe they were related? No traceback unfortunately:

./node_modules/@ckeditor/ckeditor5-react/dist/ckeditor.js at line 5:21415

{snip} ve.flush();const t=this._editor;return this._editor=null,t.model.document.off("change:data",this._throttledSave),this._destructor(t)}))}_sav {snip}
//# sourceMappingURL=ckeditor.js.map

@pomek
Copy link
Member

pomek commented May 24, 2022

That's good news that the error does not occur anymore. Perhaps it was related to promises. Before 5.0.1, they were ignored. Now the component waits to resolve them.

@tony
Copy link

tony commented May 24, 2022

That's what I suspect. It seems so.

If it comes up again I (or anyone else who bumps into it) can make a new issue (and perhaps cite this if they find it in search)

@SK-website
Copy link

SK-website commented Apr 2, 2023

Hi. Got the same problem with ckeditor5-react 5.1.0 and React 18.2.0 -
Uncaught (in promise) TypeError: Cannot read properties of null (reading 'model') at editorwatchdog.js:243:1
Is there a way to fix it by myself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squad:devops Issue to be handled by the Devops team. type:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants