Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
Comment thread
layershifter marked this conversation as resolved.
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-accordion",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-avatar",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-carousel",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-color-picker",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-dialog",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-list",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-menu",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-popover",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-swatch-picker",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-table",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-tabs",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-teaching-popover",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-toolbar",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: memoize context values in use*ContextValues hooks",
"packageName": "@fluentui/react-tree",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
'use client';

import * as React from 'react';
import type { AccordionContextValue } from '../../contexts/accordion';
import type { AccordionContextValues, AccordionState } from './Accordion.types';

export function useAccordionContextValues_unstable(state: AccordionState): AccordionContextValues {
const { navigation, openItems, requestToggle, multiple, collapsible } = state;

// This context is created with "@fluentui/react-context-selector", these is no sense to memoize it
const accordion: AccordionContextValue = {
navigation,
openItems,
requestToggle,
collapsible,
multiple,
};
const accordion = React.useMemo<AccordionContextValue>(
() => ({
navigation,
openItems,
requestToggle,
collapsible,
multiple,
}),
[navigation, openItems, requestToggle, collapsible, multiple],
);

return { accordion };
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
'use client';

import * as React from 'react';
import type { AvatarGroupContextValue, AvatarGroupContextValues, AvatarGroupState } from '../AvatarGroup';

export const useAvatarGroupContextValues = (state: AvatarGroupState): AvatarGroupContextValues => {
const { layout, size } = state;

const avatarGroup: AvatarGroupContextValue = {
layout,
size,
};
const avatarGroup = React.useMemo<AvatarGroupContextValue>(
() => ({
layout,
size,
}),
[layout, size],
);

return { avatarGroup };
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
'use client';

import * as React from 'react';
import type { AvatarGroupContextValue, AvatarGroupContextValues } from '../AvatarGroup/AvatarGroup.types';
import type { AvatarGroupPopoverState } from './AvatarGroupPopover.types';

export const useAvatarGroupPopoverContextValues_unstable = (
state: AvatarGroupPopoverState,
): AvatarGroupContextValues => {
const avatarGroup: AvatarGroupContextValue = {
isOverflow: true,
size: 24,
};
const avatarGroup = React.useMemo<AvatarGroupContextValue>(
() => ({
isOverflow: true,
size: 24,
}),
[],
);

return { avatarGroup };
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ForwardRefComponent } from '@fluentui/react-utilities';
import * as React from 'react';

import type { CarouselNavProps } from './CarouselNav.types';
import { useCarouselNavContextValues_unstable } from './CarouselNavContext';
import { useCarouselNavContextValues_unstable } from './useCarouselNavContextValues';
import { renderCarouselNav_unstable } from './renderCarouselNav';
import { useCarouselNav_unstable } from './useCarouselNav';
import { useCarouselNavStyles_unstable } from './useCarouselNavStyles.styles';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import * as React from 'react';
import type { CarouselNavContextValue, CarouselNavState } from './CarouselNav.types';
import type { CarouselNavContextValue } from './CarouselNav.types';

const carouselNavContext = React.createContext<CarouselNavContextValue | undefined>(undefined);

Expand All @@ -20,10 +20,3 @@ export const CarouselNavContextProvider = carouselNavContext.Provider;
export type CarouselNavContextValues = {
carouselNav: CarouselNavContextValue;
};

export function useCarouselNavContextValues_unstable(state: CarouselNavState): CarouselNavContextValues {
const { appearance } = state;
const carouselNav = React.useMemo(() => ({ appearance }), [appearance]);

return { carouselNav };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use client';

import * as React from 'react';
import type { CarouselNavContextValues } from './CarouselNavContext';
import type { CarouselNavState } from './CarouselNav.types';

export function useCarouselNavContextValues_unstable(state: CarouselNavState): CarouselNavContextValues {
const { appearance } = state;
const carouselNav = React.useMemo(() => ({ appearance }), [appearance]);

return { carouselNav };
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useCarouselSlider_unstable } from './useCarouselSlider';
import { renderCarouselSlider_unstable } from './renderCarouselSlider';
import { useCarouselSliderStyles_unstable } from './useCarouselSliderStyles.styles';
import type { CarouselSliderProps } from './CarouselSlider.types';
import { useCarouselSliderContextValues_unstable } from './CarouselSliderContext';
import { useCarouselSliderContextValues_unstable } from './useCarouselSliderContextValues';
import { useCustomStyleHook_unstable } from '@fluentui/react-shared-contexts';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import * as React from 'react';
import type { CarouselSliderContextValue, CarouselSliderState } from './CarouselSlider.types';
import type { CarouselSliderContextValue } from './CarouselSlider.types';

const carouselSliderContext = React.createContext<CarouselSliderContextValue | undefined>(undefined);

Expand All @@ -20,15 +20,3 @@ export const CarouselSliderContextProvider = carouselSliderContext.Provider;
export type CarouselSliderContextValues = {
carouselSlider: CarouselSliderContextValue;
};

export function useCarouselSliderContextValues_unstable(state: CarouselSliderState): CarouselSliderContextValues {
const { cardFocus } = state;
const carouselSlider = React.useMemo(
() => ({
cardFocus,
}),
[cardFocus],
);

return { carouselSlider };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use client';

import * as React from 'react';
import type { CarouselSliderContextValues } from './CarouselSliderContext';
import type { CarouselSliderState } from './CarouselSlider.types';

export function useCarouselSliderContextValues_unstable(state: CarouselSliderState): CarouselSliderContextValues {
const { cardFocus } = state;
const carouselSlider = React.useMemo(() => ({ cardFocus }), [cardFocus]);

return { carouselSlider };
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useCarouselViewport_unstable } from './useCarouselViewport';
import { renderCarouselViewport_unstable } from './renderCarouselViewport';
import { useCarouselViewportStyles_unstable } from './useCarouselViewportStyles.styles';
import type { CarouselViewportProps } from './CarouselViewport.types';
import { useCarouselSliderContextValues_unstable } from '../CarouselSlider/CarouselSliderContext';
import { useCarouselSliderContextValues_unstable } from '../CarouselSlider/useCarouselSliderContextValues';
import { useCustomStyleHook_unstable } from '@fluentui/react-shared-contexts';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useColorPicker_unstable } from './useColorPicker';
import { renderColorPicker_unstable } from './renderColorPicker';
import { useColorPickerStyles_unstable } from './useColorPickerStyles.styles';
import type { ColorPickerProps } from './ColorPicker.types';
import { useColorPickerContextValues } from '../../contexts/colorPicker';
import { useColorPickerContextValues } from './useColorPickerContextValues';
import { useCustomStyleHook_unstable } from '@fluentui/react-shared-contexts';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client';

import * as React from 'react';
import type { ColorPickerContextValue, ColorPickerContextValues } from '../../contexts/colorPicker';
import type { ColorPickerState } from './ColorPicker.types';

export const useColorPickerContextValues = (state: ColorPickerState): ColorPickerContextValues => {
const { color, shape, requestChange } = state;

const colorPicker = React.useMemo<ColorPickerContextValue>(
() => ({
requestChange,
color,
shape,
}),
[requestChange, color, shape],
);

return { colorPicker };
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type * as React from 'react';
import { createContext, useContextSelector } from '@fluentui/react-context-selector';
import type { ContextSelector, Context } from '@fluentui/react-context-selector';
import type { ColorPickerState, ColorPickerProps } from '../components/ColorPicker/ColorPicker.types';
import type { ColorPickerProps } from '../components/ColorPicker/ColorPicker.types';
import type { HsvColor } from '../types/color';

/**
Expand All @@ -19,19 +19,6 @@ export type ColorPickerContextValue = Pick<ColorPickerProps, 'shape' | 'color'>
requestChange: (event: React.ChangeEvent<HTMLInputElement>, data: { color: HsvColor }) => void;
};

export const useColorPickerContextValues = (state: ColorPickerState): ColorPickerContextValues => {
const { color, shape, requestChange } = state;

// This context is created with "@fluentui/react-context-selector", these is no sense to memoize it
const colorPicker: ColorPickerContextValue = {
requestChange,
color,
shape,
};

return { colorPicker };
};

export const colorPickerContextDefaultValue: ColorPickerContextValue = {
requestChange: () => {
/*noop*/
Expand Down
Loading
Loading