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

Use parse_request instead of wp_loaded action for scraping duotone data from theme.json #49343

Closed
wants to merge 1 commit into from

Conversation

jeryj
Copy link
Contributor

@jeryj jeryj commented Mar 24, 2023

Fixes #49324

What?

#49103 scrapes duotone theme.json data on wp_loaded, which causes theme.json to be cached too early and prevents editor-only selectors from being used in theme.json.

Why?

Not being able to generate editor-only selectors via theme.json causes a regression with the Image block and the border not being applied to the inline cropping area.

How?

Use parse_request instead of wp_loaded action to delay scraping duotone data from theme.json until after the editor-only selectors processes have finished.

Testing Instructions

  1. On trunk
  2. Add border styles to styles.blocks['core/image'].border in theme.json or via the global styles theme editor.
// theme.json
{
	"styles": {
	 	"blocks": {
	 		"core/image": {
	 			"border": {
	 				"radius": "24px",
	 				"style": "solid",
	 				"color": "red",
	 				"width": "4px"
	 			}
 	 	 	}
		}
	}
}
  1. In the post editor add an image block. The border image from global styles should be applied.
  2. Select to crop the image and notice the border is lost.
  3. Confirm there are no styles output matching the editor-only selector from image/block.json
  4. Switch to this branch fix/duotone-action-order
  5. In the post editor add an image block. The border image from global styles should be applied.
  6. Select to crop the image and notice the border is still present.

…ta from theme.json

Scraping on wp_loaded caused theme.json to be cached too early which prevents editor-only selectors from being used in theme.json.

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
@jeryj
Copy link
Contributor Author

jeryj commented Mar 24, 2023

Pairing with @ajlende and there's an issue with the selectors API from #46496 that is causing this issue when there are definitions in packages/block-library/src/image/block.json that are removing the duotone support unintentionally. Removing these lines from image/block.json allows the global styles to be applied again.

	"selectors": {
		"border": ".wp-block-image img"
	},
	"editorSelectors": {
		"border": ".wp-block-image img, .wp-block-image .wp-block-image__crop-area"
	},

@aaronrobertshaw
Copy link
Contributor

there's an issue with the selectors API

Thanks for flagging @jeryj 👍

The Selectors API got merged prematurely before I could get a final code review on it. I spotted this issue as well last week and put up a PR to update Duotone support to use the selectors API in #49325.

I think the better approach is to fix the issue rather than revert to a soon-to-be obsolete, experimental property.

@scruffian
Copy link
Contributor

I think this has now been fixed, so I think we can close this?

@ajlende ajlende closed this Mar 29, 2023
@aaronrobertshaw
Copy link
Contributor

I think this has now been fixed, so I think we can close this?

Has it actually been fixed or more that we've temporarily removed editor-only selectors?

We can of course re-open as necessary but trying to keep the caching of block metadata in theme.json as late as possible sounds less likely to trip up future enhancements to theme.json processing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duotone: Action causes premature caching of theme.json block nodes
4 participants