Skip to content
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

Block Hooks: Return early from saving meta data for the navigation without a $post->ID #59875

Merged
merged 11 commits into from
Mar 15, 2024

Conversation

tjcafferkey
Copy link
Contributor

@tjcafferkey tjcafferkey commented Mar 14, 2024

What?

If the user is creating a navigation menu via a POST request to the REST API then we need to return early since we won't have a $post->ID to store the ignored hooked blocks meta against.

Why?

There are a number of reasons for this change but primarily because it returns an error since it incorrectly assumes there's a $post->ID in a scenario when there's not.

Another reason is because if the user is creating the navigation via the REST API they likely haven't got any hooked blocks in their content since we insert these when the response is being prepared for the site editor.

The only other way a user can create a new navigation is by duplicating an existing one. In which case the hooked blocks markup and meta data will be duplicated along with it and will retain the intended behaviour.

A known side effect of this means that the next time this navigation is loaded (if the user is creating it via the REST API outside of the site editor), if it has any anchor blocks it will proceed to insert the hooked blocks since we won't have run the ignored hooked blocks logic for reasons mentioned above. Whether this is a 'bug' or not I think is still a bit of a grey area but given that I believe this is an edge case I think its acceptable until we decide a better course of action.

Fixes #59867

How?

Check for the existence of a $post->ID and if not found, return $post early.

Testing Instructions

  1. Regression test the navigation if we feel its required.
  2. Create a navigation via the REST API similar to how is done in accompanying tests and ensure you get a successful response.
@tjcafferkey tjcafferkey self-assigned this Mar 14, 2024
@Mamaduka Mamaduka added the [Type] Bug An existing feature does not function as intended label Mar 14, 2024
@tjcafferkey tjcafferkey marked this pull request as ready for review March 14, 2024 13:26
Copy link

github-actions bot commented Mar 14, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: tjcafferkey <tomjcafferkey@git.wordpress.org>
Co-authored-by: ockham <bernhard-reiter@git.wordpress.org>
Co-authored-by: Hug0-Drelon <hugod@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@tjcafferkey tjcafferkey requested a review from ockham March 14, 2024 13:27
@ockham ockham added the Backport to WP 6.6 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Mar 14, 2024
@ockham
Copy link
Contributor

ockham commented Mar 14, 2024

@youknowriad @getdave This fixes #59867, which is bad enough to warrant including the fix in RC3 IMO.

tjcafferkey and others added 3 commits March 14, 2024 14:08
Co-authored-by: Bernie Reiter <96308+ockham@users.noreply.github.com>
Co-authored-by: Bernie Reiter <96308+ockham@users.noreply.github.com>
@tjcafferkey
Copy link
Contributor Author

tjcafferkey commented Mar 14, 2024

@getdave the newly added unit test is failing on this PR but passes locally. I suspect it's because the test is running against the built version of this change, and in the CI that isn't done? Wondering if my hunch is right and if so, is there a standardized way to approach this?

Edit: You can now ignore this, @getdave

Co-authored-by: Hugo Drelon <69580439+Hug0-Drelon@users.noreply.github.com>
@tjcafferkey
Copy link
Contributor Author

tjcafferkey commented Mar 14, 2024

@getdave the newly added unit test is failing on this PR but passes locally. I suspect it's because the test is running against the built version of this change, and in the CI that isn't done? Wondering if my hunch is right and if so, is there a standardized way to approach this?

Actually it looks like npm run build is run in the workflow prior to tests, which should have built the navigation.php file 🤔

@tjcafferkey
Copy link
Contributor Author

tjcafferkey commented Mar 14, 2024

Looking at the test report, it looks like its failing on /var/www/html/wp-includes/blocks/navigation.php:1479 which is the block file from WP core (not GB) and likely won't have this change present. Perhaps a different way to write the test is needed.

Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for taking care of this, @tjcafferkey!

@tjcafferkey tjcafferkey merged commit 2e340d7 into trunk Mar 15, 2024
57 checks passed
@tjcafferkey tjcafferkey deleted the fix/check-navigation-post-id-before-saving-meta branch March 15, 2024 10:43
@github-actions github-actions bot added this to the Gutenberg 18.0 milestone Mar 15, 2024
@tjcafferkey
Copy link
Contributor Author

@getdave I'm unfamiliar with the process of backporting here (are there any docs explaining the process?). Is there anything further required of me post-merge? 🙏🏻 thanks.

@youknowriad
Copy link
Contributor

Since this change is in the block library code, there's nothing else that should be done aside adding the backport label. At this point in the release cycle, the label should only be added to the regressions that happened during 6.5 cycle and it seems to be the case for the current PR.

@ockham ockham mentioned this pull request Mar 18, 2024
16 tasks
youknowriad pushed a commit that referenced this pull request Mar 18, 2024
…thout a $post->ID (#59875)

Co-authored-by: Bernie Reiter <96308+ockham@users.noreply.github.com>
Co-authored-by: Hugo Drelon <69580439+Hug0-Drelon@users.noreply.github.com>
@youknowriad
Copy link
Contributor

I just cherry-picked this PR to the update/packages-rc2-6.5 branch to get it included in the next release: ce4250a

@youknowriad youknowriad added Backported to WP Core Pull request that has been successfully merged into WP Core and removed Backport to WP 6.6 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Mar 18, 2024
@getdave
Copy link
Contributor

getdave commented Mar 18, 2024

@getdave I'm unfamiliar with the process of backporting here (are there any docs explaining the process?). Is there anything further required of me post-merge? 🙏🏻 thanks.

Hi @tjcafferkey. Thanks for reaching out - looks like Riad got here before me with all the correct info 👍

I agree the backporting process can be pretty confusing. As a result I've spent time during this release documenting which files need manual backporting and which will be handled as part of the standard release process.

I'd greatly value your feedback on this in order that it can be made even clearer for future releases. This will help all contributors become aware of the process and make the task of managing the release slightly easier for release leads.

getdave pushed a commit that referenced this pull request Mar 18, 2024
…thout a $post->ID (#59875)

Co-authored-by: Bernie Reiter <96308+ockham@users.noreply.github.com>
Co-authored-by: Hugo Drelon <69580439+Hug0-Drelon@users.noreply.github.com>
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Mar 27, 2024
…thout a $post->ID (WordPress#59875)

Co-authored-by: Bernie Reiter <96308+ockham@users.noreply.github.com>
Co-authored-by: Hugo Drelon <69580439+Hug0-Drelon@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core [Block] Navigation Affects the Navigation Block [Feature] Block hooks [Type] Bug An existing feature does not function as intended
6 participants