Skip to content

Commit

Permalink
Flatten ReactSharedInternals (#28783)
Browse files Browse the repository at this point in the history
This is similar to #28771 but for isomorphic. We need a make over for
these dispatchers anyway so this is the first step. Also helps flush out
some internals usage that will break anyway.

It flattens the inner mutable objects onto the ReactSharedInternals.

DiffTrain build for [d50323e](d50323e)
  • Loading branch information
sebmarkbage committed Apr 8, 2024
1 parent 550d416 commit 74e25ca
Show file tree
Hide file tree
Showing 37 changed files with 2,234 additions and 2,922 deletions.
39 changes: 17 additions & 22 deletions compiled/facebook-www/JSXDEVRuntime-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ if (__DEV__) {
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Defensive in case this is fired before React is initialized.

if (ReactSharedInternals != null) {
var ReactDebugCurrentFrame =
ReactSharedInternals.ReactDebugCurrentFrame;
var stack = ReactDebugCurrentFrame.getStackAddendum();
var stack = ReactSharedInternals.getStackAddendum();

if (stack !== "") {
format += "%s";
Expand Down Expand Up @@ -486,7 +484,6 @@ if (__DEV__) {
}
}

var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
var prefix;
function describeBuiltInComponentFrame(name) {
{
Expand Down Expand Up @@ -540,13 +537,13 @@ if (__DEV__) {
var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe[incompatible-type] It does accept undefined.

Error.prepareStackTrace = undefined;
var previousDispatcher;
var previousDispatcher = null;

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

ReactCurrentDispatcher.current = null;
ReactSharedInternals.H = null;
disableLogs();
}
/**
Expand Down Expand Up @@ -739,7 +736,7 @@ if (__DEV__) {
reentry = false;

{
ReactCurrentDispatcher.current = previousDispatcher;
ReactSharedInternals.H = previousDispatcher;
reenableLogs();
}

Expand Down Expand Up @@ -967,8 +964,6 @@ if (__DEV__) {
return null;
}

var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
var REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference");
var specialPropKeyWarningShown;
var specialPropRefWarningShown;
Expand Down Expand Up @@ -1012,12 +1007,12 @@ if (__DEV__) {
{
if (
typeof config.ref === "string" &&
ReactCurrentOwner.current &&
ReactSharedInternals.owner &&
self &&
ReactCurrentOwner.current.stateNode !== self
ReactSharedInternals.owner.stateNode !== self
) {
var componentName = getComponentNameFromType(
ReactCurrentOwner.current.type
ReactSharedInternals.owner.type
);

if (!didWarnAboutStringRefs[componentName]) {
Expand All @@ -1028,7 +1023,7 @@ if (__DEV__) {
"We ask you to manually fix this case by using useRef() or createRef() instead. " +
"Learn more about using refs safely here: " +
"https://react.dev/link/strict-mode-string-ref",
getComponentNameFromType(ReactCurrentOwner.current.type),
getComponentNameFromType(ReactSharedInternals.owner.type),
config.ref
);

Expand Down Expand Up @@ -1381,7 +1376,7 @@ if (__DEV__) {
ref = config.ref;

{
ref = coerceStringRef(ref, ReactCurrentOwner.current, type);
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
}
}

Expand Down Expand Up @@ -1415,7 +1410,7 @@ if (__DEV__) {
if (enableRefAsProp && !disableStringRefs && propName === "ref") {
props.ref = coerceStringRef(
config[propName],
ReactCurrentOwner.current,
ReactSharedInternals.owner,
type
);
} else {
Expand Down Expand Up @@ -1459,7 +1454,7 @@ if (__DEV__) {
ref,
self,
source,
ReactCurrentOwner.current,
ReactSharedInternals.owner,
props
);

Expand All @@ -1473,8 +1468,8 @@ if (__DEV__) {

function getDeclarationErrorAddendum() {
{
if (ReactCurrentOwner.current) {
var name = getComponentNameFromType(ReactCurrentOwner.current.type);
if (ReactSharedInternals.owner) {
var name = getComponentNameFromType(ReactSharedInternals.owner.type);

if (name) {
return "\n\nCheck the render method of `" + name + "`.";
Expand Down Expand Up @@ -1589,7 +1584,7 @@ if (__DEV__) {
if (
element &&
element._owner != null &&
element._owner !== ReactCurrentOwner.current
element._owner !== ReactSharedInternals.owner
) {
var ownerName = null;

Expand Down Expand Up @@ -1619,9 +1614,9 @@ if (__DEV__) {
{
if (element) {
var stack = describeUnknownElementTypeFrameInDEV(element.type);
ReactDebugCurrentFrame.setExtraStackFrame(stack);
ReactSharedInternals.setExtraStackFrame(stack);
} else {
ReactDebugCurrentFrame.setExtraStackFrame(null);
ReactSharedInternals.setExtraStackFrame(null);
}
}
}
Expand Down
39 changes: 17 additions & 22 deletions compiled/facebook-www/JSXDEVRuntime-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ if (__DEV__) {
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Defensive in case this is fired before React is initialized.

if (ReactSharedInternals != null) {
var ReactDebugCurrentFrame =
ReactSharedInternals.ReactDebugCurrentFrame;
var stack = ReactDebugCurrentFrame.getStackAddendum();
var stack = ReactSharedInternals.getStackAddendum();

if (stack !== "") {
format += "%s";
Expand Down Expand Up @@ -486,7 +484,6 @@ if (__DEV__) {
}
}

var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
var prefix;
function describeBuiltInComponentFrame(name) {
{
Expand Down Expand Up @@ -540,13 +537,13 @@ if (__DEV__) {
var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe[incompatible-type] It does accept undefined.

Error.prepareStackTrace = undefined;
var previousDispatcher;
var previousDispatcher = null;

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

ReactCurrentDispatcher.current = null;
ReactSharedInternals.H = null;
disableLogs();
}
/**
Expand Down Expand Up @@ -739,7 +736,7 @@ if (__DEV__) {
reentry = false;

{
ReactCurrentDispatcher.current = previousDispatcher;
ReactSharedInternals.H = previousDispatcher;
reenableLogs();
}

Expand Down Expand Up @@ -969,8 +966,6 @@ if (__DEV__) {
return null;
}

var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
var REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference");
var specialPropKeyWarningShown;
var specialPropRefWarningShown;
Expand Down Expand Up @@ -1014,12 +1009,12 @@ if (__DEV__) {
{
if (
typeof config.ref === "string" &&
ReactCurrentOwner.current &&
ReactSharedInternals.owner &&
self &&
ReactCurrentOwner.current.stateNode !== self
ReactSharedInternals.owner.stateNode !== self
) {
var componentName = getComponentNameFromType(
ReactCurrentOwner.current.type
ReactSharedInternals.owner.type
);

if (!didWarnAboutStringRefs[componentName]) {
Expand All @@ -1030,7 +1025,7 @@ if (__DEV__) {
"We ask you to manually fix this case by using useRef() or createRef() instead. " +
"Learn more about using refs safely here: " +
"https://react.dev/link/strict-mode-string-ref",
getComponentNameFromType(ReactCurrentOwner.current.type),
getComponentNameFromType(ReactSharedInternals.owner.type),
config.ref
);

Expand Down Expand Up @@ -1383,7 +1378,7 @@ if (__DEV__) {
ref = config.ref;

{
ref = coerceStringRef(ref, ReactCurrentOwner.current, type);
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
}
}

Expand Down Expand Up @@ -1417,7 +1412,7 @@ if (__DEV__) {
if (enableRefAsProp && !disableStringRefs && propName === "ref") {
props.ref = coerceStringRef(
config[propName],
ReactCurrentOwner.current,
ReactSharedInternals.owner,
type
);
} else {
Expand Down Expand Up @@ -1461,7 +1456,7 @@ if (__DEV__) {
ref,
self,
source,
ReactCurrentOwner.current,
ReactSharedInternals.owner,
props
);

Expand All @@ -1475,8 +1470,8 @@ if (__DEV__) {

function getDeclarationErrorAddendum() {
{
if (ReactCurrentOwner.current) {
var name = getComponentNameFromType(ReactCurrentOwner.current.type);
if (ReactSharedInternals.owner) {
var name = getComponentNameFromType(ReactSharedInternals.owner.type);

if (name) {
return "\n\nCheck the render method of `" + name + "`.";
Expand Down Expand Up @@ -1591,7 +1586,7 @@ if (__DEV__) {
if (
element &&
element._owner != null &&
element._owner !== ReactCurrentOwner.current
element._owner !== ReactSharedInternals.owner
) {
var ownerName = null;

Expand Down Expand Up @@ -1621,9 +1616,9 @@ if (__DEV__) {
{
if (element) {
var stack = describeUnknownElementTypeFrameInDEV(element.type);
ReactDebugCurrentFrame.setExtraStackFrame(stack);
ReactSharedInternals.setExtraStackFrame(stack);
} else {
ReactDebugCurrentFrame.setExtraStackFrame(null);
ReactSharedInternals.setExtraStackFrame(null);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f62cf8c62052ae780d351090013f7155cf9a868c
d50323eb845c5fde0d720cae888bf35dedd05506
Loading

0 comments on commit 74e25ca

Please sign in to comment.