mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
@@ -10,7 +10,6 @@
|
||||
'use strict';
|
||||
|
||||
const React = require('react');
|
||||
const Fragment = React.Fragment;
|
||||
let ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
|
||||
let ReactDOM;
|
||||
@@ -602,84 +601,4 @@ describe('ReactDOMFiberAsync', () => {
|
||||
expect(root.createBatch).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Disable yielding', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
ReactFeatureFlags = require('shared/ReactFeatureFlags');
|
||||
ReactFeatureFlags.disableYielding = true;
|
||||
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
|
||||
ReactDOM = require('react-dom');
|
||||
Scheduler = require('scheduler');
|
||||
});
|
||||
|
||||
it('wont yield during a render if yielding is disabled', () => {
|
||||
class A extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('A');
|
||||
return <div>{this.props.children}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('B');
|
||||
return <div>{this.props.children}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
class C extends React.Component {
|
||||
render() {
|
||||
Scheduler.yieldValue('C');
|
||||
return <div>{this.props.children}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
let root = ReactDOM.unstable_createRoot(container);
|
||||
|
||||
root.render(
|
||||
<Fragment>
|
||||
<A />
|
||||
<B />
|
||||
<C />
|
||||
</Fragment>,
|
||||
);
|
||||
|
||||
expect(Scheduler).toHaveYielded([]);
|
||||
|
||||
Scheduler.unstable_flushNumberOfYields(2);
|
||||
// Even though we just flushed two yields, we should have rendered
|
||||
// everything without yielding when the flag is on.
|
||||
expect(Scheduler).toHaveYielded(['A', 'B', 'C']);
|
||||
});
|
||||
|
||||
it('wont suspend during a render if yielding is disabled', () => {
|
||||
let p = new Promise(resolve => {});
|
||||
|
||||
function Suspend() {
|
||||
throw p;
|
||||
}
|
||||
|
||||
let root = ReactDOM.unstable_createRoot(container);
|
||||
root.render(
|
||||
<React.Suspense fallback={'Loading'}>Initial</React.Suspense>,
|
||||
);
|
||||
|
||||
Scheduler.flushAll();
|
||||
expect(container.textContent).toBe('Initial');
|
||||
|
||||
root.render(
|
||||
<React.Suspense fallback={'Loading'}>
|
||||
<Suspend />
|
||||
</React.Suspense>,
|
||||
);
|
||||
|
||||
expect(Scheduler).toHaveYielded([]);
|
||||
|
||||
Scheduler.flushAll();
|
||||
|
||||
// This should have flushed to the DOM even though we haven't ran the timers.
|
||||
expect(container.textContent).toBe('Loading');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+2
-8
@@ -23,7 +23,6 @@ import {
|
||||
enableSuspenseServerRenderer,
|
||||
replayFailedUnitOfWorkWithInvokeGuardedCallback,
|
||||
enableProfilerTimer,
|
||||
disableYielding,
|
||||
enableSchedulerTracing,
|
||||
revertPassiveEffectsChange,
|
||||
} from 'shared/ReactFeatureFlags';
|
||||
@@ -1004,7 +1003,7 @@ function renderRoot(
|
||||
// possible.
|
||||
const hasNotProcessedNewUpdates =
|
||||
workInProgressRootLatestProcessedExpirationTime === Sync;
|
||||
if (hasNotProcessedNewUpdates && !disableYielding && !isSync) {
|
||||
if (hasNotProcessedNewUpdates && !isSync) {
|
||||
// If we have not processed any new updates during this pass, then this is
|
||||
// either a retry of an existing fallback state or a hidden tree.
|
||||
// Hidden trees shouldn't be batched with other work and after that's
|
||||
@@ -1041,7 +1040,7 @@ function renderRoot(
|
||||
return commitRoot.bind(null, root);
|
||||
}
|
||||
case RootSuspendedWithDelay: {
|
||||
if (!disableYielding && !isSync) {
|
||||
if (!isSync) {
|
||||
// We're suspended in a state that should be avoided. We'll try to avoid committing
|
||||
// it for as long as the timeouts let us.
|
||||
if (workInProgressRootHasPendingPing) {
|
||||
@@ -2147,11 +2146,6 @@ function computeMsUntilSuspenseLoadingDelay(
|
||||
committedExpirationTime: ExpirationTime,
|
||||
suspenseConfig: SuspenseConfig,
|
||||
) {
|
||||
if (disableYielding) {
|
||||
// Timeout immediately when yielding is disabled.
|
||||
return 0;
|
||||
}
|
||||
|
||||
const busyMinDurationMs = (suspenseConfig.busyMinDurationMs: any) | 0;
|
||||
if (busyMinDurationMs <= 0) {
|
||||
return 0;
|
||||
|
||||
@@ -11,10 +11,7 @@
|
||||
// CommonJS interop named imports.
|
||||
import * as Scheduler from 'scheduler';
|
||||
import {__interactionsRef} from 'scheduler/tracing';
|
||||
import {
|
||||
disableYielding,
|
||||
enableSchedulerTracing,
|
||||
} from 'shared/ReactFeatureFlags';
|
||||
import {enableSchedulerTracing} from 'shared/ReactFeatureFlags';
|
||||
import invariant from 'shared/invariant';
|
||||
|
||||
const {
|
||||
@@ -65,9 +62,7 @@ export const IdlePriority: ReactPriorityLevel = 95;
|
||||
// NoPriority is the absence of priority. Also React-only.
|
||||
export const NoPriority: ReactPriorityLevel = 90;
|
||||
|
||||
export const shouldYield = disableYielding
|
||||
? () => false // Never yield when `disableYielding` is on
|
||||
: Scheduler_shouldYield;
|
||||
export const shouldYield = Scheduler_shouldYield;
|
||||
|
||||
let syncQueue: Array<SchedulerCallback> | null = null;
|
||||
let immediateQueueCallbackNode: mixed | null = null;
|
||||
|
||||
@@ -45,9 +45,6 @@ export function addUserTimingListener() {
|
||||
// Disable javascript: URL strings in href for XSS protection.
|
||||
export const disableJavaScriptURLs = false;
|
||||
|
||||
// Disables yielding during render in Concurrent Mode. Used for debugging only.
|
||||
export const disableYielding = false;
|
||||
|
||||
// React Fire: prevent the value and checked attributes from syncing
|
||||
// with their related DOM properties
|
||||
export const disableInputAttributeSyncing = false;
|
||||
|
||||
@@ -27,7 +27,6 @@ export const warnAboutShorthandPropertyCollision = false;
|
||||
export const enableSchedulerDebugging = false;
|
||||
export const debugRenderPhaseSideEffectsForStrictMode = true;
|
||||
export const disableJavaScriptURLs = false;
|
||||
export const disableYielding = false;
|
||||
export const disableInputAttributeSyncing = false;
|
||||
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
|
||||
export const warnAboutDeprecatedLifecycles = true;
|
||||
|
||||
@@ -21,7 +21,6 @@ export const enableProfilerTimer = __PROFILE__;
|
||||
export const enableSchedulerTracing = __PROFILE__;
|
||||
export const enableSuspenseServerRenderer = false;
|
||||
export const disableJavaScriptURLs = false;
|
||||
export const disableYielding = false;
|
||||
export const disableInputAttributeSyncing = false;
|
||||
export const enableStableConcurrentModeAPIs = false;
|
||||
export const warnAboutShorthandPropertyCollision = false;
|
||||
|
||||
@@ -21,7 +21,6 @@ export const enableProfilerTimer = __PROFILE__;
|
||||
export const enableSchedulerTracing = __PROFILE__;
|
||||
export const enableSuspenseServerRenderer = false;
|
||||
export const disableJavaScriptURLs = false;
|
||||
export const disableYielding = false;
|
||||
export const disableInputAttributeSyncing = false;
|
||||
export const enableStableConcurrentModeAPIs = false;
|
||||
export const warnAboutShorthandPropertyCollision = false;
|
||||
|
||||
@@ -21,7 +21,6 @@ export const enableProfilerTimer = false;
|
||||
export const enableSchedulerTracing = false;
|
||||
export const enableSuspenseServerRenderer = false;
|
||||
export const disableJavaScriptURLs = false;
|
||||
export const disableYielding = false;
|
||||
export const disableInputAttributeSyncing = false;
|
||||
export const enableStableConcurrentModeAPIs = false;
|
||||
export const warnAboutShorthandPropertyCollision = false;
|
||||
|
||||
@@ -27,7 +27,6 @@ export const enableStableConcurrentModeAPIs = false;
|
||||
export const enableSchedulerDebugging = false;
|
||||
export const warnAboutDeprecatedSetNativeProps = false;
|
||||
export const disableJavaScriptURLs = false;
|
||||
export const disableYielding = false;
|
||||
export const enableEventAPI = true;
|
||||
export const enableJSXTransformAPI = true;
|
||||
export const warnAboutMissingMockScheduler = true;
|
||||
|
||||
@@ -16,7 +16,6 @@ export const {
|
||||
debugRenderPhaseSideEffectsForStrictMode,
|
||||
replayFailedUnitOfWorkWithInvokeGuardedCallback,
|
||||
warnAboutDeprecatedLifecycles,
|
||||
disableYielding,
|
||||
disableInputAttributeSyncing,
|
||||
warnAboutShorthandPropertyCollision,
|
||||
warnAboutDeprecatedSetNativeProps,
|
||||
|
||||
Reference in New Issue
Block a user