Skip to content

Commit

Permalink
[Transition Tracing] Add Offscreen Test (#25035)
Browse files Browse the repository at this point in the history
Add a test to make sure offscreen trees don't stop transitions from completing.
  • Loading branch information
lunaruan authored Aug 3, 2022
1 parent 9fcaf88 commit e193be8
Showing 1 changed file with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let act;
let getCacheForType;
let useState;
let Suspense;
let Offscreen;
let startTransition;

let caches;
Expand All @@ -34,6 +35,7 @@ describe('ReactInteractionTracing', () => {
useState = React.useState;
startTransition = React.startTransition;
Suspense = React.Suspense;
Offscreen = React.unstable_Offscreen;

getCacheForType = React.unstable_getCacheForType;

Expand Down Expand Up @@ -1362,4 +1364,74 @@ describe('ReactInteractionTracing', () => {
]);
});
});

// @gate enableTransitionTracing
it('offscreen trees should not stop transition from completing', async () => {
const transitionCallbacks = {
onTransitionStart: (name, startTime) => {
Scheduler.unstable_yieldValue(
`onTransitionStart(${name}, ${startTime})`,
);
},
onTransitionComplete: (name, startTime, endTime) => {
Scheduler.unstable_yieldValue(
`onTransitionComplete(${name}, ${startTime}, ${endTime})`,
);
},
onMarkerComplete: (transitioName, markerName, startTime, endTime) => {
Scheduler.unstable_yieldValue(
`onMarkerComplete(${transitioName}, ${markerName}, ${startTime}, ${endTime})`,
);
},
};

function App() {
return (
<React.unstable_TracingMarker name="marker">
<Suspense fallback={<Text text="Loading..." />}>
<AsyncText text="Text" />
</Suspense>
<Offscreen mode="hidden">
<Suspense fallback={<Text text="Hidden Loading..." />}>
<AsyncText text="Hidden Text" />
</Suspense>
</Offscreen>
</React.unstable_TracingMarker>
);
}

const root = ReactNoop.createRoot({
unstable_transitionCallbacks: transitionCallbacks,
});
await act(() => {
startTransition(() => root.render(<App />), {name: 'transition'});
ReactNoop.expire(1000);
advanceTimers(1000);
});
expect(Scheduler).toHaveYielded([
'Suspend [Text]',
'Loading...',
'Suspend [Hidden Text]',
'Hidden Loading...',
'onTransitionStart(transition, 0)',
]);

await act(() => {
resolveText('Text');
ReactNoop.expire(1000);
advanceTimers(1000);
});
expect(Scheduler).toHaveYielded([
'Text',
'onMarkerComplete(transition, marker, 0, 2000)',
'onTransitionComplete(transition, 0, 2000)',
]);

await act(() => {
resolveText('Hidden Text');
ReactNoop.expire(1000);
advanceTimers(1000);
});
expect(Scheduler).toHaveYielded(['Hidden Text']);
});
});

0 comments on commit e193be8

Please sign in to comment.