Issue in importing XML

Hi,
We are importing XML from our API on a button click, but our state is not updating and displaying previous XML.
How can we resolve this issue.
Below is the portion of code:
Here,
XML is a state variable,which we are getting from our API,calling on a button click and
path is the pdf URL,which too getting from API call.
Issue is, when we are switching from file1 to file2,we are setting our XML state variable to null,but still XMLof file1 are importing to file2,but our XML value on consoling is displaying NULL.

useEffect(() => {
if (xml) {
if (typeof window !== "undefined") {
if (inst.current) {
if (path) inst.current.loadDocument (path);
inst.current.Core.documentViewer.addEventListener("document Loaded", async () => {
if (xml) {
inst.current.Core.annotationManager.importAnnotations (xml);
}
inst.current.UI.openElements(["notesPanel"]);
}
} else {
if (typeof window !== "undefined") {
if (inst.current)
if (path) inst.current.loadDocument(path);
}
[path, xml]);

Below is our UI:
THis is file1,where annotations(XML)should load.


Below is file2,where annotations(XML) should not load.

Hi there,

Thanks for reaching out to pdf.js express forums,

Could you please share a minimal runnable sample project to reproduce this issue?

Just looking at the code snippet, it looks like there shouldn’t be a space between the ‘document Loaded’ event. The if statements are a bit confusing to see what is going on.

We do have a react sample for your reference: GitHub - pdfjs-express/pdfjs-express-react-sample

Best regards,
Kevin Kim