Skip to content

Commit 42b1055

Browse files
jorge-cabmanNomi
authored andcommitted
[compiler] Update test snap to include fixture comment (facebook#35100)
Summary: I missed this test case failing and now having @loggerTestOnly after landing some other PRs good to know they're not land blocking --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/35100). * facebook#35099 * __->__ facebook#35100
1 parent 26d8e2c commit 42b1055

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/effect-derived-computations/usestate-derived-from-prop-no-show-in-data-flow-tree.expect.md

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

44
```javascript
5-
// @validateNoDerivedComputationsInEffects_exp
5+
// @validateNoDerivedComputationsInEffects_exp @loggerTestOnly
66

7-
function Component({ prop }) {
8-
const [s, setS] = useState(prop)
9-
const [second, setSecond] = useState(prop)
7+
function Component({prop}) {
8+
const [s, setS] = useState();
9+
const [second, setSecond] = useState(prop);
1010

11+
/*
12+
* `second` is a source of state. It will inherit the value of `prop` in
13+
* the first render, but after that it will no longer be updated when
14+
* `prop` changes. So we shouldn't consider `second` as being derived from
15+
* `prop`
16+
*/
1117
useEffect(() => {
12-
setS(second)
13-
}, [second])
18+
setS(second);
19+
}, [second]);
1420

15-
return <div>{s}</div>
21+
return <div>{s}</div>;
1622
}
1723

1824
```
1925

2026
## Code
2127

2228
```javascript
23-
import { c as _c } from "react/compiler-runtime"; // @validateNoDerivedComputationsInEffects_exp
29+
import { c as _c } from "react/compiler-runtime"; // @validateNoDerivedComputationsInEffects_exp @loggerTestOnly
2430

2531
function Component(t0) {
2632
const $ = _c(5);
2733
const { prop } = t0;
28-
const [s, setS] = useState(prop);
34+
const [s, setS] = useState();
2935
const [second] = useState(prop);
3036
let t1;
3137
let t2;
@@ -54,6 +60,13 @@ function Component(t0) {
5460
}
5561

5662
```
63+
64+
## Logs
65+
66+
```
67+
{"kind":"CompileError","detail":{"options":{"description":"Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user\n\nThis setState call is setting a derived value that depends on the following reactive sources:\n\nState: [second]\n\nData Flow Tree:\n└── second (State)\n\nSee: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state","category":"EffectDerivationsOfState","reason":"You might not need an effect. Derive values in render, not effects.","details":[{"kind":"error","loc":{"start":{"line":14,"column":4,"index":443},"end":{"line":14,"column":8,"index":447},"filename":"usestate-derived-from-prop-no-show-in-data-flow-tree.ts","identifierName":"setS"},"message":"This should be computed during render, not in an effect"}]}},"fnLoc":null}
68+
{"kind":"CompileSuccess","fnLoc":{"start":{"line":3,"column":0,"index":64},"end":{"line":18,"column":1,"index":500},"filename":"usestate-derived-from-prop-no-show-in-data-flow-tree.ts"},"fnName":"Component","memoSlots":5,"memoBlocks":2,"memoValues":3,"prunedMemoBlocks":0,"prunedMemoValues":0}
69+
```
5770
5871
### Eval output
5972
(kind: exception) Fixture not implemented

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/effect-derived-computations/usestate-derived-from-prop-no-show-in-data-flow-tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @validateNoDerivedComputationsInEffects_exp
1+
// @validateNoDerivedComputationsInEffects_exp @loggerTestOnly
22

33
function Component({prop}) {
44
const [s, setS] = useState();

0 commit comments

Comments
 (0)