Atlassian Connect modules have three resizing modes, which are configured through the data-options
attribute on the all.js
script tag (or any element with the ID ac-iframe-options
):
- The default is to automatically resize the iframe to the size of its
<div class="ac-content">
element. - Specifying
resize:false
will disable any automatic resizing, the iframe will have no dimensions set by default. It can be resized manually usingAP.resize()
orAP.sizeToParent()
- Specifying
sizeToParent:true
will give the iframe 100% width and a height in pixels that matches the whole available space. A resize listener is enabled that will update the height when the browser window is resized.
The sizeToParent:true
option does not always work. On some systems it always works, but on some systems the iframe stays without any assigned dimensions at least on every other page load. This causes confusion for users, since parts of the content are not visible. The problem has been around for many years and impacts the usability of several of our apps. It has also been reported here:
- generalPage doesn't get proper height in Chrome
- Height issue with Safari and Atlassian-connect script
-
Add-on iframe (auto)resize problems
Resizing frame for general page module - and possibly others.
After debugging this for several hours, I believe I have found an explanation and a workaround. The whole AP module, including its resizing behaviour, is controlled by a complex and confusing interaction between atlassian-connect-js and simple-xdm. The communication between the iframe and the host product is done using message events. When all.js
loads, simple-xdm sends an init
message to the host product. Then, in the same tick, atlassian-connect-js sends a sizeToParent
message to the host product.
My suspicion is that in some scenarios, the two messages arrive in the opposite order, because the order in which messages are received is not guaranteed. As an experiment, I switched the two messages around. Sending the init
message before the resizeToParent
message (like the code currently does) almost always succeeded to resize the iframe, but sending the resizeToParent
message before the init
message almost never succeeded to resize the iframe.
As a workaround, I am waiting for the response of the init
message before enabling sizeToParent
:
<script src="https://connect-cdn.atl-paas.net/all.js" defer data-options="resize:false"></script>
<script>
window.addEventListener('message', (e) => {
if (window.AP && e.data?.type === 'init_received' && e.origin === AP._data.origin && e.source === AP._host) {
AP.sizeToParent();
}
});
</script>
We have been using this workaround for a while now and it seems to reliably solve the problem.
I believe that Atlassian should change the code so that atlassian-connect-js either waits for the init_received
message before calling sizeToParent()
, or change the mechanism so that sizeToParent()
works even if no init
message has arrived.