How to achieve conditional visibility of content based on it's location on the page (e.g. if it's at the top of the page)?

Let’s say I have the following content function that I call multiple times in my multi-page document:

#let myText = [
  #v(1em) \
  #lorem(5)
]

I would like for the space function #v(1em) to not be visible whenever #myText occurs at the top of a page right after a page break, for consistent margins. I thought I could use #context with #if here().position().y != page.margin.top.length as a conditional for visibility of the space:

#let myText = context[
  #if here().position().y != page.margin.top.length [ 
    #v(1em)
  ]
  #lorem(5)
]

However, here().position().y and page.margin.top.length do not match:

#set page(
  width: 2in,
  height: 2in,
  margin: (x: 0.4in, top: 0.4in, bottom: 0.6in),
)

#context here().position().y \
#context page.margin.top.length

It seems like here().position().y is based on the baseline of the text content. When I set a larger text size for the document, the position value changes. Is there a way to refer to the top left corner of the “bounding box” instead of the baseline position?

Or is there another way of conditionally hiding content if it occurs at the start of a page?

Using the weak parameter of h()v() might be enough for your requirements:

If true, the spacing collapses at the start or end of a paragraph. Moreover, from multiple adjacent weak spacings all but the largest one collapse.

Edit: I need to remember that h means horizontal, not height.

Unfortunately that doesn’t seem to work. Even if I put v(1em, weak: true) at the start and end of the definition of myText, there are no gaps between consecutive calls of myText.

Basically, when I have the following layout:

= Some example sections (each section is a `myText`):
#myText()[custom body argument]
#myText()[custom body argument2]
#pagebreak
#myText()[custom body argument3]
#myText()[custom body argument4]

I would like equal gaps between header and myText and between each instance of myText. But if a myText occurs at the start of a page, I don’t want any spacing between the page margin and the block. v() or h() with weak: true doesn’t seem to do the trick.

As I am understanding it, this satisfies both

equal gaps between header and myText and between each instance of myText

and

if a myText occurs at the start of a page, I don’t want any spacing between the page margin and the block

//Set up page and make the header & footer visible
#set rect(width: 100%, height: 100%)
#set page(
  height: 5cm,
  header: rect(),
  footer: rect()
)

#let myText(content) = {
  v(3em, weak: true)
  content
}

= Some example sections:
#myText()[custom body argument]
#myText()[custom body argument2]
#pagebreak()
#myText()[custom body argument3 (after `pagebreak()`)]
#myText()[custom body argument4]
#myText()[custom body argument5]
#myText()[custom body argument6 (after autmatic page break)]
#myText()[custom body argument7]
#myText()[custom body argument8]
Result

Maybe your actual function is more complicated than myText() here?