Skip to content

Commit 556a087

Browse files
authored
[DOM] disallow client entrypoints with react-server condition (#28784)
`react-server` precludes loading code that expects to be run in a client context. This includes react-dom/client react-dom/server react-dom/unstable_testing react-dom/profiling and react-dom/static This update makes importing any of these client only entrypoints an error
1 parent f62cf8c commit 556a087

6 files changed

+67
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
throw new Error(
4+
'react-dom/client is not supported in React Server Components.'
5+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
throw new Error(
4+
'react-dom/profiling is not supported in React Server Components.'
5+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
throw new Error(
4+
'react-dom/server is not supported in React Server Components.'
5+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
throw new Error(
4+
'react-dom/static is not supported in React Server Components.'
5+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
throw new Error(
4+
'react-dom/unstable_testing is not supported in React Server Components.'
5+
);

packages/react-dom/package.json

+42-10
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@
5050
"react-server": "./react-dom.react-server.js",
5151
"default": "./index.js"
5252
},
53-
"./client": "./client.js",
53+
"./client": {
54+
"react-server": "./client.react-server.js",
55+
"default": "./client.js"
56+
},
5457
"./server": {
58+
"react-server": "./server.react-server.js",
5559
"workerd": "./server.edge.js",
5660
"bun": "./server.bun.js",
5761
"deno": "./server.browser.js",
@@ -61,11 +65,24 @@
6165
"edge-light": "./server.edge.js",
6266
"default": "./server.node.js"
6367
},
64-
"./server.browser": "./server.browser.js",
65-
"./server.bun": "./server.bun.js",
66-
"./server.edge": "./server.edge.js",
67-
"./server.node": "./server.node.js",
68+
"./server.browser": {
69+
"react-server": "./server.react-server.js",
70+
"default": "./server.browser.js"
71+
},
72+
"./server.bun": {
73+
"react-server": "./server.react-server.js",
74+
"default": "./server.bun.js"
75+
},
76+
"./server.edge": {
77+
"react-server": "./server.react-server.js",
78+
"default": "./server.edge.js"
79+
},
80+
"./server.node": {
81+
"react-server": "./server.react-server.js",
82+
"default": "./server.node.js"
83+
},
6884
"./static": {
85+
"react-server": "./static.react-server.js",
6986
"workerd": "./static.edge.js",
7087
"deno": "./static.browser.js",
7188
"worker": "./static.browser.js",
@@ -74,13 +91,28 @@
7491
"edge-light": "./static.edge.js",
7592
"default": "./static.node.js"
7693
},
77-
"./static.browser": "./static.browser.js",
78-
"./static.edge": "./static.edge.js",
79-
"./static.node": "./static.node.js",
94+
"./static.browser": {
95+
"react-server": "./static.react-server.js",
96+
"default": "./static.browser.js"
97+
},
98+
"./static.edge": {
99+
"react-server": "./static.react-server.js",
100+
"default": "./static.edge.js"
101+
},
102+
"./static.node": {
103+
"react-server": "./static.react-server.js",
104+
"default": "./static.node.js"
105+
},
80106
"./server-rendering-stub": "./server-rendering-stub.js",
81-
"./profiling": "./profiling.js",
107+
"./profiling": {
108+
"react-server": "./profiling.react-server.js",
109+
"default": "./profiling.js"
110+
},
82111
"./test-utils": "./test-utils.js",
83-
"./unstable_testing": "./unstable_testing.js",
112+
"./unstable_testing": {
113+
"react-server": "./unstable_testing.react-server.js",
114+
"default": "./unstable_testing.js"
115+
},
84116
"./unstable_server-external-runtime": "./unstable_server-external-runtime.js",
85117
"./src/*": "./src/*",
86118
"./package.json": "./package.json"

0 commit comments

Comments
 (0)