diff --git a/bin/packages/build-vendors.mjs b/bin/packages/build-vendors.mjs index 1eae1af1dc9e7b..110002d9d16f05 100755 --- a/bin/packages/build-vendors.mjs +++ b/bin/packages/build-vendors.mjs @@ -145,16 +145,15 @@ async function bundleReactJsxRuntime() { async function bundleReactRefresh() { console.log( '📦 Bundling React Refresh...' ); - // Bundle react-refresh-entry + // Bundle react-refresh-entry using react-refresh const entryDir = path.join( BUILD_DIR, 'react-refresh-entry' ); await mkdir( entryDir, { recursive: true } ); + // The entry file uses ReactRefreshRuntime global, so no bundling needed await esbuild.build( { - entryPoints: [ - '@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js', - ], + entryPoints: [ path.join( __dirname, 'react-refresh-entry.js' ) ], outfile: path.join( entryDir, 'index.min.js' ), - bundle: true, + bundle: false, format: 'iife', target: 'es2015', platform: 'browser', diff --git a/bin/packages/react-refresh-entry.js b/bin/packages/react-refresh-entry.js new file mode 100644 index 00000000000000..7edf48958d6adb --- /dev/null +++ b/bin/packages/react-refresh-entry.js @@ -0,0 +1,16 @@ +/** + * React Refresh Entry + * + * Injects the React Refresh runtime into the global hook for hot module replacement. + * This file uses the ReactRefreshRuntime global provided by wp-react-refresh-runtime. + */ + +/* global ReactRefreshRuntime */ + +if ( + typeof ReactRefreshRuntime !== 'undefined' && + ! globalThis.__reactRefreshInjected +) { + ReactRefreshRuntime.injectIntoGlobalHook( globalThis ); + globalThis.__reactRefreshInjected = true; +} diff --git a/bin/tsconfig.json b/bin/tsconfig.json index 8895ff2b238771..73c4364470f98c 100644 --- a/bin/tsconfig.json +++ b/bin/tsconfig.json @@ -41,6 +41,7 @@ "log-performance-results.js", "packages/build-vendors.mjs", "packages/build.mjs", + "packages/react-refresh-entry.js", "packages/check-build-type-declaration-files.js", "plugin/cli.js", "plugin/commands/common.js", diff --git a/package-lock.json b/package-lock.json index 576a1199a4513d..8ca3d92f45b1a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,6 @@ "@inquirer/prompts": "7.2.0", "@octokit/rest": "16.26.0", "@playwright/test": "1.57.0", - "@pmmmwh/react-refresh-webpack-plugin": "0.5.11", "@storybook/addon-a11y": "10.1.11", "@storybook/addon-docs": "10.1.11", "@storybook/icons": "2.0.1", diff --git a/package.json b/package.json index 66b0188225df13..dc6358231ac846 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "@inquirer/prompts": "7.2.0", "@octokit/rest": "16.26.0", "@playwright/test": "1.57.0", - "@pmmmwh/react-refresh-webpack-plugin": "0.5.11", "@storybook/addon-a11y": "10.1.11", "@storybook/addon-docs": "10.1.11", "@storybook/icons": "2.0.1",