Skip to content

Commit

Permalink
Build: Enable React Fast Refresh for block development
Browse files Browse the repository at this point in the history
Brings the same functionality introduced in the Gutenberg plugin with WordPress/gutenberg#28273. In effect, it brings React Fast Refresh support to WordPress core for block development with `@wordpress/scripts`.

Props walbo, antonvlasenko.
See #51750, #55505.
Follow-up [53135].


Built from https://develop.svn.wordpress.org/trunk@53140


git-svn-id: http://core.svn.wordpress.org/trunk@52729 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
gziolo committed Apr 11, 2022
1 parent 8b207b7 commit 29254bd
Show file tree
Hide file tree
Showing 8 changed files with 1,403 additions and 1 deletion.
1 change: 1 addition & 0 deletions wp-includes/assets/script-loader-react-refresh-entry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('wp-react-refresh-runtime'), 'version' => '8151afc94a5ebc73b7a8229f0d7ee352');
1 change: 1 addition & 0 deletions wp-includes/assets/script-loader-react-refresh-runtime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array(), 'version' => '4fb86f241c3b2d9d9e0411b507079823');
612 changes: 612 additions & 0 deletions wp-includes/js/dist/development/react-refresh-entry.js

Large diffs are not rendered by default.

612 changes: 612 additions & 0 deletions wp-includes/js/dist/development/react-refresh-entry.min.js

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions wp-includes/js/dist/development/react-refresh-runtime.js

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions wp-includes/js/dist/development/react-refresh-runtime.min.js

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,45 @@ function wp_get_script_polyfill( $scripts, $tests ) {
return $polyfill;
}

/**
* Registers development scripts that integrate with `@wordpress/scripts`.
*
* @see https://github.com/WordPress/gutenberg/tree/trunk/packages/scripts#start
*
* @since 6.0.0
*
* @param WP_Scripts $scripts WP_Scripts object.
*/
function wp_register_development_scripts( $scripts ) {
if (
! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG
|| empty( $scripts->registered['react'] )
) {
return;
}

$development_scripts = array(
'react-refresh-entry',
'react-refresh-runtime',
);

foreach ( $development_scripts as $script_name ) {
$assets = include ABSPATH . WPINC . '/assets/script-loader-' . $script_name . '.php';
if ( ! is_array( $assets ) ) {
return;
}
$scripts->add(
'wp-' . $script_name,
'/wp-includes/js/dist/development/' . $script_name . '.js',
$assets['dependencies'],
$assets['version']
);
}

// See https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#externalising-react.
$scripts->registered['react']->deps[] = 'wp-react-refresh-entry';
}

/**
* Registers all the WordPress packages scripts that are in the standardized
* `js/dist/` location.
Expand Down Expand Up @@ -560,6 +599,7 @@ function wp_tinymce_inline_scripts() {
*/
function wp_default_packages( $scripts ) {
wp_default_packages_vendor( $scripts );
wp_register_development_scripts( $scripts );
wp_register_tinymce_scripts( $scripts );
wp_default_packages_scripts( $scripts );

Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-53139';
$wp_version = '6.0-alpha-53140';

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

0 comments on commit 29254bd

Please sign in to comment.