Skip to content

Multiple WebPart initializations when partial navigation occurs. #2023

@tdwhite0

Description

@tdwhite0

Category

  • Question
  • Typo
  • Bug
  • Additional article idea

Expected or Desired Behavior

WebParts should consistently go through their lifecycle only once per instance of the WebPart.

Observed Behavior

When navigating across site collections, webparts are not being disposed properly and initialize multiple times. Partial navigation seems to be the culprit. These instances can sometimes stack up multiple times, so browser memory increases needlessly and in some cases (IE11) crashes completely.

Steps to Reproduce

Clone this webpart: https://github.com/tdwhite0/spfx-partialnavigation-bug, build it, and add to App Catalog.

Create a Blank Communication site at /sites/bug-reproduction1

Create another Blank Communication site at /sites/bug-reproduction2

In /sites/bug-reproduction1, add the test-onepointfive app to the site. This SPFX app contains one WebPart.

Add the Bug Reproduction WebPart to the page. This is a freshly yeoman generated 1.5.0 WebPart that only adds console.log() to track when webpart lifecycle event occur.

Add a Link WebPart to the page, pointing to the home page of /sites/bug-reproduction2. Key here is it being cross site collection.

With browser dev tools open, from the home page of /sites/bug-reproduction1, refresh the page. In the console, observe the webpart reporting its different phases (onInit, render). OnInit() is called one time, and render() is called one time.

Click the link to navigate to /sites/bug-reproduction2. Observe an empty site with no webparts.

Click the back button in the browser. Observe multiple onInit() and render() calls for the dev webpart.

When you navigate around the SharePoint site between site collections, the framework doesn’t dispose the instances of the webparts properly, and loads them multiple times. Each webpart that contains async logic makes its networks calls multiple times as well. In IE11, the memory starts to add up after only a few page loads and eventually crashes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋Original poster responded to request for feedback, awaiting attention from Microsoft / community.area:spfxCategory: SharePoint Framework (not extensions related)type:bug-suspectedSuspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions