Skip to content

Commit

Permalink
To reduce hidden class checks we need to read the batch config once w…
Browse files Browse the repository at this point in the history
…hich requires inlining the requestCurrentTransition implementation.
  • Loading branch information
gnoff committed Apr 1, 2024
1 parent 5306aa4 commit 8918e5f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
7 changes: 5 additions & 2 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ import {requestTransitionLane} from './ReactFiberRootScheduler';
import {isCurrentTreeHidden} from './ReactFiberHiddenContext';
import {
notifyTransitionCallbacks,
requestCurrentTransition,
registerTransitionUpdateHandler,
} from './ReactFiberTransition';

const {ReactCurrentDispatcher, ReactCurrentBatchConfig} = ReactSharedInternals;
Expand Down Expand Up @@ -3343,7 +3343,10 @@ function dispatchOptimisticSetState<S, A>(
queue: UpdateQueue<S, A>,
action: A,
): void {
const transition = requestCurrentTransition();
const transition = ReactCurrentBatchConfig.transition;
if (transition !== null) {
registerTransitionUpdateHandler(transition);
}

if (__DEV__) {
if (transition === null) {
Expand Down
16 changes: 5 additions & 11 deletions packages/react-reconciler/src/ReactFiberTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,15 @@ import {
CacheContext,
} from './ReactFiberCacheComponent';

import ReactSharedInternals from 'shared/ReactSharedInternals';
import {entangleAsyncAction} from './ReactFiberAsyncAction';

const {ReactCurrentBatchConfig} = ReactSharedInternals;

export const NoTransition = null;

export function requestCurrentTransition(): BatchConfigTransition | null {
const transition = ReactCurrentBatchConfig.transition;
if (transition !== null) {
// Whenever a transition update is scheduled, register a callback on the
// transition object so we can get the return value of the scope function.
transition._callbacks.add(handleAsyncAction);
}
return transition;
export function registerTransitionUpdateHandler(
transition: BatchConfigTransition,
) {
// $FlowFixMe[incompatible-call]: Thenable<mixed> is not compatible with mixed. Previously this was anytyped so it was always a type error just hidden
transition._callbacks.add(handleAsyncAction);
}

function handleAsyncAction(
Expand Down
16 changes: 9 additions & 7 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ import {
lowerEventPriority,
lanesToEventPriority,
} from './ReactEventPriorities';
import {requestCurrentTransition} from './ReactFiberTransition';
import {registerTransitionUpdateHandler} from './ReactFiberTransition';
import {
SelectiveHydrationException,
beginWork,
Expand Down Expand Up @@ -621,17 +621,19 @@ export function requestUpdateLane(fiber: Fiber): Lane {
return pickArbitraryLane(workInProgressRootRenderLanes);
}

const transition = requestCurrentTransition();
const transition = ReactCurrentBatchConfig.transition;
const eventPriority = ReactCurrentBatchConfig.eventPriority;

if (transition !== null) {
if (__DEV__) {
const batchConfigTransition = ReactCurrentBatchConfig.transition;
if (!batchConfigTransition._updatedFibers) {
batchConfigTransition._updatedFibers = new Set();
if (!transition._updatedFibers) {
transition._updatedFibers = new Set();
}

batchConfigTransition._updatedFibers.add(fiber);
transition._updatedFibers.add(fiber);
}

registerTransitionUpdateHandler(transition);
const actionScopeLane = peekEntangledActionLane();
return actionScopeLane !== NoLane
? // We're inside an async action scope. Reuse the same lane.
Expand All @@ -644,7 +646,7 @@ export function requestUpdateLane(fiber: Fiber): Lane {

// If there is an eventPriority scoped to React's internals we use it.
// The opaque type used for EventPriority matches the Lane so we cast it
let updateLane: Lane = (ReactCurrentBatchConfig.eventPriority: any);
let updateLane: Lane = (eventPriority: any);
if (updateLane !== NoLane) {
return updateLane;
}
Expand Down

0 comments on commit 8918e5f

Please sign in to comment.