webusb: when connecting, send a few commands to flush commands #5843
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On my machine with a teams call & full server (watched pxt build / pxt serve) I was able to repro the 5 -> 131 almost 100% of the time when refreshing the same page (turns out having an old device helped a bit!). After poking at it for a bit, this fix of moving "command flushing" up / repeating it a few times to ensure it's cleared seems to have fixed that 100% on my machine in that scenario. I don't have as good of repro cases for the other issues but trying to get repros on the other scenarios now.
(test program i was using, modified from a previous one to be more spammy https://makecode.microbit.org/_5j14oYbeTcCC)
I believe this should actually cover the cases that the more comprehensive suggestion in #5530 handles; our typical tactic for errors in operations is 'throw up hands and reconnect when things misbehave', so clearing through this does largely the same without spreading the logic throughout the app (and if not, first step would be to add reconnect attempts in those scenarios.)