Make WordPress Core

Changeset 61487


Ignore:
Timestamp:
01/15/2026 12:55:21 PM (5 weeks ago)
Author:
youknowriad
Message:

Build/Test Tools: Restore React Refresh scripts for hot reloading.

Restores the wp_register_development_scripts() function and associated
build infrastructure to enable hot module replacement (HMR) when using
@wordpress/scripts with the --hot flag.

The React Refresh scripts were removed in [61438] as part of the Gutenberg
build restructuring, but they are still needed for plugin developers using
wp-scripts start --hot for block development.

Props jsnajdr, wildworks, manzoorwanijk.
See #64393.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/package-lock.json

    r61458 r61487  
    3939                "@lodder/grunt-postcss": "^3.1.1",
    4040                "@playwright/test": "1.56.1",
     41                "@pmmmwh/react-refresh-webpack-plugin": "0.6.1",
    4142                "@wordpress/e2e-test-utils-playwright": "1.33.2",
    4243                "@wordpress/prettier-config": "4.33.1",
     
    7172                "prettier": "npm:[email protected]",
    7273                "qunit": "~2.24.2",
     74                "react-refresh": "0.14.0",
    7375                "sass": "1.94.0",
    7476                "sinon": "16.1.3",
     
    40094011            }
    40104012        },
     4013        "node_modules/@pmmmwh/react-refresh-webpack-plugin": {
     4014            "version": "0.6.1",
     4015            "resolved": "https://registry.npmjs.org/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.6.1.tgz",
     4016            "integrity": "sha512-95DXXJxNkpYu+sqmpDp7vbw9JCyiNpHuCsvuMuOgVFrKQlwEIn9Y1+NNIQJq+zFL+eWyxw6htthB5CtdwJupNA==",
     4017            "dev": true,
     4018            "license": "MIT",
     4019            "dependencies": {
     4020                "anser": "^2.1.1",
     4021                "core-js-pure": "^3.23.3",
     4022                "error-stack-parser": "^2.0.6",
     4023                "html-entities": "^2.1.0",
     4024                "schema-utils": "^4.2.0",
     4025                "source-map": "^0.7.3"
     4026            },
     4027            "engines": {
     4028                "node": ">=18.12"
     4029            },
     4030            "peerDependencies": {
     4031                "@types/webpack": "5.x",
     4032                "react-refresh": ">=0.10.0 <1.0.0",
     4033                "sockjs-client": "^1.4.0",
     4034                "type-fest": ">=0.17.0 <5.0.0",
     4035                "webpack": "^5.0.0",
     4036                "webpack-dev-server": "^4.8.0 || 5.x",
     4037                "webpack-hot-middleware": "2.x",
     4038                "webpack-plugin-serve": "1.x"
     4039            },
     4040            "peerDependenciesMeta": {
     4041                "@types/webpack": {
     4042                    "optional": true
     4043                },
     4044                "sockjs-client": {
     4045                    "optional": true
     4046                },
     4047                "type-fest": {
     4048                    "optional": true
     4049                },
     4050                "webpack-dev-server": {
     4051                    "optional": true
     4052                },
     4053                "webpack-hot-middleware": {
     4054                    "optional": true
     4055                },
     4056                "webpack-plugin-serve": {
     4057                    "optional": true
     4058                }
     4059            }
     4060        },
     4061        "node_modules/@pmmmwh/react-refresh-webpack-plugin/node_modules/ajv": {
     4062            "version": "8.17.1",
     4063            "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz",
     4064            "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
     4065            "dev": true,
     4066            "license": "MIT",
     4067            "dependencies": {
     4068                "fast-deep-equal": "^3.1.3",
     4069                "fast-uri": "^3.0.1",
     4070                "json-schema-traverse": "^1.0.0",
     4071                "require-from-string": "^2.0.2"
     4072            },
     4073            "funding": {
     4074                "type": "github",
     4075                "url": "https://github.com/sponsors/epoberezkin"
     4076            }
     4077        },
     4078        "node_modules/@pmmmwh/react-refresh-webpack-plugin/node_modules/ajv-keywords": {
     4079            "version": "5.1.0",
     4080            "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-5.1.0.tgz",
     4081            "integrity": "sha512-YCS/JNFAUyr5vAuhk1DWm1CBxRHW9LbJ2ozWeemrIqpbsqKjHVxYPyi5GC0rjZIT5JxJ3virVTS8wk4i/Z+krw==",
     4082            "dev": true,
     4083            "license": "MIT",
     4084            "dependencies": {
     4085                "fast-deep-equal": "^3.1.3"
     4086            },
     4087            "peerDependencies": {
     4088                "ajv": "^8.8.2"
     4089            }
     4090        },
     4091        "node_modules/@pmmmwh/react-refresh-webpack-plugin/node_modules/json-schema-traverse": {
     4092            "version": "1.0.0",
     4093            "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
     4094            "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
     4095            "dev": true,
     4096            "license": "MIT"
     4097        },
     4098        "node_modules/@pmmmwh/react-refresh-webpack-plugin/node_modules/schema-utils": {
     4099            "version": "4.3.3",
     4100            "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-4.3.3.tgz",
     4101            "integrity": "sha512-eflK8wEtyOE6+hsaRVPxvUKYCpRgzLqDTb8krvAsRIwOGlHoSgYLgBXoubGgLd2fT41/OUYdb48v4k4WWHQurA==",
     4102            "dev": true,
     4103            "license": "MIT",
     4104            "dependencies": {
     4105                "@types/json-schema": "^7.0.9",
     4106                "ajv": "^8.9.0",
     4107                "ajv-formats": "^2.1.1",
     4108                "ajv-keywords": "^5.1.0"
     4109            },
     4110            "engines": {
     4111                "node": ">= 10.13.0"
     4112            },
     4113            "funding": {
     4114                "type": "opencollective",
     4115                "url": "https://opencollective.com/webpack"
     4116            }
     4117        },
     4118        "node_modules/@pmmmwh/react-refresh-webpack-plugin/node_modules/source-map": {
     4119            "version": "0.7.6",
     4120            "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.6.tgz",
     4121            "integrity": "sha512-i5uvt8C3ikiWeNZSVZNWcfZPItFQOsYTUAOkcUPGd8DqDy1uOUikjt5dG+uRlwyvR108Fb9DOd4GvXfT0N2/uQ==",
     4122            "dev": true,
     4123            "license": "BSD-3-Clause",
     4124            "engines": {
     4125                "node": ">= 12"
     4126            }
     4127        },
    40114128        "node_modules/@polka/url": {
    40124129            "version": "1.0.0-next.24",
     
    74507567            }
    74517568        },
     7569        "node_modules/anser": {
     7570            "version": "2.3.5",
     7571            "resolved": "https://registry.npmjs.org/anser/-/anser-2.3.5.tgz",
     7572            "integrity": "sha512-vcZjxvvVoxTeR5XBNJB38oTu/7eDCZlwdz32N1eNgpyPF7j/Z7Idf+CUwQOkKKpJ7RJyjxgLHCM7vdIK0iCNMQ==",
     7573            "dev": true,
     7574            "license": "MIT"
     7575        },
    74527576        "node_modules/ansi-colors": {
    74537577            "version": "4.1.3",
  • trunk/package.json

    r61458 r61487  
    2929    "devDependencies": {
    3030        "@lodder/grunt-postcss": "^3.1.1",
     31        "@pmmmwh/react-refresh-webpack-plugin": "0.6.1",
    3132        "@playwright/test": "1.56.1",
    3233        "@wordpress/e2e-test-utils-playwright": "1.33.2",
     
    6263        "prettier": "npm:[email protected]",
    6364        "qunit": "~2.24.2",
     65        "react-refresh": "0.14.0",
    6466        "sass": "1.94.0",
    6567        "sinon": "16.1.3",
  • trunk/src/wp-includes/deprecated.php

    r61472 r61487  
    64806480    <?php
    64816481}
    6482 
    6483 /**
    6484  * Registers development scripts that integrate with `@wordpress/scripts`.
    6485  *
    6486  * @see https://github.com/WordPress/gutenberg/tree/trunk/packages/scripts#start
    6487  *
    6488  * @since 6.0.0
    6489  * @deprecated 7.0.0 Obsolete due to a change in how Gutenberg is included in Core. See #64393.
    6490  *
    6491  * @param WP_Scripts $scripts WP_Scripts object.
    6492  */
    6493 function wp_register_development_scripts( $scripts ) {
    6494     _deprecated_function( __FUNCTION__, '7.0.0' );
    6495 }
  • trunk/src/wp-includes/script-loader.php

    r61485 r61487  
    164164        'after'
    165165    );
     166}
     167
     168/**
     169 * Registers development scripts that integrate with `@wordpress/scripts`.
     170 *
     171 * These scripts enable hot module replacement (HMR) for block development
     172 * when using `wp-scripts start --hot`.
     173 *
     174 * @see https://github.com/WordPress/gutenberg/tree/trunk/packages/scripts#start
     175 *
     176 * @since 6.0.0
     177 *
     178 * @param WP_Scripts $scripts WP_Scripts object.
     179 */
     180function wp_register_development_scripts( $scripts ) {
     181    if (
     182        ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG
     183        || empty( $scripts->registered['react'] )
     184        || defined( 'WP_RUN_CORE_TESTS' )
     185    ) {
     186        return;
     187    }
     188
     189    // React Refresh runtime - exposes ReactRefreshRuntime global.
     190    // No dependencies.
     191    $scripts->add(
     192        'wp-react-refresh-runtime',
     193        '/wp-includes/js/dist/development/react-refresh-runtime.js',
     194        array(),
     195        '0.14.0'
     196    );
     197
     198    // React Refresh entry - injects runtime into global hook.
     199    // Must load before React to set up hooks.
     200    $scripts->add(
     201        'wp-react-refresh-entry',
     202        '/wp-includes/js/dist/development/react-refresh-entry.js',
     203        array( 'wp-react-refresh-runtime' ),
     204        '0.14.0'
     205    );
     206
     207    // Add entry as a dependency of React so it loads first.
     208    // See https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#externalising-react.
     209    $scripts->registered['react']->deps[] = 'wp-react-refresh-entry';
    166210}
    167211
     
    619663function wp_default_packages( $scripts ) {
    620664    wp_default_packages_vendor( $scripts );
     665    wp_register_development_scripts( $scripts );
    621666    wp_register_tinymce_scripts( $scripts );
    622667    wp_default_packages_scripts( $scripts );
  • trunk/webpack.config.js

    r61438 r61487  
    11const mediaConfig = require( './tools/webpack/media' );
     2const developmentConfig = require( './tools/webpack/development' );
    23
    34module.exports = function (
     
    1213    }
    1314
    14     // Only building Core-specific media files.
     15    // Only building Core-specific media files and development scripts.
    1516    // Blocks, packages, script modules, and vendors are now sourced from
    1617    // the Gutenberg build (see tools/gutenberg/copy-gutenberg-build.js).
    17     const config = [ mediaConfig( env ) ];
     18    const config = [
     19        mediaConfig( env ),
     20        developmentConfig( env ),
     21    ];
    1822
    1923    return config;
Note: See TracChangeset for help on using the changeset viewer.