Skip to content

perf: memoize context values in use*ContextValues hooks#36008

Merged
layershifter merged 4 commits intomicrosoft:masterfrom
layershifter:refactor/memoize-context-values
Apr 23, 2026
Merged

perf: memoize context values in use*ContextValues hooks#36008
layershifter merged 4 commits intomicrosoft:masterfrom
layershifter:refactor/memoize-context-values

Conversation

@layershifter
Copy link
Copy Markdown
Member

@layershifter layershifter commented Apr 20, 2026

Summary

  • Wraps context value objects in React.useMemo across all @fluentui/react-context-selector consumer packages so Provider value identity stays stable across renders, preventing unnecessary consumer re-renders.
  • Removes the old comment "no sense to memoize it".
  • Extracts use*ContextValues hooks that were co-located with context creation (contexts/colorPicker.ts, contexts/swatchPicker.ts, CarouselSlider/CarouselSliderContext.ts, CarouselNav/CarouselNavContext.ts) into dedicated files under their component folders, matching the convention already used elsewhere.
  • Introduces usePopoverContextValues_unstable + PopoverContextValues for @fluentui/react-popover to replace the inline <PopoverContext.Provider value={{...}}> that was built directly in renderPopover_unstable. renderPopover_unstable now accepts an optional contextValues and falls back to the newly exported popoverContextDefaultValue.

Notes

  • renderPopover_unstable gains an optional contextValues parameter; the change cascades to renderTeachingPopover_unstable which re-uses it. Both remain backward compatible via the default-value fallback.
  • useSwatchPickerContextValues is publicly exported; its import surface is preserved via re-export from contexts/index.ts.
  • react-dialog/DialogSurface was intentionally skipped (returns a primitive true).
  • react-migration-v0-v9/List was intentionally skipped.

🤖 Generated with Claude Code

Wraps context value objects in `React.useMemo` across react-context-selector
consumer packages so Provider value identity stays stable across renders when
dependencies are unchanged, preventing unnecessary consumer re-renders.

