question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

resizedCallback is called too early

See original GitHub issue

Hi, for some reason my iFrame is resized 2 times during the page load and second time it is resized with message different from init and in the code I can see that in this case resizing happens inside requestAnimationFrame(say I use Chrome) which is basically async. But the callback is called synchronously.

...
default:
	resizeIFrame();
	callback('resizedCallback',messageData);
}

function resizeIFrame(){
	function resize(){
		setSize(messageData);
		setPagePosition(iframeId);
	}

	ensureInRange('Height');
	ensureInRange('Width');

	syncResize(resize,messageData,'init');
}

function syncResize(func,messageData,doNotSync){
	/* istanbul ignore if */  //Not testable in PhantomJS
	if(doNotSync!==messageData.type && requestAnimationFrame){
		log(messageData.id,'Requesting animation frame');
		requestAnimationFrame(func);
	} else {
		func();
	}
}

Finally I wrap my callback function into requestAnimationFrame which works as expected but that should be mentioned in docs if not changes in the source code. I would like to help with the fix but have no idea why you put requestAnimationFrame here. Thanks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
codenercommented, Mar 29, 2017

I am experiencing the same issue as @dshiryaev-plesk. I believe the resized callback should only be called once the resize is done:

function resizeIFrame(){
	function resize(){
		setSize(messageData);
		setPagePosition(iframeId);
		callback('resizedCallback',messageData);
	}
...

Calling back inside the resizeIFrame function even looks a bit cleaner to me.

Would you accept this change?

1reaction
dana321commented, Feb 19, 2017

I had the same issue with iframeresizer where the page loaded too quickly and triggered the javascript before it was ready after switching to a cdn for faster loading times.

The fix was to wrap the call on the onload with the javascript setTimeout function to delay loading by one second (setTimeout(iframeresizer({}),1000); (add the params you need)… You can also set the width and height using the style tag to set the width/height larger than the space you need then it should show correctly after a second… i don’t notice the difference.

Read more comments on GitHub >

github_iconTop Results From Across the Web

3026 (resizable resize handler is called too early) - jQuery UI
The resizable resize callback is called before the element is resized, and before the position and size properties (which are passed as ui.position...
Read more >
How to wait for the 'end' of 'resize' event and only then perform ...
When a user resizes a window manually (by dragging it) the resize event will be called more than once, so using .one() really...
Read more >
ResizeObserver: it's like document.onresize for elements
ResizeObserver notifies you when an element's content rectangle changes size so that you can react accordingly.
Read more >
How To Use the Resize Observer JavaScript API - DigitalOcean
In this post we'll see how we can use the new ResizeObserver API to react to an element's size changing.
Read more >
Window: resize event - Web APIs | MDN
onresize to control the time after which the event fires. Syntax. Use the event name in methods like addEventListener() , or set an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found