Skip to content

Commit 74e25ca

Browse files
committed
Flatten ReactSharedInternals (#28783)
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)
1 parent 550d416 commit 74e25ca

37 files changed

+2234
-2922
lines changed

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

+17-22
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ if (__DEV__) {
8787
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Defensive in case this is fired before React is initialized.
8888

8989
if (ReactSharedInternals != null) {
90-
var ReactDebugCurrentFrame =
91-
ReactSharedInternals.ReactDebugCurrentFrame;
92-
var stack = ReactDebugCurrentFrame.getStackAddendum();
90+
var stack = ReactSharedInternals.getStackAddendum();
9391

9492
if (stack !== "") {
9593
format += "%s";
@@ -486,7 +484,6 @@ if (__DEV__) {
486484
}
487485
}
488486

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

542539
Error.prepareStackTrace = undefined;
543-
var previousDispatcher;
540+
var previousDispatcher = null;
544541

545542
{
546-
previousDispatcher = ReactCurrentDispatcher.current; // Set the dispatcher in DEV because this might be call in the render function
543+
previousDispatcher = ReactSharedInternals.H; // Set the dispatcher in DEV because this might be call in the render function
547544
// for warnings.
548545

549-
ReactCurrentDispatcher.current = null;
546+
ReactSharedInternals.H = null;
550547
disableLogs();
551548
}
552549
/**
@@ -739,7 +736,7 @@ if (__DEV__) {
739736
reentry = false;
740737

741738
{
742-
ReactCurrentDispatcher.current = previousDispatcher;
739+
ReactSharedInternals.H = previousDispatcher;
743740
reenableLogs();
744741
}
745742

@@ -967,8 +964,6 @@ if (__DEV__) {
967964
return null;
968965
}
969966

970-
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
971-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
972967
var REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference");
973968
var specialPropKeyWarningShown;
974969
var specialPropRefWarningShown;
@@ -1012,12 +1007,12 @@ if (__DEV__) {
10121007
{
10131008
if (
10141009
typeof config.ref === "string" &&
1015-
ReactCurrentOwner.current &&
1010+
ReactSharedInternals.owner &&
10161011
self &&
1017-
ReactCurrentOwner.current.stateNode !== self
1012+
ReactSharedInternals.owner.stateNode !== self
10181013
) {
10191014
var componentName = getComponentNameFromType(
1020-
ReactCurrentOwner.current.type
1015+
ReactSharedInternals.owner.type
10211016
);
10221017

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

@@ -1381,7 +1376,7 @@ if (__DEV__) {
13811376
ref = config.ref;
13821377

13831378
{
1384-
ref = coerceStringRef(ref, ReactCurrentOwner.current, type);
1379+
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
13851380
}
13861381
}
13871382

@@ -1415,7 +1410,7 @@ if (__DEV__) {
14151410
if (enableRefAsProp && !disableStringRefs && propName === "ref") {
14161411
props.ref = coerceStringRef(
14171412
config[propName],
1418-
ReactCurrentOwner.current,
1413+
ReactSharedInternals.owner,
14191414
type
14201415
);
14211416
} else {
@@ -1459,7 +1454,7 @@ if (__DEV__) {
14591454
ref,
14601455
self,
14611456
source,
1462-
ReactCurrentOwner.current,
1457+
ReactSharedInternals.owner,
14631458
props
14641459
);
14651460

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

14741469
function getDeclarationErrorAddendum() {
14751470
{
1476-
if (ReactCurrentOwner.current) {
1477-
var name = getComponentNameFromType(ReactCurrentOwner.current.type);
1471+
if (ReactSharedInternals.owner) {
1472+
var name = getComponentNameFromType(ReactSharedInternals.owner.type);
14781473

14791474
if (name) {
14801475
return "\n\nCheck the render method of `" + name + "`.";
@@ -1589,7 +1584,7 @@ if (__DEV__) {
15891584
if (
15901585
element &&
15911586
element._owner != null &&
1592-
element._owner !== ReactCurrentOwner.current
1587+
element._owner !== ReactSharedInternals.owner
15931588
) {
15941589
var ownerName = null;
15951590

@@ -1619,9 +1614,9 @@ if (__DEV__) {
16191614
{
16201615
if (element) {
16211616
var stack = describeUnknownElementTypeFrameInDEV(element.type);
1622-
ReactDebugCurrentFrame.setExtraStackFrame(stack);
1617+
ReactSharedInternals.setExtraStackFrame(stack);
16231618
} else {
1624-
ReactDebugCurrentFrame.setExtraStackFrame(null);
1619+
ReactSharedInternals.setExtraStackFrame(null);
16251620
}
16261621
}
16271622
}

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

+17-22
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ if (__DEV__) {
8787
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Defensive in case this is fired before React is initialized.
8888

8989
if (ReactSharedInternals != null) {
90-
var ReactDebugCurrentFrame =
91-
ReactSharedInternals.ReactDebugCurrentFrame;
92-
var stack = ReactDebugCurrentFrame.getStackAddendum();
90+
var stack = ReactSharedInternals.getStackAddendum();
9391

9492
if (stack !== "") {
9593
format += "%s";
@@ -486,7 +484,6 @@ if (__DEV__) {
486484
}
487485
}
488486

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

542539
Error.prepareStackTrace = undefined;
543-
var previousDispatcher;
540+
var previousDispatcher = null;
544541

545542
{
546-
previousDispatcher = ReactCurrentDispatcher.current; // Set the dispatcher in DEV because this might be call in the render function
543+
previousDispatcher = ReactSharedInternals.H; // Set the dispatcher in DEV because this might be call in the render function
547544
// for warnings.
548545

549-
ReactCurrentDispatcher.current = null;
546+
ReactSharedInternals.H = null;
550547
disableLogs();
551548
}
552549
/**
@@ -739,7 +736,7 @@ if (__DEV__) {
739736
reentry = false;
740737

741738
{
742-
ReactCurrentDispatcher.current = previousDispatcher;
739+
ReactSharedInternals.H = previousDispatcher;
743740
reenableLogs();
744741
}
745742

@@ -969,8 +966,6 @@ if (__DEV__) {
969966
return null;
970967
}
971968

972-
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
973-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
974969
var REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference");
975970
var specialPropKeyWarningShown;
976971
var specialPropRefWarningShown;
@@ -1014,12 +1009,12 @@ if (__DEV__) {
10141009
{
10151010
if (
10161011
typeof config.ref === "string" &&
1017-
ReactCurrentOwner.current &&
1012+
ReactSharedInternals.owner &&
10181013
self &&
1019-
ReactCurrentOwner.current.stateNode !== self
1014+
ReactSharedInternals.owner.stateNode !== self
10201015
) {
10211016
var componentName = getComponentNameFromType(
1022-
ReactCurrentOwner.current.type
1017+
ReactSharedInternals.owner.type
10231018
);
10241019

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

@@ -1383,7 +1378,7 @@ if (__DEV__) {
13831378
ref = config.ref;
13841379

13851380
{
1386-
ref = coerceStringRef(ref, ReactCurrentOwner.current, type);
1381+
ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
13871382
}
13881383
}
13891384

@@ -1417,7 +1412,7 @@ if (__DEV__) {
14171412
if (enableRefAsProp && !disableStringRefs && propName === "ref") {
14181413
props.ref = coerceStringRef(
14191414
config[propName],
1420-
ReactCurrentOwner.current,
1415+
ReactSharedInternals.owner,
14211416
type
14221417
);
14231418
} else {
@@ -1461,7 +1456,7 @@ if (__DEV__) {
14611456
ref,
14621457
self,
14631458
source,
1464-
ReactCurrentOwner.current,
1459+
ReactSharedInternals.owner,
14651460
props
14661461
);
14671462

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

14761471
function getDeclarationErrorAddendum() {
14771472
{
1478-
if (ReactCurrentOwner.current) {
1479-
var name = getComponentNameFromType(ReactCurrentOwner.current.type);
1473+
if (ReactSharedInternals.owner) {
1474+
var name = getComponentNameFromType(ReactSharedInternals.owner.type);
14801475

14811476
if (name) {
14821477
return "\n\nCheck the render method of `" + name + "`.";
@@ -1591,7 +1586,7 @@ if (__DEV__) {
15911586
if (
15921587
element &&
15931588
element._owner != null &&
1594-
element._owner !== ReactCurrentOwner.current
1589+
element._owner !== ReactSharedInternals.owner
15951590
) {
15961591
var ownerName = null;
15971592

@@ -1621,9 +1616,9 @@ if (__DEV__) {
16211616
{
16221617
if (element) {
16231618
var stack = describeUnknownElementTypeFrameInDEV(element.type);
1624-
ReactDebugCurrentFrame.setExtraStackFrame(stack);
1619+
ReactSharedInternals.setExtraStackFrame(stack);
16251620
} else {
1626-
ReactDebugCurrentFrame.setExtraStackFrame(null);
1621+
ReactSharedInternals.setExtraStackFrame(null);
16271622
}
16281623
}
16291624
}

compiled/facebook-www/REVISION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f62cf8c62052ae780d351090013f7155cf9a868c
1+
d50323eb845c5fde0d720cae888bf35dedd05506

0 commit comments

Comments
 (0)