mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[FeatureFlag] Toggle enableTreatHooksAsFunctions default to true
--- Toggle default to true, since this should be a no-op refactor. Tests: - test fixtures - ran on Store + - and saw no difference in compiled output - [diff](P744101621) with `enableTreatHooksAsFunctions=false` - [diff](P744105565) with `enableTreatHooksAsFunctions=true`
This commit is contained in:
@@ -94,7 +94,7 @@ export async function compile(
|
||||
let panicOnBailout = true;
|
||||
let memoizeJsxElements = true;
|
||||
let enableAssumeHooksFollowRulesOfReact = false;
|
||||
let enableTreatHooksAsFunctions = false;
|
||||
let enableTreatHooksAsFunctions = true;
|
||||
if (firstLine.indexOf("@forgetDirective") !== -1) {
|
||||
enableOnlyOnUseForgetDirective = true;
|
||||
}
|
||||
@@ -125,8 +125,8 @@ export async function compile(
|
||||
if (firstLine.indexOf("@enableAssumeHooksFollowRulesOfReact true") !== -1) {
|
||||
enableAssumeHooksFollowRulesOfReact = true;
|
||||
}
|
||||
if (firstLine.indexOf("@enableTreatHooksAsFunctions true") !== -1) {
|
||||
enableTreatHooksAsFunctions = true;
|
||||
if (firstLine.indexOf("@enableTreatHooksAsFunctions false") !== -1) {
|
||||
enableTreatHooksAsFunctions = false;
|
||||
}
|
||||
|
||||
const language = parseLanguage(firstLine);
|
||||
|
||||
@@ -99,7 +99,7 @@ export type EnvironmentConfig = Partial<{
|
||||
* Enabling this may change inference to have a higher confidence level
|
||||
* and create more bailouts (e.g. for mutable effects to immutable values).
|
||||
*
|
||||
* Defaults to false
|
||||
* Defaults to true
|
||||
*/
|
||||
enableTreatHooksAsFunctions: boolean;
|
||||
}>;
|
||||
@@ -149,7 +149,7 @@ export class Environment {
|
||||
this.enableAssumeHooksFollowRulesOfReact =
|
||||
config?.enableAssumeHooksFollowRulesOfReact ?? false;
|
||||
this.enableTreatHooksAsFunctions =
|
||||
config?.enableTreatHooksAsFunctions ?? false;
|
||||
config?.enableTreatHooksAsFunctions ?? true;
|
||||
this.#contextIdentifiers = contextIdentifiers;
|
||||
}
|
||||
|
||||
|
||||
+12
-4
@@ -2,8 +2,12 @@
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @enableTreatHooksAsFunctions true
|
||||
// (enableAssumeHooksFollowRulesOfReact=false)
|
||||
// Forget currently bails out when it detects a potential mutation (Effect.Mutate)
|
||||
// to an immutable value. This should not apply to unknown / untyped hooks.
|
||||
|
||||
// Default feature flags:
|
||||
// enableAssumeHooksFollowRulesOfReact=false
|
||||
// enableTreatHooksAsFunctions=true
|
||||
function Component(props) {
|
||||
const x = useUnknownHook1(props);
|
||||
const y = useUnknownHook2(x);
|
||||
@@ -15,8 +19,12 @@ function Component(props) {
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
// @enableTreatHooksAsFunctions true
|
||||
// (enableAssumeHooksFollowRulesOfReact=false)
|
||||
// Forget currently bails out when it detects a potential mutation (Effect.Mutate)
|
||||
// to an immutable value. This should not apply to unknown / untyped hooks.
|
||||
|
||||
// Default feature flags:
|
||||
// enableAssumeHooksFollowRulesOfReact=false
|
||||
// enableTreatHooksAsFunctions=true
|
||||
function Component(props) {
|
||||
const x = useUnknownHook1(props);
|
||||
const y = useUnknownHook2(x);
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
// @enableTreatHooksAsFunctions true
|
||||
// (enableAssumeHooksFollowRulesOfReact=false)
|
||||
// Forget currently bails out when it detects a potential mutation (Effect.Mutate)
|
||||
// to an immutable value. This should not apply to unknown / untyped hooks.
|
||||
|
||||
// Default feature flags:
|
||||
// enableAssumeHooksFollowRulesOfReact=false
|
||||
// enableTreatHooksAsFunctions=true
|
||||
function Component(props) {
|
||||
const x = useUnknownHook1(props);
|
||||
const y = useUnknownHook2(x);
|
||||
|
||||
@@ -103,7 +103,7 @@ export default function generateTestsFromFixtures(
|
||||
let panicOnBailout = true;
|
||||
let memoizeJsxElements = true;
|
||||
let enableAssumeHooksFollowRulesOfReact = false;
|
||||
let enableTreatHooksAsFunctions = false;
|
||||
let enableTreatHooksAsFunctions = true;
|
||||
|
||||
if (inputFile != null) {
|
||||
input = fs.readFileSync(inputFile, "utf8");
|
||||
@@ -153,8 +153,8 @@ export default function generateTestsFromFixtures(
|
||||
) {
|
||||
enableAssumeHooksFollowRulesOfReact = true;
|
||||
}
|
||||
if (lines[0]!.indexOf("@enableTreatHooksAsFunctions true") !== -1) {
|
||||
enableTreatHooksAsFunctions = true;
|
||||
if (lines[0]!.indexOf("@enableTreatHooksAsFunctions false") !== -1) {
|
||||
enableTreatHooksAsFunctions = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user