[Tabs] Inifinite loop in the scroll button logic #13699
andrewtpoe posted onGitHub
<!--- Provide a general summary of the issue in the Title above -->
<!-- Thank you very much for contributing to Material-UI by creating an issue! ❤️ To avoid duplicate issues we ask you to check off the following list. -->
<!-- Checked checkbox should look like this: [x] -->
- This is not a v0.x issue. <!-- (v0.x is no longer maintained) -->
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
<!--- Describe what should happen. -->
I am rendering a tabs component with scrollButtons="auto"
and scrollable={true}
. The number of tabs I am rendering causes the scroll buttons to display at all times. If the initial value
correlates to one of the tabs hidden on first render, the tabs component should scroll to display the correct tab and show it as selected.
Current Behavior 😯
<!--- Describe what happens instead of the expected behavior. -->
I receive the following error:
Uncaught Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
at invariant (react-dom.development.js:57)
at scheduleWork (react-dom.development.js:19364)
at Object.enqueueSetState (react-dom.development.js:12789)
at Tabs.push../node_modules/react/cjs/react.development.js.Component.setState (react.development.js:354)
at Tabs._this.updateScrollButtonState (Tabs.js:264)
at Tabs.componentDidUpdate (Tabs.js:309)
at commitLifeCycles (react-dom.development.js:16737)
at commitAllLifeCycles (react-dom.development.js:18160)
at HTMLUnknownElement.callCallback (react-dom.development.js:147)
at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
at invokeGuardedCallback (react-dom.development.js:250)
at commitRoot (react-dom.development.js:18365)
at completeRoot (react-dom.development.js:19894)
at performWorkOnRoot (react-dom.development.js:19817)
at performWork (react-dom.development.js:19722)
at performSyncWork (react-dom.development.js:19696)
at requestWork (react-dom.development.js:19551)
at scheduleWork (react-dom.development.js:19358)
at Object.enqueueSetState (react-dom.development.js:12789)
at Tabs.push../node_modules/react/cjs/react.development.js.Component.setState (react.development.js:354)
at Tabs._this.updateScrollButtonState (Tabs.js:264)
at Tabs.js:280
at later (index.js:28)
Steps to Reproduce 🕹
<!--- Provide a link to a live example (you can use codesandbox.io) and an unambiguous set of steps to reproduce this bug. Include code to reproduce, if relevant (which it most likely is). This codesandbox.io template may be a good starting point: https://codesandbox.io/s/github/mui-org/material-ui/tree/master/examples/create-react-app If you're using typescript a better starting point would be https://codesandbox.io/s/github/mui-org/material-ui/tree/master/examples/create-react-app-with-typescript If YOU DO NOT take time to provide a codesandbox.io reproduction, should the COMMUNITY take time to help you? -->
Link: https://codesandbox.io/s/9oo90okxmo
This issue has happened for me with the code sandbox link, however, it is intermittent. It appears to happen more regularly with more (not necessarily related) elements rendered on screen. This makes me suspect a race condition somewhere, but as I'm not familiar with the library code I'll leave that to the experts for now.
- Render a
Tabs
component with many tabs. Include the propsscrollButtons="auto"
andscrollable={true}
. Make sure the tabs can scroll. - Set the initial value for the Tabs to a value that forces the
Tabs
component to scroll.
Context 🔦
<!--- What are you trying to accomplish? How has this issue affected you? Providing context helps us come up with a solution that is most useful in the real world. -->
My tabs scroll. I am providing a value on render. That value may mean the Tabs component should scroll.
Your Environment 🌎
<!--- Include as many relevant details about the environment with which you experienced the bug. If you encounter issues with typescript please include version and tsconfig. -->
Tech | Version |
---|---|
Material-UI | v3.5.1 |
React | 16.6.3 |
Browser | latest chrome |
TypeScript | no |
etc. |