Open aaronrobertshaw opened 1 year ago
cc/ @ajlende @jeryj would you mind taking a look at this one? In particular, if it is possible for the duotone action to use a hook later in the cycle?
While updating Duotone to use the selectors API in https://github.com/WordPress/gutenberg/pull/49325. I found that moving the set_global_style_block_names
action from wp_loaded
to parse_request
was sufficient to both, keep duotone working on the frontend (using #49325), and delay the theme.json block node retrieval long enough for the editor-only selectors to work via get_current_screen
.
This seems too brittle though so any ideas on perhaps invalidating the theme.json block metadata cache when accessed for the first time in the editor would be welcome 🙏
@oandregal do you have any wisdom to share?
This seems too brittle though so any ideas on perhaps invalidating the theme.json block metadata cache when accessed for the first time in the editor would be welcome pray
I would recommend against this.
It seems to me that the core issue is that WP_Theme_JSON_Gutenberg
uses the get_current_screen
when it shouldn't, as it makes this class coupled to a certain WordPress flow. Ideally, this class should be "pure": unaware of the context, the output should only depend on the input.
I don't know enough of the new selectors API to be more concrete, sorry, but I can start by offering the following thoughts:
get_stylesheet
method takes a $types
array because it needs different output depending on the context (editor, front, etc.).In particular, if it is possible for the duotone action to use a hook later in the cycle?
Honestly, I looked at where some other blocks had commonly hooked into for their actions. If delaying the action to parse_request
works to resolve the issue and keeps duotone output working correctly on the frontend, then that's fine with me! I'll test it out and open a PR.
cc @ajlende
@aaronrobertshaw I put in a PR at https://github.com/WordPress/gutenberg/pull/49343 to update the action to parse_request
. I'm having trouble reproducing this issue though. I've tried in two different environments, thinking maybe it was related to the dev environment not using the caching or something similar. It's very possible I'm misunderstanding the testing instructions.
Edit: @scruffian helped me understand how to reproduce it. I was applying the global duotone style to the image in the editor, rather than via the global styles theme editor.
Glad you were able to sort it out @jeryj 👍
I was applying the global duotone style to the image in the editor, rather than via the global styles theme editor.
That's the catch. Global styles are global styles and aren't applied to specific individual blocks in the block editor. The application of a duotone filter to a specific block is a "block support". There's so much overlap between the two it gets tricky to maintain the difference and nuance in conversation.
It seems to me that the core issue is that WP_Theme_JSON_Gutenberg uses the get_current_screen when it shouldn't
🙇 Thanks @oandregal for the idea. Just the sort of feedback I was hoping to get on the Selectors API PR as I wasn't sure about this approach and it was part of why I was chasing a final review of the API before merging. Unfortunately, I didn't communicate that desire clearly in my PR comments, so it merged prematurely.
We have a little time before the next Gutenberg release, so If I can't move the detection of being in the editor, outside the class, the switch to the parse_request
action is a quick fix to buy some time.
Can we make "the context" a parameter of some method? For example: the get_stylesheet method takes a $types array because it needs different output depending on the context (editor, front, etc.).
I'll try and put a PR together for this. Honestly, though at this point, I don't exactly know where I should move the detection of being in the editor, to be able to pass it as context.
Why the new selector API needs editor selectors and front-end selectors when the old API didn't?
You could argue the old API did need editor selectors but fell short in not offering them. By not offering editor-only selectors, we were outputting useless CSS on the frontend just so we could get global styles to be applied correctly in the editor.
The counterpoint to that was the old API didn't need editor-only selectors because it didn't care about the extra unused CSS on the frontend.
Description
In https://github.com/WordPress/gutenberg/pull/49103, SVG filter output was limited to only used filters. Part of this approach involved scraping block names using filters via the
wp_loaded
hook. It appears this is causing the theme.json block node processing to occur before theget_current_screen
global function is available which prevents editor-only selectors from being used in theme.json.Expected Behaviour
Duotone filter processing would occur after we might alter selectors for the editor.
Actual behaviour
Duotone actions cause caching of theme.json block node data prematurely.
Not being able to generate editor-only selectors via theme.json means that https://github.com/WordPress/gutenberg/pull/46496 causes a regression with the Image block and the border not being applied to the inline cropping area.
Potential Solutions
wp_enqueue_scripts
fixes the editor-only selectors although I don't know the implications for duotone)Step-by-step reproduction instructions
styles.blocks['core/image'].border
in theme.jsonimage/block.json
Screenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes