Skip to content

Commit 05777ff

Browse files
authored
Setting transition pending flag shouldn't be part of a surrounding transition (#26243)
Fixes #26226. (Is this the right fix?)
1 parent 21f6dba commit 05777ff

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,4 +951,43 @@ 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([0, 'A true', 'B true', 1, 'A false', 'B false']);
991+
expect(root).toMatchRenderedOutput('1, A false, B false');
992+
});
954993
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy