Skip to content

Commit 8bcc97d

Browse files
acdlitemofeiZ
andcommitted
Scaffolding for react-dom/unstable_external-server-runtime
Implements a new bundle type for in our build config called BROWSER_SCRIPT. This is intended for scripts that get delivered straight to the browser without needing to be processed by a bundler. (And also doesn't include any extra UMD crap.) Right now there's only a single use case so I didn't stress about making it general purpose. The use case is: a script that loads the Fizz browser runtime, and sets up a MutationObserver to receive instructions as HTML streams in. This will be an alternative option to the default Fizz behavior of sending the runtime down as inline script tags, to accommodate environments where inline script tags are not allowed. There's no development version of this bundle because it doesn't contain any warnings or run any user code. None of the actual implementation is in this PR; it just sets up the build infra. Co-authored-by: Mofei Zhang <[email protected]>
1 parent f07ff8b commit 8bcc97d

File tree

8 files changed

+74
-18
lines changed

8 files changed

+74
-18
lines changed

packages/react-dom/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"server-rendering-stub.js",
3939
"test-utils.js",
4040
"unstable_testing.js",
41+
"unstable_server-external-runtime.js",
4142
"cjs/",
4243
"umd/"
4344
],
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// TODO: Add Flow types
2+
import {
3+
clientRenderBoundary,
4+
completeBoundaryWithStyles,
5+
completeBoundary,
6+
completeSegment,
7+
} from 'react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSet';
8+
9+
// Intentionally does nothing. Implementation will be added in future PR.
10+
// eslint-disable-next-line no-unused-vars
11+
const observer = new MutationObserver(mutations => {
12+
// These are only called so I can check what the module output looks like. The
13+
// code is unreachable.
14+
clientRenderBoundary();
15+
completeBoundaryWithStyles();
16+
completeBoundary();
17+
completeSegment();
18+
});

packages/shared/ReactVersion.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1 @@
1-
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
3-
*
4-
* This source code is licensed under the MIT license found in the
5-
* LICENSE file in the root directory of this source tree.
6-
*/
7-
8-
// TODO: this is special because it gets imported during build.
9-
//
10-
// TODO: 18.0.0 has not been released to NPM;
11-
// It exists as a placeholder so that DevTools can support work tag changes between releases.
12-
// When we next publish a release, update the matching TODO in backend/renderer.js
13-
// TODO: This module is used both by the release scripts and to expose a version
14-
// at runtime. We should instead inject the version number as part of the build
15-
// process, and use the ReactVersions.js module as the single source of truth.
16-
export default '18.2.0';
1+
export default '18.3.0-next-d14ffea1d0-20221014';

scripts/rollup/build.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const {
6060
RN_FB_DEV,
6161
RN_FB_PROD,
6262
RN_FB_PROFILING,
63+
BROWSER_SCRIPT,
6364
} = Bundles.bundleTypes;
6465

6566
const {getFilename} = Bundles;
@@ -224,6 +225,8 @@ function getFormat(bundleType) {
224225
return `cjs`;
225226
case NODE_ESM:
226227
return `es`;
228+
case BROWSER_SCRIPT:
229+
return `iife`;
227230
}
228231
}
229232

