Skip to content

Clearing the potentialVariableMap when clearing flyout thwarts block recycling #9007

@riknoll

Description

@riknoll

Check for duplicates

  • I have searched for similar issues before opening a new one.

Description

Here is the corresponding makecode issue for this: microsoft/pxt-microbit#6181

MakeCode has recently moved to block inflaters for its flyout caching; we maintain a cache of recycled blocks and use those when creating new elements for our toolbox flyout. Many of our toolbox categories create variables like so:

Image

These variables are added to the workspace's potentialVariableMap, which gets cleared after all of the flyout items are disposed when clearing the flyout. The code for clearing variable maps also deletes all usages of the variables in the map, however the logic seems to exclude potential variables from that deletion which is good because otherwise it would dispose of all the blocks we are recycling.

This generally works as intended except when you drag one of those blocks with a variable out of the flyout. That creates a new variable in the workspace with the same ID as the potential variable. As a result, the variable map clearing code no longer filters out the potential variable usages and deletes all of the cached blocks from the workspace.

I currently have a workaround for this where I remap the variables when recycling blocks if I detect that a variable with the same ID appears in the non-potential variable map of the workspace. Ideally, however, the potential variable and the non-potential variable should have different IDs, or the variable map clearing code should know to skip usages in the flyout.

Reproduction steps

Reproducing this bug requires you to have a block inflater that recycles blocks like in MakeCode, so here are some steps to reproduce on a past version of MakeCode's micro:bit editor.

  1. go to https://makecode.microbit.org/v7.1.30
  2. create a new project
  3. in the toolbox, expand the "Advanced" section and open the Arrays category
  4. drag the "set list to ..." block out of the flyout
  5. Open the Arrays category again
  6. See the missing blocks

Stack trace

No stack trace

Screenshots

see microsoft/pxt-microbit#6181

Browsers

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugDescribes why the code or behaviour is wrong

    Type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions