Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async dispatch causes loss of change (SwiftUI, macOS) #27

Open
wtholliday opened this issue Sep 19, 2021 · 5 comments
Open

async dispatch causes loss of change (SwiftUI, macOS) #27

wtholliday opened this issue Sep 19, 2021 · 5 comments

Comments

@wtholliday
Copy link

wtholliday commented Sep 19, 2021

This line causes an occasional loss of a change with SwiftUI on macOS, presumably due to reordering of updates. After typing a character, the change is undone.

Why was the line needed? There isn't a comment in the code or an explanation in the change description. On macOS, SyntaxTextView.Coordinator.didChangeText is already called on the main thread.

There's this clue: // allow the client to decide on thread... but I'm still not sure the intent.

@andreweades

thanks!

wtholliday added a commit to audulus/Sourceful that referenced this issue Sep 19, 2021
@ActuallyTaylor
Copy link

I forget what this line does exactly, but it without it I’ve seen really odd issues in my text editor on iOS at least. I wouldn’t remove the code, maybe add a check for macOS or iOS and run the code when on iOS. This is safer than just removing the call completely.

@wtholliday
Copy link
Author

Well I've got to support iOS too, so I'll try to get to the bottom of it. I think it's pretty strange to be doing async stuff there.

@ActuallyTaylor
Copy link

Okay after some looking I found the commit that added this for my editor. I believe the reason for it was an issue with SwiftUI crashing when it was not accessed from the main thread. Which can sometimes occur.

@wtholliday
Copy link
Author

wtholliday commented Sep 20, 2021

Ok, what about using DispatchQueue.main.sync instead of async? That should avoid the reordering. I'll probably give that a shot soon.

Also, why would I want a callback on another thread?

parent.custom.didChangeText(parent)

@wtholliday
Copy link
Author

@ActuallyZach , do you know the circumstances under which didChangeText is called on a thread other than the main thread? I'm testing on iOS and just see it being called on the main thread:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants