microsoft / pxt

Microsoft MakeCode (PXT - Programming eXperience Toolkit)
https://makecode.com
MIT License
2.1k stars 588 forks source link

Some extension subcategories can go missing #7581

Open aznhassan opened 4 years ago

aznhassan commented 4 years ago

Problem

Loading an extension and then loading a second extension that contains the first can lead to missing subcategories.

Repro Steps

  1. Open up a Microbit and reset the page or clear the __pxt_apis_microbit indexed db entry.
  2. Start a new project and load the makerbit-lcd1602 extension. You'll see a MakerBit category in the toolbox with LCD1602 and LCD2004 subcategories under it.
  3. Load the makerbit extension, which includes the same lcd1602 code. You'll now see that the LCD2004 category is gone while the LCD1602 category remains.

If you look for 2004 in the toolbox search bar, you'll still be able to find the LCD2004 blocks.

Expected Behavior

The expected behavior is that the LCD2004 subcategory should not disappear.

Note

The problem probably lies with how namespaces for extensions are defined.

After Loading Just the makerbit-lcd1602 extension

JustLCD

After loading the makerbit extension as well

MakerbitAndLcd

Searching for the LCD2004 blocks

image

Desktop:

Additional context

Refer to #7562 for additional context.

aznhassan commented 4 years ago

A place to start would be the createCategories function in toolboxeditor.tsx. Looking at the following line in particular:

if ((md.subcategories && md.subcategories.length) || that.subcategoryMap[ns]) {
    subcategories = createSubCategories([ns, md], md.subcategories || Object.keys(that.subcategoryMap[ns]), isAdvanced);
}

we can see that we use the list of subcategories associated with each namespace or the subcategoryMap. When the makerbit-lcd1602 extension is installed, the makerbit Symbolnfo does not have a subcategories field, but the subcategory map contains both the LCD1602 and LCD2004 subcategories for the makerbit entry.

Later when we install the makerbit extension, the makerbit SymbolInfo will be updated to have a subcategories field. That field will not contain LCD2004. It is interesting to note that at this point, the subcategoryMap will actually contain the LCD2004 subcategory along with all the others present in the subcategory list on the makerbit SymbolInfo. There is a disconnect between the subcategoryMap the list of subcategories in the SymbolInfo of a namespace.

Subcategory list on the namespace

MissingSubcategory

Subcategories for the namespace in the subcategory map

MissingSubcategoryTwo

RRWagner commented 3 years ago

Now it seems that just loading the makerbit-lcd1602 extension, which has both 1602 and 2004, does not show MakerBit at all in the main category list, and when looking at the javascript view, only 1602 shows up, but not 2004.

image

https://makecode.microbit.org/_4UDXKjXegEvt

This may be related to issue https://github.com/microsoft/pxt/pull/7562, but in this case we're not loading a second extension (are we?).

And, it's also now the case that just trying to add the complete makerbit extension package, adds all the subcategories as can be seen in the javascript view, but MakerBit does not appear in the main category list at all.

image

This happens with both the browser editor, and the MakeCode for microbit.app for Mac, v3.0.65.

RRWagner commented 3 years ago

It may still be related to this issue: https://github.com/microsoft/pxt-microbit/issues/3332 (?)