feat(ui): add eslint rules #4290
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this? (check all applicable)
Description
Add some eslint rules to support clear and performant code.
curlyrequires conditionals to use curly bracesConditionals without curly braces like
if (thing) doOtherThing()are easy to screw up. No longer allowed.react/jsx-curly-brace-presencerequires string props to not have curly braces<MyComponent label={'Some Text'} />is no longer allowed. Must be<MyComponent label='Some Text' />.react-memo/require-memorequires function components to be wrapped inReact.memoYes, every component. React already tracks component props to do its diffing, so this is free. Prop comparing is effectively never a performance concern, while in our complex app with very deeply-nested component hierarchy, rerenders are a huge concern.
react-memo/require-usememorequires all complex props (objects, functions) to be wrapped inuseMemooruseCallbackYes, every object or function.
There is a slight upfront cost to this, but using
React.memois negated if all props are not also memoized.Memoizing everything
The last two are perhaps controversial.
Needing to decide when to use
React.memo,React.useMemoandReact.useCallbackis both unnecessary cognitive overhead and premature optimization.Using them as a rule is both simpler and will generally lead to better performance. This is relevant to InvokeAI because this app is fairly complex, with deeply-nested components and a crapload of them.
So from now on, everything should be memoized.
Teeny tiny problem
But, uh, there's a minor issue... with these rules enabled, we have a bit of work to do:

Soooooo I'm going to leave this here as future-us problem.