Skip to content

Commit ddff354

Browse files
authored
[compiler] Enable validateExhaustiveMemoizationDependencies by default (facebook#35201)
Enables `@validateExhaustiveMemoizationDependencies` feature flag by default, and disables it in select tests that failed due to the change. Some of our tests intentionally use incorrect memo dependencies in order to test edge cases. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/35201). * facebook#35213 * __->__ facebook#35201
1 parent d39a1d6 commit ddff354

File tree

128 files changed

+224
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+224
-184
lines changed

compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export const EnvironmentConfigSchema = z.object({
221221
/**
222222
* Validate that dependencies supplied to manual memoization calls are exhaustive.
223223
*/
224-
validateExhaustiveMemoizationDependencies: z.boolean().default(false),
224+
validateExhaustiveMemoizationDependencies: z.boolean().default(true),
225225

226226
/**
227227
* When this is true, rather than pruning existing manual memoization but ensuring or validating

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-modify-global-in-callback-jsx.expect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Input
33

44
```javascript
5-
// @enablePreserveExistingMemoizationGuarantees:false
5+
// @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
66
import {useMemo} from 'react';
77

88
const someGlobal = {value: 0};
@@ -33,7 +33,7 @@ export const FIXTURE_ENTRYPOINT = {
3333
## Code
3434

3535
```javascript
36-
import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees:false
36+
import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
3737
import { useMemo } from "react";
3838

3939
const someGlobal = { value: 0 };

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-modify-global-in-callback-jsx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @enablePreserveExistingMemoizationGuarantees:false
1+
// @enablePreserveExistingMemoizationGuarantees:false @validateExhaustiveMemoizationDependencies:false
22
import {useMemo} from 'react';
33

44
const someGlobal = {value: 0};

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-pattern-spread-creates-array.expect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Input
33

44
```javascript
5-
// @validatePreserveExistingMemoizationGuarantees
5+
// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
66
import {useMemo} from 'react';
77
import {makeObject_Primitives, ValidateMemoization} from 'shared-runtime';
88

@@ -36,7 +36,7 @@ export const FIXTURE_ENTRYPOINT = {
3636
## Code
3737

3838
```javascript
39-
import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
39+
import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
4040
import { useMemo } from "react";
4141
import { makeObject_Primitives, ValidateMemoization } from "shared-runtime";
4242

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-pattern-spread-creates-array.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @validatePreserveExistingMemoizationGuarantees
1+
// @validatePreserveExistingMemoizationGuarantees @validateExhaustiveMemoizationDependencies:false
22
import {useMemo} from 'react';
33
import {makeObject_Primitives, ValidateMemoization} from 'shared-runtime';
44

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/block-scoping-switch-variable-scoping.expect.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## Input
33

44
```javascript
5+
// @validateExhaustiveMemoizationDependencies:false
56
import {useMemo} from 'react';
67

78
function Component(props) {
@@ -30,7 +31,7 @@ export const FIXTURE_ENTRYPOINT = {
3031
## Code
3132

3233
```javascript
33-
import { c as _c } from "react/compiler-runtime";
34+
import { c as _c } from "react/compiler-runtime"; // @validateExhaustiveMemoizationDependencies:false
3435
import { useMemo } from "react";
3536

3637
function Component(props) {

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/block-scoping-switch-variable-scoping.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @validateExhaustiveMemoizationDependencies:false
12
import {useMemo} from 'react';
23

34
function Component(props) {

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bailout-on-suppression-of-custom-rule.expect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Input
33

44
```javascript
5-
// @eslintSuppressionRules:["my-app","react-rule"]
5+
// @eslintSuppressionRules:["my-app","react-rule"] @validateExhaustiveMemoizationDependencies:false
66

77
/* eslint-disable my-app/react-rule */
88
function lowercasecomponent() {
@@ -26,7 +26,7 @@ Error: React Compiler has skipped optimizing this component because one or more
2626
React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression `eslint-disable my-app/react-rule`.
2727
2828
error.bailout-on-suppression-of-custom-rule.ts:3:0
29-
1 | // @eslintSuppressionRules:["my-app","react-rule"]
29+
1 | // @eslintSuppressionRules:["my-app","react-rule"] @validateExhaustiveMemoizationDependencies:false
3030
2 |
3131
> 3 | /* eslint-disable my-app/react-rule */
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Found React rule suppression

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bailout-on-suppression-of-custom-rule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @eslintSuppressionRules:["my-app","react-rule"]
1+
// @eslintSuppressionRules:["my-app","react-rule"] @validateExhaustiveMemoizationDependencies:false
22

33
/* eslint-disable my-app/react-rule */
44
function lowercasecomponent() {

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-sketchy-code-use-forget.expect.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## Input
33

44
```javascript
5+
// @validateExhaustiveMemoizationDependencies:false
56
/* eslint-disable react-hooks/rules-of-hooks */
67
function lowercasecomponent() {
78
'use forget';
@@ -23,25 +24,26 @@ Error: React Compiler has skipped optimizing this component because one or more
2324
2425
React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression `eslint-disable react-hooks/rules-of-hooks`.
2526
26-
error.invalid-sketchy-code-use-forget.ts:1:0
27-
> 1 | /* eslint-disable react-hooks/rules-of-hooks */
27+
error.invalid-sketchy-code-use-forget.ts:2:0
28+
1 | // @validateExhaustiveMemoizationDependencies:false
29+
> 2 | /* eslint-disable react-hooks/rules-of-hooks */
2830
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Found React rule suppression
29-
2 | function lowercasecomponent() {
30-
3 | 'use forget';
31-
4 | const x = [];
31+
3 | function lowercasecomponent() {
32+
4 | 'use forget';
33+
5 | const x = [];
3234
3335
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled
3436
3537
React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression `eslint-disable-next-line react-hooks/rules-of-hooks`.
3638
37-
error.invalid-sketchy-code-use-forget.ts:5:2
38-
3 | 'use forget';
39-
4 | const x = [];
40-
> 5 | // eslint-disable-next-line react-hooks/rules-of-hooks
39+
error.invalid-sketchy-code-use-forget.ts:6:2
40+
4 | 'use forget';
41+
5 | const x = [];
42+
> 6 | // eslint-disable-next-line react-hooks/rules-of-hooks
4143
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Found React rule suppression
42-
6 | return <div>{x}</div>;
43-
7 | }
44-
8 | /* eslint-enable react-hooks/rules-of-hooks */
44+
7 | return <div>{x}</div>;
45+
8 | }
46+
9 | /* eslint-enable react-hooks/rules-of-hooks */
4547
```
4648
4749

0 commit comments

Comments
 (0)