-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
initializeEditor doesn’t work #49409
Comments
Hi, @htmgarcia Can you provide more details on why you're using the Plugins shouldn't use the method; the only reason it's publicly exported is for WP to initialize the post editor. |
Hi @Mamaduka, |
Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks. |
@jsnajdr, I remember you debugged the update settings race conditions for React 18 update (#46467 (comment)). Do you have any recommended way for dispatching this action from third-party plugins? |
@htmgarcia I think this is a timing issue. When the gutenberg/packages/editor/src/components/provider/index.js Lines 108 to 110 in bc39f39
That effect doesn't run synchronously, but a little bit later. If your plugin calls So, the solution is to call |
Hi @jsnajdr,
|
Yes that works, although it's bad that you're forced to do things like this. I'm exploring a solution where Not this: function initializeEditor( settings ) {
render( <Editor settings={ settings } /> );
}
function Editor( { settings } ) {
useEffect( () => {
updateEditorSettings( settings );
}, [ settings ] );
} But this: function initializeEditor( settings ) {
dispatch( editorStore ).updateEditorSettings( settings );
render( <Editor /> );
} Then, when your plugin wants to call In practice it's not so simple and there's some amount of complexity to untangle, but in principle it should work. |
@jsnajdr your proposal sounds promising. I really appreciated! |
Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks. |
Description
reinitializeEditor
was deprecated andinitializeEditor
doesn’t work as used to be.Can we still use this method to modify editor settings after
wp.domReady
?The error I get in console when calling
initializeEditor
is:"Warning: You are calling ReactDOMClient.createRoot() on a container that has already been passed to createRoot() before. Instead, call root.render() on the existing root instead if you want to update it."
wp.editPost.initializeEditor( 'editor', 'post', 99, modified_settings, [] );
Step-by-step reproduction instructions
define( 'SCRIPT_DEBUG', true );
99
with the ID of the post you're editing, andmodified_settings
with the return ofwp.data.select('core/editor').getEditorSettings()
wp.editPost.initializeEditor( 'editor', 'post', 99, modified_settings, [] );
Screenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: