Confluence Forge macro export behavior / context.localId in Word export

Hi all,

I’m currently trying to implement an export handler for a confluence macro, but got some problems.
I finally managed to get my handler called and to successfully return a string like “hello world”, which appears in the document.

I’m now trying to load an image from storage. I think, I need to use an effect to do that.

const App = () => {
  const context = useProductContext();
  const [image, setImage] = useState(null);

  const loadSVG = async (id) => {
    let result = null;
    try {
      result = await storage.get(`svg-${id}`);
    } catch (err) {
      console.log(err);
    } finally {
      return result;
    }
  }


  useEffect(() => {
    const load = async () => {
      const image = await loadSVG(context.localId);
      setImage(image);
    }
    load();
  }, []);

  return (
    <Fragment>
      {image 
        ? <Image src={"data:image/svg+xml," + image} alt={"An image"}/> 
        : <Text>Loading...</Text>}       
    </Fragment>
  );
};

my Problem is now, that the Export function seems to only get called once. So there is no way to wait for the execution of the effect and therefore the result of the storage call, right?

In my exports, the result is always “Loading…”

How do you achieve loading data for an export then?

Thank you for your responses :slight_smile:
Chris

So, i got the loading part to work now.

My export now works in PDF yay

I got a new issue though:
As you can see in my code, I use the context’s localId in my storage key to get the saved image.

I experienced a strange behavior now:
If you display the plugin normally on the page AND if you export as PDF, this ID is identical.

But: If you use the Word Export, the id is different.
Is this intentional?
It looks like a bug from my perspective…

Best regards,

Chris