Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic property required in consuming web part's manifest #3193

Closed
mpowney opened this issue Jan 2, 2019 · 8 comments

Comments

@mpowney
Copy link

@mpowney mpowney commented Jan 2, 2019

If you add a dynamic property to the propertiesMetadata() method like:

  protected get propertiesMetadata(): IWebPartPropertiesMetadata {
    return {
      'dynamicProperty0': { dynamicPropertyType: 'string' }
    };
  }

But don't add a property to the web part's manifest like:

    // preconfiguredEntries node:

    "officeFabricIconFontName": "DocumentSearch",
    "properties": {
      "dynamicProperty0": "",
    }

You get an exception raised:

Uncaught Error: Serialization failed for web part WebPart.DynamicDataConsumerWebPart.3c797b3b-6634-404c-8772-d09a49f94236.
    at t [as constructor] (sp-pages-assembly_en-us_c565a80043b8eecd7e332455be57225f.js:857)
    at new t (sp-pages-assembly_en-us_c565a80043b8eecd7e332455be57225f.js:1445)
    at Function.t.create (sp-pages-assembly_en-us_c565a80043b8eecd7e332455be57225f.js:1445)
    at DynamicDataConsumerWebPart.t._internalSerialize (sp-pages-assembly_en-us_c565a80043b8eecd7e332455be57225f.js:1445)
    at DynamicDataConsumerWebPart.t._internalSetDirtyBit (sp-pages-assembly_en-us_c565a80043b8eecd7e332455be57225f.js:1445)
    at sp-pages-assembly_en-us_c565a80043b8eecd7e332455be57225f.js:1445
    at sp-pages-assembly_en-us_c565a80043b8eecd7e332455be57225f.js:1445
    at Map.forEach (<anonymous>)
    at e._executeForIdsOrAll (sp-pages-assembly_en-us_c565a80043b8eecd7e332455be57225f.js:1445)
    at sp-pages-assembly_en-us_c565a80043b8eecd7e332455be57225f.js:1445

This seems inconsistent with other web part properties, because they can be in use without them defined as preconfiguredEntries in the manifest.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@msft-github-bot

This comment has been minimized.

Copy link
Collaborator

@msft-github-bot msft-github-bot commented Jan 2, 2019

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@patmill

This comment has been minimized.

Copy link
Contributor

@patmill patmill commented Jan 2, 2019

Just to fill in all the data, what does the property definition in the webpart properties interface look like?

@mpowney

This comment has been minimized.

Copy link
Author

@mpowney mpowney commented Jan 2, 2019

Something like this:

protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {

    return {
      pages: [
        {
          header: {
            description: strings.PropertyPaneDescription
          },
          groups: [
            {
          primaryGroup: {
          groupFields: [
            PropertyPaneTextField('dynamicProperty0', {
              label: strings.PropertyLabelDynamicProperty0
            })
          ]

        },
        secondaryGroup: {
          groupFields: [
          PropertyPaneDynamicFieldSet({
            label: strings.PropertyLabelFieldSetDynamicProperty0,
            fields: [
              PropertyPaneDynamicField('dynamicProperty0', {
                label: strings.PropertyLabelDynamicProperty0
              })
            ],
            sharedConfiguration: {
              depth: DynamicDataSharedDepth.Property
            }
          })
        ]
        },
        showSecondaryGroup: !!this.properties.dynamicProperty0.tryGetSource()
      }
    ]
  };
@patmill

This comment has been minimized.

Copy link
Contributor

@patmill patmill commented Jan 2, 2019

Sorry, I meant the properties interface that you use in the webpart. Something like "IDynamicDataConsumerWebPartProps"

@mpowney

This comment has been minimized.

Copy link
Author

@mpowney mpowney commented Jan 2, 2019

Oh right yes, this is what the props interface looks like:

export interface IDynamicDataConsumerWebPartProps {
  dynamicProperty0: DynamicProperty<string>;
}
@patmill

This comment has been minimized.

Copy link
Contributor

@patmill patmill commented Jan 3, 2019

Ah, right. To work around this, you'll want to create the dynamicProperty object in your interface. Something like this:

      protected onInit(): Promise<any> {
      if (!this.properties.dynamicProperty0.reference)
      {
         this.properties.dynamicProperty0.setValue('Here is some default content');
      }
      return Promise.resolve();
     }
@mpowney

This comment has been minimized.

Copy link
Author

@mpowney mpowney commented Jan 5, 2019

Cool thanks @patmill.

I think it would be helpful to update this issue's content source (docs/spfx/dynamic-data.md) to explicitly call out the step of adding this code to onInit(), or filling out the .manifest.json, to avoid others spending time debugging the Serialization failed for web part exception. What do you think?

@VesaJuvonen

This comment has been minimized.

Copy link
Contributor

@VesaJuvonen VesaJuvonen commented Jan 24, 2019

Noted on the documentation update requirement - added on the backlog. Closing the original issue in here still. Also - if you @mpowney have time, we would absolutely welcome suggested edit on the article updates - Edit button on the page. Thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.