nhagen/react-intercom

Fail to catch errors on unmount

Closed this issue · 3 comments

If Intercom isn't loaded by the time the component unmounts an uncaught error is thrown.

index.js:106 Uncaught TypeError: window.Intercom is not a function
at Intercom.componentWillUnmount (index.js:106)
at ReactCompositeComponent.js:409
at measureLifeCyclePerf (ReactCompositeComponent.js:75)
at ReactCompositeComponentWrapper.unmountComponent (ReactCompositeComponent.js:408)

zchsh commented

Also running into this problem - have routes split into authorized and unauthorized routes, with Intercom on the authorized route only, and when navigating from authorized to unauthorized and then back again this error always shows up.

A bit new to React etc, but it would it make sense to do something like

componentWillUnmount() {
    if (!canUseDOM) return false;
    if (!window.Intercom) return false;

    window.Intercom('shutdown');

    delete window.Intercom;
  }

It looks like #36 fixes this issue - any chance you can merge @nhagen? Thanks!

I rewrote this package today and may have resolved this issue. See more details at #73 . Closing for now, but happy to re-open if this is still an issue.