WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.49k stars 4.18k forks source link

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

Closed ramonjd closed 1 day ago

ramonjd commented 1 day ago

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 https://github.com/WordPress/gutenberg/pull/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

github-actions[bot] commented 1 day ago

Flaky tests detected in 72a47a32f4dd212c3c0d04e74124175b345a53c4. 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:

github-actions[bot] commented 1 day ago

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.

ramonjd commented 1 day ago

Thanks for testing!!

aaronrobertshaw commented 1 day ago

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!