react-native-portal: RangeError - Maximum call stack size exceeded.

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 36 (16 by maintainers)

Most upvoted comments

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.

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

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

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

@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

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

@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

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 sure, I will create a repo later today 😉

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

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

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 😃

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