Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect initial height. 'init' event stacking + called excessively. Page bogged down. tolerance ignored #1309

Closed
Gamerweazel opened this issue Aug 19, 2024 · 29 comments · Fixed by #1312

Comments

@Gamerweazel
Copy link

Describe the bug
We have purchased a business license but are using GPLv3 in the codepen for testing.
The initial height is incorrect and doesn't get the right height.
The 'init' event keeps stacking and getting called multiple times. Even when I have tolerance set, it is ignored.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codepen.io/Andrew-Eames/pen/poXaZZJ
  2. Wait for the iframe to load in the center of the page.
  3. See the frame is not correct initial height on load.
  4. Open the developer console to see the resize events I am logging.
  5. In the iframe there should be a form with a password login. Cycle between the 'Forgot Password' page and the login page several times and see the 'init' event stacking in the console logs.

Expected behavior
The iframe should get a correct initial height.
The iframe-resizer should not be stacking and bogging down the page.

Screenshots
If applicable, add screenshots to help explain your problem.

Screen.Recording.2024-08-19.at.1.30.16.PM.mov

Desktop (please complete the following information):

  • OS: macOS 13.1 (22C65)
  • Browser Chrome
  • Version 127.0.6533.100 (Official Build) (arm64)
@davidjbradshaw
Copy link
Owner

I can have more of a look tomorrow, but the issue is going to be the footer at the bottom of the page causing a resize loop. The workaround is to pick another element on the page to use to measure the content size and then add a data-iframe-size attribute to tell iframe-resizer to use that element to calculate the page size. You can then set the offsetSize option to adjust the iframe to include your footer.

@Gamerweazel
Copy link
Author

Gamerweazel commented Aug 19, 2024

I can have more of a look tomorrow, but the issue is going to be the footer at the bottom of the page causing a resize loop. The workaround is to pick another element on the page to use to measure the content size and then add a data-iframe-size attribute to tell iframe-resizer to use that element to calculate the page size. You can then set the offsetSize option to adjust the iframe to include your footer.

@davidjbradshaw . I have updated the pen to include an offsetSize: 150 and now I'm using the main (which doesn't contain the footer) with the data-iframe-size attribute in the child iframe. The resize loop is still in effect when I do my navigation between screens. But it appears the initial height is fixed. The 'init' event is still stacking considerably and slowing the page.

@davidjbradshaw
Copy link
Owner

That is very strange. It's getting late here in the U.K., I will dig into this more tomorrow.

@Gamerweazel
Copy link
Author

That is very strange. It's getting late here in the U.K., I will dig into this more tomorrow.

Thank you. For the record, we were not getting this same issue with the v4. Instead we were able to replicate #1156 on v4 and thought upgrading would fix the issue, which it did but now we are getting this new issue.

@davidjbradshaw
Copy link
Owner

One last thing, could you install the latest beta version in this example and set the log option to true. The beta builds have a lot more logging details in them.

@Gamerweazel
Copy link
Author

One last thing, could you install the latest beta version in this example and set the log option to true. The beta builds have a lot more logging details in them.

@davidjbradshaw Done. Both child frame and parent pen have been updated to @5.2.4-beta.4 and log: true on parent pen. I see lots of logs now, and I do see multiple instances of the same events like After Print and [iframe-resizer][frame] Create <body/> MutationObserver coming through on the same page.

@Gamerweazel
Copy link
Author

Another thing to note, the child frame is using react + react css transition replace library https://www.npmjs.com/package/react-css-transition-replace to animate height changes between navigation states. This could be something we are doing that could be effecting the height calculations.

@davidjbradshaw
Copy link
Owner

Thanks, that will make finding the source of the loop easier.

@davidjbradshaw
Copy link
Owner

davidjbradshaw commented Aug 20, 2024

Having slept on this and taken a look, I think issue is that you are calling the child script every time the React render runs and I accidentally removed the check from this in the latest version.

Can you please try v5.2.5-beta.1 as I have just added back an updated check and you should now see a warning if you call it more than once, rather than have it cycle round and set another instance up each time.

Going forward you should move the import for the child script to outside of the React Render.

I expect the footer might still cause issues, but if so, that is a different problem we can look at.

