-
Notifications
You must be signed in to change notification settings - Fork 2.9k
perf: memoize context values in use*ContextValues hooks #36008
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
Merged
layershifter
merged 4 commits into
microsoft:master
from
layershifter:refactor/memoize-context-values
Apr 23, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-accordion-a035aacb-feec-4686-9d08-dfe5b99b113f.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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-accordion", | ||
| "email": "olfedias@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-avatar-a7ba6b80-bd13-41cd-9f87-19a821ed169f.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-carousel-644cda54-062a-43b9-981f-c1fabf97482c.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-color-picker-d144aa96-5c6a-43be-9c90-21d1bd2486f9.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-dialog-6b927bc7-5fbf-453a-b6b3-618f33f0cef4.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-list-f2d5fd86-ac00-4a26-827d-1e8735fd408e.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-menu-b15954ad-9104-4f6b-836d-a0b19c2aa079.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-popover-6dcad78f-0802-4813-9338-396aa1c76c54.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-swatch-picker-62d6355e-f4aa-46f8-a3fc-a0b47b7b19ff.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-table-971a0a61-873b-490c-8aa6-55525810b3ef.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-tabs-2788d005-7db8-4940-b1b2-8555f2856eb3.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-teaching-popover-0fb348ae-dd55-4ad2-9c67-e07659802fae.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-toolbar-4958f82a-f2a1-4c90-a617-3072254072bc.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-tree-a8645cae-35d2-4d3d-931e-1e0b361e63ad.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
21 changes: 13 additions & 8 deletions
21
...-components/react-accordion/library/src/components/Accordion/useAccordionContextValues.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }; | ||
| } |
14 changes: 10 additions & 4 deletions
14
...components/react-avatar/library/src/components/AvatarGroup/useAvatarGroupContextValues.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }; | ||
| }; |
14 changes: 10 additions & 4 deletions
14
...ct-avatar/library/src/components/AvatarGroupPopover/useAvatarGroupPopoverContextValues.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...mponents/react-carousel/library/src/components/CarouselNav/useCarouselNavContextValues.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ts/react-carousel/library/src/components/CarouselSlider/useCarouselSliderContextValues.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...ents/react-color-picker/library/src/components/ColorPicker/useColorPickerContextValues.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.