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

Theme JSON: replace top-level background style objects on merge #66656

Merged

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Nov 1, 2024

What?

This PR fixes an omission in the theme json merge logic where top-level background image objects are not replaced, rather they are merged, which was the state of affairs before #64128

Blocks are already catered for via ::get_block_nodes().

Why?

Consider the following: I want to merge existing JSON A with incoming JSON B.

{
	"title" : "JSON A",
	"styles": {
		"background": {
			"backgroundImage": {
				"id": 1,
				"url": "http://example-site/wp-content/uploads/11/2024/test.jpg"
			}
		}
	}
}
{
	"title" : "JSON B",
	"styles": {
		"background": {
			"backgroundImage": {
				"url": "http://some-other-site/new.jpg"
			}
		}
	}
}

In trunk the outcome would be:

{
	"title" : "JSON A",
	"styles": {
		"background": {
			"backgroundImage": {
				"id": 1,
				"url": "http://some-other-site/new.jpg"
			}
		}
	}
}

Notice the "id" property, which does not belong to the new image. The entire object should be replaced.

How?

Add the top-level styles path to the paths to be merged.

Testing Instructions

Run the unit tests: npm run test:unit:php:base -- --filter WP_Theme_JSON_Gutenberg_Test

…-level background image objects are not replaced, rather they are merged, which was the state of affairs before #64128
@ramonjd ramonjd added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Nov 1, 2024
@ramonjd ramonjd self-assigned this Nov 1, 2024
Copy link

github-actions bot commented Nov 1, 2024

Flaky tests detected in 72a47a3.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11623192696
📝 Reported issues:

Copy link

github-actions bot commented Nov 1, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

Good catch! Yeah, I could imagine the merge being unexpected if and when we allow the UI to support folks using external urls for background images, too.

The logic looks good to me, and I gave background images in theme.json and uploaded via the site editor a smoke test with a variety of permutations and didn't run into any issues.

LGTM! 🚀

@ramonjd
Copy link
Member Author

ramonjd commented Nov 1, 2024

Thanks for testing!!

@ramonjd ramonjd merged commit 11e2d06 into trunk Nov 1, 2024
64 checks passed
@ramonjd ramonjd deleted the fix/theme-json-merge-merge-top-level-background-image-styles branch November 1, 2024 04:47
@github-actions github-actions bot added this to the Gutenberg 19.7 milestone Nov 1, 2024
@aaronrobertshaw
Copy link
Contributor

Bit slow to the party (as usual) but this works as advertised for me also. All the merge variations I tried produced the expected results.

Thanks for the fix!

karthick-murugan pushed a commit to karthick-murugan/gutenberg that referenced this pull request Nov 13, 2024
…Press#66656)

This commit fixes an omission in the theme json merge logic where top-level background image objects are not replaced, rather they are merged, which was the state of affairs before WordPress#64128

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants