Skip to content

Commit

Permalink
prep build 5/27
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed May 27, 2024
2 parents d5a316e + 8c3a688 commit bd5b8f4
Show file tree
Hide file tree
Showing 491 changed files with 4,666 additions and 5,024 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ module.exports = {
],
globals: {
wp: 'off',
globalThis: 'readonly',
},
settings: {
jsdoc: {
Expand All @@ -104,7 +105,7 @@ module.exports = {
'jest/expect-expect': 'off',
'react/jsx-boolean-value': 'error',
'@wordpress/dependency-group': 'error',
'@wordpress/is-gutenberg-plugin': 'error',
'@wordpress/wp-global-usage': 'error',
'@wordpress/react-no-unsafe-timeout': 'error',
'@wordpress/i18n-text-domain': [
'error',
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/check-backport-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Verify Core Backport Changlog

on:
pull_request:
types: [opened, synchronize]
types: [opened, synchronize, labeled, unlabeled]
paths:
- 'lib/**'
- '!lib/load.php'
Expand Down Expand Up @@ -31,6 +31,7 @@ jobs:
- name: 'Fetch relevant history from origin'
run: git fetch origin ${{ github.event.pull_request.base.ref }}
- name: Check CHANGELOG status
if: ${{ !contains(github.event.pull_request.labels.*.name, 'No Core Sync Required') && !contains(github.event.pull_request.labels.*.name, 'Backport from WordPress Core') }}
env:
PR_NUMBER: ${{ github.event.number }}
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ concurrency:

jobs:
performance:
timeout-minutes: 60
name: Run performance tests
runs-on: ubuntu-latest
if: ${{ github.repository == 'WordPress/gutenberg' }}
Expand Down
3 changes: 3 additions & 0 deletions backport-changelog/6.6/6279.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/6279

* https://github.com/WordPress/gutenberg/pull/60063
4 changes: 4 additions & 0 deletions backport-changelog/6.6/6567.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
https://github.com/WordPress/wordpress-develop/pull/6567

* https://github.com/WordPress/gutenberg/pull/47271
* https://github.com/WordPress/gutenberg/pull/61774
3 changes: 3 additions & 0 deletions backport-changelog/6.6/6605.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/6605

* https://github.com/WordPress/gutenberg/pull/61851
248 changes: 118 additions & 130 deletions changelog.txt

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/contributors/code/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ An **plugin-only API** is one which is planned for eventual public availability,
Plugin-only APIs are excluded from WordPress Core and only available in the Gutenberg Plugin:

```js
// Using process.env.IS_GUTENBERG_PLUGIN allows Webpack to exclude this
// Using globalThis.IS_GUTENBERG_PLUGIN allows Webpack to exclude this
// export from WordPress core:
if ( process.env.IS_GUTENBERG_PLUGIN ) {
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
export { doSomethingExciting } from './api';
}
```
Expand Down Expand Up @@ -448,8 +448,8 @@ lock( privateApis, { privateEverywhere, privateInCorePublicInPlugin } );

// The privateInCorePublicInPlugin function is explicitly exported,
// but this export will not be merged into WordPress core thanks to
// the process.env.IS_GUTENBERG_PLUGIN check.
if ( process.env.IS_GUTENBERG_PLUGIN ) {
// the globalThis.IS_GUTENBERG_PLUGIN check.
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
export const privateInCorePublicInPlugin =
unlock( privateApis ).privateInCorePublicInPlugin;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Our approach—as outlined in [the technical overview introduction](https://make

This also [gives us the flexibility](https://github.com/WordPress/gutenberg/issues/1516) to store those blocks that are inherently separate from the content stream (reusable pieces like widgets or small post type elements) elsewhere, and just keep token references for their placement.

We suggest you look at the [Gutenberg key concepts](/docs/getting-started/architecture/key-concepts.md) to learn more about how this aspect of the project works.
We suggest you look at the [Gutenberg key concepts](/docs/explanations/architecture/key-concepts.md) to learn more about how this aspect of the project works.

### How can I parse the post content back out into blocks in PHP or JS?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The [build process](docs/block-editor/getting-started/fundamentals/javascript-in

The `block.json` file contains the [block's metadata](docs/block-editor/reference-guides/block-api/block-metadata/), streamlining its definition and registration across client-side and server-side environments.

This file includes the block name, description, [attributes](docs/block-editor/reference-guides/block-api/block-attributes.md), [supports](docs/block-editor/reference-guides/block-api/block-supports.md), and more, as well as the locations of essential files responsible for the block's functionality, appearance, and styling.
This file includes the block name, description, [attributes](docs/block-editor/reference-guides/block-api/block-attributes/), [supports](docs/block-editor/reference-guides/block-api/block-supports/), and more, as well as the locations of essential files responsible for the block's functionality, appearance, and styling.

When a build process is applied, the `block.json` file and the other generated files are moved to a designated folder, often the `build` folder. Consequently, the file paths specified within `block.json` point to these processed, bundled versions of the files.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ As of Gutenberg version 14.2, the following controls are available:
- `sticky` - Shows a dropdown to select how to handle sticky posts.
- `taxQuery` - Shows available taxonomies filters for the currently selected post type.
- `author` - Shows an input field to filter the query by author.
- `search` - Shows an input filed to filter the query by keywords.
- `search` - Shows an input field to filter the query by keywords.

In our case, the property would look like this:

Expand Down
27 changes: 15 additions & 12 deletions docs/how-to-guides/feature-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

'Feature flags' are variables that allow you to prevent specific code in the Gutenberg project from being shipped to WordPress core, and to run certain experimental features only in the plugin.

## Introducing `process.env.IS_GUTENBERG_PLUGIN`
## Introducing `globalThis.IS_GUTENBERG_PLUGIN`

The `process.env.IS_GUTENBERG_PLUGIN` is an environment variable whose value 'flags' whether code is running within the Gutenberg plugin.
The `globalThis.IS_GUTENBERG_PLUGIN` is an environment variable whose value 'flags' whether code is running within the Gutenberg plugin.

When the codebase is built for the plugin, this variable will be set to `true`. When building for WordPress core, it will be set to `false` or `undefined`.

Expand All @@ -19,8 +19,9 @@ function myPluginOnlyFeature() {
// implementation
}

export const pluginOnlyFeature =
process.env.IS_GUTENBERG_PLUGIN ? myPluginOnlyFeature : undefined;
export const pluginOnlyFeature = globalThis.IS_GUTENBERG_PLUGIN
? myPluginOnlyFeature
: undefined;
```

In the above example, the `pluginOnlyFeature` export will be `undefined` in non-plugin environments such as WordPress core.
Expand All @@ -32,37 +33,39 @@ If you're attempting to import and call a plugin-only feature, be sure to wrap t
```js
import { pluginOnlyFeature } from '@wordpress/foo';

if ( process.env.IS_GUTENBERG_PLUGIN ) {
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
pluginOnlyFeature();
}
```

## How it works

During the webpack build, instances of `process.env.IS_GUTENBERG_PLUGIN` will be replaced using webpack's [define plugin](https://webpack.js.org/plugins/define-plugin/).
During the webpack build, instances of `globalThis.IS_GUTENBERG_PLUGIN` will be replaced using webpack's [define plugin](https://webpack.js.org/plugins/define-plugin/).

For example, in the following code –

```js
if ( process.env.IS_GUTENBERG_PLUGIN ) {
if ( globalThis.IS_GUTENBERG_PLUGIN ) {
pluginOnlyFeature();
}
```

– the variable `process.env.IS_GUTENBERG_PLUGIN` will be replaced with the boolean `true` during the plugin-only build:
– the variable `globalThis.IS_GUTENBERG_PLUGIN` will be replaced with the boolean `true` during the plugin-only build:

```js
if ( true ) { // Wepack has replaced `process.env.IS_GUTENBERG_PLUGIN` with `true`
if ( true ) {
// Wepack has replaced `globalThis.IS_GUTENBERG_PLUGIN` with `true`
pluginOnlyFeature();
}
```

This ensures that code within the body of the `if` statement will always be executed.

In WordPress core, the `process.env.IS_GUTENBERG_PLUGIN` variable is replaced with `undefined`. The built code looks like this:
In WordPress core, the `globalThis.IS_GUTENBERG_PLUGIN` variable is replaced with `undefined`. The built code looks like this:

```js
if ( undefined ) { // Wepack has replaced `process.env.IS_GUTENBERG_PLUGIN` with `undefined`
if ( undefined ) {
// Webpack has replaced `globalThis.IS_GUTENBERG_PLUGIN` with `undefined`
pluginOnlyFeature();
}
```
Expand Down Expand Up @@ -99,6 +102,6 @@ In this case, the minification process will remove the entire `if` statement inc

## Frequently asked questions

### Why shouldn't I assign the result of an expression involving `IS_GUTENBERG_PLUGIN` to a variable, e.g. `const isMyFeatureActive = process.env.IS_GUTENBERG_PLUGIN === 2`?
### Why shouldn't I assign the result of an expression involving `IS_GUTENBERG_PLUGIN` to a variable, e.g. `const isMyFeatureActive = ! Object.is( undefined, globalThis.IS_GUTENBERG_PLUGIN )`?

Introducing complexity may prevent webpack's minifier from identifying and therefore eliminating dead code. Therefore it is recommended to use the examples in this document to ensure your feature flag functions as intended. For further details, see the [Dead Code Elimination](#dead-code-elimination) section.
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ Add an image or video with a text overlay. ([Source](https://github.com/WordPres

- **Name:** core/cover
- **Category:** media
- **Supports:** align, anchor, color (heading, text, ~~background~~, ~~enableContrastChecker~~), dimensions (aspectRatio), interactivity (clientNavigation), layout (~~allowJustification~~), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align, anchor, color (heading, text, ~~background~~, ~~enableContrastChecker~~), dimensions (aspectRatio), interactivity (clientNavigation), layout (~~allowJustification~~), shadow, spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** allowedBlocks, alt, backgroundType, contentPosition, customGradient, customOverlayColor, dimRatio, focalPoint, gradient, hasParallax, id, isDark, isRepeated, isUserOverlayColor, minHeight, minHeightUnit, overlayColor, tagName, templateLock, url, useFeaturedImage

## Details
Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ _Returns_

### getPermalinkParts

Returns the permalink for a post, split into it's three parts: the prefix, the postName, and the suffix.
Returns the permalink for a post, split into its three parts: the prefix, the postName, and the suffix.

_Parameters_

Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-rest-global-styles-controller-gutenberg.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* REST API: Try: bundle WP_Theme_JSON class instead of inheriting per WordPress version class
* REST API: Bundle WP_Theme_JSON class instead of inheriting per WordPress version class
*
* Changes to this class should be synced to the corresponding class
* in WordPress core: src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php.
Expand Down
11 changes: 11 additions & 0 deletions lib/class-wp-theme-json-data-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,15 @@ public function update_with( $new_data ) {
public function get_data() {
return $this->theme_json->get_raw_data();
}

/**
* Return theme JSON object.
*
* @since 18.3.0
*
* @return WP_Theme_JSON
*/
public function get_theme_json() {
return $this->theme_json;
}
}
17 changes: 7 additions & 10 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ public static function get_core_data() {
* @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data_Gutenberg( $config, 'default' ) );
$config = $theme_json->get_data();
static::$core = new WP_Theme_JSON_Gutenberg( $config, 'default' );
static::$core = $theme_json->get_theme_json();

return static::$core;
}
Expand Down Expand Up @@ -254,9 +253,8 @@ public static function get_theme_data( $deprecated = array(), $options = array()
*
* @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data_Gutenberg( $theme_json_data, 'theme' ) );
$theme_json_data = $theme_json->get_data();
static::$theme = new WP_Theme_JSON_Gutenberg( $theme_json_data );
$theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data_Gutenberg( $theme_json_data, 'theme' ) );
static::$theme = $theme_json->get_theme_json();

if ( $wp_theme->parent() ) {
// Get parent theme.json.
Expand Down Expand Up @@ -398,10 +396,9 @@ public static function get_block_data() {
*
* @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data_Gutenberg( $config, 'blocks' ) );
$config = $theme_json->get_data();
$theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data_Gutenberg( $config, 'blocks' ) );
static::$blocks = $theme_json->get_theme_json();

static::$blocks = new WP_Theme_JSON_Gutenberg( $config, 'blocks' );
return static::$blocks;
}

Expand Down Expand Up @@ -533,8 +530,8 @@ public static function get_user_data() {
* @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) );
$config = $theme_json->get_data();
return new WP_Theme_JSON_Gutenberg( $config, 'custom' );

return $theme_json->get_theme_json();
}

// Very important to verify that the flag isGlobalStylesUserThemeJSON is true.
Expand Down
8 changes: 8 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,14 @@ function gutenberg_register_vendor_scripts( $scripts ) {
array( 'react' ),
'18'
);

gutenberg_override_script(
$scripts,
'react-jsx-runtime',
gutenberg_url( 'build/vendors/react-jsx-runtime' . $extension ),
array( 'react' ),
'18'
);
}
add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' );

Expand Down
3 changes: 3 additions & 0 deletions lib/compat/wordpress-6.4/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* @since 6.0.0
* @access private
*
* @global WP_Styles $wp_styles
* @global WP_Scripts $wp_scripts
*
* @return array {
* The block editor assets.
*
Expand Down
48 changes: 48 additions & 0 deletions lib/compat/wordpress-6.6/admin-bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Changes to the WordPress admin bar.
*
* @package gutenberg
*/

/**
* Adds the "Site Editor" link to the Toolbar.
*
* @since 5.9.0
* @since 6.3.0 Added `$_wp_current_template_id` global for editing of current template directly from the admin bar.
* @since 6.6.0 Added the canvas argument to the url.
*
* @global string $_wp_current_template_id
*
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
*/
function gutenberg_admin_bar_edit_site_menu( $wp_admin_bar ) {
global $_wp_current_template_id;

// Don't show if a block theme is not activated.
if ( ! wp_is_block_theme() ) {
return;
}

// Don't show for users who can't edit theme options or when in the admin.
if ( ! current_user_can( 'edit_theme_options' ) || is_admin() ) {
return;
}

$wp_admin_bar->add_node(
array(
'id' => 'site-editor',
'title' => __( 'Site Editor' ),
'href' => add_query_arg(
array(
'postType' => 'wp_template',
'postId' => $_wp_current_template_id,
'canvas' => 'edit',
),
admin_url( 'site-editor.php' )
),
)
);
}
remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_site_menu', 40 );
add_action( 'admin_bar_menu', 'gutenberg_admin_bar_edit_site_menu', 41 );
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public function get_template_fallback( $request ) {
array_shift( $hierarchy );
} while ( ! empty( $hierarchy ) && empty( $fallback_template->content ) );

$response = $this->prepare_item_for_response( $fallback_template, $request );
// To maintain original behavior, return an empty object rather than a 404 error when no template is found.
$response = $fallback_template ? $this->prepare_item_for_response( $fallback_template, $request ) : new stdClass();

return rest_ensure_response( $response );
}
Expand Down
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.5/script-loader.php';

// WordPress 6.6 compat.
require __DIR__ . '/compat/wordpress-6.6/admin-bar.php';
require __DIR__ . '/compat/wordpress-6.6/compat.php';
require __DIR__ . '/compat/wordpress-6.6/resolve-patterns.php';
require __DIR__ . '/compat/wordpress-6.6/block-bindings/pattern-overrides.php';
Expand Down
7 changes: 7 additions & 0 deletions lib/theme-i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
}
]
},
"dimensions": {
"aspectRatios": [
{
"name": "Aspect ratio name"
}
]
},
"blocks": {
"*": {
"typography": {
Expand Down
Loading

0 comments on commit bd5b8f4

Please sign in to comment.