Answered

[react-native] removing event listener throws "Maximum call stack size exceeded" error

  • 11 January 2023
  • 8 replies
  • 775 views

Howdy!

We're experiencing this issue after updating from 3.x SDK to 4.0.1 (https://github.com/intercom/intercom-react-native

 

react-native version: 0.70.5

 

 

Code sample (which is basically the same that you have in docs):

 

useEffect(() => {
const subscription = Intercom.addEventListener(
IntercomEvents.IntercomUnreadCountDidChange,
(response) => {
setCount(response.count);
}
);
 
return () => {
try {
subscription.remove();
} catch (e) {
console.log(e);
}
};
}, []);

 

Calling subscription.remove on line 11 during effect cleanup triggers an exception.

Line 13 prints:

[RangeError: Maximum call stack size exceeded]

Without try/catch block the call just fails silently due to this - https://github.com/facebook/react-native/issues/32673(which doesn't contribute to the original problem, just makes it go unnoticed).

 

 

Let me know what other details you might need.

 

What can be done about it? Thanks.

icon

Best answer by aykut.aydin 6 October 2023, 03:15

View original

8 replies

Userlevel 3
Badge +2

Looping in @user1207​  in case he has any ideas on that 🙌

Hey @alex t​! Oséas here from the Customer Support Engineering team 🕵️

 

I've opened a bug report on our end for this issue so our Product Team can investigate this further. Could you please reach out to us via the Messenger so we can add the conversation to the report and, if necessary, request more info? Make sure to mention this thread when opening the conversation so my teammate who will get the convo knows which issue to link. Once we add it, any updates made will generate an internal notification in the convo and we'll be able to notify you.

 

Thank you very much for flagging this to us - really appreciate it!

Thank you, I will

We are experiencing the the exact same issue since updating to 4.0.1, we are using react-native. And it seems the crash only occurs when running android in debug mode and the component that has the subscription cleanup, dismounts. Not entirely sure yet if it's affecting the app in production. Ios seems to have no problems.

We are encountering the same issue: removing the subscription to the unread message count throws an error:

ERROR  Warning: Internal React error: Attempted to capture a commit phase error inside a detached tree. This indicates a bug in React. Likely causes include deleting the same fiber more than once, committing an already-finished tree, or an inconsistent return pointer.

Error message:

RangeError: Maximum call stack size exceeded.

For us it’s happening on iOS, both in the simulator and on device. RN 0.68, Intercom 4.0.1.

Badge

Any update on this issue? It’s marked as solved, but it doesn’t look solved!

Any update on this issue? It’s marked as solved, but it doesn’t look solved!

I have yet to try it myself, but it does look like they have merged a pull request that fixes the infite loop issue in their latest release of react-native (5.0.0).

Userlevel 2
Badge +3

Hey everyone!

 

Just wanted to leave a reply here in case anyone is still experiencing this issue. The issue was resolved as the PR here was merged. If you use a version 5.0.0 or newer, you will not experience this issue any longer.

Reply