Skip to content

Commit

Permalink
Add test starting from hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii authored and acdlite committed Jun 1, 2021
1 parent bfea047 commit 129640c
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion packages/react-reconciler/src/__tests__/ReactOffscreen-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('ReactOffscreen', () => {

// @gate experimental
// @gate enableSuspenseLayoutEffectSemantics
it('mounts/unmounts layout effects when visibility changes', async () => {
it('mounts/unmounts layout effects when visibility changes (starting visible)', async () => {
function Child({text}) {
useLayoutEffect(() => {
Scheduler.unstable_yieldValue('Mount layout');
Expand Down Expand Up @@ -265,4 +265,58 @@ describe('ReactOffscreen', () => {
expect(Scheduler).toHaveYielded(['Child', 'Mount layout']);
expect(root).toMatchRenderedOutput(<span prop="Child" />);
});

// @gate experimental
// @gate enableSuspenseLayoutEffectSemantics
it('mounts/unmounts layout effects when visibility changes (starting hidden)', async () => {
function Child({text}) {
useLayoutEffect(() => {
Scheduler.unstable_yieldValue('Mount layout');
return () => {
Scheduler.unstable_yieldValue('Unmount layout');
};
}, []);
return <Text text="Child" />;
}

const root = ReactNoop.createRoot();
await ReactNoop.act(async () => {
// Start the tree hidden. The layout effect is not mounted.
root.render(
<Offscreen mode="hidden">
<Child />
</Offscreen>,
);
});
expect(Scheduler).toHaveYielded(['Child']);
// TODO: Offscreen does not yet hide/unhide children correctly. Until we do,
// it should only be used inside a host component wrapper whose visibility
// is toggled simultaneously.
expect(root).toMatchRenderedOutput(<span prop="Child" />);

// Show the tree. The layout effect is mounted.
await ReactNoop.act(async () => {
root.render(
<Offscreen mode="visible">
<Child />
</Offscreen>,
);
});
expect(Scheduler).toHaveYielded(['Child', 'Mount layout']);
expect(root).toMatchRenderedOutput(<span prop="Child" />);

// Hide the tree again. The layout effect is un-mounted.
await ReactNoop.act(async () => {
root.render(
<Offscreen mode="hidden">
<Child />
</Offscreen>,
);
});
expect(Scheduler).toHaveYielded(['Unmount layout', 'Child']);
// TODO: Offscreen does not yet hide/unhide children correctly. Until we do,
// it should only be used inside a host component wrapper whose visibility
// is toggled simultaneously.
expect(root).toMatchRenderedOutput(<span prop="Child" />);
});
});

0 comments on commit 129640c

Please sign in to comment.