mirror of
https://github.com/facebook/react.git
synced 2026-02-23 20:23:02 +00:00
Prefix mock Scheduler APIs with _unstable (#15999)
For now this is only meant to be consumed via `act`.
This commit is contained in:
@@ -60,7 +60,7 @@ describe('createSubscription', () => {
|
||||
ReactNoop.render(
|
||||
<Subscription source={observable}>
|
||||
{(value = 'default') => {
|
||||
Scheduler.yieldValue(value);
|
||||
Scheduler.unstable_yieldValue(value);
|
||||
return null;
|
||||
}}
|
||||
</Subscription>,
|
||||
@@ -97,7 +97,7 @@ describe('createSubscription', () => {
|
||||
});
|
||||
|
||||
function render(value = 'default') {
|
||||
Scheduler.yieldValue(value);
|
||||
Scheduler.unstable_yieldValue(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -126,9 +126,9 @@ describe('createSubscription', () => {
|
||||
|
||||
function render(hasLoaded) {
|
||||
if (hasLoaded === undefined) {
|
||||
Scheduler.yieldValue('loading');
|
||||
Scheduler.unstable_yieldValue('loading');
|
||||
} else {
|
||||
Scheduler.yieldValue(hasLoaded ? 'finished' : 'failed');
|
||||
Scheduler.unstable_yieldValue(hasLoaded ? 'finished' : 'failed');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -169,7 +169,7 @@ describe('createSubscription', () => {
|
||||
});
|
||||
|
||||
function render(value = 'default') {
|
||||
Scheduler.yieldValue(value);
|
||||
Scheduler.unstable_yieldValue(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ describe('createSubscription', () => {
|
||||
});
|
||||
|
||||
function render(hasLoaded) {
|
||||
Scheduler.yieldValue('rendered');
|
||||
Scheduler.unstable_yieldValue('rendered');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ describe('createSubscription', () => {
|
||||
});
|
||||
|
||||
function render(value = 'default') {
|
||||
Scheduler.yieldValue(value);
|
||||
Scheduler.unstable_yieldValue(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ describe('createSubscription', () => {
|
||||
const log = [];
|
||||
|
||||
function Child({value}) {
|
||||
Scheduler.yieldValue('Child: ' + value);
|
||||
Scheduler.unstable_yieldValue('Child: ' + value);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ describe('createSubscription', () => {
|
||||
return (
|
||||
<Subscription source={this.state.observed}>
|
||||
{(value = 'default') => {
|
||||
Scheduler.yieldValue('Subscriber: ' + value);
|
||||
Scheduler.unstable_yieldValue('Subscriber: ' + value);
|
||||
return <Child value={value} />;
|
||||
}}
|
||||
</Subscription>
|
||||
@@ -355,7 +355,7 @@ describe('createSubscription', () => {
|
||||
const log = [];
|
||||
|
||||
function Child({value}) {
|
||||
Scheduler.yieldValue('Child: ' + value);
|
||||
Scheduler.unstable_yieldValue('Child: ' + value);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ describe('createSubscription', () => {
|
||||
return (
|
||||
<Subscription source={this.state.observed}>
|
||||
{(value = 'default') => {
|
||||
Scheduler.yieldValue('Subscriber: ' + value);
|
||||
Scheduler.unstable_yieldValue('Subscriber: ' + value);
|
||||
return <Child value={value} />;
|
||||
}}
|
||||
</Subscription>
|
||||
|
||||
@@ -359,7 +359,7 @@ describe('ReactART', () => {
|
||||
const CurrentRendererContext = React.createContext(null);
|
||||
|
||||
function Yield(props) {
|
||||
Scheduler.yieldValue(props.value);
|
||||
Scheduler.unstable_yieldValue(props.value);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,12 +45,12 @@ describe('ReactCache', () => {
|
||||
listeners = [{resolve, reject}];
|
||||
setTimeout(() => {
|
||||
if (textResourceShouldFail) {
|
||||
Scheduler.yieldValue(`Promise rejected [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Promise rejected [${text}]`);
|
||||
status = 'rejected';
|
||||
value = new Error('Failed to load: ' + text);
|
||||
listeners.forEach(listener => listener.reject(value));
|
||||
} else {
|
||||
Scheduler.yieldValue(`Promise resolved [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Promise resolved [${text}]`);
|
||||
status = 'resolved';
|
||||
value = text;
|
||||
listeners.forEach(listener => listener.resolve(value));
|
||||
@@ -78,7 +78,7 @@ describe('ReactCache', () => {
|
||||
});
|
||||
|
||||
function Text(props) {
|
||||
Scheduler.yieldValue(props.text);
|
||||
Scheduler.unstable_yieldValue(props.text);
|
||||
return props.text;
|
||||
}
|
||||
|
||||
@@ -86,13 +86,13 @@ describe('ReactCache', () => {
|
||||
const text = props.text;
|
||||
try {
|
||||
TextResource.read([props.text, props.ms]);
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return text;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
@@ -156,7 +156,7 @@ describe('ReactCache', () => {
|
||||
});
|
||||
|
||||
function App() {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return BadTextResource.read(['Hi', 100]);
|
||||
}
|
||||
|
||||
@@ -321,13 +321,13 @@ describe('ReactCache', () => {
|
||||
const text = props.text;
|
||||
try {
|
||||
const actualText = BadTextResource.read([props.text, props.ms]);
|
||||
Scheduler.yieldValue(actualText);
|
||||
Scheduler.unstable_yieldValue(actualText);
|
||||
return actualText;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
|
||||
@@ -623,7 +623,7 @@ describe('ReactHooksInspectionIntegration', () => {
|
||||
|
||||
await LazyFoo;
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
let childFiber = renderer.root._currentFiber();
|
||||
let tree = ReactDebugTools.inspectHooksOfFiber(childFiber);
|
||||
|
||||
@@ -85,7 +85,7 @@ describe('ReactDOMFiberAsync', () => {
|
||||
}
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<Counter />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(asyncValueRef.current.textContent).toBe('');
|
||||
expect(syncValueRef.current.textContent).toBe('');
|
||||
|
||||
@@ -97,7 +97,7 @@ describe('ReactDOMFiberAsync', () => {
|
||||
|
||||
// Should flush both updates now.
|
||||
jest.runAllTimers();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(asyncValueRef.current.textContent).toBe('hello');
|
||||
expect(syncValueRef.current.textContent).toBe('hello');
|
||||
});
|
||||
@@ -115,12 +115,12 @@ describe('ReactDOMFiberAsync', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<div>Hi</div>);
|
||||
expect(container.textContent).toEqual('');
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('Hi');
|
||||
|
||||
root.render(<div>Bye</div>);
|
||||
expect(container.textContent).toEqual('Hi');
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('Bye');
|
||||
});
|
||||
|
||||
@@ -137,12 +137,12 @@ describe('ReactDOMFiberAsync', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<Component />);
|
||||
expect(container.textContent).toEqual('');
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('0');
|
||||
|
||||
instance.setState({step: 1});
|
||||
expect(container.textContent).toEqual('0');
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('1');
|
||||
});
|
||||
|
||||
@@ -264,7 +264,7 @@ describe('ReactDOMFiberAsync', () => {
|
||||
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<Component />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
// Updates are async by default
|
||||
instance.push('A');
|
||||
@@ -287,7 +287,7 @@ describe('ReactDOMFiberAsync', () => {
|
||||
expect(ops).toEqual(['BC']);
|
||||
|
||||
// Flush the async updates
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('ABCD');
|
||||
expect(ops).toEqual(['BC', 'ABCD']);
|
||||
});
|
||||
@@ -305,13 +305,13 @@ describe('ReactDOMFiberAsync', () => {
|
||||
}
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<Counter />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('0');
|
||||
|
||||
// Test that a normal update is async
|
||||
inst.increment();
|
||||
expect(container.textContent).toEqual('0');
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('1');
|
||||
|
||||
let ops = [];
|
||||
@@ -417,7 +417,7 @@ describe('ReactDOMFiberAsync', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<Form />);
|
||||
// Flush
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
let disableButton = disableButtonRef.current;
|
||||
expect(disableButton.tagName).toBe('BUTTON');
|
||||
@@ -484,7 +484,7 @@ describe('ReactDOMFiberAsync', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<Form />);
|
||||
// Flush
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
let disableButton = disableButtonRef.current;
|
||||
expect(disableButton.tagName).toBe('BUTTON');
|
||||
@@ -544,7 +544,7 @@ describe('ReactDOMFiberAsync', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<Form />);
|
||||
// Flush
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
let enableButton = enableButtonRef.current;
|
||||
expect(enableButton.tagName).toBe('BUTTON');
|
||||
@@ -576,7 +576,7 @@ describe('ReactDOMFiberAsync', () => {
|
||||
const root = ReactDOM.unstable_createSyncRoot(container);
|
||||
|
||||
function Text(props) {
|
||||
Scheduler.yieldValue(props.text);
|
||||
Scheduler.unstable_yieldValue(props.text);
|
||||
return props.text;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ describe('ReactDOMHooks', () => {
|
||||
expect(container.textContent).toBe('1');
|
||||
expect(container2.textContent).toBe('');
|
||||
expect(container3.textContent).toBe('');
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toBe('1');
|
||||
expect(container2.textContent).toBe('2');
|
||||
expect(container3.textContent).toBe('3');
|
||||
@@ -69,7 +69,7 @@ describe('ReactDOMHooks', () => {
|
||||
expect(container.textContent).toBe('2');
|
||||
expect(container2.textContent).toBe('2'); // Not flushed yet
|
||||
expect(container3.textContent).toBe('3'); // Not flushed yet
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toBe('2');
|
||||
expect(container2.textContent).toBe('4');
|
||||
expect(container3.textContent).toBe('6');
|
||||
@@ -137,14 +137,14 @@ describe('ReactDOMHooks', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<Example inputRef={inputRef} labelRef={labelRef} />);
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
inputRef.current.value = 'abc';
|
||||
inputRef.current.dispatchEvent(
|
||||
new Event('input', {bubbles: true, cancelable: true}),
|
||||
);
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
expect(labelRef.current.innerHTML).toBe('abc');
|
||||
});
|
||||
|
||||
@@ -29,17 +29,17 @@ describe('ReactDOMRoot', () => {
|
||||
it('renders children', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<div>Hi</div>);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('Hi');
|
||||
});
|
||||
|
||||
it('unmounts children', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<div>Hi</div>);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('Hi');
|
||||
root.unmount();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('');
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ describe('ReactDOMRoot', () => {
|
||||
ops.push('inside callback: ' + container.textContent);
|
||||
});
|
||||
ops.push('before committing: ' + container.textContent);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
ops.push('after committing: ' + container.textContent);
|
||||
expect(ops).toEqual([
|
||||
'before committing: ',
|
||||
@@ -64,7 +64,7 @@ describe('ReactDOMRoot', () => {
|
||||
it('resolves `work.then` callback synchronously if the work already committed', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
const work = root.render('Hi');
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
let ops = [];
|
||||
work.then(() => {
|
||||
ops.push('inside callback');
|
||||
@@ -92,7 +92,7 @@ describe('ReactDOMRoot', () => {
|
||||
<span />
|
||||
</div>,
|
||||
);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
// Accepts `hydrate` option
|
||||
const container2 = document.createElement('div');
|
||||
@@ -103,7 +103,7 @@ describe('ReactDOMRoot', () => {
|
||||
<span />
|
||||
</div>,
|
||||
);
|
||||
expect(() => Scheduler.flushAll()).toWarnDev('Extra attributes', {
|
||||
expect(() => Scheduler.unstable_flushAll()).toWarnDev('Extra attributes', {
|
||||
withoutStack: true,
|
||||
});
|
||||
});
|
||||
@@ -117,7 +117,7 @@ describe('ReactDOMRoot', () => {
|
||||
<span>d</span>
|
||||
</div>,
|
||||
);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('abcd');
|
||||
root.render(
|
||||
<div>
|
||||
@@ -125,7 +125,7 @@ describe('ReactDOMRoot', () => {
|
||||
<span>c</span>
|
||||
</div>,
|
||||
);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('abdc');
|
||||
});
|
||||
|
||||
@@ -157,7 +157,7 @@ describe('ReactDOMRoot', () => {
|
||||
const batch = root.createBatch();
|
||||
batch.render(<App />);
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
// Hasn't updated yet
|
||||
expect(container.textContent).toEqual('');
|
||||
@@ -186,7 +186,7 @@ describe('ReactDOMRoot', () => {
|
||||
const batch = root.createBatch();
|
||||
batch.render(<Foo>Hi</Foo>);
|
||||
// Flush all async work.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
// Root should complete without committing.
|
||||
expect(ops).toEqual(['Foo']);
|
||||
expect(container.textContent).toEqual('');
|
||||
@@ -204,7 +204,7 @@ describe('ReactDOMRoot', () => {
|
||||
const batch = root.createBatch();
|
||||
batch.render('Foo');
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
// Hasn't updated yet
|
||||
expect(container.textContent).toEqual('');
|
||||
@@ -244,7 +244,7 @@ describe('ReactDOMRoot', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(1);
|
||||
|
||||
Scheduler.advanceTime(2000);
|
||||
Scheduler.unstable_advanceTime(2000);
|
||||
// This batch has a later expiration time than the earlier update.
|
||||
const batch = root.createBatch();
|
||||
|
||||
@@ -252,7 +252,7 @@ describe('ReactDOMRoot', () => {
|
||||
batch.commit();
|
||||
expect(container.textContent).toEqual('');
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('1');
|
||||
});
|
||||
|
||||
@@ -279,7 +279,7 @@ describe('ReactDOMRoot', () => {
|
||||
batch1.render(1);
|
||||
|
||||
// This batch has a later expiration time
|
||||
Scheduler.advanceTime(2000);
|
||||
Scheduler.unstable_advanceTime(2000);
|
||||
const batch2 = root.createBatch();
|
||||
batch2.render(2);
|
||||
|
||||
@@ -298,7 +298,7 @@ describe('ReactDOMRoot', () => {
|
||||
batch1.render(1);
|
||||
|
||||
// This batch has a later expiration time
|
||||
Scheduler.advanceTime(2000);
|
||||
Scheduler.unstable_advanceTime(2000);
|
||||
const batch2 = root.createBatch();
|
||||
batch2.render(2);
|
||||
|
||||
@@ -308,7 +308,7 @@ describe('ReactDOMRoot', () => {
|
||||
expect(container.textContent).toEqual('2');
|
||||
|
||||
batch1.commit();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('1');
|
||||
});
|
||||
|
||||
@@ -334,7 +334,7 @@ describe('ReactDOMRoot', () => {
|
||||
it('warns when rendering with legacy API into createRoot() container', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<div>Hi</div>);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('Hi');
|
||||
expect(() => {
|
||||
ReactDOM.render(<div>Bye</div>, container);
|
||||
@@ -349,7 +349,7 @@ describe('ReactDOMRoot', () => {
|
||||
],
|
||||
{withoutStack: true},
|
||||
);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
// This works now but we could disallow it:
|
||||
expect(container.textContent).toEqual('Bye');
|
||||
});
|
||||
@@ -357,7 +357,7 @@ describe('ReactDOMRoot', () => {
|
||||
it('warns when hydrating with legacy API into createRoot() container', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<div>Hi</div>);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('Hi');
|
||||
expect(() => {
|
||||
ReactDOM.hydrate(<div>Hi</div>, container);
|
||||
@@ -377,7 +377,7 @@ describe('ReactDOMRoot', () => {
|
||||
it('warns when unmounting with legacy API (no previous content)', () => {
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<div>Hi</div>);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('Hi');
|
||||
let unmounted = false;
|
||||
expect(() => {
|
||||
@@ -393,10 +393,10 @@ describe('ReactDOMRoot', () => {
|
||||
{withoutStack: true},
|
||||
);
|
||||
expect(unmounted).toBe(false);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('Hi');
|
||||
root.unmount();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('');
|
||||
});
|
||||
|
||||
@@ -406,17 +406,17 @@ describe('ReactDOMRoot', () => {
|
||||
// The rest is the same as test above.
|
||||
const root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(<div>Hi</div>);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('Hi');
|
||||
let unmounted = false;
|
||||
expect(() => {
|
||||
unmounted = ReactDOM.unmountComponentAtNode(container);
|
||||
}).toWarnDev('Did you mean to call root.unmount()?', {withoutStack: true});
|
||||
expect(unmounted).toBe(false);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('Hi');
|
||||
root.unmount();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(container.textContent).toEqual('');
|
||||
});
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ let ReactTestUtils;
|
||||
let forwardRef;
|
||||
let memo;
|
||||
let yieldedValues;
|
||||
let yieldValue;
|
||||
let unstable_yieldValue;
|
||||
let clearYields;
|
||||
|
||||
function initModules() {
|
||||
@@ -32,7 +32,7 @@ function initModules() {
|
||||
memo = React.memo;
|
||||
|
||||
yieldedValues = [];
|
||||
yieldValue = value => {
|
||||
unstable_yieldValue = value => {
|
||||
yieldedValues.push(value);
|
||||
};
|
||||
clearYields = () => {
|
||||
@@ -92,7 +92,7 @@ describe('ReactDOMServerIntegration', () => {
|
||||
});
|
||||
|
||||
function Text({text}) {
|
||||
yieldValue(text);
|
||||
unstable_yieldValue(text);
|
||||
return <span>{text}</span>;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ describe('ReactDOMServerIntegration', () => {
|
||||
'comparator functions are not invoked on the server',
|
||||
async render => {
|
||||
const MemoCounter = React.memo(Counter, (oldProps, newProps) => {
|
||||
yieldValue(
|
||||
unstable_yieldValue(
|
||||
`Old count: ${oldProps.count}, New count: ${newProps.count}`,
|
||||
);
|
||||
return oldProps.count === newProps.count;
|
||||
|
||||
@@ -74,7 +74,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
suspend = true;
|
||||
let root = ReactDOM.unstable_createRoot(container, {hydrate: true});
|
||||
root.render(<App />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ref.current).toBe(null);
|
||||
@@ -83,7 +83,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
suspend = false;
|
||||
resolve();
|
||||
await promise;
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
// We should now have hydrated with a ref on the existing span.
|
||||
@@ -242,7 +242,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
suspend = true;
|
||||
let root = ReactDOM.unstable_createRoot(container, {hydrate: true});
|
||||
root.render(<App text="Hello" className="hello" />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ref.current).toBe(null);
|
||||
@@ -258,7 +258,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
|
||||
// Flushing both of these in the same batch won't be able to hydrate so we'll
|
||||
// probably throw away the existing subtree.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
// Pick up the new span. In an ideal implementation this might be the same span
|
||||
@@ -311,14 +311,14 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
suspend = true;
|
||||
let root = ReactDOM.unstable_createRoot(container, {hydrate: true});
|
||||
root.render(<App text="Hello" className="hello" />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ref.current).toBe(null);
|
||||
|
||||
// Render an update, but leave it still suspended.
|
||||
root.render(<App text="Hi" className="hi" />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
// Flushing now should delete the existing content and show the fallback.
|
||||
@@ -332,7 +332,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
resolve();
|
||||
await promise;
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
let span = container.getElementsByTagName('span')[0];
|
||||
@@ -384,7 +384,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
suspend = true;
|
||||
let root = ReactDOM.unstable_createRoot(container, {hydrate: true});
|
||||
root.render(<App text="Hello" className="hello" />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ref.current).toBe(null);
|
||||
@@ -393,7 +393,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
root.render(<App text="Hi" className="hi" />);
|
||||
|
||||
// Flushing now should delete the existing content and show the fallback.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(container.getElementsByTagName('span').length).toBe(0);
|
||||
@@ -405,7 +405,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
resolve();
|
||||
await promise;
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
let span = container.getElementsByTagName('span')[0];
|
||||
@@ -456,7 +456,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
suspend = true;
|
||||
let root = ReactDOM.unstable_createRoot(container, {hydrate: true});
|
||||
root.render(<App text="Hello" className="hello" />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ref.current).toBe(null);
|
||||
@@ -465,7 +465,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
root.render(<App text="Hi" className="hi" />);
|
||||
|
||||
// Flushing now should delete the existing content and show the fallback.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(container.getElementsByTagName('span').length).toBe(0);
|
||||
@@ -477,7 +477,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
resolve();
|
||||
await promise;
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
let span = container.getElementsByTagName('span')[0];
|
||||
@@ -537,7 +537,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
<App />
|
||||
</Context.Provider>,
|
||||
);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ref.current).toBe(null);
|
||||
@@ -557,7 +557,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
|
||||
// Flushing both of these in the same batch won't be able to hydrate so we'll
|
||||
// probably throw away the existing subtree.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
// Pick up the new span. In an ideal implementation this might be the same span
|
||||
@@ -620,7 +620,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
<App />
|
||||
</Context.Provider>,
|
||||
);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ref.current).toBe(null);
|
||||
@@ -633,7 +633,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
);
|
||||
|
||||
// Flushing now should delete the existing content and show the fallback.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(container.getElementsByTagName('span').length).toBe(0);
|
||||
@@ -645,7 +645,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
resolve();
|
||||
await promise;
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
let span = container.getElementsByTagName('span')[0];
|
||||
@@ -694,7 +694,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
suspend = false;
|
||||
let root = ReactDOM.unstable_createRoot(container, {hydrate: true});
|
||||
root.render(<App />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(container.textContent).toBe('Hello');
|
||||
@@ -750,7 +750,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
suspend = false;
|
||||
let root = ReactDOM.unstable_createRoot(container, {hydrate: true});
|
||||
root.render(<App />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
// This will have exceeded the suspended time so we should timeout.
|
||||
jest.advanceTimersByTime(500);
|
||||
// The boundary should longer be suspended for the middle content
|
||||
@@ -811,7 +811,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
suspend = false;
|
||||
let root = ReactDOM.unstable_createRoot(container, {hydrate: true});
|
||||
root.render(<App />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
// This will have exceeded the suspended time so we should timeout.
|
||||
jest.advanceTimersByTime(500);
|
||||
// The boundary should longer be suspended for the middle content
|
||||
@@ -887,7 +887,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
suspend = false;
|
||||
let root = ReactDOM.unstable_createRoot(container, {hydrate: true});
|
||||
root.render(<App />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
// We're still loading because we're waiting for the server to stream more content.
|
||||
@@ -903,7 +903,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
// But it is not yet hydrated.
|
||||
expect(ref.current).toBe(null);
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
// Now it's hydrated.
|
||||
@@ -980,7 +980,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
suspend = false;
|
||||
let root = ReactDOM.unstable_createRoot(container, {hydrate: true});
|
||||
root.render(<App />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
// We're still loading because we're waiting for the server to stream more content.
|
||||
@@ -994,7 +994,7 @@ describe('ReactDOMServerPartialHydration', () => {
|
||||
expect(container.textContent).toBe('Loading...');
|
||||
expect(ref.current).toBe(null);
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
// Hydrating should've generated an error and replaced the suspense boundary.
|
||||
|
||||
@@ -96,7 +96,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
|
||||
|
||||
await advanceTimers(500);
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
expect(window.getComputedStyle(divs[0].current).display).toEqual('block');
|
||||
expect(window.getComputedStyle(divs[1].current).display).toEqual('block');
|
||||
@@ -119,7 +119,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
|
||||
|
||||
await advanceTimers(500);
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
expect(container.textContent).toEqual('ABC');
|
||||
});
|
||||
@@ -168,7 +168,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
|
||||
|
||||
await advanceTimers(500);
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
expect(container.innerHTML).toEqual(
|
||||
'<span style="display: inline;">Sibling</span><span style="">Async</span>',
|
||||
|
||||
@@ -500,7 +500,7 @@ describe('ReactDOMServerHydration', () => {
|
||||
|
||||
jest.runAllTimers();
|
||||
await Promise.resolve();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(element.textContent).toBe('Hello world');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,7 +71,7 @@ function runActTests(label, render, unmount) {
|
||||
it('can use act to flush effects', () => {
|
||||
function App() {
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue(100);
|
||||
Scheduler.unstable_yieldValue(100);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ function runActTests(label, render, unmount) {
|
||||
function App() {
|
||||
let [ctr, setCtr] = React.useState(0);
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue(ctr);
|
||||
Scheduler.unstable_yieldValue(ctr);
|
||||
});
|
||||
return (
|
||||
<button id="button" onClick={() => setCtr(x => x + 1)}>
|
||||
@@ -140,7 +140,7 @@ function runActTests(label, render, unmount) {
|
||||
it('should flush effects only on exiting the outermost act', () => {
|
||||
function App() {
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue(0);
|
||||
Scheduler.unstable_yieldValue(0);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
@@ -390,7 +390,7 @@ function runActTests(label, render, unmount) {
|
||||
something();
|
||||
}, []);
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue(state);
|
||||
Scheduler.unstable_yieldValue(state);
|
||||
});
|
||||
return state;
|
||||
}
|
||||
@@ -415,7 +415,7 @@ function runActTests(label, render, unmount) {
|
||||
}
|
||||
React.useEffect(
|
||||
() => {
|
||||
Scheduler.yieldValue(state);
|
||||
Scheduler.unstable_yieldValue(state);
|
||||
ticker();
|
||||
},
|
||||
[Math.min(state, 4)],
|
||||
@@ -564,7 +564,7 @@ function runActTests(label, render, unmount) {
|
||||
it('should cleanup after errors - sync', () => {
|
||||
function App() {
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue('oh yes');
|
||||
Scheduler.unstable_yieldValue('oh yes');
|
||||
});
|
||||
return null;
|
||||
}
|
||||
@@ -590,7 +590,7 @@ function runActTests(label, render, unmount) {
|
||||
function App() {
|
||||
async function somethingAsync() {
|
||||
await null;
|
||||
Scheduler.yieldValue('oh yes');
|
||||
Scheduler.unstable_yieldValue('oh yes');
|
||||
}
|
||||
React.useEffect(() => {
|
||||
somethingAsync();
|
||||
|
||||
@@ -1296,7 +1296,7 @@ describe('ReactUpdates', () => {
|
||||
const container = document.createElement('div');
|
||||
|
||||
function Baz() {
|
||||
Scheduler.yieldValue('Baz');
|
||||
Scheduler.unstable_yieldValue('Baz');
|
||||
return <p>baz</p>;
|
||||
}
|
||||
|
||||
@@ -1304,14 +1304,14 @@ describe('ReactUpdates', () => {
|
||||
function Bar() {
|
||||
const [counter, _setCounter] = React.useState(0);
|
||||
setCounter = _setCounter;
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return <p>bar {counter}</p>;
|
||||
}
|
||||
|
||||
function Foo() {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue('Foo#effect');
|
||||
Scheduler.unstable_yieldValue('Foo#effect');
|
||||
});
|
||||
return (
|
||||
<div>
|
||||
@@ -1608,7 +1608,7 @@ describe('ReactUpdates', () => {
|
||||
const [step, setStep] = React.useState(0);
|
||||
React.useEffect(() => {
|
||||
setStep(x => x + 1);
|
||||
Scheduler.yieldValue(step);
|
||||
Scheduler.unstable_yieldValue(step);
|
||||
});
|
||||
return step;
|
||||
}
|
||||
@@ -1653,7 +1653,7 @@ describe('ReactUpdates', () => {
|
||||
React.useEffect(() => {
|
||||
if (step < LIMIT) {
|
||||
setStep(x => x + 1);
|
||||
Scheduler.yieldValue(step);
|
||||
Scheduler.unstable_yieldValue(step);
|
||||
}
|
||||
});
|
||||
return step;
|
||||
@@ -1690,7 +1690,7 @@ describe('ReactUpdates', () => {
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
setStep(x => x + 1);
|
||||
}
|
||||
Scheduler.yieldValue('Done');
|
||||
Scheduler.unstable_yieldValue('Done');
|
||||
}, []);
|
||||
return step;
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ describe('ChangeEventPlugin', () => {
|
||||
expect(ops).toEqual([]);
|
||||
expect(input).toBe(undefined);
|
||||
// Flush callbacks.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(ops).toEqual(['render: initial']);
|
||||
expect(input.value).toBe('initial');
|
||||
|
||||
@@ -571,7 +571,7 @@ describe('ChangeEventPlugin', () => {
|
||||
expect(ops).toEqual([]);
|
||||
expect(input).toBe(undefined);
|
||||
// Flush callbacks.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(ops).toEqual(['render: false']);
|
||||
expect(input.checked).toBe(false);
|
||||
|
||||
@@ -587,7 +587,7 @@ describe('ChangeEventPlugin', () => {
|
||||
|
||||
// Now let's make sure we're using the controlled value.
|
||||
root.render(<ControlledInput reverse={true} />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
ops = [];
|
||||
|
||||
@@ -630,7 +630,7 @@ describe('ChangeEventPlugin', () => {
|
||||
expect(ops).toEqual([]);
|
||||
expect(textarea).toBe(undefined);
|
||||
// Flush callbacks.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(ops).toEqual(['render: initial']);
|
||||
expect(textarea.value).toBe('initial');
|
||||
|
||||
@@ -681,7 +681,7 @@ describe('ChangeEventPlugin', () => {
|
||||
expect(ops).toEqual([]);
|
||||
expect(input).toBe(undefined);
|
||||
// Flush callbacks.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(ops).toEqual(['render: initial']);
|
||||
expect(input.value).toBe('initial');
|
||||
|
||||
@@ -732,7 +732,7 @@ describe('ChangeEventPlugin', () => {
|
||||
expect(ops).toEqual([]);
|
||||
expect(input).toBe(undefined);
|
||||
// Flush callbacks.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(ops).toEqual(['render: initial']);
|
||||
expect(input.value).toBe('initial');
|
||||
|
||||
@@ -747,7 +747,7 @@ describe('ChangeEventPlugin', () => {
|
||||
expect(input.value).toBe('initial');
|
||||
|
||||
// Flush callbacks.
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
// Now the click update has flushed.
|
||||
expect(ops).toEqual(['render: ']);
|
||||
expect(input.value).toBe('');
|
||||
@@ -792,7 +792,7 @@ describe('ChangeEventPlugin', () => {
|
||||
target.current.dispatchEvent(mouseOverEvent);
|
||||
|
||||
// 3s should be enough to expire the updates
|
||||
Scheduler.advanceTime(3000);
|
||||
Scheduler.unstable_advanceTime(3000);
|
||||
expect(container.textContent).toEqual('hovered');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -275,7 +275,7 @@ describe('SimpleEventPlugin', function() {
|
||||
expect(ops).toEqual([]);
|
||||
expect(button).toBe(undefined);
|
||||
// Flush async work
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(ops).toEqual(['render button: enabled']);
|
||||
|
||||
ops = [];
|
||||
@@ -315,7 +315,7 @@ describe('SimpleEventPlugin', function() {
|
||||
click();
|
||||
click();
|
||||
click();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(ops).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -346,7 +346,7 @@ describe('SimpleEventPlugin', function() {
|
||||
// Should not have flushed yet because it's async
|
||||
expect(button).toBe(undefined);
|
||||
// Flush async work
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(button.textContent).toEqual('Count: 0');
|
||||
|
||||
function click() {
|
||||
@@ -369,7 +369,7 @@ describe('SimpleEventPlugin', function() {
|
||||
click();
|
||||
|
||||
// Flush the remaining work
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
// The counter should equal the total number of clicks
|
||||
expect(button.textContent).toEqual('Count: 7');
|
||||
});
|
||||
@@ -385,7 +385,7 @@ describe('SimpleEventPlugin', function() {
|
||||
const text = `High-pri count: ${
|
||||
this.props.highPriCount
|
||||
}, Low-pri count: ${this.state.lowPriCount}`;
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return (
|
||||
<button
|
||||
ref={el => (button = el)}
|
||||
|
||||
@@ -45,7 +45,7 @@ const {ReactCurrentActingRendererSigil} = ReactSharedInternals;
|
||||
|
||||
let hasWarnedAboutMissingMockScheduler = false;
|
||||
const flushWork =
|
||||
Scheduler.unstable_flushWithoutYielding ||
|
||||
Scheduler.unstable_flushAllWithoutAsserting ||
|
||||
function() {
|
||||
if (warnAboutMissingMockScheduler === true) {
|
||||
if (hasWarnedAboutMissingMockScheduler === false) {
|
||||
|
||||
@@ -301,7 +301,7 @@ describe('Hover event responder', () => {
|
||||
target.current.dispatchEvent(createEvent('mouseover'));
|
||||
|
||||
// 3s should be enough to expire the updates
|
||||
Scheduler.advanceTime(3000);
|
||||
Scheduler.unstable_advanceTime(3000);
|
||||
expect(newContainer.textContent).toEqual('hovered');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2732,7 +2732,7 @@ describe('Event responder: Press', () => {
|
||||
const root = ReactDOM.unstable_createRoot(newContainer);
|
||||
document.body.appendChild(newContainer);
|
||||
root.render(<MyComponent />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
dispatchEventWithTimeStamp(ref.current, 'pointerdown', 100);
|
||||
dispatchEventWithTimeStamp(ref.current, 'pointerup', 100);
|
||||
@@ -2743,7 +2743,7 @@ describe('Event responder: Press', () => {
|
||||
} else {
|
||||
expect(renderCounts).toBe(1);
|
||||
}
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
if (__DEV__) {
|
||||
expect(renderCounts).toBe(4);
|
||||
} else {
|
||||
@@ -2761,7 +2761,7 @@ describe('Event responder: Press', () => {
|
||||
expect(renderCounts).toBe(3);
|
||||
}
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
document.body.removeChild(newContainer);
|
||||
});
|
||||
|
||||
@@ -2798,7 +2798,7 @@ describe('Event responder: Press', () => {
|
||||
const root = ReactDOM.unstable_createRoot(newContainer);
|
||||
document.body.appendChild(newContainer);
|
||||
root.render(<MyComponent />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
dispatchEventWithTimeStamp(ref.current, 'pointerdown', 100);
|
||||
dispatchEventWithTimeStamp(ref.current, 'pointerup', 100);
|
||||
@@ -2809,7 +2809,7 @@ describe('Event responder: Press', () => {
|
||||
} else {
|
||||
expect(renderCounts).toBe(2);
|
||||
}
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
if (__DEV__) {
|
||||
expect(renderCounts).toBe(6);
|
||||
} else {
|
||||
@@ -2827,7 +2827,7 @@ describe('Event responder: Press', () => {
|
||||
expect(renderCounts).toBe(4);
|
||||
}
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
document.body.removeChild(newContainer);
|
||||
});
|
||||
|
||||
@@ -2873,13 +2873,13 @@ describe('Event responder: Press', () => {
|
||||
const root = ReactDOM.unstable_createRoot(newContainer);
|
||||
|
||||
root.render(<MyComponent />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(newContainer.textContent).toEqual('Presses: 0, Clicks: 0');
|
||||
|
||||
dispatchEventWithTimeStamp(button.current, 'pointerdown', 100);
|
||||
dispatchEventWithTimeStamp(button.current, 'pointerup', 100);
|
||||
dispatchEventWithTimeStamp(button.current, 'click', 100);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(newContainer.textContent).toEqual('Presses: 1, Clicks: 1');
|
||||
|
||||
expect(ops).toEqual(['Presses: 0, Clicks: 0']);
|
||||
|
||||
@@ -662,7 +662,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
|
||||
|
||||
let hasWarnedAboutMissingMockScheduler = false;
|
||||
const flushWork =
|
||||
Scheduler.unstable_flushWithoutYielding ||
|
||||
Scheduler.unstable_flushAllWithoutAsserting ||
|
||||
function() {
|
||||
if (warnAboutMissingMockScheduler === true) {
|
||||
if (hasWarnedAboutMissingMockScheduler === false) {
|
||||
@@ -1108,7 +1108,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
|
||||
hostUpdateCounter = 0;
|
||||
hostCloneCounter = 0;
|
||||
try {
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
return useMutation
|
||||
? {
|
||||
hostDiffCounter,
|
||||
@@ -1125,7 +1125,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
|
||||
}
|
||||
},
|
||||
|
||||
expire: Scheduler.advanceTime,
|
||||
expire: Scheduler.unstable_advanceTime,
|
||||
|
||||
flushExpired(): Array<mixed> {
|
||||
return Scheduler.unstable_flushExpired();
|
||||
@@ -1261,7 +1261,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
|
||||
_next: null,
|
||||
};
|
||||
root.firstBatch = batch;
|
||||
Scheduler.unstable_flushWithoutYielding();
|
||||
Scheduler.unstable_flushAllWithoutAsserting();
|
||||
const actual = Scheduler.unstable_clearYields();
|
||||
expect(actual).toEqual(expectedFlush);
|
||||
return (expectedCommit: Array<mixed>) => {
|
||||
|
||||
@@ -58,7 +58,7 @@ describe('ErrorBoundaryReconciliation', () => {
|
||||
</ErrorBoundary>,
|
||||
{unstable_isConcurrent: isConcurrent},
|
||||
);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(renderer).toMatchRenderedOutput(<span prop="BrokenRender" />);
|
||||
|
||||
expect(() => {
|
||||
@@ -67,7 +67,7 @@ describe('ErrorBoundaryReconciliation', () => {
|
||||
<BrokenRender fail={true} />
|
||||
</ErrorBoundary>,
|
||||
);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
}).toWarnDev(isConcurrent ? ['invalid', 'invalid'] : ['invalid']);
|
||||
const Fallback = fallbackTagName;
|
||||
expect(renderer).toMatchRenderedOutput(<Fallback prop="ErrorBoundary" />);
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('ReactBatchedMode', () => {
|
||||
TextResource = ReactCache.unstable_createResource(([text, ms = 0]) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
setTimeout(() => {
|
||||
Scheduler.yieldValue(`Promise resolved [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Promise resolved [${text}]`);
|
||||
resolve(text);
|
||||
}, ms),
|
||||
);
|
||||
@@ -29,7 +29,7 @@ describe('ReactBatchedMode', () => {
|
||||
});
|
||||
|
||||
function Text(props) {
|
||||
Scheduler.yieldValue(props.text);
|
||||
Scheduler.unstable_yieldValue(props.text);
|
||||
return props.text;
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ describe('ReactBatchedMode', () => {
|
||||
const text = props.text;
|
||||
try {
|
||||
TextResource.read([props.text, props.ms]);
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return props.text;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ describe('ReactBatchedMode', () => {
|
||||
|
||||
function App() {
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue('Layout effect');
|
||||
Scheduler.unstable_yieldValue('Layout effect');
|
||||
});
|
||||
return <Text text="Hi" />;
|
||||
}
|
||||
|
||||
@@ -51,13 +51,13 @@ describe('ReactExpiration', () => {
|
||||
it('two updates of like priority in the same event always flush within the same batch', () => {
|
||||
class Text extends React.Component {
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(`${this.props.text} [commit]`);
|
||||
Scheduler.unstable_yieldValue(`${this.props.text} [commit]`);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue(`${this.props.text} [commit]`);
|
||||
Scheduler.unstable_yieldValue(`${this.props.text} [commit]`);
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue(`${this.props.text} [render]`);
|
||||
Scheduler.unstable_yieldValue(`${this.props.text} [render]`);
|
||||
return <span prop={this.props.text} />;
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ describe('ReactExpiration', () => {
|
||||
// Schedule an update.
|
||||
ReactNoop.render(<Text text="A" />);
|
||||
// Advance the timer.
|
||||
Scheduler.advanceTime(2000);
|
||||
Scheduler.unstable_advanceTime(2000);
|
||||
// Partially flush the the first update, then interrupt it.
|
||||
expect(Scheduler).toFlushAndYieldThrough(['A [render]']);
|
||||
interrupt();
|
||||
@@ -100,7 +100,7 @@ describe('ReactExpiration', () => {
|
||||
// Now do the same thing again, except this time don't flush any work in
|
||||
// between the two updates.
|
||||
ReactNoop.render(<Text text="A" />);
|
||||
Scheduler.advanceTime(2000);
|
||||
Scheduler.unstable_advanceTime(2000);
|
||||
expect(Scheduler).toHaveYielded([]);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('B')]);
|
||||
// Schedule another update.
|
||||
@@ -116,13 +116,13 @@ describe('ReactExpiration', () => {
|
||||
() => {
|
||||
class Text extends React.Component {
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(`${this.props.text} [commit]`);
|
||||
Scheduler.unstable_yieldValue(`${this.props.text} [commit]`);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue(`${this.props.text} [commit]`);
|
||||
Scheduler.unstable_yieldValue(`${this.props.text} [commit]`);
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue(`${this.props.text} [render]`);
|
||||
Scheduler.unstable_yieldValue(`${this.props.text} [render]`);
|
||||
return <span prop={this.props.text} />;
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ describe('ReactExpiration', () => {
|
||||
// Schedule an update.
|
||||
ReactNoop.render(<Text text="A" />);
|
||||
// Advance the timer.
|
||||
Scheduler.advanceTime(2000);
|
||||
Scheduler.unstable_advanceTime(2000);
|
||||
// Partially flush the the first update, then interrupt it.
|
||||
expect(Scheduler).toFlushAndYieldThrough(['A [render]']);
|
||||
interrupt();
|
||||
@@ -165,7 +165,7 @@ describe('ReactExpiration', () => {
|
||||
// Now do the same thing again, except this time don't flush any work in
|
||||
// between the two updates.
|
||||
ReactNoop.render(<Text text="A" />);
|
||||
Scheduler.advanceTime(2000);
|
||||
Scheduler.unstable_advanceTime(2000);
|
||||
expect(Scheduler).toHaveYielded([]);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('B')]);
|
||||
|
||||
@@ -188,17 +188,17 @@ describe('ReactExpiration', () => {
|
||||
state = {text: store.text};
|
||||
componentDidMount() {
|
||||
subscribers.push(this);
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`${this.state.text} [${this.props.label}] [commit]`,
|
||||
);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`${this.state.text} [${this.props.label}] [commit]`,
|
||||
);
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`${this.state.text} [${this.props.label}] [render]`,
|
||||
);
|
||||
return <span prop={this.state.text} />;
|
||||
@@ -255,7 +255,7 @@ describe('ReactExpiration', () => {
|
||||
// Before importing the renderer, advance the current time by a number
|
||||
// larger than the maximum allowed for bitwise operations.
|
||||
const maxSigned31BitInt = 1073741823;
|
||||
Scheduler.advanceTime(maxSigned31BitInt * 100);
|
||||
Scheduler.unstable_advanceTime(maxSigned31BitInt * 100);
|
||||
|
||||
// Now import the renderer. On module initialization, it will read the
|
||||
// current time.
|
||||
@@ -268,7 +268,7 @@ describe('ReactExpiration', () => {
|
||||
expect(ReactNoop).toMatchRenderedOutput(null);
|
||||
|
||||
// Advance the time some more to expire the update.
|
||||
Scheduler.advanceTime(10000);
|
||||
Scheduler.unstable_advanceTime(10000);
|
||||
expect(Scheduler).toFlushExpired([]);
|
||||
expect(ReactNoop).toMatchRenderedOutput('Hi');
|
||||
});
|
||||
@@ -279,7 +279,7 @@ describe('ReactExpiration', () => {
|
||||
// default to 0, and most tests don't advance time.
|
||||
|
||||
// Before scheduling an update, advance the current time.
|
||||
Scheduler.advanceTime(10000);
|
||||
Scheduler.unstable_advanceTime(10000);
|
||||
|
||||
ReactNoop.render('Hi');
|
||||
expect(Scheduler).toFlushExpired([]);
|
||||
@@ -287,7 +287,7 @@ describe('ReactExpiration', () => {
|
||||
|
||||
// Advancing by ~5 seconds should be sufficient to expire the update. (I
|
||||
// used a slightly larger number to allow for possible rounding.)
|
||||
Scheduler.advanceTime(6000);
|
||||
Scheduler.unstable_advanceTime(6000);
|
||||
|
||||
ReactNoop.render('Hi');
|
||||
expect(Scheduler).toFlushExpired([]);
|
||||
|
||||
@@ -799,12 +799,12 @@ describe('ReactFiberEvents', () => {
|
||||
};
|
||||
|
||||
function Async() {
|
||||
Scheduler.yieldValue('Suspend!');
|
||||
Scheduler.unstable_yieldValue('Suspend!');
|
||||
throw thenable;
|
||||
}
|
||||
|
||||
function Text(props) {
|
||||
Scheduler.yieldValue(props.text);
|
||||
Scheduler.unstable_yieldValue(props.text);
|
||||
return props.text;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ describe('ReactHooks', () => {
|
||||
const {useState, useLayoutEffect} = React;
|
||||
|
||||
function Child({text}) {
|
||||
Scheduler.yieldValue('Child: ' + text);
|
||||
Scheduler.unstable_yieldValue('Child: ' + text);
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -73,9 +73,9 @@ describe('ReactHooks', () => {
|
||||
setCounter2 = _setCounter2;
|
||||
|
||||
const text = `${counter1}, ${counter2}`;
|
||||
Scheduler.yieldValue(`Parent: ${text}`);
|
||||
Scheduler.unstable_yieldValue(`Parent: ${text}`);
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue(`Effect: ${text}`);
|
||||
Scheduler.unstable_yieldValue(`Effect: ${text}`);
|
||||
});
|
||||
return <Child text={text} />;
|
||||
}
|
||||
@@ -169,7 +169,7 @@ describe('ReactHooks', () => {
|
||||
const {useState, memo} = React;
|
||||
|
||||
function Child({text}) {
|
||||
Scheduler.yieldValue('Child: ' + text);
|
||||
Scheduler.unstable_yieldValue('Child: ' + text);
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ describe('ReactHooks', () => {
|
||||
setCounter2 = _setCounter2;
|
||||
|
||||
const text = `${counter1}, ${counter2} (${theme})`;
|
||||
Scheduler.yieldValue(`Parent: ${text}`);
|
||||
Scheduler.unstable_yieldValue(`Parent: ${text}`);
|
||||
return <Child text={text} />;
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ describe('ReactHooks', () => {
|
||||
const [counter, _setCounter] = useState(0);
|
||||
setCounter = _setCounter;
|
||||
|
||||
Scheduler.yieldValue(`Count: ${counter}`);
|
||||
Scheduler.unstable_yieldValue(`Count: ${counter}`);
|
||||
return counter;
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ describe('ReactHooks', () => {
|
||||
const [counter, _dispatch] = useReducer((s, a) => a, 0);
|
||||
dispatch = _dispatch;
|
||||
|
||||
Scheduler.yieldValue(`Count: ${counter}`);
|
||||
Scheduler.unstable_yieldValue(`Count: ${counter}`);
|
||||
return counter;
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ describe('ReactHooks', () => {
|
||||
let setTheme;
|
||||
function ThemeProvider({children}) {
|
||||
const [theme, _setTheme] = useState('light');
|
||||
Scheduler.yieldValue('Theme: ' + theme);
|
||||
Scheduler.unstable_yieldValue('Theme: ' + theme);
|
||||
setTheme = _setTheme;
|
||||
return (
|
||||
<ThemeContext.Provider value={theme}>{children}</ThemeContext.Provider>
|
||||
@@ -330,7 +330,7 @@ describe('ReactHooks', () => {
|
||||
}
|
||||
|
||||
function Child({text}) {
|
||||
Scheduler.yieldValue('Child: ' + text);
|
||||
Scheduler.unstable_yieldValue('Child: ' + text);
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -342,9 +342,9 @@ describe('ReactHooks', () => {
|
||||
const theme = useContext(ThemeContext);
|
||||
|
||||
const text = `${counter} (${theme})`;
|
||||
Scheduler.yieldValue(`Parent: ${text}`);
|
||||
Scheduler.unstable_yieldValue(`Parent: ${text}`);
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue(`Effect: ${text}`);
|
||||
Scheduler.unstable_yieldValue(`Effect: ${text}`);
|
||||
});
|
||||
return <Child text={text} />;
|
||||
}
|
||||
@@ -405,7 +405,7 @@ describe('ReactHooks', () => {
|
||||
const {useState, useLayoutEffect} = React;
|
||||
|
||||
function Child({text}) {
|
||||
Scheduler.yieldValue('Child: ' + text);
|
||||
Scheduler.unstable_yieldValue('Child: ' + text);
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -413,9 +413,9 @@ describe('ReactHooks', () => {
|
||||
function Parent() {
|
||||
const [counter, _setCounter] = useState(0);
|
||||
setCounter = _setCounter;
|
||||
Scheduler.yieldValue('Parent: ' + counter);
|
||||
Scheduler.unstable_yieldValue('Parent: ' + counter);
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue('Effect: ' + counter);
|
||||
Scheduler.unstable_yieldValue('Effect: ' + counter);
|
||||
});
|
||||
return <Child text={counter} />;
|
||||
}
|
||||
@@ -483,7 +483,7 @@ describe('ReactHooks', () => {
|
||||
const {useState} = React;
|
||||
|
||||
function Child({text}) {
|
||||
Scheduler.yieldValue('Child: ' + text);
|
||||
Scheduler.unstable_yieldValue('Child: ' + text);
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -491,7 +491,7 @@ describe('ReactHooks', () => {
|
||||
function Parent() {
|
||||
const [counter, _setCounter] = useState(0);
|
||||
setCounter = _setCounter;
|
||||
Scheduler.yieldValue('Parent: ' + counter);
|
||||
Scheduler.unstable_yieldValue('Parent: ' + counter);
|
||||
return <Child text={counter} />;
|
||||
}
|
||||
|
||||
@@ -502,7 +502,9 @@ describe('ReactHooks', () => {
|
||||
|
||||
const update = value => {
|
||||
setCounter(previous => {
|
||||
Scheduler.yieldValue(`Compute state (${previous} -> ${value})`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Compute state (${previous} -> ${value})`,
|
||||
);
|
||||
return value;
|
||||
});
|
||||
};
|
||||
@@ -541,7 +543,7 @@ describe('ReactHooks', () => {
|
||||
const {useState} = React;
|
||||
|
||||
function Child({text}) {
|
||||
Scheduler.yieldValue('Child: ' + text);
|
||||
Scheduler.unstable_yieldValue('Child: ' + text);
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -549,7 +551,7 @@ describe('ReactHooks', () => {
|
||||
function Parent() {
|
||||
const [counter, _setCounter] = useState(1);
|
||||
setCounter = _setCounter;
|
||||
Scheduler.yieldValue('Parent: ' + counter);
|
||||
Scheduler.unstable_yieldValue('Parent: ' + counter);
|
||||
return <Child text={counter} />;
|
||||
}
|
||||
|
||||
@@ -561,7 +563,9 @@ describe('ReactHooks', () => {
|
||||
const update = compute => {
|
||||
setCounter(previous => {
|
||||
const value = compute(previous);
|
||||
Scheduler.yieldValue(`Compute state (${previous} -> ${value})`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Compute state (${previous} -> ${value})`,
|
||||
);
|
||||
return value;
|
||||
});
|
||||
};
|
||||
@@ -599,7 +603,9 @@ describe('ReactHooks', () => {
|
||||
const {useLayoutEffect} = React;
|
||||
function App(props) {
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue('Did commit: ' + props.dependencies.join(', '));
|
||||
Scheduler.unstable_yieldValue(
|
||||
'Did commit: ' + props.dependencies.join(', '),
|
||||
);
|
||||
}, props.dependencies);
|
||||
return props.dependencies;
|
||||
}
|
||||
@@ -620,7 +626,7 @@ describe('ReactHooks', () => {
|
||||
const {useMemo} = React;
|
||||
function App({text, hasDeps}) {
|
||||
const resolvedText = useMemo(() => {
|
||||
Scheduler.yieldValue('Compute');
|
||||
Scheduler.unstable_yieldValue('Compute');
|
||||
return text.toUpperCase();
|
||||
}, hasDeps ? null : [text]);
|
||||
return resolvedText;
|
||||
@@ -1836,7 +1842,7 @@ describe('ReactHooks', () => {
|
||||
);
|
||||
expect(root).toMatchRenderedOutput('loading');
|
||||
await Promise.resolve();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(root).toMatchRenderedOutput('hello');
|
||||
});
|
||||
|
||||
@@ -1868,7 +1874,7 @@ describe('ReactHooks', () => {
|
||||
);
|
||||
expect(root).toMatchRenderedOutput('loading');
|
||||
await Promise.resolve();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(root).toMatchRenderedOutput('hello');
|
||||
});
|
||||
|
||||
@@ -1900,7 +1906,7 @@ describe('ReactHooks', () => {
|
||||
);
|
||||
expect(root).toMatchRenderedOutput('loading');
|
||||
await Promise.resolve();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(root).toMatchRenderedOutput('hello');
|
||||
});
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
}
|
||||
|
||||
function Text(props) {
|
||||
Scheduler.yieldValue(props.text);
|
||||
Scheduler.unstable_yieldValue(props.text);
|
||||
return <span prop={props.text} />;
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('lazy state initializer', () => {
|
||||
function Counter(props, ref) {
|
||||
const [count, updateCount] = useState(() => {
|
||||
Scheduler.yieldValue('getInitialState');
|
||||
Scheduler.unstable_yieldValue('getInitialState');
|
||||
return props.initialState;
|
||||
});
|
||||
useImperativeHandle(ref, () => ({updateCount}));
|
||||
@@ -346,7 +346,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
if (count < 3) {
|
||||
setCount(count + 1);
|
||||
}
|
||||
Scheduler.yieldValue('Render: ' + count);
|
||||
Scheduler.unstable_yieldValue('Render: ' + count);
|
||||
return <Text text={count} />;
|
||||
}
|
||||
|
||||
@@ -369,7 +369,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
setCount(c => c + 1);
|
||||
setCount(c => c + 1);
|
||||
}
|
||||
Scheduler.yieldValue('Render: ' + count);
|
||||
Scheduler.unstable_yieldValue('Render: ' + count);
|
||||
return <Text text={count} />;
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
function Counter({row: newRow}) {
|
||||
let [count, setCount] = useState(0);
|
||||
setCount(count + 1);
|
||||
Scheduler.yieldValue('Render: ' + count);
|
||||
Scheduler.unstable_yieldValue('Render: ' + count);
|
||||
return <Text text={count} />;
|
||||
}
|
||||
ReactNoop.render(<Counter />);
|
||||
@@ -409,7 +409,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
if (count < 3) {
|
||||
dispatch('increment');
|
||||
}
|
||||
Scheduler.yieldValue('Render: ' + count);
|
||||
Scheduler.unstable_yieldValue('Render: ' + count);
|
||||
return <Text text={count} />;
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
setReducer(() => reducerA);
|
||||
}
|
||||
}
|
||||
Scheduler.yieldValue('Render: ' + count);
|
||||
Scheduler.unstable_yieldValue('Render: ' + count);
|
||||
return <Text text={count} />;
|
||||
}
|
||||
Counter = forwardRef(Counter);
|
||||
@@ -550,7 +550,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
function Counter(props, ref) {
|
||||
const [count, dispatch] = useReducer(reducer, props, p => {
|
||||
Scheduler.yieldValue('Init');
|
||||
Scheduler.unstable_yieldValue('Init');
|
||||
return p.initialCount;
|
||||
});
|
||||
useImperativeHandle(ref, () => ({dispatch}));
|
||||
@@ -618,13 +618,13 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('simple mount and update', () => {
|
||||
function Counter(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Passive effect [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Passive effect [${props.count}]`);
|
||||
});
|
||||
return <Text text={'Count: ' + props.count} />;
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -634,7 +634,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
|
||||
@@ -646,13 +646,13 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('flushes passive effects even with sibling deletions', () => {
|
||||
function LayoutEffect(props) {
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue(`Layout effect`);
|
||||
Scheduler.unstable_yieldValue(`Layout effect`);
|
||||
});
|
||||
return <Text text="Layout" />;
|
||||
}
|
||||
function PassiveEffect(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Passive effect`);
|
||||
Scheduler.unstable_yieldValue(`Passive effect`);
|
||||
}, []);
|
||||
return <Text text="Passive" />;
|
||||
}
|
||||
@@ -681,7 +681,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('flushes passive effects even if siblings schedule an update', () => {
|
||||
function PassiveEffect(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue('Passive effect');
|
||||
Scheduler.unstable_yieldValue('Passive effect');
|
||||
});
|
||||
return <Text text="Passive" />;
|
||||
}
|
||||
@@ -692,7 +692,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
if (count === 0) {
|
||||
setCount(1);
|
||||
}
|
||||
Scheduler.yieldValue('Layout effect ' + count);
|
||||
Scheduler.unstable_yieldValue('Layout effect ' + count);
|
||||
});
|
||||
return <Text text="Layout" />;
|
||||
}
|
||||
@@ -719,13 +719,13 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('flushes passive effects even if siblings schedule a new root', () => {
|
||||
function PassiveEffect(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue('Passive effect');
|
||||
Scheduler.unstable_yieldValue('Passive effect');
|
||||
}, []);
|
||||
return <Text text="Passive" />;
|
||||
}
|
||||
function LayoutEffect(props) {
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue('Layout effect');
|
||||
Scheduler.unstable_yieldValue('Layout effect');
|
||||
// Scheduling work shouldn't interfere with the queued passive effect
|
||||
ReactNoop.renderToRootWithID(<Text text="New Root" />, 'root2');
|
||||
});
|
||||
@@ -761,7 +761,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
function Counter(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Committed state when effect was fired: ${getCommittedText()}`,
|
||||
);
|
||||
});
|
||||
@@ -769,13 +769,13 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([0, 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span(0)]);
|
||||
// Before the effects have a chance to flush, schedule another update
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([
|
||||
// The previous effect flushes before the reconciliation
|
||||
@@ -797,7 +797,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
const [count, updateCount] = useState('(empty)');
|
||||
useEffect(
|
||||
() => {
|
||||
Scheduler.yieldValue(`Schedule update [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Schedule update [${props.count}]`);
|
||||
updateCount(props.count);
|
||||
},
|
||||
[props.count],
|
||||
@@ -806,7 +806,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([
|
||||
'Count: (empty)',
|
||||
@@ -820,7 +820,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -835,7 +835,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
const [count, updateCount] = useState('(empty)');
|
||||
useEffect(
|
||||
() => {
|
||||
Scheduler.yieldValue(`Schedule update [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Schedule update [${props.count}]`);
|
||||
updateCount(props.count);
|
||||
},
|
||||
[props.count],
|
||||
@@ -844,7 +844,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([
|
||||
'Count: (empty)',
|
||||
@@ -854,7 +854,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
// Rendering again should flush the previous commit's effects
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([
|
||||
'Schedule update [0]',
|
||||
@@ -877,7 +877,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
const [count, updateCount] = useState(0);
|
||||
_updateCount = updateCount;
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Will set count to 1`);
|
||||
Scheduler.unstable_yieldValue(`Will set count to 1`);
|
||||
updateCount(1);
|
||||
}, []);
|
||||
return <Text text={'Count: ' + count} />;
|
||||
@@ -887,7 +887,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
// it's a lot harder to simulate this condition inside an act scope
|
||||
expect(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -933,7 +933,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
expect(SchedulerTracing.unstable_getCurrent()).toMatchInteractions([
|
||||
tracingEvent,
|
||||
]);
|
||||
Scheduler.yieldValue(`Will set count to 1`);
|
||||
Scheduler.unstable_yieldValue(`Will set count to 1`);
|
||||
updateCount(1);
|
||||
}, []);
|
||||
return <Text text={'Count: ' + count} />;
|
||||
@@ -948,7 +948,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
tracingEvent.timestamp,
|
||||
() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -1022,7 +1022,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
const [count, updateCount] = useState('(empty)');
|
||||
useEffect(
|
||||
() => {
|
||||
Scheduler.yieldValue(`Schedule update [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Schedule update [${props.count}]`);
|
||||
ReactNoop.flushSync(() => {
|
||||
updateCount(props.count);
|
||||
});
|
||||
@@ -1033,7 +1033,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([
|
||||
'Count: (empty)',
|
||||
@@ -1049,16 +1049,16 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('unmounts previous effect', () => {
|
||||
function Counter(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Did create [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Did create [${props.count}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Did destroy [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Did destroy [${props.count}]`);
|
||||
};
|
||||
});
|
||||
return <Text text={'Count: ' + props.count} />;
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -1068,7 +1068,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
|
||||
@@ -1080,16 +1080,16 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('unmounts on deletion', () => {
|
||||
function Counter(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Did create [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Did create [${props.count}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Did destroy [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Did destroy [${props.count}]`);
|
||||
};
|
||||
});
|
||||
return <Text text={'Count: ' + props.count} />;
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -1105,16 +1105,16 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('unmounts on deletion after skipped effect', () => {
|
||||
function Counter(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Did create [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Did create [${props.count}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Did destroy [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Did destroy [${props.count}]`);
|
||||
};
|
||||
}, []);
|
||||
return <Text text={'Count: ' + props.count} />;
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -1124,7 +1124,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
|
||||
@@ -1139,9 +1139,9 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
it('always fires effects if no dependencies are provided', () => {
|
||||
function effect() {
|
||||
Scheduler.yieldValue(`Did create`);
|
||||
Scheduler.unstable_yieldValue(`Did create`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Did destroy`);
|
||||
Scheduler.unstable_yieldValue(`Did destroy`);
|
||||
};
|
||||
}
|
||||
function Counter(props) {
|
||||
@@ -1150,7 +1150,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -1160,7 +1160,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
|
||||
@@ -1178,9 +1178,9 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
const text = `${props.label}: ${props.count}`;
|
||||
useEffect(
|
||||
() => {
|
||||
Scheduler.yieldValue(`Did create [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Did create [${text}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Did destroy [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Did destroy [${text}]`);
|
||||
};
|
||||
},
|
||||
[props.label, props.count],
|
||||
@@ -1189,7 +1189,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter label="Count" count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
});
|
||||
@@ -1199,7 +1199,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter label="Count" count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
// Count changed
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
|
||||
@@ -1213,7 +1213,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter label="Count" count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
// Nothing changed, so no effect should have fired
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
|
||||
@@ -1224,7 +1224,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter label="Total" count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
// Label changed
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Total: 1', 'Sync effect']);
|
||||
@@ -1240,16 +1240,16 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('multiple effects', () => {
|
||||
function Counter(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Did commit 1 [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Did commit 1 [${props.count}]`);
|
||||
});
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Did commit 2 [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Did commit 2 [${props.count}]`);
|
||||
});
|
||||
return <Text text={'Count: ' + props.count} />;
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -1259,7 +1259,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
|
||||
@@ -1270,22 +1270,22 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('unmounts all previous effects before creating any new ones', () => {
|
||||
function Counter(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Mount A [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount A [${props.count}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Unmount A [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Unmount A [${props.count}]`);
|
||||
};
|
||||
});
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Mount B [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount B [${props.count}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Unmount B [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Unmount B [${props.count}]`);
|
||||
};
|
||||
});
|
||||
return <Text text={'Count: ' + props.count} />;
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -1295,7 +1295,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
|
||||
@@ -1311,25 +1311,25 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('handles errors on mount', () => {
|
||||
function Counter(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Mount A [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount A [${props.count}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Unmount A [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Unmount A [${props.count}]`);
|
||||
};
|
||||
});
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue('Oops!');
|
||||
Scheduler.unstable_yieldValue('Oops!');
|
||||
throw new Error('Oops!');
|
||||
// eslint-disable-next-line no-unreachable
|
||||
Scheduler.yieldValue(`Mount B [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount B [${props.count}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Unmount B [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Unmount B [${props.count}]`);
|
||||
};
|
||||
});
|
||||
return <Text text={'Count: ' + props.count} />;
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -1349,26 +1349,26 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('handles errors on update', () => {
|
||||
function Counter(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Mount A [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount A [${props.count}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Unmount A [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Unmount A [${props.count}]`);
|
||||
};
|
||||
});
|
||||
useEffect(() => {
|
||||
if (props.count === 1) {
|
||||
Scheduler.yieldValue('Oops!');
|
||||
Scheduler.unstable_yieldValue('Oops!');
|
||||
throw new Error('Oops!');
|
||||
}
|
||||
Scheduler.yieldValue(`Mount B [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount B [${props.count}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Unmount B [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Unmount B [${props.count}]`);
|
||||
};
|
||||
});
|
||||
return <Text text={'Count: ' + props.count} />;
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -1379,7 +1379,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
act(() => {
|
||||
// This update will trigger an errror
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
|
||||
@@ -1400,25 +1400,25 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('handles errors on unmount', () => {
|
||||
function Counter(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Mount A [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount A [${props.count}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue('Oops!');
|
||||
Scheduler.unstable_yieldValue('Oops!');
|
||||
throw new Error('Oops!');
|
||||
// eslint-disable-next-line no-unreachable
|
||||
Scheduler.yieldValue(`Unmount A [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Unmount A [${props.count}]`);
|
||||
};
|
||||
});
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Mount B [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount B [${props.count}]`);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Unmount B [${props.count}]`);
|
||||
Scheduler.unstable_yieldValue(`Unmount B [${props.count}]`);
|
||||
};
|
||||
});
|
||||
return <Text text={'Count: ' + props.count} />;
|
||||
}
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
@@ -1429,7 +1429,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
act(() => {
|
||||
// This update will trigger an errror
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
|
||||
@@ -1446,15 +1446,15 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('works with memo', () => {
|
||||
function Counter({count}) {
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue('Mount: ' + count);
|
||||
return () => Scheduler.yieldValue('Unmount: ' + count);
|
||||
Scheduler.unstable_yieldValue('Mount: ' + count);
|
||||
return () => Scheduler.unstable_yieldValue('Unmount: ' + count);
|
||||
});
|
||||
return <Text text={'Count: ' + count} />;
|
||||
}
|
||||
Counter = memo(Counter);
|
||||
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([
|
||||
'Count: 0',
|
||||
@@ -1464,7 +1464,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([
|
||||
'Count: 1',
|
||||
@@ -1485,7 +1485,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
function getCommittedText() {
|
||||
const yields = Scheduler.unstable_clearYields();
|
||||
const children = ReactNoop.getChildren();
|
||||
Scheduler.yieldValue(yields);
|
||||
Scheduler.unstable_yieldValue(yields);
|
||||
if (children === null) {
|
||||
return null;
|
||||
}
|
||||
@@ -1494,13 +1494,13 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
function Counter(props) {
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue(`Current: ${getCommittedText()}`);
|
||||
Scheduler.unstable_yieldValue(`Current: ${getCommittedText()}`);
|
||||
});
|
||||
return <Text text={props.count} />;
|
||||
}
|
||||
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([
|
||||
[0],
|
||||
@@ -1510,7 +1510,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([span(0)]);
|
||||
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([
|
||||
[1],
|
||||
@@ -1529,15 +1529,23 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
// intentionally omits a mutation effect.
|
||||
committedText = props.count + '';
|
||||
|
||||
Scheduler.yieldValue(`Mount layout [current: ${committedText}]`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Mount layout [current: ${committedText}]`,
|
||||
);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Unmount layout [current: ${committedText}]`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Unmount layout [current: ${committedText}]`,
|
||||
);
|
||||
};
|
||||
});
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Mount normal [current: ${committedText}]`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Mount normal [current: ${committedText}]`,
|
||||
);
|
||||
return () => {
|
||||
Scheduler.yieldValue(`Unmount normal [current: ${committedText}]`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Unmount normal [current: ${committedText}]`,
|
||||
);
|
||||
};
|
||||
});
|
||||
return null;
|
||||
@@ -1545,7 +1553,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([
|
||||
'Mount layout [current: 0]',
|
||||
@@ -1553,7 +1561,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
]);
|
||||
expect(committedText).toEqual('0');
|
||||
ReactNoop.render(<Counter count={1} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough([
|
||||
'Mount normal [current: 0]',
|
||||
@@ -1642,7 +1650,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
const text = props.text;
|
||||
const capitalizedText = useMemo(
|
||||
() => {
|
||||
Scheduler.yieldValue(`Capitalize '${text}'`);
|
||||
Scheduler.unstable_yieldValue(`Capitalize '${text}'`);
|
||||
return text.toUpperCase();
|
||||
},
|
||||
[text],
|
||||
@@ -1674,12 +1682,12 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
}
|
||||
|
||||
function computeA() {
|
||||
Scheduler.yieldValue('compute A');
|
||||
Scheduler.unstable_yieldValue('compute A');
|
||||
return 'A';
|
||||
}
|
||||
|
||||
function computeB() {
|
||||
Scheduler.yieldValue('compute B');
|
||||
Scheduler.unstable_yieldValue('compute B');
|
||||
return 'B';
|
||||
}
|
||||
|
||||
@@ -1709,7 +1717,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
}
|
||||
|
||||
function compute(val) {
|
||||
Scheduler.yieldValue('compute ' + val);
|
||||
Scheduler.unstable_yieldValue('compute ' + val);
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -1749,7 +1757,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
function App() {
|
||||
ping = useDebouncedCallback(
|
||||
value => {
|
||||
Scheduler.yieldValue('ping: ' + value);
|
||||
Scheduler.unstable_yieldValue('ping: ' + value);
|
||||
},
|
||||
100,
|
||||
[],
|
||||
@@ -2020,17 +2028,17 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
it('unmount effects', () => {
|
||||
function App(props) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue('Mount A');
|
||||
Scheduler.unstable_yieldValue('Mount A');
|
||||
return () => {
|
||||
Scheduler.yieldValue('Unmount A');
|
||||
Scheduler.unstable_yieldValue('Unmount A');
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (props.showMore) {
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue('Mount B');
|
||||
Scheduler.unstable_yieldValue('Mount B');
|
||||
return () => {
|
||||
Scheduler.yieldValue('Unmount B');
|
||||
Scheduler.unstable_yieldValue('Unmount B');
|
||||
};
|
||||
}, []);
|
||||
}
|
||||
@@ -2040,7 +2048,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<App showMore={false} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Sync effect']);
|
||||
});
|
||||
@@ -2091,17 +2099,17 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
// This reducer closes over a value from props. If the reducer is not
|
||||
// properly updated, the eager reducer will compare to an old value
|
||||
// and bail out incorrectly.
|
||||
Scheduler.yieldValue('Reducer: ' + count);
|
||||
Scheduler.unstable_yieldValue('Reducer: ' + count);
|
||||
return count;
|
||||
}, -1);
|
||||
useEffect(
|
||||
() => {
|
||||
Scheduler.yieldValue('Effect: ' + count);
|
||||
Scheduler.unstable_yieldValue('Effect: ' + count);
|
||||
dispatch();
|
||||
},
|
||||
[count],
|
||||
);
|
||||
Scheduler.yieldValue('Render: ' + state);
|
||||
Scheduler.unstable_yieldValue('Render: ' + state);
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -2143,7 +2151,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
setStep(step + 1);
|
||||
}
|
||||
|
||||
Scheduler.yieldValue(`Step: ${step}, Shadow: ${shadow}`);
|
||||
Scheduler.unstable_yieldValue(`Step: ${step}, Shadow: ${shadow}`);
|
||||
return shadow;
|
||||
}
|
||||
|
||||
@@ -2184,7 +2192,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
const [count, updateCount] = useState(0);
|
||||
_updateCount = updateCount;
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(`Will set count to 1`);
|
||||
Scheduler.unstable_yieldValue(`Will set count to 1`);
|
||||
updateCount(1);
|
||||
}, []);
|
||||
return <Text text={'Count: ' + count} />;
|
||||
@@ -2192,7 +2200,7 @@ describe('ReactHooksWithNoopRenderer', () => {
|
||||
|
||||
act(() => {
|
||||
ReactNoop.render(<Counter count={0} />, () =>
|
||||
Scheduler.yieldValue('Sync effect'),
|
||||
Scheduler.unstable_yieldValue('Sync effect'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('ReactIncremental', () => {
|
||||
|
||||
it('should render a simple component, in steps if needed', () => {
|
||||
function Bar() {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return (
|
||||
<span>
|
||||
<div>Hello World</div>
|
||||
@@ -51,11 +51,11 @@ describe('ReactIncremental', () => {
|
||||
}
|
||||
|
||||
function Foo() {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return [<Bar key="a" isBar={true} />, <Bar key="b" isBar={true} />];
|
||||
}
|
||||
|
||||
ReactNoop.render(<Foo />, () => Scheduler.yieldValue('callback'));
|
||||
ReactNoop.render(<Foo />, () => Scheduler.unstable_yieldValue('callback'));
|
||||
// Do one step of work.
|
||||
expect(ReactNoop.flushNextYield()).toEqual(['Foo']);
|
||||
|
||||
@@ -132,12 +132,12 @@ describe('ReactIncremental', () => {
|
||||
|
||||
it('can cancel partially rendered work and restart', () => {
|
||||
function Bar(props) {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return <div>{props.children}</div>;
|
||||
}
|
||||
|
||||
function Foo(props) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<div>
|
||||
<Bar>{props.text}</Bar>
|
||||
@@ -192,10 +192,10 @@ describe('ReactIncremental', () => {
|
||||
|
||||
inst.setState(
|
||||
() => {
|
||||
Scheduler.yieldValue('setState1');
|
||||
Scheduler.unstable_yieldValue('setState1');
|
||||
return {text: 'bar'};
|
||||
},
|
||||
() => Scheduler.yieldValue('callback1'),
|
||||
() => Scheduler.unstable_yieldValue('callback1'),
|
||||
);
|
||||
|
||||
// Flush part of the work
|
||||
@@ -205,10 +205,10 @@ describe('ReactIncremental', () => {
|
||||
ReactNoop.flushSync(() => ReactNoop.render(<Foo />));
|
||||
inst.setState(
|
||||
() => {
|
||||
Scheduler.yieldValue('setState2');
|
||||
Scheduler.unstable_yieldValue('setState2');
|
||||
return {text2: 'baz'};
|
||||
},
|
||||
() => Scheduler.yieldValue('callback2'),
|
||||
() => Scheduler.unstable_yieldValue('callback2'),
|
||||
);
|
||||
|
||||
// Flush the rest of the work which now includes the low priority
|
||||
@@ -223,17 +223,17 @@ describe('ReactIncremental', () => {
|
||||
|
||||
it('can deprioritize unfinished work and resume it later', () => {
|
||||
function Bar(props) {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return <div>{props.children}</div>;
|
||||
}
|
||||
|
||||
function Middle(props) {
|
||||
Scheduler.yieldValue('Middle');
|
||||
Scheduler.unstable_yieldValue('Middle');
|
||||
return <span>{props.children}</span>;
|
||||
}
|
||||
|
||||
function Foo(props) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<div>
|
||||
<Bar>{props.text}</Bar>
|
||||
@@ -1086,7 +1086,7 @@ describe('ReactIncremental', () => {
|
||||
class Foo extends React.PureComponent {
|
||||
render() {
|
||||
const msg = `A: ${a}, B: ${this.props.b}`;
|
||||
Scheduler.yieldValue(msg);
|
||||
Scheduler.unstable_yieldValue(msg);
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -1456,18 +1456,18 @@ describe('ReactIncremental', () => {
|
||||
class Parent extends React.Component {
|
||||
state = {parentRenders: 0};
|
||||
static getDerivedStateFromProps(props, prevState) {
|
||||
Scheduler.yieldValue('getDerivedStateFromProps');
|
||||
Scheduler.unstable_yieldValue('getDerivedStateFromProps');
|
||||
return prevState.parentRenders + 1;
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Parent');
|
||||
Scheduler.unstable_yieldValue('Parent');
|
||||
return <Child parentRenders={this.state.parentRenders} ref={child} />;
|
||||
}
|
||||
}
|
||||
|
||||
class Child extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('Child');
|
||||
Scheduler.unstable_yieldValue('Child');
|
||||
return this.props.parentRenders;
|
||||
}
|
||||
}
|
||||
@@ -1819,7 +1819,7 @@ describe('ReactIncremental', () => {
|
||||
};
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Intl ' + JSON.stringify(this.context));
|
||||
Scheduler.unstable_yieldValue('Intl ' + JSON.stringify(this.context));
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
@@ -1834,7 +1834,7 @@ describe('ReactIncremental', () => {
|
||||
};
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Router ' + JSON.stringify(this.context));
|
||||
Scheduler.unstable_yieldValue('Router ' + JSON.stringify(this.context));
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
@@ -1844,7 +1844,9 @@ describe('ReactIncremental', () => {
|
||||
locale: PropTypes.string,
|
||||
};
|
||||
render() {
|
||||
Scheduler.yieldValue('ShowLocale ' + JSON.stringify(this.context));
|
||||
Scheduler.unstable_yieldValue(
|
||||
'ShowLocale ' + JSON.stringify(this.context),
|
||||
);
|
||||
return this.context.locale;
|
||||
}
|
||||
}
|
||||
@@ -1854,13 +1856,15 @@ describe('ReactIncremental', () => {
|
||||
route: PropTypes.string,
|
||||
};
|
||||
render() {
|
||||
Scheduler.yieldValue('ShowRoute ' + JSON.stringify(this.context));
|
||||
Scheduler.unstable_yieldValue(
|
||||
'ShowRoute ' + JSON.stringify(this.context),
|
||||
);
|
||||
return this.context.route;
|
||||
}
|
||||
}
|
||||
|
||||
function ShowBoth(props, context) {
|
||||
Scheduler.yieldValue('ShowBoth ' + JSON.stringify(context));
|
||||
Scheduler.unstable_yieldValue('ShowBoth ' + JSON.stringify(context));
|
||||
return `${context.route} in ${context.locale}`;
|
||||
}
|
||||
ShowBoth.contextTypes = {
|
||||
@@ -1870,14 +1874,18 @@ describe('ReactIncremental', () => {
|
||||
|
||||
class ShowNeither extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('ShowNeither ' + JSON.stringify(this.context));
|
||||
Scheduler.unstable_yieldValue(
|
||||
'ShowNeither ' + JSON.stringify(this.context),
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class Indirection extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('Indirection ' + JSON.stringify(this.context));
|
||||
Scheduler.unstable_yieldValue(
|
||||
'Indirection ' + JSON.stringify(this.context),
|
||||
);
|
||||
return [
|
||||
<ShowLocale key="a" />,
|
||||
<ShowRoute key="b" />,
|
||||
@@ -2056,7 +2064,7 @@ describe('ReactIncremental', () => {
|
||||
};
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Intl ' + JSON.stringify(this.context));
|
||||
Scheduler.unstable_yieldValue('Intl ' + JSON.stringify(this.context));
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
@@ -2066,7 +2074,9 @@ describe('ReactIncremental', () => {
|
||||
locale: PropTypes.string,
|
||||
};
|
||||
render() {
|
||||
Scheduler.yieldValue('ShowLocale ' + JSON.stringify(this.context));
|
||||
Scheduler.unstable_yieldValue(
|
||||
'ShowLocale ' + JSON.stringify(this.context),
|
||||
);
|
||||
return this.context.locale;
|
||||
}
|
||||
}
|
||||
@@ -2817,12 +2827,12 @@ describe('ReactIncremental', () => {
|
||||
|
||||
it('does not interrupt for update at same priority', () => {
|
||||
function Parent(props) {
|
||||
Scheduler.yieldValue('Parent: ' + props.step);
|
||||
Scheduler.unstable_yieldValue('Parent: ' + props.step);
|
||||
return <Child step={props.step} />;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
Scheduler.yieldValue('Child: ' + props.step);
|
||||
Scheduler.unstable_yieldValue('Child: ' + props.step);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2837,12 +2847,12 @@ describe('ReactIncremental', () => {
|
||||
|
||||
it('does not interrupt for update at lower priority', () => {
|
||||
function Parent(props) {
|
||||
Scheduler.yieldValue('Parent: ' + props.step);
|
||||
Scheduler.unstable_yieldValue('Parent: ' + props.step);
|
||||
return <Child step={props.step} />;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
Scheduler.yieldValue('Child: ' + props.step);
|
||||
Scheduler.unstable_yieldValue('Child: ' + props.step);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2858,12 +2868,12 @@ describe('ReactIncremental', () => {
|
||||
|
||||
it('does interrupt for update at higher priority', () => {
|
||||
function Parent(props) {
|
||||
Scheduler.yieldValue('Parent: ' + props.step);
|
||||
Scheduler.unstable_yieldValue('Parent: ' + props.step);
|
||||
return <Child step={props.step} />;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
Scheduler.yieldValue('Child: ' + props.step);
|
||||
Scheduler.unstable_yieldValue('Child: ' + props.step);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,31 +45,31 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
class ErrorBoundary extends React.Component {
|
||||
state = {error: null};
|
||||
static getDerivedStateFromError(error) {
|
||||
Scheduler.yieldValue('getDerivedStateFromError');
|
||||
Scheduler.unstable_yieldValue('getDerivedStateFromError');
|
||||
return {error};
|
||||
}
|
||||
render() {
|
||||
if (this.state.error) {
|
||||
Scheduler.yieldValue('ErrorBoundary (catch)');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary (catch)');
|
||||
return <ErrorMessage error={this.state.error} />;
|
||||
}
|
||||
Scheduler.yieldValue('ErrorBoundary (try)');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary (try)');
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
function ErrorMessage(props) {
|
||||
Scheduler.yieldValue('ErrorMessage');
|
||||
Scheduler.unstable_yieldValue('ErrorMessage');
|
||||
return <span prop={`Caught an error: ${props.error.message}`} />;
|
||||
}
|
||||
|
||||
function Indirection(props) {
|
||||
Scheduler.yieldValue('Indirection');
|
||||
Scheduler.unstable_yieldValue('Indirection');
|
||||
return props.children || null;
|
||||
}
|
||||
|
||||
function BadRender() {
|
||||
Scheduler.yieldValue('throw');
|
||||
Scheduler.unstable_yieldValue('throw');
|
||||
throw new Error('oops!');
|
||||
}
|
||||
|
||||
@@ -139,31 +139,31 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
class ErrorBoundary extends React.Component {
|
||||
state = {error: null};
|
||||
componentDidCatch(error) {
|
||||
Scheduler.yieldValue('componentDidCatch');
|
||||
Scheduler.unstable_yieldValue('componentDidCatch');
|
||||
this.setState({error});
|
||||
}
|
||||
render() {
|
||||
if (this.state.error) {
|
||||
Scheduler.yieldValue('ErrorBoundary (catch)');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary (catch)');
|
||||
return <ErrorMessage error={this.state.error} />;
|
||||
}
|
||||
Scheduler.yieldValue('ErrorBoundary (try)');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary (try)');
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
function ErrorMessage(props) {
|
||||
Scheduler.yieldValue('ErrorMessage');
|
||||
Scheduler.unstable_yieldValue('ErrorMessage');
|
||||
return <span prop={`Caught an error: ${props.error.message}`} />;
|
||||
}
|
||||
|
||||
function Indirection(props) {
|
||||
Scheduler.yieldValue('Indirection');
|
||||
Scheduler.unstable_yieldValue('Indirection');
|
||||
return props.children || null;
|
||||
}
|
||||
|
||||
function BadRender() {
|
||||
Scheduler.yieldValue('throw');
|
||||
Scheduler.unstable_yieldValue('throw');
|
||||
throw new Error('oops!');
|
||||
}
|
||||
|
||||
@@ -218,15 +218,15 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
it("retries at a lower priority if there's additional pending work", () => {
|
||||
function App(props) {
|
||||
if (props.isBroken) {
|
||||
Scheduler.yieldValue('error');
|
||||
Scheduler.unstable_yieldValue('error');
|
||||
throw new Error('Oops!');
|
||||
}
|
||||
Scheduler.yieldValue('success');
|
||||
Scheduler.unstable_yieldValue('success');
|
||||
return <span prop="Everything is fine." />;
|
||||
}
|
||||
|
||||
function onCommit() {
|
||||
Scheduler.yieldValue('commit');
|
||||
Scheduler.unstable_yieldValue('commit');
|
||||
}
|
||||
|
||||
function interrupt() {
|
||||
@@ -236,7 +236,7 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
}
|
||||
|
||||
ReactNoop.render(<App isBroken={true} />, onCommit);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['error']);
|
||||
interrupt();
|
||||
|
||||
@@ -260,11 +260,11 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
class Parent extends React.Component {
|
||||
state = {hideChild: false};
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue('commit: ' + this.state.hideChild);
|
||||
Scheduler.unstable_yieldValue('commit: ' + this.state.hideChild);
|
||||
}
|
||||
render() {
|
||||
if (this.state.hideChild) {
|
||||
Scheduler.yieldValue('(empty)');
|
||||
Scheduler.unstable_yieldValue('(empty)');
|
||||
return <span prop="(empty)" />;
|
||||
}
|
||||
return <Child isBroken={this.props.childIsBroken} />;
|
||||
@@ -273,10 +273,10 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
|
||||
function Child(props) {
|
||||
if (props.isBroken) {
|
||||
Scheduler.yieldValue('Error!');
|
||||
Scheduler.unstable_yieldValue('Error!');
|
||||
throw new Error('Error!');
|
||||
}
|
||||
Scheduler.yieldValue('Child');
|
||||
Scheduler.unstable_yieldValue('Child');
|
||||
return <span prop="Child" />;
|
||||
}
|
||||
|
||||
@@ -308,17 +308,17 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
|
||||
it('retries one more time before handling error', () => {
|
||||
function BadRender() {
|
||||
Scheduler.yieldValue('BadRender');
|
||||
Scheduler.unstable_yieldValue('BadRender');
|
||||
throw new Error('oops');
|
||||
}
|
||||
|
||||
function Sibling() {
|
||||
Scheduler.yieldValue('Sibling');
|
||||
Scheduler.unstable_yieldValue('Sibling');
|
||||
return <span prop="Sibling" />;
|
||||
}
|
||||
|
||||
function Parent() {
|
||||
Scheduler.yieldValue('Parent');
|
||||
Scheduler.unstable_yieldValue('Parent');
|
||||
return (
|
||||
<React.Fragment>
|
||||
<BadRender />
|
||||
@@ -327,7 +327,7 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
);
|
||||
}
|
||||
|
||||
ReactNoop.render(<Parent />, () => Scheduler.yieldValue('commit'));
|
||||
ReactNoop.render(<Parent />, () => Scheduler.unstable_yieldValue('commit'));
|
||||
|
||||
// Render the bad component asynchronously
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Parent', 'BadRender']);
|
||||
@@ -357,7 +357,7 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
throw new Error(`Error ${++id}`);
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('BadMount');
|
||||
Scheduler.unstable_yieldValue('BadMount');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -365,14 +365,14 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
class ErrorBoundary extends React.Component {
|
||||
state = {errorCount: 0};
|
||||
componentDidCatch(error) {
|
||||
Scheduler.yieldValue(`componentDidCatch: ${error.message}`);
|
||||
Scheduler.unstable_yieldValue(`componentDidCatch: ${error.message}`);
|
||||
this.setState(state => ({errorCount: state.errorCount + 1}));
|
||||
}
|
||||
render() {
|
||||
if (this.state.errorCount > 0) {
|
||||
return <span prop={`Number of errors: ${this.state.errorCount}`} />;
|
||||
}
|
||||
Scheduler.yieldValue('ErrorBoundary');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary');
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
@@ -430,23 +430,23 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
class ErrorBoundary extends React.Component {
|
||||
state = {error: null};
|
||||
componentDidCatch(error) {
|
||||
Scheduler.yieldValue('ErrorBoundary componentDidCatch');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary componentDidCatch');
|
||||
this.setState({error});
|
||||
}
|
||||
render() {
|
||||
if (this.state.error) {
|
||||
Scheduler.yieldValue('ErrorBoundary render error');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary render error');
|
||||
return (
|
||||
<span prop={`Caught an error: ${this.state.error.message}.`} />
|
||||
);
|
||||
}
|
||||
Scheduler.yieldValue('ErrorBoundary render success');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary render success');
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
function BrokenRender(props) {
|
||||
Scheduler.yieldValue('BrokenRender');
|
||||
Scheduler.unstable_yieldValue('BrokenRender');
|
||||
throw new Error('Hello');
|
||||
}
|
||||
|
||||
@@ -603,17 +603,17 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
it('propagates an error from a noop error boundary during partial deferred mounting', () => {
|
||||
class RethrowErrorBoundary extends React.Component {
|
||||
componentDidCatch(error) {
|
||||
Scheduler.yieldValue('RethrowErrorBoundary componentDidCatch');
|
||||
Scheduler.unstable_yieldValue('RethrowErrorBoundary componentDidCatch');
|
||||
throw error;
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('RethrowErrorBoundary render');
|
||||
Scheduler.unstable_yieldValue('RethrowErrorBoundary render');
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
function BrokenRender() {
|
||||
Scheduler.yieldValue('BrokenRender');
|
||||
Scheduler.unstable_yieldValue('BrokenRender');
|
||||
throw new Error('Hello');
|
||||
}
|
||||
|
||||
@@ -758,7 +758,7 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
});
|
||||
});
|
||||
}).toThrow('Hello');
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(ReactNoop.getChildren()).toEqual([span('a:3')]);
|
||||
});
|
||||
|
||||
@@ -862,7 +862,7 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
it('should not attempt to recover an unmounting error boundary', () => {
|
||||
class Parent extends React.Component {
|
||||
componentWillUnmount() {
|
||||
Scheduler.yieldValue('Parent componentWillUnmount');
|
||||
Scheduler.unstable_yieldValue('Parent componentWillUnmount');
|
||||
}
|
||||
render() {
|
||||
return <Boundary />;
|
||||
@@ -871,7 +871,7 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
|
||||
class Boundary extends React.Component {
|
||||
componentDidCatch(e) {
|
||||
Scheduler.yieldValue(`Caught error: ${e.message}`);
|
||||
Scheduler.unstable_yieldValue(`Caught error: ${e.message}`);
|
||||
}
|
||||
render() {
|
||||
return <ThrowsOnUnmount />;
|
||||
@@ -880,7 +880,7 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
|
||||
class ThrowsOnUnmount extends React.Component {
|
||||
componentWillUnmount() {
|
||||
Scheduler.yieldValue('ThrowsOnUnmount componentWillUnmount');
|
||||
Scheduler.unstable_yieldValue('ThrowsOnUnmount componentWillUnmount');
|
||||
throw new Error('unmount error');
|
||||
}
|
||||
render() {
|
||||
@@ -1423,31 +1423,31 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
class ErrorBoundary extends React.Component {
|
||||
state = {error: null};
|
||||
componentDidCatch(error) {
|
||||
Scheduler.yieldValue('componentDidCatch');
|
||||
Scheduler.unstable_yieldValue('componentDidCatch');
|
||||
this.setState({error});
|
||||
}
|
||||
render() {
|
||||
if (this.state.error) {
|
||||
Scheduler.yieldValue('ErrorBoundary (catch)');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary (catch)');
|
||||
return <ErrorMessage error={this.state.error} />;
|
||||
}
|
||||
Scheduler.yieldValue('ErrorBoundary (try)');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary (try)');
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
function ErrorMessage(props) {
|
||||
Scheduler.yieldValue('ErrorMessage');
|
||||
Scheduler.unstable_yieldValue('ErrorMessage');
|
||||
return <span prop={`Caught an error: ${props.error.message}`} />;
|
||||
}
|
||||
|
||||
function BadRenderSibling(props) {
|
||||
Scheduler.yieldValue('BadRenderSibling');
|
||||
Scheduler.unstable_yieldValue('BadRenderSibling');
|
||||
return null;
|
||||
}
|
||||
|
||||
function BadRender() {
|
||||
Scheduler.yieldValue('throw');
|
||||
Scheduler.unstable_yieldValue('throw');
|
||||
throw new Error('oops!');
|
||||
}
|
||||
|
||||
@@ -1485,25 +1485,25 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
// where we checked for the existence of didUpdate instead of didMount, and
|
||||
// didMount was not defined.
|
||||
function BadRender() {
|
||||
Scheduler.yieldValue('throw');
|
||||
Scheduler.unstable_yieldValue('throw');
|
||||
throw new Error('oops!');
|
||||
}
|
||||
|
||||
class Parent extends React.Component {
|
||||
state = {error: null, other: false};
|
||||
componentDidCatch(error) {
|
||||
Scheduler.yieldValue('did catch');
|
||||
Scheduler.unstable_yieldValue('did catch');
|
||||
this.setState({error});
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue('did update');
|
||||
Scheduler.unstable_yieldValue('did update');
|
||||
}
|
||||
render() {
|
||||
if (this.state.error) {
|
||||
Scheduler.yieldValue('render error message');
|
||||
Scheduler.unstable_yieldValue('render error message');
|
||||
return <span prop={`Caught an error: ${this.state.error.message}`} />;
|
||||
}
|
||||
Scheduler.yieldValue('render');
|
||||
Scheduler.unstable_yieldValue('render');
|
||||
return <BadRender />;
|
||||
}
|
||||
}
|
||||
@@ -1529,7 +1529,7 @@ describe('ReactIncrementalErrorHandling', () => {
|
||||
}
|
||||
render() {
|
||||
if (this.state.errorInfo) {
|
||||
Scheduler.yieldValue('render error message');
|
||||
Scheduler.unstable_yieldValue('render error message');
|
||||
return (
|
||||
<span
|
||||
prop={`Caught an error:${normalizeCodeLocInfo(
|
||||
|
||||
@@ -167,10 +167,12 @@ describe('ReactIncrementalErrorLogging', () => {
|
||||
this.setState({step: 1});
|
||||
}
|
||||
componentWillUnmount() {
|
||||
Scheduler.yieldValue('componentWillUnmount: ' + this.state.step);
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentWillUnmount: ' + this.state.step,
|
||||
);
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('render: ' + this.state.step);
|
||||
Scheduler.unstable_yieldValue('render: ' + this.state.step);
|
||||
if (this.state.step > 0) {
|
||||
throw new Error('oops');
|
||||
}
|
||||
|
||||
@@ -397,21 +397,21 @@ describe('ReactDebugFiberPerf', () => {
|
||||
it('measures deferred work in chunks', () => {
|
||||
class A extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('A');
|
||||
Scheduler.unstable_yieldValue('A');
|
||||
return <div>{this.props.children}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('B');
|
||||
Scheduler.unstable_yieldValue('B');
|
||||
return <div>{this.props.children}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
class C extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('C');
|
||||
Scheduler.unstable_yieldValue('C');
|
||||
return <div>{this.props.children}</div>;
|
||||
}
|
||||
}
|
||||
@@ -652,7 +652,7 @@ describe('ReactDebugFiberPerf', () => {
|
||||
|
||||
it('warns if an in-progress update is interrupted', () => {
|
||||
function Foo() {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return <span />;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,10 +47,14 @@ describe('ReactIncrementalReflection', () => {
|
||||
}
|
||||
UNSAFE_componentWillMount() {
|
||||
instances.push(this);
|
||||
Scheduler.yieldValue('componentWillMount: ' + this._isMounted());
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentWillMount: ' + this._isMounted(),
|
||||
);
|
||||
}
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue('componentDidMount: ' + this._isMounted());
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentDidMount: ' + this._isMounted(),
|
||||
);
|
||||
}
|
||||
render() {
|
||||
return <span />;
|
||||
@@ -91,16 +95,18 @@ describe('ReactIncrementalReflection', () => {
|
||||
instances.push(this);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
Scheduler.yieldValue('componentWillUnmount: ' + this._isMounted());
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentWillUnmount: ' + this._isMounted(),
|
||||
);
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Component');
|
||||
Scheduler.unstable_yieldValue('Component');
|
||||
return <span />;
|
||||
}
|
||||
}
|
||||
|
||||
function Other() {
|
||||
Scheduler.yieldValue('Other');
|
||||
Scheduler.unstable_yieldValue('Other');
|
||||
return <span />;
|
||||
}
|
||||
|
||||
@@ -149,22 +155,37 @@ describe('ReactIncrementalReflection', () => {
|
||||
class Component extends React.Component {
|
||||
UNSAFE_componentWillMount() {
|
||||
classInstance = this;
|
||||
Scheduler.yieldValue(['componentWillMount', findInstance(this)]);
|
||||
Scheduler.unstable_yieldValue([
|
||||
'componentWillMount',
|
||||
findInstance(this),
|
||||
]);
|
||||
}
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(['componentDidMount', findInstance(this)]);
|
||||
Scheduler.unstable_yieldValue([
|
||||
'componentDidMount',
|
||||
findInstance(this),
|
||||
]);
|
||||
}
|
||||
UNSAFE_componentWillUpdate() {
|
||||
Scheduler.yieldValue(['componentWillUpdate', findInstance(this)]);
|
||||
Scheduler.unstable_yieldValue([
|
||||
'componentWillUpdate',
|
||||
findInstance(this),
|
||||
]);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue(['componentDidUpdate', findInstance(this)]);
|
||||
Scheduler.unstable_yieldValue([
|
||||
'componentDidUpdate',
|
||||
findInstance(this),
|
||||
]);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
Scheduler.yieldValue(['componentWillUnmount', findInstance(this)]);
|
||||
Scheduler.unstable_yieldValue([
|
||||
'componentWillUnmount',
|
||||
findInstance(this),
|
||||
]);
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('render');
|
||||
Scheduler.unstable_yieldValue('render');
|
||||
return this.props.step < 2 ? (
|
||||
<span ref={ref => (this.span = ref)} />
|
||||
) : this.props.step === 2 ? (
|
||||
@@ -177,7 +198,7 @@ describe('ReactIncrementalReflection', () => {
|
||||
|
||||
function Sibling() {
|
||||
// Sibling is used to assert that we've rendered past the first component.
|
||||
Scheduler.yieldValue('render sibling');
|
||||
Scheduler.unstable_yieldValue('render sibling');
|
||||
return <span />;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ describe('ReactIncrementalScheduling', () => {
|
||||
function Text({text}) {
|
||||
useEffect(
|
||||
() => {
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
},
|
||||
[text],
|
||||
);
|
||||
@@ -144,24 +144,24 @@ describe('ReactIncrementalScheduling', () => {
|
||||
state = {tick: 0};
|
||||
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentDidMount (before setState): ' + this.state.tick,
|
||||
);
|
||||
this.setState({tick: 1});
|
||||
// We're in a batch. Update hasn't flushed yet.
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentDidMount (after setState): ' + this.state.tick,
|
||||
);
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue('componentDidUpdate: ' + this.state.tick);
|
||||
Scheduler.unstable_yieldValue('componentDidUpdate: ' + this.state.tick);
|
||||
if (this.state.tick === 2) {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentDidUpdate (before setState): ' + this.state.tick,
|
||||
);
|
||||
this.setState({tick: 3});
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentDidUpdate (after setState): ' + this.state.tick,
|
||||
);
|
||||
// We're in a batch. Update hasn't flushed yet.
|
||||
@@ -169,7 +169,7 @@ describe('ReactIncrementalScheduling', () => {
|
||||
}
|
||||
|
||||
render() {
|
||||
Scheduler.yieldValue('render: ' + this.state.tick);
|
||||
Scheduler.unstable_yieldValue('render: ' + this.state.tick);
|
||||
instance = this;
|
||||
return <span prop={this.state.tick} />;
|
||||
}
|
||||
@@ -209,11 +209,11 @@ describe('ReactIncrementalScheduling', () => {
|
||||
|
||||
componentDidMount() {
|
||||
ReactNoop.deferredUpdates(() => {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentDidMount (before setState): ' + this.state.tick,
|
||||
);
|
||||
this.setState({tick: 1});
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentDidMount (after setState): ' + this.state.tick,
|
||||
);
|
||||
});
|
||||
@@ -221,13 +221,15 @@ describe('ReactIncrementalScheduling', () => {
|
||||
|
||||
componentDidUpdate() {
|
||||
ReactNoop.deferredUpdates(() => {
|
||||
Scheduler.yieldValue('componentDidUpdate: ' + this.state.tick);
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentDidUpdate: ' + this.state.tick,
|
||||
);
|
||||
if (this.state.tick === 2) {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentDidUpdate (before setState): ' + this.state.tick,
|
||||
);
|
||||
this.setState({tick: 3});
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
'componentDidUpdate (after setState): ' + this.state.tick,
|
||||
);
|
||||
}
|
||||
@@ -235,7 +237,7 @@ describe('ReactIncrementalScheduling', () => {
|
||||
}
|
||||
|
||||
render() {
|
||||
Scheduler.yieldValue('render: ' + this.state.tick);
|
||||
Scheduler.unstable_yieldValue('render: ' + this.state.tick);
|
||||
instance = this;
|
||||
return <span prop={this.state.tick} />;
|
||||
}
|
||||
@@ -285,7 +287,7 @@ describe('ReactIncrementalScheduling', () => {
|
||||
});
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return <span prop={this.state.step} />;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,12 +375,12 @@ describe('ReactIncrementalSideEffects', () => {
|
||||
|
||||
it('does not update child nodes if a flush is aborted', () => {
|
||||
function Bar(props) {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return <span prop={props.text} />;
|
||||
}
|
||||
|
||||
function Foo(props) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
@@ -409,12 +409,12 @@ describe('ReactIncrementalSideEffects', () => {
|
||||
|
||||
it('preserves a previously rendered node when deprioritized', () => {
|
||||
function Middle(props) {
|
||||
Scheduler.yieldValue('Middle');
|
||||
Scheduler.unstable_yieldValue('Middle');
|
||||
return <span prop={props.children} />;
|
||||
}
|
||||
|
||||
function Foo(props) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<div>
|
||||
<div hidden={true}>
|
||||
@@ -435,7 +435,9 @@ describe('ReactIncrementalSideEffects', () => {
|
||||
</div>,
|
||||
);
|
||||
|
||||
ReactNoop.render(<Foo text="bar" />, () => Scheduler.yieldValue('commit'));
|
||||
ReactNoop.render(<Foo text="bar" />, () =>
|
||||
Scheduler.unstable_yieldValue('commit'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Foo', 'commit']);
|
||||
expect(ReactNoop.getChildrenAsJSX()).toEqual(
|
||||
<div>
|
||||
@@ -457,7 +459,7 @@ describe('ReactIncrementalSideEffects', () => {
|
||||
|
||||
it('can reuse side-effects after being preempted', () => {
|
||||
function Bar(props) {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return <span prop={props.children} />;
|
||||
}
|
||||
|
||||
@@ -469,7 +471,7 @@ describe('ReactIncrementalSideEffects', () => {
|
||||
);
|
||||
|
||||
function Foo(props) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<div hidden={true}>
|
||||
{props.step === 0 ? (
|
||||
@@ -500,7 +502,7 @@ describe('ReactIncrementalSideEffects', () => {
|
||||
// Make a quick update which will schedule low priority work to
|
||||
// update the middle content.
|
||||
ReactNoop.render(<Foo text="bar" step={1} />, () =>
|
||||
Scheduler.yieldValue('commit'),
|
||||
Scheduler.unstable_yieldValue('commit'),
|
||||
);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Foo', 'commit', 'Bar']);
|
||||
|
||||
@@ -540,7 +542,7 @@ describe('ReactIncrementalSideEffects', () => {
|
||||
return this.props.children !== nextProps.children;
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return <span prop={this.props.children} />;
|
||||
}
|
||||
}
|
||||
@@ -550,7 +552,7 @@ describe('ReactIncrementalSideEffects', () => {
|
||||
return this.props.step !== nextProps.step;
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Content');
|
||||
Scheduler.unstable_yieldValue('Content');
|
||||
return (
|
||||
<div>
|
||||
<Bar>{this.props.step === 0 ? 'Hi' : 'Hello'}</Bar>
|
||||
@@ -561,7 +563,7 @@ describe('ReactIncrementalSideEffects', () => {
|
||||
}
|
||||
|
||||
function Foo(props) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<div hidden={true}>
|
||||
<Content step={props.step} text={props.text} />
|
||||
@@ -619,7 +621,7 @@ describe('ReactIncrementalSideEffects', () => {
|
||||
|
||||
it('can update a completed tree before it has a chance to commit', () => {
|
||||
function Foo(props) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return <span prop={props.step} />;
|
||||
}
|
||||
ReactNoop.render(<Foo step={1} />);
|
||||
@@ -901,12 +903,12 @@ describe('ReactIncrementalSideEffects', () => {
|
||||
this.setState({active: true});
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return <span prop={this.state.active ? 'X' : this.props.idx} />;
|
||||
}
|
||||
}
|
||||
function Foo(props) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<div>
|
||||
<span prop={props.tick} />
|
||||
|
||||
@@ -216,7 +216,7 @@ describe('ReactIncrementalTriangle', () => {
|
||||
}
|
||||
render() {
|
||||
if (yieldAfterEachRender) {
|
||||
Scheduler.yieldValue(this);
|
||||
Scheduler.unstable_yieldValue(this);
|
||||
}
|
||||
const {counter, remainingDepth} = this.props;
|
||||
return (
|
||||
@@ -308,7 +308,7 @@ describe('ReactIncrementalTriangle', () => {
|
||||
} else {
|
||||
ReactNoop.render(<App remainingDepth={MAX_DEPTH} key={keyCounter++} />);
|
||||
}
|
||||
Scheduler.unstable_flushWithoutYielding();
|
||||
Scheduler.unstable_flushAllWithoutAsserting();
|
||||
assertConsistentTree();
|
||||
return appInstance;
|
||||
}
|
||||
@@ -390,7 +390,7 @@ describe('ReactIncrementalTriangle', () => {
|
||||
Scheduler.unstable_flushNumberOfYields(action.unitsOfWork);
|
||||
break;
|
||||
case FLUSH_ALL:
|
||||
Scheduler.unstable_flushWithoutYielding();
|
||||
Scheduler.unstable_flushAllWithoutAsserting();
|
||||
break;
|
||||
case STEP:
|
||||
ReactNoop.deferredUpdates(() => {
|
||||
@@ -432,7 +432,7 @@ describe('ReactIncrementalTriangle', () => {
|
||||
assertConsistentTree(activeLeafIndices);
|
||||
}
|
||||
// Flush remaining work
|
||||
Scheduler.unstable_flushWithoutYielding();
|
||||
Scheduler.unstable_flushAllWithoutAsserting();
|
||||
assertConsistentTree(activeLeafIndices, expectedCounterAtEnd);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ describe('ReactIncrementalUpdates', () => {
|
||||
class Foo extends React.Component {
|
||||
state = {};
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue('commit');
|
||||
Scheduler.unstable_yieldValue('commit');
|
||||
ReactNoop.deferredUpdates(() => {
|
||||
// Has low priority
|
||||
this.setState({b: 'b'});
|
||||
@@ -150,7 +150,7 @@ describe('ReactIncrementalUpdates', () => {
|
||||
|
||||
function createUpdate(letter) {
|
||||
return () => {
|
||||
Scheduler.yieldValue(letter);
|
||||
Scheduler.unstable_yieldValue(letter);
|
||||
return {
|
||||
[letter]: letter,
|
||||
};
|
||||
@@ -221,7 +221,7 @@ describe('ReactIncrementalUpdates', () => {
|
||||
|
||||
function createUpdate(letter) {
|
||||
return () => {
|
||||
Scheduler.yieldValue(letter);
|
||||
Scheduler.unstable_yieldValue(letter);
|
||||
return {
|
||||
[letter]: letter,
|
||||
};
|
||||
@@ -461,9 +461,9 @@ describe('ReactIncrementalUpdates', () => {
|
||||
const {useEffect} = React;
|
||||
|
||||
function App({label}) {
|
||||
Scheduler.yieldValue('Render: ' + label);
|
||||
Scheduler.unstable_yieldValue('Render: ' + label);
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue('Commit: ' + label);
|
||||
Scheduler.unstable_yieldValue('Commit: ' + label);
|
||||
});
|
||||
return label;
|
||||
}
|
||||
@@ -478,22 +478,22 @@ describe('ReactIncrementalUpdates', () => {
|
||||
// updates in separate batches are all flushed in the same callback
|
||||
ReactNoop.act(() => {
|
||||
ReactNoop.render(<App label="" />);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.render(<App label="he" />);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.render(<App label="hell" />);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.render(<App label="hello" />);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
@@ -519,27 +519,27 @@ describe('ReactIncrementalUpdates', () => {
|
||||
// Now do the same thing over again, but this time, expire all the updates
|
||||
// instead of flushing them normally.
|
||||
ReactNoop.render(<App label="" />);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.render(<App label="go" />);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.render(<App label="good" />);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.render(<App label="goodbye" />);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
// All the updates should render and commit in a single batch.
|
||||
Scheduler.advanceTime(10000);
|
||||
Scheduler.unstable_advanceTime(10000);
|
||||
expect(Scheduler).toHaveYielded(['Render: goodbye']);
|
||||
// Passive effect
|
||||
expect(Scheduler).toFlushAndYield(['Commit: goodbye']);
|
||||
@@ -551,9 +551,9 @@ describe('ReactIncrementalUpdates', () => {
|
||||
const {useEffect} = React;
|
||||
|
||||
function App({label}) {
|
||||
Scheduler.yieldValue('Render: ' + label);
|
||||
Scheduler.unstable_yieldValue('Render: ' + label);
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue('Commit: ' + label);
|
||||
Scheduler.unstable_yieldValue('Commit: ' + label);
|
||||
});
|
||||
return label;
|
||||
}
|
||||
@@ -568,25 +568,25 @@ describe('ReactIncrementalUpdates', () => {
|
||||
// updates in separate batches are all flushed in the same callback
|
||||
ReactNoop.renderToRootWithID(<App label="" />, 'a');
|
||||
ReactNoop.renderToRootWithID(<App label="" />, 'b');
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.renderToRootWithID(<App label="he" />, 'a');
|
||||
ReactNoop.renderToRootWithID(<App label="he" />, 'b');
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.renderToRootWithID(<App label="hell" />, 'a');
|
||||
ReactNoop.renderToRootWithID(<App label="hell" />, 'b');
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.renderToRootWithID(<App label="hello" />, 'a');
|
||||
ReactNoop.renderToRootWithID(<App label="hello" />, 'b');
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
@@ -621,30 +621,30 @@ describe('ReactIncrementalUpdates', () => {
|
||||
// instead of flushing them normally.
|
||||
ReactNoop.renderToRootWithID(<App label="" />, 'a');
|
||||
ReactNoop.renderToRootWithID(<App label="" />, 'b');
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.renderToRootWithID(<App label="go" />, 'a');
|
||||
ReactNoop.renderToRootWithID(<App label="go" />, 'b');
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.renderToRootWithID(<App label="good" />, 'a');
|
||||
ReactNoop.renderToRootWithID(<App label="good" />, 'b');
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
ReactNoop.renderToRootWithID(<App label="goodbye" />, 'a');
|
||||
ReactNoop.renderToRootWithID(<App label="goodbye" />, 'b');
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
|
||||
interrupt();
|
||||
|
||||
// All the updates should render and commit in a single batch.
|
||||
Scheduler.advanceTime(10000);
|
||||
Scheduler.unstable_advanceTime(10000);
|
||||
expect(Scheduler).toHaveYielded([
|
||||
'Render: goodbye',
|
||||
'Commit: goodbye',
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('ReactLazy', () => {
|
||||
});
|
||||
|
||||
function Text(props) {
|
||||
Scheduler.yieldValue(props.text);
|
||||
Scheduler.unstable_yieldValue(props.text);
|
||||
return props.text;
|
||||
}
|
||||
|
||||
@@ -205,10 +205,10 @@ describe('ReactLazy', () => {
|
||||
it('mount and reorder', async () => {
|
||||
class Child extends React.Component {
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue('Did mount: ' + this.props.label);
|
||||
Scheduler.unstable_yieldValue('Did mount: ' + this.props.label);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue('Did update: ' + this.props.label);
|
||||
Scheduler.unstable_yieldValue('Did update: ' + this.props.label);
|
||||
}
|
||||
render() {
|
||||
return <Text text={this.props.label} />;
|
||||
@@ -299,7 +299,7 @@ describe('ReactLazy', () => {
|
||||
|
||||
it('resolves defaultProps without breaking memoization', async () => {
|
||||
function LazyImpl(props) {
|
||||
Scheduler.yieldValue('Lazy');
|
||||
Scheduler.unstable_yieldValue('Lazy');
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Text text={props.siblingText} />
|
||||
@@ -349,38 +349,42 @@ describe('ReactLazy', () => {
|
||||
state = {};
|
||||
|
||||
static getDerivedStateFromProps(props) {
|
||||
Scheduler.yieldValue(`getDerivedStateFromProps: ${props.text}`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`getDerivedStateFromProps: ${props.text}`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
Scheduler.yieldValue(`constructor: ${this.props.text}`);
|
||||
Scheduler.unstable_yieldValue(`constructor: ${this.props.text}`);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(`componentDidMount: ${this.props.text}`);
|
||||
Scheduler.unstable_yieldValue(`componentDidMount: ${this.props.text}`);
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`componentDidUpdate: ${prevProps.text} -> ${this.props.text}`,
|
||||
);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
Scheduler.yieldValue(`componentWillUnmount: ${this.props.text}`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`componentWillUnmount: ${this.props.text}`,
|
||||
);
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps) {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`shouldComponentUpdate: ${this.props.text} -> ${nextProps.text}`,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
getSnapshotBeforeUpdate(prevProps) {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`getSnapshotBeforeUpdate: ${prevProps.text} -> ${this.props.text}`,
|
||||
);
|
||||
return null;
|
||||
@@ -449,17 +453,19 @@ describe('ReactLazy', () => {
|
||||
state = {};
|
||||
|
||||
UNSAFE_componentWillMount() {
|
||||
Scheduler.yieldValue(`UNSAFE_componentWillMount: ${this.props.text}`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`UNSAFE_componentWillMount: ${this.props.text}`,
|
||||
);
|
||||
}
|
||||
|
||||
UNSAFE_componentWillUpdate(nextProps) {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`UNSAFE_componentWillUpdate: ${this.props.text} -> ${nextProps.text}`,
|
||||
);
|
||||
}
|
||||
|
||||
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`UNSAFE_componentWillReceiveProps: ${this.props.text} -> ${
|
||||
nextProps.text
|
||||
}`,
|
||||
@@ -512,7 +518,7 @@ describe('ReactLazy', () => {
|
||||
|
||||
it('resolves defaultProps on the outer wrapper but warns', async () => {
|
||||
function T(props) {
|
||||
Scheduler.yieldValue(props.inner + ' ' + props.outer);
|
||||
Scheduler.unstable_yieldValue(props.inner + ' ' + props.outer);
|
||||
return props.inner + ' ' + props.outer;
|
||||
}
|
||||
T.defaultProps = {inner: 'Hi'};
|
||||
@@ -655,7 +661,7 @@ describe('ReactLazy', () => {
|
||||
await Promise.resolve();
|
||||
expect(() => {
|
||||
expect(Scheduler);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
}).toWarnDev([
|
||||
'Invalid prop `inner` of type `string` supplied to `Add`, expected `number`.',
|
||||
]);
|
||||
@@ -862,7 +868,7 @@ describe('ReactLazy', () => {
|
||||
|
||||
it('includes lazy-loaded component in warning stack', async () => {
|
||||
const LazyFoo = lazy(() => {
|
||||
Scheduler.yieldValue('Started loading');
|
||||
Scheduler.unstable_yieldValue('Started loading');
|
||||
const Foo = props => <div>{[<Text text="A" />, <Text text="B" />]}</div>;
|
||||
return fakeImport(Foo);
|
||||
});
|
||||
@@ -905,7 +911,7 @@ describe('ReactLazy', () => {
|
||||
}
|
||||
return fakeImport(
|
||||
React.forwardRef((props, ref) => {
|
||||
Scheduler.yieldValue('forwardRef');
|
||||
Scheduler.unstable_yieldValue('forwardRef');
|
||||
return <Bar ref={ref} />;
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('memo', () => {
|
||||
}
|
||||
|
||||
function Text(props) {
|
||||
Scheduler.yieldValue(props.text);
|
||||
Scheduler.unstable_yieldValue(props.text);
|
||||
return <span prop={props.text} />;
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ describe('memo', () => {
|
||||
return <Text text={count} />;
|
||||
}
|
||||
Counter = memo(Counter, (oldProps, newProps) => {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Old count: ${oldProps.count}, New count: ${newProps.count}`,
|
||||
);
|
||||
return oldProps.count === newProps.count;
|
||||
|
||||
@@ -30,7 +30,7 @@ describe('ReactNewContext', () => {
|
||||
});
|
||||
|
||||
function Text(props) {
|
||||
Scheduler.yieldValue(props.text);
|
||||
Scheduler.unstable_yieldValue(props.text);
|
||||
return <span prop={props.text} />;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ describe('ReactNewContext', () => {
|
||||
const ContextConsumer = getConsumer(Context);
|
||||
|
||||
function Provider(props) {
|
||||
Scheduler.yieldValue('Provider');
|
||||
Scheduler.unstable_yieldValue('Provider');
|
||||
return (
|
||||
<Context.Provider value={props.value}>
|
||||
{props.children}
|
||||
@@ -169,11 +169,11 @@ describe('ReactNewContext', () => {
|
||||
}
|
||||
|
||||
function Consumer(props) {
|
||||
Scheduler.yieldValue('Consumer');
|
||||
Scheduler.unstable_yieldValue('Consumer');
|
||||
return (
|
||||
<ContextConsumer>
|
||||
{value => {
|
||||
Scheduler.yieldValue('Consumer render prop');
|
||||
Scheduler.unstable_yieldValue('Consumer render prop');
|
||||
return <span prop={'Result: ' + value} />;
|
||||
}}
|
||||
</ContextConsumer>
|
||||
@@ -185,13 +185,13 @@ describe('ReactNewContext', () => {
|
||||
return false;
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Indirection');
|
||||
Scheduler.unstable_yieldValue('Indirection');
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
function App(props) {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return (
|
||||
<Provider value={props.value}>
|
||||
<Indirection>
|
||||
@@ -229,7 +229,7 @@ describe('ReactNewContext', () => {
|
||||
const ContextConsumer = getConsumer(Context);
|
||||
|
||||
function Provider(props) {
|
||||
Scheduler.yieldValue('Provider');
|
||||
Scheduler.unstable_yieldValue('Provider');
|
||||
return (
|
||||
<Context.Provider value={props.value}>
|
||||
{props.children}
|
||||
@@ -238,11 +238,11 @@ describe('ReactNewContext', () => {
|
||||
}
|
||||
|
||||
function Consumer(props) {
|
||||
Scheduler.yieldValue('Consumer');
|
||||
Scheduler.unstable_yieldValue('Consumer');
|
||||
return (
|
||||
<ContextConsumer>
|
||||
{value => {
|
||||
Scheduler.yieldValue('Consumer render prop');
|
||||
Scheduler.unstable_yieldValue('Consumer render prop');
|
||||
return <span prop={'Result: ' + value} />;
|
||||
}}
|
||||
</ContextConsumer>
|
||||
@@ -254,13 +254,13 @@ describe('ReactNewContext', () => {
|
||||
return false;
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Indirection');
|
||||
Scheduler.unstable_yieldValue('Indirection');
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
function App(props) {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return (
|
||||
<Provider value={props.value}>
|
||||
<Indirection>
|
||||
@@ -463,7 +463,7 @@ describe('ReactNewContext', () => {
|
||||
const ContextConsumer = getConsumer(Context);
|
||||
|
||||
function Provider(props) {
|
||||
Scheduler.yieldValue('Provider');
|
||||
Scheduler.unstable_yieldValue('Provider');
|
||||
return (
|
||||
<Context.Provider value={props.value}>
|
||||
{props.children}
|
||||
@@ -472,11 +472,11 @@ describe('ReactNewContext', () => {
|
||||
}
|
||||
|
||||
function Consumer(props) {
|
||||
Scheduler.yieldValue('Consumer');
|
||||
Scheduler.unstable_yieldValue('Consumer');
|
||||
return (
|
||||
<ContextConsumer>
|
||||
{value => {
|
||||
Scheduler.yieldValue('Consumer render prop');
|
||||
Scheduler.unstable_yieldValue('Consumer render prop');
|
||||
return <span prop={'Result: ' + value} />;
|
||||
}}
|
||||
</ContextConsumer>
|
||||
@@ -488,13 +488,13 @@ describe('ReactNewContext', () => {
|
||||
return false;
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('Indirection');
|
||||
Scheduler.unstable_yieldValue('Indirection');
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
function App(props) {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return (
|
||||
<Provider value={props.value}>
|
||||
<Indirection>
|
||||
@@ -605,7 +605,7 @@ describe('ReactNewContext', () => {
|
||||
return (
|
||||
<Consumer unstable_observedBits={0b01}>
|
||||
{value => {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return <span prop={'Foo: ' + value.foo} />;
|
||||
}}
|
||||
</Consumer>
|
||||
@@ -616,7 +616,7 @@ describe('ReactNewContext', () => {
|
||||
return (
|
||||
<Consumer unstable_observedBits={0b10}>
|
||||
{value => {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return <span prop={'Bar: ' + value.bar} />;
|
||||
}}
|
||||
</Consumer>
|
||||
@@ -704,7 +704,7 @@ describe('ReactNewContext', () => {
|
||||
return (
|
||||
<Consumer unstable_observedBits={0b01}>
|
||||
{value => {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<React.Fragment>
|
||||
<span prop={'Foo: ' + value.foo} />
|
||||
@@ -720,7 +720,7 @@ describe('ReactNewContext', () => {
|
||||
return (
|
||||
<Consumer unstable_observedBits={0b10}>
|
||||
{value => {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return (
|
||||
<React.Fragment>
|
||||
<span prop={'Bar: ' + value.bar} />
|
||||
@@ -808,7 +808,7 @@ describe('ReactNewContext', () => {
|
||||
class Child extends React.Component {
|
||||
state = {step: 0};
|
||||
render() {
|
||||
Scheduler.yieldValue('Child');
|
||||
Scheduler.unstable_yieldValue('Child');
|
||||
return (
|
||||
<span
|
||||
prop={`Context: ${this.props.context}, Step: ${
|
||||
@@ -824,7 +824,7 @@ describe('ReactNewContext', () => {
|
||||
<Context.Provider value={props.value}>
|
||||
<Consumer>
|
||||
{value => {
|
||||
Scheduler.yieldValue('Consumer render prop');
|
||||
Scheduler.unstable_yieldValue('Consumer render prop');
|
||||
return <Child ref={inst => (child = inst)} context={value} />;
|
||||
}}
|
||||
</Consumer>
|
||||
@@ -847,24 +847,24 @@ describe('ReactNewContext', () => {
|
||||
const Consumer = getConsumer(Context);
|
||||
|
||||
function renderChildValue(value) {
|
||||
Scheduler.yieldValue('Consumer');
|
||||
Scheduler.unstable_yieldValue('Consumer');
|
||||
return <span prop={value} />;
|
||||
}
|
||||
|
||||
function ChildWithInlineRenderCallback() {
|
||||
Scheduler.yieldValue('ChildWithInlineRenderCallback');
|
||||
Scheduler.unstable_yieldValue('ChildWithInlineRenderCallback');
|
||||
// Note: we are intentionally passing an inline arrow. Don't refactor.
|
||||
return <Consumer>{value => renderChildValue(value)}</Consumer>;
|
||||
}
|
||||
|
||||
function ChildWithCachedRenderCallback() {
|
||||
Scheduler.yieldValue('ChildWithCachedRenderCallback');
|
||||
Scheduler.unstable_yieldValue('ChildWithCachedRenderCallback');
|
||||
return <Consumer>{renderChildValue}</Consumer>;
|
||||
}
|
||||
|
||||
class PureIndirection extends React.PureComponent {
|
||||
render() {
|
||||
Scheduler.yieldValue('PureIndirection');
|
||||
Scheduler.unstable_yieldValue('PureIndirection');
|
||||
return (
|
||||
<React.Fragment>
|
||||
<ChildWithInlineRenderCallback />
|
||||
@@ -876,7 +876,7 @@ describe('ReactNewContext', () => {
|
||||
|
||||
class App extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return (
|
||||
<Context.Provider value={this.props.value}>
|
||||
<PureIndirection />
|
||||
@@ -988,7 +988,7 @@ describe('ReactNewContext', () => {
|
||||
};
|
||||
|
||||
render() {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return (
|
||||
<Context.Provider value={this.state.step}>
|
||||
<StaticContent />
|
||||
@@ -1016,7 +1016,7 @@ describe('ReactNewContext', () => {
|
||||
return (
|
||||
<ContextConsumer>
|
||||
{value => {
|
||||
Scheduler.yieldValue('Consumer');
|
||||
Scheduler.unstable_yieldValue('Consumer');
|
||||
return <span prop={value} />;
|
||||
}}
|
||||
</ContextConsumer>
|
||||
@@ -1079,7 +1079,7 @@ describe('ReactNewContext', () => {
|
||||
const Context = React.createContext(0);
|
||||
|
||||
function Foo(props) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1119,14 +1119,14 @@ describe('ReactNewContext', () => {
|
||||
const Context = React.createContext(0);
|
||||
|
||||
function Child() {
|
||||
Scheduler.yieldValue('Child');
|
||||
Scheduler.unstable_yieldValue('Child');
|
||||
return <span prop="Child" />;
|
||||
}
|
||||
|
||||
const children = <Child />;
|
||||
|
||||
function App(props) {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return (
|
||||
<Context.Provider value={props.value}>{children}</Context.Provider>
|
||||
);
|
||||
@@ -1150,7 +1150,7 @@ describe('ReactNewContext', () => {
|
||||
const Context = React.createContext(0);
|
||||
|
||||
function Child() {
|
||||
Scheduler.yieldValue('Child');
|
||||
Scheduler.unstable_yieldValue('Child');
|
||||
return <span prop="Child" />;
|
||||
}
|
||||
|
||||
@@ -1165,7 +1165,7 @@ describe('ReactNewContext', () => {
|
||||
return {legacyValue: this.state.legacyValue};
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue('LegacyProvider');
|
||||
Scheduler.unstable_yieldValue('LegacyProvider');
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
@@ -1173,7 +1173,7 @@ describe('ReactNewContext', () => {
|
||||
class App extends React.Component {
|
||||
state = {value: 1};
|
||||
render() {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return (
|
||||
<Context.Provider value={this.state.value}>
|
||||
{this.props.children}
|
||||
@@ -1299,12 +1299,12 @@ describe('ReactNewContext', () => {
|
||||
};
|
||||
|
||||
renderConsumer = context => {
|
||||
Scheduler.yieldValue('App#renderConsumer');
|
||||
Scheduler.unstable_yieldValue('App#renderConsumer');
|
||||
return <span prop={this.state.text} />;
|
||||
};
|
||||
|
||||
render() {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return (
|
||||
<Context.Provider value={this.props.value}>
|
||||
<Consumer>{this.renderConsumer}</Consumer>
|
||||
@@ -1439,12 +1439,12 @@ describe('ReactNewContext', () => {
|
||||
};
|
||||
|
||||
renderConsumer = context => {
|
||||
Scheduler.yieldValue('App#renderConsumer');
|
||||
Scheduler.unstable_yieldValue('App#renderConsumer');
|
||||
return <span prop={this.state.text} />;
|
||||
};
|
||||
|
||||
render() {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return (
|
||||
<Context.Provider value={this.props.value}>
|
||||
<Consumer>{this.renderConsumer}</Consumer>
|
||||
@@ -1571,12 +1571,12 @@ describe('ReactNewContext', () => {
|
||||
};
|
||||
|
||||
renderConsumer = context => {
|
||||
Scheduler.yieldValue('App#renderConsumer');
|
||||
Scheduler.unstable_yieldValue('App#renderConsumer');
|
||||
return <span prop={this.state.text} />;
|
||||
};
|
||||
|
||||
render() {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return (
|
||||
<Context.Provider value={this.props.value}>
|
||||
<Consumer>{this.renderConsumer}</Consumer>
|
||||
@@ -1699,7 +1699,7 @@ describe('ReactNewContext', () => {
|
||||
return false;
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue();
|
||||
Scheduler.unstable_yieldValue();
|
||||
if (this.props.depth >= this.props.maxDepth) {
|
||||
return null;
|
||||
}
|
||||
@@ -1777,7 +1777,7 @@ describe('ReactNewContext', () => {
|
||||
actions.forEach(action => {
|
||||
switch (action.type) {
|
||||
case FLUSH_ALL:
|
||||
Scheduler.unstable_flushWithoutYielding();
|
||||
Scheduler.unstable_flushAllWithoutAsserting();
|
||||
break;
|
||||
case FLUSH:
|
||||
Scheduler.unstable_flushNumberOfYields(action.unitsOfWork);
|
||||
@@ -1795,7 +1795,7 @@ describe('ReactNewContext', () => {
|
||||
assertConsistentTree();
|
||||
});
|
||||
|
||||
Scheduler.unstable_flushWithoutYielding();
|
||||
Scheduler.unstable_flushAllWithoutAsserting();
|
||||
assertConsistentTree(finalExpectedValues);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,9 @@ describe('ReactNoop.act()', () => {
|
||||
function App() {
|
||||
let [ctr, setCtr] = React.useState(0);
|
||||
async function someAsyncFunction() {
|
||||
Scheduler.yieldValue('stage 1');
|
||||
Scheduler.unstable_yieldValue('stage 1');
|
||||
await null;
|
||||
Scheduler.yieldValue('stage 2');
|
||||
Scheduler.unstable_yieldValue('stage 2');
|
||||
await null;
|
||||
setCtr(1);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,9 @@ describe('ReactSchedulerIntegration', () => {
|
||||
|
||||
it('has correct priority during rendering', () => {
|
||||
function ReadPriority() {
|
||||
Scheduler.yieldValue('Priority: ' + getCurrentPriorityAsString());
|
||||
Scheduler.unstable_yieldValue(
|
||||
'Priority: ' + getCurrentPriorityAsString(),
|
||||
);
|
||||
return null;
|
||||
}
|
||||
ReactNoop.render(<ReadPriority />);
|
||||
@@ -76,7 +78,9 @@ describe('ReactSchedulerIntegration', () => {
|
||||
|
||||
it('has correct priority when continuing a render after yielding', () => {
|
||||
function ReadPriority() {
|
||||
Scheduler.yieldValue('Priority: ' + getCurrentPriorityAsString());
|
||||
Scheduler.unstable_yieldValue(
|
||||
'Priority: ' + getCurrentPriorityAsString(),
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -106,9 +110,11 @@ describe('ReactSchedulerIntegration', () => {
|
||||
it('layout effects have immediate priority', () => {
|
||||
const {useLayoutEffect} = React;
|
||||
function ReadPriority() {
|
||||
Scheduler.yieldValue('Render priority: ' + getCurrentPriorityAsString());
|
||||
Scheduler.unstable_yieldValue(
|
||||
'Render priority: ' + getCurrentPriorityAsString(),
|
||||
);
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
'Layout priority: ' + getCurrentPriorityAsString(),
|
||||
);
|
||||
});
|
||||
@@ -125,9 +131,11 @@ describe('ReactSchedulerIntegration', () => {
|
||||
it('passive effects have the same priority as render', () => {
|
||||
const {useEffect} = React;
|
||||
function ReadPriority() {
|
||||
Scheduler.yieldValue('Render priority: ' + getCurrentPriorityAsString());
|
||||
Scheduler.unstable_yieldValue(
|
||||
'Render priority: ' + getCurrentPriorityAsString(),
|
||||
);
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
'Passive priority: ' + getCurrentPriorityAsString(),
|
||||
);
|
||||
});
|
||||
@@ -153,7 +161,9 @@ describe('ReactSchedulerIntegration', () => {
|
||||
|
||||
it('after completing a level of work, infers priority of the next batch based on its expiration time', () => {
|
||||
function App({label}) {
|
||||
Scheduler.yieldValue(`${label} [${getCurrentPriorityAsString()}]`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`${label} [${getCurrentPriorityAsString()}]`,
|
||||
);
|
||||
return label;
|
||||
}
|
||||
|
||||
@@ -172,20 +182,20 @@ describe('ReactSchedulerIntegration', () => {
|
||||
|
||||
const root = ReactNoop.createRoot();
|
||||
root.render('Initial');
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('A'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('B'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('C'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('A'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('B'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('C'));
|
||||
|
||||
// Schedule a React render. React will request a paint after committing it.
|
||||
root.render('Update');
|
||||
|
||||
// Advance time just to be sure the next tasks have lower priority
|
||||
Scheduler.advanceTime(2000);
|
||||
Scheduler.unstable_advanceTime(2000);
|
||||
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('D'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('E'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('D'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('E'));
|
||||
|
||||
// Flush everything up to the next paint. Should yield after the
|
||||
// React commit.
|
||||
|
||||
@@ -40,12 +40,12 @@ describe('ReactSuspense', () => {
|
||||
listeners = [{resolve, reject}];
|
||||
setTimeout(() => {
|
||||
if (textResourceShouldFail) {
|
||||
Scheduler.yieldValue(`Promise rejected [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Promise rejected [${text}]`);
|
||||
status = 'rejected';
|
||||
value = new Error('Failed to load: ' + text);
|
||||
listeners.forEach(listener => listener.reject(value));
|
||||
} else {
|
||||
Scheduler.yieldValue(`Promise resolved [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Promise resolved [${text}]`);
|
||||
status = 'resolved';
|
||||
value = text;
|
||||
listeners.forEach(listener => listener.resolve(value));
|
||||
@@ -72,7 +72,7 @@ describe('ReactSuspense', () => {
|
||||
});
|
||||
|
||||
function Text(props) {
|
||||
Scheduler.yieldValue(props.text);
|
||||
Scheduler.unstable_yieldValue(props.text);
|
||||
return props.text;
|
||||
}
|
||||
|
||||
@@ -80,13 +80,13 @@ describe('ReactSuspense', () => {
|
||||
const text = props.text;
|
||||
try {
|
||||
TextResource.read([props.text, props.ms]);
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return text;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
@@ -94,12 +94,12 @@ describe('ReactSuspense', () => {
|
||||
|
||||
it('suspends rendering and continues later', () => {
|
||||
function Bar(props) {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return props.children;
|
||||
}
|
||||
|
||||
function Foo({renderBar}) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<Suspense fallback={<Text text="Loading..." />}>
|
||||
{renderBar ? (
|
||||
@@ -211,10 +211,10 @@ describe('ReactSuspense', () => {
|
||||
|
||||
function Async() {
|
||||
if (!didResolve) {
|
||||
Scheduler.yieldValue('Suspend!');
|
||||
Scheduler.unstable_yieldValue('Suspend!');
|
||||
throw thenable;
|
||||
}
|
||||
Scheduler.yieldValue('Async');
|
||||
Scheduler.unstable_yieldValue('Async');
|
||||
return 'Async';
|
||||
}
|
||||
|
||||
@@ -266,10 +266,10 @@ describe('ReactSuspense', () => {
|
||||
it('mounts a lazy class component in non-concurrent mode', async () => {
|
||||
class Class extends React.Component {
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue('Did mount: ' + this.props.label);
|
||||
Scheduler.unstable_yieldValue('Did mount: ' + this.props.label);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue('Did update: ' + this.props.label);
|
||||
Scheduler.unstable_yieldValue('Did update: ' + this.props.label);
|
||||
}
|
||||
render() {
|
||||
return <Text text={this.props.label} />;
|
||||
@@ -346,13 +346,13 @@ describe('ReactSuspense', () => {
|
||||
it('a mounted class component can suspend without losing state', () => {
|
||||
class TextWithLifecycle extends React.Component {
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(`Mount [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount [${this.props.text}]`);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue(`Update [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Update [${this.props.text}]`);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
Scheduler.yieldValue(`Unmount [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Unmount [${this.props.text}]`);
|
||||
}
|
||||
render() {
|
||||
return <Text {...this.props} />;
|
||||
@@ -363,15 +363,17 @@ describe('ReactSuspense', () => {
|
||||
class AsyncTextWithLifecycle extends React.Component {
|
||||
state = {step: 1};
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(`Mount [${this.props.text}:${this.state.step}]`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Mount [${this.props.text}:${this.state.step}]`,
|
||||
);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Update [${this.props.text}:${this.state.step}]`,
|
||||
);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
Scheduler.yieldValue(
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Unmount [${this.props.text}:${this.state.step}]`,
|
||||
);
|
||||
}
|
||||
@@ -381,13 +383,13 @@ describe('ReactSuspense', () => {
|
||||
const ms = this.props.ms;
|
||||
try {
|
||||
TextResource.read([text, ms]);
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return text;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
@@ -572,20 +574,20 @@ describe('ReactSuspense', () => {
|
||||
it('suspends in a class that has componentWillUnmount and is then deleted', () => {
|
||||
class AsyncTextWithUnmount extends React.Component {
|
||||
componentWillUnmount() {
|
||||
Scheduler.yieldValue('will unmount');
|
||||
Scheduler.unstable_yieldValue('will unmount');
|
||||
}
|
||||
render() {
|
||||
const text = this.props.text;
|
||||
const ms = this.props.ms;
|
||||
try {
|
||||
TextResource.read([text, ms]);
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return text;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
@@ -616,20 +618,20 @@ describe('ReactSuspense', () => {
|
||||
|
||||
useLayoutEffect(
|
||||
() => {
|
||||
Scheduler.yieldValue('Did commit: ' + text);
|
||||
Scheduler.unstable_yieldValue('Did commit: ' + text);
|
||||
},
|
||||
[text],
|
||||
);
|
||||
|
||||
try {
|
||||
TextResource.read([props.text, props.ms]);
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return text;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
@@ -852,13 +854,13 @@ describe('ReactSuspense', () => {
|
||||
const fullText = `${text}:${step}`;
|
||||
try {
|
||||
TextResource.read([fullText, ms]);
|
||||
Scheduler.yieldValue(fullText);
|
||||
Scheduler.unstable_yieldValue(fullText);
|
||||
return fullText;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${fullText}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${fullText}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${fullText}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${fullText}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ describe('ReactSuspenseFuzz', () => {
|
||||
};
|
||||
const timeoutID = setTimeout(() => {
|
||||
pendingTasks.delete(task);
|
||||
Scheduler.yieldValue(task.label);
|
||||
Scheduler.unstable_yieldValue(task.label);
|
||||
setStep(i + 1);
|
||||
}, remountAfter);
|
||||
pendingTasks.add(task);
|
||||
@@ -89,7 +89,7 @@ describe('ReactSuspenseFuzz', () => {
|
||||
};
|
||||
const timeoutID = setTimeout(() => {
|
||||
pendingTasks.delete(task);
|
||||
Scheduler.yieldValue(task.label);
|
||||
Scheduler.unstable_yieldValue(task.label);
|
||||
setStep([i + 1, suspendFor]);
|
||||
}, beginAfter);
|
||||
pendingTasks.add(task);
|
||||
@@ -121,36 +121,36 @@ describe('ReactSuspenseFuzz', () => {
|
||||
setTimeout(() => {
|
||||
cache.set(fullText, fullText);
|
||||
pendingTasks.delete(task);
|
||||
Scheduler.yieldValue(task.label);
|
||||
Scheduler.unstable_yieldValue(task.label);
|
||||
resolve();
|
||||
}, delay);
|
||||
},
|
||||
};
|
||||
cache.set(fullText, thenable);
|
||||
Scheduler.yieldValue(`Suspended! [${fullText}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspended! [${fullText}]`);
|
||||
throw thenable;
|
||||
} else if (typeof resolvedText.then === 'function') {
|
||||
const thenable = resolvedText;
|
||||
Scheduler.yieldValue(`Suspended! [${fullText}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspended! [${fullText}]`);
|
||||
throw thenable;
|
||||
}
|
||||
} else {
|
||||
resolvedText = fullText;
|
||||
}
|
||||
|
||||
Scheduler.yieldValue(resolvedText);
|
||||
Scheduler.unstable_yieldValue(resolvedText);
|
||||
return resolvedText;
|
||||
}
|
||||
|
||||
function resolveAllTasks() {
|
||||
Scheduler.unstable_flushWithoutYielding();
|
||||
Scheduler.unstable_flushAllWithoutAsserting();
|
||||
let elapsedTime = 0;
|
||||
while (pendingTasks && pendingTasks.size > 0) {
|
||||
if ((elapsedTime += 1000) > 1000000) {
|
||||
throw new Error('Something did not resolve properly.');
|
||||
}
|
||||
ReactNoop.act(() => jest.advanceTimersByTime(1000));
|
||||
Scheduler.unstable_flushWithoutYielding();
|
||||
Scheduler.unstable_flushAllWithoutAsserting();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('ReactSuspenseList', () => {
|
||||
});
|
||||
|
||||
function Text(props) {
|
||||
Scheduler.yieldValue(props.text);
|
||||
Scheduler.unstable_yieldValue(props.text);
|
||||
return <span>{props.text}</span>;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('ReactSuspenseList', () => {
|
||||
let resolved = false;
|
||||
let Component = function() {
|
||||
if (!resolved) {
|
||||
Scheduler.yieldValue('Suspend! [' + text + ']');
|
||||
Scheduler.unstable_yieldValue('Suspend! [' + text + ']');
|
||||
throw promise;
|
||||
}
|
||||
return <Text text={text} />;
|
||||
@@ -54,7 +54,7 @@ describe('ReactSuspenseList', () => {
|
||||
|
||||
ReactNoop.render(<Foo />);
|
||||
|
||||
expect(() => Scheduler.flushAll()).toWarnDev([
|
||||
expect(() => Scheduler.unstable_flushAll()).toWarnDev([
|
||||
'Warning: "something" is not a supported revealOrder on ' +
|
||||
'<SuspenseList />. Did you mean "together", "forwards" or "backwards"?' +
|
||||
'\n in SuspenseList (at **)' +
|
||||
@@ -73,7 +73,7 @@ describe('ReactSuspenseList', () => {
|
||||
|
||||
ReactNoop.render(<Foo />);
|
||||
|
||||
expect(() => Scheduler.flushAll()).toWarnDev([
|
||||
expect(() => Scheduler.unstable_flushAll()).toWarnDev([
|
||||
'Warning: "TOGETHER" is not a valid value for revealOrder on ' +
|
||||
'<SuspenseList />. Use lowercase "together" instead.' +
|
||||
'\n in SuspenseList (at **)' +
|
||||
@@ -92,7 +92,7 @@ describe('ReactSuspenseList', () => {
|
||||
|
||||
ReactNoop.render(<Foo />);
|
||||
|
||||
expect(() => Scheduler.flushAll()).toWarnDev([
|
||||
expect(() => Scheduler.unstable_flushAll()).toWarnDev([
|
||||
'Warning: "forward" is not a valid value for revealOrder on ' +
|
||||
'<SuspenseList />. React uses the -s suffix in the spelling. ' +
|
||||
'Use "forwards" instead.' +
|
||||
@@ -1050,12 +1050,12 @@ describe('ReactSuspenseList', () => {
|
||||
|
||||
expect(Scheduler).toFlushAndYieldThrough(['A']);
|
||||
|
||||
Scheduler.advanceTime(300);
|
||||
Scheduler.unstable_advanceTime(300);
|
||||
jest.advanceTimersByTime(300);
|
||||
|
||||
expect(Scheduler).toFlushAndYieldThrough(['B']);
|
||||
|
||||
Scheduler.advanceTime(300);
|
||||
Scheduler.unstable_advanceTime(300);
|
||||
jest.advanceTimersByTime(300);
|
||||
|
||||
// We've still not been able to show anything on the screen even though
|
||||
|
||||
@@ -46,12 +46,12 @@ describe('ReactSuspensePlaceholder', () => {
|
||||
listeners = [{resolve, reject}];
|
||||
setTimeout(() => {
|
||||
if (textResourceShouldFail) {
|
||||
Scheduler.yieldValue(`Promise rejected [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Promise rejected [${text}]`);
|
||||
status = 'rejected';
|
||||
value = new Error('Failed to load: ' + text);
|
||||
listeners.forEach(listener => listener.reject(value));
|
||||
} else {
|
||||
Scheduler.yieldValue(`Promise resolved [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Promise resolved [${text}]`);
|
||||
status = 'resolved';
|
||||
value = text;
|
||||
listeners.forEach(listener => listener.resolve(value));
|
||||
@@ -78,22 +78,22 @@ describe('ReactSuspensePlaceholder', () => {
|
||||
});
|
||||
|
||||
function Text({fakeRenderDuration = 0, text = 'Text'}) {
|
||||
Scheduler.advanceTime(fakeRenderDuration);
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_advanceTime(fakeRenderDuration);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
function AsyncText({fakeRenderDuration = 0, ms, text}) {
|
||||
Scheduler.advanceTime(fakeRenderDuration);
|
||||
Scheduler.unstable_advanceTime(fakeRenderDuration);
|
||||
try {
|
||||
TextResource.read([text, ms]);
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return text;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ describe('ReactSuspensePlaceholder', () => {
|
||||
class HiddenText extends React.PureComponent {
|
||||
render() {
|
||||
const text = this.props.text;
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return <span hidden={true}>{text}</span>;
|
||||
}
|
||||
}
|
||||
@@ -278,19 +278,19 @@ describe('ReactSuspensePlaceholder', () => {
|
||||
onRender = jest.fn();
|
||||
|
||||
const Fallback = () => {
|
||||
Scheduler.yieldValue('Fallback');
|
||||
Scheduler.advanceTime(10);
|
||||
Scheduler.unstable_yieldValue('Fallback');
|
||||
Scheduler.unstable_advanceTime(10);
|
||||
return 'Loading...';
|
||||
};
|
||||
|
||||
const Suspending = () => {
|
||||
Scheduler.yieldValue('Suspending');
|
||||
Scheduler.advanceTime(2);
|
||||
Scheduler.unstable_yieldValue('Suspending');
|
||||
Scheduler.unstable_advanceTime(2);
|
||||
return <AsyncText ms={1000} text="Loaded" fakeRenderDuration={1} />;
|
||||
};
|
||||
|
||||
App = ({shouldSuspend, text = 'Text', textRenderDuration = 5}) => {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return (
|
||||
<Profiler id="root" onRender={onRender}>
|
||||
<Suspense fallback={<Fallback />}>
|
||||
|
||||
@@ -26,10 +26,10 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
return new Promise((resolve, reject) =>
|
||||
setTimeout(() => {
|
||||
if (textResourceShouldFail) {
|
||||
Scheduler.yieldValue(`Promise rejected [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Promise rejected [${text}]`);
|
||||
reject(new Error('Failed to load: ' + text));
|
||||
} else {
|
||||
Scheduler.yieldValue(`Promise resolved [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Promise resolved [${text}]`);
|
||||
resolve(text);
|
||||
}
|
||||
}, ms),
|
||||
@@ -66,7 +66,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
}
|
||||
|
||||
function Text(props) {
|
||||
Scheduler.yieldValue(props.text);
|
||||
Scheduler.unstable_yieldValue(props.text);
|
||||
return <span prop={props.text} ref={props.hostRef} />;
|
||||
}
|
||||
|
||||
@@ -74,13 +74,13 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
const text = props.text;
|
||||
try {
|
||||
TextResource.read([props.text, props.ms]);
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return <span prop={text} />;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
ReactNoop.render(<Foo />);
|
||||
|
||||
expect(() => Scheduler.flushAll()).toWarnDev([
|
||||
expect(() => Scheduler.unstable_flushAll()).toWarnDev([
|
||||
'Warning: maxDuration has been removed from React. ' +
|
||||
'Remove the maxDuration prop.' +
|
||||
'\n in Suspense (at **)' +
|
||||
@@ -107,12 +107,12 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
it('does not restart rendering for initial render', async () => {
|
||||
function Bar(props) {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return props.children;
|
||||
}
|
||||
|
||||
function Foo() {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Suspense fallback={<Text text="Loading..." />}>
|
||||
@@ -142,7 +142,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
|
||||
// Flush the promise completely
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
await advanceTimers(100);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
|
||||
|
||||
@@ -171,12 +171,12 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
it('suspends rendering and continues later', async () => {
|
||||
function Bar(props) {
|
||||
Scheduler.yieldValue('Bar');
|
||||
Scheduler.unstable_yieldValue('Bar');
|
||||
return props.children;
|
||||
}
|
||||
|
||||
function Foo({renderBar}) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<Suspense fallback={<Text text="Loading..." />}>
|
||||
{renderBar ? (
|
||||
@@ -772,7 +772,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
<AsyncText text="B" ms={100} />
|
||||
</Suspense>,
|
||||
);
|
||||
Scheduler.advanceTime(10000);
|
||||
Scheduler.unstable_advanceTime(10000);
|
||||
expect(Scheduler).toHaveYielded([
|
||||
'Suspend! [A]',
|
||||
'Suspend! [B]',
|
||||
@@ -884,10 +884,10 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
it('flushes all expired updates in a single batch', async () => {
|
||||
class Foo extends React.Component {
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue('Commit: ' + this.props.text);
|
||||
Scheduler.unstable_yieldValue('Commit: ' + this.props.text);
|
||||
}
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue('Commit: ' + this.props.text);
|
||||
Scheduler.unstable_yieldValue('Commit: ' + this.props.text);
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
@@ -909,7 +909,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
jest.advanceTimersByTime(1000);
|
||||
ReactNoop.render(<Foo text="goodbye" />);
|
||||
|
||||
Scheduler.advanceTime(10000);
|
||||
Scheduler.unstable_advanceTime(10000);
|
||||
jest.advanceTimersByTime(10000);
|
||||
|
||||
expect(Scheduler).toHaveYielded([
|
||||
@@ -919,7 +919,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
]);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
|
||||
|
||||
Scheduler.advanceTime(20000);
|
||||
Scheduler.unstable_advanceTime(20000);
|
||||
await advanceTimers(20000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [goodbye]']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
|
||||
@@ -932,7 +932,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
// Regression test. This test used to fall into an infinite loop.
|
||||
function ExpensiveText({text}) {
|
||||
// This causes the update to expire.
|
||||
Scheduler.advanceTime(10000);
|
||||
Scheduler.unstable_advanceTime(10000);
|
||||
// Then something suspends.
|
||||
return <AsyncText text={text} ms={200000} />;
|
||||
}
|
||||
@@ -1044,7 +1044,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
// Update.
|
||||
text.current.setState({step: 2}, () =>
|
||||
Scheduler.yieldValue('Update did commit'),
|
||||
Scheduler.unstable_yieldValue('Update did commit'),
|
||||
);
|
||||
|
||||
expect(ReactNoop.flushNextYield()).toEqual([
|
||||
@@ -1078,10 +1078,10 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
it('does not re-render siblings in loose mode', async () => {
|
||||
class TextWithLifecycle extends React.Component {
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(`Mount [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount [${this.props.text}]`);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue(`Update [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Update [${this.props.text}]`);
|
||||
}
|
||||
render() {
|
||||
return <Text {...this.props} />;
|
||||
@@ -1090,10 +1090,10 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
class AsyncTextWithLifecycle extends React.Component {
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(`Mount [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount [${this.props.text}]`);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue(`Update [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Update [${this.props.text}]`);
|
||||
}
|
||||
render() {
|
||||
return <AsyncText {...this.props} />;
|
||||
@@ -1111,7 +1111,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
}
|
||||
|
||||
ReactNoop.renderLegacySyncRoot(<App />, () =>
|
||||
Scheduler.yieldValue('Commit root'),
|
||||
Scheduler.unstable_yieldValue('Commit root'),
|
||||
);
|
||||
expect(Scheduler).toHaveYielded([
|
||||
'A',
|
||||
@@ -1154,24 +1154,24 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const text = props.text;
|
||||
Scheduler.yieldValue('constructor');
|
||||
Scheduler.unstable_yieldValue('constructor');
|
||||
try {
|
||||
TextResource.read([props.text, props.ms]);
|
||||
this.state = {text};
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
}
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue('componentDidMount');
|
||||
Scheduler.unstable_yieldValue('componentDidMount');
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue(this.state.text);
|
||||
Scheduler.unstable_yieldValue(this.state.text);
|
||||
return <span prop={this.state.text} />;
|
||||
}
|
||||
}
|
||||
@@ -1248,7 +1248,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
const child = useRef(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue(ReactNoop.getPendingChildrenAsJSX());
|
||||
Scheduler.unstable_yieldValue(ReactNoop.getPendingChildrenAsJSX());
|
||||
});
|
||||
|
||||
return (
|
||||
@@ -1291,7 +1291,9 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
const child = useRef(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
Scheduler.yieldValue('Child is hidden: ' + child.current.hidden);
|
||||
Scheduler.unstable_yieldValue(
|
||||
'Child is hidden: ' + child.current.hidden,
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
@@ -1329,13 +1331,13 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
it('does not call lifecycles of a suspended component', async () => {
|
||||
class TextWithLifecycle extends React.Component {
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(`Mount [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount [${this.props.text}]`);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue(`Update [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Update [${this.props.text}]`);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
Scheduler.yieldValue(`Unmount [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Unmount [${this.props.text}]`);
|
||||
}
|
||||
render() {
|
||||
return <Text {...this.props} />;
|
||||
@@ -1344,26 +1346,26 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
class AsyncTextWithLifecycle extends React.Component {
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(`Mount [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Mount [${this.props.text}]`);
|
||||
}
|
||||
componentDidUpdate() {
|
||||
Scheduler.yieldValue(`Update [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Update [${this.props.text}]`);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
Scheduler.yieldValue(`Unmount [${this.props.text}]`);
|
||||
Scheduler.unstable_yieldValue(`Unmount [${this.props.text}]`);
|
||||
}
|
||||
render() {
|
||||
const text = this.props.text;
|
||||
const ms = this.props.ms;
|
||||
try {
|
||||
TextResource.read([text, ms]);
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
return <span prop={text} />;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend! [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error! [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error! [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
@@ -1381,7 +1383,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
}
|
||||
|
||||
ReactNoop.renderLegacySyncRoot(<App />, () =>
|
||||
Scheduler.yieldValue('Commit root'),
|
||||
Scheduler.unstable_yieldValue('Commit root'),
|
||||
);
|
||||
expect(Scheduler).toHaveYielded([
|
||||
'A',
|
||||
@@ -1407,7 +1409,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
it('suspends for longer if something took a long (CPU bound) time to render', async () => {
|
||||
function Foo({renderContent}) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<Suspense fallback={<Text text="Loading..." />}>
|
||||
{renderContent ? <AsyncText text="A" ms={5000} /> : null}
|
||||
@@ -1419,12 +1421,12 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(Scheduler).toFlushAndYield(['Foo']);
|
||||
|
||||
ReactNoop.render(<Foo renderContent={true} />);
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
await advanceTimers(100);
|
||||
// Start rendering
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Foo']);
|
||||
// For some reason it took a long time to render Foo.
|
||||
Scheduler.advanceTime(1250);
|
||||
Scheduler.unstable_advanceTime(1250);
|
||||
await advanceTimers(1250);
|
||||
expect(Scheduler).toFlushAndYield([
|
||||
// A suspends
|
||||
@@ -1435,7 +1437,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
|
||||
// Flush some of the time
|
||||
Scheduler.advanceTime(450);
|
||||
Scheduler.unstable_advanceTime(450);
|
||||
await advanceTimers(450);
|
||||
// Because we've already been waiting for so long we can
|
||||
// wait a bit longer. Still nothing...
|
||||
@@ -1443,14 +1445,14 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
|
||||
// Eventually we'll show the fallback.
|
||||
Scheduler.advanceTime(500);
|
||||
Scheduler.unstable_advanceTime(500);
|
||||
await advanceTimers(500);
|
||||
// No need to rerender.
|
||||
expect(Scheduler).toFlushWithoutYielding();
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
|
||||
|
||||
// Flush the promise completely
|
||||
Scheduler.advanceTime(4500);
|
||||
Scheduler.unstable_advanceTime(4500);
|
||||
await advanceTimers(4500);
|
||||
// Renders successfully
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
|
||||
@@ -1460,7 +1462,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
it('does not suspends if a fallback has been shown for a long time', async () => {
|
||||
function Foo() {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<Suspense fallback={<Text text="Loading..." />}>
|
||||
<AsyncText text="A" ms={5000} />
|
||||
@@ -1485,7 +1487,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
|
||||
|
||||
// Wait a long time.
|
||||
Scheduler.advanceTime(5000);
|
||||
Scheduler.unstable_advanceTime(5000);
|
||||
await advanceTimers(5000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
|
||||
|
||||
@@ -1504,7 +1506,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
]);
|
||||
|
||||
// Flush the last promise completely
|
||||
Scheduler.advanceTime(5000);
|
||||
Scheduler.unstable_advanceTime(5000);
|
||||
await advanceTimers(5000);
|
||||
// Renders successfully
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
|
||||
@@ -1514,7 +1516,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
it('does suspend if a fallback has been shown for a short time', async () => {
|
||||
function Foo() {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<Suspense fallback={<Text text="Loading..." />}>
|
||||
<AsyncText text="A" ms={200} />
|
||||
@@ -1539,7 +1541,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
|
||||
|
||||
// Wait a short time.
|
||||
Scheduler.advanceTime(250);
|
||||
Scheduler.unstable_advanceTime(250);
|
||||
await advanceTimers(250);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
|
||||
|
||||
@@ -1554,7 +1556,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
// wait a bit longer. Still nothing...
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
|
||||
|
||||
Scheduler.advanceTime(200);
|
||||
Scheduler.unstable_advanceTime(200);
|
||||
await advanceTimers(200);
|
||||
|
||||
// Before we commit another Promise resolves.
|
||||
@@ -1568,7 +1570,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
it('does not suspend for very long after a higher priority update', async () => {
|
||||
function Foo({renderContent}) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<Suspense fallback={<Text text="Loading..." />}>
|
||||
{renderContent ? <AsyncText text="A" ms={5000} /> : null}
|
||||
@@ -1585,7 +1587,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Foo']);
|
||||
|
||||
// Advance some time.
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
await advanceTimers(100);
|
||||
|
||||
expect(Scheduler).toFlushAndYield([
|
||||
@@ -1597,7 +1599,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
|
||||
// Flush some of the time
|
||||
Scheduler.advanceTime(500);
|
||||
Scheduler.unstable_advanceTime(500);
|
||||
expect(() => {
|
||||
jest.advanceTimersByTime(500);
|
||||
}).toWarnDev(
|
||||
@@ -1616,7 +1618,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
it('warns when suspending inside discrete update', async () => {
|
||||
function A() {
|
||||
Scheduler.yieldValue('A');
|
||||
Scheduler.unstable_yieldValue('A');
|
||||
TextResource.read(['A', 1000]);
|
||||
return 'A';
|
||||
}
|
||||
@@ -1650,7 +1652,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
// Timeout and commit the fallback
|
||||
expect(() => {
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
}).toWarnDev(
|
||||
'The following components suspended during a user-blocking update: A, C',
|
||||
{withoutStack: true},
|
||||
@@ -1659,7 +1661,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
it('shows the parent fallback if the inner fallback should be avoided', async () => {
|
||||
function Foo({showC}) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<Suspense fallback={<Text text="Initial load..." />}>
|
||||
<Suspense
|
||||
@@ -1683,7 +1685,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Initial load...')]);
|
||||
|
||||
// Eventually we resolve and show the data.
|
||||
Scheduler.advanceTime(5000);
|
||||
Scheduler.unstable_advanceTime(5000);
|
||||
await advanceTimers(5000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
|
||||
expect(Scheduler).toFlushAndYield(['A', 'B']);
|
||||
@@ -1699,7 +1701,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
'B',
|
||||
]);
|
||||
// Flush to skip suspended time.
|
||||
Scheduler.advanceTime(600);
|
||||
Scheduler.unstable_advanceTime(600);
|
||||
await advanceTimers(600);
|
||||
// Since the optional suspense boundary is already showing its content,
|
||||
// we have to use the inner fallback instead.
|
||||
@@ -1710,7 +1712,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
]);
|
||||
|
||||
// Later we load the data.
|
||||
Scheduler.advanceTime(5000);
|
||||
Scheduler.unstable_advanceTime(5000);
|
||||
await advanceTimers(5000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [C]']);
|
||||
expect(Scheduler).toFlushAndYield(['A', 'C']);
|
||||
@@ -1719,7 +1721,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
it('favors showing the inner fallback for nested top level avoided fallback', async () => {
|
||||
function Foo({showB}) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<Suspense
|
||||
unstable_avoidThisFallback={true}
|
||||
@@ -1742,7 +1744,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
'Loading B...',
|
||||
]);
|
||||
// Flush to skip suspended time.
|
||||
Scheduler.advanceTime(600);
|
||||
Scheduler.unstable_advanceTime(600);
|
||||
await advanceTimers(600);
|
||||
|
||||
expect(ReactNoop.getChildren()).toEqual([span('A'), span('Loading B...')]);
|
||||
@@ -1750,7 +1752,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
it('keeps showing an avoided parent fallback if it is already showing', async () => {
|
||||
function Foo({showB}) {
|
||||
Scheduler.yieldValue('Foo');
|
||||
Scheduler.unstable_yieldValue('Foo');
|
||||
return (
|
||||
<Suspense fallback={<Text text="Initial load..." />}>
|
||||
<Suspense
|
||||
@@ -1785,7 +1787,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([span('A')]);
|
||||
|
||||
// Flush to skip suspended time.
|
||||
Scheduler.advanceTime(600);
|
||||
Scheduler.unstable_advanceTime(600);
|
||||
await advanceTimers(600);
|
||||
|
||||
expect(ReactNoop.getChildren()).toEqual([span('A'), span('Loading B...')]);
|
||||
@@ -1809,7 +1811,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
// Took a long time to render. This is to ensure we get a long suspense time.
|
||||
// Could also use something like withSuspenseConfig to simulate this.
|
||||
Scheduler.advanceTime(1500);
|
||||
Scheduler.unstable_advanceTime(1500);
|
||||
await advanceTimers(1500);
|
||||
|
||||
expect(Scheduler).toFlushAndYield(['Suspend! [A]', 'Loading A...']);
|
||||
@@ -1826,14 +1828,14 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
|
||||
// Advance time a little bit.
|
||||
Scheduler.advanceTime(150);
|
||||
Scheduler.unstable_advanceTime(150);
|
||||
await advanceTimers(150);
|
||||
|
||||
// We should not have committed yet because we had a long suspense time.
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
|
||||
// Flush to skip suspended time.
|
||||
Scheduler.advanceTime(600);
|
||||
Scheduler.unstable_advanceTime(600);
|
||||
await advanceTimers(600);
|
||||
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Loading A...')]);
|
||||
@@ -1861,12 +1863,12 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
expect(Scheduler).toFlushAndYield(['Suspend! [A]', 'Loading...']);
|
||||
// Only a short time is needed to unsuspend the initial loading state.
|
||||
Scheduler.advanceTime(400);
|
||||
Scheduler.unstable_advanceTime(400);
|
||||
await advanceTimers(400);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
|
||||
|
||||
// Later we load the data.
|
||||
Scheduler.advanceTime(5000);
|
||||
Scheduler.unstable_advanceTime(5000);
|
||||
await advanceTimers(5000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
|
||||
expect(Scheduler).toFlushAndYield(['A']);
|
||||
@@ -1879,11 +1881,11 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
);
|
||||
|
||||
expect(Scheduler).toFlushAndYield(['Suspend! [B]', 'Loading...']);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
await advanceTimers(1000);
|
||||
// Even after a second, we have still not yet flushed the loading state.
|
||||
expect(ReactNoop.getChildren()).toEqual([span('A')]);
|
||||
Scheduler.advanceTime(1100);
|
||||
Scheduler.unstable_advanceTime(1100);
|
||||
await advanceTimers(1100);
|
||||
// After the timeout, we do show the loading state.
|
||||
expect(ReactNoop.getChildren()).toEqual([
|
||||
@@ -1891,7 +1893,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
span('Loading...'),
|
||||
]);
|
||||
// Later we load the data.
|
||||
Scheduler.advanceTime(3000);
|
||||
Scheduler.unstable_advanceTime(3000);
|
||||
await advanceTimers(3000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
|
||||
expect(Scheduler).toFlushAndYield(['B']);
|
||||
@@ -1925,13 +1927,13 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
expect(Scheduler).toFlushAndYield(['Suspend! [A]', 'Loading...']);
|
||||
// Only a short time is needed to unsuspend the initial loading state.
|
||||
Scheduler.advanceTime(400);
|
||||
Scheduler.unstable_advanceTime(400);
|
||||
await advanceTimers(400);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
|
||||
});
|
||||
|
||||
// Later we load the data.
|
||||
Scheduler.advanceTime(5000);
|
||||
Scheduler.unstable_advanceTime(5000);
|
||||
await advanceTimers(5000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
|
||||
expect(Scheduler).toFlushAndYield(['A']);
|
||||
@@ -1945,11 +1947,11 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
);
|
||||
|
||||
expect(Scheduler).toFlushAndYield(['Suspend! [B]', 'Loading...']);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
await advanceTimers(1000);
|
||||
// Even after a second, we have still not yet flushed the loading state.
|
||||
expect(ReactNoop.getChildren()).toEqual([span('A')]);
|
||||
Scheduler.advanceTime(1100);
|
||||
Scheduler.unstable_advanceTime(1100);
|
||||
await advanceTimers(1100);
|
||||
// After the timeout, we do show the loading state.
|
||||
expect(ReactNoop.getChildren()).toEqual([
|
||||
@@ -1958,7 +1960,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
]);
|
||||
});
|
||||
// Later we load the data.
|
||||
Scheduler.advanceTime(3000);
|
||||
Scheduler.unstable_advanceTime(3000);
|
||||
await advanceTimers(3000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
|
||||
expect(Scheduler).toFlushAndYield(['B']);
|
||||
@@ -1995,13 +1997,13 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
expect(Scheduler).toFlushAndYield(['Suspend! [A]', 'Loading...']);
|
||||
// Only a short time is needed to unsuspend the initial loading state.
|
||||
Scheduler.advanceTime(400);
|
||||
Scheduler.unstable_advanceTime(400);
|
||||
await advanceTimers(400);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
|
||||
});
|
||||
|
||||
// Later we load the data.
|
||||
Scheduler.advanceTime(5000);
|
||||
Scheduler.unstable_advanceTime(5000);
|
||||
await advanceTimers(5000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
|
||||
expect(Scheduler).toFlushAndYield(['A']);
|
||||
@@ -2015,11 +2017,11 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
);
|
||||
|
||||
expect(Scheduler).toFlushAndYield(['Suspend! [B]', 'Loading...']);
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
await advanceTimers(1000);
|
||||
// Even after a second, we have still not yet flushed the loading state.
|
||||
expect(ReactNoop.getChildren()).toEqual([span('A')]);
|
||||
Scheduler.advanceTime(1100);
|
||||
Scheduler.unstable_advanceTime(1100);
|
||||
await advanceTimers(1100);
|
||||
// After the timeout, we do show the loading state.
|
||||
expect(ReactNoop.getChildren()).toEqual([
|
||||
@@ -2028,7 +2030,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
]);
|
||||
});
|
||||
// Later we load the data.
|
||||
Scheduler.advanceTime(3000);
|
||||
Scheduler.unstable_advanceTime(3000);
|
||||
await advanceTimers(3000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
|
||||
expect(Scheduler).toFlushAndYield(['B']);
|
||||
@@ -2048,7 +2050,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
// Initial render.
|
||||
ReactNoop.render(<App page="A" />);
|
||||
expect(Scheduler).toFlushAndYield(['Suspend! [A]', 'Loading...']);
|
||||
Scheduler.advanceTime(2000);
|
||||
Scheduler.unstable_advanceTime(2000);
|
||||
await advanceTimers(2000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
|
||||
expect(Scheduler).toFlushAndYield(['A']);
|
||||
@@ -2069,7 +2071,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
expect(Scheduler).toFlushAndYield(['Suspend! [B]', 'Loading...']);
|
||||
// Suspended
|
||||
expect(ReactNoop.getChildren()).toEqual([span('A')]);
|
||||
Scheduler.advanceTime(500);
|
||||
Scheduler.unstable_advanceTime(500);
|
||||
await advanceTimers(500);
|
||||
// Committed loading state.
|
||||
expect(ReactNoop.getChildren()).toEqual([
|
||||
@@ -2077,7 +2079,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
span('Loading...'),
|
||||
]);
|
||||
|
||||
Scheduler.advanceTime(2000);
|
||||
Scheduler.unstable_advanceTime(2000);
|
||||
await advanceTimers(2000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
|
||||
expect(Scheduler).toFlushAndYield(['B']);
|
||||
@@ -2102,11 +2104,11 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
'Loading...',
|
||||
]);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('B')]);
|
||||
Scheduler.advanceTime(1200);
|
||||
Scheduler.unstable_advanceTime(1200);
|
||||
await advanceTimers(1200);
|
||||
// Even after a second, we have still not yet flushed the loading state.
|
||||
expect(ReactNoop.getChildren()).toEqual([span('B')]);
|
||||
Scheduler.advanceTime(1200);
|
||||
Scheduler.unstable_advanceTime(1200);
|
||||
await advanceTimers(1200);
|
||||
// After the two second timeout we show the loading state.
|
||||
expect(ReactNoop.getChildren()).toEqual([
|
||||
@@ -2132,7 +2134,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
// Initial render.
|
||||
ReactNoop.render(<App page="A" />);
|
||||
expect(Scheduler).toFlushAndYield(['Hi!', 'Suspend! [A]', 'Loading...']);
|
||||
Scheduler.advanceTime(3000);
|
||||
Scheduler.unstable_advanceTime(3000);
|
||||
await advanceTimers(3000);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
|
||||
expect(Scheduler).toFlushAndYield(['Hi!', 'A']);
|
||||
@@ -2148,12 +2150,12 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
// Suspended
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Hi!'), span('A')]);
|
||||
Scheduler.advanceTime(1800);
|
||||
Scheduler.unstable_advanceTime(1800);
|
||||
await advanceTimers(1800);
|
||||
expect(Scheduler).toFlushAndYield([]);
|
||||
// We should still be suspended here because this loading state should be avoided.
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Hi!'), span('A')]);
|
||||
Scheduler.advanceTime(1500);
|
||||
Scheduler.unstable_advanceTime(1500);
|
||||
await advanceTimers(1500);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
|
||||
expect(ReactNoop.getChildren()).toEqual([
|
||||
@@ -2196,12 +2198,12 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
// Suspended
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Hi!'), span('A')]);
|
||||
Scheduler.advanceTime(1800);
|
||||
Scheduler.unstable_advanceTime(1800);
|
||||
await advanceTimers(1800);
|
||||
expect(Scheduler).toFlushAndYield([]);
|
||||
// We should still be suspended here because this loading state should be avoided.
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Hi!'), span('A')]);
|
||||
Scheduler.advanceTime(1500);
|
||||
Scheduler.unstable_advanceTime(1500);
|
||||
await advanceTimers(1500);
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
|
||||
expect(ReactNoop.getChildren()).toEqual([
|
||||
@@ -2257,7 +2259,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
transitionToPage('B');
|
||||
// Rendering B is quick and we didn't have enough
|
||||
// time to show the loading indicator.
|
||||
Scheduler.advanceTime(200);
|
||||
Scheduler.unstable_advanceTime(200);
|
||||
await advanceTimers(200);
|
||||
expect(Scheduler).toFlushAndYield(['A', 'L', 'B']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('B')]);
|
||||
@@ -2267,14 +2269,14 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
transitionToPage('C');
|
||||
// Rendering C is a bit slower so we've already showed
|
||||
// the loading indicator.
|
||||
Scheduler.advanceTime(600);
|
||||
Scheduler.unstable_advanceTime(600);
|
||||
await advanceTimers(600);
|
||||
expect(Scheduler).toFlushAndYield(['B', 'L', 'C']);
|
||||
// We're technically done now but we haven't shown the
|
||||
// loading indicator for long enough yet so we'll suspend
|
||||
// while we keep it on the screen a bit longer.
|
||||
expect(ReactNoop.getChildren()).toEqual([span('B'), span('L')]);
|
||||
Scheduler.advanceTime(400);
|
||||
Scheduler.unstable_advanceTime(400);
|
||||
await advanceTimers(400);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('C')]);
|
||||
});
|
||||
@@ -2283,7 +2285,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
transitionToPage('D');
|
||||
// Rendering D is very slow so we've already showed
|
||||
// the loading indicator.
|
||||
Scheduler.advanceTime(1000);
|
||||
Scheduler.unstable_advanceTime(1000);
|
||||
await advanceTimers(1000);
|
||||
expect(Scheduler).toFlushAndYield(['C', 'L', 'D']);
|
||||
// However, since we exceeded the minimum time to show
|
||||
@@ -2309,7 +2311,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
|
||||
|
||||
// Resolve initial render
|
||||
await ReactNoop.act(async () => {
|
||||
Scheduler.advanceTime(2000);
|
||||
Scheduler.unstable_advanceTime(2000);
|
||||
await advanceTimers(2000);
|
||||
});
|
||||
expect(Scheduler).toHaveYielded([
|
||||
|
||||
@@ -2355,7 +2355,7 @@ describe('ReactFresh', () => {
|
||||
const AppV1 = prepare(() => {
|
||||
function Hello() {
|
||||
React.useLayoutEffect(() => {
|
||||
Scheduler.yieldValue('Hello#layout');
|
||||
Scheduler.unstable_yieldValue('Hello#layout');
|
||||
});
|
||||
const [val, setVal] = React.useState(0);
|
||||
return (
|
||||
@@ -2368,7 +2368,7 @@ describe('ReactFresh', () => {
|
||||
|
||||
return function App({offscreen}) {
|
||||
React.useLayoutEffect(() => {
|
||||
Scheduler.yieldValue('App#layout');
|
||||
Scheduler.unstable_yieldValue('App#layout');
|
||||
});
|
||||
return (
|
||||
<div hidden={offscreen}>
|
||||
@@ -2389,7 +2389,7 @@ describe('ReactFresh', () => {
|
||||
patch(() => {
|
||||
function Hello() {
|
||||
React.useLayoutEffect(() => {
|
||||
Scheduler.yieldValue('Hello#layout');
|
||||
Scheduler.unstable_yieldValue('Hello#layout');
|
||||
});
|
||||
const [val, setVal] = React.useState(0);
|
||||
return (
|
||||
@@ -2423,7 +2423,7 @@ describe('ReactFresh', () => {
|
||||
patch(() => {
|
||||
function Hello() {
|
||||
React.useLayoutEffect(() => {
|
||||
Scheduler.yieldValue('Hello#layout');
|
||||
Scheduler.unstable_yieldValue('Hello#layout');
|
||||
});
|
||||
const [val, setVal] = React.useState(0);
|
||||
return (
|
||||
|
||||
@@ -26,7 +26,7 @@ const {ReactCurrentActingRendererSigil} = ReactSharedInternals;
|
||||
|
||||
let hasWarnedAboutMissingMockScheduler = false;
|
||||
const flushWork =
|
||||
Scheduler.unstable_flushWithoutYielding ||
|
||||
Scheduler.unstable_flushAllWithoutAsserting ||
|
||||
function() {
|
||||
if (warnAboutMissingMockScheduler === true) {
|
||||
if (hasWarnedAboutMissingMockScheduler === false) {
|
||||
|
||||
@@ -72,7 +72,7 @@ describe('ReactTestRenderer', () => {
|
||||
const root = ReactTestRenderer.create(<App text="initial" />);
|
||||
PendingResources.initial('initial');
|
||||
await Promise.resolve();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(root.toJSON()).toEqual('initial');
|
||||
|
||||
root.update(<App text="dynamic" />);
|
||||
@@ -80,7 +80,7 @@ describe('ReactTestRenderer', () => {
|
||||
|
||||
PendingResources.dynamic('dynamic');
|
||||
await Promise.resolve();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(root.toJSON()).toEqual('dynamic');
|
||||
|
||||
done();
|
||||
@@ -100,7 +100,7 @@ describe('ReactTestRenderer', () => {
|
||||
const root = ReactTestRenderer.create(<App text="initial" />);
|
||||
PendingResources.initial('initial');
|
||||
await Promise.resolve();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(root.toJSON().children).toEqual(['initial']);
|
||||
|
||||
root.update(<App text="dynamic" />);
|
||||
@@ -108,7 +108,7 @@ describe('ReactTestRenderer', () => {
|
||||
|
||||
PendingResources.dynamic('dynamic');
|
||||
await Promise.resolve();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
expect(root.toJSON().children).toEqual(['dynamic']);
|
||||
|
||||
done();
|
||||
|
||||
@@ -92,9 +92,9 @@ describe('ReactTestRenderer.act()', () => {
|
||||
// This component will keep updating itself until step === 3
|
||||
const [step, proceed] = useReducer(s => (s === 3 ? 3 : s + 1), 1);
|
||||
useEffect(() => {
|
||||
Scheduler.yieldValue('Effect');
|
||||
Scheduler.unstable_yieldValue('Effect');
|
||||
alreadyResolvedPromise.then(() => {
|
||||
Scheduler.yieldValue('Microtask');
|
||||
Scheduler.unstable_yieldValue('Microtask');
|
||||
proceed();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,7 +48,7 @@ describe('ReactTestRendererAsync', () => {
|
||||
|
||||
it('flushAll returns array of yielded values', () => {
|
||||
function Child(props) {
|
||||
Scheduler.yieldValue(props.children);
|
||||
Scheduler.unstable_yieldValue(props.children);
|
||||
return props.children;
|
||||
}
|
||||
function Parent(props) {
|
||||
@@ -74,7 +74,7 @@ describe('ReactTestRendererAsync', () => {
|
||||
|
||||
it('flushThrough flushes until the expected values is yielded', () => {
|
||||
function Child(props) {
|
||||
Scheduler.yieldValue(props.children);
|
||||
Scheduler.unstable_yieldValue(props.children);
|
||||
return props.children;
|
||||
}
|
||||
function Parent(props) {
|
||||
@@ -102,7 +102,7 @@ describe('ReactTestRendererAsync', () => {
|
||||
|
||||
it('supports high priority interruptions', () => {
|
||||
function Child(props) {
|
||||
Scheduler.yieldValue(props.children);
|
||||
Scheduler.unstable_yieldValue(props.children);
|
||||
return props.children;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ describe('ReactTestRendererAsync', () => {
|
||||
describe('Jest matchers', () => {
|
||||
it('toFlushAndYieldThrough', () => {
|
||||
const Yield = ({id}) => {
|
||||
Scheduler.yieldValue(id);
|
||||
Scheduler.unstable_yieldValue(id);
|
||||
return id;
|
||||
};
|
||||
|
||||
@@ -165,7 +165,7 @@ describe('ReactTestRendererAsync', () => {
|
||||
|
||||
it('toFlushAndYield', () => {
|
||||
const Yield = ({id}) => {
|
||||
Scheduler.yieldValue(id);
|
||||
Scheduler.unstable_yieldValue(id);
|
||||
return id;
|
||||
};
|
||||
|
||||
@@ -199,7 +199,7 @@ describe('ReactTestRendererAsync', () => {
|
||||
|
||||
it('toFlushAndThrow', () => {
|
||||
const Yield = ({id}) => {
|
||||
Scheduler.yieldValue(id);
|
||||
Scheduler.unstable_yieldValue(id);
|
||||
return id;
|
||||
};
|
||||
|
||||
@@ -238,7 +238,7 @@ describe('ReactTestRendererAsync', () => {
|
||||
|
||||
it('toHaveYielded', () => {
|
||||
const Yield = ({id}) => {
|
||||
Scheduler.yieldValue(id);
|
||||
Scheduler.unstable_yieldValue(id);
|
||||
return id;
|
||||
};
|
||||
|
||||
@@ -262,7 +262,7 @@ describe('ReactTestRendererAsync', () => {
|
||||
ReactTestRenderer.create(<div />, {
|
||||
unstable_isConcurrent: true,
|
||||
});
|
||||
Scheduler.yieldValue('Something');
|
||||
Scheduler.unstable_yieldValue('Something');
|
||||
expect(() => expect(Scheduler).toFlushWithoutYielding()).toThrow(
|
||||
'Log of yielded values is not empty.',
|
||||
);
|
||||
|
||||
@@ -69,13 +69,13 @@ describe('ReactDOMTracing', () => {
|
||||
it('traces interaction through hidden subtree', () => {
|
||||
const Child = () => {
|
||||
const [didMount, setDidMount] = React.useState(false);
|
||||
Scheduler.yieldValue('Child');
|
||||
Scheduler.unstable_yieldValue('Child');
|
||||
React.useEffect(
|
||||
() => {
|
||||
if (didMount) {
|
||||
Scheduler.yieldValue('Child:update');
|
||||
Scheduler.unstable_yieldValue('Child:update');
|
||||
} else {
|
||||
Scheduler.yieldValue('Child:mount');
|
||||
Scheduler.unstable_yieldValue('Child:mount');
|
||||
setDidMount(true);
|
||||
}
|
||||
},
|
||||
@@ -85,9 +85,9 @@ describe('ReactDOMTracing', () => {
|
||||
};
|
||||
|
||||
const App = () => {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue('App:mount');
|
||||
Scheduler.unstable_yieldValue('App:mount');
|
||||
}, []);
|
||||
return (
|
||||
<div hidden={true}>
|
||||
@@ -142,17 +142,17 @@ describe('ReactDOMTracing', () => {
|
||||
|
||||
it('traces interaction through hidden subtree when there is other pending traced work', () => {
|
||||
const Child = () => {
|
||||
Scheduler.yieldValue('Child');
|
||||
Scheduler.unstable_yieldValue('Child');
|
||||
return <div />;
|
||||
};
|
||||
|
||||
let wrapped = null;
|
||||
|
||||
const App = () => {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
React.useEffect(() => {
|
||||
wrapped = SchedulerTracing.unstable_wrap(() => {});
|
||||
Scheduler.yieldValue('App:mount');
|
||||
Scheduler.unstable_yieldValue('App:mount');
|
||||
}, []);
|
||||
return (
|
||||
<div hidden={true}>
|
||||
@@ -210,13 +210,13 @@ describe('ReactDOMTracing', () => {
|
||||
it('traces interaction through hidden subtree that schedules more idle/never work', () => {
|
||||
const Child = () => {
|
||||
const [didMount, setDidMount] = React.useState(false);
|
||||
Scheduler.yieldValue('Child');
|
||||
Scheduler.unstable_yieldValue('Child');
|
||||
React.useLayoutEffect(
|
||||
() => {
|
||||
if (didMount) {
|
||||
Scheduler.yieldValue('Child:update');
|
||||
Scheduler.unstable_yieldValue('Child:update');
|
||||
} else {
|
||||
Scheduler.yieldValue('Child:mount');
|
||||
Scheduler.unstable_yieldValue('Child:mount');
|
||||
Scheduler.unstable_runWithPriority(
|
||||
Scheduler.unstable_IdlePriority,
|
||||
() => setDidMount(true),
|
||||
@@ -229,9 +229,9 @@ describe('ReactDOMTracing', () => {
|
||||
};
|
||||
|
||||
const App = () => {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue('App:mount');
|
||||
Scheduler.unstable_yieldValue('App:mount');
|
||||
}, []);
|
||||
return (
|
||||
<div hidden={true}>
|
||||
@@ -289,14 +289,14 @@ describe('ReactDOMTracing', () => {
|
||||
|
||||
it('does not continue interactions across pre-existing idle work', () => {
|
||||
const Child = () => {
|
||||
Scheduler.yieldValue('Child');
|
||||
Scheduler.unstable_yieldValue('Child');
|
||||
return <div />;
|
||||
};
|
||||
|
||||
let update = null;
|
||||
|
||||
const WithHiddenWork = () => {
|
||||
Scheduler.yieldValue('WithHiddenWork');
|
||||
Scheduler.unstable_yieldValue('WithHiddenWork');
|
||||
return (
|
||||
<div hidden={true}>
|
||||
<Child />
|
||||
@@ -305,9 +305,9 @@ describe('ReactDOMTracing', () => {
|
||||
};
|
||||
|
||||
const Updater = () => {
|
||||
Scheduler.yieldValue('Updater');
|
||||
Scheduler.unstable_yieldValue('Updater');
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue('Updater:effect');
|
||||
Scheduler.unstable_yieldValue('Updater:effect');
|
||||
});
|
||||
|
||||
const setCount = React.useState(0)[1];
|
||||
@@ -319,9 +319,9 @@ describe('ReactDOMTracing', () => {
|
||||
};
|
||||
|
||||
const App = () => {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue('App:effect');
|
||||
Scheduler.unstable_yieldValue('App:effect');
|
||||
});
|
||||
|
||||
return (
|
||||
@@ -389,7 +389,7 @@ describe('ReactDOMTracing', () => {
|
||||
|
||||
it('should properly trace interactions when there is work of interleaved priorities', () => {
|
||||
const Child = () => {
|
||||
Scheduler.yieldValue('Child');
|
||||
Scheduler.unstable_yieldValue('Child');
|
||||
return <div />;
|
||||
};
|
||||
|
||||
@@ -399,9 +399,9 @@ describe('ReactDOMTracing', () => {
|
||||
const MaybeHiddenWork = () => {
|
||||
const [flag, setFlag] = React.useState(false);
|
||||
scheduleUpdateWithHidden = () => setFlag(true);
|
||||
Scheduler.yieldValue('MaybeHiddenWork');
|
||||
Scheduler.unstable_yieldValue('MaybeHiddenWork');
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue('MaybeHiddenWork:effect');
|
||||
Scheduler.unstable_yieldValue('MaybeHiddenWork:effect');
|
||||
});
|
||||
return flag ? (
|
||||
<div hidden={true}>
|
||||
@@ -411,9 +411,9 @@ describe('ReactDOMTracing', () => {
|
||||
};
|
||||
|
||||
const Updater = () => {
|
||||
Scheduler.yieldValue('Updater');
|
||||
Scheduler.unstable_yieldValue('Updater');
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue('Updater:effect');
|
||||
Scheduler.unstable_yieldValue('Updater:effect');
|
||||
});
|
||||
|
||||
const setCount = React.useState(0)[1];
|
||||
@@ -423,9 +423,9 @@ describe('ReactDOMTracing', () => {
|
||||
};
|
||||
|
||||
const App = () => {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue('App:effect');
|
||||
Scheduler.unstable_yieldValue('App:effect');
|
||||
});
|
||||
|
||||
return (
|
||||
@@ -512,9 +512,9 @@ describe('ReactDOMTracing', () => {
|
||||
const SuspenseList = React.unstable_SuspenseList;
|
||||
const Suspense = React.Suspense;
|
||||
function Text({text}) {
|
||||
Scheduler.yieldValue(text);
|
||||
Scheduler.unstable_yieldValue(text);
|
||||
React.useEffect(() => {
|
||||
Scheduler.yieldValue('Commit ' + text);
|
||||
Scheduler.unstable_yieldValue('Commit ' + text);
|
||||
});
|
||||
return <span>{text}</span>;
|
||||
}
|
||||
@@ -548,12 +548,12 @@ describe('ReactDOMTracing', () => {
|
||||
|
||||
expect(Scheduler).toFlushAndYieldThrough(['A']);
|
||||
|
||||
Scheduler.advanceTime(300);
|
||||
Scheduler.unstable_advanceTime(300);
|
||||
jest.advanceTimersByTime(300);
|
||||
|
||||
expect(Scheduler).toFlushAndYieldThrough(['B']);
|
||||
|
||||
Scheduler.advanceTime(300);
|
||||
Scheduler.unstable_advanceTime(300);
|
||||
jest.advanceTimersByTime(300);
|
||||
|
||||
// Time has now elapsed for so long that we're just going to give up
|
||||
@@ -625,7 +625,7 @@ describe('ReactDOMTracing', () => {
|
||||
|
||||
root.render(<App />);
|
||||
});
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ref.current).not.toBe(null);
|
||||
@@ -685,7 +685,7 @@ describe('ReactDOMTracing', () => {
|
||||
|
||||
root.render(<App />);
|
||||
});
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ref.current).toBe(null);
|
||||
@@ -699,7 +699,7 @@ describe('ReactDOMTracing', () => {
|
||||
suspend = false;
|
||||
resolve();
|
||||
await promise;
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(ref.current).not.toBe(null);
|
||||
|
||||
@@ -59,7 +59,7 @@ function loadModules({
|
||||
}
|
||||
render() {
|
||||
// Simulate time passing when this component is rendered
|
||||
Scheduler.advanceTime(this.props.byAmount);
|
||||
Scheduler.unstable_advanceTime(this.props.byAmount);
|
||||
return this.props.children || null;
|
||||
}
|
||||
};
|
||||
@@ -69,7 +69,7 @@ function loadModules({
|
||||
TextResource = ReactCache.unstable_createResource(([text, ms = 0]) => {
|
||||
resourcePromise = new Promise((resolve, reject) =>
|
||||
setTimeout(() => {
|
||||
Scheduler.yieldValue(`Promise resolved [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Promise resolved [${text}]`);
|
||||
resolve(text);
|
||||
}, ms),
|
||||
);
|
||||
@@ -79,20 +79,20 @@ function loadModules({
|
||||
AsyncText = ({ms, text}) => {
|
||||
try {
|
||||
TextResource.read([text, ms]);
|
||||
Scheduler.yieldValue(`AsyncText [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`AsyncText [${text}]`);
|
||||
return text;
|
||||
} catch (promise) {
|
||||
if (typeof promise.then === 'function') {
|
||||
Scheduler.yieldValue(`Suspend [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Suspend [${text}]`);
|
||||
} else {
|
||||
Scheduler.yieldValue(`Error [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Error [${text}]`);
|
||||
}
|
||||
throw promise;
|
||||
}
|
||||
};
|
||||
|
||||
Text = ({text}) => {
|
||||
Scheduler.yieldValue(`Text [${text}]`);
|
||||
Scheduler.unstable_yieldValue(`Text [${text}]`);
|
||||
return text;
|
||||
};
|
||||
}
|
||||
@@ -237,7 +237,7 @@ describe('Profiler', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
const Yield = ({value}) => {
|
||||
Scheduler.yieldValue(value);
|
||||
Scheduler.unstable_yieldValue(value);
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -268,7 +268,7 @@ describe('Profiler', () => {
|
||||
return {
|
||||
...ActualScheduler,
|
||||
unstable_now: function mockUnstableNow() {
|
||||
ActualScheduler.yieldValue('read current time');
|
||||
ActualScheduler.unstable_yieldValue('read current time');
|
||||
return ActualScheduler.unstable_now();
|
||||
},
|
||||
};
|
||||
@@ -309,7 +309,7 @@ describe('Profiler', () => {
|
||||
it('logs render times for both mount and update', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
const renderer = ReactTestRenderer.create(
|
||||
<React.Profiler id="test" onRender={callback}>
|
||||
@@ -332,7 +332,7 @@ describe('Profiler', () => {
|
||||
|
||||
callback.mockReset();
|
||||
|
||||
Scheduler.advanceTime(20); // 15 -> 35
|
||||
Scheduler.unstable_advanceTime(20); // 15 -> 35
|
||||
|
||||
renderer.update(
|
||||
<React.Profiler id="test" onRender={callback}>
|
||||
@@ -355,7 +355,7 @@ describe('Profiler', () => {
|
||||
|
||||
callback.mockReset();
|
||||
|
||||
Scheduler.advanceTime(20); // 45 -> 65
|
||||
Scheduler.unstable_advanceTime(20); // 45 -> 65
|
||||
|
||||
renderer.update(
|
||||
<React.Profiler id="test" onRender={callback}>
|
||||
@@ -380,7 +380,7 @@ describe('Profiler', () => {
|
||||
it('includes render times of nested Profilers in their parent times', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
ReactTestRenderer.create(
|
||||
<React.Fragment>
|
||||
@@ -415,7 +415,7 @@ describe('Profiler', () => {
|
||||
it('traces sibling Profilers separately', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
ReactTestRenderer.create(
|
||||
<React.Fragment>
|
||||
@@ -448,7 +448,7 @@ describe('Profiler', () => {
|
||||
it('does not include time spent outside of profile root', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
ReactTestRenderer.create(
|
||||
<React.Fragment>
|
||||
@@ -523,7 +523,7 @@ describe('Profiler', () => {
|
||||
it('decreases actual time but not base time when sCU prevents an update', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
const renderer = ReactTestRenderer.create(
|
||||
<React.Profiler id="test" onRender={callback}>
|
||||
@@ -535,7 +535,7 @@ describe('Profiler', () => {
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
|
||||
Scheduler.advanceTime(30); // 28 -> 58
|
||||
Scheduler.unstable_advanceTime(30); // 28 -> 58
|
||||
|
||||
renderer.update(
|
||||
<React.Profiler id="test" onRender={callback}>
|
||||
@@ -566,22 +566,22 @@ describe('Profiler', () => {
|
||||
class WithLifecycles extends React.Component {
|
||||
state = {};
|
||||
static getDerivedStateFromProps() {
|
||||
Scheduler.advanceTime(3);
|
||||
Scheduler.unstable_advanceTime(3);
|
||||
return null;
|
||||
}
|
||||
shouldComponentUpdate() {
|
||||
Scheduler.advanceTime(7);
|
||||
Scheduler.unstable_advanceTime(7);
|
||||
return true;
|
||||
}
|
||||
render() {
|
||||
Scheduler.advanceTime(5);
|
||||
Scheduler.unstable_advanceTime(5);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const callback = jest.fn();
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
const renderer = ReactTestRenderer.create(
|
||||
<React.Profiler id="test" onRender={callback}>
|
||||
@@ -589,7 +589,7 @@ describe('Profiler', () => {
|
||||
</React.Profiler>,
|
||||
);
|
||||
|
||||
Scheduler.advanceTime(15); // 13 -> 28
|
||||
Scheduler.unstable_advanceTime(15); // 13 -> 28
|
||||
|
||||
renderer.update(
|
||||
<React.Profiler id="test" onRender={callback}>
|
||||
@@ -619,12 +619,12 @@ describe('Profiler', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
const Yield = ({renderTime}) => {
|
||||
Scheduler.advanceTime(renderTime);
|
||||
Scheduler.yieldValue('Yield:' + renderTime);
|
||||
Scheduler.unstable_advanceTime(renderTime);
|
||||
Scheduler.unstable_yieldValue('Yield:' + renderTime);
|
||||
return null;
|
||||
};
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
// Render partially, but run out of time before completing.
|
||||
ReactTestRenderer.create(
|
||||
@@ -653,12 +653,12 @@ describe('Profiler', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
const Yield = ({renderTime}) => {
|
||||
Scheduler.advanceTime(renderTime);
|
||||
Scheduler.yieldValue('Yield:' + renderTime);
|
||||
Scheduler.unstable_advanceTime(renderTime);
|
||||
Scheduler.unstable_yieldValue('Yield:' + renderTime);
|
||||
return null;
|
||||
};
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
// Render partially, but don't finish.
|
||||
// This partial render should take 5ms of simulated time.
|
||||
@@ -676,7 +676,7 @@ describe('Profiler', () => {
|
||||
expect(callback).toHaveBeenCalledTimes(0);
|
||||
|
||||
// Simulate time moving forward while frame is paused.
|
||||
Scheduler.advanceTime(50); // 10 -> 60
|
||||
Scheduler.unstable_advanceTime(50); // 10 -> 60
|
||||
|
||||
// Flush the remaining work,
|
||||
// Which should take an additional 10ms of simulated time.
|
||||
@@ -703,12 +703,12 @@ describe('Profiler', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
const Yield = ({renderTime}) => {
|
||||
Scheduler.advanceTime(renderTime);
|
||||
Scheduler.yieldValue('Yield:' + renderTime);
|
||||
Scheduler.unstable_advanceTime(renderTime);
|
||||
Scheduler.unstable_yieldValue('Yield:' + renderTime);
|
||||
return null;
|
||||
};
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
// Render a partially update, but don't finish.
|
||||
// This partial render should take 10ms of simulated time.
|
||||
@@ -723,7 +723,7 @@ describe('Profiler', () => {
|
||||
expect(callback).toHaveBeenCalledTimes(0);
|
||||
|
||||
// Simulate time moving forward while frame is paused.
|
||||
Scheduler.advanceTime(100); // 15 -> 115
|
||||
Scheduler.unstable_advanceTime(100); // 15 -> 115
|
||||
|
||||
// Interrupt with higher priority work.
|
||||
// The interrupted work simulates an additional 5ms of time.
|
||||
@@ -756,12 +756,12 @@ describe('Profiler', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
const Yield = ({renderTime}) => {
|
||||
Scheduler.advanceTime(renderTime);
|
||||
Scheduler.yieldValue('Yield:' + renderTime);
|
||||
Scheduler.unstable_advanceTime(renderTime);
|
||||
Scheduler.unstable_yieldValue('Yield:' + renderTime);
|
||||
return null;
|
||||
};
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
const renderer = ReactTestRenderer.create(
|
||||
<React.Profiler id="test" onRender={callback}>
|
||||
@@ -783,7 +783,7 @@ describe('Profiler', () => {
|
||||
|
||||
callback.mockReset();
|
||||
|
||||
Scheduler.advanceTime(30); // 26 -> 56
|
||||
Scheduler.unstable_advanceTime(30); // 26 -> 56
|
||||
|
||||
// Render a partially update, but don't finish.
|
||||
// This partial render should take 3ms of simulated time.
|
||||
@@ -798,14 +798,14 @@ describe('Profiler', () => {
|
||||
expect(callback).toHaveBeenCalledTimes(0);
|
||||
|
||||
// Simulate time moving forward while frame is paused.
|
||||
Scheduler.advanceTime(100); // 59 -> 159
|
||||
Scheduler.unstable_advanceTime(100); // 59 -> 159
|
||||
|
||||
// Render another 5ms of simulated time.
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Yield:5']);
|
||||
expect(callback).toHaveBeenCalledTimes(0);
|
||||
|
||||
// Simulate time moving forward while frame is paused.
|
||||
Scheduler.advanceTime(100); // 164 -> 264
|
||||
Scheduler.unstable_advanceTime(100); // 164 -> 264
|
||||
|
||||
// Interrupt with higher priority work.
|
||||
// The interrupted work simulates an additional 11ms of time.
|
||||
@@ -837,8 +837,8 @@ describe('Profiler', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
const Yield = ({renderTime}) => {
|
||||
Scheduler.advanceTime(renderTime);
|
||||
Scheduler.yieldValue('Yield:' + renderTime);
|
||||
Scheduler.unstable_advanceTime(renderTime);
|
||||
Scheduler.unstable_yieldValue('Yield:' + renderTime);
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -847,8 +847,10 @@ describe('Profiler', () => {
|
||||
state = {renderTime: 1};
|
||||
render() {
|
||||
first = this;
|
||||
Scheduler.advanceTime(this.state.renderTime);
|
||||
Scheduler.yieldValue('FirstComponent:' + this.state.renderTime);
|
||||
Scheduler.unstable_advanceTime(this.state.renderTime);
|
||||
Scheduler.unstable_yieldValue(
|
||||
'FirstComponent:' + this.state.renderTime,
|
||||
);
|
||||
return <Yield renderTime={4} />;
|
||||
}
|
||||
}
|
||||
@@ -857,13 +859,15 @@ describe('Profiler', () => {
|
||||
state = {renderTime: 2};
|
||||
render() {
|
||||
second = this;
|
||||
Scheduler.advanceTime(this.state.renderTime);
|
||||
Scheduler.yieldValue('SecondComponent:' + this.state.renderTime);
|
||||
Scheduler.unstable_advanceTime(this.state.renderTime);
|
||||
Scheduler.unstable_yieldValue(
|
||||
'SecondComponent:' + this.state.renderTime,
|
||||
);
|
||||
return <Yield renderTime={7} />;
|
||||
}
|
||||
}
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
const renderer = ReactTestRenderer.create(
|
||||
<React.Profiler id="test" onRender={callback}>
|
||||
@@ -891,7 +895,7 @@ describe('Profiler', () => {
|
||||
|
||||
callback.mockClear();
|
||||
|
||||
Scheduler.advanceTime(100); // 19 -> 119
|
||||
Scheduler.unstable_advanceTime(100); // 19 -> 119
|
||||
|
||||
// Render a partially update, but don't finish.
|
||||
// This partial render will take 10ms of actual render time.
|
||||
@@ -900,7 +904,7 @@ describe('Profiler', () => {
|
||||
expect(callback).toHaveBeenCalledTimes(0);
|
||||
|
||||
// Simulate time moving forward while frame is paused.
|
||||
Scheduler.advanceTime(100); // 129 -> 229
|
||||
Scheduler.unstable_advanceTime(100); // 129 -> 229
|
||||
|
||||
// Interrupt with higher priority work.
|
||||
// This simulates a total of 37ms of actual render time.
|
||||
@@ -921,7 +925,7 @@ describe('Profiler', () => {
|
||||
callback.mockClear();
|
||||
|
||||
// Simulate time moving forward while frame is paused.
|
||||
Scheduler.advanceTime(100); // 266 -> 366
|
||||
Scheduler.unstable_advanceTime(100); // 266 -> 366
|
||||
|
||||
// Resume the original low priority update, with rebased state.
|
||||
// This simulates a total of 14ms of actual render time,
|
||||
@@ -957,7 +961,7 @@ describe('Profiler', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
const ThrowsError = () => {
|
||||
Scheduler.advanceTime(3);
|
||||
Scheduler.unstable_advanceTime(3);
|
||||
throw Error('expected error');
|
||||
};
|
||||
|
||||
@@ -967,7 +971,7 @@ describe('Profiler', () => {
|
||||
this.setState({error});
|
||||
}
|
||||
render() {
|
||||
Scheduler.advanceTime(2);
|
||||
Scheduler.unstable_advanceTime(2);
|
||||
return this.state.error === null ? (
|
||||
this.props.children
|
||||
) : (
|
||||
@@ -976,7 +980,7 @@ describe('Profiler', () => {
|
||||
}
|
||||
}
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
ReactTestRenderer.create(
|
||||
<React.Profiler id="test" onRender={callback}>
|
||||
@@ -1036,7 +1040,7 @@ describe('Profiler', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
const ThrowsError = () => {
|
||||
Scheduler.advanceTime(10);
|
||||
Scheduler.unstable_advanceTime(10);
|
||||
throw Error('expected error');
|
||||
};
|
||||
|
||||
@@ -1046,7 +1050,7 @@ describe('Profiler', () => {
|
||||
return {error};
|
||||
}
|
||||
render() {
|
||||
Scheduler.advanceTime(2);
|
||||
Scheduler.unstable_advanceTime(2);
|
||||
return this.state.error === null ? (
|
||||
this.props.children
|
||||
) : (
|
||||
@@ -1055,7 +1059,7 @@ describe('Profiler', () => {
|
||||
}
|
||||
}
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
ReactTestRenderer.create(
|
||||
<React.Profiler id="test" onRender={callback}>
|
||||
@@ -1135,7 +1139,7 @@ describe('Profiler', () => {
|
||||
it('reflects the most recently rendered id value', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
Scheduler.advanceTime(5); // 0 -> 5
|
||||
Scheduler.unstable_advanceTime(5); // 0 -> 5
|
||||
|
||||
const renderer = ReactTestRenderer.create(
|
||||
<React.Profiler id="one" onRender={callback}>
|
||||
@@ -1145,7 +1149,7 @@ describe('Profiler', () => {
|
||||
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
|
||||
Scheduler.advanceTime(20); // 7 -> 27
|
||||
Scheduler.unstable_advanceTime(20); // 7 -> 27
|
||||
|
||||
renderer.update(
|
||||
<React.Profiler id="two" onRender={callback}>
|
||||
@@ -1183,11 +1187,11 @@ describe('Profiler', () => {
|
||||
|
||||
class ClassComponent extends React.Component {
|
||||
componentDidMount() {
|
||||
Scheduler.advanceTime(5);
|
||||
Scheduler.unstable_advanceTime(5);
|
||||
classComponentMounted = true;
|
||||
}
|
||||
render() {
|
||||
Scheduler.advanceTime(2);
|
||||
Scheduler.unstable_advanceTime(2);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1209,14 +1213,16 @@ describe('Profiler', () => {
|
||||
loadModules({useNoopRenderer: true});
|
||||
|
||||
const Child = ({duration, id}) => {
|
||||
Scheduler.advanceTime(duration);
|
||||
Scheduler.yieldValue(`Child:render:${id}`);
|
||||
Scheduler.unstable_advanceTime(duration);
|
||||
Scheduler.unstable_yieldValue(`Child:render:${id}`);
|
||||
return null;
|
||||
};
|
||||
|
||||
class Parent extends React.Component {
|
||||
componentDidMount() {
|
||||
Scheduler.yieldValue(`Parent:componentDidMount:${this.props.id}`);
|
||||
Scheduler.unstable_yieldValue(
|
||||
`Parent:componentDidMount:${this.props.id}`,
|
||||
);
|
||||
}
|
||||
render() {
|
||||
const {duration, id} = this.props;
|
||||
@@ -1229,7 +1235,7 @@ describe('Profiler', () => {
|
||||
}
|
||||
}
|
||||
|
||||
Scheduler.advanceTime(50);
|
||||
Scheduler.unstable_advanceTime(50);
|
||||
|
||||
ReactNoop.renderToRootWithID(<Parent duration={3} id="one" />, 'one');
|
||||
|
||||
@@ -1242,13 +1248,13 @@ describe('Profiler', () => {
|
||||
|
||||
expect(ReactNoop.getRoot('one').current.actualDuration).toBe(0);
|
||||
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
|
||||
// Process some async work, but yield before committing it.
|
||||
ReactNoop.renderToRootWithID(<Parent duration={7} id="two" />, 'two');
|
||||
expect(Scheduler).toFlushAndYieldThrough(['Child:render:two']);
|
||||
|
||||
Scheduler.advanceTime(150);
|
||||
Scheduler.unstable_advanceTime(150);
|
||||
|
||||
// Commit the previously paused, batched work.
|
||||
commitFirstRender(['Parent:componentDidMount:one']);
|
||||
@@ -1256,7 +1262,7 @@ describe('Profiler', () => {
|
||||
expect(ReactNoop.getRoot('one').current.actualDuration).toBe(6);
|
||||
expect(ReactNoop.getRoot('two').current.actualDuration).toBe(0);
|
||||
|
||||
Scheduler.advanceTime(200);
|
||||
Scheduler.unstable_advanceTime(200);
|
||||
|
||||
expect(Scheduler).toFlushAndYield([
|
||||
'Child:render:two',
|
||||
@@ -1333,7 +1339,7 @@ describe('Profiler', () => {
|
||||
describe('error handling', () => {
|
||||
it('should cover errors thrown in onWorkScheduled', () => {
|
||||
function Component({children}) {
|
||||
Scheduler.yieldValue('Component:' + children);
|
||||
Scheduler.unstable_yieldValue('Component:' + children);
|
||||
return children;
|
||||
}
|
||||
|
||||
@@ -1368,7 +1374,7 @@ describe('Profiler', () => {
|
||||
|
||||
it('should cover errors thrown in onWorkStarted', () => {
|
||||
function Component({children}) {
|
||||
Scheduler.yieldValue('Component:' + children);
|
||||
Scheduler.unstable_yieldValue('Component:' + children);
|
||||
return children;
|
||||
}
|
||||
|
||||
@@ -1403,7 +1409,7 @@ describe('Profiler', () => {
|
||||
|
||||
it('should cover errors thrown in onWorkStopped', () => {
|
||||
function Component({children}) {
|
||||
Scheduler.yieldValue('Component:' + children);
|
||||
Scheduler.unstable_yieldValue('Component:' + children);
|
||||
return children;
|
||||
}
|
||||
|
||||
@@ -1438,7 +1444,7 @@ describe('Profiler', () => {
|
||||
|
||||
it('should cover errors thrown in onInteractionScheduledWorkCompleted', () => {
|
||||
function Component({children}) {
|
||||
Scheduler.yieldValue('Component:' + children);
|
||||
Scheduler.unstable_yieldValue('Component:' + children);
|
||||
return children;
|
||||
}
|
||||
|
||||
@@ -1513,8 +1519,8 @@ describe('Profiler', () => {
|
||||
let instance = null;
|
||||
|
||||
const Yield = ({duration = 10, value}) => {
|
||||
Scheduler.advanceTime(duration);
|
||||
Scheduler.yieldValue(value);
|
||||
Scheduler.unstable_advanceTime(duration);
|
||||
Scheduler.unstable_yieldValue(value);
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -1534,7 +1540,7 @@ describe('Profiler', () => {
|
||||
}
|
||||
}
|
||||
|
||||
Scheduler.advanceTime(1);
|
||||
Scheduler.unstable_advanceTime(1);
|
||||
|
||||
const interactionCreation = {
|
||||
id: 0,
|
||||
@@ -1608,7 +1614,7 @@ describe('Profiler', () => {
|
||||
onWorkStarted.mockClear();
|
||||
onWorkStopped.mockClear();
|
||||
|
||||
Scheduler.advanceTime(3);
|
||||
Scheduler.unstable_advanceTime(3);
|
||||
|
||||
let didRunCallback = false;
|
||||
|
||||
@@ -1684,7 +1690,7 @@ describe('Profiler', () => {
|
||||
onWorkStarted.mockClear();
|
||||
onWorkStopped.mockClear();
|
||||
|
||||
Scheduler.advanceTime(17);
|
||||
Scheduler.unstable_advanceTime(17);
|
||||
|
||||
// Verify that updating state again does not re-log our interaction.
|
||||
instance.setState({count: 3});
|
||||
@@ -1708,7 +1714,7 @@ describe('Profiler', () => {
|
||||
|
||||
onRender.mockClear();
|
||||
|
||||
Scheduler.advanceTime(3);
|
||||
Scheduler.unstable_advanceTime(3);
|
||||
|
||||
// Verify that root updates are also associated with traced events.
|
||||
const interactionTwo = {
|
||||
@@ -1781,7 +1787,7 @@ describe('Profiler', () => {
|
||||
state = {count: 0};
|
||||
render() {
|
||||
first = this;
|
||||
Scheduler.yieldValue('FirstComponent');
|
||||
Scheduler.unstable_yieldValue('FirstComponent');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1790,12 +1796,12 @@ describe('Profiler', () => {
|
||||
state = {count: 0};
|
||||
render() {
|
||||
second = this;
|
||||
Scheduler.yieldValue('SecondComponent');
|
||||
Scheduler.unstable_yieldValue('SecondComponent');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Scheduler.advanceTime(5);
|
||||
Scheduler.unstable_advanceTime(5);
|
||||
|
||||
const renderer = ReactTestRenderer.create(
|
||||
<React.Profiler id="test" onRender={onRender}>
|
||||
@@ -1813,7 +1819,7 @@ describe('Profiler', () => {
|
||||
|
||||
onRender.mockClear();
|
||||
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
|
||||
const interactionLowPri = {
|
||||
id: 0,
|
||||
@@ -1847,7 +1853,7 @@ describe('Profiler', () => {
|
||||
).toMatchInteractions([interactionLowPri]);
|
||||
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(0);
|
||||
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
|
||||
const interactionHighPri = {
|
||||
id: 1,
|
||||
@@ -1898,7 +1904,7 @@ describe('Profiler', () => {
|
||||
|
||||
onRender.mockClear();
|
||||
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
|
||||
// Resume the original low priority update, with rebased state.
|
||||
// Verify the low priority update was retained.
|
||||
@@ -1949,18 +1955,18 @@ describe('Profiler', () => {
|
||||
count: 0,
|
||||
};
|
||||
componentDidMount() {
|
||||
Scheduler.advanceTime(10); // Advance timer to keep commits separate
|
||||
Scheduler.unstable_advanceTime(10); // Advance timer to keep commits separate
|
||||
this.setState({count: 1}); // Intentional cascading update
|
||||
}
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
if (this.state.count === 2 && prevState.count === 1) {
|
||||
Scheduler.advanceTime(10); // Advance timer to keep commits separate
|
||||
Scheduler.unstable_advanceTime(10); // Advance timer to keep commits separate
|
||||
this.setState({count: 3}); // Intentional cascading update
|
||||
}
|
||||
}
|
||||
render() {
|
||||
instance = this;
|
||||
Scheduler.yieldValue('Example:' + this.state.count);
|
||||
Scheduler.unstable_yieldValue('Example:' + this.state.count);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2056,7 +2062,7 @@ describe('Profiler', () => {
|
||||
expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(2);
|
||||
expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(2);
|
||||
|
||||
Scheduler.advanceTime(5);
|
||||
Scheduler.unstable_advanceTime(5);
|
||||
|
||||
// Flush async work (outside of traced scope)
|
||||
// This will cause an intentional cascading update from did-update
|
||||
@@ -2174,7 +2180,7 @@ describe('Profiler', () => {
|
||||
|
||||
class Child extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('Child:' + this.props.count);
|
||||
Scheduler.unstable_yieldValue('Child:' + this.props.count);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2193,7 +2199,7 @@ describe('Profiler', () => {
|
||||
}
|
||||
}
|
||||
|
||||
Scheduler.advanceTime(1);
|
||||
Scheduler.unstable_advanceTime(1);
|
||||
|
||||
ReactTestRenderer.create(<Parent />, {
|
||||
unstable_isConcurrent: true,
|
||||
@@ -2267,7 +2273,7 @@ describe('Profiler', () => {
|
||||
const monkey = React.createRef();
|
||||
class Monkey extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('Monkey');
|
||||
Scheduler.unstable_yieldValue('Monkey');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2464,7 +2470,7 @@ describe('Profiler', () => {
|
||||
},
|
||||
);
|
||||
|
||||
Scheduler.advanceTime(400);
|
||||
Scheduler.unstable_advanceTime(400);
|
||||
await awaitableAdvanceTimers(400);
|
||||
|
||||
expect(Scheduler).toFlushAndYield([
|
||||
@@ -2473,7 +2479,7 @@ describe('Profiler', () => {
|
||||
]);
|
||||
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
|
||||
|
||||
Scheduler.advanceTime(500);
|
||||
Scheduler.unstable_advanceTime(500);
|
||||
await awaitableAdvanceTimers(500);
|
||||
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [loaded]']);
|
||||
@@ -2602,7 +2608,7 @@ describe('Profiler', () => {
|
||||
).toMatchInteraction(highPriUpdateInteraction);
|
||||
onInteractionScheduledWorkCompleted.mockClear();
|
||||
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
jest.advanceTimersByTime(100);
|
||||
await originalPromise;
|
||||
|
||||
@@ -2662,7 +2668,7 @@ describe('Profiler', () => {
|
||||
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
|
||||
expect(onRender).not.toHaveBeenCalled();
|
||||
|
||||
Scheduler.advanceTime(50);
|
||||
Scheduler.unstable_advanceTime(50);
|
||||
jest.advanceTimersByTime(50);
|
||||
|
||||
const highPriUpdateInteraction = {
|
||||
@@ -2704,7 +2710,7 @@ describe('Profiler', () => {
|
||||
|
||||
expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(0);
|
||||
|
||||
Scheduler.advanceTime(50);
|
||||
Scheduler.unstable_advanceTime(50);
|
||||
jest.advanceTimersByTime(50);
|
||||
await originalPromise;
|
||||
expect(Scheduler).toHaveYielded(['Promise resolved [loaded]']);
|
||||
|
||||
@@ -105,7 +105,7 @@ describe('ProfilerDOM', () => {
|
||||
resourcePromise.then(
|
||||
SchedulerTracing.unstable_wrap(() => {
|
||||
jest.runAllTimers();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
|
||||
expect(element.textContent).toBe('Text');
|
||||
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
|
||||
@@ -133,7 +133,7 @@ describe('ProfilerDOM', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
});
|
||||
|
||||
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
|
||||
@@ -141,7 +141,7 @@ describe('ProfilerDOM', () => {
|
||||
interaction,
|
||||
);
|
||||
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
jest.advanceTimersByTime(500);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,7 +47,7 @@ describe('ReactProfiler DevTools integration', () => {
|
||||
}
|
||||
render() {
|
||||
// Simulate time passing when this component is rendered
|
||||
Scheduler.advanceTime(this.props.byAmount);
|
||||
Scheduler.unstable_advanceTime(this.props.byAmount);
|
||||
return this.props.children || null;
|
||||
}
|
||||
};
|
||||
@@ -55,7 +55,7 @@ describe('ReactProfiler DevTools integration', () => {
|
||||
|
||||
it('should auto-Profile all fibers if the DevTools hook is detected', () => {
|
||||
const App = ({multiplier}) => {
|
||||
Scheduler.advanceTime(2);
|
||||
Scheduler.unstable_advanceTime(2);
|
||||
return (
|
||||
<React.Profiler id="Profiler" onRender={onRender}>
|
||||
<AdvanceTime byAmount={3 * multiplier} shouldComponentUpdate={true} />
|
||||
@@ -121,7 +121,7 @@ describe('ReactProfiler DevTools integration', () => {
|
||||
});
|
||||
|
||||
it('should reset the fiber stack correctly after an error when profiling host roots', () => {
|
||||
Scheduler.advanceTime(20);
|
||||
Scheduler.unstable_advanceTime(20);
|
||||
|
||||
const rendered = ReactTestRenderer.create(
|
||||
<div>
|
||||
@@ -129,7 +129,7 @@ describe('ReactProfiler DevTools integration', () => {
|
||||
</div>,
|
||||
);
|
||||
|
||||
Scheduler.advanceTime(20);
|
||||
Scheduler.unstable_advanceTime(20);
|
||||
|
||||
expect(() => {
|
||||
rendered.update(
|
||||
@@ -139,7 +139,7 @@ describe('ReactProfiler DevTools integration', () => {
|
||||
);
|
||||
}).toThrow();
|
||||
|
||||
Scheduler.advanceTime(20);
|
||||
Scheduler.unstable_advanceTime(20);
|
||||
|
||||
// But this should render correctly, if the profiler's fiber stack has been reset.
|
||||
rendered.update(
|
||||
@@ -164,7 +164,7 @@ describe('ReactProfiler DevTools integration', () => {
|
||||
const root = rendered.root._currentFiber().return;
|
||||
expect(root.stateNode.memoizedInteractions).toContainNoInteractions();
|
||||
|
||||
Scheduler.advanceTime(10);
|
||||
Scheduler.unstable_advanceTime(10);
|
||||
|
||||
const eventTime = Scheduler.unstable_now();
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@ describe('ReactStrictMode', () => {
|
||||
unstable_isConcurrent: true,
|
||||
});
|
||||
root.update(<AsyncRoot />);
|
||||
expect(() => Scheduler.flushAll()).toWarnDev(
|
||||
expect(() => Scheduler.unstable_flushAll()).toWarnDev(
|
||||
'Unsafe lifecycle methods were found within a strict-mode tree:' +
|
||||
'\n\ncomponentWillMount: Please update the following components ' +
|
||||
'to use componentDidMount instead: AsyncRoot' +
|
||||
@@ -363,7 +363,7 @@ describe('ReactStrictMode', () => {
|
||||
|
||||
// Dedupe
|
||||
root.update(<AsyncRoot />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
});
|
||||
|
||||
it('should coalesce warnings by lifecycle name', () => {
|
||||
@@ -395,7 +395,7 @@ describe('ReactStrictMode', () => {
|
||||
root.update(<AsyncRoot />);
|
||||
|
||||
expect(() => {
|
||||
expect(() => Scheduler.flushAll()).toWarnDev(
|
||||
expect(() => Scheduler.unstable_flushAll()).toWarnDev(
|
||||
'Unsafe lifecycle methods were found within a strict-mode tree:' +
|
||||
'\n\ncomponentWillMount: Please update the following components ' +
|
||||
'to use componentDidMount instead: AsyncRoot, Parent' +
|
||||
@@ -418,7 +418,7 @@ describe('ReactStrictMode', () => {
|
||||
|
||||
// Dedupe
|
||||
root.update(<AsyncRoot />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
});
|
||||
|
||||
it('should warn about components not present during the initial render', () => {
|
||||
@@ -444,7 +444,7 @@ describe('ReactStrictMode', () => {
|
||||
unstable_isConcurrent: true,
|
||||
});
|
||||
root.update(<AsyncRoot foo={true} />);
|
||||
expect(() => Scheduler.flushAll()).toWarnDev(
|
||||
expect(() => Scheduler.unstable_flushAll()).toWarnDev(
|
||||
'Unsafe lifecycle methods were found within a strict-mode tree:' +
|
||||
'\n\ncomponentWillMount: Please update the following components ' +
|
||||
'to use componentDidMount instead: Foo' +
|
||||
@@ -454,7 +454,7 @@ describe('ReactStrictMode', () => {
|
||||
);
|
||||
|
||||
root.update(<AsyncRoot foo={false} />);
|
||||
expect(() => Scheduler.flushAll()).toWarnDev(
|
||||
expect(() => Scheduler.unstable_flushAll()).toWarnDev(
|
||||
'Unsafe lifecycle methods were found within a strict-mode tree:' +
|
||||
'\n\ncomponentWillMount: Please update the following components ' +
|
||||
'to use componentDidMount instead: Bar' +
|
||||
@@ -465,9 +465,9 @@ describe('ReactStrictMode', () => {
|
||||
|
||||
// Dedupe
|
||||
root.update(<AsyncRoot foo={true} />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
root.update(<AsyncRoot foo={false} />);
|
||||
Scheduler.flushAll();
|
||||
Scheduler.unstable_flushAll();
|
||||
});
|
||||
|
||||
it('should also warn inside of "strict" mode trees', () => {
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('forwardRef', () => {
|
||||
it('should work without a ref to be forwarded', () => {
|
||||
class Child extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue(this.props.value);
|
||||
Scheduler.unstable_yieldValue(this.props.value);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ describe('forwardRef', () => {
|
||||
it('should forward a ref for a single child', () => {
|
||||
class Child extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue(this.props.value);
|
||||
Scheduler.unstable_yieldValue(this.props.value);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ describe('forwardRef', () => {
|
||||
it('should forward a ref for multiple children', () => {
|
||||
class Child extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue(this.props.value);
|
||||
Scheduler.unstable_yieldValue(this.props.value);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ describe('forwardRef', () => {
|
||||
super(props);
|
||||
}
|
||||
render() {
|
||||
Scheduler.yieldValue(this.props.value);
|
||||
Scheduler.unstable_yieldValue(this.props.value);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -138,28 +138,28 @@ describe('forwardRef', () => {
|
||||
class ErrorBoundary extends React.Component {
|
||||
state = {error: null};
|
||||
componentDidCatch(error) {
|
||||
Scheduler.yieldValue('ErrorBoundary.componentDidCatch');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary.componentDidCatch');
|
||||
this.setState({error});
|
||||
}
|
||||
render() {
|
||||
if (this.state.error) {
|
||||
Scheduler.yieldValue('ErrorBoundary.render: catch');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary.render: catch');
|
||||
return null;
|
||||
}
|
||||
Scheduler.yieldValue('ErrorBoundary.render: try');
|
||||
Scheduler.unstable_yieldValue('ErrorBoundary.render: try');
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
class BadRender extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('BadRender throw');
|
||||
Scheduler.unstable_yieldValue('BadRender throw');
|
||||
throw new Error('oops!');
|
||||
}
|
||||
}
|
||||
|
||||
function Wrapper(props) {
|
||||
Scheduler.yieldValue('Wrapper');
|
||||
Scheduler.unstable_yieldValue('Wrapper');
|
||||
return <BadRender {...props} ref={props.forwardedRef} />;
|
||||
}
|
||||
|
||||
@@ -196,24 +196,24 @@ describe('forwardRef', () => {
|
||||
|
||||
class Inner extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('Inner');
|
||||
Scheduler.unstable_yieldValue('Inner');
|
||||
inst = this;
|
||||
return <div ref={this.props.forwardedRef} />;
|
||||
}
|
||||
}
|
||||
|
||||
function Middle(props) {
|
||||
Scheduler.yieldValue('Middle');
|
||||
Scheduler.unstable_yieldValue('Middle');
|
||||
return <Inner {...props} />;
|
||||
}
|
||||
|
||||
const Forward = React.forwardRef((props, ref) => {
|
||||
Scheduler.yieldValue('Forward');
|
||||
Scheduler.unstable_yieldValue('Forward');
|
||||
return <Middle {...props} forwardedRef={ref} />;
|
||||
});
|
||||
|
||||
function App() {
|
||||
Scheduler.yieldValue('App');
|
||||
Scheduler.unstable_yieldValue('App');
|
||||
return <Forward />;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,10 +39,10 @@ describe('Scheduler', () => {
|
||||
});
|
||||
|
||||
it('flushes work incrementally', () => {
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('A'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('B'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('C'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('D'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('A'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('B'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('C'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('D'));
|
||||
|
||||
expect(Scheduler).toFlushAndYieldThrough(['A', 'B']);
|
||||
expect(Scheduler).toFlushAndYieldThrough(['C']);
|
||||
@@ -50,11 +50,11 @@ describe('Scheduler', () => {
|
||||
});
|
||||
|
||||
it('cancels work', () => {
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('A'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('A'));
|
||||
const callbackHandleB = scheduleCallback(NormalPriority, () =>
|
||||
Scheduler.yieldValue('B'),
|
||||
Scheduler.unstable_yieldValue('B'),
|
||||
);
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('C'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('C'));
|
||||
|
||||
cancelCallback(callbackHandleB);
|
||||
|
||||
@@ -66,14 +66,18 @@ describe('Scheduler', () => {
|
||||
});
|
||||
|
||||
it('executes the highest priority callbacks first', () => {
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('A'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('B'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('A'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('B'));
|
||||
|
||||
// Yield before B is flushed
|
||||
expect(Scheduler).toFlushAndYieldThrough(['A']);
|
||||
|
||||
scheduleCallback(UserBlockingPriority, () => Scheduler.yieldValue('C'));
|
||||
scheduleCallback(UserBlockingPriority, () => Scheduler.yieldValue('D'));
|
||||
scheduleCallback(UserBlockingPriority, () =>
|
||||
Scheduler.unstable_yieldValue('C'),
|
||||
);
|
||||
scheduleCallback(UserBlockingPriority, () =>
|
||||
Scheduler.unstable_yieldValue('D'),
|
||||
);
|
||||
|
||||
// C and D should come first, because they are higher priority
|
||||
expect(Scheduler).toFlushAndYield(['C', 'D', 'B']);
|
||||
@@ -81,41 +85,41 @@ describe('Scheduler', () => {
|
||||
|
||||
it('expires work', () => {
|
||||
scheduleCallback(NormalPriority, didTimeout => {
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.yieldValue(`A (did timeout: ${didTimeout})`);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
Scheduler.unstable_yieldValue(`A (did timeout: ${didTimeout})`);
|
||||
});
|
||||
scheduleCallback(UserBlockingPriority, didTimeout => {
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.yieldValue(`B (did timeout: ${didTimeout})`);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
Scheduler.unstable_yieldValue(`B (did timeout: ${didTimeout})`);
|
||||
});
|
||||
scheduleCallback(UserBlockingPriority, didTimeout => {
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.yieldValue(`C (did timeout: ${didTimeout})`);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
Scheduler.unstable_yieldValue(`C (did timeout: ${didTimeout})`);
|
||||
});
|
||||
|
||||
// Advance time, but not by enough to expire any work
|
||||
Scheduler.advanceTime(249);
|
||||
Scheduler.unstable_advanceTime(249);
|
||||
expect(Scheduler).toHaveYielded([]);
|
||||
|
||||
// Schedule a few more callbacks
|
||||
scheduleCallback(NormalPriority, didTimeout => {
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.yieldValue(`D (did timeout: ${didTimeout})`);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
Scheduler.unstable_yieldValue(`D (did timeout: ${didTimeout})`);
|
||||
});
|
||||
scheduleCallback(NormalPriority, didTimeout => {
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.yieldValue(`E (did timeout: ${didTimeout})`);
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
Scheduler.unstable_yieldValue(`E (did timeout: ${didTimeout})`);
|
||||
});
|
||||
|
||||
// Advance by just a bit more to expire the user blocking callbacks
|
||||
Scheduler.advanceTime(1);
|
||||
Scheduler.unstable_advanceTime(1);
|
||||
expect(Scheduler).toHaveYielded([
|
||||
'B (did timeout: true)',
|
||||
'C (did timeout: true)',
|
||||
]);
|
||||
|
||||
// Expire A
|
||||
Scheduler.advanceTime(4600);
|
||||
Scheduler.unstable_advanceTime(4600);
|
||||
expect(Scheduler).toHaveYielded(['A (did timeout: true)']);
|
||||
|
||||
// Flush the rest without expiring
|
||||
@@ -126,23 +130,23 @@ describe('Scheduler', () => {
|
||||
});
|
||||
|
||||
it('has a default expiration of ~5 seconds', () => {
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('A'));
|
||||
scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('A'));
|
||||
|
||||
Scheduler.advanceTime(4999);
|
||||
Scheduler.unstable_advanceTime(4999);
|
||||
expect(Scheduler).toHaveYielded([]);
|
||||
|
||||
Scheduler.advanceTime(1);
|
||||
Scheduler.unstable_advanceTime(1);
|
||||
expect(Scheduler).toHaveYielded(['A']);
|
||||
});
|
||||
|
||||
it('continues working on same task after yielding', () => {
|
||||
scheduleCallback(NormalPriority, () => {
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.yieldValue('A');
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
Scheduler.unstable_yieldValue('A');
|
||||
});
|
||||
scheduleCallback(NormalPriority, () => {
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.yieldValue('B');
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
Scheduler.unstable_yieldValue('B');
|
||||
});
|
||||
|
||||
let didYield = false;
|
||||
@@ -150,8 +154,8 @@ describe('Scheduler', () => {
|
||||
const C = () => {
|
||||
while (tasks.length > 0) {
|
||||
const [label, ms] = tasks.shift();
|
||||
Scheduler.advanceTime(ms);
|
||||
Scheduler.yieldValue(label);
|
||||
Scheduler.unstable_advanceTime(ms);
|
||||
Scheduler.unstable_yieldValue(label);
|
||||
if (shouldYield()) {
|
||||
didYield = true;
|
||||
return C;
|
||||
@@ -162,12 +166,12 @@ describe('Scheduler', () => {
|
||||
scheduleCallback(NormalPriority, C);
|
||||
|
||||
scheduleCallback(NormalPriority, () => {
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.yieldValue('D');
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
Scheduler.unstable_yieldValue('D');
|
||||
});
|
||||
scheduleCallback(NormalPriority, () => {
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.yieldValue('E');
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
Scheduler.unstable_yieldValue('E');
|
||||
});
|
||||
|
||||
// Flush, then yield while in the middle of C.
|
||||
@@ -184,8 +188,8 @@ describe('Scheduler', () => {
|
||||
const work = () => {
|
||||
while (tasks.length > 0) {
|
||||
const [label, ms] = tasks.shift();
|
||||
Scheduler.advanceTime(ms);
|
||||
Scheduler.yieldValue(label);
|
||||
Scheduler.unstable_advanceTime(ms);
|
||||
Scheduler.unstable_yieldValue(label);
|
||||
if (shouldYield()) {
|
||||
return work;
|
||||
}
|
||||
@@ -199,7 +203,7 @@ describe('Scheduler', () => {
|
||||
expect(Scheduler).toFlushAndYieldThrough(['A', 'B']);
|
||||
|
||||
// Advance time by just a bit more. This should expire all the remaining work.
|
||||
Scheduler.advanceTime(1);
|
||||
Scheduler.unstable_advanceTime(1);
|
||||
expect(Scheduler).toHaveYielded(['C', 'D']);
|
||||
});
|
||||
|
||||
@@ -208,8 +212,8 @@ describe('Scheduler', () => {
|
||||
const work = () => {
|
||||
while (tasks.length > 0) {
|
||||
const [label, ms] = tasks.shift();
|
||||
Scheduler.advanceTime(ms);
|
||||
Scheduler.yieldValue(label);
|
||||
Scheduler.unstable_advanceTime(ms);
|
||||
Scheduler.unstable_yieldValue(label);
|
||||
if (tasks.length > 0 && shouldYield()) {
|
||||
return work;
|
||||
}
|
||||
@@ -219,8 +223,8 @@ describe('Scheduler', () => {
|
||||
expect(Scheduler).toFlushAndYieldThrough(['A']);
|
||||
|
||||
scheduleCallback(UserBlockingPriority, () => {
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.yieldValue('High pri');
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
Scheduler.unstable_yieldValue('High pri');
|
||||
});
|
||||
|
||||
expect(Scheduler).toFlushAndYield(['High pri', 'B', 'C', 'D']);
|
||||
@@ -235,18 +239,18 @@ describe('Scheduler', () => {
|
||||
while (tasks.length > 0) {
|
||||
const task = tasks.shift();
|
||||
const [label, ms] = task;
|
||||
Scheduler.advanceTime(ms);
|
||||
Scheduler.yieldValue(label);
|
||||
Scheduler.unstable_advanceTime(ms);
|
||||
Scheduler.unstable_yieldValue(label);
|
||||
if (label === 'B') {
|
||||
// Schedule high pri work from inside another callback
|
||||
Scheduler.yieldValue('Schedule high pri');
|
||||
Scheduler.unstable_yieldValue('Schedule high pri');
|
||||
scheduleCallback(UserBlockingPriority, () => {
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.yieldValue('High pri');
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
Scheduler.unstable_yieldValue('High pri');
|
||||
});
|
||||
}
|
||||
if (tasks.length > 0 && shouldYield()) {
|
||||
Scheduler.yieldValue('Yield!');
|
||||
Scheduler.unstable_yieldValue('Yield!');
|
||||
return work;
|
||||
}
|
||||
}
|
||||
@@ -268,10 +272,18 @@ describe('Scheduler', () => {
|
||||
);
|
||||
|
||||
it('top-level immediate callbacks fire in a subsequent task', () => {
|
||||
scheduleCallback(ImmediatePriority, () => Scheduler.yieldValue('A'));
|
||||
scheduleCallback(ImmediatePriority, () => Scheduler.yieldValue('B'));
|
||||
scheduleCallback(ImmediatePriority, () => Scheduler.yieldValue('C'));
|
||||
scheduleCallback(ImmediatePriority, () => Scheduler.yieldValue('D'));
|
||||
scheduleCallback(ImmediatePriority, () =>
|
||||
Scheduler.unstable_yieldValue('A'),
|
||||
);
|
||||
scheduleCallback(ImmediatePriority, () =>
|
||||
Scheduler.unstable_yieldValue('B'),
|
||||
);
|
||||
scheduleCallback(ImmediatePriority, () =>
|
||||
Scheduler.unstable_yieldValue('C'),
|
||||
);
|
||||
scheduleCallback(ImmediatePriority, () =>
|
||||
Scheduler.unstable_yieldValue('D'),
|
||||
);
|
||||
// Immediate callback hasn't fired, yet.
|
||||
expect(Scheduler).toHaveYielded([]);
|
||||
// They all flush immediately within the subsequent task.
|
||||
@@ -279,13 +291,19 @@ describe('Scheduler', () => {
|
||||
});
|
||||
|
||||
it('nested immediate callbacks are added to the queue of immediate callbacks', () => {
|
||||
scheduleCallback(ImmediatePriority, () => Scheduler.yieldValue('A'));
|
||||
scheduleCallback(ImmediatePriority, () =>
|
||||
Scheduler.unstable_yieldValue('A'),
|
||||
);
|
||||
scheduleCallback(ImmediatePriority, () => {
|
||||
Scheduler.yieldValue('B');
|
||||
Scheduler.unstable_yieldValue('B');
|
||||
// This callback should go to the end of the queue
|
||||
scheduleCallback(ImmediatePriority, () => Scheduler.yieldValue('C'));
|
||||
scheduleCallback(ImmediatePriority, () =>
|
||||
Scheduler.unstable_yieldValue('C'),
|
||||
);
|
||||
});
|
||||
scheduleCallback(ImmediatePriority, () => Scheduler.yieldValue('D'));
|
||||
scheduleCallback(ImmediatePriority, () =>
|
||||
Scheduler.unstable_yieldValue('D'),
|
||||
);
|
||||
expect(Scheduler).toHaveYielded([]);
|
||||
// C should flush at the end
|
||||
expect(Scheduler).toFlushExpired(['A', 'B', 'D', 'C']);
|
||||
@@ -299,7 +317,7 @@ describe('Scheduler', () => {
|
||||
it('wrapped callbacks inherit the current priority', () => {
|
||||
const wrappedCallback = runWithPriority(NormalPriority, () =>
|
||||
wrapCallback(() => {
|
||||
Scheduler.yieldValue(getCurrentPriorityLevel());
|
||||
Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -307,7 +325,7 @@ describe('Scheduler', () => {
|
||||
UserBlockingPriority,
|
||||
() =>
|
||||
wrapCallback(() => {
|
||||
Scheduler.yieldValue(getCurrentPriorityLevel());
|
||||
Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -324,11 +342,11 @@ describe('Scheduler', () => {
|
||||
|
||||
runWithPriority(NormalPriority, () => {
|
||||
wrappedCallback = wrapCallback(() => {
|
||||
Scheduler.yieldValue(getCurrentPriorityLevel());
|
||||
Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
|
||||
});
|
||||
wrappedUserBlockingCallback = runWithPriority(UserBlockingPriority, () =>
|
||||
wrapCallback(() => {
|
||||
Scheduler.yieldValue(getCurrentPriorityLevel());
|
||||
Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -342,14 +360,14 @@ describe('Scheduler', () => {
|
||||
|
||||
it("immediate callbacks fire even if there's an error", () => {
|
||||
scheduleCallback(ImmediatePriority, () => {
|
||||
Scheduler.yieldValue('A');
|
||||
Scheduler.unstable_yieldValue('A');
|
||||
throw new Error('Oops A');
|
||||
});
|
||||
scheduleCallback(ImmediatePriority, () => {
|
||||
Scheduler.yieldValue('B');
|
||||
Scheduler.unstable_yieldValue('B');
|
||||
});
|
||||
scheduleCallback(ImmediatePriority, () => {
|
||||
Scheduler.yieldValue('C');
|
||||
Scheduler.unstable_yieldValue('C');
|
||||
throw new Error('Oops C');
|
||||
});
|
||||
|
||||
@@ -369,22 +387,22 @@ describe('Scheduler', () => {
|
||||
scheduleCallback(ImmediatePriority, () => {
|
||||
throw new Error('Second error');
|
||||
});
|
||||
expect(() => Scheduler.flushAll()).toThrow('First error');
|
||||
expect(() => Scheduler.unstable_flushAll()).toThrow('First error');
|
||||
// The next error is thrown in the subsequent event
|
||||
expect(() => Scheduler.flushAll()).toThrow('Second error');
|
||||
expect(() => Scheduler.unstable_flushAll()).toThrow('Second error');
|
||||
});
|
||||
|
||||
it('exposes the current priority level', () => {
|
||||
Scheduler.yieldValue(getCurrentPriorityLevel());
|
||||
Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
|
||||
runWithPriority(ImmediatePriority, () => {
|
||||
Scheduler.yieldValue(getCurrentPriorityLevel());
|
||||
Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
|
||||
runWithPriority(NormalPriority, () => {
|
||||
Scheduler.yieldValue(getCurrentPriorityLevel());
|
||||
Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
|
||||
runWithPriority(UserBlockingPriority, () => {
|
||||
Scheduler.yieldValue(getCurrentPriorityLevel());
|
||||
Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
|
||||
});
|
||||
});
|
||||
Scheduler.yieldValue(getCurrentPriorityLevel());
|
||||
Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
|
||||
});
|
||||
|
||||
expect(Scheduler).toHaveYielded([
|
||||
@@ -398,53 +416,73 @@ describe('Scheduler', () => {
|
||||
|
||||
describe('delayed tasks', () => {
|
||||
it('schedules a delayed task', () => {
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('A'), {
|
||||
delay: 1000,
|
||||
});
|
||||
scheduleCallback(
|
||||
NormalPriority,
|
||||
() => Scheduler.unstable_yieldValue('A'),
|
||||
{
|
||||
delay: 1000,
|
||||
},
|
||||
);
|
||||
|
||||
// Should flush nothing, because delay hasn't elapsed
|
||||
expect(Scheduler).toFlushAndYield([]);
|
||||
|
||||
// Advance time until right before the threshold
|
||||
Scheduler.advanceTime(999);
|
||||
Scheduler.unstable_advanceTime(999);
|
||||
// Still nothing
|
||||
expect(Scheduler).toFlushAndYield([]);
|
||||
|
||||
// Advance time past the threshold
|
||||
Scheduler.advanceTime(1);
|
||||
Scheduler.unstable_advanceTime(1);
|
||||
|
||||
// Now it should flush like normal
|
||||
expect(Scheduler).toFlushAndYield(['A']);
|
||||
});
|
||||
|
||||
it('schedules multiple delayed tasks', () => {
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('C'), {
|
||||
delay: 300,
|
||||
});
|
||||
scheduleCallback(
|
||||
NormalPriority,
|
||||
() => Scheduler.unstable_yieldValue('C'),
|
||||
{
|
||||
delay: 300,
|
||||
},
|
||||
);
|
||||
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('B'), {
|
||||
delay: 200,
|
||||
});
|
||||
scheduleCallback(
|
||||
NormalPriority,
|
||||
() => Scheduler.unstable_yieldValue('B'),
|
||||
{
|
||||
delay: 200,
|
||||
},
|
||||
);
|
||||
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('D'), {
|
||||
delay: 400,
|
||||
});
|
||||
scheduleCallback(
|
||||
NormalPriority,
|
||||
() => Scheduler.unstable_yieldValue('D'),
|
||||
{
|
||||
delay: 400,
|
||||
},
|
||||
);
|
||||
|
||||
scheduleCallback(NormalPriority, () => Scheduler.yieldValue('A'), {
|
||||
delay: 100,
|
||||
});
|
||||
scheduleCallback(
|
||||
NormalPriority,
|
||||
() => Scheduler.unstable_yieldValue('A'),
|
||||
{
|
||||
delay: 100,
|
||||
},
|
||||
);
|
||||
|
||||
// Should flush nothing, because delay hasn't elapsed
|
||||
expect(Scheduler).toFlushAndYield([]);
|
||||
|
||||
// Advance some time.
|
||||
Scheduler.advanceTime(200);
|
||||
Scheduler.unstable_advanceTime(200);
|
||||
// Both A and B are no longer delayed. They can now flush incrementally.
|
||||
expect(Scheduler).toFlushAndYieldThrough(['A']);
|
||||
expect(Scheduler).toFlushAndYield(['B']);
|
||||
|
||||
// Advance the rest
|
||||
Scheduler.advanceTime(200);
|
||||
Scheduler.unstable_advanceTime(200);
|
||||
expect(Scheduler).toFlushAndYield(['C', 'D']);
|
||||
});
|
||||
|
||||
@@ -453,31 +491,31 @@ describe('Scheduler', () => {
|
||||
// elapses, they will be the most important callback in the queue.
|
||||
scheduleCallback(
|
||||
UserBlockingPriority,
|
||||
() => Scheduler.yieldValue('Timer 2'),
|
||||
() => Scheduler.unstable_yieldValue('Timer 2'),
|
||||
{delay: 300},
|
||||
);
|
||||
scheduleCallback(
|
||||
UserBlockingPriority,
|
||||
() => Scheduler.yieldValue('Timer 1'),
|
||||
() => Scheduler.unstable_yieldValue('Timer 1'),
|
||||
{delay: 100},
|
||||
);
|
||||
|
||||
// Schedule some tasks at default priority.
|
||||
scheduleCallback(NormalPriority, () => {
|
||||
Scheduler.yieldValue('A');
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_yieldValue('A');
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
});
|
||||
scheduleCallback(NormalPriority, () => {
|
||||
Scheduler.yieldValue('B');
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_yieldValue('B');
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
});
|
||||
scheduleCallback(NormalPriority, () => {
|
||||
Scheduler.yieldValue('C');
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_yieldValue('C');
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
});
|
||||
scheduleCallback(NormalPriority, () => {
|
||||
Scheduler.yieldValue('D');
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_yieldValue('D');
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
});
|
||||
|
||||
// Flush all the work. The timers should be interleaved with the
|
||||
@@ -497,12 +535,12 @@ describe('Scheduler', () => {
|
||||
// elapses, they will be the most important callback in the queue.
|
||||
scheduleCallback(
|
||||
UserBlockingPriority,
|
||||
() => Scheduler.yieldValue('Timer 2'),
|
||||
() => Scheduler.unstable_yieldValue('Timer 2'),
|
||||
{delay: 300},
|
||||
);
|
||||
scheduleCallback(
|
||||
UserBlockingPriority,
|
||||
() => Scheduler.yieldValue('Timer 1'),
|
||||
() => Scheduler.unstable_yieldValue('Timer 1'),
|
||||
{delay: 100},
|
||||
);
|
||||
|
||||
@@ -512,8 +550,8 @@ describe('Scheduler', () => {
|
||||
while (tasks.length > 0) {
|
||||
const task = tasks.shift();
|
||||
const [label, ms] = task;
|
||||
Scheduler.advanceTime(ms);
|
||||
Scheduler.yieldValue(label);
|
||||
Scheduler.unstable_advanceTime(ms);
|
||||
Scheduler.unstable_yieldValue(label);
|
||||
if (tasks.length > 0 && shouldYield()) {
|
||||
return work;
|
||||
}
|
||||
@@ -537,26 +575,26 @@ describe('Scheduler', () => {
|
||||
scheduleCallback(
|
||||
NormalPriority,
|
||||
() => {
|
||||
Scheduler.yieldValue('A');
|
||||
Scheduler.advanceTime(100);
|
||||
Scheduler.unstable_yieldValue('A');
|
||||
Scheduler.unstable_advanceTime(100);
|
||||
},
|
||||
{delay: 100, timeout: 900},
|
||||
);
|
||||
|
||||
Scheduler.advanceTime(99);
|
||||
Scheduler.unstable_advanceTime(99);
|
||||
// Does not flush because delay has not elapsed
|
||||
expect(Scheduler).toFlushAndYield([]);
|
||||
|
||||
// Delay has elapsed but task has not expired
|
||||
Scheduler.advanceTime(1);
|
||||
Scheduler.unstable_advanceTime(1);
|
||||
expect(Scheduler).toFlushExpired([]);
|
||||
|
||||
// Still not expired
|
||||
Scheduler.advanceTime(899);
|
||||
Scheduler.unstable_advanceTime(899);
|
||||
expect(Scheduler).toFlushExpired([]);
|
||||
|
||||
// Now it expires
|
||||
Scheduler.advanceTime(1);
|
||||
Scheduler.unstable_advanceTime(1);
|
||||
expect(Scheduler).toHaveYielded(['A']);
|
||||
});
|
||||
|
||||
@@ -566,17 +604,17 @@ describe('Scheduler', () => {
|
||||
|
||||
scheduleCallback(
|
||||
NormalPriority,
|
||||
() => Scheduler.yieldValue('A'),
|
||||
() => Scheduler.unstable_yieldValue('A'),
|
||||
options,
|
||||
);
|
||||
const taskB = scheduleCallback(
|
||||
NormalPriority,
|
||||
() => Scheduler.yieldValue('B'),
|
||||
() => Scheduler.unstable_yieldValue('B'),
|
||||
options,
|
||||
);
|
||||
const taskC = scheduleCallback(
|
||||
NormalPriority,
|
||||
() => Scheduler.yieldValue('C'),
|
||||
() => Scheduler.unstable_yieldValue('C'),
|
||||
options,
|
||||
);
|
||||
|
||||
@@ -585,7 +623,7 @@ describe('Scheduler', () => {
|
||||
cancelCallback(taskB);
|
||||
|
||||
// Cancel C after its delay has elapsed
|
||||
Scheduler.advanceTime(500);
|
||||
Scheduler.unstable_advanceTime(500);
|
||||
cancelCallback(taskC);
|
||||
|
||||
// Only A should flush
|
||||
|
||||
@@ -140,7 +140,7 @@ export function unstable_flushExpired() {
|
||||
}
|
||||
}
|
||||
|
||||
export function unstable_flushWithoutYielding(): boolean {
|
||||
export function unstable_flushAllWithoutAsserting(): boolean {
|
||||
// Returns false if no work was flushed.
|
||||
if (isFlushing) {
|
||||
throw new Error('Already flushing work.');
|
||||
@@ -174,14 +174,14 @@ export function unstable_clearYields(): Array<mixed> {
|
||||
return values;
|
||||
}
|
||||
|
||||
export function flushAll(): void {
|
||||
export function unstable_flushAll(): void {
|
||||
if (yieldedValues !== null) {
|
||||
throw new Error(
|
||||
'Log is not empty. Assert on the log of yielded values before ' +
|
||||
'flushing additional work.',
|
||||
);
|
||||
}
|
||||
unstable_flushWithoutYielding();
|
||||
unstable_flushAllWithoutAsserting();
|
||||
if (yieldedValues !== null) {
|
||||
throw new Error(
|
||||
'While flushing work, something yielded a value. Use an ' +
|
||||
@@ -191,7 +191,7 @@ export function flushAll(): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function yieldValue(value: mixed): void {
|
||||
export function unstable_yieldValue(value: mixed): void {
|
||||
if (yieldedValues === null) {
|
||||
yieldedValues = [value];
|
||||
} else {
|
||||
@@ -199,7 +199,7 @@ export function yieldValue(value: mixed): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function advanceTime(ms: number) {
|
||||
export function unstable_advanceTime(ms: number) {
|
||||
currentTime += ms;
|
||||
if (!isFlushing) {
|
||||
if (scheduledTimeout !== null && timeoutTime <= currentTime) {
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
export * from './src/Scheduler';
|
||||
|
||||
export {
|
||||
unstable_flushWithoutYielding,
|
||||
unstable_flushAllWithoutAsserting,
|
||||
unstable_flushNumberOfYields,
|
||||
unstable_flushExpired,
|
||||
unstable_clearYields,
|
||||
unstable_flushUntilNextPaint,
|
||||
flushAll,
|
||||
yieldValue,
|
||||
advanceTime,
|
||||
unstable_flushAll,
|
||||
unstable_yieldValue,
|
||||
unstable_advanceTime,
|
||||
} from './src/SchedulerHostConfig.js';
|
||||
|
||||
@@ -32,7 +32,7 @@ const {
|
||||
|
||||
// this doesn't actually exist on the scheduler, but it *does*
|
||||
// on scheduler/unstable_mock, which we'll need inside act().
|
||||
unstable_flushWithoutYielding,
|
||||
unstable_flushAllWithoutAsserting,
|
||||
} = ReactInternals.Scheduler;
|
||||
|
||||
export {
|
||||
@@ -53,5 +53,5 @@ export {
|
||||
unstable_LowPriority,
|
||||
unstable_IdlePriority,
|
||||
unstable_forceFrameRate,
|
||||
unstable_flushWithoutYielding,
|
||||
unstable_flushAllWithoutAsserting,
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ function assertYieldsWereCleared(Scheduler) {
|
||||
|
||||
function toFlushAndYield(Scheduler, expectedYields) {
|
||||
assertYieldsWereCleared(Scheduler);
|
||||
Scheduler.unstable_flushWithoutYielding();
|
||||
Scheduler.unstable_flushAllWithoutAsserting();
|
||||
const actualYields = Scheduler.unstable_clearYields();
|
||||
return captureAssertion(() => {
|
||||
expect(actualYields).toEqual(expectedYields);
|
||||
@@ -68,7 +68,7 @@ function toFlushAndThrow(Scheduler, ...rest) {
|
||||
assertYieldsWereCleared(Scheduler);
|
||||
return captureAssertion(() => {
|
||||
expect(() => {
|
||||
Scheduler.unstable_flushWithoutYielding();
|
||||
Scheduler.unstable_flushAllWithoutAsserting();
|
||||
}).toThrow(...rest);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user