The following steps reproduce an issue which impacts Confluence user experience and prohibits implementing key functionality when developing macros. The bug produces old, stale macros which are momentarily rendered when they should not be.
- Create a basic connect app which includes the following Dynamic Content Macro. This test macro includes a parameter to more closely recreate what would happen with an actual production app macro.
{
"key": "bananamacro",
"name": {
"value": "Banana"
},
"url": "/macro/banana.html",
"description": {
"value": "Yellow banana"
},
"outputType": "block",
"bodyType": "none",
"parameters": [
{
"identifier": "param1",
"name": {
"value": "Test Parameter"
},
"description": {
"value": "A test parameter"
},
"type": "string",
"required": true
}
]
},
- Use the following for banana.html, which includes a crude but simple script to render based on the parameter data:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Cache-control" content="no-cache,no-store">
<title>Banana</title>
<script src="https://connect-cdn.atl-paas.net/all.js" type="text/javascript"></script>
<script>
let macroDataPromise = new Promise((resolve) => {
window.AP.confluence.getMacroData(function (macroData) {
resolve(macroData)
})
})
macroDataPromise.then((macroData) => {
document.getElementById('banana-container').innerHTML = macroData.param1
})
</script>
</head>
<body>
<p id="banana-container" class="inline-paragraph">
Loading...
</p>
</body>
</html>
- Insert the macro into a Confluence page, with some test text in the parameter input field
- Save the macro (let’s call this ‘macro state A’)
- Observe the rendered content, which is based on the parameter value
- Publish the page
- Edit the page
- Edit the macro and change the parameter to a different text value
- Save the macro (let’s call this ‘macro state B’) and publish the page
- Edit the page and observe what is rendered
Expected result
The macro is rendered with macro state B
Actual result
The macro is rendered with ‘macro state A’ briefly, before being replace with ‘macro state B’
When the macro is rendered with ‘macro state A’, the entire macro code is run with the old, obsolete context. If we consider this behaviour occurring in a production application’s macro, then depending on what your macro does exactly, I believe this could result in anything from an annoying visual bug to potentially a legitimate security concern.
The entire macro code is run when this ‘phantom macro’ is rendered, using the old context, meaning erroneous side effects (sentry calls, analytic collections, Confluence AP Events) are produced. Since AP Events are produced, this severely impacts the usefulness of that feature - it’s difficult or impossible to code around this as your code does not expect these events.