Skip to content

UseEditor onCreate event is called twice with two different editor instances in React.StrictMode #7091

Description

@rykala

Affected Packages

react

Version(s)

3.7.2

Bug Description

When using useEditor hook in React Strict Mode, the onCreate callback is called twice with two different editor instances, even though the hook correctly returns the same instance both times.

This is caused since the callback in the useState(() => new EditorInstanceManager(mostRecentOptions)) is called twice it causes the event onCreate event handler to be also called twice, each time with different instance.

I am not sure if this is related but the css styles are also not injected correctly as I suspect that the editor.destroy() of the second instance is called it unmounts the styles.

Browser Used

Chrome

Code Example URL

https://codesandbox.io/p/devbox/smoosh-framework-5tdhz9?workspaceId=ws_QZ6DpcrUC3wD6QbYWzwFrx

Expected Behavior

I feel like this can have several expected behaviours:

  • The events should not be called twice in the strict mode, or

  • The onCreate should be called with the same editor instance

  • Also I could see a world where this can be expected behaviour but should be at least documented.

Additional Context (Optional)

This is my first OS issue so I apologize in advance if I did something wrong 🙏

Dependency Updates

  • Yes, I've updated all my dependencies.

Metadata

Metadata

Assignees

Labels

area: coreCore editor engine and ProseMirror integrationarea: editorEditor behavior, commands, and transactionsarea: reactReact integration and componentscomplexity: mediumModerate change, possibly multiple filesimpact: mediumAffects some users or workflowsstatus: triageNeeds initial review and categorizationtype: help-wantedCommunity contributions welcome

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions