sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Property pane options are not refreshed when calling this.onDispose method

Open Sartor87 opened this issue 9 years ago • 6 comments

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

  1. Create a blank project in SPFx
  2. 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[]>;

Sartor87 avatar Mar 01 '17 07:03 Sartor87

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.

manishgarg1 avatar Mar 02 '17 01:03 manishgarg1

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.

Sartor87 avatar Mar 02 '17 11:03 Sartor87

Updated the document - it was written a while ago before the APIs changed. You need to call this.context.propertyPane.refresh();

patmill avatar Mar 02 '17 19:03 patmill

@patmill thanks - works properly now!

Sartor87 avatar Mar 06 '17 07:03 Sartor87

@Sartor87 - Looks like the you are good now. I am closing this issue. Please re-open if you think the issue still exists.

srideshpande avatar Mar 09 '17 22:03 srideshpande

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

msft-github-bot avatar Jan 29 '20 18:01 msft-github-bot