[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
Josh Story committed
Apr 8, 2024 at 15:37 UTC
556a087de3c94761d3834b11c30630dcaa82600c
6 files changed
+67
-10
packages/react-dom/npm/client.react-server.js
new
+5
@@ -0,0 +1,5 @@
1
+'use strict';
2
+
3
+throw new Error(
4
+ 'react-dom/client is not supported in React Server Components.'
5
+);
packages/react-dom/npm/profiling.react-server.js
new
+5
@@ -0,0 +1,5 @@
1
+'use strict';
2
+
3
+throw new Error(
4
+ 'react-dom/profiling is not supported in React Server Components.'
5
+);
packages/react-dom/npm/server.react-server.js
new
+5
@@ -0,0 +1,5 @@
1
+'use strict';
2
+
3
+throw new Error(
4
+ 'react-dom/server is not supported in React Server Components.'
5
+);
packages/react-dom/npm/static.react-server.js
new
+5
@@ -0,0 +1,5 @@
1
+'use strict';
2
+
3
+throw new Error(
4
+ 'react-dom/static is not supported in React Server Components.'
5
+);
packages/react-dom/npm/unstable_testing.react-server.js
new
+5
@@ -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
@@ -50,8 +50,12 @@
50
"react-server": "./react-dom.react-server.js",
51
"default": "./index.js"
52
},
53
- "./client": "./client.js",
53
+ "./client": {
54
+ "react-server": "./client.react-server.js",
55
+ "default": "./client.js"
56
+ },
57
"./server": {
58
+ "react-server": "./server.react-server.js",
59
"workerd": "./server.edge.js",
60
"bun": "./server.bun.js",
61
"deno": "./server.browser.js",
@@ -61,11 +65,24 @@
65
"edge-light": "./server.edge.js",
66
"default": "./server.node.js"
67
},
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
+ },
84
"./static": {
85
+ "react-server": "./static.react-server.js",
86
"workerd": "./static.edge.js",
87
"deno": "./static.browser.js",
88
"worker": "./static.browser.js",
@@ -74,13 +91,28 @@
91
"edge-light": "./static.edge.js",
92
"default": "./static.node.js"
93
},
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
+ },
106
"./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
+ },
111
"./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
+ },
116
"./unstable_server-external-runtime": "./unstable_server-external-runtime.js",
117
"./src/*": "./src/*",
118
"./package.json": "./package.json"