-
Notifications
You must be signed in to change notification settings - Fork 934
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
Fix for Memory Leak in TableToolbar #829
Conversation
Sorry for doing this backwards. I should have verified the memory problem before putting in a pull request. I saw @Fabbok1x comment on styled.js and a comment in the code mentioned that it allowed you to use props within your style rules. This piqued my interest since I thought Material already allowed that (I was mistakenly thinking of makeStyles instead of withStyles). While I was poking around TableToolbar.js I realized styled.js wasn't needed anyway and could be removed. I figured that would just solve the problem, but after thinking about it, unless there was a verifiable problem to solve, the PR wouldn't be that beneficial. Also, @coveralls was down for maintenance when I put this in. Not sure if there's a way to manually call it. |
|
Ugh, ok scratch that. I can produce it. Here's how to see the memory leak:
In a separate tab, open up https://codesandbox.io/s/mui-datatables-9pmct and do the exact same steps. Then look at the graph difference between the two sandboxes. The second sandbox is my PR with the modified TableToolbar.js and a modified customize-filter example. |
Thank you for your investigative efforts @patorjk! I took your suggested steps to reproduce and I captured each scenario in order: To me, they don't look appreciably different. I do remember when I tried a few days ago, they did look more dissimilar. I think this is really tricky to trace, especially in codesandbox, because we're dealing with a VM behind the scenes which may be getting its own updates or experiencing its own bugs (and it also seems like more than one being open in a browser at the same time shares resources between them). So, I couldn't quite locate a real "smoking gun" issue here. However, I think it might be a good idea to keep these changes anyway, as
What do you think? |
@patorjk : Thank you. All I could add to this is that in my environment I was able to tackle the issue with a 100% certainty on the styled.js HOC beeing one of the core issues of this leak. Removing the HOC will definetly resolve a big part of the leak. To add that React 16.9.0 came up with a fix regarding a major memory leak (facebook/react#16115) aswell. In case you have updated the react version meanwhile this would most probably explain the discrepancy which would/could then definetly seem rather random and might've had its' root cause in the prior mentioned ReactJS leak.In case you have not updated the ReactJS version then a resolution of the leak would still take effect by removing styled.js in a given environment. |
@Fabbok1x Thanks for finding this! This was a pretty amazing find, especially being able to pinpoint the root cause (even if it is unclear why it happens). @gabrielliwerant I concur, though I've adjusted the timeouts in the examples to make them faster so the issue shows up better over ~20s, however, there could be other factors (browser, OS, etc) that affect it. However, I agree with your assessment on keeping things more unified. That's part of the reason I submitted this without first verifying it, I figured it was good update since worst case it made things a little more simple. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a bit of history around the hardcoded style HOC, it looks like it was a workaround for pre-3.5 versions of material-ui, but since we are now on 3.5.1, it doesn't seem like there is a need any longer.
@@ -294,6 +294,9 @@ class MUIDataTable extends React.Component { | |||
if (props.options.rowsPerPageOptions) { | |||
this.options.rowsPerPageOptions = props.options.rowsPerPageOptions; | |||
} | |||
if (['scroll', 'stacked'].indexOf(this.options.responsive) === -1) { | |||
console.error('Invalid option value for responsive. Please use string option: stacked | scroll'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
Fix for #809
See comment #809 (comment) on how to reproduce the problem.
This PR refactors TableToolbar.js to use withStyles instead of styled.js. styled.js was being used because it allows you to access props when setting up your styles. However, the props used were not needed. They were used for this line:
According to the docs, options.responsive should have a value of either "scroll" or "stacked", so this check should always resolve to true.
This PR refactors TableToolbar so that it uses withStyles instead of styled.js.
Quick view of PR: https://codesandbox.io/s/mui-datatables-9pmct - You can use the method described in the comment above to see that the memory difference between styled.js and withStyles (original / styled.js version here: https://codesandbox.io/s/muidatatables-custom-toolbar-5o1hr - though you need to enable the Toolbar in that example to see the memory not being released).See #829 (comment)