Simple refresh in Confluence editor breaks Connect iframes ("ac/context missing ac/content-resolver")

Hi there,

Working on a macro as part of Codegeist, we noticed that sometimes AP.context wasn’t available in our Connect Iframes. As a result, whenever this happens, our macro, macro editor, or any other Connect Iframes on that pages were completely broken.

Reproducing the error is as simple as this:

  • Going to a Confluence page.
  • Opening the editor.
  • Letting everything load, mouving your mouse, maybing typing something…
  • Refreshing the page

In the console you will find an error message ac/context missing ac/content-resolver and from this point on, Connect iframes are basically broken. You can watch me do it here: https://drive.google.com/file/d/1yLL-fDeMt8zH8JTQj1nzaZzAw6aoM2sI/view

We’ve been able to reproduce this on several different Cloud instances, using different computers and browsers. Sometimes the ac/context missing ac/content-resolver error even appeared out of the blue without explicitly reloading.

Help? :frowning:

Cheers,
Sven

3 Likes

I just confirmed this. I don’t think it’s affecting our macros only because we aren’t using AP.context. But it seems like a significant bug in the big picture.

2 Likes

Thanks for raising this @sven.schatter and going to the trouble of creating a really clear demo. ac/context is the module that implements the AC.context API which is injected into the iframe. It depends on the ac/content-resolver module to fetch context information from the server. I don’t know why the ac/content-resolver module isn’t available, but I notice that it is only defined after the global object connectHost has been defined. I’ll chase it up on Monday morning.
Regards,
Dugald

2 Likes

This has been hitting my users for weeks now. I added a wait function that stopped execution until !!AP.context. That reduced the error count, but now users get AP.context.getToken === undefined instead.

3 Likes

Hi @jason,
When I follow @sven.schatter’s procedure, AP.context is undefined indefinitely.
Regards,
Dugald

1 Like

Hm. AJS.toInit should ensure that AP is fully loaded, right? Then it looks like I’m hitting a different bug.

As far as I’m aware AJS (AUI) has nothing to do with AP (Cloud API / All.js) but I might be wrong. :sweat_smile:

1 Like

Well, you’re right, but the point stands that (AFAIK) AP should be fully loaded at that point, since AJS.toInit is a wrapper for $(document).ready. But in fact AP components seem to get loaded asynchronously and thus are frequently missing when needed.

1 Like

@dmorrow @sven.schatter
Possibly related issue: Getting ReferenceError AP is not defined - #23 by BobBergman
This is tracked at [CONFCLOUD-69391] Using Connect Apps in the new editor sometimes causes: ReferenceError: _AP is not defined - Create and track feature requests for Atlassian products.

1 Like

Yeah, there’s no formal relationship between AJS and AP. AJS is the JavaScript library that supplements AUI which is the pre-cursor to AtlasKit. The API provided by the AP object is detailed in the JavaScript API section of the documentation and is referred to as Atlassian Connect JavaScript (ACJS). Some of ACJS is open source and you can see it depends on AJS to perform certain UI actions such as creating flags and dialogs. ACJS has been updated to allow for an AtlasKit implementation of the various UI interactions, but this requires adoption by Jira and Confluence which is still pending.

1 Like

@dmorrow Do you have any idea how can we ensure that AP.context is properly loaded?

Yes, AP is defined by all.js, the debug version of which is located at https://connect-cdn.atl-paas.net/all-debug.js. App iframes must load this directly so that the API can be injected from the host.

1 Like

The API is defined on the host side and injected into the app iframe using the simple-xdm library.

1 Like

For those of you sweating on this issue, a fix has been proposed and now needs to be reviewed. With any luck, it may be available early to mid next week.

Regards,
Dugald

3 Likes

Awesome @dmorrow! Thanks for keeping us in the loop and escalating this so quickly! :heart:

1 Like

Fix has been rolled out

2 Likes