Skip to content

Commit 65237a2

Browse files
authored
Codemod it.experimental to gate pragma (facebook#18582)
* Codemod it.experimental to gate pragma Find-and-replace followed by Prettier * Delete it.experimental Removes the API from our test setup script
1 parent 42d7c2e commit 65237a2

20 files changed

+1194
-1246
lines changed

packages/react-dom/src/__tests__/ReactDOMFiberAsync-test.js

Lines changed: 230 additions & 236 deletions
Large diffs are not rendered by default.

packages/react-dom/src/__tests__/ReactDOMHooks-test.js

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -105,41 +105,39 @@ describe('ReactDOMHooks', () => {
105105
expect(labelRef.current.innerHTML).toBe('abc');
106106
});
107107

108-
it.experimental(
109-
'should not bail out when an update is scheduled from within an event handler in Concurrent Mode',
110-
() => {
111-
const {createRef, useCallback, useState} = React;
112-
113-
const Example = ({inputRef, labelRef}) => {
114-
const [text, setText] = useState('');
115-
const handleInput = useCallback(event => {
116-
setText(event.target.value);
117-
});
118-
119-
return (
120-
<>
121-
<input ref={inputRef} onInput={handleInput} />
122-
<label ref={labelRef}>{text}</label>
123-
</>
124-
);
125-
};
126-
127-
const inputRef = createRef();
128-
const labelRef = createRef();
129-
130-
const root = ReactDOM.createRoot(container);
131-
root.render(<Example inputRef={inputRef} labelRef={labelRef} />);
132-
133-
Scheduler.unstable_flushAll();
134-
135-
inputRef.current.value = 'abc';
136-
inputRef.current.dispatchEvent(
137-
new Event('input', {bubbles: true, cancelable: true}),
108+
// @gate experimental
109+
it('should not bail out when an update is scheduled from within an event handler in Concurrent Mode', () => {
110+
const {createRef, useCallback, useState} = React;
111+
112+
const Example = ({inputRef, labelRef}) => {
113+
const [text, setText] = useState('');
114+
const handleInput = useCallback(event => {
115+
setText(event.target.value);
116+
});
117+
118+
return (
119+
<>
120+
<input ref={inputRef} onInput={handleInput} />
121+
<label ref={labelRef}>{text}</label>
122+
</>
138123
);
124+
};
139125

140-
Scheduler.unstable_flushAll();
126+
const inputRef = createRef();
127+
const labelRef = createRef();
128+
129+
const root = ReactDOM.createRoot(container);
130+
root.render(<Example inputRef={inputRef} labelRef={labelRef} />);
131+
132+
Scheduler.unstable_flushAll();
133+
134+
inputRef.current.value = 'abc';
135+
inputRef.current.dispatchEvent(
136+
new Event('input', {bubbles: true, cancelable: true}),
137+
);
141138

142-
expect(labelRef.current.innerHTML).toBe('abc');
143-
},
144-
);
139+
Scheduler.unstable_flushAll();
140+
141+
expect(labelRef.current.innerHTML).toBe('abc');
142+
});
145143
});

packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -491,23 +491,21 @@ describe('ReactDOMServerHydration', () => {
491491
expect(element.textContent).toBe('Hello world');
492492
});
493493

494-
it.experimental(
495-
'does not re-enter hydration after committing the first one',
496-
() => {
497-
const finalHTML = ReactDOMServer.renderToString(<div />);
498-
const container = document.createElement('div');
499-
container.innerHTML = finalHTML;
500-
const root = ReactDOM.createRoot(container, {hydrate: true});
501-
root.render(<div />);
502-
Scheduler.unstable_flushAll();
503-
root.render(null);
504-
Scheduler.unstable_flushAll();
505-
// This should not reenter hydration state and therefore not trigger hydration
506-
// warnings.
507-
root.render(<div />);
508-
Scheduler.unstable_flushAll();
509-
},
510-
);
494+
// @gate experimental
495+
it('does not re-enter hydration after committing the first one', () => {
496+
const finalHTML = ReactDOMServer.renderToString(<div />);
497+
const container = document.createElement('div');
498+
container.innerHTML = finalHTML;
499+
const root = ReactDOM.createRoot(container, {hydrate: true});
500+
root.render(<div />);
501+
Scheduler.unstable_flushAll();
502+
root.render(null);
503+
Scheduler.unstable_flushAll();
504+
// This should not reenter hydration state and therefore not trigger hydration
505+
// warnings.
506+
root.render(<div />);
507+
Scheduler.unstable_flushAll();
508+
});
511509

512510
it('Suspense + hydration in legacy mode', () => {
513511
const element = document.createElement('div');

packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ describe('ReactTestUtils.act()', () => {
124124
]);
125125
});
126126

