-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
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.