Skip to content

Commit

Permalink
(Land #28798) Move Current Owner (and Cache) to an Async Dispatcher (#…
Browse files Browse the repository at this point in the history
…28912)

Rebasing and landing #28798

This PR was approved already but held back to give time for the sync.
Rebased and landing here without pushing to seb's remote to avoid
possibility of lost updates

---------

Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>

DiffTrain build for commit 94eed63.
  • Loading branch information
gnoff committed Apr 25, 2024
1 parent 3a8adbf commit e4c6e4a
Show file tree
Hide file tree
Showing 17 changed files with 425 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<c3ec935f7569a8a6d52e0966b2837ffe>>
* @generated SignedSource<<000c06a477839c734ee52d10d49394b6>>
*/

'use strict';
Expand Down Expand Up @@ -562,6 +562,11 @@ var PassiveMask = Passive$1 | Visibility | ChildDeletion; // Union of tags that

var StaticMask = LayoutStatic | PassiveStatic | RefStatic | MaySuspendCommit;

var currentOwner = null;
function setCurrentOwner(fiber) {
currentOwner = fiber;
}

function getNearestMountedFiber(fiber) {
var node = fiber;
var nearestMounted = fiber;
Expand Down Expand Up @@ -605,7 +610,7 @@ function isFiberMounted(fiber) {
}
function isMounted(component) {
{
var owner = ReactSharedInternals.owner;
var owner = currentOwner;

if (owner !== null && owner.tag === ClassComponent) {
var ownerFiber = owner;
Expand Down Expand Up @@ -11897,7 +11902,7 @@ function updateForwardRef(current, workInProgress, Component, nextProps, renderL
}

{
ReactSharedInternals.owner = workInProgress;
setCurrentOwner(workInProgress);
setIsRendering(true);
nextChildren = renderWithHooks(current, workInProgress, render, propsWithoutRef, ref, renderLanes);
setIsRendering(false);
Expand Down Expand Up @@ -12380,7 +12385,7 @@ function updateFunctionComponent(current, workInProgress, Component, nextProps,
}

{
ReactSharedInternals.owner = workInProgress;
setCurrentOwner(workInProgress);
setIsRendering(true);
nextChildren = renderWithHooks(current, workInProgress, Component, nextProps, context, renderLanes);
setIsRendering(false);
Expand Down Expand Up @@ -12532,7 +12537,7 @@ function finishClassComponent(current, workInProgress, Component, shouldUpdate,
var instance = workInProgress.stateNode; // Rerender

{
ReactSharedInternals.owner = workInProgress;
setCurrentOwner(workInProgress);
}

var nextChildren;
Expand Down Expand Up @@ -13851,7 +13856,7 @@ function updateContextConsumer(current, workInProgress, renderLanes) {
var newChildren;

{
ReactSharedInternals.owner = workInProgress;
setCurrentOwner(workInProgress);
setIsRendering(true);
newChildren = render(newValue);
setIsRendering(false);
Expand Down Expand Up @@ -19158,10 +19163,16 @@ function getCacheForType(resourceType) {
return cacheForType;
}

var DefaultCacheDispatcher = {
var DefaultAsyncDispatcher = {
getCacheForType: getCacheForType
};

{
DefaultAsyncDispatcher.getOwner = function () {
return currentOwner;
};
}

if (typeof Symbol === 'function' && Symbol.for) {
var symbolFor = Symbol.for;
symbolFor('selector.component');
Expand Down Expand Up @@ -20114,7 +20125,7 @@ function handleThrow(root, thrownValue) {
resetCurrentFiber();

{
ReactSharedInternals.owner = null;
setCurrentOwner(null);
}

if (thrownValue === SuspenseException) {
Expand Down Expand Up @@ -20270,17 +20281,17 @@ function popDispatcher(prevDispatcher) {
ReactSharedInternals.H = prevDispatcher;
}

function pushCacheDispatcher() {
function pushAsyncDispatcher() {
{
var prevCacheDispatcher = ReactSharedInternals.C;
ReactSharedInternals.C = DefaultCacheDispatcher;
return prevCacheDispatcher;
var prevAsyncDispatcher = ReactSharedInternals.A;
ReactSharedInternals.A = DefaultAsyncDispatcher;
return prevAsyncDispatcher;
}
}

function popCacheDispatcher(prevCacheDispatcher) {
function popAsyncDispatcher(prevAsyncDispatcher) {
{
ReactSharedInternals.C = prevCacheDispatcher;
ReactSharedInternals.A = prevAsyncDispatcher;
}
}

Expand Down Expand Up @@ -20338,7 +20349,7 @@ function renderRootSync(root, lanes) {
var prevExecutionContext = executionContext;
executionContext |= RenderContext;
var prevDispatcher = pushDispatcher();
var prevCacheDispatcher = pushCacheDispatcher(); // If the root or lanes have changed, throw out the existing stack
var prevAsyncDispatcher = pushAsyncDispatcher(); // If the root or lanes have changed, throw out the existing stack
// and prepare a fresh one. Otherwise we'll continue where we left off.

if (workInProgressRoot !== root || workInProgressRootRenderLanes !== lanes) {
Expand Down Expand Up @@ -20418,7 +20429,7 @@ function renderRootSync(root, lanes) {
resetContextDependencies();
executionContext = prevExecutionContext;
popDispatcher(prevDispatcher);
popCacheDispatcher(prevCacheDispatcher);
popAsyncDispatcher(prevAsyncDispatcher);

if (workInProgress !== null) {
// This is a sync render, so we should have finished the whole tree.
Expand Down Expand Up @@ -20451,7 +20462,7 @@ function renderRootConcurrent(root, lanes) {
var prevExecutionContext = executionContext;
executionContext |= RenderContext;
var prevDispatcher = pushDispatcher();
var prevCacheDispatcher = pushCacheDispatcher(); // If the root or lanes have changed, throw out the existing stack
var prevAsyncDispatcher = pushAsyncDispatcher(); // If the root or lanes have changed, throw out the existing stack
// and prepare a fresh one. Otherwise we'll continue where we left off.

if (workInProgressRoot !== root || workInProgressRootRenderLanes !== lanes) {
Expand Down Expand Up @@ -20664,7 +20675,7 @@ function renderRootConcurrent(root, lanes) {

resetContextDependencies();
popDispatcher(prevDispatcher);
popCacheDispatcher(prevCacheDispatcher);
popAsyncDispatcher(prevAsyncDispatcher);
executionContext = prevExecutionContext;


Expand Down Expand Up @@ -20728,7 +20739,7 @@ function performUnitOfWork(unitOfWork) {
}

{
ReactSharedInternals.owner = null;
setCurrentOwner(null);
}
}

Expand Down Expand Up @@ -20828,7 +20839,7 @@ function replaySuspendedUnitOfWork(unitOfWork) {
}

{
ReactSharedInternals.owner = null;
setCurrentOwner(null);
}
}

Expand Down Expand Up @@ -21156,7 +21167,7 @@ function commitRootImpl(root, recoverableErrors, transitions, didIncludeRenderPh
executionContext |= CommitContext; // Reset this to null before calling lifecycles

{
ReactSharedInternals.owner = null;
setCurrentOwner(null);
} // The commit phase is broken into several sub-phases. We do a separate pass
// of the effect list for each phase: all mutation effects come before all
// layout effects, and so on.
Expand Down Expand Up @@ -22978,7 +22989,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
return root;
}

var ReactVersion = '19.0.0-beta-6e32de0b';
var ReactVersion = '19.0.0-beta-fd8f46d6';

/*
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol
Expand Down
Loading

0 comments on commit e4c6e4a

Please sign in to comment.