How to fix my error: Show and set rules and queries only work with element functions

Hi,
in one of my main.typ files I use the following:

// Configure page properties.
#set page(
numbering: “1”,

// The header always contains the book title on odd pages and
// the chapter title on even pages, unless the page is one
// that starts a chapter (the chapter title is obvious then).
header: locate(loc => {
  // Are we on an odd page?
  let i = counter(page).at(loc).first()
  if calc.odd(i) {
    return text(0.95em, smallcaps(title))
  }

  // Are we on a page that starts a chapter? (We also check
  // the previous page because some headings contain pagebreaks.)
  let all = query(heading, loc)
  if all.any(it => it.location().page() in (i - 1, i)) {
    return
  }

  // Find the heading of the section we are currently in.
  let before = query(selector(heading).before(loc), loc)
  if before != () {
    align(right, text(0.95em, smallcaps(before.last().body)))
  }
}),

)

Hallo Welt

Today the TYPST compiler shows the following error message:

Can anybody show/explain me how to fix this error to re-enable preview?

Could you provide more background for your code? Specifically, what do you want to implement? Did you write the code yourself or copy it from somewhere?

About the error message you encountered:
In the old versions of Typst, the locate function accepts a loc => {…} unnamed function; however, that syntax has been replaced with context locate(selector) for a while. In the new syntax, the selector is usually an element function. That’s what the error is complaining about.

(By the way, you can stay with the old version by adjusting the settings in the left toolbar on typst.app.)