Commit 2e2829904b for wordpress.org

commit 2e2829904b5eca69922e6d766ee9db2112a67a5a
Author: hellofromTonya <hellofromTonya@git.wordpress.org>
Date:   Mon Dec 6 22:42:00 2021 +0000

    Editor: Allow theme.json to take precedence in setting the root level element's reset margin value.

    Any margin added to the root element via `theme.json` is overwritten by a CSS reset margin value provided by the Gutenberg Plugin.

    This commit makes `theme.json` setting take precedence by generating the global styles body reset prior to processing the theme.json.

    Follow-up to [52049].

    Props get_dave, hellofromTonya.
    Fixes #54550.
    Built from https://develop.svn.wordpress.org/trunk@52329


    git-svn-id: http://core.svn.wordpress.org/trunk@51921 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php
index f13569f788..66b7d55e7d 100644
--- a/wp-includes/class-wp-theme-json.php
+++ b/wp-includes/class-wp-theme-json.php
@@ -355,9 +355,9 @@ class WP_Theme_JSON {
 	 *
 	 * @since 5.8.0
 	 *
-	 * @param array $theme_json A structure that follows the theme.json schema.
-	 * @param string $origin    Optional. What source of data this object represents.
-	 *                          One of 'default', 'theme', or 'custom'. Default 'theme'.
+	 * @param array  $theme_json A structure that follows the theme.json schema.
+	 * @param string $origin     Optional. What source of data this object represents.
+	 *                           One of 'default', 'theme', or 'custom'. Default 'theme'.
 	 */
 	public function __construct( $theme_json = array(), $origin = 'theme' ) {
 		if ( ! in_array( $origin, self::VALID_ORIGINS, true ) ) {
@@ -776,6 +776,18 @@ class WP_Theme_JSON {
 				}
 			}

+			/*
+			 * Reset default browser margin on the root body element.
+			 * This is set on the root selector **before** generating the ruleset
+			 * from the `theme.json`. This is to ensure that if the `theme.json` declares
+			 * `margin` in its `spacing` declaration for the `body` element then these
+			 * user-generated values take precedence in the CSS cascade.
+			 * @link https://github.com/WordPress/gutenberg/issues/36147.
+			 */
+			if ( self::ROOT_BLOCK_SELECTOR === $selector ) {
+				$block_rules .= 'body { margin: 0; }';
+			}
+
 			// 2. Generate the rules that use the general selector.
 			$block_rules .= self::to_ruleset( $selector, $declarations );

@@ -786,7 +798,6 @@ class WP_Theme_JSON {
 			}

 			if ( self::ROOT_BLOCK_SELECTOR === $selector ) {
-				$block_rules .= 'body { margin: 0; }';
 				$block_rules .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }';
 				$block_rules .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
 				$block_rules .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 03ad333ee3..db79323ae4 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '5.9-beta1-52328';
+$wp_version = '5.9-beta1-52329';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.