@davidjbradshaw
Copy link
Owner

I had a look at the source code of react-css-transition-replace and I think it will cause issues, but these can be worked around using the Custom page size options.

@Gamerweazel
Copy link
Author

Having slept on this and taken a look, I think issue is that you are calling the child script every time the React render runs and I accidentally removed the check from this in the latest version.

Can you please try v5.2.5-beta.1 as I have just added back an updated check and you should now see a warning if you call it more than once, rather than have it cycle round and set another instance up each time.

Going forward you should move the import for the child script to outside of the React Render.

I expect the footer might still cause issues, but if so, that is a different problem we can look at.

@davidjbradshaw I was thinking it was somehow related to react rendering as well, so on the child frame I made sure to include it via CDN in the main html index just so make sure it was never touched by JS. So I don't think that's the problem, react never initializes it.

@Gamerweazel
Copy link
Author

I had a look at the source code of react-css-transition-replace and I think it will cause issues, but these can be worked around using the Custom page size options.

@davidjbradshaw I am using the custom frame size option on the 'main' tag as per your suggestion and the problem persists. You can see in the child frame on the pen I'm using the 'data-iframe-size'. The 'main' tag does contain the element subject to react-css-transition-replace but we've hadn't had this issue with v4.

@davidjbradshaw
Copy link
Owner

@Gamerweazel, can you please give the latest beta a try, so we can rule it out one way or the other.

@davidjbradshaw
Copy link
Owner

I placed your iframe in my test page and I get the following logged out. The child script gets initialised twice on this page. This is either down to you navigating from one page to another or it being loaded twice.

The other odd thing is that it thinks the iframe has been hidden a few times, due to the content height being set to zero. Not a major issue, as when this happens it returns the existing iframe height, so nothing happens. But it did strike me a little strange. Are you completely deleting all the content on the page a few times?

I will need a login, if you would like me to see what happens on the next page.

