Skip to content

Commit 00f9acb

Browse files
authored
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
1 parent cf925eb commit 00f9acb

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -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';
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
"default": "./index.js"
2626
},
2727
"./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+
},
2932
"./jsx-dev-runtime": "./jsx-dev-runtime.js",
3033
"./src/*": "./src/*"
3134
},
+22
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,18 @@ const bundles = [
134134
externals: ['react', 'ReactNativeInternalFeatureFlags'],
135135
},
136136

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+
137149
/******* React JSX DEV Runtime *******/
138150
{
139151
bundleTypes: [
@@ -176,7 +188,7 @@ const bundles = [
176188
externals: ['react'],
177189
},
178190

179-
/******* React DOM Shared Subset *******/
191+
/******* React DOM React Server *******/
180192
{
181193
bundleTypes: [NODE_DEV, NODE_PROD],
182194
moduleType: RENDERER,

0 commit comments

Comments
 (0)