Skip to content

Context not being reinitialized between pages #1201

@tarjeieo

Description

@tarjeieo

This issue seems related to #544. I talked with Vesa on twitter and he asked me to create a new issue.

Category

  • Question
  • Typo
  • Bug
  • Additional article idea

Expected or Desired Behavior

We have an SpFx web part that renders an editing experience for additional list fields on the page. The web part is upgraded to the latest 1.4 drop. The editors can edit the page and then select a value from a dropdown. On save, the web part persists the field value for the current page. This works as intended on a single page.

Observed Behavior

When standing on a page with the web part present, and then creating a new page, and adding this web part again, the problem appears. Seemingly everything works as intended, but when selecting a value in the dropdown and saving the page, the previous page's value is updated, not the current one. When creating another page and repeating this again, the first page is updated.

Investing this further, it looks like this.context is not being reinitialized. Specifically the page id (which we are using) is not updated, and always contains the first, initial page that has this web part. This property is this.context.pageContext.listItem.id. I haven't noticed (nor looked for to be fair) if any other properties are updated later.

Our code uses OnInit to create the pnp context each time, but while debugging it doesn't look like the context changes in this method.

Another observed behavior is that the web part's console logging is stacking on subsequent pages. I.e. if you've created 5 pages in one go, the web part's log messages are appearing in the console 5 times with the exact same messages. Not sure if this is related, or a symptom of something else.

Steps to Reproduce

  • Create a web part that uses this.context.pageContext.listItem.Id
  • Add web part to a page
  • Create a new page while standing on the first page
  • Add the same web part to the new page
  • Observe that this.context.pageContext.listItem.Id has the Id of the initial page

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:spfxCategory: SharePoint Framework (not extensions related)status:fixed-next-dropIssue planned to be fixed in an upcoming release.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions