Skip to content

Commit

Permalink
Rename The Secret Export of Server Internals (#28786)
Browse files Browse the repository at this point in the history
We have a different set of dispatchers that Flight uses. This also
includes the `jsx-runtime` which must also be aliased to use the right
version.

To ensure the right versions are used together we rename the export of
the SharedInternals from 'react' and alias it in relevant bundles.

DiffTrain build for [c771016](c771016)
  • Loading branch information
sebmarkbage committed Apr 9, 2024
1 parent 74e25ca commit dad4604
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 40 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d50323eb845c5fde0d720cae888bf35dedd05506
c771016e19384e4b6e42e1c275bdf03fe51c2907
36 changes: 22 additions & 14 deletions compiled/facebook-www/ReactDOMServerStreaming-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -2345,8 +2345,16 @@ if (__DEV__) {
: 'something with type "' + typeof thing + '"';
}

var ReactSharedInternals =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
var ReactSharedInternalsServer = // $FlowFixMe: It's defined in the one we resolve to.
React.__SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

if (!ReactSharedInternalsServer) {
throw new Error(
'The "react" package in this environment is not configured correctly. ' +
'The "react-server" condition must be enabled in any environment that ' +
"runs React Server Components."
);
}

// same object across all transitions.

Expand Down Expand Up @@ -10735,10 +10743,10 @@ if (__DEV__) {
var previousDispatcher = null;

{
previousDispatcher = ReactSharedInternals.H; // Set the dispatcher in DEV because this might be call in the render function
previousDispatcher = ReactSharedInternalsServer.H; // Set the dispatcher in DEV because this might be call in the render function
// for warnings.

ReactSharedInternals.H = null;
ReactSharedInternalsServer.H = null;
disableLogs();
}
/**
Expand Down Expand Up @@ -10931,7 +10939,7 @@ if (__DEV__) {
reentry = false;

{
ReactSharedInternals.H = previousDispatcher;
ReactSharedInternalsServer.H = previousDispatcher;
reenableLogs();
}

Expand Down Expand Up @@ -13779,22 +13787,22 @@ if (__DEV__) {
}

var prevContext = getActiveContext();
var prevDispatcher = ReactSharedInternals.H;
ReactSharedInternals.H = HooksDispatcher;
var prevDispatcher = ReactSharedInternalsServer.H;
ReactSharedInternalsServer.H = HooksDispatcher;
var prevCacheDispatcher = null;

{
prevCacheDispatcher = ReactSharedInternals.C;
ReactSharedInternals.C = DefaultCacheDispatcher;
prevCacheDispatcher = ReactSharedInternalsServer.C;
ReactSharedInternalsServer.C = DefaultCacheDispatcher;
}

var prevRequest = currentRequest;
currentRequest = request;
var prevGetCurrentStackImpl = null;

{
prevGetCurrentStackImpl = ReactSharedInternals.getCurrentStack;
ReactSharedInternals.getCurrentStack = getCurrentStackInDEV;
prevGetCurrentStackImpl = ReactSharedInternalsServer.getCurrentStack;
ReactSharedInternalsServer.getCurrentStack = getCurrentStackInDEV;
}

var prevResumableState = currentResumableState;
Expand All @@ -13820,14 +13828,14 @@ if (__DEV__) {
fatalError(request, error);
} finally {
setCurrentResumableState(prevResumableState);
ReactSharedInternals.H = prevDispatcher;
ReactSharedInternalsServer.H = prevDispatcher;

{
ReactSharedInternals.C = prevCacheDispatcher;
ReactSharedInternalsServer.C = prevCacheDispatcher;
}

{
ReactSharedInternals.getCurrentStack = prevGetCurrentStackImpl;
ReactSharedInternalsServer.getCurrentStack = prevGetCurrentStackImpl;
}

if (prevDispatcher === HooksDispatcher) {
Expand Down
22 changes: 13 additions & 9 deletions compiled/facebook-www/ReactDOMServerStreaming-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,13 @@ function sanitizeURL(url) {
? "javascript:throw new Error('React has blocked a javascript: URL as a security precaution.')"
: url;
}
var ReactSharedInternals =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
sharedNotPendingObject = {
var ReactSharedInternalsServer =
React.__SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
if (!ReactSharedInternalsServer)
throw Error(
'The "react" package in this environment is not configured correctly. The "react-server" condition must be enabled in any environment that runs React Server Components.'
);
var sharedNotPendingObject = {
pending: !1,
data: null,
method: null,
Expand Down Expand Up @@ -5261,10 +5265,10 @@ exports.renderNextChunk = function (stream) {
stream = stream.destination;
if (2 !== request.status) {
var prevContext = currentActiveSnapshot,
prevDispatcher = ReactSharedInternals.H;
ReactSharedInternals.H = HooksDispatcher;
var prevCacheDispatcher = ReactSharedInternals.C;
ReactSharedInternals.C = DefaultCacheDispatcher;
prevDispatcher = ReactSharedInternalsServer.H;
ReactSharedInternalsServer.H = HooksDispatcher;
var prevCacheDispatcher = ReactSharedInternalsServer.C;
ReactSharedInternalsServer.C = DefaultCacheDispatcher;
var prevRequest = currentRequest;
currentRequest = request;
var prevResumableState = currentResumableState;
Expand Down Expand Up @@ -5418,8 +5422,8 @@ exports.renderNextChunk = function (stream) {
logRecoverableError(request, error, {}), fatalError(request, error);
} finally {
(currentResumableState = prevResumableState),
(ReactSharedInternals.H = prevDispatcher),
(ReactSharedInternals.C = prevCacheDispatcher),
(ReactSharedInternalsServer.H = prevDispatcher),
(ReactSharedInternalsServer.C = prevCacheDispatcher),
prevDispatcher === HooksDispatcher && switchContext(prevContext),
(currentRequest = prevRequest);
}
Expand Down
14 changes: 11 additions & 3 deletions compiled/facebook-www/ReactFlightDOMServer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1146,10 +1146,18 @@ if (__DEV__) {
return "\n " + str;
}

var ReactSharedInternals$1 =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
var ReactSharedInternalsServer = // $FlowFixMe: It's defined in the one we resolve to.
React.__SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

var ReactSharedInternals = ReactSharedInternals$1;
if (!ReactSharedInternalsServer) {
throw new Error(
'The "react" package in this environment is not configured correctly. ' +
'The "react-server" condition must be enabled in any environment that ' +
"runs React Server Components."
);
}

var ReactSharedInternals = ReactSharedInternalsServer;

function patchConsole(consoleInst, methodName) {
var descriptor = Object.getOwnPropertyDescriptor(consoleInst, methodName);
Expand Down
22 changes: 13 additions & 9 deletions compiled/facebook-www/ReactFlightDOMServer-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,13 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
"\n " + str + "\n " + objectOrArray)
: "\n " + str;
}
var ReactSharedInternals$1 =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
ObjectPrototype = Object.prototype,
var ReactSharedInternalsServer =
React.__SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
if (!ReactSharedInternalsServer)
throw Error(
'The "react" package in this environment is not configured correctly. The "react-server" condition must be enabled in any environment that runs React Server Components.'
);
var ObjectPrototype = Object.prototype,
stringify = JSON.stringify;
function defaultErrorHandler(error) {
console.error(error);
Expand Down Expand Up @@ -1018,8 +1022,8 @@ function retryTask(request, task) {
}
}
function performWork(request) {
var prevDispatcher = ReactSharedInternals$1.H;
ReactSharedInternals$1.H = HooksDispatcher;
var prevDispatcher = ReactSharedInternalsServer.H;
ReactSharedInternalsServer.H = HooksDispatcher;
var prevRequest = currentRequest;
currentRequest$1 = currentRequest = request;
try {
Expand All @@ -1032,7 +1036,7 @@ function performWork(request) {
} catch (error) {
logRecoverableError(request, error), fatalError(request, error);
} finally {
(ReactSharedInternals$1.H = prevDispatcher),
(ReactSharedInternalsServer.H = prevDispatcher),
(currentRequest$1 = null),
(currentRequest = prevRequest);
}
Expand Down Expand Up @@ -1085,11 +1089,11 @@ exports.renderToDestination = function (destination, model, options) {
);
var onError = options ? options.onError : void 0;
if (
null !== ReactSharedInternals$1.C &&
ReactSharedInternals$1.C !== DefaultCacheDispatcher
null !== ReactSharedInternalsServer.C &&
ReactSharedInternalsServer.C !== DefaultCacheDispatcher
)
throw Error("Currently React only supports one RSC renderer at a time.");
ReactSharedInternals$1.C = DefaultCacheDispatcher;
ReactSharedInternalsServer.C = DefaultCacheDispatcher;
var abortSet = new Set();
options = [];
var hints = new Set();
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactServer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -3083,7 +3083,7 @@ if (__DEV__) {

function noop() {}

var ReactVersion = "19.0.0-www-modern-85fbc52f";
var ReactVersion = "19.0.0-www-modern-15824b86";

// Patch fetch
var Children = {
Expand All @@ -3105,7 +3105,7 @@ if (__DEV__) {
exports.Profiler = REACT_PROFILER_TYPE;
exports.StrictMode = REACT_STRICT_MODE_TYPE;
exports.Suspense = REACT_SUSPENSE_TYPE;
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED =
exports.__SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED =
ReactSharedInternals;
exports.cache = cache;
exports.cloneElement = cloneElement;
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactServer-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ exports.Fragment = REACT_FRAGMENT_TYPE;
exports.Profiler = REACT_PROFILER_TYPE;
exports.StrictMode = REACT_STRICT_MODE_TYPE;
exports.Suspense = REACT_SUSPENSE_TYPE;
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED =
exports.__SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED =
ReactSharedInternals;
exports.cache = function (fn) {
return function () {
Expand Down Expand Up @@ -587,4 +587,4 @@ exports.useId = function () {
exports.useMemo = function (create, deps) {
return ReactSharedInternals.H.useMemo(create, deps);
};
exports.version = "19.0.0-www-modern-fc045344";
exports.version = "19.0.0-www-modern-5bb44c5c";

0 comments on commit dad4604

Please sign in to comment.