From 20fecfd7af0d3e301511acdd2ec95c006bd2053d Mon Sep 17 00:00:00 2001 From: sebmarkbage Date: Thu, 28 Sep 2023 15:08:13 +0000 Subject: [PATCH] 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 DiffTrain build for [1ebedbec2bec08e07c286ea6c3cff62737a0fd3a](https://github.com/facebook/react/commit/1ebedbec2bec08e07c286ea6c3cff62737a0fd3a) --- compiled/facebook-www/REVISION | 2 +- compiled/facebook-www/React-dev.classic.js | 10 +++++++++- compiled/facebook-www/React-dev.modern.js | 10 +++++++++- compiled/facebook-www/ReactDOMTesting-prod.classic.js | 6 +++--- compiled/facebook-www/WARNINGS | 1 + 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/compiled/facebook-www/REVISION b/compiled/facebook-www/REVISION index 04a927d5cb..631f5aeb9d 100644 --- a/compiled/facebook-www/REVISION +++ b/compiled/facebook-www/REVISION @@ -1 +1 @@ -f81c0f1ed962036f25b87281b3c18cef3860ded8 +1ebedbec2bec08e07c286ea6c3cff62737a0fd3a diff --git a/compiled/facebook-www/React-dev.classic.js b/compiled/facebook-www/React-dev.classic.js index f4f2425d48..418af9c062 100644 --- a/compiled/facebook-www/React-dev.classic.js +++ b/compiled/facebook-www/React-dev.classic.js @@ -27,7 +27,7 @@ if ( } "use strict"; -var ReactVersion = "18.3.0-www-classic-ceb12d9d"; +var ReactVersion = "18.3.0-www-classic-443dd2b0"; // ATTENTION // When adding new symbols to this file, @@ -2949,6 +2949,14 @@ function cloneElementWithValidation(element, props, children) { var ContextRegistry = ReactSharedInternals.ContextRegistry; function createServerContext(globalName, defaultValue) { + { + error( + "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." + ); + } + var wasDefined = true; if (!ContextRegistry[globalName]) { diff --git a/compiled/facebook-www/React-dev.modern.js b/compiled/facebook-www/React-dev.modern.js index ea0ed0defd..b0e2a6fa19 100644 --- a/compiled/facebook-www/React-dev.modern.js +++ b/compiled/facebook-www/React-dev.modern.js @@ -27,7 +27,7 @@ if ( } "use strict"; -var ReactVersion = "18.3.0-www-modern-6c7b6f54"; +var ReactVersion = "18.3.0-www-modern-df3e4079"; // ATTENTION // When adding new symbols to this file, @@ -2915,6 +2915,14 @@ function cloneElementWithValidation(element, props, children) { var ContextRegistry = ReactSharedInternals.ContextRegistry; function createServerContext(globalName, defaultValue) { + { + error( + "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." + ); + } + var wasDefined = true; if (!ContextRegistry[globalName]) { diff --git a/compiled/facebook-www/ReactDOMTesting-prod.classic.js b/compiled/facebook-www/ReactDOMTesting-prod.classic.js index 4af40deb8a..ff7f558079 100644 --- a/compiled/facebook-www/ReactDOMTesting-prod.classic.js +++ b/compiled/facebook-www/ReactDOMTesting-prod.classic.js @@ -16694,7 +16694,7 @@ Internals.Events = [ var devToolsConfig$jscomp$inline_1805 = { findFiberByHostInstance: getClosestInstanceFromNode, bundleType: 0, - version: "18.3.0-www-classic-ceb12d9d", + version: "18.3.0-www-classic-443dd2b0", rendererPackageName: "react-dom" }; var internals$jscomp$inline_2154 = { @@ -16724,7 +16724,7 @@ var internals$jscomp$inline_2154 = { scheduleRoot: null, setRefreshHandler: null, getCurrentFiber: null, - reconcilerVersion: "18.3.0-www-classic-ceb12d9d" + reconcilerVersion: "18.3.0-www-classic-443dd2b0" }; if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) { var hook$jscomp$inline_2155 = __REACT_DEVTOOLS_GLOBAL_HOOK__; @@ -17212,4 +17212,4 @@ exports.unstable_renderSubtreeIntoContainer = function ( ); }; exports.unstable_runWithPriority = runWithPriority; -exports.version = "18.3.0-www-classic-ceb12d9d"; +exports.version = "18.3.0-www-classic-443dd2b0"; diff --git a/compiled/facebook-www/WARNINGS b/compiled/facebook-www/WARNINGS index 935f0fb45b..2b3cadba76 100644 --- a/compiled/facebook-www/WARNINGS +++ b/compiled/facebook-www/WARNINGS @@ -258,6 +258,7 @@ "Rendering is not supported and will be removed in a future major release. Did you mean to render instead?" "Rendering directly is not supported and will be removed in a future major release. Did you mean to render instead?" "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" +"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." "ServerContext can only have a value prop and children. Found: %s" "Setting `displayName` on Context.Consumer has no effect. You should set it directly on the context with Context.displayName = '%s'." "Setting defaultProps as an instance property on %s is not supported and will be ignored. Instead, define defaultProps as a static property on %s."