@@ -247,6 +250,7 @@ function isProductionBundleType(bundleType) {
247250
case RN_OSS_PROFILING:
248251
case RN_FB_PROD:
249252
case RN_FB_PROFILING:
253+
case BROWSER_SCRIPT:
250254
return true;
251255
default:
252256
throw new Error(`Unknown type: ${bundleType}`);
@@ -267,6 +271,7 @@ function isProfilingBundleType(bundleType) {
267271
case RN_OSS_PROD:
268272
case UMD_DEV:
269273
case UMD_PROD:
274+
case BROWSER_SCRIPT:
270275
return false;
271276
case FB_WWW_PROFILING:
272277
case NODE_PROFILING:
@@ -582,6 +587,7 @@ async function createBundle(bundle, bundleType) {
582587
},
583588
};
584589
const mainOutputPath = Packaging.getBundleOutputPath(
590+
bundle,
585591
bundleType,
586592
filename,
587593
packageName
@@ -724,7 +730,8 @@ async function buildEverything() {
724730
[bundle, RN_OSS_PROFILING],
725731
[bundle, RN_FB_DEV],
726732
[bundle, RN_FB_PROD],
727-
[bundle, RN_FB_PROFILING]
733+
[bundle, RN_FB_PROFILING],
734+
[bundle, BROWSER_SCRIPT]
728735
);
729736
}
730737

scripts/rollup/bundles.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const bundleTypes = {
2525
RN_FB_DEV: 'RN_FB_DEV',
2626
RN_FB_PROD: 'RN_FB_PROD',
2727
RN_FB_PROFILING: 'RN_FB_PROFILING',
28+
BROWSER_SCRIPT: 'BROWSER_SCRIPT',
2829
};
2930

3031
const {
@@ -45,6 +46,7 @@ const {
4546
RN_FB_DEV,
4647
RN_FB_PROD,
4748
RN_FB_PROFILING,
49+
BROWSER_SCRIPT,
4850
} = bundleTypes;
4951

5052
const moduleTypes = {
@@ -351,6 +353,18 @@ const bundles = [
351353
externals: ['react', 'util', 'stream', 'react-dom'],
352354
},
353355

356+
/******* React DOM Fizz Server External Runtime *******/
357+
{
358+
bundleTypes: [BROWSER_SCRIPT],
359+
moduleType: RENDERER,
360+
entry: 'react-dom/src/server/ReactDOMServerExternalRuntime.js',
361+
outputPath: 'unstable_server-external-runtime.js',
362+
global: 'ReactDOMServerExternalRuntime',
363+
minifyWithProdErrorCodes: false,
364+
wrapWithModuleBoundaries: false,
365+
externals: [],
366+
},
367+
354368
/******* React DOM Server Render Stub *******/
355369
{
356370
bundleTypes: [NODE_DEV, NODE_PROD, UMD_DEV, UMD_PROD],
@@ -1030,6 +1044,8 @@ function getOriginalFilename(bundle, bundleType) {
10301044
case RN_FB_PROFILING:
10311045
case RN_OSS_PROFILING:
10321046
return `${globalName}-profiling.js`;
1047+
case BROWSER_SCRIPT:
1048+
return `${name}.js`;
10331049
}
10341050
}
10351051

scripts/rollup/packaging.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const {
3333
RN_FB_DEV,
3434
RN_FB_PROD,
3535
RN_FB_PROFILING,
36+
BROWSER_SCRIPT,
3637
} = Bundles.bundleTypes;
3738

3839
function getPackageName(name) {
@@ -42,7 +43,7 @@ function getPackageName(name) {
4243
return name;
4344
}
4445

45-
function getBundleOutputPath(bundleType, filename, packageName) {
46+
function getBundleOutputPath(bundle, bundleType, filename, packageName) {
4647
switch (bundleType) {
4748
case NODE_ES2015:
4849
return `build/node_modules/${packageName}/cjs/${filename}`;
@@ -88,6 +89,24 @@ function getBundleOutputPath(bundleType, filename, packageName) {
8889
default:
8990
throw new Error('Unknown RN package.');
9091
}
92+
case BROWSER_SCRIPT: {
93+
// Bundles that are served as browser scripts need to be able to be sent
94+
// straight to the browser with any additional bundling. We shouldn't use
95+
// a module to re-export. Depending on how they are served, they also may
96+
// not go through package.json module resolution, so we shouldn't rely on
97+
// that either. We should consider the output path as part of the public
98+
// contract, and explicitly specify its location within the package's
99+
// directory structure.
100+
const outputPath = bundle.outputPath;
101+
if (!outputPath) {
102+
throw new Error(
103+
'Bundles with type BROWSER_SCRIPT must specific an explicit ' +
104+
'output path.'
105+
);
106+
}
107+
console.log(packageName);
108+
return `build/node_modules/${packageName}/${outputPath}`;
109+
}
91110
default:
92111
throw new Error('Unknown bundle type.');
93112
}

scripts/rollup/wrappers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const {
2222
RN_FB_DEV,
2323
RN_FB_PROD,
2424
RN_FB_PROFILING,
25+
BROWSER_SCRIPT,
2526
} = bundleTypes;
2627

2728
const {RECONCILER} = moduleTypes;
@@ -384,6 +385,12 @@ function wrapBundle(
384385
}
385386
}
386387

388+
if (bundleType === BROWSER_SCRIPT) {
389+
// Bundles of type BROWSER_SCRIPT get sent straight to the browser without
390+
// additional processing. So we should exclude any extra wrapper comments.
391+
return source;
392+
}
393+
387394
if (moduleType === RECONCILER) {
388395
// Standalone reconciler is only used by third-party renderers.
389396
// It is handled separately.
@@ -395,6 +402,7 @@ function wrapBundle(
395402
}
396403
return wrapper(source, globalName, filename, moduleType);
397404
}
405+
398406
// All the other packages.
399407
const wrapper = wrappers[bundleType];
400408
if (typeof wrapper !== 'function') {

scripts/shared/inlinedHostConfigs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = [
1515
'react-dom/src/server/ReactDOMFizzServerNode.js',
1616
'react-dom/static.node',
1717
'react-dom/server-rendering-stub',
18+
'react-dom/src/server/ReactDOMServerExternalRuntime.js',
1819
'react-server-dom-webpack/writer.node.server',
1920
'react-server-dom-webpack',
2021
],
@@ -51,6 +52,7 @@ module.exports = [
5152
'react-dom/src/server/ReactDOMFizzServerBrowser.js',
5253
'react-dom/static.browser',
5354
'react-dom/server-rendering-stub',
55+
'react-dom/src/server/ReactDOMServerExternalRuntime.js',
5456
'react-server-dom-webpack/writer.browser.server',
5557
'react-server-dom-webpack',
5658
],

0 commit comments

Comments
 (0)