Fix for WP_Theme_JSON_Resolver_Gutenberg::get_merged_data
#48644
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.
Related trac ticket https://core.trac.wordpress.org/ticket/57824
Reverts WordPress/wordpress-develop#3441
Backport PR WordPress/wordpress-develop#4145
What
This PR fixes a bug by which the reset function of the global styles sidebar wouldn't work as expected in the site editor.
How to reproduce
Take the following steps:
Note that if this is saved and then site editor reloaded, the proper data is shown.
How this PR fixes the issue
By reverting WordPress/wordpress-develop#3441 which was the one that introduced the issue.
That PR changed the
get_merged_data
code to (pseudo-code):However, by doing so, the base object (
$result
) is modifying the$core
object directly, and$core
ends up storing the consolidated values instead of only the ones coming from thetheme.json
provided by core.This is problematic because
$core
data is cached. Take, for example, the following scenario:The expected output for
$data
is that it should not have data coming from the 'custom' origin, however, it does.The fix is reverting the change and use an empty object as base (pseudo-code):
Performance
(The performance data is taken from core, not Gutenberg. Left here as a section for visibility).
This is a bug that needs to be fixed. I thought about running some performance analysis anyway, given the intent of the PR this reverts was improving performance. Given the improvements introduced in 6.2, reverting the PR doesn't affect performance.
Using XDebug (only for completeness, we should not use data extracted from a xdebug profiler to make perf decisions, as there's a cost to observability):
WP_Theme_JSON_Resolver::get_merged_data
WP_Theme_JSON->merge
Using production code (see raw data): the variance is sub-millisecond, so it may be attributed to the measuring conditions.