Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.78k stars 894 forks source link

Yoast SEO sidebar doesn't save the metadata on block editor when the Yoast SEO metabox is disabled #21851

Open shabnam611 opened 2 days ago

shabnam611 commented 2 days ago

Please give us a description of what happened

If Yoast SEO metabox is disabled, then Yoast SEO sidebar doesn't save the metadata like SEO title, meta description. Also, this data does not appear in the page source and remains missing from the post overview page as well.

This issue with saving data applies not only to the SEO title/description but also to all our settings added via the sidebar.

To Reproduce

Step-by-step reproduction instructions

  1. Disable Yoast SEO metabox from post editor > Preference > General > Advanced and disable the Yoast SEO toggle button.
  2. Add a new post, use the Search Appearance tab of Yoast SEO sidebar to add the meta description [for example]
  3. Publish the post. Refresh the page and open the Search Appearance tab of Yoast SEO sidebar.

Expected results

  1. The data added via Yoast SEO sidebar should remain saved without metabox being enabled.

Actual results

  1. Metadata is not being saved in the Yoast SEO sidebar

Screenshots, screen recording, code snippet

https://www.loom.com/share/bdf879f26d67454caca89aa7b6c3de0b

Technical info

Used versions

shabnam611 commented 2 days ago

+1 https://wordpress.org/support/topic/changes-not-saved-11/

stokesman commented 1 day ago

I got here from wordpress/gutenberg#67207 which has been acknowledged as a regression and a fix is in the works. It seems the earliest that WP can release with the fix will be in 6.7.2 sometime after December 2.

In case the issue is more urgent for Yoast, it seems possible to patch with something like the following:

add_action( 'enqueue_block_editor_assets', 'hotfix_initialize_meta_boxes' );
function hotfix_initialize_meta_boxes() {
    $initializer = <<<JS
        ( ( { dispatch, select, subscribe } ) => {
            const unsub = subscribe( () => {
                const isEditorReady = select( wp.editor.store ).__unstableIsEditorReady();
                const isInitialized = select( wp.editPost.store ).areMetaBoxesInitialized();
                if ( isEditorReady ) {
                    if ( isInitialized ) {
                        unsub();
                    } else {
                        dispatch( wp.editPost.store ).initializeMetaBoxes();
                    }
                }
            } );
        } )( wp.data );
    JS;
    wp_add_inline_script( 'wp-edit-post', $initializer );
}

Given that Yoast renders React components, I think it may be done alternatively with hooks (useSelect/useDispatch) and added to the plugins sidebar component.