Also extracts `use*ContextValues` hooks that were co-located with context
creation into dedicated files under their component folders (color-picker,
swatch-picker, carousel-slider, carousel-nav), and introduces a new
`usePopoverContextValues_unstable` hook to replace the inline Provider
object that was built directly in `renderPopover_unstable`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 20, 2026

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-accordion
Accordion (including children components)
103.515 kB
31.358 kB
103.546 kB
31.361 kB
31 B
3 B
react-avatar
AvatarGroup
17.5 kB
7.006 kB
17.525 kB
7.018 kB
25 B
12 B
react-charts
AreaChart
412.943 kB
126.648 kB
413.179 kB
126.715 kB
236 B
67 B
react-charts
DeclarativeChart
763.705 kB
220.666 kB
763.941 kB
220.708 kB
236 B
42 B
react-charts
DonutChart
323.362 kB
97.164 kB
323.598 kB
97.203 kB
236 B
39 B
react-charts
FunnelChart
314.909 kB
94.178 kB
315.145 kB
94.214 kB
236 B
36 B
react-charts
GanttChart
396.051 kB
120.15 kB
396.287 kB
120.229 kB
236 B
79 B
react-charts
GaugeChart
322.795 kB
96.593 kB
323.031 kB
96.624 kB
236 B
31 B
react-charts
GroupedVerticalBarChart
403.926 kB
122.719 kB
404.162 kB
122.801 kB
236 B
82 B
react-charts
HeatMapChart
398.123 kB
122.053 kB
398.359 kB
122.12 kB
236 B
67 B
react-charts
HorizontalBarChart
303.092 kB
89.309 kB
303.328 kB
89.375 kB
236 B
66 B
react-charts
Legends
242.983 kB
71.8 kB
243.069 kB
71.827 kB
86 B
27 B
react-charts
LineChart
424.283 kB
128.705 kB
424.519 kB
128.787 kB
236 B
82 B
react-charts
PolarChart
351.931 kB
107.572 kB
352.167 kB
107.633 kB
236 B
61 B
react-charts
SankeyChart
220.845 kB
68 kB
221.013 kB
68.074 kB
168 B
74 B
react-charts
ScatterChart
403.665 kB
122.833 kB
403.901 kB
122.916 kB
236 B
83 B
react-charts
VerticalBarChart
440.395 kB
128.325 kB
440.631 kB
128.396 kB
236 B
71 B
react-charts
VerticalStackedBarChart
409.937 kB
124.242 kB
410.173 kB
124.305 kB
236 B
63 B
react-color-picker
ColorPicker
16.187 kB
6.529 kB
16.214 kB
6.542 kB
27 B
13 B
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
237.205 kB
68.894 kB
237.472 kB
68.929 kB
267 B
35 B
react-components
react-components: entire library
1.301 MB
325.227 kB
1.302 MB
325.417 kB
726 B
190 B
react-dialog
Dialog (including children components)
102.135 kB
30.369 kB
102.176 kB
30.389 kB
41 B
20 B
react-headless-components-preview
react-headless-components-preview: entire library
70.65 kB
20.862 kB
70.724 kB
20.881 kB
74 B
19 B
react-list
List
87.128 kB
25.767 kB
87.155 kB
25.773 kB
27 B
6 B
react-menu
Menu (including children components)
170.824 kB
52.032 kB
170.91 kB
52.06 kB
86 B
28 B
react-menu
Menu (including selectable components)
174.002 kB
52.615 kB
174.088 kB
52.647 kB
86 B
32 B
react-popover
Popover
134.131 kB
41.552 kB
134.299 kB
41.601 kB
168 B
49 B
react-swatch-picker
@fluentui/react-swatch-picker - package
104.323 kB
29.946 kB
104.356 kB
29.956 kB
33 B
10 B
react-table
DataGrid
159.801 kB
45.015 kB
159.836 kB
45.028 kB
35 B
13 B
react-teaching-popover
TeachingPopover
112.414 kB
34.219 kB
112.771 kB
34.321 kB
357 B
102 B
react-tree
FlatTree
148.117 kB
42.216 kB
148.205 kB
42.256 kB
88 B
40 B
react-tree
PersonaFlatTree
149.945 kB
42.59 kB
150.033 kB
42.629 kB
88 B
39 B
react-tree
PersonaTree
146.005 kB
41.416 kB
146.093 kB
41.446 kB
88 B
30 B
react-tree
Tree
144.183 kB
41.042 kB
144.271 kB
41.075 kB
88 B
33 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-avatar
Avatar
48.492 kB
15.379 kB
react-avatar
AvatarGroupItem
61.88 kB
19.405 kB
react-breadcrumb
@fluentui/react-breadcrumb - package
115.18 kB
31.479 kB
react-charts
HorizontalBarChartWithAxis
63 B
83 B
react-charts
Sparkline
91.4 kB
28.708 kB
react-color-picker
ColorArea
47.556 kB
16.703 kB
react-color-picker
ColorSlider
39.73 kB
14.746 kB
react-components
react-components: Button, FluentProvider & webLightTheme
70.415 kB
19.963 kB
react-components
react-components: FluentProvider & webLightTheme
43.63 kB
14.026 kB
react-datepicker-compat
DatePicker Compat
225.645 kB
63.659 kB
react-list
ListItem
111.036 kB
32.683 kB
react-overflow
hooks only
12.117 kB
4.627 kB
react-persona
Persona
55.447 kB
17.311 kB
react-portal-compat
PortalCompatProvider
8.386 kB
2.624 kB
react-table
Table (Primitives only)
41.015 kB
13.174 kB
react-table
Table as DataGrid
131.023 kB
36.014 kB
react-table
Table (Selection only)
69.409 kB
19.408 kB
react-table
Table (Sort only)
68.052 kB
19.026 kB
react-tag-picker
@fluentui/react-tag-picker - package
187.196 kB
55.98 kB
react-tags
InteractionTag
13.742 kB
5.473 kB
react-tags
Tag
29.666 kB
9.433 kB
react-tags
TagGroup
82.265 kB
24.156 kB
react-timepicker-compat
TimePicker
109.856 kB
36.253 kB
🤖 This report was generated against 81852161f3ed30c461b2c8e7af30b8d0b4387fa1

@github-actions
Copy link
Copy Markdown

Pull request demo site: URL

@layershifter layershifter force-pushed the refactor/memoize-context-values branch from d9c6d11 to ce3566a Compare April 22, 2026 08:41
Copy link
Copy Markdown
Contributor

@Mitch-At-Work Mitch-At-Work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeachingPopover and Carousel looking good after changes (E2E covered in another PR)

@layershifter layershifter merged commit 13bcf75 into microsoft:master Apr 23, 2026
12 checks passed
@layershifter layershifter deleted the refactor/memoize-context-values branch April 23, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants