sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

When navigating from one site to another, webparts are loaded 3 times on landing page

Open BraunJonathan opened this issue 8 years ago • 9 comments

Category

  • [ ] Question
  • [ ] Typo
  • [x] Bug
  • [ ] Additional article idea

Expected or Desired Behavior

When i navigate from a site to another, on the arrival page, the webpart should load only once...

This is really annoying because we have pages with webparts doing some pretty heavy data loading and which are accessed nearly exclusively from one site to antoher...

Observed Behavior

When i navigate from a site to another, on the landing page, the webpart is loaded 3 times (entirely recreated 3times, i put a log in OnInit function and it is showed 3 times). If i navigate from one page to another on the same site, the webaprt is only loaded once.

Steps to Reproduce

Assuming you have a webpart with a console log on the oninit method, juste put it on a page. Then go on ather SP site and add a link to the previous page. Click on the link and watch your log beeing shown 3 times...

Thanks for your contribution! Sharing is caring.

BraunJonathan avatar Oct 10 '18 10:10 BraunJonathan

After a few more tests, it seems it is even worse than i initially thought... It seems that 3 instances of the webpart are kept in the memory and every user action on the webpart is done 3 times !!! When navigating back and forth from the page to another site, the browser ends by not responding at all...

BraunJonathan avatar Oct 10 '18 12:10 BraunJonathan

Please provide your key code and project configure infomation.

Seiyasu avatar Oct 11 '18 02:10 Seiyasu

helloworld.zip Hi, you can find enclosed a helloworld sample spfx webpart with just a onInit method added.

I tested it with two modern communication sites (let's call them 'site A' and 'site B'); I created a page on 'site A' called page1.aspx and put the webpart on this page.

Then i went to site B and added an html link to page1.aspx. When a navigate throgh the link, the webpart is loaded 3 times (the onInit log appears 3 times).

I then added a second link on site B but this time to home.aspx of site A and also added a link on home.aspx of site A to page1.aspx. When i navigate from 'site B' to home.aspx of 'site A' and then from that page to page1.aspx, the webpart is only loaded once...

Does that cover what you asked?

BraunJonathan avatar Oct 11 '18 06:10 BraunJonathan

I can confirm this behavior. But in my case, the onInit (and also the render method btw....) gets called twice and not three times. Which of course is still too much. This only happens during page transition, not when reloading the full site via F5 in the browser for example.

OliverZeiser avatar Oct 12 '18 06:10 OliverZeiser

Interesting. I've got only one call from my webpart.

I've used webpart react template and add onInit into the project.

Then deploy the project into the SPO.

Install the webpart on the classic page on Site A

Create a Link on Site B Home page.

Click the link create on Site Home page and direct to Site A

Here is the screenshot of developer tool.

I guess is that bug on modern site, and I'm using classic site?

image

TheMiao avatar Oct 25 '18 12:10 TheMiao

Yes, i should have added that i'm experiencing that problem with two modern communication sites. Thanks for the intel though, as it could help devs to more easily find where the problem stands...

BraunJonathan avatar Oct 25 '18 13:10 BraunJonathan

Yes @BraunJonathan I've created modern site (both teams and communication), and I could reproduce your scenario.

From my own point of view. If you really want to have work around way to get rid of extra OnInit method calls. You could create a extra list, and use your webpart to listen your list. Once field in your list changed, don't load webpart. But it is a nasty way. Hopefully dev team will work on this soon.

TheMiao avatar Oct 26 '18 08:10 TheMiao

This should have been fixed in the service. Let us know if you continue seeing this issue.

johnguy0 avatar Jan 29 '20 00:01 johnguy0

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

msft-github-bot avatar Feb 05 '20 06:02 msft-github-bot