-
Notifications
You must be signed in to change notification settings - Fork 1k
Breaking change in SPFx dynamic data consuming page environment data (started June 23rd 2020) #5947
Description
Category
- Bug
Describe the bug
June 23rd a change happened which caused DynamicProperty.tryGetValue() to return an object instead of a string. This has had a severe impact on PnP Modern Search web part scenario's which use this functionality. It's not related to search, but to use of any of the page environment properties.
The failing line in the sample below is value = this.properties.foo.tryGetValue(); which was expected to return a string, which now has to be parsed.
It's ok to have a change, but should then be tied to a newer release of SPFx.
Create a web part with the sample code, configure to use Dynamic data via any page environment. Using local workbench you get a string, using hosted workbench you get an object. We're tracking the issue at microsoft-search/pnp-modern-search#325
import { Version } from '@microsoft/sp-core-library';
import { IPropertyPaneConfiguration, PropertyPaneDynamicField } from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart, IWebPartPropertiesMetadata } from '@microsoft/sp-webpart-base';
import { escape } from '@microsoft/sp-lodash-subset';
import * as strings from 'DdTestWebPartStrings';
import { DynamicProperty } from '@microsoft/sp-component-base';
export interface IDdTestWebPartProps {
foo: DynamicProperty<string>;
}
export default class DdTestWebPart extends BaseClientSideWebPart<IDdTestWebPartProps> {
public render(): void {
let value = "";
if (this.properties && this.properties.foo) {
value = this.properties.foo.tryGetValue();
}
this.domElement.innerHTML = `
<div>
${escape(value)}
</div>`;
}
protected get propertiesMetadata(): IWebPartPropertiesMetadata {
return {
'foo': {
dynamicPropertyType: 'string'
}
};
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: { description: strings.PropertyPaneDescription },
groups: [{
groupName: strings.BasicGroupName,
groupFields: [PropertyPaneDynamicField('foo', { label: strings.DescriptionFieldLabel })
]
}]
}
]
};
}
}