-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support disabling spurious act warnings with a global environment flag (
#22561) * Extract `act` environment check into function `act` checks the environment to determine whether to fire a warning. We're changing how this check works in React 18. As a first step, this refactors the logic into a single function. No behavior changes yet. * Use IS_REACT_ACT_ENVIRONMENT to disable warnings If `IS_REACT_ACT_ENVIRONMENT` is set to `false`, we will suppress any `act` warnings. Otherwise, the behavior of `act` is the same as in React 17: if `jest` is defined, it warns. In concurrent mode, the plan is to remove the `jest` check and only warn if `IS_REACT_ACT_ENVIRONMENT` is true. I have not implemented that part yet.
- Loading branch information
Showing
16 changed files
with
142 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -279,5 +279,6 @@ module.exports = { | |
__VARIANT__: true, | ||
gate: true, | ||
trustedTypes: true, | ||
IS_REACT_ACT_ENVIRONMENT: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {Fiber} from './ReactFiber.new'; | ||
import {warnsIfNotActing} from './ReactFiberHostConfig'; | ||
|
||
export function isActEnvironment(fiber: Fiber) { | ||
if (__DEV__) { | ||
const isReactActEnvironmentGlobal = | ||
// $FlowExpectedError – Flow doesn't know about IS_REACT_ACT_ENVIRONMENT global | ||
typeof IS_REACT_ACT_ENVIRONMENT !== 'undefined' | ||
? IS_REACT_ACT_ENVIRONMENT | ||
: undefined; | ||
|
||
// TODO: Only check `jest` in legacy mode. In concurrent mode, this | ||
// heuristic is replaced by IS_REACT_ACT_ENVIRONMENT. | ||
// $FlowExpectedError - Flow doesn't know about jest | ||
const jestIsDefined = typeof jest !== 'undefined'; | ||
return ( | ||
warnsIfNotActing && | ||
jestIsDefined && | ||
// Legacy mode assumes an act environment whenever `jest` is defined, but | ||
// you can still turn off spurious warnings by setting | ||
// IS_REACT_ACT_ENVIRONMENT explicitly to false. | ||
isReactActEnvironmentGlobal !== false | ||
); | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {Fiber} from './ReactFiber.old'; | ||
import {warnsIfNotActing} from './ReactFiberHostConfig'; | ||
|
||
export function isActEnvironment(fiber: Fiber) { | ||
if (__DEV__) { | ||
const isReactActEnvironmentGlobal = | ||
// $FlowExpectedError – Flow doesn't know about IS_REACT_ACT_ENVIRONMENT global | ||
typeof IS_REACT_ACT_ENVIRONMENT !== 'undefined' | ||
? IS_REACT_ACT_ENVIRONMENT | ||
: undefined; | ||
|
||
// TODO: Only check `jest` in legacy mode. In concurrent mode, this | ||
// heuristic is replaced by IS_REACT_ACT_ENVIRONMENT. | ||
// $FlowExpectedError - Flow doesn't know about jest | ||
const jestIsDefined = typeof jest !== 'undefined'; | ||
return ( | ||
warnsIfNotActing && | ||
jestIsDefined && | ||
// Legacy mode assumes an act environment whenever `jest` is defined, but | ||
// you can still turn off spurious warnings by setting | ||
// IS_REACT_ACT_ENVIRONMENT explicitly to false. | ||
isReactActEnvironmentGlobal !== false | ||
); | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.