-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Meta boxes saving when they’re not present (#67254)
* Initialize meta boxes whether or not they’re visible * Add hook for initialization of meta boxes * Minimize hook for meta boxes initialization * Name the export Co-authored-by: stokesman <[email protected]> Co-authored-by: afercia <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: enricobattocchi <[email protected]>
- Loading branch information
1 parent
d3f344f
commit cd26001
Showing
3 changed files
with
43 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/edit-post/src/components/meta-boxes/use-meta-box-initialization.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editPostStore } from '../../store'; | ||
|
||
/** | ||
* Initializes WordPress `postboxes` script and the logic for saving meta boxes. | ||
* | ||
* @param { boolean } enabled | ||
*/ | ||
export const useMetaBoxInitialization = ( enabled ) => { | ||
const isEnabledAndEditorReady = useSelect( | ||
( select ) => | ||
enabled && select( editorStore ).__unstableIsEditorReady(), | ||
[ enabled ] | ||
); | ||
const { initializeMetaBoxes } = useDispatch( editPostStore ); | ||
// The effect has to rerun when the editor is ready because initializeMetaBoxes | ||
// will noop until then. | ||
useEffect( () => { | ||
if ( isEnabledAndEditorReady ) { | ||
initializeMetaBoxes(); | ||
} | ||
}, [ isEnabledAndEditorReady, initializeMetaBoxes ] ); | ||
}; |
cd26001
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in cd26001.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12120764031
📝 Reported issues:
/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js