Skip to content

Commit b427398

Browse files
jsnajdrMamadukaaduth
authored andcommitted
React vendor script: avoid warning on createRoot (#76825)
* React vendor script: avoid warning on createRoot * Fix broken build script Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: aduth <aduth@git.wordpress.org>
1 parent 345f967 commit b427398

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

bin/packages/build-vendors.mjs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const VENDOR_SCRIPTS = [
2222
global: 'ReactDOM',
2323
handle: 'react-dom',
2424
dependencies: [ 'react' ],
25+
contents: [
26+
'export * from "react-dom";',
27+
'export { createRoot, hydrateRoot } from "react-dom/client";',
28+
].join( '\n' ),
2529
},
2630
{
2731
name: 'react/jsx-runtime',
@@ -87,7 +91,7 @@ async function generateAssetFile( config ) {
8791
* @return {Promise<void>} Promise that resolves when all builds are finished.
8892
*/
8993
async function bundleVendorScript( config ) {
90-
const { name, global, handle } = config;
94+
const { name, global, handle, contents } = config;
9195

9296
// Plugin that externalizes the `react` package.
9397
const reactExternalPlugin = {
@@ -114,7 +118,6 @@ async function bundleVendorScript( config ) {
114118
};
115119

116120
const esbuildOptions = {
117-
entryPoints: [ name ],
118121
bundle: true,
119122
format: 'iife',
120123
globalName: global,
@@ -123,6 +126,16 @@ async function bundleVendorScript( config ) {
123126
plugins: [ reactExternalPlugin ],
124127
};
125128

129+
if ( contents ) {
130+
esbuildOptions.stdin = {
131+
contents,
132+
resolveDir: ROOT_DIR,
133+
loader: 'js',
134+
};
135+
} else {
136+
esbuildOptions.entryPoints = [ name ];
137+
}
138+
126139
await Promise.all( [
127140
esbuild.build( {
128141
...esbuildOptions,
@@ -150,11 +163,11 @@ async function buildVendors() {
150163
await bundleVendorScript( vendorConfig );
151164
const buildTime = Date.now() - startTime;
152165
console.log(
153-
` ✔ Bundled vendor ${ vendorConfig.name } (${ buildTime }ms)`
166+
` ✔ Bundled vendor ${ vendorConfig.handle } (${ buildTime }ms)`
154167
);
155168
} catch ( error ) {
156169
console.error(
157-
` ✘ Failed to bundle vendor ${ vendorConfig.name }: ${ error.message }`
170+
` ✘ Failed to bundle vendor ${ vendorConfig.handle }: ${ error.message }`
158171
);
159172
}
160173
}

0 commit comments

Comments
 (0)