Skip to content

Commit

Permalink
[Perf] Avoid React.Children.count traversal for empty state early ret…
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinTCoughlin authored and Seth Donohue committed Nov 23, 2020
1 parent ea78e4b commit ca7538c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
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

0 comments on commit ca7538c

Please sign in to comment.