@primer/react 0.0.0-20260707213122 → 0.0.0-20260707214244

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,6 +1,6 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260707213122
3
+ ## 0.0.0-20260707214244
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -17,6 +17,8 @@
17
17
 
18
18
  ### Patch Changes
19
19
 
20
+ - [#8005](https://github.com/primer/react/pull/8005) [`5d24be4`](https://github.com/primer/react/commit/5d24be483f2fdfa305970907984d04522e2aa13c) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Derive `AutocompleteMenu` close-time re-sorting and `LabelGroup` numeric truncation during render instead of in effects, removing redundant render passes. No public API or visual changes.
21
+
20
22
  - Fake entry to force publishing
21
23
 
22
24
  - [#7901](https://github.com/primer/react/pull/7901) [`8288ed9`](https://github.com/primer/react/commit/8288ed9d88668f93cf3b1eb70ee61edac6217367) Thanks [@mattcosta7](https://github.com/mattcosta7)! - PageHeader: improve rendering performance by removing expensive `:has()` selectors. No visual or API changes.
@@ -25,8 +27,6 @@
25
27
 
26
28
  - [#8035](https://github.com/primer/react/pull/8035) [`723f4d6`](https://github.com/primer/react/commit/723f4d6db12710e2b94f56b945a937158fcbb127) Thanks [@mattcosta7](https://github.com/mattcosta7)! - UnderlineNav, ActionBar: Detect item overflow with a single shared IntersectionObserver per component instead of one observer per item, reducing observer churn during resize. No public API changes.
27
29
 
28
- - [#8001](https://github.com/primer/react/pull/8001) [`7358e8c`](https://github.com/primer/react/commit/7358e8ce22a000d0e0ce8d203c7c82d3f9360c8d) Thanks [@mattcosta7](https://github.com/mattcosta7)! - `useMedia` now reads the live `matchMedia` value on the first client render instead of after an effect, removing a redundant render pass. `defaultState` is only used for the SSR/hydration snapshot (no public API changes).
29
-
30
30
  ## 38.31.0
31
31
 
32
32
  ### Minor Changes
@@ -43,7 +43,7 @@ const debounceAnnouncement = debounce((announcement) => {
43
43
  announce(announcement);
44
44
  }, 250);
45
45
  function AutocompleteMenu(props) {
46
- const $ = c(78);
46
+ const $ = c(75);
47
47
  const autocompleteContext = useContext(AutocompleteContext);
48
48
  const deferredInputContext = useContext(AutocompleteDeferredInputContext);
49
49
  if (autocompleteContext === null || deferredInputContext === null) throw new Error("AutocompleteContext returned null values");
@@ -253,54 +253,46 @@ function AutocompleteMenu(props) {
253
253
  t16 = $[54];
254
254
  }
255
255
  useEffect(t15, t16);
256
+ if (showMenu === false) {
257
+ const itemIdSortResult = [...sortedItemIds].sort(sortOnCloseFn ? sortOnCloseFn : getDefaultSortFn((itemId_0) => isItemSelected(itemId_0, selectedItemIds)));
258
+ if (!(itemIdSortResult.length === sortedItemIds.length && itemIdSortResult.every((element_0, index) => element_0 === sortedItemIds[index]))) setSortedItemIds(itemIdSortResult);
259
+ }
256
260
  let t17;
257
261
  let t18;
258
- if ($[55] !== onOpenChange || $[56] !== selectedItemIds || $[57] !== showMenu || $[58] !== sortOnCloseFn || $[59] !== sortedItemIds) {
262
+ if ($[55] !== onOpenChange || $[56] !== showMenu) {
259
263
  t17 = () => {
260
- const itemIdSortResult = [...sortedItemIds].sort(sortOnCloseFn ? sortOnCloseFn : getDefaultSortFn((itemId_0) => isItemSelected(itemId_0, selectedItemIds)));
261
- const sortResultMatchesState = itemIdSortResult.length === sortedItemIds.length && itemIdSortResult.every((element_0, index) => element_0 === sortedItemIds[index]);
262
- if (showMenu === false && !sortResultMatchesState) setSortedItemIds(itemIdSortResult);
263
264
  onOpenChange && onOpenChange(Boolean(showMenu));
264
265
  };
265
- t18 = [
266
- showMenu,
267
- onOpenChange,
268
- selectedItemIds,
269
- sortOnCloseFn,
270
- sortedItemIds
271
- ];
266
+ t18 = [showMenu, onOpenChange];
272
267
  $[55] = onOpenChange;
273
- $[56] = selectedItemIds;
274
- $[57] = showMenu;
275
- $[58] = sortOnCloseFn;
276
- $[59] = sortedItemIds;
277
- $[60] = t17;
278
- $[61] = t18;
268
+ $[56] = showMenu;
269
+ $[57] = t17;
270
+ $[58] = t18;
279
271
  } else {
280
- t17 = $[60];
281
- t18 = $[61];
272
+ t17 = $[57];
273
+ t18 = $[58];
282
274
  }
283
275
  useEffect(t17, t18);
284
276
  let t19;
285
- if ($[62] !== selectedItemIds.length || $[63] !== setSelectedItemLength) {
277
+ if ($[59] !== selectedItemIds.length || $[60] !== setSelectedItemLength) {
286
278
  t19 = () => {
287
279
  if (selectedItemIds.length) setSelectedItemLength(selectedItemIds.length);
288
280
  };
289
- $[62] = selectedItemIds.length;
290
- $[63] = setSelectedItemLength;
291
- $[64] = t19;
292
- } else t19 = $[64];
281
+ $[59] = selectedItemIds.length;
282
+ $[60] = setSelectedItemLength;
283
+ $[61] = t19;
284
+ } else t19 = $[61];
293
285
  let t20;
294
- if ($[65] !== selectedItemIds || $[66] !== setSelectedItemLength) {
286
+ if ($[62] !== selectedItemIds || $[63] !== setSelectedItemLength) {
295
287
  t20 = [selectedItemIds, setSelectedItemLength];
296
- $[65] = selectedItemIds;
297
- $[66] = setSelectedItemLength;
298
- $[67] = t20;
299
- } else t20 = $[67];
288
+ $[62] = selectedItemIds;
289
+ $[63] = setSelectedItemLength;
290
+ $[64] = t20;
291
+ } else t20 = $[64];
300
292
  useEffect(t19, t20);
301
293
  if (selectionVariant === "single" && selectedItemIds.length > 1) throw new Error("Autocomplete: selectionVariant \"single\" cannot be used with multiple selected items");
302
294
  let t21;
303
- if ($[68] !== allItemsToRender || $[69] !== ariaLabelledBy || $[70] !== emptyStateText || $[71] !== id || $[72] !== loading || $[73] !== selectionVariant) {
295
+ if ($[65] !== allItemsToRender || $[66] !== ariaLabelledBy || $[67] !== emptyStateText || $[68] !== id || $[69] !== loading || $[70] !== selectionVariant) {
304
296
  t21 = loading ? /*#__PURE__*/ jsx("div", {
305
297
  className: AutocompleteMenu_module_css_default.SpinnerWrapper,
306
298
  children: /*#__PURE__*/ jsx(Spinner, {})
@@ -318,24 +310,24 @@ function AutocompleteMenu(props) {
318
310
  children: emptyStateText
319
311
  }) : null
320
312
  });
321
- $[68] = allItemsToRender;
322
- $[69] = ariaLabelledBy;
323
- $[70] = emptyStateText;
324
- $[71] = id;
325
- $[72] = loading;
326
- $[73] = selectionVariant;
327
- $[74] = t21;
328
- } else t21 = $[74];
313
+ $[65] = allItemsToRender;
314
+ $[66] = ariaLabelledBy;
315
+ $[67] = emptyStateText;
316
+ $[68] = id;
317
+ $[69] = loading;
318
+ $[70] = selectionVariant;
319
+ $[71] = t21;
320
+ } else t21 = $[71];
329
321
  let t22;
330
- if ($[75] !== showMenu || $[76] !== t21) {
322
+ if ($[72] !== showMenu || $[73] !== t21) {
331
323
  t22 = /*#__PURE__*/ jsx(VisuallyHidden, {
332
324
  isVisible: showMenu,
333
325
  children: t21
334
326
  });
335
- $[75] = showMenu;
336
- $[76] = t21;
337
- $[77] = t22;
338
- } else t22 = $[77];
327
+ $[72] = showMenu;
328
+ $[73] = t21;
329
+ $[74] = t22;
330
+ } else t22 = $[74];
339
331
  return t22;
340
332
  }
341
333
  function _temp5(item_2) {
@@ -14,6 +14,16 @@ const getOverlayWidth = (buttonClientRect, containerRef, overlayPaddingPx) => {
14
14
  var _containerRef$current;
15
15
  return overlayPaddingPx + buttonClientRect.right - (((_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.getBoundingClientRect().left) || 0);
16
16
  };
17
+ const getVisibilityMapAfterIndex = (childCount, truncateAfter) => {
18
+ const updatedEntries = {};
19
+ for (let index = 0; index < childCount; index++) updatedEntries[index.toString()] = index < truncateAfter;
20
+ return updatedEntries;
21
+ };
22
+ const visibilityMapsMatch = (left, right) => {
23
+ const leftKeys = Object.keys(left);
24
+ const rightKeys = Object.keys(right);
25
+ return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.prototype.hasOwnProperty.call(right, key) && left[key] === right[key]);
26
+ };
17
27
  const InlineToggle = (t0) => {
18
28
  const $ = c(7);
19
29
  const { collapseButtonRef, collapseInlineExpandedChildren, expandButtonRef, hiddenItemIds, isOverflowShown, showAllTokensInline } = t0;
@@ -133,6 +143,7 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
133
143
  bottom: 0,
134
144
  toJSON: () => void 0
135
145
  });
146
+ const childArray = React.Children.toArray(children);
136
147
  const overlayPaddingPx = 8;
137
148
  const hiddenItemIds = Object.keys(visibilityMap).filter((key) => !visibilityMap[key]);
138
149
  const overlayWidth = hiddenItemIds.length && overflowStyle === "overlay" ? getOverlayWidth(buttonClientRect, containerRef, overlayPaddingPx) : void 0;
@@ -144,15 +155,8 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
144
155
  }
145
156
  }, [buttonClientRect]);
146
157
  const hideChildrenAfterIndex = React.useCallback((truncateAfter) => {
147
- var _containerRef$current2;
148
- const containerChildren = ((_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children) || [];
149
- const updatedEntries = {};
150
- for (const child of containerChildren) {
151
- const targetId = child.getAttribute("data-index");
152
- if (targetId) updatedEntries[targetId] = parseInt(targetId, 10) < truncateAfter;
153
- }
154
- setVisibilityMap(updatedEntries);
155
- }, []);
158
+ setVisibilityMap(getVisibilityMapAfterIndex(childArray.length, truncateAfter));
159
+ }, [childArray.length]);
156
160
  const openOverflowOverlay = React.useCallback(() => setIsOverflowShown(true), [setIsOverflowShown]);
