From 369a6ba73e4b99567b2b0808877ce8aaa80793bd Mon Sep 17 00:00:00 2001 From: "David J. Bradshaw" Date: Wed, 28 Aug 2024 16:28:44 +0100 Subject: [PATCH] Use setTimeout(0) on events with void return type --- packages/child/index.js | 6 +++--- packages/core/index.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/child/index.js b/packages/child/index.js index 55a701dad..d3b524ab7 100644 --- a/packages/child/index.js +++ b/packages/child/index.js @@ -156,7 +156,7 @@ function iframeResizerChild() { sendTitle() initEventListeners() - onReady() + setTimeout(onReady) log('Initialization complete') log('---') @@ -1285,7 +1285,7 @@ The size() method has been deprecated and replaced with resize(). U const msgBody = getData() log(`PageInfo received from parent: ${msgBody}`) if (onPageInfo) { - onPageInfo(JSON.parse(msgBody)) + setTimeout(() => onPageInfo(JSON.parse(msgBody))) } else { // not expected, so cancel more messages sendMsg(0, 0, 'pageInfoStop') @@ -1297,7 +1297,7 @@ The size() method has been deprecated and replaced with resize(). U const msgBody = getData() log(`ParentInfo received from parent: ${msgBody}`) if (onParentInfo) { - onParentInfo(Object.freeze(JSON.parse(msgBody))) + setTimeout(onParentInfo(Object.freeze(JSON.parse(msgBody)))) } else { // not expected, so cancel more messages sendMsg(0, 0, 'parentInfoStop') diff --git a/packages/core/index.js b/packages/core/index.js index 9fbf9cf4d..be8ecabda 100644 --- a/packages/core/index.js +++ b/packages/core/index.js @@ -676,13 +676,13 @@ function chkEvent(iframeId, funcName, val) { if (settings[iframeId]) { func = settings[iframeId][funcName] - if (typeof func === 'function') { - retVal = func(val) - } else { + if (typeof func === 'function') + if (funcName === 'onClose' || funcName === 'onScroll') retVal = func(val) + else setTimeout(() => func(val)) + else throw new TypeError( `${funcName} on iFrame[${iframeId}] is not a function`, ) - } } return retVal