'Why does the combination of @Environment and .onChange cause the view to redraw itself?

Build this very simple app and observe the logs as you minimize the app (or put it in the background) and make bring it back.

import SwiftUI

@main
struct DemoApp: App {
    var body: some Scene {
        WindowGroup {
            FocusedView()
        }
    }
}

struct FocusedView: View {
    @Environment(\.locale) private var locale
    
    @FocusState private var isEmptyFocused: Bool
    
    var body: some View {
        let _ = Self._printChanges()
        EmptyView()
            .onChange(of: isEmptyFocused) { _ in
            }
    }
}

You should get a new FocusedView: _isEmptyFocused changed. each time.

Comment either @Environment or .onChange(of: ) {} and it's silent. But having both triggers a redraw.

The @Environment value doesn't have to be locale, it can be something else.



Solution 1:[1]

A DNS record is just something like a translation table between the domain name and the IP address.

  • Your server keeps the IP address.
  • At the provider, where you buy the domain name, create an A Record mapping the domain name to the IP address.

If you want to keep the port, you can, nothing prevents you to do so (you will need to explicitly provide the port number the same way you do with the IP address)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gusto2