fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

Panel component calling render() twice upon launch

Open denniscoh opened this issue 7 years ago • 6 comments

We're upgrading Shifts Web from Fabric 6.182.1 to 7.23.0, and we're seeing Panel now calling its render() twice upon launch. Previously this would only get called once.

Jason Gore did some initial investigation and thinks there might be a change in 6.74 that caused this.

Here's a sandbox with Panel on 7.23.0 - render() called twice: https://codesandbox.io/s/office-ui-fabric-react-ts-jx9eu

And here's the same example with 6.182.1 - render() called once: https://codesandbox.io/s/office-ui-fabric-react-ts-dm2z5

Either set a breakpoint in render() of Panel.base.js, or look at the console.log output to see the sample's onRenderHeader callback get called.

denniscoh avatar Aug 14 '19 23:08 denniscoh

cc @kkjeer in case she has context

cliffkoh avatar Aug 15 '19 09:08 cliffkoh

The change I mentioned about 6.74 couldn't apply here since you didn't see this behavior in 6.182.1.

JasonGore avatar Aug 15 '19 15:08 JasonGore

I set up a CodePen with various React and Fabric versions that renders a Panel with a button. You can easily set the Fabric and React version used in the HTML tab.

This CodePen shows there have been multiple renders for some time with Panel when it is added to the DOM dynamically, stretching as far back as v6.4.

It does seem, however, that #6680 (introduced in v6.84.1) added a third render call. (@micahgodbolt Would you expect an additional render based on the changes in #6680?)

However, there will always be multiple Layer render calls on mount due to the mechanics of Layer, React portals and virtual parentage. We can look at fixing the third render, but I there will still be 2 renders occurring when Panel is rendered dynamically. I'm not sure why the initial page load example you provided differs in behavior between Fabric 6 and 7, but since Layer is known to render multiple times on mount, multiple renders should be expected in all cases.

JasonGore avatar Aug 15 '19 21:08 JasonGore

OH here's part of the challenge. This onRender has a different signature (and used differently) than all of our other onRenders

https://github.com/OfficeDev/office-ui-fabric-react/blob/fb8d01cccc8773da2617450e9522df7b3cc984b8/packages/office-ui-fabric-react/src/components/Panel/Panel.types.ts#L237-L246

Due to this approach, it appears that the function is getting called a few times to generate the finished header, and then render that header.

https://github.com/OfficeDev/office-ui-fabric-react/blob/2894062b1d0515055c29061dfc6f586f918ca41c/packages/office-ui-fabric-react/src/components/Panel/Panel.base.tsx#L180

micahgodbolt avatar Aug 21 '19 17:08 micahgodbolt

#6680 seems to have added an additional call. Do you expect that to be the case?

JasonGore avatar Aug 21 '19 17:08 JasonGore

This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your contributions to Fabric React!

msft-github-bot avatar Oct 27 '19 16:10 msft-github-bot