Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
],
"devDependencies": {
"@lodder/grunt-postcss": "^3.1.1",
"@pmmmwh/react-refresh-webpack-plugin": "0.6.1",
"@playwright/test": "1.56.1",
"@wordpress/e2e-test-utils-playwright": "1.33.2",
"@wordpress/prettier-config": "4.33.1",
Expand Down Expand Up @@ -61,6 +62,7 @@
"postcss": "8.5.6",
"prettier": "npm:wp-prettier@3.0.3",
"qunit": "~2.24.2",
"react-refresh": "0.14.0",
"sass": "1.94.0",
"sinon": "16.1.3",
"sinon-test": "~3.1.6",
Expand Down
14 changes: 0 additions & 14 deletions src/wp-includes/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -6479,17 +6479,3 @@ function wp_print_auto_sizes_contain_css_fix() {
<style>img:is([sizes="auto" i], [sizes^="auto," i]) { contain-intrinsic-size: 3000px 1500px }</style>
<?php
}

/**
* Registers development scripts that integrate with `@wordpress/scripts`.
*
* @see https://github.com/WordPress/gutenberg/tree/trunk/packages/scripts#start
*
* @since 6.0.0
* @deprecated 7.0.0 Obsolete due to a change in how Gutenberg is included in Core. See #64393.
*
* @param WP_Scripts $scripts WP_Scripts object.
*/
function wp_register_development_scripts( $scripts ) {
_deprecated_function( __FUNCTION__, '7.0.0' );
}
45 changes: 45 additions & 0 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,50 @@ function wp_default_packages_vendor( $scripts ) {
);
}

/**
* Registers development scripts that integrate with `@wordpress/scripts`.
*
* These scripts enable hot module replacement (HMR) for block development
* when using `wp-scripts start --hot`.
*
* @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 ) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we backport this to Gutenberg to avoid 404 errors as mentioned in WordPress/gutenberg#74618 (comment)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need, this is only missing in WordPress trunk, which will get updated once this commit lands.

Copy link
Member

@manzoorwanijk manzoorwanijk Jan 15, 2026

Choose a reason for hiding this comment

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

But we don't register those in Gutenberg to override the Core scripts. Which means that the ones in Gutenberg are never actually loaded. That is the reason I had to write Step 10 in the Testing Instructions in WordPress/gutenberg#74618 to load the scripts from Gutenberg to be able to test them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But we don't register those in Gutenberg to override the Core scripts. Which means that the ones in Gutenberg are never actually loaded. That is the reason I had to write Step 10 in the Testing Instructions in WordPress/gutenberg#74618 to load the scripts from Gutenberg to be able to test them.

I think we should remove the ones in Gutenberg entirely.

if (
! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG
|| empty( $scripts->registered['react'] )
|| defined( 'WP_RUN_CORE_TESTS' )
) {
return;
}

// React Refresh runtime - exposes ReactRefreshRuntime global.
// No dependencies.
$scripts->add(
'wp-react-refresh-runtime',
'/wp-includes/js/dist/development/react-refresh-runtime.js',
array(),
'0.14.0'
);

// React Refresh entry - injects runtime into global hook.
// Must load before React to set up hooks.
$scripts->add(
'wp-react-refresh-entry',
'/wp-includes/js/dist/development/react-refresh-entry.js',
array( 'wp-react-refresh-runtime' ),
'0.14.0'
);

// Add entry as a dependency of React so it loads first.
// See https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#externalising-react.
$scripts->registered['react']->deps[] = 'wp-react-refresh-entry';
}

/**
* Returns contents of an inline script used in appending polyfill scripts for
* browsers which fail the provided tests. The provided array is a mapping from
Expand Down Expand Up @@ -618,6 +662,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
72 changes: 72 additions & 0 deletions tools/webpack/development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* External dependencies
*/
const TerserPlugin = require( 'terser-webpack-plugin' );

/**
* Internal dependencies
*/
const { baseDir } = require( './shared' );

/**
* Webpack configuration for development scripts (React Refresh).
*
* These scripts enable hot module replacement for block development
* when using `@wordpress/scripts` with the `--hot` flag.
*
* @param {Object} env Environment options.
* @param {string} env.buildTarget Build target directory.
* @param {boolean} env.watch Whether to watch for changes.
* @return {Object} Webpack configuration object.
*/
module.exports = function( env = { buildTarget: 'src/', watch: false } ) {
const buildTarget = env.buildTarget || 'src/';

const entry = {
// React Refresh runtime - exposes ReactRefreshRuntime global.
[ buildTarget + 'wp-includes/js/dist/development/react-refresh-runtime.js' ]: {
import: 'react-refresh/runtime',
library: {
name: 'ReactRefreshRuntime',
type: 'window',
},
},
[ buildTarget + 'wp-includes/js/dist/development/react-refresh-runtime.min.js' ]: {
import: 'react-refresh/runtime',
library: {
name: 'ReactRefreshRuntime',
type: 'window',
},
},
// React Refresh entry - injects runtime into global hook before React loads.
[ buildTarget + 'wp-includes/js/dist/development/react-refresh-entry.js' ]:
'@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js',
[ buildTarget + 'wp-includes/js/dist/development/react-refresh-entry.min.js' ]:
'@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js',
Comment on lines +41 to +45
Copy link
Member

Choose a reason for hiding this comment

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

We already have these in Gutenberg, why not use them from there?

Copy link
Member

Choose a reason for hiding this comment

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

We have them only when we have the built files in build. But that's not always true. The webpack dev server serves files from memory, and needs to build the entire self-contained set of Gutenberg JS assets.

};

return {
target: 'browserslist',
// Must use development mode to preserve process.env.NODE_ENV checks
// in the source files. These scripts are only used during development.
mode: 'development',
devtool: false,
cache: true,
entry,
output: {
path: baseDir,
filename: '[name]',
},
optimization: {
minimize: true,
moduleIds: 'deterministic',
minimizer: [
new TerserPlugin( {
include: /\.min\.js$/,
extractComments: false,
} ),
],
},
watch: env.watch,
};
};
8 changes: 6 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const mediaConfig = require( './tools/webpack/media' );
const developmentConfig = require( './tools/webpack/development' );

module.exports = function (
env = { environment: 'production', watch: false, buildTarget: false }
Expand All @@ -11,10 +12,13 @@ module.exports = function (
env.buildTarget = env.mode === 'production' ? 'build/' : 'src/';
}

// Only building Core-specific media files.
// Only building Core-specific media files and development scripts.
// Blocks, packages, script modules, and vendors are now sourced from
// the Gutenberg build (see tools/gutenberg/copy-gutenberg-build.js).
const config = [ mediaConfig( env ) ];
const config = [
mediaConfig( env ),
developmentConfig( env ),
];

return config;
};
Loading