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

Allow blocks with parents in the woocommerce namespace to be rendered as inner blocks #48543

Merged
merged 15 commits into from
Jul 2, 2024

Conversation

opr
Copy link
Contributor

@opr opr commented Jun 17, 2024

Changes proposed in this Pull Request:

  • Cache the list of registered block types with at least one parent block in the woocommerce namespace. Do this on init.
  • When checking blocks that can have data-block-name added, consider if their parent is in the woocommerce namespace (cached above)

Closes #46264

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Register a custom block, in this example we'll be using the @woocommerce/extend-cart-checkout-block test-block package.
  2. Go to wp-content/plugins and run npx @wordpress/create-block -t @woocommerce/extend-cart-checkout-block test-block.
  3. Edit the block's "lock" attribute (go to src/js/checkout-newsletter-subscription/block.json) so it is:
	"lock": {
			"type": "object",
			"default": {
				"remove": false,
				"move": true
			}
		},
  1. Make sure the block is rebuilt after changing this (use npm run start)
  2. Go to the Checkout block in the editor, and go to the contact information block.
  3. Add a new block, and select the Newsletter Subscription! block.
  4. Add another new block and select the core Image block. Add an image to it.
  5. Save the page.
  6. Go to the front-end, add an item to your cart and visit the Checkout block.
  7. Ensure you see the newsletter subscription block and the image block.
image
  1. Go back to the editor and delete the newsletter subscription block. Save the page.
  2. Reload the Checkout block in the editor and ensure the newsletter subscription block is not there.
  3. Reload the Checkout block on the front-end and ensure the newsletter subscription block is not there.
  4. Go back to the block.json settings and set the lock.remove property to true.
  5. Save and build, then go to the Checkout block on the front end.
  6. Ensure the newsletter subscription block is visible again.

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jun 17, 2024
@opr opr self-assigned this Jun 17, 2024
Copy link
Contributor

github-actions bot commented Jun 17, 2024

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

Copy link
Contributor

github-actions bot commented Jun 17, 2024

Size Change: 0 B

Total Size: 2.49 MB

compressed-size-action

Copy link
Contributor

github-actions bot commented Jun 25, 2024

Hi @mikejolley, @senadir,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Copy link
Member

@mikejolley mikejolley left a comment

Choose a reason for hiding this comment

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

I got your testing steps to work, but there are some improvements we can make to the cache. I left comments below.

@opr
Copy link
Contributor Author

opr commented Jun 27, 2024

@mikejolley I also added PHP unit tests for this.

@opr opr requested a review from mikejolley June 27, 2024 21:12
Copy link
Member

@mikejolley mikejolley left a comment

Choose a reason for hiding this comment

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

Thanks for making those improvements @opr

Happy with this so pre-approving. However the CI linting rules are not happy with the tests so make sure to appease the CI before merging.

@opr opr force-pushed the fix/rendering-unforced-blocks branch from 44c50b2 to 6d833fb Compare July 2, 2024 11:09
@opr opr force-pushed the fix/rendering-unforced-blocks branch from 6d833fb to 622584f Compare July 2, 2024 12:53
return $this->registered_blocks_with_woocommerce_parents;
}

$registered_blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered();
Copy link
Member

Choose a reason for hiding this comment

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

Not all blocks are PHP registered, but this should work.

Copy link
Member

@senadir senadir left a comment

Choose a reason for hiding this comment

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

Approving this, I'd wish we don't really need this for now, but I can't think of something else.

@opr opr merged commit a032d4f into trunk Jul 2, 2024
38 checks passed
@opr opr deleted the fix/rendering-unforced-blocks branch July 2, 2024 17:24
@github-actions github-actions bot added this to the 9.2.0 milestone Jul 2, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Jul 2, 2024
@nigeljamesstevenson nigeljamesstevenson added status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Jul 3, 2024
mattsherman pushed a commit that referenced this pull request Jul 3, 2024
thealexandrelara pushed a commit that referenced this pull request Jul 18, 2024
@ralucaStan ralucaStan added the team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues label Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom inner block is not rendered on checkout when added manually from block editor
5 participants