[Tabs] Inifinite loop in the scroll button logic
See original GitHub issue- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
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 😯
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 🕹
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 🔦
My tabs scroll. I am providing a value on render. That value may mean the Tabs component should scroll.
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v3.5.1 |
React | 16.6.3 |
Browser | latest chrome |
TypeScript | no |
etc. |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:15 (9 by maintainers)
Top GitHub Comments
Having the same issue… with v3.4.0 https://9oo90okxmo.codesandbox.io/ This is the same sandbox instance of @andrewtpoe, but full-screened. As you can see the error occurs. Thanks!
Tried this and it didn’t work. As it stands right now its toggling
showRightScroll
on every cDU. Needs further investigation. Maybe gSBU will help.Update:
clientWidth
ofdiv[role="tabslist"]
is changing on everycDU
Update2:
overflow: hidden
and some csstranslate
do the rest.