From cc30d2a9ca359f569deb02ee5daa5827caf23a70 Mon Sep 17 00:00:00 2001 From: "David J. Bradshaw" Date: Mon, 24 Jun 2024 11:17:39 +0100 Subject: [PATCH 1/6] Fixed: WeakMap error on 0 height iframes #1275 --- packages/child/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/child/index.js b/packages/child/index.js index bcb01e0dc..75132243d 100644 --- a/packages/child/index.js +++ b/packages/child/index.js @@ -866,8 +866,10 @@ function getMaxElement(side) { let elVal = 0 let len = calcElements.length - let maxEl - let maxVal = 0 + let maxEl = document.documentElement + let maxVal = hasTags + ? 0 + : document.documentElement.getBoundingClientRect().bottom let timer = performance.now() calcElements.forEach((element) => { @@ -896,11 +898,12 @@ function getMaxElement(side) { if (len > 1) usedEl(maxEl) const logMsg = ` -Parsed ${len} element${(len = SINGLE ? '' : 's')} in ${timer.toPrecision(3)}ms +Parsed ${len} element${len === SINGLE ? '' : 's'} in ${timer.toPrecision(3)}ms ${Side} ${hasTags ? 'tagged ' : ''}element found at: ${maxVal}px Position calculated from HTML element: ${getElementName(maxEl)} (${elementSnippet(maxEl, 100)})` - if (timer < 1.1 || isInit || hasTags) { + if (timer < 4 || len < 10 || hasTags || isInit) { + console.log('len', len) log(logMsg) } else { if (perfWarned > timer) return maxVal From a9433347f319d26dd890e37d0c422e18969b9aa8 Mon Sep 17 00:00:00 2001 From: "David J. Bradshaw" Date: Mon, 24 Jun 2024 11:21:07 +0100 Subject: [PATCH 2/6] Remove console.log --- packages/child/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/child/index.js b/packages/child/index.js index 75132243d..72af0fb53 100644 --- a/packages/child/index.js +++ b/packages/child/index.js @@ -903,7 +903,6 @@ ${Side} ${hasTags ? 'tagged ' : ''}element found at: ${maxVal}px Position calculated from HTML element: ${getElementName(maxEl)} (${elementSnippet(maxEl, 100)})` if (timer < 4 || len < 10 || hasTags || isInit) { - console.log('len', len) log(logMsg) } else { if (perfWarned > timer) return maxVal From e34f29fd01ea02900987a4e76ef6a6e49b63182f Mon Sep 17 00:00:00 2001 From: "David J. Bradshaw" Date: Mon, 24 Jun 2024 11:29:51 +0100 Subject: [PATCH 3/6] Demagic numbers --- packages/child/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/child/index.js b/packages/child/index.js index 72af0fb53..3456f994a 100644 --- a/packages/child/index.js +++ b/packages/child/index.js @@ -3,6 +3,9 @@ import formatAdvise from '../common/format-advise' import { addEventListener, removeEventListener } from '../common/listeners' import { getModeData } from '../common/mode' +const PERF_TIME_LIMIT = 4 +const PERF_MIN_ELEMENTS = 10 + const checkVisibilityOptions = { contentVisibilityAuto: true, opacityProperty: true, @@ -902,10 +905,9 @@ Parsed ${len} element${len === SINGLE ? '' : 's'} in ${timer.toPrecision(3)}ms ${Side} ${hasTags ? 'tagged ' : ''}element found at: ${maxVal}px Position calculated from HTML element: ${getElementName(maxEl)} (${elementSnippet(maxEl, 100)})` - if (timer < 4 || len < 10 || hasTags || isInit) { + if (timer < PERF_TIME_LIMIT || len < PERF_MIN_ELEMENTS || hasTags || isInit) { log(logMsg) - } else { - if (perfWarned > timer) return maxVal + } else if (perfWarned < timer) { perfWarned = timer advise( `Performance Warning From 15538b8ca579210df16de2618d31e6469c6c593e Mon Sep 17 00:00:00 2001 From: "David J. Bradshaw" Date: Mon, 24 Jun 2024 12:34:53 +0100 Subject: [PATCH 4/6] Only perf warn if two size checks in a row are slow --- packages/child/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/child/index.js b/packages/child/index.js index 3456f994a..565024c28 100644 --- a/packages/child/index.js +++ b/packages/child/index.js @@ -862,7 +862,8 @@ function usedEl(el) { return false } -let perfWarned = 0 +let perfWarned = PERF_TIME_LIMIT +let lastTimer = PERF_TIME_LIMIT function getMaxElement(side) { const Side = capitalizeFirstLetter(side) @@ -907,8 +908,8 @@ Position calculated from HTML element: ${getElementName(maxEl)} (${elementSnippe if (timer < PERF_TIME_LIMIT || len < PERF_MIN_ELEMENTS || hasTags || isInit) { log(logMsg) - } else if (perfWarned < timer) { - perfWarned = timer + } else if (perfWarned < timer && perfWarned < lastTimer) { + perfWarned = timer + 1 advise( `Performance Warning @@ -919,6 +920,7 @@ ${logMsg}`, ) } + lastTimer = timer return maxVal } From eb8e23ca28edc09c5cbed732f095d0a681b24551 Mon Sep 17 00:00:00 2001 From: "David J. Bradshaw" Date: Mon, 24 Jun 2024 12:57:20 +0100 Subject: [PATCH 5/6] set perf warn increase to 20% --- packages/child/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/child/index.js b/packages/child/index.js index 565024c28..4a01bf0bf 100644 --- a/packages/child/index.js +++ b/packages/child/index.js @@ -909,7 +909,7 @@ Position calculated from HTML element: ${getElementName(maxEl)} (${elementSnippe if (timer < PERF_TIME_LIMIT || len < PERF_MIN_ELEMENTS || hasTags || isInit) { log(logMsg) } else if (perfWarned < timer && perfWarned < lastTimer) { - perfWarned = timer + 1 + perfWarned = timer * 1.2 advise( `Performance Warning From 440e27b2a7c581e3303ee70e6a7298ff2cfea975 Mon Sep 17 00:00:00 2001 From: "David J. Bradshaw" Date: Mon, 24 Jun 2024 20:08:44 +0100 Subject: [PATCH 6/6] Update advise msgs --- packages/child/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/child/index.js b/packages/child/index.js index 4a01bf0bf..a465afe22 100644 --- a/packages/child/index.js +++ b/packages/child/index.js @@ -4,7 +4,7 @@ import { addEventListener, removeEventListener } from '../common/listeners' import { getModeData } from '../common/mode' const PERF_TIME_LIMIT = 4 -const PERF_MIN_ELEMENTS = 10 +const PERF_MIN_ELEMENTS = 99 const checkVisibilityOptions = { contentVisibilityAuto: true, @@ -914,8 +914,6 @@ Position calculated from HTML element: ${getElementName(maxEl)} (${elementSnippe `Performance Warning Calculating the page size took an excessive amount of time. To improve performance add the data-iframe-size attribute to the ${side} most element on the page. - -More info: https://iframe-resizer.com/performance. ${logMsg}`, ) } @@ -961,7 +959,9 @@ This causes iframe-resizer to fall back to checking the position of every To fix this issue, and remove this warning, you can either ensure the content of the page does not overflow the element or alternatively you can add the attribute data-iframe-size to the elements on the page that you want iframe-resizer to use when calculating the dimensions of the iframe. When present the ${side} margin of the ${furthest} element with a data-iframe-size attribute will be used to set the ${dimension} of the iframe. - + +More info: https://iframe-resizer.com/performance. + (Page size: ${scrollSize} > document size: ${ceilBoundingSize})` advise(overflowDetectedMessage)