-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Initialize the state before rendering widgets editor #25736
Conversation
Size Change: +170 B (0%) Total Size: 1.18 MB
ℹ️ View Unchanged
|
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.
I was digging through edit-widgets/src/store
yesterday and got confused when I didn't see any code like this, so glad to see it! 😀
}, [] ); | ||
|
||
if ( ! stateInitialized ) { | ||
return <div></div>; |
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.
Could this be return null;
? Having an empty div in the DOM structure isn't ideal.
yield persistStubPost( buildWidgetAreasPostId(), [] ); | ||
} | ||
|
||
export const persistStubPost = function* ( id, blocks ) { |
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.
This is exported so needs a doc comment.
export const persistStubPost = function* ( id, blocks ) { | ||
const stubPost = createStubPost( id, blocks ); | ||
const args = [ KIND, POST_TYPE, id ]; | ||
yield dispatch( 'core', 'startResolution', 'getEntityRecord', args ); |
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.
I know from experience that this is the magic that prevents core-data
from trying to resolve the entity, but I imagine most would not pick that up. Let's add a doc comment.
const { initializeState } = useDispatch( 'core/edit-widgets' ); | ||
const [ stateInitialized, setStateInitialized ] = useState( false ); | ||
useEffect( () => { | ||
initializeState(); |
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.
It's strange to see an action that looks so... imperative. I wonder if instead of an action we should use a resolver called getStubPost
or getWidgetsEditorPost
and then discard the return value? Third party plugins might find the return value useful.
Not a strong opinion, just an idea, take it with a grain of salt, etc.
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.
Oh. There's already getWidgetAreas
which is called here:
gutenberg/packages/edit-widgets/src/components/widget-areas-block-editor-provider/index.js
Line 39 in 2acb853
widgetAreas: select( 'core/edit-widgets' ).getWidgetAreas(), |
If we have that and are calling it when WidgetAreasBlockEditorProvider
mounts, why is this PR necessary?
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.
@noisysocks we need this PR to explicitly do things in certain order and avoid race conditions. Without this PR the post is requested before the widgets resolver initialize it. We could maybe line up the code so that it doesn’t happen, but I’d rather do it explicitly.
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.
Mostly looks good to me. Just same as what @noisysocks already mentioned 👍
* Initialize the state before rendering widgets editor * Replace empty div with null * Document persistStubPost * Document persistStubPost further
* Include edit-widgets php files in build (#25792) * Fix PHP warining in widget utils controller (#25797) * Fix PHP warning in WP_REST_Widget_Utils_Controller The `WP_REST_Widget_Utils_Controller::is_valid_widget` method needs to be public in order to be accessible as a callback (since it's being called from outside the class, via `call_user_func`). This commit fixes the warning by changing the method's visibility from `private` to `public`. * Ammend the inline documentation. Add `* @access public` * [Widgets Editor] Fix insertion point in widget areas (#25727) * Move hooks inside the newly created Interface component * Fix insertion at the top of the widget area * Fix widget insertion from sidebar block library by using a declared insertionPoint prop (#25763) * Fix widget insertion from sidebar block library by using a declared insertionPoint prop * Add comments * Optimize by avoiding `getEntityRecord` call unless needed Co-authored-by: Daniel Richards <[email protected]> * Initialize the state before rendering widgets editor (#25736) * Initialize the state before rendering widgets editor * Replace empty div with null * Document persistStubPost * Document persistStubPost further * Bump version to 9.1.1 * Update changelog * Fix spaces in changelog.txt * Adjust spaces in changelog.txt * Fix link formatting in the changelog Co-authored-by: Jon Surrell <[email protected]> Co-authored-by: David Biňovec <[email protected]> Co-authored-by: Kai Hao <[email protected]> Co-authored-by: Daniel Richards <[email protected]>
Description
The widgets editor uses a "stub post" as a container for all widget areas. It must be initialized upfront or the data layer would attempt an API resolution. This PR adds that initialization.
How has this been tested?
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: