@primer/react 0.0.0-20260220144103 → 0.0.0-20260220145113

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,12 +1,18 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260220144103
3
+ ## 0.0.0-20260220145113
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - Fake entry to force publishing
8
8
 
9
- - [#7551](https://github.com/primer/react/pull/7551) [`edb8eca`](https://github.com/primer/react/commit/edb8eca477e9bb940732bddfa83a294332f2381a) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(Text): remove unnecessary useRef and useImperativeHandle hooks
9
+ - [#7555](https://github.com/primer/react/pull/7555) [`64c2243`](https://github.com/primer/react/commit/64c2243d07fc580a5565493b917b27081ef6a191) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(useSlots): short-circuit iteration and skip filled slots
10
+
11
+ - [#7547](https://github.com/primer/react/pull/7547) [`4943d67`](https://github.com/primer/react/commit/4943d671ddb590461e59f9745e6093d47e770f7a) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(useScrollFlash): defer scroll read/write to requestAnimationFrame to avoid forced reflow
12
+
13
+ - [#7551](https://github.com/primer/react/pull/7551) [`2fbfc49`](https://github.com/primer/react/commit/2fbfc49fad6f11edc51850e32e9c0b2ade8ca1f1) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(Text): remove unnecessary useRef and useImperativeHandle hooks
14
+
15
+ - [#7553](https://github.com/primer/react/pull/7553) [`6225ba2`](https://github.com/primer/react/commit/6225ba231cfdbe6ef7fa41dd62734d5a970bdc7d) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(useRefObjectAsForwardedRef): add dependency array to useImperativeHandle
10
16
 
11
17
  ## 38.13.0
12
18
 
@@ -1,6 +1,5 @@
1
- import { c } from 'react-compiler-runtime';
2
- import { useRef, useReducer, useDeferredValue } from 'react';
3
- import { AutocompleteContext, AutocompleteDeferredInputContext, AutocompleteInputContext } from './AutocompleteContext.js';
1
+ import { useRef, useReducer, useCallback, useMemo, useDeferredValue } from 'react';
2
+ import { AutocompleteContext, AutocompleteInputContext, AutocompleteDeferredInputContext } from './AutocompleteContext.js';
4
3
  import AutocompleteInput from './AutocompleteInput.js';
5
4
  import AutocompleteMenu from './AutocompleteMenu.js';
6
5
  import AutocompleteOverlay from './AutocompleteOverlay.js';
@@ -49,12 +48,10 @@ const reducer = (state, action) => {
49
48
  return state;
50
49
  }
51
50
  };
52
- const Autocomplete = t0 => {
53
- const $ = c(24);
54
- const {
55
- children,
56
- id: idProp
57
- } = t0;
51
+ const Autocomplete = ({
52
+ children,
53
+ id: idProp
54
+ }) => {
58
55
  const activeDescendantRef = useRef(null);
59
56
  const scrollContainerRef = useRef(null);
60
57
  const inputRef = useRef(null);
@@ -66,160 +63,80 @@ const Autocomplete = t0 => {
66
63
  isMenuDirectlyActivated,
67
64
  selectedItemLength
68
65
  } = state;
69
- let t1;
70
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
71
- t1 = value => {
72
- dispatch({
73
- type: "inputValue",
74
- payload: value
75
- });
76
- };
77
- $[0] = t1;
78
- } else {
79
- t1 = $[0];
80
- }
81
- const setInputValue = t1;
82
- let t2;
83
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
84
- t2 = value_0 => {
85
- dispatch({
86
- type: "showMenu",
87
- payload: value_0
88
- });
89
- };
90
- $[1] = t2;
91
- } else {
92
- t2 = $[1];
93
- }
94
- const setShowMenu = t2;
95
- let t3;
96
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
97
- t3 = value_1 => {
98
- dispatch({
99
- type: "autocompleteSuggestion",
100
- payload: value_1
101
- });
102
- };
103
- $[2] = t3;
104
- } else {
105
- t3 = $[2];
106
- }
107
- const setAutocompleteSuggestion = t3;
108
- let t4;
109
- if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
110
- t4 = value_2 => {
111
- dispatch({
112
- type: "isMenuDirectlyActivated",
113
- payload: value_2
114
- });
115
- };
116
- $[3] = t4;
117
- } else {
118
- t4 = $[3];
119
- }
120
- const setIsMenuDirectlyActivated = t4;
121
- let t5;
122
- if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
123
- t5 = value_3 => {
124
- dispatch({
125
- type: "selectedItemLength",
126
- payload: value_3
127
- });
128
- };
129
- $[4] = t5;
130
- } else {
131
- t5 = $[4];
132
- }
133
- const setSelectedItemLength = t5;
134
- const id = useId(idProp);
135
- let t6;
136
- if ($[5] !== id || $[6] !== selectedItemLength || $[7] !== showMenu) {
137
- t6 = {
138
- activeDescendantRef,
139
- id,
140
- inputRef,
141
- scrollContainerRef,
142
- selectedItemLength,
143
- setAutocompleteSuggestion,
144
- setInputValue,
145
- setIsMenuDirectlyActivated,
146
- setShowMenu,
147
- setSelectedItemLength,
148
- showMenu
149
- };
150
- $[5] = id;
151
- $[6] = selectedItemLength;
152
- $[7] = showMenu;
153
- $[8] = t6;
154
- } else {
155
- t6 = $[8];
156
- }
157
- const autocompleteContextValue = t6;
158
- let t7;
159
- if ($[9] !== autocompleteSuggestion || $[10] !== inputValue || $[11] !== isMenuDirectlyActivated) {
160
- t7 = {
161
- autocompleteSuggestion,
162
- inputValue,
163
- isMenuDirectlyActivated
164
- };
165
- $[9] = autocompleteSuggestion;
166
- $[10] = inputValue;
167
- $[11] = isMenuDirectlyActivated;
168
- $[12] = t7;
169
- } else {
170
- t7 = $[12];
171
- }
172
- const autocompleteInputContextValue = t7;
173
- const deferredInputValue = useDeferredValue(inputValue);
174
- let t8;
175
- if ($[13] !== deferredInputValue) {
176
- t8 = {
177
- deferredInputValue
178
- };
179
- $[13] = deferredInputValue;
180
- $[14] = t8;
181
- } else {
182
- t8 = $[14];
183
- }
184
- const autocompleteDeferredInputContextValue = t8;
185
- let t9;
186
- if ($[15] !== autocompleteDeferredInputContextValue || $[16] !== children) {
187
- t9 = /*#__PURE__*/jsx(AutocompleteDeferredInputContext.Provider, {
188
- value: autocompleteDeferredInputContextValue,
189
- children: children
66
+ const setInputValue = useCallback(value => {
67
+ dispatch({
68
+ type: 'inputValue',
69
+ payload: value
190
70
  });
191
- $[15] = autocompleteDeferredInputContextValue;
192
- $[16] = children;
193
- $[17] = t9;
194
- } else {
195
- t9 = $[17];
196
- }
197
- let t10;
198
- if ($[18] !== autocompleteInputContextValue || $[19] !== t9) {
199
- t10 = /*#__PURE__*/jsx(AutocompleteInputContext.Provider, {
200
- value: autocompleteInputContextValue,
201
- children: t9
71
+ }, []);
72
+ const setShowMenu = useCallback(value => {
73
+ dispatch({
74
+ type: 'showMenu',
75
+ payload: value
202
76
  });
203
- $[18] = autocompleteInputContextValue;
204
- $[19] = t9;
205
- $[20] = t10;
206
- } else {
207
- t10 = $[20];
208
- }
209
- let t11;
210
- if ($[21] !== autocompleteContextValue || $[22] !== t10) {
211
- t11 = /*#__PURE__*/jsx(AutocompleteContext.Provider, {
212
- value: autocompleteContextValue,
213
- children: t10
77
+ }, []);
78
+ const setAutocompleteSuggestion = useCallback(value => {
79
+ dispatch({
80
+ type: 'autocompleteSuggestion',
81
+ payload: value
214
82
  });
215
- $[21] = autocompleteContextValue;
216
- $[22] = t10;
217
- $[23] = t11;
218
- } else {
219
- t11 = $[23];
220
- }
221
- return t11;
83
+ }, []);
84
+ const setIsMenuDirectlyActivated = useCallback(value => {
85
+ dispatch({
86
+ type: 'isMenuDirectlyActivated',
87
+ payload: value
88
+ });
89
+ }, []);
90
+ const setSelectedItemLength = useCallback(value => {
91
+ dispatch({
92
+ type: 'selectedItemLength',
93
+ payload: value
94
+ });
95
+ }, []);
96
+ const id = useId(idProp);
97
+
98
+ // Base context: refs, IDs, menu visibility, and callbacks
99
+ // Changes when menu opens/closes or selection changes, but NOT on every keystroke
100
+ const autocompleteContextValue = useMemo(() => ({
101
+ activeDescendantRef,
102
+ id,
103
+ inputRef,
104
+ scrollContainerRef,
105
+ selectedItemLength,
106
+ setAutocompleteSuggestion,
107
+ setInputValue,
108
+ setIsMenuDirectlyActivated,
109
+ setShowMenu,
110
+ setSelectedItemLength,
111
+ showMenu
112
+ }), [id, selectedItemLength, setAutocompleteSuggestion, setInputValue, setIsMenuDirectlyActivated, setShowMenu, setSelectedItemLength, showMenu]);
113
+
114
+ // Input state context: values that change on every keystroke
115
+ // Split to prevent Overlay from re-rendering during typing
116
+ const autocompleteInputContextValue = useMemo(() => ({
117
+ autocompleteSuggestion,
118
+ inputValue,
119
+ isMenuDirectlyActivated
120
+ }), [autocompleteSuggestion, inputValue, isMenuDirectlyActivated]);
121
+
122
+ // Deferred input value for expensive operations like filtering
123
+ // Menu subscribes to this instead of inputValue to avoid re-rendering on every keystroke
124
+ const deferredInputValue = useDeferredValue(inputValue);
125
+ const autocompleteDeferredInputContextValue = useMemo(() => ({
126
+ deferredInputValue
127
+ }), [deferredInputValue]);
128
+ return /*#__PURE__*/jsx(AutocompleteContext.Provider, {
129
+ value: autocompleteContextValue,
130
+ children: /*#__PURE__*/jsx(AutocompleteInputContext.Provider, {
131
+ value: autocompleteInputContextValue,
132
+ children: /*#__PURE__*/jsx(AutocompleteDeferredInputContext.Provider, {
133
+ value: autocompleteDeferredInputContextValue,
134
+ children: children
135
+ })
136
+ })
137
+ });
222
138
  };
139
+ Autocomplete.displayName = "Autocomplete";
223
140
  var Autocomplete$1 = Object.assign(Autocomplete, {
224
141
  __SLOT__: Symbol('Autocomplete'),
225
142
  Context: AutocompleteContext,