Swift UI ‘ghost’ outline left over during TextField edition

Folks,

I’m try to write a brand new MacOS app from scratch using Swift UI and concurrency… Quite a steep learning curve to learn how to mix the two.

Anyway, I think I’m getting the hang of it now, but I’m faced with a small glitch. I have a simple form to start with in order to input credentials to log into a server where the data to display is (REST API). Valid credentials are pre-filled in the Form Text/SecureField. But as soon as I try to edit (just testing) one of the fields, a spurious outline appears (see attached screenshots). Sometimes that outline appears when the window closes and another one pops up as a segue. If I hide the window under, say, the Xcode main window and raise it back, the spurious outline disappears, so that’s definitely a remnant of a transient operation.

I wonder where is the bug responsible for that. I don’t see what could cause such a ‘ghost’ to show up, but I might be just overlooking it. Has anyone experienced the same thing?

Make sure you only access the GUI and the corresponding state from the main thread. If not, all kind of strange behaviour may occur.

Yeah, you’re right, I am aware of that, and I’m taking great pains to stay safe. But what I am at a loss is where a data race could occur so early in the code.

My @stateobject is marked @MainActor, but there is no background thread activity before the OK button is clicked (credentials check). Thus the only write operations that occur on the state object at this stage are the updates triggered by the TextFields themselves.

There’s a if statement in the WindowsGroup in order to move on to a different window if the credentials are cleared, but the glitch happens even if I remove the if part.

Really, I’m a bit stumped.

UPDATE: This seems related to the use of SecureField. When I use a TextField instead, the outline doesn’t seem to show up. I wonder if this is not caused by an interference with the password pop-up that shows up and offers to pick up a username/password combination already registered (maybe the system wants to show it, but then reneges on that).

Swift UI ‘ghost’ outline left over during TextField edition
 
 
Q