I am creating a simple Figma plugin. I am trying to show a loader when I click a button to hide the current div and show next div, sort of a new page.
When I add the basic JavaScript statement to show a loader, it is sometimes loading with a delay. It is sometimes showing only just before the transition happens. But sometimes it shows immediately when I click on the button.
Here is my code.
document.getElementById(‘buttonCalculate’).onclick = () => {
document.getElementById(‘figsuLoader’).style.display = “block”;
parent.postMessage({ pluginMessage: { type: ‘calculate-weight’} }, ‘*’);
onmessage = (event) => {
if (event.data.pluginMessage.type !== ‘error’) {
document.getElementById(‘figsuLoader’).style.display = “none”;
}
}
}
I am not sure if its because of the delay due to content loaded in iFrame. I debugged this in depth. But I am not able to get a resolution for this. Please help me here.