Skip to content

Commit 20fecfd

Browse files
committed
Add Server Context deprecation warning (#27424)
As agreed, we're removing Server Context. This was never official documented. We've found that it's not that useful in practice. Often the better options are: - Read things off the url or global scope like params or cookies. - Use the module system for global dependency injection. - Use `React.cache()` to dedupe multiple things instead of computing once and passing down. There are still legit use cases for Server Context but you have to be very careful not to pass any large data, so in generally we recommend against it anyway. Yes, prop drilling is annoying but it's not impossible for the cases this is needed. I would personally always pick it over Server Context anyway. Semantically, Server Context also blocks object deduping due to how it plays out with Server Components that can't be deduped. This is much more important feature. Since it's already in canary along with the rest of RSC, we're adding a warning for a few versions before removing completely to help migration. --------- Co-authored-by: Josh Story <[email protected]> DiffTrain build for [1ebedbe](1ebedbe)
1 parent 6db6c39 commit 20fecfd

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f81c0f1ed962036f25b87281b3c18cef3860ded8
1+
1ebedbec2bec08e07c286ea6c3cff62737a0fd3a

compiled/facebook-www/React-dev.classic.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-classic-ceb12d9d";
30+
var ReactVersion = "18.3.0-www-classic-443dd2b0";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,
@@ -2949,6 +2949,14 @@ function cloneElementWithValidation(element, props, children) {
29492949

29502950
var ContextRegistry = ReactSharedInternals.ContextRegistry;
29512951
function createServerContext(globalName, defaultValue) {
2952+
{
2953+
error(
2954+
"Server Context is deprecated and will soon be removed. " +
2955+
"It was never documented and we have found it not to be useful " +
2956+
"enough to warrant the downside it imposes on all apps."
2957+
);
2958+
}
2959+
29522960
var wasDefined = true;
29532961

29542962
if (!ContextRegistry[globalName]) {

compiled/facebook-www/React-dev.modern.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-modern-6c7b6f54";
30+
var ReactVersion = "18.3.0-www-modern-df3e4079";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,
@@ -2915,6 +2915,14 @@ function cloneElementWithValidation(element, props, children) {
29152915

29162916
var ContextRegistry = ReactSharedInternals.ContextRegistry;
29172917
function createServerContext(globalName, defaultValue) {
2918+
{
2919+
error(
2920+
"Server Context is deprecated and will soon be removed. " +
2921+
"It was never documented and we have found it not to be useful " +
2922+
"enough to warrant the downside it imposes on all apps."
2923+
);
2924+
}
2925+
29182926
var wasDefined = true;
29192927

29202928
if (!ContextRegistry[globalName]) {

compiled/facebook-www/ReactDOMTesting-prod.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16694,7 +16694,7 @@ Internals.Events = [
1669416694
var devToolsConfig$jscomp$inline_1805 = {
1669516695
findFiberByHostInstance: getClosestInstanceFromNode,
1669616696
bundleType: 0,
16697-
version: "18.3.0-www-classic-ceb12d9d",
16697+
version: "18.3.0-www-classic-443dd2b0",
1669816698
rendererPackageName: "react-dom"
1669916699
};
1670016700
var internals$jscomp$inline_2154 = {
@@ -16724,7 +16724,7 @@ var internals$jscomp$inline_2154 = {
1672416724
scheduleRoot: null,
1672516725
setRefreshHandler: null,
1672616726
getCurrentFiber: null,
16727-
reconcilerVersion: "18.3.0-www-classic-ceb12d9d"
16727+
reconcilerVersion: "18.3.0-www-classic-443dd2b0"
1672816728
};
1672916729
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1673016730
var hook$jscomp$inline_2155 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17212,4 +17212,4 @@ exports.unstable_renderSubtreeIntoContainer = function (
1721217212
);
1721317213
};
1721417214
exports.unstable_runWithPriority = runWithPriority;
17215-
exports.version = "18.3.0-www-classic-ceb12d9d";
17215+
exports.version = "18.3.0-www-classic-443dd2b0";

compiled/facebook-www/WARNINGS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@
258258
"Rendering <Context.Consumer.Provider> is not supported and will be removed in a future major release. Did you mean to render <Context.Provider> instead?"
259259
"Rendering <Context> directly is not supported and will be removed in a future major release. Did you mean to render <Context.Consumer> instead?"
260260
"Select elements must be either controlled or uncontrolled (specify either the value prop, or the defaultValue prop, but not both). Decide between using a controlled or uncontrolled select element and remove one of these props. More info: https://reactjs.org/link/controlled-components"
261+
"Server Context is deprecated and will soon be removed. It was never documented and we have found it not to be useful enough to warrant the downside it imposes on all apps."
261262
"ServerContext can only have a value prop and children. Found: %s"
262263
"Setting `displayName` on Context.Consumer has no effect. You should set it directly on the context with Context.displayName = '%s'."
263264
"Setting defaultProps as an instance property on %s is not supported and will be ignored. Instead, define defaultProps as a static property on %s."

0 commit comments

Comments
 (0)