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

CKEditorContext component doesn't destroy properly #283

Closed
Mgsy opened this issue Feb 8, 2022 · 0 comments · Fixed by #284
Closed

CKEditorContext component doesn't destroy properly #283

Mgsy opened this issue Feb 8, 2022 · 0 comments · Fixed by #284
Assignees
Labels
squad:platform Issue to be handled by the Platform team. type:bug
Milestone

Comments

@Mgsy
Copy link
Member

Mgsy commented Feb 8, 2022

Description

It seems that <CKEditorContext> component doesn't destroy properly, as it keeps an open WebSocket connection after unmounting. For example, as a result, it leaves connected users in the presence list. 

The easiest way to reproduce the problem is to use our Comments outside of the editor for React sample, where Context + RTC are integrated. The sample should be modified to allow component destruction. I have prepared a simple solution that adds a button for toggling editors - it could be used for the reproduction, just replace the original sample.js file with the one from my gist.

After creating the editors, the WebSocket connection is open, but after removing the editor, it is still open. This issue doesn't occur with the default <CKEditor> component or default Context integration.

Possible solution

Here is the part responsible for destroying the context after unmounting the component:

https://github.com/ckeditor/ckeditor5-react/blob/master/src/ckeditorcontext.jsx#L82-L87

_destroyContext() {
	if ( this.contextWatchdog ) {
		this.contextWatchdog.destroy();
		this.contextWatchdog = null;
	}
}

I noticed that converting this method to the async method fixes the issue and makes all asynchronous code from ContextWatchdog run properly (however, I don't know if it is a correct approach).

async _destroyContext() {
	if ( this.contextWatchdog ) {
		await this.contextWatchdog.destroy();
		this.contextWatchdog = null;
	}
}

Before the change (see the dev tools and Time column of the WebSocket connection - it's pending after the destroy):

After the change:

@Mgsy Mgsy added type:bug squad:platform Issue to be handled by the Platform team. labels Feb 8, 2022
@pomek pomek added this to the iteration 51 milestone Feb 9, 2022
@pomek pomek closed this as completed in #284 Feb 9, 2022
pomek added a commit that referenced this issue Feb 9, 2022
Fix: Use `async/await` in `CKEditorContext#_destroyContext()` to handle context destruction properly. Closes #283.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squad:platform Issue to be handled by the Platform team. type:bug
Projects
None yet
2 participants