Hi, I have an issue where the render method is called many times on a page that has an spfx webpart on it - this usually happens when navigating to a page from a hero webpart.
When navigating to a page with a webpart on it from a hero , I expect the spfx webpart on a page to be rendered once.
The page I navigated to, will usually be rendered twice, if not more - the most I've seen is 4 times.This happens pretty consistently.
console.log("Rendered!");
```
public render(): void {
this.domElement.innerHTML =
Customize SharePoint experiences using Web Parts.
${escape(this.properties.description)}
`

It seems that if you navigate to the page the web part is on directly , it only renders once, if you go to the page from a link in the menu, it renders usually twice , and if you go there from a hero it will render usually 2 -4 times. Is this desired behaviour, or am I missing something?
Unfortunately we do not guarantee that render will only get called once. You should not rely on a single render. However, we will look into this and try to understand why render is called multiple times, but please don't rely on that.
Ok thanks, how do you reccomend on dealing with multiple renders and not duplicating output?
Thanks :)
@will101 use the BaseClientSideWebPart.renderedOnce property on the base webpart:
public render(): void {
if (!this.renderedOnce) {
this.domElement.innerHTML = `bla bla bla`;
}
}
Ahhhh that's a really good idea, thank you sir!

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
Most helpful comment
@will101 use the
BaseClientSideWebPart.renderedOnceproperty on the base webpart: