Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] Fix eslint errors from jsx-no-bind #1 #52856

Merged

Conversation

patrykkopycinski
Copy link
Contributor

Summary

I'm working on improving the performance of the SIEM app and one of the ways to avoid unnecessary re-renders is to memoize callbacks.
We have over 300 errors from jsx-no-bind rule, so I've decided to split fixes into couple PR, so they are more digestable ;)

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@@ -15,7 +15,7 @@ import { SpyRoute } from '../../utils/route/spy_routes';
import * as i18n from './translations';

const TimelinesContainer = styled.div`
width: 100%:
width: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, nice! We used to have a linter for styled components that was nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to add it back 😄

@FrankHassanabad
Copy link
Contributor

Are there before and after performance charts for this PR so we can see what the improvements are?

@@ -93,7 +113,7 @@ export const NetworkDnsTableComponent = React.memo<NetworkDnsTableProps>(
}
}
},
[sort, type]
[sort, type, tableType]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is tableType necessary here but not on updateLimitPagination & updateActivePage? I see it's excluded for most other callbacks as well.

Seems to be differing usages between here and the other tables onChange() as well -- I might be missing something here, but just want to verify what difference changes the consistency between tables.

[tableType, sort.direction, type, updateNetworkTable]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was my mistake, the first round was done without any help, so I've added tableType to dependencies even though it was unnecessary, so to make sure that all dependencies are correct I've enabled temporarly react-hooks/exhaustive-deps rule and fixed everything as it suggested. I believe now it should be correct

render: (value: TableData['activate'], item: TableData) => {
const handleRuleStateChange: RuleStateChangeCallback = async (enabled, id) => {
await enableRulesAction([id], enabled, dispatch, kbnVersion);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for the cleanup here -- after reviewing this PR I'll be better prepared next time around 🙂

to: fromTo.to,
});
}}
narrowDateRange={narrowDateRange}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice pickup! 😉

Copy link
Member

@spong spong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked out locally to test, and performed a code review. The app feels noticeably snappier -- thanks for combing through the codebase and making these optimizations @patrykkopycinski! As @FrankHassanabad mentioned, if you happen to have any perf charts of before/after, be sure to include them here for posterity.

For anyone passing through, be sure to check out the Perf Section from the Hooks FAQ for details on when and how you should declare dependencies, especially with regards to function dependencies.

Looking forward to Part II @patrykkopycinski, whereafter we can hopefully enable the jsx-no-bind linter rule for good 🙂

LGTM! 👍 🚀

@patrykkopycinski
Copy link
Contributor Author

@elasticmachine merge upstream

@patrykkopycinski
Copy link
Contributor Author

@elasticmachine merge upstream

@patrykkopycinski
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@patrykkopycinski patrykkopycinski merged commit 022e6c4 into elastic:master Dec 17, 2019
@patrykkopycinski patrykkopycinski deleted the chore/fix-jsx-no-bind-1 branch December 17, 2019 21:51
patrykkopycinski added a commit to patrykkopycinski/kibana that referenced this pull request Dec 17, 2019
cjcenizal pushed a commit to cjcenizal/kibana that referenced this pull request Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:SIEM v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants