You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reinitializeEditor was deprecated and initializeEditor 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."
In wp-config.php set define( 'SCRIPT_DEBUG', true );
Open a post edit
Open browser console
Execute the line of code below replacing 99 with the ID of the post you're editing, and modified_settings with the return of wp.data.select('core/editor').getEditorSettings()
Hi @Mamaduka,
I use initializeEditor to modify allowedBlockTypes. I wonder if there is an alternative method to achieve the same result? Tried updateEditorSettings with no luck.
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 initializeEditor function is called with a settings parameter, it mounts the editor React UI with the EditorProvider component, and there is an effect in that component that synchronizes the settings to the data store, calling updateEditorSettings:
That effect doesn't run synchronously, but a little bit later. If your plugin calls updateEditorSettings too soon, as it probably does, your changes will be overwritten by that effect.
So, the solution is to call updateEditorSettings only after that effect runs. But I don't know at this moment how to do it simply, reliably and elegantly.
So, the solution is to call updateEditorSettings only after that effect runs. But I don't know at this moment how to do it simply, reliably and elegantly.
Hi @jsnajdr,
thanks for jumping into the conversation. In the meanwhile I wrapped updateEditorSettings with a time delay:
Then, when your plugin wants to call updateEditorSettings, initializeEditor has already run and updated the settings. There is no scheduled effect that would overwrite your changes.
In practice it's not so simple and there's some amount of complexity to untangle, but in principle it should work.
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.
Activity
Mamaduka commentedon Mar 29, 2023
Hi, @htmgarcia
Can you provide more details on why you're using the
initializeEditor?Plugins shouldn't use the method; the only reason it's publicly exported is for WP to initialize the post editor.
htmgarcia commentedon Mar 29, 2023
Hi @Mamaduka,
I use
initializeEditorto modifyallowedBlockTypes. I wonder if there is an alternative method to achieve the same result? Tried updateEditorSettings with no luck.github-actions commentedon Apr 14, 2023
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.
Mamaduka commentedon Apr 18, 2023
@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?
jsnajdr commentedon Apr 18, 2023
@htmgarcia I think this is a timing issue. When the
initializeEditorfunction is called with asettingsparameter, it mounts the editor React UI with theEditorProvidercomponent, and there is an effect in that component that synchronizes the settings to the data store, callingupdateEditorSettings: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
updateEditorSettingstoo soon, as it probably does, your changes will be overwritten by that effect.So, the solution is to call
updateEditorSettingsonly after that effect runs. But I don't know at this moment how to do it simply, reliably and elegantly.htmgarcia commentedon Apr 18, 2023
Hi @jsnajdr,
thanks for jumping into the conversation. In the meanwhile I wrapped
updateEditorSettingswith a time delay:jsnajdr commentedon Apr 19, 2023
Yes that works, although it's bad that you're forced to do things like this.
I'm exploring a solution where
initializeEditorwould update the settings immediately, instead of postponing it to an effect.Not this:
But this:
Then, when your plugin wants to call
updateEditorSettings,initializeEditorhas already run and updated the settings. There is no scheduled effect that would overwrite your changes.In practice it's not so simple and there's some amount of complexity to untangle, but in principle it should work.
htmgarcia commentedon Apr 19, 2023
@jsnajdr your proposal sounds promising. I really appreciated!
github-actions commentedon May 5, 2023
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.
Mamaduka commentedon May 7, 2025
I'm going to close this as a duplicate of #15993.