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

RangeError - Maximum call stack size exceeded. #15

Closed
alexanderwallin opened this issue Mar 18, 2021 · 36 comments · Fixed by #20
Closed

RangeError - Maximum call stack size exceeded. #15

alexanderwallin opened this issue Mar 18, 2021 · 36 comments · Fixed by #20
Assignees

Comments

@alexanderwallin
Copy link

alexanderwallin commented Mar 18, 2021

Hi there,

I liked the API design of this library and decided to use it together with react-native-modalize. It worked well locally, but in distribution builds the below error caused crashes on both iOS and Android.

I switched to another library and unfortunately can't put time into creating a bare minimum reproducible case. But I thought I'd share it!

RangeError
Maximum call stack size exceeded.

    node_modules/immer/dist/immer.esm.js:1:712 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588 
    node_modules/immer/dist/immer.esm.js:1:782 
    [native code] forEach
    node_modules/immer/dist/immer.esm.js:1:745 i
    node_modules/immer/dist/immer.esm.js:1:2562 M
    node_modules/immer/dist/immer.esm.js:1:3055 A
    node_modules/immer/dist/immer.esm.js:1:2588
@gorhom
Copy link
Owner

gorhom commented Mar 19, 2021

hi @alexanderwallin, could you provide a reproducible sample code so i could investigate it.

@gorhom gorhom self-assigned this Mar 19, 2021
@alexanderwallin
Copy link
Author

@gorhom Sorry, like I said in the description, I unfortunately don't have the time.

@beqramo
Copy link

beqramo commented Mar 25, 2021

@gorhom I have the same problem, and reproduction steps are simple, take any example and place Portalhost in the parent component of Portal and you will see the problem. I agree @alexanderwallin that it is only in production.

image:
image

@gorhom
Copy link
Owner

gorhom commented Mar 25, 2021

@beqramo thanks for adding more context to this bug, i will look into it

@beqramo
Copy link

beqramo commented Mar 30, 2021

@gorhom by the way, I'm using it with https://github.com/dabakovich/react-native-controlled-mentions#readme
maybe it will give you some clue, and maybe the problem is when using it with a library.

@mobily
Copy link

mobily commented May 10, 2021

I was struggling with this error as well, and I was able to fix it only by completely removing immer and patching the lib with patch-package.

@gorhom I will do some testing once again, but I think that the reducer logic isn't very complex, and immer looks like a redundant dependency, if you would like to remove it, I can create a PR :)

@alexanderwallin
Copy link
Author

No idea if this causes the issue, but the return here looks a little suspicious, I don't think you are supposed to return the draft.
https://github.com/gorhom/react-native-portal/blob/master/src/state/reducer.ts#L132

@beqramo
Copy link

beqramo commented May 10, 2021

indeed I was able to resolve this issue by wrapping my components in useMemo. there was rerender problem and so for me, that was a solution.

@mobily
Copy link

mobily commented May 10, 2021

@alexanderwallin I've just tested it, and it still doesn't work, the same error occurs 😢

@beqramo cool! nevertheless, I think it should work either with or without memo

@gorhom
Copy link
Owner

gorhom commented May 11, 2021

i will look into this today, sorry for the late response

@gorhom
Copy link
Owner

gorhom commented May 11, 2021

@mobily did removing Immer solve the problem ?

@mobily
Copy link

mobily commented May 12, 2021

@gorhom yup, I have been looking for the root of this issue for a few hours and couldn't find anything, and removing Immer did solve the issue eventually

@gorhom
Copy link
Owner

gorhom commented May 12, 2021

@mobily alright! one more thing, could you provide a reproducible sample code ?

@mobily
Copy link

mobily commented May 12, 2021

@gorhom sure, I will create a repo later today ;)

@timbastin
Copy link

I am having the same issue. Is there any fix for this yet?

@gorhom
Copy link
Owner

gorhom commented May 19, 2021

@mobily any luck with the repo ?

@mobily
Copy link

mobily commented May 20, 2021

