Compiler bailout not caught by linter #24
Replies: 2 comments 6 replies
-
For some background, the compiler's lint plugin doesn't report all errors, only the ones that are actionable by the user. We only want to surface errors that someone can actually fix in their code if it breaks a Rule of React. The compiler currently uses manual memoization as a hint. We compare our inferred memoization against manual memoization and bail out if they don't line up exactly. If the manual memoization was used to preserve stability in say, a useEffect downstream, changing memoization can result in unexpected behavior. But manual memoization not lining up with our inferred memoization isn't wrong, it just means the developer has more information than the compiler does about referential stability. So from the compiler's perspective, this is not an actionable error. If you do happen to notice unnecessary manual useMemo/useCallback/React.memo, you can remove them. We are in the midst of prototyping an IDE for React so this validation will be something we'll be thinking about as information we can provide to developers that isn't a hard error/warning, which is typically what we'll surface in ESLint instead. |
Beta Was this translation helpful? Give feedback.
-
If you are, like I was, eager to do everything possible right now to make your components memoizable by the React Compiler, you can try this alternate ESLint plugin that sets the highest "panic threshold" for the compiler which surfaces ~all possible issues in your editor. I think the argument from @poteto is essentially "it's better not to worry about this since many of these issues aren't actionable" but - I found I was able to stomp out 100% of lints on a pretty large codebase in a weekend. Also - when writing components, I like to know for sure that the compiler is working without having to copy/paste to Playground, so I know I don't have to add manual memoization. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
React Compiler Playground link: https://playground.react.dev/#N4Igzg9grgTgxgUxALhAHQHYEsC2AHCGAFwAIAlBAQzlIDMYIcSByGKm5gbk0wQA8CxEgBMEtSlAA2dKBhpYIGEgGFGBDAgxEAFAEoSwTCRJxFYUnFhstAVTAIYASWEkAvCQDKjBAHFJEACNKST0AOixhbgwjEzNSHABPAFlKDChgpIQcCDcSKHtM7O0Y4z03AD4SCCIACwc7B2c3V3dLGGsiBqdhAH5QoggPIhgsDABzPQAaEpIAbTaOrudJqtr6+26AXWmlEl0omLYiWCUAHmEsADdy4ESUtIysiABfU4B6C+vMZ5BnoA
The compiler bails out of optimizing this component because of
However, the linter doesn't seem to mention this as an issue.
Beta Was this translation helpful? Give feedback.
All reactions