(Bug?) content.type is still "display" in preview mode

It’s impossible to get the body of a macro in preview mode, so we need to at least show a placeholder. According to the dynamicContentMacro docs, the content type should be preview when in preview mode.

output.type : The output type, e.g. display or preview

But that’s just not the case. Even in preview mode it’s still ‘display’. This is very frustrating because users think it’s a bug with our app when it really isn’t.

Hi @PhilipFeldmann ,

I’ve written a little test app that has a dynamic content macro and displays the value of {output.type}. When the page is in edit mode, the macro indicates {output.type} is preview.

Perhaps you can install the app, https://dx-custom-macro-editor-app.glitch.me/connect.json, to see if you observe the same results. The code for the app can be seen here.

Regards,
Dugald

Thanks @dmorrow for making this example. The result is the same. It displays “preview” in edit mode, but this is not my concern for macros with a body, because those don’t have a live preview. I am talking about the actual preview mode of the page (ctrl shift e).

It’s impossible to fetch the content of a macro with a body in preview mode. According to the docs, it should be possible to work around this with outputType, but the outputType is just incorrect for this case and it’s impossible to show a proper preview to users.

Hi @PhilipFeldmann ,

My understanding is that the intention of the Confluence page preview feature is to provide users with a visualisation of the page prior to publishing it. For this reason, it makes sense to me that the macro would be in display mode when the page is in preview mode.

Regards,
Dugald

Hi @dmorrow

My understanding is that the intention of the Confluence page preview feature is to provide users with a visualization of the page prior to publishing it.

Yes, exactly, I agree! Users want to see an accurate preview before publishing. This is not possible at the moment. Please have a look at the url parameter section of the dynamicContentMacro page..
About halfway in the paragraph it states:

Preview Mode: If you use the {macro.id} in your URL, the REST api will not return the macro body during a preview request, because the page has not been saved yet. You can use the {output.type} parameter to detect whether the macro is rendered in preview mode and adapt the response accordingly.

In order to receive the body of a macro, the rest API needs to be called like this:

"/rest/api/content/" + pageId +"/history/" + pageVersion +"/macro/id/" + macroId,

Please note that there’s a macroId at the end, which is absolutely required to fetch the body from the Confluence API. Before the page is saved, there either is no macroId OR the macroId is stale and belongs to an old version of the macro (if it has been updated). In either scenario, the API responds with an error.

For our macro there is no way to determine whether it’s currently in preview mode or not, because Confluence tells it that there the current mode is “display”. The provided macro- and pageIds however lead to an error in this mode when being sent to the API. And we can not know if this is due to it being in preview mode or something else is going wrong, because Confluence does not give us any hints about this, thus we have to display an error to the user, which is VERY confusing to them, and I can’t blame them.

The documentation of dynamicContentMacro is even aware of this! Again, I want to quote it:

If you use the {macro.id} in your URL, the REST api will not return the macro body during a preview request, because the page has not been saved yet. You can use the {output.type} parameter to detect whether the macro is rendered in preview mode and adapt the response accordingly.

It clearly says that we can use the output.type to work around this case, but this is just inaccurate information. This is becoming increasingly frustrating because we get more and more requests from users who do not understand this error.

Hi @PhilipFeldmann ,

In the context of the Dynamic Content Macro documentation, I think preview mode corresponds to the page being in edit mode and the macro not in edit mode (whether the page is in preview mode is irrelevant).

When the page is in preview mode (and therefore the macro is in display mode), can you try calling AP.confluence.getMacroBody() to get the body.

Regards,
Dugald

@dmorrow Thanks, this seems to work! Is this new? I remember getMacroBody to be only available in the editor itself :thinking: