Describe the bug
Calling shutdown() will disconnect the Intercom callbacks. Calling boot again to re-connect will not re-attach them.
So everything will works but the callback will not be called anymore
A usecase is the user opting out of cookies for example and then re-opting in in the same session.
To Reproduce
Wrap your code in the IntercomProvider context
Have some logic call boot, then shutdown, then boot again
What happens:
All the reactivity of the IntercomProvider context is lost:
isOpen will not update anymore when the messanger is opened/closed
all the callbacks attached to the context will not be called anymore
no action code should go in the body of a component. This initialization should probably go inside a useEffect
the listeners attachments should be moved inside the "boot" function, as any shutdown call will disconnect them they need to be re-connected at every boot
// Attach callbacks on boot
const boot = React.useCallback(
(props?: IntercomProps) => {
if (!window.Intercom && !shouldInitialize) {
logger.log(
'warn',
'Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`',
);
return;
}
const metaData: RawIntercomBootProps = {
app_id: appId,
...(apiBase && { api_base: apiBase }),
...(props && mapIntercomPropsToRawIntercomProps(props)),
};
window.intercomSettings = metaData;
IntercomAPI('boot', metaData);
// attach listeners
IntercomAPI('onHide', onHideWrapper);
IntercomAPI('onShow', onShowWrapper);
IntercomAPI('onUserEmailSupplied', onUserEmailSupplied);
if (onUnreadCountChange)
IntercomAPI('onUnreadCountChange', onUnreadCountChange);
isBooted.current = true;
},
[apiBase, appId, shouldInitialize, onHideWrapper, onShowWrapper, onUserEmailSupplied, onUnreadCountChange],
);
// Move inizialization in an effect run only on mount
useEffect(() => {
if (shouldInitialize && !isInitialized.current) {
initialize(appId, initializeDelay);
isInitialized.current = true;
if (autoBoot) {
boot(autoBootProps);
}
}
}, []);
Describe the bug Calling
shutdown()
will disconnect the Intercom callbacks. Calling boot again to re-connect will not re-attach them. So everything will works but the callback will not be called anymoreA usecase is the user opting out of cookies for example and then re-opting in in the same session.
To Reproduce
Codesandbox link https://codesandbox.io/p/sandbox/react-new
Expected behavior Calling boot should re-connet all the callbacks
Fix Suggestions This block of code in the IntercomProvider should be updated