Property pane options are not refreshed when calling this.onDispose method
Category
- [ ] Question
- [ ] Typo
- [x] Bug
- [ ] Enhancement / Suggestion
- [ ] Additional article idea
Expected or Desired Behavior
Property pane options should be refreshed on calling this.onDispose() method in a promise callback.
Observed Behavior
Property pane options are not refreshed on calling this.onDispose() method in a promise callback. This is observed in the localhost's workbench.
On debugging the solution, I have observed that the getPropertyPaneConfiguration is called multiple times and eventually onDispose method kicks in somewhere internally although the check in my code does not allow calling the method for loading the data multiple times.
Steps to Reproduce
- Create a blank project in SPFx
- In the getPropertyPaneConfiguration method add code for loading values, i.e.
if (!this.listsFetched) {
this.fetchLists().then((response) => {
this.dropDownOptionsLists = response;
this.listsFetched = true;
// the next line refreshes the property pane
this.onDispose();
});
}
....
// skipped for brevity
groupFields: [
PropertyPaneDropdown('calendarList', {
label: 'List Title',
options: this.dropDownOptionsLists
}),
]
3. In my case, the fetchLists method returns a promise of type array with IPropertyPaneDropdownOption objects and checks for the environment type - local or SharePoint / SharePoint classic.
This is the part of the code calling the mock data for local:
return this._getMockListData().then((data: ISPLists) => {
var result: IPropertyPaneDropdownOption[] = new Array<IPropertyPaneDropdownOption>();
data.value.forEach((list: ISPList) => {
result.push({ key: list.Id, text: list.Title });
});
return result;
}) as Promise<IPropertyPaneDropdownOption[]>;
Hi @Sartor87, Why do you call the onDispose yourself. The onDispose() is a lifecycle method that is expected to be called when we dispose the web part. This gives the developer an options to dispose client side resources like DOM element.
https://github.com/SharePoint/sp-dev-docs/wiki/Async-data-fetch-in-the-property-pane
I was referring to that document, but it seems it has changed since last visited. However, now I am getting compile error that the refreshPropertyPane does not exist.
Re-created the web part - same error.
Updated the document - it was written a while ago before the APIs changed. You need to call this.context.propertyPane.refresh();
@patmill thanks - works properly now!
@Sartor87 - Looks like the you are good now. I am closing this issue. Please re-open if you think the issue still exists.
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues