Skip to content

Commit 4017121

Browse files
committed
Setting transition pending flag shouldn't be part of a surrounding transition
Fixes #26226. (Is this the right fix?)
1 parent 99aa082 commit 4017121

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,11 +2389,11 @@ function startTransition(
23892389
higherEventPriority(previousPriority, ContinuousEventPriority),
23902390
);
23912391

2392-
setPending(true);
2393-
23942392
const prevTransition = ReactCurrentBatchConfig.transition;
2395-
ReactCurrentBatchConfig.transition = ({}: BatchConfigTransition);
2396-
const currentTransition = ReactCurrentBatchConfig.transition;
2393+
ReactCurrentBatchConfig.transition = null;
2394+
setPending(true);
2395+
const currentTransition = (ReactCurrentBatchConfig.transition =
2396+
({}: BatchConfigTransition));
23972397

23982398
if (enableTransitionTracing) {
23992399
if (options !== undefined && options.name !== undefined) {

packages/react-reconciler/src/__tests__/ReactTransition-test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,4 +951,50 @@ describe('ReactTransition', () => {
951951

952952
expect(root).toMatchRenderedOutput('Transition pri: 1, Normal pri: 1');
953953
});
954+
955+
it('tracks two pending flags for nested startTransition (#26226)', async () => {
956+
let update;
957+
function App() {
958+
const [isPendingA, startTransitionA] = useTransition();
959+
const [isPendingB, startTransitionB] = useTransition();
960+
const [state, setState] = useState(0);
961+
962+
update = function () {
963+
startTransitionA(() => {
964+
startTransitionB(() => {
965+
setState(1);
966+
});
967+
});
968+
};
969+
970+
return (
971+
<>
972+
<Text text={state} />
973+
{', '}
974+
<Text text={'A ' + isPendingA} />
975+
{', '}
976+
<Text text={'B ' + isPendingB} />
977+
</>
978+
);
979+
}
980+
const root = ReactNoop.createRoot();
981+
await act(async () => {
982+
root.render(<App />);
983+
});
984+
assertLog([0, 'A false', 'B false']);
985+
expect(root).toMatchRenderedOutput('0, A false, B false');
986+
987+
await act(async () => {
988+
update();
989+
});
990+
assertLog([
991+
0,
992+
'A true',
993+
'B true',
994+
1,
995+
'A false',
996+
'B false',
997+
]);
998+
expect(root).toMatchRenderedOutput('1, A false, B false');
999+
});
9541000
});

0 commit comments

Comments
 (0)