Skip to content

Fix react-compiler entrypoint for react-server #29057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
2 changes: 1 addition & 1 deletion packages/react/compiler-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* @flow
*/

export {useMemoCache as c} from './src/ReactHooks';
export * from './src/ReactCompilerRuntimeClient';
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
10 changes: 10 additions & 0 deletions packages/react/src/ReactCompilerRuntimeClient.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 {useMemoCache as c} from './ReactHooks';
10 changes: 10 additions & 0 deletions packages/react/src/ReactCompilerRuntimeServer.js
Copy link
Contributor Author

@lubieowoce lubieowoce May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, this could be a stub file like

throw new Error("The React compiler does not support Server Components.");

because AFAIK RSC's are not currently intended to be processed by the compiler at all

But also, the Flight dispatcher does have a stub useMemoCache implementation, so i'm not sure what's the preferred behavior here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But also, the Flight dispatcher does have a stub useMemoCache implementation

We should remove it.

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 {useMemoCache as c} from './ReactHooks';
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, NODE_PROFILING],
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