Can't you just add a @MainActor annotation to the block?
.onPreferenceChange(HeightKey.self) { @MainActor height in self.height = height }