You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[compiler] Fix false negatives and add data flow tree to compiler error for no-deriving-state-in-effects
Summary:
Revamped the derivationCache graph.
This fixes a bunch of bugs where sometimes we fail to track from which props/state we derived values from.
Also, it is more intuitive and allows us to easily implement a Data Flow Tree.
We can print this tree which gives insight on how the data is derived and should facilitate error resolution in complicated components
Test Plan:
Added a test case where we were failing to track derivations. Also updated the test cases with the new error containing the data flow tree
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects_exp.ts
constdescription=`Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user
610
+
611
+
This setState call is setting a derived value that depends on the following reactive sources:
description: `Derived values (${description}) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user`,
622
+
description: description,
537
623
category: ErrorCategory.EffectDerivationsOfState,
538
624
reason:
539
625
'You might not need an effect. Derive values in render, not effects.',
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/effect-derived-computations/error.derived-state-conditionally-in-effect.expect.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,16 @@ Found 1 error:
34
34
35
35
Error: You might not need an effect. Derive values in render, not effects.
36
36
37
-
Derived values (From props: [value]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
37
+
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user
38
+
39
+
This setState call is setting a derived value that depends on the following reactive sources:
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/effect-derived-computations/error.derived-state-from-default-props.expect.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,16 @@ Found 1 error:
31
31
32
32
Error: You might not need an effect. Derive values in render, not effects.
33
33
34
-
Derived values (From props: [input]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
34
+
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user
35
+
36
+
This setState call is setting a derived value that depends on the following reactive sources:
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/effect-derived-computations/error.derived-state-from-local-state-in-effect.expect.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,16 @@ Found 1 error:
28
28
29
29
Error: You might not need an effect. Derive values in render, not effects.
30
30
31
-
Derived values (From local state: [count]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
31
+
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user
32
+
33
+
This setState call is setting a derived value that depends on the following reactive sources:
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/effect-derived-computations/error.derived-state-from-prop-local-state-and-component-scope.expect.md
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,18 @@ Found 1 error:
38
38
39
39
Error: You might not need an effect. Derive values in render, not effects.
40
40
41
-
Derived values (From props and local state: [firstName, lastName]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
41
+
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user
42
+
43
+
This setState call is setting a derived value that depends on the following reactive sources:
Copy file name to clipboardExpand all lines: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/effect-derived-computations/error.derived-state-from-prop-with-side-effect.expect.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,16 @@ Found 1 error:
31
31
32
32
Error: You might not need an effect. Derive values in render, not effects.
33
33
34
-
Derived values (From props: [value]) should be computed during render, rather than in effects. Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user.
34
+
Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user
35
+
36
+
This setState call is setting a derived value that depends on the following reactive sources:
0 commit comments