127-
it.experimental('warns in blocking mode', () => {
127+
// @gate experimental
128+
it('warns in blocking mode', () => {
128129
expect(() => {
129130
const root = ReactDOM.createBlockingRoot(document.createElement('div'));
130131
root.render(<App />);
@@ -134,7 +135,8 @@ describe('ReactTestUtils.act()', () => {
134135
]);
135136
});
136137

137-
it.experimental('warns in concurrent mode', () => {
138+
// @gate experimental
139+
it('warns in concurrent mode', () => {
138140
expect(() => {
139141
const root = ReactDOM.createRoot(document.createElement('div'));
140142
root.render(<App />);

packages/react-dom/src/__tests__/ReactUnmockedSchedulerWarning-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ it('does not warn when rendering in legacy mode', () => {
2727
}).toErrorDev([]);
2828
});
2929

30-
it.experimental('should warn when rendering in concurrent mode', () => {
30+
// @gate experimental
31+
it('should warn when rendering in concurrent mode', () => {
3132
expect(() => {
3233
ReactDOM.createRoot(document.createElement('div')).render(<App />);
3334
}).toErrorDev(
@@ -41,7 +42,8 @@ it.experimental('should warn when rendering in concurrent mode', () => {
4142
}).toErrorDev([]);
4243
});
4344

44-
it.experimental('should warn when rendering in blocking mode', () => {
45+
// @gate experimental
46+
it('should warn when rendering in blocking mode', () => {
4547
expect(() => {
4648
ReactDOM.createBlockingRoot(document.createElement('div')).render(<App />);
4749
}).toErrorDev(

packages/react-dom/src/__tests__/ReactUpdates-test.js

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,64 +1287,62 @@ describe('ReactUpdates', () => {
12871287
expect(ops).toEqual(['Foo', 'Bar', 'Baz']);
12881288
});
12891289

1290-
it.experimental(
1291-
'delays sync updates inside hidden subtrees in Concurrent Mode',
1292-
() => {
1293-
const container = document.createElement('div');
1294-
1295-
function Baz() {
1296-
Scheduler.unstable_yieldValue('Baz');
1297-
return <p>baz</p>;
1298-
}
1299-
1300-
let setCounter;
1301-
function Bar() {
1302-
const [counter, _setCounter] = React.useState(0);
1303-
setCounter = _setCounter;
1304-
Scheduler.unstable_yieldValue('Bar');
1305-
return <p>bar {counter}</p>;
1306-
}
1290+
// @gate experimental
1291+
it('delays sync updates inside hidden subtrees in Concurrent Mode', () => {
1292+
const container = document.createElement('div');
13071293

1308-
function Foo() {
1309-
Scheduler.unstable_yieldValue('Foo');
1310-
React.useEffect(() => {
1311-
Scheduler.unstable_yieldValue('Foo#effect');
1312-
});
1313-
return (
1314-
<div>
1315-
<div hidden={true}>
1316-
<Bar />
1317-
</div>
1318-
<Baz />
1319-
</div>
1320-
);
1321-
}
1294+
function Baz() {
1295+
Scheduler.unstable_yieldValue('Baz');
1296+
return <p>baz</p>;
1297+
}
13221298

1323-
const root = ReactDOM.createRoot(container);
1324-
let hiddenDiv;
1325-
act(() => {
1326-
root.render(<Foo />);
1327-
expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Baz', 'Foo#effect']);
1328-
hiddenDiv = container.firstChild.firstChild;
1329-
expect(hiddenDiv.hidden).toBe(true);
1330-
expect(hiddenDiv.innerHTML).toBe('');
1331-
// Run offscreen update
1332-
expect(Scheduler).toFlushAndYield(['Bar']);
1333-
expect(hiddenDiv.hidden).toBe(true);
1334-
expect(hiddenDiv.innerHTML).toBe('<p>bar 0</p>');
1335-
});
1299+
let setCounter;
1300+
function Bar() {
1301+
const [counter, _setCounter] = React.useState(0);
1302+
setCounter = _setCounter;
1303+
Scheduler.unstable_yieldValue('Bar');
1304+
return <p>bar {counter}</p>;
1305+
}
13361306

1337-
ReactDOM.flushSync(() => {
1338-
setCounter(1);
1307+
function Foo() {
1308+
Scheduler.unstable_yieldValue('Foo');
1309+
React.useEffect(() => {
1310+
Scheduler.unstable_yieldValue('Foo#effect');
13391311
});
1340-
// Should not flush yet
1341-
expect(hiddenDiv.innerHTML).toBe('<p>bar 0</p>');
1312+
return (
1313+
<div>
1314+
<div hidden={true}>
1315+
<Bar />
1316+
</div>
1317+
<Baz />
1318+
</div>
1319+
);
1320+
}
13421321

1322+
const root = ReactDOM.createRoot(container);
1323+
let hiddenDiv;
1324+
act(() => {
1325+
root.render(<Foo />);
1326+
expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Baz', 'Foo#effect']);
1327+
hiddenDiv = container.firstChild.firstChild;
1328+
expect(hiddenDiv.hidden).toBe(true);
1329+
expect(hiddenDiv.innerHTML).toBe('');
13431330
// Run offscreen update
13441331
expect(Scheduler).toFlushAndYield(['Bar']);
1345-
expect(hiddenDiv.innerHTML).toBe('<p>bar 1</p>');
1346-
},
1347-
);
1332+
expect(hiddenDiv.hidden).toBe(true);
1333+
expect(hiddenDiv.innerHTML).toBe('<p>bar 0</p>');
1334+
});
1335+
1336+
ReactDOM.flushSync(() => {
1337+
setCounter(1);
1338+
});
1339+
// Should not flush yet
1340+
expect(hiddenDiv.innerHTML).toBe('<p>bar 0</p>');
1341+
1342+
// Run offscreen update
1343+
expect(Scheduler).toFlushAndYield(['Bar']);
1344+
expect(hiddenDiv.innerHTML).toBe('<p>bar 1</p>');
1345+
});
13481346

13491347
it('can render ridiculously large number of roots without triggering infinite update loop error', () => {
13501348
class Foo extends React.Component {

0 commit comments

Comments
 (0)