fix: Fix exception when disposing of a workspace with a variable block obscuring a shadow block. #8619
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.
The basics
The details
Resolves
Fixes gonfunko/scratch-blocks#210
Proposed Changes
This PR fixes a tricky bug related to workspace disposal. When a WorkspaceSvg instance A is disposed:
this.rendered = false
VariableMap.deleteVariable
callsVariableMap.getVariableUsesById
to identify references to the variableVariableMap.getVariableUsesById
callsVariables.getVariableUsesById
, passing its workspace, which, because this variable map was shared with the flyout by Workspace A, is Workspace A, which is in the process of being torn downVariables.getVariableUsesById
retrieves the blocks of Workspace A, which in this (mildly) contrived example includes a variable block obscuring a shadow blockVariableMap.deleteVariable
callsdispose
on the variable block obscuring a shadow block on Workspace A, in order to clean up references to the being-deleted variableBlockSvg
constructor checks to ensure that its workspace is rendered (to prevent creating aBlockSvg
on a regularWorkspace
), but because the workspace is being disposed,rendered
isfalse
, so it throwsThis PR only clears the variable map when the workspace being disposed is not a flyout workspace, which resolves the issue.