157
161
  const closeOverflowOverlay = React.useCallback(() => {
158
162
  setIsOverflowShown(false);
@@ -173,34 +177,39 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
173
177
  setVisibilityMap({});
174
178
  setIsOverflowShown(true);
175
179
  }, [setVisibilityMap, setIsOverflowShown]);
180
+ const numericVisibilityMap = React.useMemo(() => visibleChildCount && typeof visibleChildCount === "number" && !isOverflowShown ? getVisibilityMapAfterIndex(childArray.length, visibleChildCount) : void 0, [
181
+ childArray.length,
182
+ isOverflowShown,
183
+ visibleChildCount
184
+ ]);
185
+ if (numericVisibilityMap && !visibilityMapsMatch(visibilityMap, numericVisibilityMap)) setVisibilityMap(numericVisibilityMap);
176
186
  React.useEffect(() => {
177
187
  if (!visibleChildCount || isOverflowShown) return;
178
188
  if (visibleChildCount === "auto") {
179
189
  const observer = new IntersectionObserver((entries) => {
180
- const updatedEntries_0 = {};
190
+ const updatedEntries = {};
181
191
  for (const entry of entries) {
182
- const targetId_0 = entry.target.getAttribute("data-index");
183
- if (targetId_0) updatedEntries_0[targetId_0] = entry.isIntersecting;
192
+ const targetId = entry.target.getAttribute("data-index");
193
+ if (targetId) updatedEntries[targetId] = entry.isIntersecting;
184
194
  }
185
195
  setVisibilityMap((prev) => ({
186
196
  ...prev,
187
- ...updatedEntries_0
197
+ ...updatedEntries
188
198
  }));
189
199
  }, {
190
200
  root: containerRef.current,
191
201
  rootMargin: `0px -${buttonClientRect.width}px 0px 0px`,
192
202
  threshold: 1
193
203
  });
194
- for (const item of ((_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.children) || []) {
195
- var _containerRef$current3;
204
+ for (const item of ((_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children) || []) {
205
+ var _containerRef$current2;
196
206
  if (item.getAttribute("data-index")) observer.observe(item);
197
207
  }
198
208
  return () => observer.disconnect();
199
- } else hideChildrenAfterIndex(visibleChildCount);
209
+ }
200
210
  }, [
201
211
  buttonClientRect,
202
212
  visibleChildCount,
203
- hideChildrenAfterIndex,
204
213
  isOverflowShown
205
214
  ]);
206
215
  React.useEffect(() => {
@@ -230,10 +239,10 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
230
239
  "data-list": isList || void 0,
231
240
  className: clsx(className, LabelGroup_module_css_default.Container),
232
241
  "data-component": "LabelGroup",
233
- children: [React.Children.map(children, (child_0, index) => /*#__PURE__*/ jsx(ItemWrapperComponent, {
242
+ children: [childArray.map((child, index) => /*#__PURE__*/ jsx(ItemWrapperComponent, {
234
243
  "data-index": index,
235
244
  className: clsx(LabelGroup_module_css_default.ItemWrapper, { [LabelGroup_module_css_default["ItemWrapper--hidden"]]: hiddenItemIds.includes(index.toString()) }),
236
- children: child_0
245
+ children: child
237
246
  }, index)), /*#__PURE__*/ jsx(ToggleWrapper, {
238
247
  "data-component": "LabelGroup.Toggle",
239
248
  children: overflowStyle === "inline" ? /*#__PURE__*/ jsx(InlineToggle, {
@@ -243,7 +252,7 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
243
252
  hiddenItemIds,
244
253
  isOverflowShown,
245
254
  showAllTokensInline,
246
- totalLength: React.Children.toArray(children).length
255
+ totalLength: childArray.length
247
256
  }) : /*#__PURE__*/ jsx(OverlayToggle, {
248
257
  closeOverflowOverlay,
249
258
  expandButtonRef,
@@ -252,7 +261,7 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
252
261
  openOverflowOverlay,
253
262
  overlayPaddingPx,
254
263
  overlayWidth,
255
- totalLength: React.Children.toArray(children).length,
264
+ totalLength: childArray.length,
256
265
  children
257
266
  })
258
267
  })]
@@ -261,8 +270,8 @@ const LabelGroup = ({ children, visibleChildCount, overflowStyle = "overlay", as
261
270
  "data-list": isList || void 0,
262
271
  className: clsx(className, LabelGroup_module_css_default.Container),
263
272
  "data-component": "LabelGroup",
264
- children: isList ? React.Children.map(children, (child_1, index_0) => {
265
- return /*#__PURE__*/ jsx("li", { children: child_1 }, index_0);
273
+ children: isList ? React.Children.map(children, (child_0, index_0) => {
274
+ return /*#__PURE__*/ jsx("li", { children: child_0 }, index_0);
266
275
  }) : children
267
276
  });
268
277
  };
@@ -1,7 +1,8 @@
1
+ import { canUseDOM } from "../utils/environment.js";
1
2
  import { warning } from "../utils/warning.js";
2
3
  import { MatchMediaContext } from "./MatchMediaContext.js";
3
4
  import { c } from "react-compiler-runtime";
4
- import { useContext, useSyncExternalStore } from "react";
5
+ import React, { useContext, useEffect } from "react";
5
6
  //#region src/hooks/useMedia.ts
6
7
  /**
7
8
  * `useMedia` will use the given `mediaQueryString` with `matchMedia` to
@@ -17,54 +18,52 @@ import { useContext, useSyncExternalStore } from "react";
17
18
  * }
18
19
  */
19
20
  function useMedia(mediaQueryString, defaultState) {
20
- const $ = c(9);
21
- const contextValue = useContext(MatchMediaContext)[mediaQueryString];
21
+ const $ = c(8);
22
+ const features = useContext(MatchMediaContext);
22
23
  let t0;
23
- if ($[0] !== contextValue || $[1] !== mediaQueryString) {
24
- t0 = (onStoreChange) => {
25
- if (contextValue !== void 0) return _temp;
26
- const mediaQueryList = window.matchMedia(mediaQueryString);
27
- if (mediaQueryList.addEventListener) {
28
- mediaQueryList.addEventListener("change", onStoreChange);
29
- return () => {
30
- mediaQueryList.removeEventListener("change", onStoreChange);
31
- };
32
- }
33
- mediaQueryList.addListener(onStoreChange);
34
- return () => {
35
- mediaQueryList.removeListener(onStoreChange);
36
- };
24
+ if ($[0] !== defaultState || $[1] !== features || $[2] !== mediaQueryString) {
25
+ t0 = () => {
26
+ if (features[mediaQueryString] !== void 0) return features[mediaQueryString];
27
+ if (defaultState !== void 0) return defaultState;
28
+ if (canUseDOM) return window.matchMedia(mediaQueryString).matches;
29
+ warning(true, "`useMedia` When server side rendering, defaultState should be defined to prevent a hydration mismatches.");
30
+ return false;
37
31
  };
38
- $[0] = contextValue;
39
- $[1] = mediaQueryString;
40
- $[2] = t0;
41
- } else t0 = $[2];
42
- const subscribe = t0;
32
+ $[0] = defaultState;
33
+ $[1] = features;
34
+ $[2] = mediaQueryString;
35
+ $[3] = t0;
36
+ } else t0 = $[3];
37
+ const [matches, setMatches] = React.useState(t0);
38
+ if (features[mediaQueryString] !== void 0 && matches !== features[mediaQueryString]) setMatches(features[mediaQueryString]);
43
39
  let t1;
44
- if ($[3] !== contextValue || $[4] !== mediaQueryString) {
45
- t1 = () => {
46
- if (contextValue !== void 0) return contextValue;
47
- return window.matchMedia(mediaQueryString).matches;
48
- };
49
- $[3] = contextValue;
50
- $[4] = mediaQueryString;
51
- $[5] = t1;
52
- } else t1 = $[5];
53
- const getSnapshot = t1;
54
40
  let t2;
55
- if ($[6] !== contextValue || $[7] !== defaultState) {
56
- t2 = () => {
57
- if (contextValue !== void 0) return contextValue;
58
- if (defaultState !== void 0) return defaultState;
59
- warning(typeof window === "undefined", "`useMedia` When server side rendering, defaultState should be defined to prevent a hydration mismatches.");
60
- return false;
41
+ if ($[4] !== features || $[5] !== mediaQueryString) {
42
+ t1 = () => {
43
+ if (features[mediaQueryString] !== void 0) return;
44
+ const listener = function listener(event) {
45
+ setMatches(event.matches);
46
+ };
47
+ const mediaQueryList = window.matchMedia(mediaQueryString);
48
+ if (mediaQueryList.addEventListener) mediaQueryList.addEventListener("change", listener);
49
+ else mediaQueryList.addListener(listener);
50
+ setMatches(mediaQueryList.matches);
51
+ return () => {
52
+ if (mediaQueryList.addEventListener) mediaQueryList.removeEventListener("change", listener);
53
+ else mediaQueryList.removeListener(listener);
54
+ };
61
55
  };
62
- $[6] = contextValue;
63
- $[7] = defaultState;
64
- $[8] = t2;
65
- } else t2 = $[8];
66
- return useSyncExternalStore(subscribe, getSnapshot, t2);
56
+ t2 = [features, mediaQueryString];
57
+ $[4] = features;
58
+ $[5] = mediaQueryString;
59
+ $[6] = t1;
60
+ $[7] = t2;
61
+ } else {
62
+ t1 = $[6];
63
+ t2 = $[7];
64
+ }
65
+ useEffect(t1, t2);
66
+ return matches;
67
67
  }
68
- function _temp() {}
69
68
  //#endregion
70
69
  export { useMedia };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260707213122",
4
+ "version": "0.0.0-20260707214244",
5
5
  "description": "An implementation of GitHub's Primer Design System using React",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",