Automattic / newspack-blocks

Gutenberg blocks for the Newspack project.
208 stars 43 forks source link

fix: potential fatal with invalid attribute combo #1900

Closed dkoo closed 1 month ago

dkoo commented 1 month ago

All Submissions:

Changes proposed in this Pull Request:

Fixes an obscure edge case that we've nevertheless seen out in the wild, which can potentially cause a fatal error.

How to test the changes in this Pull Request:

  1. On trunk, add a Checkout Button block to a post or page and set it to a variable product.
  2. Enter Code Editing mode and replace the variation attribute and the value in the hidden input for variation_id with an empty space, like so (you can also replace it with a gibberish string):
<!-- wp:newspack-blocks/checkout-button {"product":"662","variation":" ","is_variable":true,"price":"","text":"Invalid Checkout Button"} -->
<div class="wp-block-newspack-blocks-checkout-button wp-block-button"><form><button class="wp-block-button__link">Invalid Checkout Button</button><input type="hidden" name="product_id" value="662"/><input type="hidden" name="newspack_checkout" value="1"/><input type="hidden" name="variation_id" value=" "/><input type="hidden" name="is_variable" value="1"/><input type="hidden" name="after_success_button_label" value="Continue browsing"/></form></div>
<!-- /wp:newspack-blocks/checkout-button -->
  1. Exit Code Editing mode and observe that the block attribute are now in this strange invalid state (no variation selected, but the "Allow the reader to select the variation before checkout" option also unchecked):
Screenshot 2024-10-09 at 10 17 37 AM
  1. View the block on the front-end and observe that it results in a critical error.
  2. Check out this branch, refresh the front-end, and confirm that there's no fatal and that clicking the block brings up the modal checkout with the first/default variation.

Other information:

matticbot commented 1 month ago

:tada: This PR is included in version 4.2.3-alpha.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

matticbot commented 1 month ago

:tada: This PR is included in version 4.2.4-alpha.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

matticbot commented 1 month ago

:tada: This PR is included in version 4.3.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: