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

Fix MakeCode Editor Service Ready State #9837

Merged
merged 2 commits into from
Jan 30, 2024

Conversation

thsparks
Copy link
Contributor

Fixes a bug where you couldn't run eval multiple times. (In fact, messaging to the iframe was totally breaking down.)

Before this change, the makecodeEditorService unset its readyForMessages flag anytime the iframe ref was updated. This was done under the assumption that the ref updating also means the iframe would reload, which turns out to be untrue. As a result, we end up setting readyForMessages to false and get stuck because the editor inside the iframe does not send its editorcontentloaded event again, since it already did so a while ago.

I basically took the simplest approach to fixing this, which is to make the readyForMessages reset an intentional action, and only call that when we change the iframe url. It seems to work in my testing and I'm struggling to find a scenario where we'd get into a bad state again, but it's possible I'm missing something.

An alternative approach would be to send an "are you ready?" ping any time we want to send a message but readyForMessages is false, then switch to ready and clear the queue if the editor responds to that ping successfully (as we do currently when we get an editorcontentloaded event)...but that feels like it may be unnecessary at this stage.

I've also included a few UI touch-ups for when you are running eval multiple times and/or changing the rubric after eval has run.

Upload target: https://makecode.microbit.org/app/f3f1b4e65ff5b1c8a233beb71cf0024757ea5b4a-aff29c0756

…en we change the iframe url.

The ref can be updated anytime and doesn't necessarily mean the content of the iframe has changed or refreshed, so we can't simply unset the ready flag whenever that updates (the app has already sent its editorcontentloaded event, so it won't send another to unblock us). Instead, we need to preserve our ready flag unless the actual contents of the iframe changes.

An alternative approach would be to send a "ping" any time we try to send a message but we're not ready, and switch to ready if the ping is successful, but that feels like it may be unnecessary at this stage.
@thsparks thsparks requested a review from a team January 30, 2024 01:56
Copy link
Collaborator

@eanders-ms eanders-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@thsparks thsparks merged commit f743cf6 into master Jan 30, 2024
7 checks passed
@thsparks thsparks deleted the thsparks/teacher_tool/fix_iframe_ready branch January 30, 2024 18:58
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

Successfully merging this pull request may close these issues.

2 participants