add RSC entrypoint for jsx-runtime (#28217)
Adds a new entrypoint for the production jsx-runtime when using react-server condition. Currently the entrypoints are the same but in the future we will potentially change the implementation of the runtime in ways that can only be optimized for react-server constraints and we want to have the entrypoint already separated so environments using it will be pulling in the right version
Josh Story committed
Feb 2, 2024 at 13:37 UTC
00f9acb12c036ef24a2b6d7957d75359c6280087
5 files changed
+55
-2
packages/react/jsx-runtime.react-server.js
new
+9
@@ -0,0 +1,9 @@
1
+/**
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+ * @flow
8
+ */
9
+export {Fragment, jsx, jsxs} from './src/jsx/ReactJSXServer';
packages/react/npm/jsx-runtime.react-server.js
new
+7
@@ -0,0 +1,7 @@
1
+'use strict';
2
+
3
+if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./cjs/react-jsx-runtime.react-server.production.min.js');
5
+} else {
6
+ module.exports = require('./cjs/react-jsx-runtime.react-server.development.js');
7
+}
packages/react/package.json
+4
-1
@@ -25,7 +25,10 @@
25
"default": "./index.js"
26
},
27
"./package.json": "./package.json",
28
- "./jsx-runtime": "./jsx-runtime.js",
28
+ "./jsx-runtime": {
29
+ "react-server": "./jsx-runtime.react-server.js",
30
+ "default": "./jsx-runtime.js"
31
+ },
32
"./jsx-dev-runtime": "./jsx-dev-runtime.js",
33
"./src/*": "./src/*"
34
},
packages/react/src/jsx/ReactJSXServer.js
new
+22
@@ -0,0 +1,22 @@
1
+/**
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+ * @flow
8
+ */
9
+
10
+// These are implementations of the jsx APIs for React Server runtimes.
11
+import {REACT_FRAGMENT_TYPE} from 'shared/ReactSymbols';
12
+import {
13
+ jsxWithValidationStatic,
14
+ jsxWithValidationDynamic,
15
+} from './ReactJSXElementValidator';
16
+import {jsx as jsxProd} from './ReactJSXElement';
17
+const jsx: any = __DEV__ ? jsxWithValidationDynamic : jsxProd;
18
+// we may want to special case jsxs internally to take advantage of static children.
19
+// for now we can ship identical prod functions
20
+const jsxs: any = __DEV__ ? jsxWithValidationStatic : jsxProd;
21
+
22
+export {REACT_FRAGMENT_TYPE as Fragment, jsx, jsxs};
scripts/rollup/bundles.js
+13
-1
@@ -134,6 +134,18 @@ const bundles = [
134
externals: ['react', 'ReactNativeInternalFeatureFlags'],
135
},
136
137
+ /******* React JSX Runtime React Server *******/
138
+ {
139
+ bundleTypes: [NODE_DEV, NODE_PROD],
140
+ moduleType: ISOMORPHIC,
141
+ entry: 'react/src/jsx/ReactJSXServer.js',
142
+ name: 'react-jsx-runtime.react-server',
143
+ global: 'JSXRuntime',
144
+ minifyWithProdErrorCodes: false,
145
+ wrapWithModuleBoundaries: false,
146
+ externals: ['react', 'ReactNativeInternalFeatureFlags'],
147
+ },
148
+
149
/******* React JSX DEV Runtime *******/
150
{
151
bundleTypes: [
@@ -176,7 +188,7 @@ const bundles = [
188
externals: ['react'],
189
},
190
179
- /******* React DOM Shared Subset *******/
191
+ /******* React DOM React Server *******/
192
{
193
bundleTypes: [NODE_DEV, NODE_PROD],
194
moduleType: RENDERER,