From baf30f0aefefae4b903cac17a190e4739ed0e171 Mon Sep 17 00:00:00 2001 From: Josh Story Date: Fri, 2 Feb 2024 10:48:17 -0800 Subject: [PATCH] Adds a new entrypoing 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 aleady separated so environments using it will be pulling in the right version --- packages/react/jsx-runtime.react-server.js | 9 ++++++++ .../react/npm/jsx-runtime.react-server.js | 7 ++++++ packages/react/package.json | 5 ++++- packages/react/src/jsx/ReactJSXServer.js | 22 +++++++++++++++++++ scripts/rollup/bundles.js | 14 +++++++++++- 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 packages/react/jsx-runtime.react-server.js create mode 100644 packages/react/npm/jsx-runtime.react-server.js create mode 100644 packages/react/src/jsx/ReactJSXServer.js diff --git a/packages/react/jsx-runtime.react-server.js b/packages/react/jsx-runtime.react-server.js new file mode 100644 index 0000000000000..fa48a68d3e0d9 --- /dev/null +++ b/packages/react/jsx-runtime.react-server.js @@ -0,0 +1,9 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ +export {Fragment, jsx, jsxs} from './src/jsx/ReactJSXServer'; diff --git a/packages/react/npm/jsx-runtime.react-server.js b/packages/react/npm/jsx-runtime.react-server.js new file mode 100644 index 0000000000000..cd80277331d46 --- /dev/null +++ b/packages/react/npm/jsx-runtime.react-server.js @@ -0,0 +1,7 @@ +'use strict'; + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/react-jsx-runtime.react-server.production.min.js'); +} else { + module.exports = require('./cjs/react-jsx-runtime.react-server.development.js'); +} diff --git a/packages/react/package.json b/packages/react/package.json index 39b545825875c..049e457704d4e 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -25,7 +25,10 @@ "default": "./index.js" }, "./package.json": "./package.json", - "./jsx-runtime": "./jsx-runtime.js", + "./jsx-runtime": { + "react-server": "./jsx-runtime.react-server.js", + "default": "./jsx-runtime.js" + }, "./jsx-dev-runtime": "./jsx-dev-runtime.js", "./src/*": "./src/*" }, diff --git a/packages/react/src/jsx/ReactJSXServer.js b/packages/react/src/jsx/ReactJSXServer.js new file mode 100644 index 0000000000000..2112cd80776a1 --- /dev/null +++ b/packages/react/src/jsx/ReactJSXServer.js @@ -0,0 +1,22 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +// These are implementations of the jsx APIs for React Server runtimes. +import {REACT_FRAGMENT_TYPE} from 'shared/ReactSymbols'; +import { + jsxWithValidationStatic, + jsxWithValidationDynamic, +} from './ReactJSXElementValidator'; +import {jsx as jsxProd} from './ReactJSXElement'; +const jsx: any = __DEV__ ? jsxWithValidationDynamic : jsxProd; +// we may want to special case jsxs internally to take advantage of static children. +// for now we can ship identical prod functions +const jsxs: any = __DEV__ ? jsxWithValidationStatic : jsxProd; + +export {REACT_FRAGMENT_TYPE as Fragment, jsx, jsxs}; diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index a4f3f08bbd522..683208d1fd584 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -134,6 +134,18 @@ const bundles = [ externals: ['react', 'ReactNativeInternalFeatureFlags'], }, + /******* React JSX Runtime React Server *******/ + { + bundleTypes: [NODE_DEV, NODE_PROD], + moduleType: ISOMORPHIC, + entry: 'react/src/jsx/ReactJSXServer.js', + name: 'react-jsx-runtime.react-server', + global: 'JSXRuntime', + minifyWithProdErrorCodes: false, + wrapWithModuleBoundaries: false, + externals: ['react', 'ReactNativeInternalFeatureFlags'], + }, + /******* React JSX DEV Runtime *******/ { bundleTypes: [ @@ -176,7 +188,7 @@ const bundles = [ externals: ['react'], }, - /******* React DOM Shared Subset *******/ + /******* React DOM React Server *******/ { bundleTypes: [NODE_DEV, NODE_PROD], moduleType: RENDERER,