question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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.

  1. Render a Tabs component with many tabs. Include the props scrollButtons="auto" and scrollable={true}. Make sure the tabs can scroll.
  2. 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:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
DekelYossefcommented, Nov 28, 2018

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!

1reaction
eps1loncommented, Nov 28, 2018

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 of div[role="tabslist"] is changing on every cDU

Update2:

  • Fix looks promising. Could everybody who was able to reproduce it check out: https://6233p4jzpn.codesandbox.io/ The solution was to snapshot measuring and scroll properties of the tabslist and use those instead of the current ref to determine if we should update. Overall I think we might be able to simplify the component by always rendering the indicators and simply let overflow: hidden and some css translate do the rest.
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Tabs] Inifinite loop in the scroll button logic #13699 - GitHub
The number of tabs I am rendering causes the scroll buttons to display at all times. If the initial value correlates to one...
Read more >
Scroll Events and Intersection Observer - Beginner JavaScript
In this video we will learn about scroll events. A scroll event is when someone goes ahead and scrolls on the page or...
Read more >
Scroll loop - CodePen
Infinite scroll loop which positions you to the top or bottom of the container when the opposite end is reached. Horizontal demo: http://codepen.io/vi......
Read more >
How to Scroll to Top, Bottom or Any Section in React with a ...
In this hands-on guide, we will learn how to make a React button that allows users to scroll to the top, bottom or...
Read more >
Going “Meta GSAP”: The Quest for “Perfect” Infinite Scrolling
So you have to either loop the scroll position like this demo (found in the ScrollTrigger demos section) or hook directly into the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found