Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Remove additional call to
WP_Theme_JSON::_construct
#6271Remove additional call to
WP_Theme_JSON::_construct
#6271Changes from all commits
a184a82
a3523d0
53a5e2e
bbcc411
002c2cc
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some linting issues in the committed code, incorrect spacing before the equals signs here.
The main reason I'm looking at this though is that a new feature was merged in Gutenberg - WordPress/gutenberg#57908. It was testing fine prior to the changes on these lines, but after the change there's an exception being thrown by this change (I bisected to find it).
To repro:
wp-content/themes/twentytwentyfour/styles/block-style-contrast.json
:If you then revert the change on this line(s), the error goes away.
I don't have much of an understanding why this causes an issue. It'd be great to understand why it's happening before taking any action. I'll continue looking into it, but any help appreciated, as this'll need to be fixed prior to the 6.6 beta.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kt-12 @joemcgill @oandregal I think I have an understanding of what's happening, but worth noting I'm not an expert with these theme json classes.
The gutenberg codebase hooks into the
wp_theme_json_data_theme
filter, but can return aWP_Theme_JSON_Gutenberg
from the filter. Before your change, it didn't really matter as core would construct aWP_Theme_JSON
from that, but now I think the change can mean core holding on to aWP_Theme_JSON_Gutenberg
reference. This might be leading to some incompatibilities in the data structures. At some point the newerWP_Theme_JSON_Gutenberg
data is being processed by an olderWP_Theme_JSON
class, and that's when the error happens. I'm not sure exactly how that happens, still investigating.The core backport for the feature (#6662) does resolve the issue, as it updates
WP_Theme_JSON
to be compatible.But I think there are question marks over what happens when the gutenberg plugin tries to implement new features in the future that extend the theme json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @talldan. We had this reported to the related Trac ticket and have created this follow-up PR to address the issue. If you could test it and confirm that it fixes the issue, I can get it committed.
I think this is a very good question. I've had some discussion with @tellthemachines and @oandregal about making the
WP_Theme_JSON_
related classes read only in the WP-dev repo and sync them from the GB repo the way we sync other packages, which is one way to solve these incompatibilities, but we've not confirmed that approach. I need to open a new issue for us to consider those changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't have time to look at this today but will do next week. This smells to a bug we need to fix, for which we have time in the beta period. I'm available and happy to help uncover the issue and prepare a fix. Please, ping me in any related tickets/PR (subscribed to the PRs & trac tickets mentioned).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally got some time to look at this today. Sharing what I know.
The flow:
wp_theme_json_data_theme
filter.gutenberg_resolve_style_variations_*
runs as a filter callbackWP_Theme_JSON_Data_Gutenberg
which uses to validate the data (update_with
) and then returns.At 4, core receives some data and it expects it to be validated by the consumer of the filter (this is, the consumer uses
update_with
). While Gutenberg validates the data properly, it uses different metadata/schema than core does.In the particular case that Dan raised, Gutenberg was able to get more style variations than core had:
At the point of processing the variations, core is unable to find the first three variations, hence the
PHP Warning: Undefined array key "styleVariations" in /var/www/src/wp-includes/class-wp-theme-json.php on line 2445
raised here. Before this PR, core did an extra validation step, getting rid of the extraneous data before processing it, so that never happened.There's a few layers to this issue, and it only happens because Gutenberg is re-triggering the same filters than core (
wp_theme_json_data_theme
). The consumers of the filters run twice (one for core and the second time for the plugin). It's the first time that it fails because the metadata/schemas are different.Unlike this other issue, this is very Gutenberg-specific because it is the result of modifying the metadata/schema of the theme.json. I don't have any more time today to look into solutions, but wanted to share what I know about as soon as possible. I'll do some more testing in the next days to assess the severity and what can we do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a different issue, I ended up proposing a change to how "block style variations" defined by the theme are registered at #6756 By doing that, the error reported by Dan no longer happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this @oandregal. It still seems like this is very similar to https://core.trac.wordpress.org/ticket/61112, but seems like the problem is that because core is not converting the
WP_Theme_JSON_Data_Gutenberg
object back into aWP_Theme_JSON_Data
object, the incompatibilities are possible.It seems wrong that Gutenberg would return an object from these filters that are not compatible with
WP_Theme_JSON_Data
objects, but we may be able to simply update the fix proposed in #6626 to check for whether the returned object is aWP_Theme_JSON_Data
object, and reprocess if not, rather than just if it aget_theme_json
method exists on the class.As a matter of process, I think following up on this whole issue should be done in as a part of https://core.trac.wordpress.org/ticket/61112 so this doesn't get lost, so I'm going to summarize this issue on that ticket and update the PR with the new approach I just proposed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the approach in #6626 that should address the exception @talldan describes, though better ways of extending these objects in the Gutenberg repo are still worth investigating further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I've noticed after reviewing the Gutenberg PR WordPress/gutenberg#61262 is that this is different in Gutenberg: there, we do
$config['isGlobalStylesUserThemeJSON'] = true;
before the call toWP_Theme_JSON
. We need to consolidate that logic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like #6616 will undo this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@talldan w.r.t to keeping both the repos same, that change should be fine. But w.r.t performance we might need to find a better way to do that later on.