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

Uncaught Error: Maximum update depth exceeded on tab change #2821

Closed
6 tasks done
jordoh opened this issue Jul 26, 2019 · 9 comments · May be fixed by actionhero/actionhero-react-native-example#33
Closed
6 tasks done

Comments

@jordoh
Copy link

jordoh commented Jul 26, 2019

I have gone through these following points

Issue Description

Changing tabs results in the following exception:

Invariant Violation: 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.

image

This happens before the function provided to onChangeTab is called.

native-base 2.13.4
react 16.8.3
react-native 0.59.10

Expected behaviour

No crash.

Actual behaviour

Crash.

Steps to reproduce

        <Tabs
          initialPage={ 0 }
          page={ currentTabIndex }
          onChangeTab={ this._onTabChange }
          ref={ this._setTabs }
          contentProps={ { keyboardDismissMode: "none" } }
        >
          <Tab heading="TAB 1">
            { currentTabIndex === 0 ? this._renderQuickResults() : null }
          </Tab>
          <Tab heading="TAB 2">
            { currentTabIndex === 1 ? this._renderFullResults() : null }
          </Tab>
        </Tabs>

Is the bug present in both iOS and Android or in any one of them?

Happens on both iOS and Android.

Any other additional info which would help us debug the issue quicker.

This appears to be similar to #2812 and #2810

@jordoh
Copy link
Author

jordoh commented Jul 26, 2019

Also: I can confirm that changing ScrollableTabView's componentDidUpdate to UNSAFE_componentWillReceiveProps fixes the issue.

@majugurci
Copy link

majugurci commented Jul 31, 2019

I have the same issue.

Environment:
expo 34.0.0
native-base 2.13.4

I have made a minimal reproduction case:
https://snack.expo.io/ByT_9S1Xr

I have found the same issue from before:
#2359

The issue from before had a solution with binding this.setState but I'm using functional component and useState.

EDIT: I can confirm it is working as expected when using class component:
https://snack.expo.io/SkyvkLyXr

EDIT 2: I have made a mistake in previous code example edit. I have not used the variable from component's state so page is undefined, it is just calling onChangeTab but it is not referencing state variable. If state variable is properly referenced the same is happening (maximum update depth):
https://snack.expo.io/Sy3gBI1XS

EDIT 3: I have found a hacky way to avoid this until this is fixed:
https://snack.expo.io/HkEk5GemB

PlabanJr added a commit that referenced this issue Aug 1, 2019
@PlabanJr PlabanJr reopened this Aug 1, 2019
@equesteo
Copy link

equesteo commented Aug 2, 2019

I continue to have this problem even with this fix. It might be slightly different, but it seems like the onChangeEvent is firing more than one time with different page number values when the tab is switched, leading to an infinite loop.

@Slessi
Copy link

Slessi commented Aug 5, 2019

same here, UNSAFE_componentWillReceiveProps doesn't change anything for me

@PlabanJr
Copy link
Contributor

PlabanJr commented Aug 5, 2019

I continue to have this problem even with this fix. It might be slightly different, but it seems like the onChangeEvent is firing more than one time with different page number values when the tab is switched, leading to an infinite loop.

Can you please provide us with a snack to reproduce.

@ricardochen
Copy link

ricardochen commented Aug 12, 2019

In my case I just removed the property
page={this.state.activeTab} from component Tabs

@hellsan631
Copy link

hellsan631 commented Aug 14, 2019

Here is an example of this behavior:

https://snack.expo.io/@hellsan631/native-base-tabs-example

I should be able to control the state of tabs, so that they can respond to changes in the outside world.

I would expect onChangeTab to fire only once when a tab is changed internally, not when the page is changed externally.

@PlabanJr
Copy link
Contributor

Please try out our latest release v2.12.5. This issue has been taken care of.

Thank you for reporting!

@gaohan1994
Copy link

Please try out our latest release v2.12.5. This issue has been taken care of.

Thank you for reporting!

Hi, there
I'm using native-base@2.13.0 in my project, but still got this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants