Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IIFE bundle for SSR instruction streaming runtime #25459

Closed
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
6 changes: 6 additions & 0 deletions packages/react-dom/instruction-streaming-runtime.js
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 4 additions & 1 deletion packages/react-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"index.js",
"client.js",
"profiling.js",
"instruction-streaming-runtime.js",
"server.js",
"server.browser.js",
"server.node.js",
Expand All @@ -39,7 +40,8 @@
"test-utils.js",
"unstable_testing.js",
"cjs/",
"umd/"
"umd/",
"iife/"
],
"exports": {
".": "./index.js",
Expand All @@ -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",
Expand Down
31 changes: 28 additions & 3 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -224,6 +228,11 @@ function getFormat(bundleType) {
return `cjs`;
case NODE_ESM:
return `es`;
case IIFE_DEV:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it's worth having a dev build of this. It doesn't have any warnings or anything. Let's just do prod only.

case IIFE_PROD:
case FB_IIFE_DEV:
case FB_IIFE_PROD:
return 'iife';
}
}

Expand All @@ -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:
Expand All @@ -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}`);
Expand All @@ -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:
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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]
);
}

Expand Down
27 changes: 27 additions & 0 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should probably prefix this with unstable- for now

name: 'instruction-streaming-runtime',
global: 'ReactDOMInstructionStreamingRuntime',
minifyWithProdErrorCodes: true,
wrapWithModuleBoundaries: false,
externals: [],
},

/******* React DOM Fizz Static *******/
{
bundleTypes: __EXPERIMENTAL__ ? [NODE_DEV, NODE_PROD] : [],
Expand Down Expand Up @@ -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:
Expand All @@ -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`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly here, I don't think we should bother with the .production.min.js stuff. We do that in our packages that are consumed by a bundler (like ES Modules or Common JS) but in this case there is no bundler, Fizz is going to inject this directly.

So let's just output the exact filename.

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:
Expand Down
9 changes: 9 additions & 0 deletions scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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:
Expand Down Expand Up @@ -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}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar here: let's remove the iife subdirectory and place it directly at the top level.

default:
throw new Error('Unknown bundle type.');
}
Expand Down
53 changes: 53 additions & 0 deletions scripts/rollup/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -294,6 +298,55 @@ ${license}
* ${'@gen' + 'erated'}
*/

${source}`;
},

[IIFE_DEV](source, globalName, filename, moduleType) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can skip this. Remember these files are going to get sent straight to the browser with no post-processing by a bundler or minifier. Don't want the extra bytes.

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}`;
},
};
Expand Down
2 changes: 2 additions & 0 deletions scripts/shared/inlinedHostConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down Expand Up @@ -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',
],
Expand Down