loadFontAsync always get stuck

I want to load some fonts programatically I get the font form the selected text layer and apply it in another text layer and do some changes

const fontLoadingFunction = async (node: TextNode) => {
  await Promise.all(
    node.getRangeAllFontNames(0, node.characters.length)
      .map(figma.loadFontAsync)
  )
  console.log("Awaiting the fonts.")
}

and this is the call function

  // Load fonts
  await fontLoadingFunction(textNode);

after this function I do some changes to node

the code works very well when I try it in the console.
but when I try it in the plugin it doesn’t work and give me this warning
there are still font loads in progress. Please ensure closePlugin is not called until after the font loading has resolved.