@gorhom 👋 no luck :( I have created a fresh RN project with basic components/hooks/helpers that I use in my commercial project, and it works with no error, the app doesn't crash in the release mode… not sure why, I'm looking for a reason

@jordoh
Copy link

jordoh commented May 25, 2021

I'm seeing the same exception using react-native-portal via react-native-bottom-sheet - it only happens in production, when a button on one BottomSheetModal triggers a present on a second BottomSheetModal. I've spent some time trying to reproduce in expo (with expo in production mode) without any success.

@alexco2
Copy link

alexco2 commented May 28, 2021

I have the same error in react-native-bottom-sheet. It happens when I close the screen that holds the bottomSheetModalRef while the BottomSheetModal is still open (for example with the hardware back button). In that case the BottomSheetModal closes after the screen is closed. If I try to open the BottomSheetModal again after opening the screen, the app crashes with the error "RangeError: Maximum call stack size exceeded" error.
I tried to close the BottomSheetModal activley when the screen unmounts with useEffect, which did not solve the problem. If I listen for the Backhandler and close the BottomSheetModal as soon as the Back Button is pressed, the error just occurs, if I fully extended the BottomSheetModal first. Then the BottomSheetModal is closed when pressing the Back Button, but can not be opened again. After closing and opening the screen that holds the bottomSheetModalRef, the app crashes when I try to open the BottomSheetModal again. In development, I get the error TypeError: Cannot read property 'minimize' of null, js engine: hermes (picture). The BottomSheetModalProvider is on the top level on my App btw.
I hope this description somehow helps.
BottomSheetModal error

@gorhom
Copy link
Owner

gorhom commented Jun 10, 2021

Hi everyone , could anyone try to reproduce it on v1.0.6, thanks ?

@egadstar
Copy link
Contributor

I had seen this error before, but no more. Thanks.

@mobily
Copy link

mobily commented Jul 12, 2021

@gorhom works fine! thanks for fixing this issue ❤️

@gorhom
Copy link
Owner

gorhom commented Jul 12, 2021

@mobily thanks for testing it 👏

@dburdan
Copy link

dburdan commented Jul 16, 2021

We're also getting Maximum call stack size exceeded when dismissing one BottomSheetModal and immediately opening another. Using @gorhom/portal: 1.0.7 & @gorhom/bottom-sheet": 4.0.0-alpha.18. Only happens in release mode, and haven't been able to find a solution.

@gorhom
Copy link
Owner

gorhom commented Jul 17, 2021

@dburdan could you please provide more info ( env, os, rn version ) or a reproducible sample ? I appreciate it

@dburdan
Copy link

dburdan commented Jul 18, 2021

@gorhom We are running react-native: 0.64.2. Crash exists across iOS and Android, and every device we've tested.

It's been difficult to trace since everything works great when in debug mode. The crash only appears after building to device or to simulator in release mode. Is there any other information I could share that would be helpful? If I get some time this week, I'll try to build a reproducible example.

@UrbanChrisy
Copy link

I was using react context provider inside the Portal component, and I was getting this issue in a release build only like above. When I moved the context provider to the outside of the PortalHost. Because I'm using the portal host at a different layer than the root host. Then I no longer had this issue. I don't know what would cause this, but ill try to create a reproducible expo demo tomorrow. Ill update where I get to.

@UrbanChrisy
Copy link

UrbanChrisy commented Aug 20, 2021

Unable to reproduce as of yet. Ive spent wayyy too long on this already sorry guys unable to give a demo. I managed to fix my issue by moving the context provider to wrap the portal host inside the nested child portal

@lucianojsjr
Copy link

@gorhom Are there some news about this problem? I'm getting the same error and I'm using [email protected].

@SCasarotto
Copy link

I am also seeing this issue but it only seems to appear once the app is in release mode or built.

@egadstar
Copy link
Contributor

egadstar commented Sep 20, 2021

Could this be the source based on the original stacktrace? immerjs/immer#832

immerjs/immer#673

@egadstar
Copy link
Contributor

I ended up forking and refactoring immer from the project; my production builds are no longer crashing with the RangeError, so feel pretty certain that the issue is related to a bug within immer.

@gorhom
Copy link
Owner

gorhom commented Sep 20, 2021

@egadstar would you mind submitting a pr :)

@egadstar
Copy link
Contributor

Yea, no problem. Because I removed immer, I didn't know if you wanted to move that direction. I'll get it submitted, and you can review it.

@egadstar
Copy link
Contributor

I did a poor job reading through this thread; didn't realize that @mobily had already zeroed in on immer.

@gorhom
Copy link
Owner

gorhom commented Sep 21, 2021

this should be fixed with v1.0.9 , thanks to @egadstar PR 👏

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