From 513a715c51cb8fcabbdf642a8db2b5ef289b4295 Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Mon, 10 Oct 2022 17:44:06 -0400 Subject: [PATCH] Add IIFE bundle for SSR instruction streaming runtime --- .../instruction-streaming-runtime.js | 6 +++ packages/react-dom/package.json | 5 +- scripts/rollup/build.js | 31 +++++++++-- scripts/rollup/bundles.js | 27 ++++++++++ scripts/rollup/packaging.js | 9 ++++ scripts/rollup/wrappers.js | 53 +++++++++++++++++++ scripts/shared/inlinedHostConfigs.js | 2 + 7 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 packages/react-dom/instruction-streaming-runtime.js diff --git a/packages/react-dom/instruction-streaming-runtime.js b/packages/react-dom/instruction-streaming-runtime.js new file mode 100644 index 0000000000000..66b24c757f771 --- /dev/null +++ b/packages/react-dom/instruction-streaming-runtime.js @@ -0,0 +1,6 @@ +// SSR instruction streaming runtime +// will be added by https://github.com/facebook/react/pull/25437 + +const message = 'SSR instruction streaming runtime'; +// eslint-disable-next-line react-internal/no-production-logging +console.assert(false, message); diff --git a/packages/react-dom/package.json b/packages/react-dom/package.json index c39432aa32046..c3dd48aebcf2b 100644 --- a/packages/react-dom/package.json +++ b/packages/react-dom/package.json @@ -29,6 +29,7 @@ "index.js", "client.js", "profiling.js", + "instruction-streaming-runtime.js", "server.js", "server.browser.js", "server.node.js", @@ -39,7 +40,8 @@ "test-utils.js", "unstable_testing.js", "cjs/", - "umd/" + "umd/", + "iife/" ], "exports": { ".": "./index.js", @@ -61,6 +63,7 @@ "./static.browser": "./static.browser.js", "./static.node": "./static.node.js", "./server-rendering-stub": "./server-rendering-stub.js", + "./instruction-streaming-runtime": "./instruction-streaming-runtime.js", "./profiling": "./profiling.js", "./test-utils": "./test-utils.js", "./unstable_testing": "./unstable_testing.js", diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 52c0b7dc9fe29..f96821ffb8e40 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -60,6 +60,10 @@ const { RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING, + IIFE_DEV, + IIFE_PROD, + FB_IIFE_DEV, + FB_IIFE_PROD, } = Bundles.bundleTypes; const {getFilename} = Bundles; @@ -224,6 +228,11 @@ function getFormat(bundleType) { return `cjs`; case NODE_ESM: return `es`; + case IIFE_DEV: + case IIFE_PROD: + case FB_IIFE_DEV: + case FB_IIFE_PROD: + return 'iife'; } } @@ -236,6 +245,8 @@ function isProductionBundleType(bundleType) { case FB_WWW_DEV: case RN_OSS_DEV: case RN_FB_DEV: + case IIFE_DEV: + case FB_IIFE_DEV: return false; case UMD_PROD: case NODE_PROD: @@ -247,6 +258,8 @@ function isProductionBundleType(bundleType) { case RN_OSS_PROFILING: case RN_FB_PROD: case RN_FB_PROFILING: + case IIFE_PROD: + case FB_IIFE_PROD: return true; default: throw new Error(`Unknown type: ${bundleType}`); @@ -267,6 +280,10 @@ function isProfilingBundleType(bundleType) { case RN_OSS_PROD: case UMD_DEV: case UMD_PROD: + case IIFE_DEV: + case IIFE_PROD: + case FB_IIFE_DEV: + case FB_IIFE_PROD: return false; case FB_WWW_PROFILING: case NODE_PROFILING: @@ -315,7 +332,9 @@ function getPlugins( const isFBWWWBundle = bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD || - bundleType === FB_WWW_PROFILING; + bundleType === FB_WWW_PROFILING || + bundleType === FB_IIFE_DEV || + bundleType === FB_IIFE_PROD; const isRNBundle = bundleType === RN_OSS_DEV || bundleType === RN_OSS_PROD || @@ -509,7 +528,9 @@ async function createBundle(bundle, bundleType) { const isFBWWWBundle = bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD || - bundleType === FB_WWW_PROFILING; + bundleType === FB_WWW_PROFILING || + bundleType === FB_IIFE_DEV || + bundleType === FB_IIFE_PROD; const isFBRNBundle = bundleType === RN_FB_DEV || @@ -724,7 +745,11 @@ async function buildEverything() { [bundle, RN_OSS_PROFILING], [bundle, RN_FB_DEV], [bundle, RN_FB_PROD], - [bundle, RN_FB_PROFILING] + [bundle, RN_FB_PROFILING], + [bundle, IIFE_DEV], + [bundle, IIFE_PROD], + [bundle, FB_IIFE_DEV], + [bundle, FB_IIFE_PROD] ); } diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index 1f7297a8f2174..b576555661e0f 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -25,6 +25,10 @@ const bundleTypes = { RN_FB_DEV: 'RN_FB_DEV', RN_FB_PROD: 'RN_FB_PROD', RN_FB_PROFILING: 'RN_FB_PROFILING', + IIFE_DEV: 'IIFE_DEV', + IIFE_PROD: 'IIFE_PROD', + FB_IIFE_DEV: 'FB_IIFE_DEV', + FB_IIFE_PROD: 'FB_IIFE_PROD', }; const { @@ -45,6 +49,10 @@ const { RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING, + IIFE_DEV, + IIFE_PROD, + FB_IIFE_DEV, + FB_IIFE_PROD, } = bundleTypes; const moduleTypes = { @@ -330,6 +338,19 @@ const bundles = [ externals: ['react', 'react-dom'], }, + { + bundleTypes: __EXPERIMENTAL__ + ? [IIFE_DEV, IIFE_PROD, FB_IIFE_DEV, FB_IIFE_PROD] + : [], + moduleType: RENDERER, + entry: 'react-dom/instruction-streaming-runtime', + name: 'instruction-streaming-runtime', + global: 'ReactDOMInstructionStreamingRuntime', + minifyWithProdErrorCodes: true, + wrapWithModuleBoundaries: false, + externals: [], + }, + /******* React DOM Fizz Static *******/ { bundleTypes: __EXPERIMENTAL__ ? [NODE_DEV, NODE_PROD] : [], @@ -1006,6 +1027,8 @@ function getOriginalFilename(bundle, bundleType) { return `${name}.js`; case NODE_ESM: return `${name}.js`; + case IIFE_DEV: + return `${name}.development.js`; case UMD_DEV: return `${name}.development.js`; case UMD_PROD: @@ -1018,13 +1041,17 @@ function getOriginalFilename(bundle, bundleType) { return `${name}.production.min.js`; case NODE_PROFILING: return `${name}.profiling.min.js`; + case IIFE_PROD: + return `${name}.production.min.js`; case FB_WWW_DEV: case RN_OSS_DEV: case RN_FB_DEV: + case FB_IIFE_DEV: return `${globalName}-dev.js`; case FB_WWW_PROD: case RN_OSS_PROD: case RN_FB_PROD: + case FB_IIFE_PROD: return `${globalName}-prod.js`; case FB_WWW_PROFILING: case RN_FB_PROFILING: diff --git a/scripts/rollup/packaging.js b/scripts/rollup/packaging.js index bd66d0b634730..36035661ded4a 100644 --- a/scripts/rollup/packaging.js +++ b/scripts/rollup/packaging.js @@ -33,6 +33,10 @@ const { RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING, + IIFE_DEV, + IIFE_PROD, + FB_IIFE_DEV, + FB_IIFE_PROD, } = Bundles.bundleTypes; function getPackageName(name) { @@ -59,6 +63,8 @@ function getBundleOutputPath(bundleType, filename, packageName) { case FB_WWW_DEV: case FB_WWW_PROD: case FB_WWW_PROFILING: + case FB_IIFE_DEV: + case FB_IIFE_PROD: return `build/facebook-www/${filename}`; case RN_OSS_DEV: case RN_OSS_PROD: @@ -88,6 +94,9 @@ function getBundleOutputPath(bundleType, filename, packageName) { default: throw new Error('Unknown RN package.'); } + case IIFE_DEV: + case IIFE_PROD: + return `build/node_modules/${packageName}/iife/${filename}`; default: throw new Error('Unknown bundle type.'); } diff --git a/scripts/rollup/wrappers.js b/scripts/rollup/wrappers.js index 44d83e4f58ee0..5435f83fca812 100644 --- a/scripts/rollup/wrappers.js +++ b/scripts/rollup/wrappers.js @@ -22,6 +22,10 @@ const { RN_FB_DEV, RN_FB_PROD, RN_FB_PROFILING, + IIFE_DEV, + IIFE_PROD, + FB_IIFE_DEV, + FB_IIFE_PROD, } = bundleTypes; const {RECONCILER} = moduleTypes; @@ -294,6 +298,55 @@ ${license} * ${'@gen' + 'erated'} */ +${source}`; + }, + + [IIFE_DEV](source, globalName, filename, moduleType) { + return `/** + * @license React + * ${filename} + * +${license} + */ +${source}`; + }, + [IIFE_PROD](source, globalName, filename, moduleType) { + return `/** + * @license React + * ${filename} + * +${license} + */ +${source}`; + }, + [FB_IIFE_DEV](source, globalName, filename, moduleType) { + return `/** +${license} + * + * @noflow + * @nolint + * @preventMunge + * @preserve-invariant-messages + */ + +'use strict'; + +if (__DEV__) { + (function() { +${source} + })(); +}`; + }, + [FB_IIFE_PROD](source, globalName, filename, moduleType) { + return `/** +${license} + * + * @noflow + * @nolint + * @preventMunge + * @preserve-invariant-messages + */ + ${source}`; }, }; diff --git a/scripts/shared/inlinedHostConfigs.js b/scripts/shared/inlinedHostConfigs.js index 1113bad1247d0..80aa56d562e99 100644 --- a/scripts/shared/inlinedHostConfigs.js +++ b/scripts/shared/inlinedHostConfigs.js @@ -15,6 +15,7 @@ module.exports = [ 'react-dom/src/server/ReactDOMFizzServerNode.js', 'react-dom/static.node', 'react-dom/server-rendering-stub', + 'react-dom/instruction-streaming-runtime', 'react-server-dom-webpack/writer.node.server', 'react-server-dom-webpack', ], @@ -51,6 +52,7 @@ module.exports = [ 'react-dom/src/server/ReactDOMFizzServerBrowser.js', 'react-dom/static.browser', 'react-dom/server-rendering-stub', + 'react-dom/instruction-streaming-runtime', 'react-server-dom-webpack/writer.browser.server', 'react-server-dom-webpack', ],