Closed Mati365 closed 3 months ago
Hi,
Just a question on this implementation so I can confirm closure of https://github.com/ckeditor/ckeditor5-react/issues/513 when this is merged, onChangeEditorsMap
will be fired when an editor is ready right?
So this is equivalent to listening to the onReady callback from an editor.
If this is the same as the callback from
context.editors.on<CollectionChangeEvent<Editor>>( 'change', ( ev, data ) => {
Then I think this won't be useful as the editor is still not actually ready.
@glynam1 It'll be fired when editor is ready (and after destroying of editor). It's the flat map of fully initialized editors that are present in React tree.
@glynam1 It'll be fired when editor is ready (and after destroying of editor). It's the flat map of fully initialized editors that are present in React tree.
Nice one, looking forward to the update so!
LGTM, but the naming is not clear enough.
@arkflpc I renamed callback to onWatchInitializedEditors
. Can you take a look?
Suggested merge commit message (convention)
Feature: Add an
onChangeInitializedEditors
callback toCKEditorContext
to allow tracking of newly initialized editors within the JSX React tree. Closes https://github.com/ckeditor/ckeditor5-react/issues/513Additional information
During the React 19 refactor, it was discovered that
CKEditorContext
must be initialized before rendering the rest of the React tree (due toStrictMode
re-renders onCKEditorContext
). This order is also necessary because the rendering of newer React JSX trees is asynchronous, and it is not guaranteed that allCKEditor
instances will be registered in the context beforeonReady
is called.The issue is that some implementations rely on this behavior. Like this one: https://github.com/ckeditor/ckeditor5-react/issues/513
While we cannot track the full initialization of the entire tree, we can incrementally track what has been added.
⚠️ I'll update docs after approval of this PR
This PR adds:
onChangeInitializedEditors
callback toCKEditorContext
component, that is fired after any initialization or destruction of any editor in the context.contextItemMetadata
property toCKEditor
component that allowsonChangeEditorsMap
to assign proper name to initialized / or destroyed editor.Example
onWatchInitializedEditors
will be called twice in example above:{ editor1: ... }
{ editor1: ..., editor2: ... }
Order of initialization is not guaranteed.
editor2
might be initialized beforeeditor1
.