Iframe-resizer: debouce function 'eats' events

Created on 14 Sep 2016  Â·  5Comments  Â·  Source: davidjbradshaw/iframe-resizer

First of all; thanks for this great toolkit/component!
Just recently however I found out there seems to be a pretty big issue/bug at the very core.
The implementation of the debounce system bases himself on one single 'timer', if a timer is already running the next debounce call is just ending in doing nothing at all. So the first call is executed after X waittime, and all the next calls are just thrown away. In a typical 'debounce' you would expect the reverse; only the last one should be fired. But that's not the biggest problem...
Once you have 2 and the same events being triggered for multiple purposes the current implementation of 'debounce' will throw away one of the 2 since there is only one timer variable.

Example on how I noticed this behavior and how to simulate it:
Just use the parentIFrame.getPageInfo callback system from without iframe content. That results in 2 'resize' listeners on window on the main page. Now resize your main page; you'll most likely not going to get any 'pageInfo' in the iframe as the 'debounce' method on the main page just threw away that message as there was already a timer running.

Hope my explanation is clear enough.

I think the easiest solution (without too many refactoring) is introduce a 3rd parameter to the current existing debounce method. 3rd parameter should be an ID towards a timer. The timer variable itself should then be an object with a timer per ID and access/test on it by doing timer[ID]. => using this workaround/solution as for now in my local copy of iframeResizer.js and that's looking good

Another possibility is to replace the rebounce method as a whole by for example https://davidwalsh.name/javascript-debounce-function, but that requires quite some refactoring as the result of the that new debounce is a function on itself which should be passed to the listeners.

bug

Most helpful comment

Thanks for agreeing on a 'bug' and sorry to bother you again...

Problem can indeed be 'fixed' by removing the rebounce on getPageInfo... But that seems more like an ugly workaround to me, because I believe the rebounce is useful for the getPageInfo callback system. Without it it will fire a lot of events and post message api calls during resizing of the main page/window for nothing. I guess that is also the reason why it is there in the current version.

The only future proof fix imo is to fix the 'rebouce' function/system 'once and for all' (and not limit the use of it).

Greetz

All 5 comments

Hmm the debounce was added long before getPageInfo, so only cared about the frame being resized. Agree getPageInfo should not run through debounce.

Thanks for agreeing on a 'bug' and sorry to bother you again...

Problem can indeed be 'fixed' by removing the rebounce on getPageInfo... But that seems more like an ugly workaround to me, because I believe the rebounce is useful for the getPageInfo callback system. Without it it will fire a lot of events and post message api calls during resizing of the main page/window for nothing. I guess that is also the reason why it is there in the current version.

The only future proof fix imo is to fix the 'rebouce' function/system 'once and for all' (and not limit the use of it).

Greetz

Any updates?

getPageInfo()'s callback not firing when window resized

I'd welcome a PR if anyone wants to fix this.

On Wed, Jul 26, 2017 at 9:33 AM, Jun-ho, Song notifications@github.com
wrote:

Any updates?

getPageInfo()'s callback not firing when window resized

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/davidjbradshaw/iframe-resizer/issues/405#issuecomment-317973276,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAkHEkcDmIc4cReS9wUDQKCvlEOP8lxrks5sRuvYgaJpZM4J8gHH
.

--
David J. Bradshaw )'( [email protected]

Fixed in v3.6.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thomasbilk picture thomasbilk  Â·  4Comments

dfelix86 picture dfelix86  Â·  4Comments

Warox23 picture Warox23  Â·  6Comments

Testato picture Testato  Â·  6Comments

premedios picture premedios  Â·  5Comments