Skip to content

[RFC] Label updates from setOptimistic per API #33451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,7 @@ function mountOptimistic<S, A>(
// This is different than the normal setState function.
const dispatch: A => void = (dispatchOptimisticSetState.bind(
null,
'setOptimistic()',
currentlyRenderingFiber,
true,
queue,
Expand Down Expand Up @@ -2398,6 +2399,7 @@ function mountActionState<S, P>(
const pendingStateHook = mountStateImpl((false: Thenable<boolean> | boolean));
const setPendingState: boolean => void = (dispatchOptimisticSetState.bind(
null,
'useActionState()',
currentlyRenderingFiber,
false,
((pendingStateHook.queue: any): UpdateQueue<
Expand Down Expand Up @@ -3117,7 +3119,7 @@ function startTransition<S>(
// diverges; for example, both an optimistic update and this one should
// share the same lane.
ReactSharedInternals.T = currentTransition;
dispatchOptimisticSetState(fiber, false, queue, pendingState);
dispatchOptimisticSetState('useTransition()', fiber, false, queue, pendingState);

try {
const returnValue = callback();
Expand Down Expand Up @@ -3682,6 +3684,7 @@ function dispatchSetStateInternal<S, A>(
}

function dispatchOptimisticSetState<S, A>(
label: string,
fiber: Fiber,
throwIfDuringRender: boolean,
queue: UpdateQueue<S, A>,
Expand Down Expand Up @@ -3766,7 +3769,7 @@ function dispatchOptimisticSetState<S, A>(
// will never be attempted before the optimistic update. This currently
// holds because the optimistic update is always synchronous. If we ever
// change that, we'll need to account for this.
startUpdateTimerByLane(lane, 'setOptimistic()');
startUpdateTimerByLane(lane, label);
scheduleUpdateOnFiber(root, fiber, lane);
// Optimistic updates are always synchronous, so we don't need to call
// entangleTransitionUpdate here.
Expand Down
Loading