Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Perf] Avoid React.Children.count traversal for empty state early return #15503

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Avoid React.Children traversal for early return cases",
"packageName": "@fluentui/react-internal",
"email": "KevinTCoughlin@users.noreply.github.com",
"dependentChangeType": "patch",
"date": "2020-10-13T23:47:26.980Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Avoid React.Children traversal for early return cases",
"packageName": "@fluentui/react-cards",
"email": "KevinTCoughlin@users.noreply.github.com",
"dependentChangeType": "patch",
"date": "2020-10-13T23:47:14.293Z"
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/** @jsx withSlots */
import * as React from 'react';
import { withSlots, getSlots } from '@fluentui/foundation-legacy';
import { Stack } from '@fluentui/react/lib/Stack';
import { ICardSectionComponent, ICardSectionProps, ICardSectionSlots } from './CardSection.types';

export const CardSectionView: ICardSectionComponent['view'] = props => {
const { children, ...rest } = props;
if (React.Children.count(children) < 1) {
// eslint-disable-next-line eqeqeq
if (children == null) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { StackItemStyles as styles } from './StackItem.styles';

const StackItemView: IStackItemComponent['view'] = props => {
const { children } = props;
if (React.Children.count(children) < 1) {
// eslint-disable-next-line eqeqeq
if (children == null) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-internal/src/components/Text/Text.view.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/** @jsx withSlots */
import * as React from 'react';
import { withSlots, getSlots } from '@fluentui/foundation-legacy';
import { getNativeProps, htmlElementProperties } from '../../Utilities';
import { ITextComponent, ITextProps, ITextSlots } from './Text.types';

export const TextView: ITextComponent['view'] = props => {
if (React.Children.count(props.children) === 0) {
// eslint-disable-next-line eqeqeq
if (props.children == null) {
return null;
}

Expand Down