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 commit d50323e.
  • Loading branch information
sebmarkbage committed Apr 8, 2024
1 parent d629d07 commit deede8d
Show file tree
Hide file tree
Showing 17 changed files with 951 additions and 1,186 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<493cdb9fbf258eb499287015c0434886>>
* @generated SignedSource<<87f2bb9cd01d048068daf2853de59b90>>
*/

"use strict";
Expand Down Expand Up @@ -2133,9 +2133,7 @@ function findFirstSuspended(row) {
}
return null;
}
var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher,
ReactCurrentBatchConfig$2 = ReactSharedInternals.ReactCurrentBatchConfig,
renderLanes = 0,
var renderLanes = 0,
currentlyRenderingFiber$1 = null,
currentHook = null,
workInProgressHook = null,
Expand Down Expand Up @@ -2169,7 +2167,7 @@ function renderWithHooks(
workInProgress.memoizedState = null;
workInProgress.updateQueue = null;
workInProgress.lanes = 0;
ReactCurrentDispatcher$1.current =
ReactSharedInternals.H =
null === current || null === current.memoizedState
? HooksDispatcherOnMount
: HooksDispatcherOnUpdate;
Expand All @@ -2187,7 +2185,7 @@ function renderWithHooks(
return current;
}
function finishRenderingHooks() {
ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
ReactSharedInternals.H = ContextOnlyDispatcher;
var didRenderTooFewHooks = null !== currentHook && null !== currentHook.next;
renderLanes = 0;
workInProgressHook = currentHook = currentlyRenderingFiber$1 = null;
Expand All @@ -2213,13 +2211,13 @@ function renderWithHooksAgain(workInProgress, Component, props, secondArg) {
numberOfReRenders += 1;
workInProgressHook = currentHook = null;
workInProgress.updateQueue = null;
ReactCurrentDispatcher$1.current = HooksDispatcherOnRerender;
ReactSharedInternals.H = HooksDispatcherOnRerender;
var children = Component(props, secondArg);
} while (didScheduleRenderPhaseUpdateDuringThisPass);
return children;
}
function TransitionAwareHostComponent() {
var maybeThenable = ReactCurrentDispatcher$1.current.useState()[0];
var maybeThenable = ReactSharedInternals.H.useState()[0];
return "function" === typeof maybeThenable.then
? useThenable(maybeThenable)
: maybeThenable;
Expand Down Expand Up @@ -2310,7 +2308,7 @@ function useThenable(thenable) {
(null === workInProgressHook
? null === currentlyRenderingFiber$1.memoizedState
: null === workInProgressHook.next) &&
(ReactCurrentDispatcher$1.current = HooksDispatcherOnMount);
(ReactSharedInternals.H = HooksDispatcherOnMount);
return thenable;
}
function use(usable) {
Expand Down Expand Up @@ -2610,9 +2608,9 @@ function dispatchActionState(
function runActionStateAction(actionQueue, setPendingState, setState, payload) {
var action = actionQueue.action,
prevState = actionQueue.state,
prevTransition = ReactCurrentBatchConfig$2.transition,
prevTransition = ReactSharedInternals.T,
currentTransition = { _callbacks: new Set() };
ReactCurrentBatchConfig$2.transition = currentTransition;
ReactSharedInternals.T = currentTransition;
setPendingState(!0);
try {
var returnValue = action(prevState, payload);
Expand Down Expand Up @@ -2645,7 +2643,7 @@ function runActionStateAction(actionQueue, setPendingState, setState, payload) {
setState({ then: function () {}, status: "rejected", reason: error }),
finishRunningActionStateAction(actionQueue, setPendingState, setState);
} finally {
ReactCurrentBatchConfig$2.transition = prevTransition;
ReactSharedInternals.T = prevTransition;
}
}
function finishRunningActionStateAction(
Expand Down Expand Up @@ -2882,9 +2880,9 @@ function startTransition(fiber, queue, pendingState, finishedState, callback) {
var previousPriority = currentUpdatePriority;
currentUpdatePriority =
0 !== previousPriority && 8 > previousPriority ? previousPriority : 8;
var prevTransition = ReactCurrentBatchConfig$2.transition,
var prevTransition = ReactSharedInternals.T,
currentTransition = { _callbacks: new Set() };
ReactCurrentBatchConfig$2.transition = currentTransition;
ReactSharedInternals.T = currentTransition;
dispatchOptimisticSetState(fiber, !1, queue, pendingState);
try {
var returnValue = callback();
Expand All @@ -2908,7 +2906,7 @@ function startTransition(fiber, queue, pendingState, finishedState, callback) {
});
} finally {
(currentUpdatePriority = previousPriority),
(ReactCurrentBatchConfig$2.transition = prevTransition);
(ReactSharedInternals.T = prevTransition);
}
}
function useHostTransitionStatus() {
Expand Down Expand Up @@ -3744,8 +3742,7 @@ function throwException(
} while (null !== returnFiber);
return !1;
}
var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner,
SelectiveHydrationException = Error(
var SelectiveHydrationException = Error(
"This is not a real error. It's an implementation detail of React's selective hydration feature. If this leaks into userspace, it's a bug in React. Please file an issue."
),
didReceiveUpdate = !1;
Expand Down Expand Up @@ -4242,7 +4239,7 @@ function finishClassComponent(
bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes)
);
shouldUpdate = workInProgress.stateNode;
ReactCurrentOwner$1.current = workInProgress;
ReactSharedInternals.owner = workInProgress;
var nextChildren =
didCaptureError && "function" !== typeof Component.getDerivedStateFromError
? null
Expand Down Expand Up @@ -5438,9 +5435,8 @@ function releaseCache(cache) {
cache.controller.abort();
});
}
var ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
function requestCurrentTransition() {
var transition = ReactCurrentBatchConfig$1.transition;
var transition = ReactSharedInternals.T;
null !== transition && transition._callbacks.add(handleAsyncAction);
return transition;
}
Expand Down Expand Up @@ -7383,10 +7379,6 @@ var DefaultCacheDispatcher = {
}
},
PossiblyWeakMap = "function" === typeof WeakMap ? WeakMap : Map,
ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher,
ReactCurrentCache = ReactSharedInternals.ReactCurrentCache,
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner,
ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig,
executionContext = 0,
workInProgressRoot = null,
workInProgress = null,
Expand Down Expand Up @@ -7740,18 +7732,14 @@ function flushSyncFromReconciler(fn) {
flushPassiveEffects();
var prevExecutionContext = executionContext;
executionContext |= 1;
var prevTransition = ReactCurrentBatchConfig.transition,
var prevTransition = ReactSharedInternals.T,
previousPriority = currentUpdatePriority;
try {
if (
((currentUpdatePriority = 2),
(ReactCurrentBatchConfig.transition = null),
fn)
)
if (((currentUpdatePriority = 2), (ReactSharedInternals.T = null), fn))
return fn();
} finally {
(currentUpdatePriority = previousPriority),
(ReactCurrentBatchConfig.transition = prevTransition),
(ReactSharedInternals.T = prevTransition),
(executionContext = prevExecutionContext),
0 === (executionContext & 6) && flushSyncWorkAcrossRoots_impl(!1);
}
Expand Down Expand Up @@ -7817,8 +7805,8 @@ function prepareFreshStack(root, lanes) {
}
function handleThrow(root, thrownValue) {
currentlyRenderingFiber$1 = null;
ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
ReactCurrentOwner.current = null;
ReactSharedInternals.H = ContextOnlyDispatcher;
ReactSharedInternals.owner = null;
if (thrownValue === SuspenseException) {
thrownValue = getSuspendedThenable();
var handler = suspenseHandlerStackCursor.current;
Expand Down Expand Up @@ -7856,13 +7844,13 @@ function handleThrow(root, thrownValue) {
));
}
function pushDispatcher() {
var prevDispatcher = ReactCurrentDispatcher.current;
ReactCurrentDispatcher.current = ContextOnlyDispatcher;
var prevDispatcher = ReactSharedInternals.H;
ReactSharedInternals.H = ContextOnlyDispatcher;
return null === prevDispatcher ? ContextOnlyDispatcher : prevDispatcher;
}
function pushCacheDispatcher() {
var prevCacheDispatcher = ReactCurrentCache.current;
ReactCurrentCache.current = DefaultCacheDispatcher;
var prevCacheDispatcher = ReactSharedInternals.C;
ReactSharedInternals.C = DefaultCacheDispatcher;
return prevCacheDispatcher;
}
function renderDidSuspendDelayIfPossible() {
Expand Down Expand Up @@ -7914,8 +7902,8 @@ function renderRootSync(root, lanes) {
lanes && root.shellSuspendCounter++;
resetContextDependencies();
executionContext = prevExecutionContext;
ReactCurrentDispatcher.current = prevDispatcher;
ReactCurrentCache.current = prevCacheDispatcher;
ReactSharedInternals.H = prevDispatcher;
ReactSharedInternals.C = prevCacheDispatcher;
if (null !== workInProgress)
throw Error(
"Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue."
Expand Down Expand Up @@ -8021,8 +8009,8 @@ function renderRootConcurrent(root, lanes) {
}
while (1);
resetContextDependencies();
ReactCurrentDispatcher.current = prevDispatcher;
ReactCurrentCache.current = prevCacheDispatcher;
ReactSharedInternals.H = prevDispatcher;
ReactSharedInternals.C = prevCacheDispatcher;
executionContext = prevExecutionContext;
if (null !== workInProgress) return 0;
workInProgressRoot = null;
Expand All @@ -8038,7 +8026,7 @@ function performUnitOfWork(unitOfWork) {
var next = beginWork(unitOfWork.alternate, unitOfWork, entangledRenderLanes);
unitOfWork.memoizedProps = unitOfWork.pendingProps;
null === next ? completeUnitOfWork(unitOfWork) : (workInProgress = next);
ReactCurrentOwner.current = null;
ReactSharedInternals.owner = null;
}
function replaySuspendedUnitOfWork(unitOfWork) {
var current = unitOfWork.alternate;
Expand Down Expand Up @@ -8092,7 +8080,7 @@ function replaySuspendedUnitOfWork(unitOfWork) {
null === current
? completeUnitOfWork(unitOfWork)
: (workInProgress = current);
ReactCurrentOwner.current = null;
ReactSharedInternals.owner = null;
}
function throwAndUnwindWorkLoop(root, unitOfWork, thrownValue) {
resetContextDependencies();
Expand Down Expand Up @@ -8179,11 +8167,11 @@ function commitRoot(
didIncludeRenderPhaseUpdate,
spawnedLane
) {
var prevTransition = ReactCurrentBatchConfig.transition,
var prevTransition = ReactSharedInternals.T,
previousUpdateLanePriority = currentUpdatePriority;
try {
(currentUpdatePriority = 2),
(ReactCurrentBatchConfig.transition = null),
(ReactSharedInternals.T = null),
commitRootImpl(
root,
recoverableErrors,
Expand All @@ -8193,7 +8181,7 @@ function commitRoot(
spawnedLane
);
} finally {
(ReactCurrentBatchConfig.transition = prevTransition),
(ReactSharedInternals.T = prevTransition),
(currentUpdatePriority = previousUpdateLanePriority);
}
return null;
Expand Down Expand Up @@ -8240,21 +8228,21 @@ function commitRootImpl(
}));
transitions = 0 !== (finishedWork.flags & 15990);
if (0 !== (finishedWork.subtreeFlags & 15990) || transitions) {
transitions = ReactCurrentBatchConfig.transition;
ReactCurrentBatchConfig.transition = null;
transitions = ReactSharedInternals.T;
ReactSharedInternals.T = null;
spawnedLane = currentUpdatePriority;
currentUpdatePriority = 2;
var prevExecutionContext = executionContext;
executionContext |= 4;
ReactCurrentOwner.current = null;
ReactSharedInternals.owner = null;
commitBeforeMutationEffects(root, finishedWork);
commitMutationEffectsOnFiber(finishedWork, root);
root.current = finishedWork;
commitLayoutEffectOnFiber(root, finishedWork.alternate, finishedWork);
requestPaint();
executionContext = prevExecutionContext;
currentUpdatePriority = spawnedLane;
ReactCurrentBatchConfig.transition = transitions;
ReactSharedInternals.T = transitions;
} else root.current = finishedWork;
rootDoesHavePassiveEffects
? ((rootDoesHavePassiveEffects = !1),
Expand Down Expand Up @@ -8299,11 +8287,11 @@ function flushPassiveEffects() {
remainingLanes = pendingPassiveEffectsRemainingLanes;
pendingPassiveEffectsRemainingLanes = 0;
var renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes),
prevTransition = ReactCurrentBatchConfig.transition,
prevTransition = ReactSharedInternals.T,
previousPriority = currentUpdatePriority;
try {
currentUpdatePriority = 32 > renderPriority ? 32 : renderPriority;
ReactCurrentBatchConfig.transition = null;
ReactSharedInternals.T = null;
if (null === rootWithPendingPassiveEffects)
var JSCompiler_inline_result = !1;
else {
Expand Down Expand Up @@ -8338,7 +8326,7 @@ function flushPassiveEffects() {
return JSCompiler_inline_result;
} finally {
(currentUpdatePriority = previousPriority),
(ReactCurrentBatchConfig.transition = prevTransition),
(ReactSharedInternals.T = prevTransition),
releaseRootPooledCache(root, remainingLanes);
}
}
Expand Down Expand Up @@ -9153,10 +9141,10 @@ var devToolsConfig$jscomp$inline_1000 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "19.0.0-canary-0c75b31c",
version: "19.0.0-canary-3a10429d",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1222 = {
var internals$jscomp$inline_1221 = {
bundleType: devToolsConfig$jscomp$inline_1000.bundleType,
version: devToolsConfig$jscomp$inline_1000.version,
rendererPackageName: devToolsConfig$jscomp$inline_1000.rendererPackageName,
Expand All @@ -9170,7 +9158,7 @@ var internals$jscomp$inline_1222 = {
setErrorHandler: null,
setSuspenseHandler: null,
scheduleUpdate: null,
currentDispatcherRef: ReactSharedInternals.ReactCurrentDispatcher,
currentDispatcherRef: ReactSharedInternals,
findHostInstanceByFiber: function (fiber) {
fiber = findCurrentFiberUsingSlowPath(fiber);
fiber = null !== fiber ? findCurrentHostFiberImpl(fiber) : null;
Expand All @@ -9184,19 +9172,19 @@ var internals$jscomp$inline_1222 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-canary-0c75b31c"
reconcilerVersion: "19.0.0-canary-3a10429d"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1223 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
var hook$jscomp$inline_1222 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
if (
!hook$jscomp$inline_1223.isDisabled &&
hook$jscomp$inline_1223.supportsFiber
!hook$jscomp$inline_1222.isDisabled &&
hook$jscomp$inline_1222.supportsFiber
)
try {
(rendererID = hook$jscomp$inline_1223.inject(
internals$jscomp$inline_1222
(rendererID = hook$jscomp$inline_1222.inject(
internals$jscomp$inline_1221
)),
(injectedHook = hook$jscomp$inline_1223);
(injectedHook = hook$jscomp$inline_1222);
} catch (err) {}
}
exports._Scheduler = Scheduler;
Expand Down
Loading

0 comments on commit deede8d

Please sign in to comment.