Skip to content
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

Setting transition pending flag shouldn't be part of a surrounding transition #26243

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2389,11 +2389,11 @@ function startTransition(
higherEventPriority(previousPriority, ContinuousEventPriority),
);

setPending(true);

const prevTransition = ReactCurrentBatchConfig.transition;
ReactCurrentBatchConfig.transition = ({}: BatchConfigTransition);
const currentTransition = ReactCurrentBatchConfig.transition;
ReactCurrentBatchConfig.transition = null;
setPending(true);
const currentTransition = (ReactCurrentBatchConfig.transition =
({}: BatchConfigTransition));

if (enableTransitionTracing) {
if (options !== undefined && options.name !== undefined) {
Expand Down
39 changes: 39 additions & 0 deletions packages/react-reconciler/src/__tests__/ReactTransition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,4 +951,43 @@ describe('ReactTransition', () => {

expect(root).toMatchRenderedOutput('Transition pri: 1, Normal pri: 1');
});

it('tracks two pending flags for nested startTransition (#26226)', async () => {
let update;
function App() {
const [isPendingA, startTransitionA] = useTransition();
const [isPendingB, startTransitionB] = useTransition();
const [state, setState] = useState(0);

update = function () {
startTransitionA(() => {
startTransitionB(() => {
setState(1);
});
});
};

return (
<>
<Text text={state} />
{', '}
<Text text={'A ' + isPendingA} />
{', '}
<Text text={'B ' + isPendingB} />
</>
);
}
const root = ReactNoop.createRoot();
await act(async () => {
root.render(<App />);
});
assertLog([0, 'A false', 'B false']);
expect(root).toMatchRenderedOutput('0, A false, B false');

await act(async () => {
update();
});
assertLog([0, 'A true', 'B true', 1, 'A false', 'B false']);
expect(root).toMatchRenderedOutput('1, A false, B false');
});
});