Skip to content

[Transition Tracing] Fix excess calls to the transition start callback #24806

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

Merged
merged 2 commits into from
Jun 29, 2022
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
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberLane.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,9 @@ export function addTransitionToLanesMap(
const index = laneToIndex(lane);
let transitions = transitionLanesMap[index];
if (transitions === null) {
transitions = [];
transitions = new Set();
}
transitions.push(transition);
transitions.add(transition);

transitionLanesMap[index] = transitions;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberLane.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,9 @@ export function addTransitionToLanesMap(
const index = laneToIndex(lane);
let transitions = transitionLanesMap[index];
if (transitions === null) {
transitions = [];
transitions = new Set();
}
transitions.push(transition);
transitions.add(transition);

transitionLanesMap[index] = transitions;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactInternalTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export type TransitionTracingCallbacks = {
// The following fields are only used in transition tracing in Profile builds
type TransitionTracingOnlyFiberRootProperties = {|
transitionCallbacks: null | TransitionTracingCallbacks,
transitionLanes: Array<Array<Transition> | null>,
transitionLanes: Array<Set<Transition> | null>,
// Transitions on the root can be represented as a bunch of tracing markers.
// Each entangled group of transitions can be treated as a tracing marker.
// It will have a set of pending suspense boundaries. These transitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,69 @@ describe('ReactInteractionTracing', () => {
});
});

// @gate enableTransitionTracing
it('multiple updates in transition callback should only result in one transitionStart/transitionComplete call', async () => {
const transitionCallbacks = {
onTransitionStart: (name, startTime) => {
Scheduler.unstable_yieldValue(
`onTransitionStart(${name}, ${startTime})`,
);
},
onTransitionComplete: (name, startTime, endTime) => {
Scheduler.unstable_yieldValue(
`onTransitionComplete(${name}, ${startTime}, ${endTime})`,
);
},
};

let navigateToPageTwo;
let setText;
function App() {
const [navigate, setNavigate] = useState(false);
const [text, _setText] = useState('hide');
navigateToPageTwo = () => setNavigate(true);
setText = () => _setText('show');

return (
<div>
{navigate ? (
<Text text={`Page Two: ${text}`} />
) : (
<Text text={`Page One: ${text}`} />
)}
</div>
);
}

const root = ReactNoop.createRoot({transitionCallbacks});
await act(async () => {
root.render(<App />);
ReactNoop.expire(1000);
await advanceTimers(1000);

expect(Scheduler).toFlushAndYield(['Page One: hide']);

await act(async () => {
startTransition(
() => {
navigateToPageTwo();
setText();
},
{name: 'page transition'},
);

ReactNoop.expire(1000);
await advanceTimers(1000);

expect(Scheduler).toFlushAndYield([
'Page Two: show',
'onTransitionStart(page transition, 1000)',
'onTransitionComplete(page transition, 1000, 2000)',
]);
});
});
});

// @gate enableTransitionTracing
it('should correctly trace interactions for async roots', async () => {
const transitionCallbacks = {
Expand Down