[iframe-resizer][Parent page: iFrameResizer0] Added missing iframe ID: iFrameResizer0 (https://stage.xp.audience.io/experience/1603834)
[iframe-resizer][Parent page: iFrameResizer0] Direction set to "vertical"
[iframe-resizer][Parent page: v5.2.5-beta.1 (Business)]
[iframe-resizer][Parent page: iFrameResizer0] IFrame scrolling disabled for iFrameResizer0
[iframe-resizer][Parent page: iFrameResizer0] [iFrame.onload] Sending message to iframe[iFrameResizer0] (iFrameResizer0:8:false:true:32:true:true::auto:::0:true:child:auto:true:::true:GPLv3:5.2.5-beta.1:0:false) targetOrigin: https://stage.xp.audience.io
[iframe-resizer][iFrameResizer0] Cross domain iframe detected.
[iframe-resizer][iFrameResizer0] Version mismatch

The parent and child pages are running different versions of iframe resizer.

Parent page: 5.2.5-beta.1 - Child page: 5.2.4-beta.4.

[iframe-resizer][iFrameResizer0] width calculation method set to "auto"
[iframe-resizer][iFrameResizer0] Tagged elements found: false
[iframe-resizer][iFrameResizer0] Add event listener: Mouse Enter
[iframe-resizer][iFrameResizer0] Add event listener: Mouse Leave
[iframe-resizer][iFrameResizer0] Setting up location.hash handlers
[iframe-resizer][iFrameResizer0] HTML & body height set to "auto !important"
[iframe-resizer][iFrameResizer0] overflowedElements: 2
[iframe-resizer][iFrameResizer0] Page is hidden: HTML: 0  Page: 1426
[iframe-resizer][iFrameResizer0] Trigger event lock on
[iframe-resizer][iFrameResizer0] Sending message to host page (iFrameResizer0:1426:907:init:5.2.4-beta.4) via postMessage
[iframe-resizer][iFrameResizer0] Add event listener: After Print
[iframe-resizer][iFrameResizer0] Add event listener: Before Print
[iframe-resizer][iFrameResizer0] Add event listener: Ready State Change
[iframe-resizer][iFrameResizer0] Create <body/> MutationObserver
[iframe-resizer][iFrameResizer0] Attached resizeObserver: BODY
[iframe-resizer][iFrameResizer0] Initialization complete
[iframe-resizer][iFrameResizer0] ---
[iframe-resizer][Parent page: iFrameResizer0] Received: [iFrameSizer]iFrameResizer0:1426:907:init:5.2.4-beta.4
[iframe-resizer][Parent page: iFrameResizer0] Checking connection is from: https://stage.xp.audience.io
[iframe-resizer][Parent page: iFrameResizer0] IFrame (iFrameResizer0) height set to 1426px
[iframe-resizer][Parent page: iFrameResizer0] sameDomain: false
[iframe-resizer][Parent page: iFrameResizer0] Version mismatch (Child: 5.2.4-beta.4 !== Parent: 5.2.5-beta.1)
[iframe-resizer][iFrameResizer0] Trigger event lock off
[iframe-resizer][iFrameResizer0] --
[iframe-resizer][iFrameResizer0] Trigger event: Resize Observed: BODY
[iframe-resizer][iFrameResizer0] Page is hidden: HTML: 0  Page: 1426
[iframe-resizer][iFrameResizer0] Sending message to host page (iFrameResizer0:0:0:mouseenter:-1374:3136) via postMessage
[iframe-resizer][Parent page: iFrameResizer0] Received: [iFrameSizer]iFrameResizer0:0:0:mouseenter:-1374:3136
[iframe-resizer][Parent page: iFrameResizer0] Checking connection is from: https://stage.xp.audience.io
[iframe-resizer][iFrameResizer0] Tagged elements found: false
[iframe-resizer][iFrameResizer0] Attached resizeObserver: DIV.ui text loader
[iframe-resizer][iFrameResizer0] Trigger event: Resize Observed: DIV.ui text loader
[iframe-resizer][iFrameResizer0] Page is hidden: HTML: 0  Page: 1426
[iframe-resizer][iFrameResizer0] overflowedElements: 3
[iframe-resizer][iFrameResizer0] Trigger event: Resize Observed: DIV.ui text loader
[iframe-resizer][iFrameResizer0] Page is hidden: HTML: 0  Page: 1426
62Third-party cookie will be blocked in future Chrome versions as part of Privacy Sandbox.
[iframe-resizer][iFrameResizer0] Tagged elements found: false
[iframe-resizer][iFrameResizer0] Attached resizeObserver: DIV.grecaptcha-badge
[iframe-resizer][iFrameResizer0] Trigger event: Resize Observed: DIV.grecaptcha-badge
[iframe-resizer][iFrameResizer0] Page is hidden: HTML: 0  Page: 1426
[iframe-resizer][iFrameResizer0] overflowedElements: 6
[iframe-resizer][iFrameResizer0] Tagged elements found: false
[iframe-resizer][iFrameResizer0] overflowedElements: 7
[iframe-resizer][iFrameResizer0] Sending message to host page (iFrameResizer0:0:0:mouseenter:-1270:3400) via postMessage
[iframe-resizer][iFrameResizer0] Tagged elements found: true
[iframe-resizer][iFrameResizer0] Attached resizeObserver: DIV.sc-eGPXGI dCpkka
[iframe-resizer][iFrameResizer0] Attached resizeObserver: DIV.ui fluid left icon input sc-hmjpVf sc-eLwHnm iRhDdN
[iframe-resizer][iFrameResizer0] Attached resizeObserver: I.mail icon
[iframe-resizer][iFrameResizer0] Attached resizeObserver: DIV.ui fluid left icon input sc-hmjpVf sc-eLwHnm iRhDdN
[iframe-resizer][iFrameResizer0] Attached resizeObserver: I.key icon
[iframe-resizer][Parent page: iFrameResizer0] Received: [iFrameSizer]iFrameResizer0:0:0:mouseenter:-1270:3400
[iframe-resizer][Parent page: iFrameResizer0] Checking connection is from: https://stage.xp.audience.io
[iframe-resizer][iFrameResizer0] Trigger event lock on
[iframe-resizer][iFrameResizer0] Sending message to host page (iFrameResizer0:1027:907:init:5.2.4-beta.4) via postMessage
[iframe-resizer][iFrameResizer0] Add event listener: After Print
[iframe-resizer][iFrameResizer0] Add event listener: Before Print
[iframe-resizer][iFrameResizer0] Add event listener: Ready State Change
[iframe-resizer][iFrameResizer0] Create <body/> MutationObserver
[iframe-resizer][iFrameResizer0] Initialization complete
[iframe-resizer][iFrameResizer0] ---
[iframe-resizer][iFrameResizer0] Trigger event: Resize Observed: BODY
[iframe-resizer][Parent page: iFrameResizer0] Received: [iFrameSizer]iFrameResizer0:1027:907:init:5.2.4-beta.4
[iframe-resizer][Parent page: iFrameResizer0] Checking connection is from: https://stage.xp.audience.io
[iframe-resizer][Parent page: iFrameResizer0] IFrame (iFrameResizer0) height set to 1027px
[iframe-resizer][Parent page: iFrameResizer0] sameDomain: false
[iframe-resizer][Parent page: iFrameResizer0] Version mismatch (Child: 5.2.4-beta.4 !== Parent: 5.2.5-beta.1)
[iframe-resizer][iFrameResizer0] Trigger event lock off
[iframe-resizer][iFrameResizer0] --
[iframe-resizer][iFrameResizer0] Sending message to host page (iFrameResizer0:0:0:mouseleave:-1453:3406) via postMessage
[iframe-resizer][Parent page: iFrameResizer0] Received: [iFrameSizer]iFrameResizer0:0:0:mouseleave:-1453:3406
[iframe-resizer][Parent page: iFrameResizer0] Checking connection is from: https://stage.xp.audience.io
[iframe-resizer][iFrameResizer0] Sending message to host page (iFrameResizer0:0:0:mouseenter:-1082:3418) via postMessage
[iframe-resizer][Parent page: iFrameResizer0] Received: [iFrameSizer]iFrameResizer0:0:0:mouseenter:-1082:3418
[iframe-resizer][Parent page: iFrameResizer0] Checking connection is from: https://stage.xp.audience.io
[iframe-resizer][iFrameResizer0] Sending message to host page (iFrameResizer0:0:0:mouseleave:-1384:2904) via postMessage
[iframe-resizer][Parent page: iFrameResizer0] Received: [iFrameSizer]iFrameResizer0:0:0:mouseleave:-1384:2904
[iframe-resizer][Parent page: iFrameResizer0] Checking connection is from: https://stage.xp.audience.io

@Gamerweazel
Copy link
Author

@davidjbradshaw You can cycle back and forth using the "Forgot Password" button. Going back and forth causes the slowdown.

@davidjbradshaw
Copy link
Owner

Found another bug and have just published v5.2.5-beta.2 with a fix. Can you please let me know if this works for you.

@Gamerweazel
Copy link
Author

Found another bug and have just published v5.2.5-beta.2 with a fix. Can you please let me know if this works for you.

@davidjbradshaw I bumped the version on the pen and child frame to v5.2.5-beta.2 and the stacking problem appears to persist. I have tried commenting out my react-css-transition-replace and it seems to still be stacking.

@davidjbradshaw
Copy link
Owner

My bad, can you please try Beta.3. I published from the branch and forgot to fold in the latest update from Master.

@Gamerweazel
Copy link
Author

My bad, can you please try Beta.3. I published from the branch and forgot to fold in the latest update from Master.

@davidjbradshaw It seems like the stacking issue is still present after bumping to latest beta. I updated the pen and the child frame to v5.2.5-beta.3

@davidjbradshaw
Copy link
Owner

OK bugger, looking at the logs a bit more, and tracking things back, I'm wondering if the following function is the issue.

https://github.com/davidjbradshaw/iframe-resizer/blob/master/packages/common/utils.js#L3-L11

Think I need to sleep on this some more, I can pick this up again on Thursday. Hopefully this two bugs down and only one more to go.

@Gamerweazel
Copy link
Author

OK bugger, looking at the logs a bit more, and tracking things back, I'm wondering if the following function is the issue.

https://github.com/davidjbradshaw/iframe-resizer/blob/master/packages/common/utils.js#L3-L11

Think I need to sleep on this some more, I can pick this up again on Thursday. Hopefully this two bugs down and only one more to go.

@davidjbradshaw Are there local development instructions we can follow and see if we can encounter a solution and post back about it here?

@davidjbradshaw
Copy link
Owner

If you fork and download the repo, the build process is simple enough.

npm run build:dev

You can also do

npm run test:all

If you go into the /example/html folder you can update the index.html file to point to your iframe.

The dev built versions of the child script will be in the /js folder.

To run the examples, your best option is to run a http server in the project route. I use 'http-server'

The npm modules can be created with npm run build:prod but these will have the logging disabled by default. So it will be easier to just use the parent page in the example folder.

@davidjbradshaw
Copy link
Owner

davidjbradshaw commented Aug 20, 2024

What I think is happening, is that when the page updates, it triggers a MutaionObserver, which then looks for page element that are positioned to be outside the document flow and then adds resizeObsevers to them.

When this happens it is triggering the second part of the init script, that by default has to wait for this to happen during page setup.

That call is wrapped with a once() function, so it should not be getting called, but for some reason is.

I'm afraid the call stack is going to bounce through a number of events, so might not be that easy to follow.

The file to look at is child/overflow.js and child/index.js. The main file is 11 years old and showing its age somewhat. Still in the process of modernisation and breaking it up into smaller bits. But it requires a fair bit of untangling to do that.

@Gamerweazel
Copy link
Author

What I think is happening, is that when the page updates, it triggers a MutaionObserver, which then looks for page element that are positioned to be outside the document flow and then adds resizeObsevers to them.

When this happens it is triggering the second part of the init script, that by default has to wait for this to happen during page setup.

That call is wrapped with a once() function, so it should not be getting called, but for some reason is.

I'm afraid the call stack is going to bounce through a number of events, so might not be that easy to follow.

The file to look at is child/overflow.js and child/index.js. The main file is 11 years old and showing its age somewhat. Still in the process of modernisation and breaking it up into smaller bits. But it requires a fair bit of untangling to do that.

@davidjbradshaw This commit here seemed to fix our issue: https://github.com/davidjbradshaw/iframe-resizer/compare/master...aptivada:iframe-resizer:master?diff=unified&w=#

I did notice another instance of initContinue on https://github.com/aptivada/iframe-resizer/blob/374b78f491daead14c82789ba8008d40e6c39e3f/packages/child/index.js#L180 and it appears THAT was the one getting saturated with calls, but I'm unsure if it's because our application setup that we are exposing an issue or we are somehow not subject to needing this called multiple times.

@davidjbradshaw
Copy link
Owner

Your fix makes sense to me, although I’m not exactly sure why moving the once() causes it to start working.

Would you like to submit this as a PR and I will test it out in the morning.

@Gamerweazel
Copy link
Author

Your fix makes sense to me, although I’m not exactly sure why moving the once() causes it to start working.

Would you like to submit this as a PR and I will test it out in the morning.

@davidjbradshaw Done #1314. It's because it's called from more places than what was wrapped in once. I provided the other calling location in my previous comment.

@davidjbradshaw
Copy link
Owner

davidjbradshaw commented Aug 22, 2024

@Gamerweazel Beta.4 hopefully now address both your issues. Neither of which I've been able to create a simple repro of or automatic test. I have, however, in the last week had a separate report of each of your two issues from different people.

In the process of trying to create simple examples of each bug, I have found and fixed another two issues!

I've not directly used your PR, but it did give the direction of the fix, the onChange event is now much simpler, and just calls for the content size to be rechecked, rather than the once(inti) call.

Anyway if this all works for you. I will release it as the final version.

Thanks for all the help on this one.

@Gamerweazel
Copy link
Author

@Gamerweazel Beta.4 hopefully now address both your issues. Neither of which I've been able to create a simple repro of or automatic test. I have, however, in the last week had a separate report of each of your two issues from different people.

In the process of trying to create simple examples of each bug, I have found and fixed another two issues!

I've not directly used your PR, but it did give the direction of the fix, the onChange event is now much simpler, and just calls for the content size to be rechecked, rather than the once(inti) call.

Anyway if this all works for you. I will release it as the final version.

Thanks for all the help on this one.

@davidjbradshaw No problem! I have updated my pen and can confirm that 5.2.5-beta.4 fixes the issue!

@davidjbradshaw
Copy link
Owner

Release v5.2.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants