Using `flex-caption` and `placement: auto` can lead to incorrect page numbers in outline of figures

In my project, I have used the forum-suggested flex-caption method for getting a different caption in the outline (of figures) and in the main body. I have also set the placement: auto argument of a figure. The issue is that this combination seems to induce incorrect page numbering in a figure outline.

I was able to reproduce this in the web app (0.14.2), per the example below. In this example, the outline lists the figure on page 2, when the figure is actually on page 3. The link to the figure also scrolls to page 2.

#let in-outline = state("in-outline", false)
  
#let flex-caption(
  short: none, 
  long: none
) = context if state("in-outline", false).get() {
  short
  } else { 
    long 
  }

#show outline: it => {
    in-outline.update(true)
    it
    in-outline.update(false)
  }


#let test-img = {
  image(
  bytes(range(16).map(x => x * 16)),
  format: (
    encoding: "luma8",
    width: 4,
    height: 4,
  ),
  width: 90%,
)
}

#outline(target: figure)

#set page(numbering: "1")

#lorem(360)

#lorem(120)


#figure(test-img, placement: auto, caption: flex-caption(short: lorem(8), long: lorem(60)))

#lorem(120)

#lorem(180)

Without manually moving the figure or adding page breaks, is there a way to fix this? Should it be considered a bug? Cheers.

If I remove the flex-caption from your example, the problem is still there. I think you are running into this bug: References to floating figures point to wrong location · Issue #4359 · typst/typst · GitHub (The issue says references, but the outline bug #5537 points to the same issue)