Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/packages/react-compiler-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"react-server": "./dist/index.react-server.js",
"default": "./dist/index.js"
}
},
"files": [
"dist",
"src"
Expand Down
7 changes: 5 additions & 2 deletions compiler/packages/react-compiler-runtime/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ const argv = yargs(process.argv.slice(2))
.parse();

const config = {
entryPoints: [path.join(__dirname, '../src/index.ts')],
outfile: path.join(__dirname, '../dist/index.js'),
entryPoints: [
path.join(__dirname, '../src/index.ts'),
path.join(__dirname, '../src/index.react-server.ts'),
],
outdir: path.join(__dirname, '../dist'),
bundle: true,
external: ['react'],
format: 'cjs',
Expand Down
12 changes: 12 additions & 0 deletions compiler/packages/react-compiler-runtime/src/index.react-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* 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.
*/

throw new Error(
'The React Compiler is currently not supported in a React Server environment. ' +
'Ensure that modules imported with a `react-server` condition are not compiled with the React Compiler. ' +
"Libraries should provide a dedicated `react-server` entrypoint that wasn't compiled with the React Compiler.",
);
10 changes: 10 additions & 0 deletions packages/react/compiler-runtime.react-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* 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 * from './src/ReactCompilerRuntimeServer';
14 changes: 14 additions & 0 deletions packages/react/npm/compiler-runtime.react-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* 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.
*/

'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-compiler-runtime.react-server.production.js');
} else {
module.exports = require('./cjs/react-compiler-runtime.react-server.development.js');
}
3 changes: 2 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"index.js",
"cjs/",
"compiler-runtime.js",
"compiler-runtime.react-server.js",
"jsx-runtime.js",
"jsx-runtime.react-server.js",
"jsx-dev-runtime.js",
Expand All @@ -36,7 +37,7 @@
"default": "./jsx-dev-runtime.js"
},
"./compiler-runtime": {
"react-server": "./compiler-runtime.js",
"react-server": "./compiler-runtime.react-server.js",
"default": "./compiler-runtime.js"
},
"./src/*": "./src/*"
Expand Down
14 changes: 14 additions & 0 deletions packages/react/src/ReactCompilerRuntimeServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* 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
*/

throw new Error(
'The React Compiler is currently not supported in a React Server environment. ' +
'Ensure that modules imported with a `react-server` condition are not compiled with the React Compiler. ' +
"Libraries should provide a dedicated `react-server` entrypoint that wasn't compiled with the React Compiler.",
);
3 changes: 2 additions & 1 deletion scripts/error-codes/codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -529,5 +529,6 @@
"541": "Compared context values must be arrays",
"542": "Suspense Exception: This is not a real error! It's an implementation detail of `useActionState` to interrupt the current render. You must either rethrow it immediately, or move the `useActionState` call outside of the `try/catch` block. Capturing without rethrowing will lead to unexpected behavior.\n\nTo handle async errors, wrap your component in an error boundary.",
"543": "Expected a ResourceEffectUpdate to be pushed together with ResourceEffectIdentity. This is a bug in React.",
"544": "Found a pair with an auto name. This is a bug in React."
"544": "Found a pair with an auto name. This is a bug in React.",
"545": "The React Compiler is currently not supported in a React Server environment. Ensure that modules imported with a `react-server` condition are not compiled with the React Compiler. Libraries should provide a dedicated `react-server` entrypoint that wasn't compiled with the React Compiler."
}
13 changes: 13 additions & 0 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ const bundles = [
externals: ['react'],
},

/******* Compiler Runtime React Server *******/
{
bundleTypes: [NODE_DEV, NODE_PROD],
moduleType: ISOMORPHIC,
entry: 'react/src/ReactCompilerRuntimeServer.js',
name: 'react-compiler-runtime.react-server',
condition: 'react-server',
global: 'CompilerRuntime',
minifyWithProdErrorCodes: true,
wrapWithModuleBoundaries: false,
externals: ['react'],
},

/******* React JSX Runtime React Server *******/
{
bundleTypes: [NODE_DEV, NODE_PROD],
Expand Down
Loading