Skip to content

Commit

Permalink
Add test gate alias for Offscreen (#24749)
Browse files Browse the repository at this point in the history
Offscreen is only enabled in the www and experimental channels. Instead
of listing these on every Offscreen test, I added a test gate alias
called `enableOffscreen`. Makes it easier to grep for these, and edit or
remove the channels later.
  • Loading branch information
acdlite authored Jun 30, 2022
1 parent 6b6cf83 commit a7b192e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
21 changes: 10 additions & 11 deletions packages/react-reconciler/src/__tests__/ReactOffscreen-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('ReactOffscreen', () => {
return <span prop={props.text} />;
}

// @gate www
// @gate enableLegacyHidden
it('unstable-defer-without-hiding should never toggle the visibility of its children', async () => {
function App({mode}) {
return (
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('ReactOffscreen', () => {
);
});

// @gate experimental || www
// @gate enableOffscreen
it('mounts without layout effects when hidden', async () => {
function Child({text}) {
useLayoutEffect(() => {
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('ReactOffscreen', () => {
expect(root).toMatchRenderedOutput(<span prop="Child" />);
});

// @gate experimental || www
// @gate enableOffscreen
it('mounts/unmounts layout effects when visibility changes (starting visible)', async () => {
function Child({text}) {
useLayoutEffect(() => {
Expand Down Expand Up @@ -264,7 +264,7 @@ describe('ReactOffscreen', () => {
expect(root).toMatchRenderedOutput(<span prop="Child" />);
});

// @gate experimental || www
// @gate enableOffscreen
it('mounts/unmounts layout effects when visibility changes (starting hidden)', async () => {
function Child({text}) {
useLayoutEffect(() => {
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('ReactOffscreen', () => {
expect(root).toMatchRenderedOutput(<span hidden={true} prop="Child" />);
});

// @gate experimental || www
// @gate enableOffscreen
it('hides children of offscreen after layout effects are destroyed', async () => {
const root = ReactNoop.createRoot();
function Child({text}) {
Expand Down Expand Up @@ -350,7 +350,7 @@ describe('ReactOffscreen', () => {
expect(root).toMatchRenderedOutput(<span hidden={true} prop="Child" />);
});

// @gate www
// @gate enableLegacyHidden
it('does not toggle effects for LegacyHidden component', async () => {
// LegacyHidden is meant to be the same as offscreen except it doesn't
// do anything to effects. Only used by www, as a temporary migration step.
Expand Down Expand Up @@ -398,7 +398,7 @@ describe('ReactOffscreen', () => {
expect(Scheduler).toHaveYielded(['Unmount layout']);
});

// @gate experimental || www
// @gate enableOffscreen
it('hides new insertions into an already hidden tree', async () => {
const root = ReactNoop.createRoot();
await act(async () => {
Expand Down Expand Up @@ -428,7 +428,7 @@ describe('ReactOffscreen', () => {
);
});

// @gate experimental || www
// @gate enableOffscreen
it('hides updated nodes inside an already hidden tree', async () => {
const root = ReactNoop.createRoot();
await act(async () => {
Expand Down Expand Up @@ -474,7 +474,7 @@ describe('ReactOffscreen', () => {
expect(root).toMatchRenderedOutput(<span>Hi</span>);
});

// @gate experimental || www
// @gate enableOffscreen
it('revealing a hidden tree at high priority does not cause tearing', async () => {
// When revealing an offscreen tree, we need to include updates that were
// previously deferred because the tree was hidden, even if they are lower
Expand Down Expand Up @@ -593,8 +593,7 @@ describe('ReactOffscreen', () => {
);
});

// TODO: Create TestFlag alias for Offscreen
// @gate experimental || www
// @gate enableOffscreen
it('regression: Offscreen instance is sometimes null during setState', async () => {
let setState;
function Child() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('ReactOffscreen', () => {
return text;
}

// @gate experimental || www
// @gate enableOffscreen
test('detect updates to a hidden tree during a concurrent event', async () => {
// This is a pretty complex test case. It relates to how we detect if an
// update is made to a hidden tree: when scheduling the update, we walk up
Expand Down
2 changes: 2 additions & 0 deletions scripts/jest/TestFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ function getTestFlags() {
// This isn't a flag, just a useful alias for tests.
enableUseSyncExternalStoreShim: !__VARIANT__,
enableSuspenseList: releaseChannel === 'experimental' || www,
enableOffscreen: releaseChannel === 'experimental' || www,
enableLegacyHidden: www,

// If there's a naming conflict between scheduler and React feature flags, the
// React ones take precedence.
Expand Down

0 comments on commit a7b192e

Please sign in to comment.