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] Add new ValidateNoVoidUseMemo pass (#33990)
Adds a new validation pass to validate against `useMemo`s that don't
return anything. This usually indicates some kind of "useEffect"-like
code that has side effects that need to be memoized to prevent
overfiring, and is an anti-pattern.
A follow up validation could also look at the return value of `useMemo`s
to see if they are being used.
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33990).
* #34022
* #34002
* #34001
* __->__ #33990
* #33989
DiffTrain build for [c60eebf](c60eebf)
reason: `React Compiler has skipped optimizing this component because ${useMemoHook.name} doesn't return a value. ${useMemoHook.name} should only be used for memoizing values, not running arbitrary side effects.`,
47664
+
loc: useMemoHook.loc,
47665
+
suggestions: null,
47666
+
description: null,
47667
+
});
47668
+
}
47669
+
}
47670
+
}
47671
+
}
47672
+
}
47673
+
}
47674
+
return errors.asResult();
47675
+
}
47676
+
function checkFunctionHasNonVoidReturn(func) {
47677
+
for (const [, block] of func.body.blocks) {
47678
+
if (block.terminal.kind === 'return') {
47679
+
if (block.terminal.returnVariant === 'Explicit' ||
47680
+
block.terminal.returnVariant === 'Implicit') {
47681
+
return true;
47682
+
}
47683
+
}
47684
+
}
47685
+
return false;
47686
+
}
47687
+
function collectTemporaries(instr, env, sidemap) {
0 commit comments