mark editor as incomplete when loading blocks file #10900
Merged
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.
fixes https://github.com/microsoft/pxt-minecraft/issues/2945
possibly also fixes the other code disappearing bugs, but i can't repro those so not sure.
this bug was caused by a race condition where the tutorial loading triggered a save operation while blockly was still being loaded. because the file hadn't been loaded yet, the editor would overwrite the file it was loading with an empty workspace thus erasing all the blocks.
i'm still not sure why this doesn't trigger in our other editors (like micro:bit), but i'm guessing it's just a trick of timing.
the fix here is to just prevent the editor from saving when it's loading a file. we already have an
isIncomplete
API which source editors implement to indicate when the editor is in a state where the source should not be saved (for example, while a block is being dragged by the user), so i've extended that logic to also check to see if a file is being loaded. i also moved the flag tracking that state earlier in the process so that we set it before the blockly load starts.changing this stuff is always tricky, so we should make sure to really test this. i'd like to do a bigger refactor here but deliberately kept the change as minimal as possible.