Skip to content

Commit

Permalink
add jsx-runtime and jsx-dev-runtime (facebook#18299)
Browse files Browse the repository at this point in the history
This PR adds the jsx-runtime and jsx-dev-runtime modules for the JSX Babel Plugin. WWW still relies on jsx/jsxs/jsxDEV from the "react" module, so once we refactor the code to point to the runtime modules we will remove jsx/jsxs/jsxDEV from the "react" module.
  • Loading branch information
lunaruan authored and rajitkhanna committed Oct 21, 2024
1 parent 2666642 commit 5c97c74
Show file tree
Hide file tree
Showing 18 changed files with 927 additions and 88 deletions.
5 changes: 1 addition & 4 deletions packages/react/index.classic.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,5 @@ export {
DEPRECATED_createResponder,
// enableScopeAPI
unstable_createScope,
// enableJSXTransformAPI
jsx,
jsxs,
jsxDEV,
} from './src/React';
export {jsx, jsxs, jsxDEV} from './src/jsx/ReactJSX';
4 changes: 0 additions & 4 deletions packages/react/index.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,4 @@ export {
unstable_withSuspenseConfig,
// enableBlocksAPI
block,
// enableJSXTransformAPI
jsx,
jsxs,
jsxDEV,
} from './src/React';
3 changes: 0 additions & 3 deletions packages/react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,4 @@ export {
DEPRECATED_createResponder,
unstable_createFundamental,
unstable_createScope,
jsx,
jsxs,
jsxDEV,
} from './src/React';
5 changes: 1 addition & 4 deletions packages/react/index.modern.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,5 @@ export {
DEPRECATED_createResponder,
// enableScopeAPI
unstable_createScope,
// enableJSXTransformAPI
jsx,
jsxs,
jsxDEV,
} from './src/React';
export {jsx, jsxs, jsxDEV} from './src/jsx/ReactJSX';
10 changes: 10 additions & 0 deletions packages/react/jsx-dev-runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its 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, jsxDEV} from './src/jsx/ReactJSX';
9 changes: 9 additions & 0 deletions packages/react/jsx-runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Copyright (c) Facebook, Inc. and its 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/ReactJSX';
7 changes: 7 additions & 0 deletions packages/react/npm/jsx-dev-runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-jsx-dev-runtime.production.min.js');
} else {
module.exports = require('./cjs/react-jsx-dev-runtime.development.js');
}
7 changes: 7 additions & 0 deletions packages/react/npm/jsx-runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-jsx-runtime.production.min.js');
} else {
module.exports = require('./cjs/react-jsx-runtime.development.js');
}
4 changes: 3 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"build-info.json",
"index.js",
"cjs/",
"umd/"
"umd/",
"jsx-runtime.js",
"jsx-dev-runtime.js"
],
"main": "index.js",
"repository": {
Expand Down
15 changes: 0 additions & 15 deletions packages/react/src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
createFactory as createFactoryProd,
cloneElement as cloneElementProd,
isValidElement,
jsx as jsxProd,
} from './ReactElement';
import {createContext} from './ReactContext';
import {lazy} from './ReactLazy';
Expand Down Expand Up @@ -52,9 +51,6 @@ import {
createElementWithValidation,
createFactoryWithValidation,
cloneElementWithValidation,
jsxWithValidation,
jsxWithValidationStatic,
jsxWithValidationDynamic,
} from './ReactElementValidator';
import createMutableSource from './createMutableSource';
import ReactSharedInternals from './ReactSharedInternals';
Expand All @@ -67,12 +63,6 @@ const createElement = __DEV__ ? createElementWithValidation : createElementProd;
const cloneElement = __DEV__ ? cloneElementWithValidation : cloneElementProd;
const createFactory = __DEV__ ? createFactoryWithValidation : createFactoryProd;

const jsxDEV = __DEV__ ? jsxWithValidation : undefined;
const jsx = __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 = __DEV__ ? jsxWithValidationStatic : jsxProd;

const Children = {
map,
forEach,
Expand Down Expand Up @@ -127,9 +117,4 @@ export {
createFundamental as unstable_createFundamental,
// enableScopeAPI
createScope as unstable_createScope,
// enableJSXTransformAPI
jsx,
jsxs,
// TODO: jsxDEV should not be exposed as a name. We might want to move it to a different entry point.
jsxDEV,
};
7 changes: 7 additions & 0 deletions packages/react/src/ReactDebugCurrentFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export function setCurrentlyValidatingElement(element: null | ReactElement) {
}

if (__DEV__) {
ReactDebugCurrentFrame.setCurrentlyValidatingElement = function(
element: null | ReactElement,
) {
if (__DEV__) {
currentlyValidatingElement = element;
}
};
// Stack implementation injected by the current renderer.
ReactDebugCurrentFrame.getCurrentStack = (null: null | (() => string));

Expand Down
Loading

0 comments on commit 5c97c74

Please sign in to comment.