Skip to content

Commit a10a9a6

Browse files
authored
Add test for hiding children after layout destroy (#24483)
1 parent b4eb0ad commit a10a9a6

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎packages/react-reconciler/src/__tests__/ReactOffscreen-test.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,47 @@ describe('ReactOffscreen', () => {
310310
expect(root).toMatchRenderedOutput(<spanhidden={true}prop="Child"/>);
311311
});
312312

313+
// @gate experimental || www
314+
// @gate enableSuspenseLayoutEffectSemantics
315+
// @gate enableFlipOffscreenUnhideOrder
316+
it('hides children of offscreen after layout effects are destroyed',async()=>{
317+
constroot=ReactNoop.createRoot();
318+
functionChild({text}){
319+
useLayoutEffect(()=>{
320+
Scheduler.unstable_yieldValue('Mount layout');
321+
return()=>{
322+
// The child should not be hidden yet.
323+
expect(root).toMatchRenderedOutput(<spanprop="Child"/>);
324+
Scheduler.unstable_yieldValue('Unmount layout');
325+
};
326+
},[]);
327+
return<Texttext="Child"/>;
328+
}
329+
330+
awaitact(async()=>{
331+
root.render(
332+
<Offscreenmode="visible">
333+
<Child/>
334+
</Offscreen>,
335+
);
336+
});
337+
expect(Scheduler).toHaveYielded(['Child','Mount layout']);
338+
expect(root).toMatchRenderedOutput(<spanprop="Child"/>);
339+
340+
// Hide the tree. The layout effect is unmounted.
341+
awaitact(async()=>{
342+
root.render(
343+
<Offscreenmode="hidden">
344+
<Child/>
345+
</Offscreen>,
346+
);
347+
});
348+
expect(Scheduler).toHaveYielded(['Unmount layout','Child']);
349+
350+
// After the layout effect is unmounted, the child is hidden.
351+
expect(root).toMatchRenderedOutput(<spanhidden={true}prop="Child"/>);
352+
});
353+
313354
// @gate www
314355
it('does not toggle effects for LegacyHidden component',async()=>{
315356
// LegacyHidden is meant to be the same as offscreen except it doesn't

‎packages/shared/ReactFeatureFlags.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const skipUnmountedBoundaries = true;
3838
//
3939
// TODO: Finish rolling out in www
4040
exportconstenableSuspenseLayoutEffectSemantics=true;
41-
exportconstenableFlipOffscreenUnhideOrder=false;
41+
exportconstenableFlipOffscreenUnhideOrder=true;
4242

4343
// TODO: Finish rolling out in www
4444
exportconstenableClientRenderFallbackOnTextMismatch=true;

0 commit comments

Comments
 (0)