From fbfbf80f0a916ae339eb87e70fc72964d936ce77 Mon Sep 17 00:00:00 2001 From: "David J. Bradshaw" Date: Tue, 25 Jun 2024 10:28:09 +0100 Subject: [PATCH] Fixed: Issue where child code is run before document.body has a value --- packages/child/index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/child/index.js b/packages/child/index.js index a465afe22..8336c6541 100644 --- a/packages/child/index.js +++ b/packages/child/index.js @@ -99,6 +99,9 @@ const capitalizeFirstLetter = (string) => const isDef = (value) => `${value}` !== '' && value !== undefined +const usedTags = new WeakSet() +const addUsedTag = (el) => typeof el === 'object' && usedTags.add(el) + function getElementName(el) { switch (true) { case !isDef(el): @@ -171,6 +174,8 @@ function init() { setupMouseEvents() startEventListeners() inPageLinks = setupInPageLinks() + addUsedTag(document.documentElement) + addUsedTag(document.body) sendSize('init', 'Init message from host page', undefined, undefined, VERSION) sendTitle() onReady() @@ -849,13 +854,9 @@ function setupMutationObserver() { bodyObserver = setupBodyMutationObserver() } -const usedTags = new WeakSet() -usedTags.add(document.documentElement) -usedTags.add(document.body) - function usedEl(el) { if (usedTags.has(el)) return true - usedTags.add(el) + addUsedTag(el) info( `\nHeight calculated from: ${getElementName(el)} (${elementSnippet(el)})`, )