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

[Transition Tracing] Don't call transition callbacks if no transition name specified #24887

Merged
merged 3 commits into from
Jul 11, 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
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ export function scheduleUpdateOnFiber(

if (enableTransitionTracing) {
const transition = ReactCurrentBatchConfig.transition;
if (transition !== null) {
if (transition !== null && transition.name != null) {
if (transition.startTime === -1) {
transition.startTime = now();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ export function scheduleUpdateOnFiber(

if (enableTransitionTracing) {
const transition = ReactCurrentBatchConfig.transition;
if (transition !== null) {
if (transition !== null && transition.name != null) {
if (transition.startTime === -1) {
transition.startTime = now();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,87 @@ describe('ReactInteractionTracing', () => {
return Promise.resolve().then(() => {});
}

// @gate enableTransitionTracing
it(' should not call callbacks when transition is not defined', async () => {
const transitionCallbacks = {
onTransitionStart: (name, startTime) => {
Scheduler.unstable_yieldValue(
`onTransitionStart(${name}, ${startTime})`,
);
},
onTransitionProgress: (name, startTime, endTime, pending) => {
const suspenseNames = pending.map(p => p.name || '<null>').join(', ');
Scheduler.unstable_yieldValue(
`onTransitionProgress(${name}, ${startTime}, ${endTime}, [${suspenseNames}])`,
);
},
onTransitionComplete: (name, startTime, endTime) => {
Scheduler.unstable_yieldValue(
`onTransitionComplete(${name}, ${startTime}, ${endTime})`,
);
},
onMarkerProgress: (
transitioName,
markerName,
startTime,
currentTime,
pending,
) => {
const suspenseNames = pending.map(p => p.name || '<null>').join(', ');
Scheduler.unstable_yieldValue(
`onMarkerProgress(${transitioName}, ${markerName}, ${startTime}, ${currentTime}, [${suspenseNames}])`,
);
},
onMarkerComplete: (transitioName, markerName, startTime, endTime) => {
Scheduler.unstable_yieldValue(
`onMarkerComplete(${transitioName}, ${markerName}, ${startTime}, ${endTime})`,
);
},
};

function App({navigate}) {
return (
<div>
{navigate ? (
<React.unstable_TracingMarker name="marker">
<Text text="Page Two" />
</React.unstable_TracingMarker>
) : (
<Text text="Page One" />
)}
</div>
);
}

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

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

await act(async () => {
startTransition(() => root.render(<App navigate={true} />));

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

// Doesn't call transition or marker code
expect(Scheduler).toFlushAndYield(['Page Two']);

startTransition(() => root.render(<App navigate={false} />), {
name: 'transition',
});
expect(Scheduler).toFlushAndYield([
'Page One',
'onTransitionStart(transition, 2000)',
'onTransitionComplete(transition, 2000, 2000)',
]);
});
});
});

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