Can not get the instances of the widget when moving toolbar button to unready menu panel.

RESOLVED DUPLICATE of bug 941903

Status

()

defect
RESOLVED DUPLICATE of bug 941903
5 years ago
5 years ago

People

(Reporter: pzhang, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Here is the steps to reproduce:
  - Place the open-file-button in the toolbar.
  - Restart Firefox, *do not* open the menu panel.
  - Run the following code in the *browser* console.
    CustomizableUI.addListener({
      onWidgetAdded: (aWidgetId, aArea, aPosition) => {
        if (aWidgetId == 'open-file-button') {
          alert('Number of instances: ' + CustomizableUI.getWidget(aWidgetId).instances.length);
        }
      }
    });
  - Move the open-file-button to the menu panel.
    You can right click on the open-file-button, and click on the "Move to Menu" item.
  - Open the menu panel.

Expected result:
  An alert window is shown with message: "Number of instances: 1"

Actual result:
  An alert window is shown with message: "Number of instances: 0"


This is the issue i encountered when I tried to hide the badge icon when the button is placed in the menu panel, because of bug 1029937.

Comment 1

5 years ago
This is by design; the menu panel is not populated until it is first opened. For API-based widgets, that means it's possible for there to not be an instance in the window at this time. We tried improving this but the perf implications were very sad. See bug 941903 for more info.
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 941903

Comment 2

5 years ago
(you can probably achieve what you want using onWidgetBeforeDOMChange instead)
Reporter

Comment 3

5 years ago
(In reply to :Gijs Kruitbosch from comment #2)
> (you can probably achieve what you want using onWidgetBeforeDOMChange
> instead)

I tried, |onWidgetBeforeDOMChange| is fired before |onWidgetAdded|, so we can't get |widget.instances| in the |onWidgetBeforeDOMChange| listener either.

Comment 4

5 years ago
(In reply to Pin Zhang [:pzhang] from comment #3)
> (In reply to :Gijs Kruitbosch from comment #2)
> > (you can probably achieve what you want using onWidgetBeforeDOMChange
> > instead)
> 
> I tried, |onWidgetBeforeDOMChange| is fired before |onWidgetAdded|, so we
> can't get |widget.instances| in the |onWidgetBeforeDOMChange| listener
> either.

Why do you still need .instances? The *DOM* methods get the actual nodes passed. Also, are you caching |widget| in a variable, or not?
Reporter

Comment 5

5 years ago
(In reply to :Gijs Kruitbosch from comment #4)
> (In reply to Pin Zhang [:pzhang] from comment #3)
> > (In reply to :Gijs Kruitbosch from comment #2)
> > > (you can probably achieve what you want using onWidgetBeforeDOMChange
> > > instead)
> > 
> > I tried, |onWidgetBeforeDOMChange| is fired before |onWidgetAdded|, so we
> > can't get |widget.instances| in the |onWidgetBeforeDOMChange| listener
> > either.
> 
> Why do you still need .instances? The *DOM* methods get the actual nodes
> passed. Also, are you caching |widget| in a variable, or not?

No, i didn't cache |widget|.

As I mentioned in comment 0, as a workaround to bug 1029937, I tried to update remove the badge style from the widget button in all the opened windows, so it won't break the menu panel. 

BTW, using css rule to disable the badged style in the menu-panel works well as a workaround.
You need to log in before you can comment on or make changes to this bug.