-
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
Navigation: Avoid content loss when only specific entity fields are edited #60071
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1520,6 +1520,14 @@ function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) { | |
return $post; | ||
} | ||
|
||
/** | ||
* Skip meta generation when consumers intentionally update specific Navigation fields | ||
* and omit the content update. | ||
*/ | ||
if ( ! isset( $post->post_content ) ) { | ||
return $post; | ||
} | ||
Comment on lines
+1523
to
+1529
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still want to generate meta when the requests skip content updates? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand this correctly, the hook looks at If the REST request doesn't modify I'm more curious about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is correct. We could also use the Unfortunately, I'm not very familiar with the internals of Block Hooks API. @ockham and @tjcafferkey can provide more details. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ideally the Because
I believe the fix in #59875 is not 100% correct. The code needs the The current code will fail to set the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks both. You are right @jsnajdr in saying this.
The fix in #59875 was accepted to cover a fatal error happening in what we considered to be an edge-case. It's not 'ideal', and I'm sure there's a solution in what you mentioned above. Unfortunately time was not on our side when this was reported and considered it more important to fix the error. I'm going to create a follow-up issue to look into a better solution. cc @ockham incase I've misspoken or there's something further to add 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to add to this.
We will never get this data in the request since the Navigation block (which contains the metadata) and its inner blocks are detached, the POST request would only contain inner block data. In the function above we have to mock the Navigation block in order to generate the necessary meta data to save. We do this because we assume the incoming $post data is coming from the Site Editor where the Block Hooks algorithm has already run when preparing the response for the Editor to insert the hooked blocks. Still, a follow-up issue should be created to look if there's a better solution to tackle the side effect detailed in the description of #59875. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My apologies, I've only seen this now, since I wasn't working on Friday. Anyway, thanks a lot @jsnajdr for reporting #59991, @Mamaduka for this fix, and @tjcafferkey for the follow-up clarification! I think your reasoning about the issue is spot-on, as is the fix. I'll try to address some of the concerns that Jarda raised about #59875: https://github.com/WordPress/gutenberg/pull/60071/files#r1533833240:
This was covered by Tom in the PR description of #59875:
https://github.com/WordPress/gutenberg/pull/60071/files#r1535417586:
Yes, that's something we learned the hard way (as writing twice even causes an issue with encoding): #59561. Aside, with some background.What makes things even trickier is that the mechanism that injects Block Hooks (and the related Note that this is only a problem for the filter
This would however require us to communicate a bunch of data computed in |
||
|
||
/* | ||
* We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into | ||
* all anchor blocks. For the root level, we create a mock Navigation and extract them from there. | ||
|
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.
Noting that this is
stdClass
because it’s hooked to https://developer.wordpress.org/reference/hooks/rest_pre_insert_this-post_type/.