@samitouri / QOS-React / commits / 7d67591041

[compiler] Remove useState argument constraint. no-derived-computations-in-effects (#35174)

Summary: I missed this conditional messing things up for undefined useState() calls. We should be tracking them. I also missed a test that expect an error was not throwing. Test Plan: Update broken test --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/35174). * __->__ #35174 * #35173

Jorge Cabiedes committed Nov 20, 2025 at 10:45 UTC 7d67591041e3ac47eac3bab6cff209071d4c0c6c
2 files changed +2 -1
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects_exp.ts
+1 -1
@@ -388,7 +388,7 @@ function recordInstructionDerivations(
388 dependencies: deps,
389 });
390 }
391 - } else if (isUseStateType(lvalue.identifier) && value.args.length > 0) {
391 + } else if (isUseStateType(lvalue.identifier)) {
392 typeOfValue = 'fromState';
393 context.derivationCache.addDerivationEntry(
394 lvalue,
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
+1
@@ -64,6 +64,7 @@ function Component(t0) {
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 ```
70