diff --git a/src/api.js b/src/api.js index d57ddf69..3caa5a0d 100644 --- a/src/api.js +++ b/src/api.js @@ -34,7 +34,10 @@ const api = { open: ( { authentication, canChat, entry, entryOptions, groups, nodeId, theme, user } ) => { authenticator.init( authentication ); - const targetNode = createTargetNode( { nodeId, theme, groups, entryOptions } ); + const { + targetNode, + heightInterval + } = createTargetNode( { nodeId, theme, groups, entryOptions } ); authenticator .login() @@ -49,6 +52,11 @@ const api = { } ) ) .catch( error => renderError( targetNode, { error } ) ); + + // a cleanup function + return () => { + clearInterval( heightInterval ) + } }, /** * Method to subscribe to Happychat events, either 'availability' or 'chatStatus'. diff --git a/src/index.js b/src/index.js index eee95bd6..2bebfbff 100644 --- a/src/index.js +++ b/src/index.js @@ -165,14 +165,14 @@ const createIframe = ( { nodeId, theme }, assetsLoadedHook = () => {} ) => { targetNode.appendChild( spinnerLine ); iframeElement.contentDocument.body.appendChild( targetNode ); - setInterval( () => { + const heightInterval = setInterval( () => { const h = iframeElement.contentDocument.scrollingElement.scrollHeight; if ( iframeElement.offsetHeight != h ) { iframeElement.setAttribute( 'height', h + 'px' ); } }, 200 ); - return targetNode; + return { targetNode, heightInterval }; }; const isAnyCanChatPropFalse = ( canChat, { primaryOptions, secondaryOptions, itemList, defaultValues } ) => {