@primer/react 0.0.0-20260526014931 → 0.0.0-20260526182004

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,11 +1,48 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260526014931
3
+ ## 0.0.0-20260526182004
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - [#7864](https://github.com/primer/react/pull/7864) [`e7205ea`](https://github.com/primer/react/commit/e7205ea51b02fb1b7ac9de2df122f7ba67ebe078) Thanks [@mattcosta7](https://github.com/mattcosta7)! - Eliminate nested-update cascades in `useFocus`, `PageLayout.Pane`, and
8
+ `AnchoredOverlay`:
9
+
10
+ - `useFocus` no longer produces a second re-render after focusing; one
11
+ `focus()` call now results in exactly one render instead of two.
12
+ - `PageLayout.Pane` (resizable) no longer triggers a forced re-render
13
+ before paint on mount. The CSS variable and ARIA attributes are still
14
+ updated synchronously in the layout effect; the React state sync is
15
+ wrapped in `startTransition` so it runs in the transition lane rather
16
+ than as part of the layout-effect commit.
17
+ - `AnchoredOverlay` no longer keeps `useAnchoredPosition`'s scroll
18
+ listeners and `ResizeObserver` attached while it is closed. After an
19
+ open→close cycle, the first scroll/resize event no longer fires a
20
+ spurious `setPosition(undefined)` that re-renders the closed overlay.
21
+
22
+ Also adds a profiler-based test harness at
23
+ `src/utils/testing/profiler.tsx` so future regressions can be pinned with
24
+ `counter.updateCount` and `counter.nestedUpdateCount` assertions.
25
+
7
26
  - Fake entry to force publishing
8
27
 
28
+ - [#7875](https://github.com/primer/react/pull/7875) [`1fcc071`](https://github.com/primer/react/commit/1fcc071865a6b9b06988a84864f20a3faa9d523d) Thanks [@mattcosta7](https://github.com/mattcosta7)! - UnderlineNav: Re-architect item measurement to remove a cascading render on
29
+ mount. Each `UnderlineNav.Item` no longer dispatches measurement setState calls
30
+ back into its parent via context; `UnderlineNav` now walks its rendered items
31
+ in a single layout effect and stores widths in refs. Overflow state is
32
+ consolidated into one `useState` object (one commit per change), the context
33
+ value is memoized, `UnderlineNav.Item` is wrapped in `React.memo`, and the
34
+ external-`aria-current` swap was moved out of render-phase setState into a
35
+ layout effect. Behavior is unchanged for consumers, but the initial mount and
36
+ overflow-state transitions produce far fewer per-item renders.
37
+
38
+ - [#7874](https://github.com/primer/react/pull/7874) [`8cc7e99`](https://github.com/primer/react/commit/8cc7e998d2dbde1fb927b598755810b534702a6a) Thanks [@mattcosta7](https://github.com/mattcosta7)! - Dev-only effects (the `if (__DEV__) { useEffect(...) }` pattern with an
39
+ `eslint-disable react-hooks/rules-of-hooks` comment at every call site) are
40
+ now expressed via a new internal `useDevOnlyEffect` hook. The lint
41
+ suppression lives in the wrapper, the effect is dropped from production by
42
+ the consumer's `process.env.NODE_ENV` replacement, and call sites get
43
+ `react-hooks/exhaustive-deps` lint via `additionalEffectHooks`. No public
44
+ API changes.
45
+
9
46
  ## 38.25.0
10
47
 
11
48
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"AnchoredOverlay.d.ts","sourceRoot":"","sources":["../../src/AnchoredOverlay/AnchoredOverlay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAmC,KAAK,GAAG,EAAC,MAAM,OAAO,CAAA;AAChE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAA;AAEhE,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAA;AAIhE,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAC,KAAK,eAAe,EAAC,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAa,KAAK,eAAe,EAAC,MAAM,WAAW,CAAA;AAO1D,UAAU,8BAA8B;IACtC;;;OAGG;IACH,YAAY,EAAE,CAA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C,CAAA;IAEpC;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAA;IAElD;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAA;IAElD;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,YAAY,CAAC,CAAA;IAChE;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,EAAC,QAAQ,EAAC,EAAE;QAAC,QAAQ,EAAE,cAAc,CAAA;KAAC,KAAK,IAAI,CAAA;IACnE;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;IAC3C;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;CAChC;AAED,MAAM,MAAM,oBAAoB,GAAG,wBAAwB,GACzD,CAAC,8BAA8B,GAAG,iCAAiC,CAAC,GACpE,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,MAAM,GAAG,cAAc,GAAG,iBAAiB,GAAG,mBAAmB,CAAC,CAAC,CAAA;AAS9G;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAuRnF,CAAA"}
@@ -110,10 +110,13 @@ const AnchoredOverlay = ({
110
110
  anchorOffset,
111
111
  displayInViewport,
112
112
  onPositionChange: positionChange,
113
- // When native CSS anchor positioning is active, skip JS-based position
114
- // computation, scroll listeners, and resize observers since the browser
115
- // handles repositioning natively.
116
- enabled: !cssAnchorPositioning
113
+ // Disable position computation, scroll listeners, and resize observers
114
+ // when the overlay is closed (no floating element to position) or when
115
+ // native CSS anchor positioning is active (the browser handles it).
116
+ // Skipping the listeners while closed avoids a wasted re-render on the
117
+ // first scroll/resize after a close (where `setPosition(undefined)`
118
+ // would otherwise clear the stale open-position state).
119
+ enabled: open && !cssAnchorPositioning
117
120
  }, [overlayElement]);
118
121
  useEffect(() => {
119
122
  // ensure overlay ref gets cleared when closed, so position can reset between closing/re-opening
@@ -1 +1 @@
1
- {"version":3,"file":"Banner.d.ts","sourceRoot":"","sources":["../../src/Banner/Banner.tsx"],"names":[],"mappings":"AACA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAElD,OAAO,EAAqB,KAAK,WAAW,EAAC,MAAM,WAAW,CAAA;AAK9D,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAE/F,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAA;AAQlF,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,wBAAwB,CAAC,SAAS,CAAC,GAAG;IACpE;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAE7B;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;;OAGG;IACH,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAEtB;;OAEG;IACH,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAE/B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IAEtB;;OAEG;IACH,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAE/B;;OAEG;IACH,eAAe,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAEjC;;;OAG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-1,5 +1,6 @@
1
1
  import { clsx } from 'clsx';
2
- import React, { useEffect, forwardRef } from 'react';
2
+ import React, { forwardRef } from 'react';
3
+ import { useDevOnlyEffect } from '../internal/hooks/useDevOnlyEffect.js';
3
4
  import { XIcon, AlertIcon, InfoIcon, CheckCircleIcon, StopIcon } from '@primer/octicons-react';
4
5
  import { IconButton } from '../Button/IconButton.js';
5
6
  import { ButtonComponent } from '../Button/Button.js';
@@ -42,25 +43,21 @@ const Banner = /*#__PURE__*/React.forwardRef(function Banner({
42
43
  const supportsCustomIcon = variant === 'info' || variant === 'upsell';
43
44
  const titleId = useId();
44
45
  const visual = leadingVisual !== null && leadingVisual !== void 0 ? leadingVisual : icon;
45
- if (process.env.NODE_ENV !== "production") {
46
- // This hook is called consistently depending on the environment
47
- // eslint-disable-next-line react-hooks/rules-of-hooks
48
- useEffect(() => {
49
- if (title) {
50
- return;
51
- }
52
- const {
53
- current: banner
54
- } = bannerRef;
55
- if (!banner) {
56
- return;
57
- }
58
- const hasTitle = banner.querySelector('[data-banner-title]');
59
- if (!hasTitle) {
60
- throw new Error('Expected a title to be provided to the <Banner> component with the `title` prop or through `<Banner.Title>` but no title was found');
61
- }
62
- }, [title]);
63
- }
46
+ useDevOnlyEffect(() => {
47
+ if (title) {
48
+ return;
49
+ }
50
+ const {
51
+ current: banner
52
+ } = bannerRef;
53
+ if (!banner) {
54
+ return;
55
+ }
56
+ const hasTitle = banner.querySelector('[data-banner-title]');
57
+ if (!hasTitle) {
58
+ throw new Error('Expected a title to be provided to the <Banner> component with the `title` prop or through `<Banner.Title>` but no title was found');
59
+ }
60
+ }, [title]);
64
61
  return /*#__PURE__*/jsx(BannerContext.Provider, {
65
62
  value: {
66
63
  titleId
@@ -1 +1 @@
1
- {"version":3,"file":"Heading.d.ts","sourceRoot":"","sources":["../../src/Heading/Heading.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAG/F,KAAK,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAE5D,KAAK,kBAAkB,GAAG;IACxB,EAAE,CAAC,EAAE,aAAa,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;CACvC,CAAA;AAED,QAAA,MAAM,OAAO,EA6BP,8BAA8B,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAA;AAIvE,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,OAAO,CAAC,CAAA;AACzD,eAAe,OAAO,CAAA"}
1
+ {"version":3,"file":"Heading.d.ts","sourceRoot":"","sources":["../../src/Heading/Heading.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAG/F,KAAK,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAE5D,KAAK,kBAAkB,GAAG;IACxB,EAAE,CAAC,EAAE,aAAa,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;CACvC,CAAA;AAED,QAAA,MAAM,OAAO,EAoBP,8BAA8B,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAA;AAIvE,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,OAAO,CAAC,CAAA;AACzD,eAAe,OAAO,CAAA"}
@@ -1,5 +1,6 @@
1
1
  import { clsx } from 'clsx';
2
- import React, { forwardRef, useEffect } from 'react';
2
+ import React, { forwardRef } from 'react';
3
+ import { useDevOnlyEffect } from '../internal/hooks/useDevOnlyEffect.js';
3
4
  import classes from './Heading.module.css.js';
4
5
  import { jsx } from 'react/jsx-runtime';
5
6
  import { useMergedRefs } from '../hooks/useMergedRefs.js';
@@ -12,21 +13,12 @@ const Heading = /*#__PURE__*/forwardRef(({
12
13
  }, forwardedRef) => {
13
14
  const innerRef = React.useRef(null);
14
15
  const mergedRef = useMergedRefs(forwardedRef, innerRef);
15
- if (process.env.NODE_ENV !== "production") {
16
- /**
17
- * The Linter yells because it thinks this conditionally calls an effect,
18
- * but since this is a compile-time flag and not a runtime conditional
19
- * this is safe, and ensures the entire effect is kept out of prod builds
20
- * shaving precious bytes from the output, and avoiding mounting a noop effect
21
- */
22
- // eslint-disable-next-line react-hooks/rules-of-hooks
23
- useEffect(() => {
24
- if (innerRef.current && !(innerRef.current instanceof HTMLHeadingElement)) {
25
- // eslint-disable-next-line no-console
26
- console.warn('This Heading component should be an instanceof of h1-h6');
27
- }
28
- }, [innerRef]);
29
- }
16
+ useDevOnlyEffect(() => {
17
+ if (innerRef.current && !(innerRef.current instanceof HTMLHeadingElement)) {
18
+ // eslint-disable-next-line no-console
19
+ console.warn('This Heading component should be an instanceof of h1-h6');
20
+ }
21
+ }, [innerRef]);
30
22
  return /*#__PURE__*/jsx(Component, {
31
23
  className: clsx(className, classes.Heading),
32
24
  "data-variant": variant,
@@ -1 +1 @@
1
- {"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../src/Link/Link.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAA;AAG1E,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAC,KAAK,gBAAgB,EAAkB,MAAM,6BAA6B,CAAA;AAElF,KAAK,eAAe,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,GAAG,IAAI;IACzD,EAAE,CAAC,EAAE,EAAE,CAAA;IACP,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAA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C,OAAO,IAAI,CAAC,CAAA;AACnD,eAAe,IAAI,CAAA"}
package/dist/Link/Link.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { clsx } from 'clsx';
2
- import React, { useEffect } from 'react';
2
+ import React from 'react';
3
+ import { useDevOnlyEffect } from '../internal/hooks/useDevOnlyEffect.js';
3
4
  import classes from './Link.module.css.js';
4
5
  import { fixedForwardRef } from '../utils/modern-polymorphic.js';
5
6
  import { jsx } from 'react/jsx-runtime';
@@ -16,21 +17,12 @@ const UnwrappedLink = (props, ref) => {
16
17
  } = props;
17
18
  const innerRef = React.useRef(null);
18
19
  const mergedRef = useMergedRefs(ref, innerRef);
19
- if (process.env.NODE_ENV !== "production") {
20
- /**
21
- * The Linter yells because it thinks this conditionally calls an effect,
22
- * but since this is a compile-time flag and not a runtime conditional
23
- * this is safe, and ensures the entire effect is kept out of prod builds
24
- * shaving precious bytes from the output, and avoiding mounting a noop effect
25
- */
26
- // eslint-disable-next-line react-hooks/rules-of-hooks
27
- useEffect(() => {
28
- if (innerRef.current && !(innerRef.current instanceof HTMLButtonElement) && !(innerRef.current instanceof HTMLAnchorElement)) {
29
- // eslint-disable-next-line no-console
30
- console.error('Error: Found `Link` component that renders an inaccessible element', innerRef.current, 'Please ensure `Link` always renders as <a> or <button>');
31
- }
32
- }, [innerRef]);
33
- }
20
+ useDevOnlyEffect(() => {
21
+ if (innerRef.current && !(innerRef.current instanceof HTMLButtonElement) && !(innerRef.current instanceof HTMLAnchorElement)) {
22
+ // eslint-disable-next-line no-console
23
+ console.error('Error: Found `Link` component that renders an inaccessible element', innerRef.current, 'Please ensure `Link` always renders as <a> or <button>');
24
+ }
25
+ }, [innerRef]);
34
26
  return /*#__PURE__*/jsx(Component, {
35
27
  className: clsx(className, classes.Link),
36
28
  "data-component": "Link",
@@ -1 +1 @@
1
- {"version":3,"file":"usePaneWidth.d.ts","sourceRoot":"","sources":["../../src/PageLayout/usePaneWidth.ts"],"names":[],"mappings":"AAAA,OAAO,KAA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
351
351
  const initialMax = getMaxPaneWidthRef.current();
352
352
  maxPaneWidthRef.current = initialMax;
353
- setMaxPaneWidth(initialMax);
354
353
  (_paneRef$current3 = paneRef.current) === null || _paneRef$current3 === void 0 ? void 0 : _paneRef$current3.style.setProperty("--pane-max-width", `${initialMax}px`);
355
354
  updateAriaValues(handleRef.current, {
356
355
  min: minPaneWidth,
357
356
  max: initialMax,
358
357
  current: currentWidthRef.current
359
358
  });
359
+ startTransition(() => {
360
+ setMaxPaneWidth(initialMax);
361
+ });
360
362
  if (customMaxWidth !== null && !constrainToViewport) {
361
363
  return;
362
364
  }
@@ -15,7 +15,5 @@ export type UnderlineNavProps = {
15
15
  */
16
16
  variant?: 'inset' | 'flush';
17
17
  };
18
- export declare const MORE_BTN_WIDTH = 86;
19
- export declare const getValidChildren: (children: React.ReactNode) => React.ReactElement<any>[];
20
18
  export declare const UnderlineNav: React.ForwardRefExoticComponent<UnderlineNavProps & React.RefAttributes<unknown>>;
21
19
  //# sourceMappingURL=UnderlineNav.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UnderlineNav.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNav.tsx"],"names":[],"mappings":"AACA,OAAO,KAA6D,MAAM,OAAO,CAAA;AAmBjF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;IACjD,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;CAC5B,CAAA;AAGD,eAAO,MAAM,cAAc,KAAK,CAAA;AAwEhC,eAAO,MAAM,gBAAgB,GAAI,UAAU,KAAK,CAAC,SAAS,KAEgC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,EAChH,CAAA;AAgCD,eAAO,MAAM,YAAY,mFA8SxB,CAAA"}
1
+ {"version":3,"file":"UnderlineNav.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNav.tsx"],"names":[],"mappings":"AACA,OAAO,KAA2D,MAAM,OAAO,CAAA;AAqB/E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;IACjD,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;CAC5B,CAAA;AAkHD,eAAO,MAAM,YAAY,mFA2ZxB,CAAA"}
@@ -1,8 +1,10 @@
1
- import React, { forwardRef, useRef, useState, useEffect, useCallback } from 'react';
1
+ import React, { forwardRef, useRef, useState, useCallback, useMemo } from 'react';
2
+ import { useDevOnlyEffect } from '../internal/hooks/useDevOnlyEffect.js';
2
3
  import { UnderlineNavContext } from './UnderlineNavContext.js';
3
4
  import { useResizeObserver } from '../hooks/useResizeObserver.js';
5
+ import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
4
6
  import VisuallyHidden from '../_VisuallyHidden.js';
5
- import { dividerStyles, baseMenuMinWidth, menuItemStyles } from './styles.js';
7
+ import { baseMenuMinWidth, dividerStyles, menuItemStyles } from './styles.js';
6
8
  import { UnderlineWrapper, UnderlineItemList, LoadingCounter, GAP } from '../internal/components/UnderlineTabbedInterface.js';
7
9
  import { TriangleDownIcon } from '@primer/octicons-react';
8
10
  import { useOnEscapePress } from '../hooks/useOnEscapePress.js';
@@ -21,19 +23,19 @@ import CounterLabel from '../CounterLabel/CounterLabel.js';
21
23
  const MORE_BTN_WIDTH = 86;
22
24
  // The height is needed to make sure we don't have a layout shift when the more button is the only item in the nav.
23
25
  const MORE_BTN_HEIGHT = 45;
24
- const overflowEffect = (navWidth, moreMenuWidth, childArray, childWidthArray, noIconChildWidthArray, updateListAndMenu) => {
26
+ const computeOverflow = (navWidth, moreMenuWidth, childArray, childWidths, noIconChildWidths) => {
25
27
  let iconsVisible = true;
26
- if (childWidthArray.length === 0) {
27
- updateListAndMenu({
28
+ if (childWidths.size === 0) {
29
+ return {
28
30
  items: childArray,
29
- menuItems: []
30
- }, iconsVisible, false);
31
- return;
31
+ menuItems: [],
32
+ iconsVisible
33
+ };
32
34
  }
33
- const numberOfItemsPossible = calculatePossibleItems(childWidthArray, navWidth);
34
- const numberOfItemsWithoutIconPossible = calculatePossibleItems(noIconChildWidthArray, navWidth);
35
+ const numberOfItemsPossible = calculatePossibleItems(childArray, childWidths, navWidth);
36
+ const numberOfItemsWithoutIconPossible = calculatePossibleItems(childArray, noIconChildWidths, navWidth);
35
37
  // We need to take more menu width into account when calculating the number of items possible
36
- const numberOfItemsPossibleWithMoreMenu = calculatePossibleItems(noIconChildWidthArray, navWidth, moreMenuWidth || MORE_BTN_WIDTH);
38
+ const numberOfItemsPossibleWithMoreMenu = calculatePossibleItems(childArray, noIconChildWidths, navWidth, moreMenuWidth || MORE_BTN_WIDTH);
37
39
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
40
  const items = [];
39
41
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -76,26 +78,27 @@ const overflowEffect = (navWidth, moreMenuWidth, childArray, childWidthArray, no
76
78
  }
77
79
  }
78
80
  }
79
- updateListAndMenu({
81
+ return {
80
82
  items,
81
- menuItems
82
- }, iconsVisible, true);
83
+ menuItems,
84
+ iconsVisible
85
+ };
83
86
  };
84
87
  const getValidChildren = children => {
85
88
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
89
  return React.Children.toArray(children).filter(child => /*#__PURE__*/React.isValidElement(child));
87
90
  };
88
- const calculatePossibleItems = (childWidthArray, navWidth, moreMenuWidth = 0) => {
91
+ const calculatePossibleItems = (childArray, widthMap, navWidth, moreMenuWidth = 0) => {
89
92
  const widthToFit = navWidth - moreMenuWidth;
90
- let breakpoint = childWidthArray.length; // assume all items will fit
93
+ let breakpoint = childArray.length; // assume all items will fit
91
94
  let sumsOfChildWidth = 0;
92
- for (const [index, childWidth] of childWidthArray.entries()) {
93
- sumsOfChildWidth = sumsOfChildWidth + childWidth.width + GAP;
95
+ for (const [index, child] of childArray.entries()) {
96
+ var _widthMap$get;
97
+ const width = (_widthMap$get = widthMap.get(String(child.key))) !== null && _widthMap$get !== void 0 ? _widthMap$get : 0;
98
+ sumsOfChildWidth = sumsOfChildWidth + width + GAP;
94
99
  if (sumsOfChildWidth > widthToFit) {
95
100
  breakpoint = index;
96
101
  break;
97
- } else {
98
- continue;
99
102
  }
100
103
  }
101
104
  return breakpoint;
@@ -122,7 +125,6 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
122
125
  className,
123
126
  children
124
127
  }, forwardedRef) => {
125
- var _listRef$current2;
126
128
  const backupRef = useRef(null);
127
129
  const navRef = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
128
130
  const listRef = useRef(null);
@@ -131,104 +133,217 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
131
133
  const containerRef = React.useRef(null);
132
134
  const disclosureWidgetId = useId();
133
135
  const [isWidgetOpen, setIsWidgetOpen] = useState(false);
134
- const [iconsVisible, setIconsVisible] = useState(true);
135
- const [childWidthArray, setChildWidthArray] = useState([]);
136
- const [noIconChildWidthArray, setNoIconChildWidthArray] = useState([]);
137
- // Track whether the initial overflow calculation is complete to prevent CLS
138
- const [isOverflowMeasured, setIsOverflowMeasured] = useState(false);
136
+ // Measurement results are stored in refs because only `computeOverflow` reads them;
137
+ // they should not trigger re-renders. Keyed by `String(element.key)` so lookups
138
+ // are O(1) and survive non-string item children.
139
+ const childWidthsRef = useRef(new Map());
140
+ const noIconChildWidthsRef = useRef(new Map());
139
141
  const validChildren = getValidChildren(children);
142
+ // Stable signature of the children list — when it changes we re-run the
143
+ // measurement pass with all items rendered (with icons) in the list. The
144
+ // delimiter is U+0000 (NUL) because React rejects NUL inside element keys,
145
+ // so consumer-provided keys cannot collide with the separator.
146
+ const childrenKey = validChildren.map(c => String(c.key)).join('\u0000');
147
+
148
+ // Single consolidated overflow state. Bundling `items`, `menuItems`,
149
+ // `iconsVisible`, `measured`, and `childrenKey` together means every
150
+ // overflow update — measurement, swap, resize, or children-change reset —
151
+ // is exactly one setState call (one commit), instead of fanning out to
152
+ // multiple back-to-back commits.
140
153
 
141
- // Responsive props object manages which items are in the list and which items are in the menu.
142
- const [responsiveProps, setResponsiveProps] = useState({
154
+ const [overflowState, setOverflowState] = useState(() => ({
143
155
  items: validChildren,
144
- menuItems: []
145
- });
156
+ menuItems: [],
157
+ iconsVisible: true,
158
+ measured: false,
159
+ childrenKey
160
+ }));
161
+
162
+ // Derived-state reset: when the children list changes, push everything back into
163
+ // the list (with icons) so the next layout effect can measure all items in one
164
+ // pass. This is React's recommended "store information from previous renders"
165
+ // pattern — calling setState during render lets React discard the in-progress
166
+ // render and re-render immediately with the reset state, before paint.
167
+ if (overflowState.childrenKey !== childrenKey) {
168
+ setOverflowState({
169
+ items: validChildren,
170
+ menuItems: [],
171
+ iconsVisible: true,
172
+ measured: false,
173
+ childrenKey
174
+ });
175
+ }
176
+
177
+ // Build a key-indexed view of validChildren once per render so the listItems /
178
+ // menuItems prop-refresh below is O(N) instead of O(N^2) via Array.prototype.find.
179
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
180
+ const validChildrenByKey = new Map();
181
+ for (const c of validChildren) validChildrenByKey.set(String(c.key), c);
182
+ const {
183
+ iconsVisible,
184
+ measured: isOverflowMeasured
185
+ } = overflowState;
146
186
 
147
187
  // Make sure to have the fresh props data for list items when children are changed (keeping aria-current up-to-date)
148
- const listItems = responsiveProps.items.map(item => {
149
- var _validChildren$find;
150
- return (_validChildren$find = validChildren.find(child => child.key === item.key)) !== null && _validChildren$find !== void 0 ? _validChildren$find : item;
188
+ const listItems = overflowState.items.map(item => {
189
+ var _validChildrenByKey$g;
190
+ return (_validChildrenByKey$g = validChildrenByKey.get(String(item.key))) !== null && _validChildrenByKey$g !== void 0 ? _validChildrenByKey$g : item;
151
191
  });
152
192
 
153
193
  // Make sure to have the fresh props data for menu items when children are changed (keeping aria-current up-to-date)
154
- const menuItems = responsiveProps.menuItems.map(menuItem => {
155
- var _validChildren$find2;
156
- return (_validChildren$find2 = validChildren.find(child => child.key === menuItem.key)) !== null && _validChildren$find2 !== void 0 ? _validChildren$find2 : menuItem;
194
+ const menuItems = overflowState.menuItems.map(item => {
195
+ var _validChildrenByKey$g2;
196
+ return (_validChildrenByKey$g2 = validChildrenByKey.get(String(item.key))) !== null && _validChildrenByKey$g2 !== void 0 ? _validChildrenByKey$g2 : item;
157
197
  });
158
198
  // This is the case where the viewport is too narrow to show any list item with the more menu. In this case, we only show the dropdown
159
- const onlyMenuVisible = responsiveProps.items.length === 0;
160
- if (process.env.NODE_ENV !== "production") {
161
- // Practically, this is not a conditional hook, it is just making sure this hook runs only on DEV not PROD.
162
- // eslint-disable-next-line react-hooks/rules-of-hooks
163
- useEffect(() => {
164
- // Address illegal state where there are multiple items that have `aria-current='page'` attribute
165
- const activeElements = validChildren.filter(child => {
166
- return child.props['aria-current'] !== undefined;
167
- });
168
- !(activeElements.length <= 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Only one current element is allowed') : invariant(false) : void 0;
169
- !ariaLabel ? process.env.NODE_ENV !== "production" ? invariant(false, 'Use the `aria-label` prop to provide an accessible label for assistive technology') : invariant(false) : void 0;
199
+ const onlyMenuVisible = overflowState.items.length === 0;
200
+ useDevOnlyEffect(() => {
201
+ // Address illegal state where there are multiple items that have `aria-current='page'` attribute
202
+ const activeElements = validChildren.filter(child => {
203
+ return child.props['aria-current'] !== undefined;
170
204
  });
171
- }
172
- function getItemsWidth(itemText) {
173
- var _noIconChildWidthArra, _noIconChildWidthArra2;
174
- return (_noIconChildWidthArra = (_noIconChildWidthArra2 = noIconChildWidthArray.find(item => item.text === itemText)) === null || _noIconChildWidthArra2 === void 0 ? void 0 : _noIconChildWidthArra2.width) !== null && _noIconChildWidthArra !== void 0 ? _noIconChildWidthArra : 0;
175
- }
176
- const swapMenuItemWithListItem = (prospectiveListItem, indexOfProspectiveListItem, event, callback) => {
205
+ !(activeElements.length <= 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Only one current element is allowed') : invariant(false) : void 0;
206
+ !ariaLabel ? process.env.NODE_ENV !== "production" ? invariant(false, 'Use the `aria-label` prop to provide an accessible label for assistive technology') : invariant(false) : void 0;
207
+ }, [validChildren, ariaLabel]);
208
+
209
+ // Returns the measured "no icon" width for an item, looking up by element key.
210
+ // Previously this was a text-based lookup, which silently returned 0 when an
211
+ // item's children weren't a plain string and caused the swap math to degenerate.
212
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
+ const getItemNoIconWidth = item => {
214
+ var _noIconChildWidthsRef;
215
+ return (_noIconChildWidthsRef = noIconChildWidthsRef.current.get(String(item.key))) !== null && _noIconChildWidthsRef !== void 0 ? _noIconChildWidthsRef : 0;
216
+ };
217
+
218
+ // Pure: returns the {items, menuItems} that result from promoting
219
+ // `prospectiveListItem` (currently at position `indexOfProspectiveListItem`
220
+ // in `currentMenuItems`) into `currentItems`. Does not call setState.
221
+ const computeSwap = (currentItems, currentMenuItems, prospectiveListItem, indexOfProspectiveListItem) => {
177
222
  var _navRef$current$getBo, _navRef$current, _listRef$current$getB, _listRef$current;
178
- // get the selected menu item's width
179
- const widthToFitIntoList = getItemsWidth(prospectiveListItem.props.children);
180
- // Check if there is any empty space on the right side of the list
223
+ const widthToFitIntoList = getItemNoIconWidth(prospectiveListItem);
181
224
  const availableSpace = ((_navRef$current$getBo = (_navRef$current = navRef.current) === null || _navRef$current === void 0 ? void 0 : _navRef$current.getBoundingClientRect().width) !== null && _navRef$current$getBo !== void 0 ? _navRef$current$getBo : 0) - ((_listRef$current$getB = (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.getBoundingClientRect().width) !== null && _listRef$current$getB !== void 0 ? _listRef$current$getB : 0);
182
225
 
183
- // Calculate how many items need to be pulled in to the menu to make room for the selected menu item
184
- // I.e. if we need to pull 2 items in (index 0 and index 1), breakpoint (index) will return 1.
185
- const index = getBreakpointForItemSwapping(widthToFitIntoList, availableSpace);
186
- const indexToSliceAt = responsiveProps.items.length - 1 - index;
187
- // Form the new list of items
188
- const itemsLeftInList = [...responsiveProps.items].slice(0, indexToSliceAt);
189
- const updatedItemList = [...itemsLeftInList, prospectiveListItem];
190
- // Form the new menu items
191
- const itemsToAddToMenu = [...responsiveProps.items].slice(indexToSliceAt);
192
- const updatedMenuItems = [...menuItems];
193
- // Add itemsToAddToMenu array's items to the menu at the index of the prospectiveListItem and remove 1 count of items (prospectiveListItem)
194
- updatedMenuItems.splice(indexOfProspectiveListItem, 1, ...itemsToAddToMenu);
195
- callback({
196
- items: updatedItemList,
197
- menuItems: updatedMenuItems
198
- }, false, true);
199
- };
200
- // How many items do we need to pull in to the menu to make room for the selected menu item.
201
- function getBreakpointForItemSwapping(widthToFitIntoList, availableSpace) {
226
+ // How many items at the end of the list have to move to the menu to make
227
+ // room for the promoted item.
202
228
  let widthToSwap = 0;
203
229
  let breakpoint = 0;
204
- for (const [index, item] of [...responsiveProps.items].reverse().entries()) {
205
- widthToSwap += getItemsWidth(item.props.children);
230
+ for (const [index, item] of [...currentItems].reverse().entries()) {
231
+ widthToSwap += getItemNoIconWidth(item);
206
232
  if (widthToFitIntoList < widthToSwap + availableSpace) {
207
233
  breakpoint = index;
208
234
  break;
209
235
  }
210
236
  }
211
- return breakpoint;
212
- }
213
- const updateListAndMenu = useCallback((props, displayIcons, overflowMeasured) => {
214
- setResponsiveProps(props);
215
- setIconsVisible(displayIcons);
216
- if (overflowMeasured) {
217
- setIsOverflowMeasured(true);
237
+ const indexToSliceAt = currentItems.length - 1 - breakpoint;
238
+ const itemsLeftInList = currentItems.slice(0, indexToSliceAt);
239
+ const updatedItemList = [...itemsLeftInList, prospectiveListItem];
240
+ const itemsToAddToMenu = currentItems.slice(indexToSliceAt);
241
+ const updatedMenuItems = [...currentMenuItems];
242
+ updatedMenuItems.splice(indexOfProspectiveListItem, 1, ...itemsToAddToMenu);
243
+ return {
244
+ items: updatedItemList,
245
+ menuItems: updatedMenuItems
246
+ };
247
+ };
248
+ const swapMenuItemWithListItem = (prospectiveListItem, indexOfProspectiveListItem) => {
249
+ const swap = computeSwap(overflowState.items, menuItems, prospectiveListItem, indexOfProspectiveListItem);
250
+ setOverflowState(prev => ({
251
+ items: swap.items,
252
+ menuItems: swap.menuItems,
253
+ iconsVisible: false,
254
+ measured: true,
255
+ childrenKey: prev.childrenKey
256
+ }));
257
+ };
258
+
259
+ // Single combined layout effect that performs measurement (when needed) and
260
+ // the external-aria-current promotion (when needed), then commits at most
261
+ // one setOverflowState per pass. Replaces the previous two effects (each of
262
+ // which produced its own commit) and removes the render-phase setState that
263
+ // the original component used to do the same swap from inside menuItems.map.
264
+ //
265
+ // Why no deps array: the swap branch depends on `aria-current` which lives
266
+ // on item props (not on `overflowState`); a deps-driven effect would not
267
+ // notice prop-only changes without rebuilding a signature. The body
268
+ // short-circuits cheaply on every render where neither pass needs to run.
269
+ useIsomorphicLayoutEffect(() => {
270
+ var _next;
271
+ const listEl = listRef.current;
272
+ const navEl = navRef.current;
273
+ if (!listEl || !navEl) return;
274
+ let next = null;
275
+
276
+ // Pass 1: measurement (runs once after each remeasure trigger).
277
+ if (!isOverflowMeasured) {
278
+ var _moreMenuRef$current$, _moreMenuRef$current;
279
+ const widths = new Map();
280
+ const noIconWidths = new Map();
281
+ const itemEls = listEl.querySelectorAll('[data-underlinenav-item="true"]');
282
+
283
+ // The N-th [data-underlinenav-item] element corresponds to validChildren[N]
284
+ // because the measurement pass runs only when all items are in the list,
285
+ // in render order. Pair them up positionally so we can key widths by the
286
+ // element's React key.
287
+ const upToBoundary = Math.min(itemEls.length, validChildren.length);
288
+ for (let index = 0; index < upToBoundary; index++) {
289
+ const liEl = itemEls[index];
290
+ const linkEl = liEl.querySelector('a, button');
291
+ if (!linkEl) continue;
292
+ const child = validChildren[index];
293
+ const key = String(child.key);
294
+ const domRect = linkEl.getBoundingClientRect();
295
+ const iconEl = linkEl.querySelector('[data-component="icon"]');
296
+ let iconWidthWithMargin = 0;
297
+ if (iconEl) {
298
+ const style = getComputedStyle(iconEl);
299
+ iconWidthWithMargin = iconEl.getBoundingClientRect().width + (parseFloat(style.marginRight) || 0) + (parseFloat(style.marginLeft) || 0);
300
+ }
301
+ widths.set(key, domRect.width);
302
+ noIconWidths.set(key, domRect.width - iconWidthWithMargin);
303
+ }
304
+ childWidthsRef.current = widths;
305
+ noIconChildWidthsRef.current = noIconWidths;
306
+ const navWidth = navEl.getBoundingClientRect().width;
307
+ if (navWidth === 0) return;
308
+ const moreMenuWidth = (_moreMenuRef$current$ = (_moreMenuRef$current = moreMenuRef.current) === null || _moreMenuRef$current === void 0 ? void 0 : _moreMenuRef$current.getBoundingClientRect().width) !== null && _moreMenuRef$current$ !== void 0 ? _moreMenuRef$current$ : 0;
309
+ const result = computeOverflow(navWidth, moreMenuWidth, validChildren, widths, noIconWidths);
310
+ next = {
311
+ items: result.items,
312
+ menuItems: result.menuItems,
313
+ iconsVisible: result.iconsVisible,
314
+ measured: true,
315
+ childrenKey: overflowState.childrenKey
316
+ };
218
317
  }
219
- }, []);
220
- const setChildrenWidth = useCallback(size => {
221
- setChildWidthArray(arr => {
222
- const newArr = [...arr, size];
223
- return newArr;
224
- });
225
- }, []);
226
- const setNoIconChildrenWidth = useCallback(size => {
227
- setNoIconChildWidthArray(arr => {
228
- const newArr = [...arr, size];
229
- return newArr;
230
- });
231
- }, []);
318
+
319
+ // Pass 2: external-aria-current promotion. Operates on the freshest
320
+ // (post-measurement) items so it can fold into the same setState.
321
+ const considered = (_next = next) !== null && _next !== void 0 ? _next : overflowState;
322
+ if (considered.measured && considered.items.length > 0) {
323
+ // Look at FRESH props (current aria-current) by remapping through
324
+ // validChildrenByKey (O(1) per lookup; the previous .find() pattern was
325
+ // O(N) and ran inside a .map() — quadratic on every commit).
326
+ const freshMenuItems = considered.menuItems.map(item => {
327
+ var _validChildrenByKey$g3;
328
+ return (_validChildrenByKey$g3 = validChildrenByKey.get(String(item.key))) !== null && _validChildrenByKey$g3 !== void 0 ? _validChildrenByKey$g3 : item;
329
+ });
330
+ const indexOfCurrent = freshMenuItems.findIndex(item => {
331
+ const c = item.props['aria-current'];
332
+ return Boolean(c) && c !== 'false';
333
+ });
334
+ if (indexOfCurrent !== -1) {
335
+ const swap = computeSwap(considered.items, freshMenuItems, freshMenuItems[indexOfCurrent], indexOfCurrent);
336
+ next = {
337
+ items: swap.items,
338
+ menuItems: swap.menuItems,
339
+ iconsVisible: false,
340
+ measured: true,
341
+ childrenKey: considered.childrenKey
342
+ };
343
+ }
344
+ }
345
+ if (next) setOverflowState(next);
346
+ });
232
347
  const closeOverlay = React.useCallback(() => {
233
348
  setIsWidgetOpen(false);
234
349
  }, [setIsWidgetOpen]);
@@ -255,36 +370,66 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
255
370
  ignoreClickRefs: [moreMenuBtnRef]
256
371
  });
257
372
  useResizeObserver(resizeObserverEntries => {
258
- var _moreMenuRef$current$, _moreMenuRef$current;
373
+ var _moreMenuRef$current$2, _moreMenuRef$current2;
259
374
  const navWidth = resizeObserverEntries[0].contentRect.width;
260
- const moreMenuWidth = (_moreMenuRef$current$ = (_moreMenuRef$current = moreMenuRef.current) === null || _moreMenuRef$current === void 0 ? void 0 : _moreMenuRef$current.getBoundingClientRect().width) !== null && _moreMenuRef$current$ !== void 0 ? _moreMenuRef$current$ : 0;
261
- navWidth !== 0 && overflowEffect(navWidth, moreMenuWidth, validChildren, childWidthArray, noIconChildWidthArray, updateListAndMenu);
375
+ if (navWidth === 0) return;
376
+ const moreMenuWidth = (_moreMenuRef$current$2 = (_moreMenuRef$current2 = moreMenuRef.current) === null || _moreMenuRef$current2 === void 0 ? void 0 : _moreMenuRef$current2.getBoundingClientRect().width) !== null && _moreMenuRef$current$2 !== void 0 ? _moreMenuRef$current$2 : 0;
377
+ const result = computeOverflow(navWidth, moreMenuWidth, validChildren, childWidthsRef.current, noIconChildWidthsRef.current);
378
+ setOverflowState(prev => ({
379
+ items: result.items,
380
+ menuItems: result.menuItems,
381
+ iconsVisible: result.iconsVisible,
382
+ measured: childWidthsRef.current.size > 0 || prev.measured,
383
+ childrenKey: prev.childrenKey
384
+ }));
262
385
  }, navRef);
263
386
 
264
- // Compute menuInlineStyles if needed
265
- let menuInlineStyles = {
266
- ...baseMenuInlineStyles
267
- };
268
- if (containerRef.current && listRef.current) {
387
+ // Menu anchor position. `undefined` means "use the default right: 0 from
388
+ // baseMenuInlineStyles" (the list is wide enough that no anchoring is
389
+ // needed). A number means the menu is anchored to that `left` coordinate,
390
+ // overriding right.
391
+ //
392
+ // This used to be computed inline during render by reading
393
+ // containerRef.current / listRef.current — refs are mutable and unsafe to
394
+ // read during render under concurrent rendering (the first render saw null
395
+ // refs and fell through to the unanchored fallback; subsequent renders
396
+ // anchored differently, producing a perceptible reflow).
397
+ const [menuAnchorLeft, setMenuAnchorLeft] = useState(undefined);
398
+ useIsomorphicLayoutEffect(() => {
399
+ const container = containerRef.current;
400
+ const list = listRef.current;
401
+ if (!container || !list) return;
402
+ if (list.clientWidth >= baseMenuMinWidth) {
403
+ if (menuAnchorLeft !== undefined) setMenuAnchorLeft(undefined);
404
+ return;
405
+ }
269
406
  const {
270
407
  left
271
- } = getAnchoredPosition(containerRef.current, listRef.current, {
408
+ } = getAnchoredPosition(container, list, {
272
409
  align: 'start',
273
410
  side: 'outside-bottom'
274
411
  });
275
- menuInlineStyles = {
276
- ...baseMenuInlineStyles,
277
- right: undefined,
278
- left
279
- };
280
- }
412
+ if (menuAnchorLeft !== left) setMenuAnchorLeft(left);
413
+ }, [isWidgetOpen, isOverflowMeasured, menuItems.length, menuAnchorLeft]);
414
+
415
+ // Stable context value: a fresh object literal here would re-render every
416
+ // consumer (UnderlineNav.Item) on every parent re-render, undoing the
417
+ // React.memo on UnderlineNavItem.
418
+ const contextValue = useMemo(() => ({
419
+ loadingCounters,
420
+ iconsVisible
421
+ }), [loadingCounters, iconsVisible]);
422
+ const menuStyle = menuAnchorLeft !== undefined ? {
423
+ ...baseMenuInlineStyles,
424
+ right: undefined,
425
+ left: menuAnchorLeft,
426
+ display: isWidgetOpen ? 'block' : 'none'
427
+ } : {
428
+ ...baseMenuInlineStyles,
429
+ display: isWidgetOpen ? 'block' : 'none'
430
+ };
281
431
  return /*#__PURE__*/jsxs(UnderlineNavContext.Provider, {
282
- value: {
283
- setChildrenWidth,
284
- setNoIconChildrenWidth,
285
- loadingCounters,
286
- iconsVisible
287
- },
432
+ value: contextValue,
288
433
  children: [ariaLabel && /*#__PURE__*/jsx(VisuallyHidden, {
289
434
  as: "h2",
290
435
  children: `${ariaLabel} navigation`
@@ -331,31 +476,23 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
331
476
  selectionVariant: "single",
332
477
  ref: containerRef,
333
478
  id: disclosureWidgetId,
334
- style: {
335
- ...((_listRef$current2 = listRef.current) !== null && _listRef$current2 !== void 0 && _listRef$current2.clientWidth && listRef.current.clientWidth >= baseMenuMinWidth ? baseMenuInlineStyles : menuInlineStyles),
336
- display: isWidgetOpen ? 'block' : 'none'
337
- },
479
+ style: menuStyle,
338
480
  children: menuItems.map((menuItem, index) => {
339
481
  const {
340
482
  children: menuItemChildren,
341
483
  counter,
342
- 'aria-current': ariaCurrent,
484
+ // Stripped from the spread below; the swap effect reads aria-current
485
+ // directly from item.props (not via these destructured locals).
486
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
487
+ 'aria-current': _ariaCurrent,
343
488
  onSelect,
344
489
  ...menuItemProps
345
490
  } = menuItem.props;
346
-
347
- // This logic is used to pop the selected item out of the menu and into the list when the navigation is control externally
348
- if (Boolean(ariaCurrent) && ariaCurrent !== 'false') {
349
- const event = new MouseEvent('click');
350
- !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index,
351
- // @ts-ignore - not a big deal because it is internally creating an event but ask help
352
- event, updateListAndMenu);
353
- }
354
491
  return /*#__PURE__*/jsx(ActionList.LinkItem, {
355
492
  style: menuItemStyles,
356
493
  onClick: event => {
357
494
  // When there are no items in the list, do not run the swap function as we want to keep everything in the menu.
358
- !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index, event, updateListAndMenu);
495
+ !onlyMenuVisible && swapMenuItemWithListItem(menuItem, index);
359
496
  closeOverlay();
360
497
  focusOnMoreMenuBtn();
361
498
  // fire onSelect event that comes from the UnderlineNav.Item (if it is defined)
@@ -371,7 +508,7 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
371
508
  })
372
509
  })]
373
510
  })
374
- }, menuItemChildren);
511
+ }, String(menuItem.key));
375
512
  })
376
513
  })]
377
514
  })]
@@ -381,4 +518,4 @@ const UnderlineNav = /*#__PURE__*/forwardRef(({
381
518
  });
382
519
  UnderlineNav.displayName = 'UnderlineNav';
383
520
 
384
- export { MORE_BTN_WIDTH, UnderlineNav, getValidChildren };
521
+ export { UnderlineNav };
@@ -1,13 +1,4 @@
1
- import type React from 'react';
2
- export declare const UnderlineNavContext: React.Context<{
3
- setChildrenWidth: React.Dispatch<{
4
- text: string;
5
- width: number;
6
- }>;
7
- setNoIconChildrenWidth: React.Dispatch<{
8
- text: string;
9
- width: number;
10
- }>;
1
+ export declare const UnderlineNavContext: import("react").Context<{
11
2
  loadingCounters: boolean;
12
3
  iconsVisible: boolean;
13
4
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"UnderlineNavContext.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNavContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,eAAO,MAAM,mBAAmB;sBACZ,KAAK,CAAC,QAAQ,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC;4BACvC,KAAK,CAAC,QAAQ,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC;qBACpD,OAAO;kBACV,OAAO;EAMrB,CAAA"}
1
+ {"version":3,"file":"UnderlineNavContext.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNavContext.tsx"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB;qBACb,OAAO;kBACV,OAAO;EAIrB,CAAA"}
@@ -1,8 +1,6 @@
1
1
  import { createContext } from 'react';
2
2
 
3
3
  const UnderlineNavContext = /*#__PURE__*/createContext({
4
- setChildrenWidth: () => null,
5
- setNoIconChildrenWidth: () => null,
6
4
  loadingCounters: false,
7
5
  iconsVisible: true
8
6
  });
@@ -43,5 +43,7 @@ export type UnderlineNavItemProps = {
43
43
  */
44
44
  counter?: number | string;
45
45
  } & LinkProps;
46
- export declare const UnderlineNavItem: PolymorphicForwardRefComponent<"a", UnderlineNavItemProps>;
46
+ declare const UnderlineNavItemImpl: PolymorphicForwardRefComponent<"a", UnderlineNavItemProps>;
47
+ export declare const UnderlineNavItem: typeof UnderlineNavItemImpl;
48
+ export {};
47
49
  //# sourceMappingURL=UnderlineNavItem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UnderlineNavItem.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNavItem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAuC,MAAM,OAAO,CAAA;AAC3D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAO/F,MAAM,MAAM,SAAS,GAAG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;QAEI;IACJ,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,GAAG,CAAA;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAC1B,GAAG,SAAS,CAAA;AAEb,QAAA,MAAM,oBAAoB,EAwDrB,8BAA8B,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAA;AAK/D,eAAO,MAAM,gBAAgB,EAAkD,OAAO,oBAAoB,CAAA"}
@@ -1,11 +1,10 @@
1
1
  import React, { forwardRef, useRef, useContext } from 'react';
2
2
  import { UnderlineNavContext } from './UnderlineNavContext.js';
3
- import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
4
3
  import { UnderlineItem } from '../internal/components/UnderlineTabbedInterface.js';
5
4
  import classes from './UnderlineNavItem.module.css.js';
6
5
  import { jsx } from 'react/jsx-runtime';
7
6
 
8
- const UnderlineNavItem = /*#__PURE__*/forwardRef(({
7
+ const UnderlineNavItemImpl = /*#__PURE__*/forwardRef(({
9
8
  as: Component = 'a',
10
9
  href = '#',
11
10
  children,
@@ -19,28 +18,9 @@ const UnderlineNavItem = /*#__PURE__*/forwardRef(({
19
18
  const backupRef = useRef(null);
20
19
  const ref = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
21
20
  const {
22
- setChildrenWidth,
23
- setNoIconChildrenWidth,
24
21
  loadingCounters,
25
22
  iconsVisible
26
23
  } = useContext(UnderlineNavContext);
27
- useIsomorphicLayoutEffect(() => {
28
- if (ref.current) {
29
- const domRect = ref.current.getBoundingClientRect();
30
- const icon = Array.from(ref.current.children).find(child => child.getAttribute('data-component') === 'icon');
31
- const content = Array.from(ref.current.children).find(child => child.getAttribute('data-component') === 'text');
32
- const text = content.textContent;
33
- const iconWidthWithMargin = icon ? icon.getBoundingClientRect().width + Number(getComputedStyle(icon).marginRight.slice(0, -2)) + Number(getComputedStyle(icon).marginLeft.slice(0, -2)) : 0;
34
- setChildrenWidth({
35
- text,
36
- width: domRect.width
37
- });
38
- setNoIconChildrenWidth({
39
- text,
40
- width: domRect.width - iconWidthWithMargin
41
- });
42
- }
43
- }, [ref, setChildrenWidth, setNoIconChildrenWidth]);
44
24
  const keyDownHandler = React.useCallback(event => {
45
25
  if ((event.key === ' ' || event.key === 'Enter') && !event.defaultPrevented && typeof onSelect === 'function') {
46
26
  onSelect(event);
@@ -53,6 +33,7 @@ const UnderlineNavItem = /*#__PURE__*/forwardRef(({
53
33
  }, [onSelect]);
54
34
  return /*#__PURE__*/jsx("li", {
55
35
  className: classes.UnderlineNavItem,
36
+ "data-underlinenav-item": "true",
56
37
  children: /*#__PURE__*/jsx(UnderlineItem, {
57
38
  ref: ref,
58
39
  as: Component,
@@ -69,6 +50,10 @@ const UnderlineNavItem = /*#__PURE__*/forwardRef(({
69
50
  })
70
51
  });
71
52
  });
72
- UnderlineNavItem.displayName = 'UnderlineNavItem';
53
+ UnderlineNavItemImpl.displayName = 'UnderlineNavItem';
54
+
55
+ // Memoized so that re-renders of UnderlineNav (e.g. when overflow state changes)
56
+ // do not re-render every item when the consumer-provided children haven't changed.
57
+ const UnderlineNavItem = /*#__PURE__*/React.memo(UnderlineNavItemImpl);
73
58
 
74
59
  export { UnderlineNavItem };
@@ -1,8 +1,4 @@
1
- export type ChildSize = {
2
- text: string;
3
- width: number;
4
- };
5
- export type ChildWidthArray = Array<ChildSize>;
1
+ export type ChildWidthMap = Map<string, number>;
6
2
  export type ResponsiveProps = {
7
3
  items: Array<React.ReactElement<any>>;
8
4
  menuItems: Array<React.ReactElement<any>>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AACD,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,SAAS,CAAC,CAAA;AAC9C,MAAM,MAAM,eAAe,GAAG;IAE5B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;IAErC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;CAC1C,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/types.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE/C,MAAM,MAAM,eAAe,GAAG;IAE5B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;IAErC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;CAC1C,CAAA"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Runs an effect only in development. Wrapping `useEffect` in a regular hook
3
+ * with an outer `__DEV__` guard keeps the production cost to zero (the entire
4
+ * call is dropped by the consumer's `process.env.NODE_ENV` replacement) while
5
+ * centralising the `eslint-disable react-hooks/rules-of-hooks` to one place
6
+ * instead of every call site.
7
+ *
8
+ * `exhaustive-deps` is wired up to also check call sites of this hook via
9
+ * `additionalEffectHooks` in `eslint.config.mjs`, so callers get the same
10
+ * deps lint they would for a plain `useEffect`.
11
+ *
12
+ * @param effect The effect callback to run in development.
13
+ * @param deps Dependency list, same semantics as `useEffect`.
14
+ */
15
+ export declare const useDevOnlyEffect: (effect: React.EffectCallback, deps?: React.DependencyList) => void;
16
+ //# sourceMappingURL=useDevOnlyEffect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDevOnlyEffect.d.ts","sourceRoot":"","sources":["../../../src/internal/hooks/useDevOnlyEffect.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,KAAK,CAAC,cAAc,EAAE,OAAO,KAAK,CAAC,cAAc,SAMzF,CAAA"}
@@ -0,0 +1,25 @@
1
+ import { useEffect } from 'react';
2
+
3
+ /**
4
+ * Runs an effect only in development. Wrapping `useEffect` in a regular hook
5
+ * with an outer `__DEV__` guard keeps the production cost to zero (the entire
6
+ * call is dropped by the consumer's `process.env.NODE_ENV` replacement) while
7
+ * centralising the `eslint-disable react-hooks/rules-of-hooks` to one place
8
+ * instead of every call site.
9
+ *
10
+ * `exhaustive-deps` is wired up to also check call sites of this hook via
11
+ * `additionalEffectHooks` in `eslint.config.mjs`, so callers get the same
12
+ * deps lint they would for a plain `useEffect`.
13
+ *
14
+ * @param effect The effect callback to run in development.
15
+ * @param deps Dependency list, same semantics as `useEffect`.
16
+ */
17
+ const useDevOnlyEffect = (effect, deps) => {
18
+ if (process.env.NODE_ENV !== "production") {
19
+ // Forwarding wrapper; deps lint applies at call sites.
20
+ // eslint-disable-next-line react-hooks/rules-of-hooks
21
+ useEffect(effect, deps);
22
+ }
23
+ };
24
+
25
+ export { useDevOnlyEffect };
@@ -1,3 +1,11 @@
1
1
  import { type RefObject } from 'react';
2
- export declare function useFocus(): import("react").Dispatch<import("react").SetStateAction<HTMLElement | RefObject<HTMLElement> | null>>;
2
+ /**
3
+ * Returns a function that focuses the given element on the next render commit.
4
+ *
5
+ * The target is stored in a ref (not state) and the effect is gated by a
6
+ * version counter, so calling `focus()` produces exactly one render — never
7
+ * the two-render cascade you'd get from `setState(target)` followed by
8
+ * `setState(null)` inside the effect.
9
+ */
10
+ export declare function useFocus(): (target: HTMLElement | RefObject<HTMLElement>) => void;
3
11
  //# sourceMappingURL=useFocus.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFocus.d.ts","sourceRoot":"","sources":["../../../src/internal/hooks/useFocus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,SAAS,EAAsB,MAAM,OAAO,CAAA;AAEzD,wBAAgB,QAAQ,0GAmBvB"}
1
+ {"version":3,"file":"useFocus.d.ts","sourceRoot":"","sources":["../../../src/internal/hooks/useFocus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,SAAS,EAA2C,MAAM,OAAO,CAAA;AAE9E;;;;;;;GAOG;AACH,wBAAgB,QAAQ,aAgBM,WAAW,GAAG,SAAS,CAAC,WAAW,CAAC,UAIjE"}
@@ -0,0 +1,35 @@
1
+ import { type ReactElement } from 'react';
2
+ export type RenderCounter = {
3
+ /** Total number of times the wrapped subtree has rendered (mount + updates). */
4
+ readonly count: number;
5
+ /** Number of mount renders. */
6
+ readonly mountCount: number;
7
+ /** Number of update renders (any cause). */
8
+ readonly updateCount: number;
9
+ /**
10
+ * Number of updates triggered inside the same commit cycle that produced the
11
+ * original render — i.e., a `setState` call from inside a `useLayoutEffect`
12
+ * that forced a synchronous re-render before paint. This is the canonical
13
+ * "nested update" / cascade signal; assert `nestedUpdateCount === 0` to pin
14
+ * that a component never forces a double-commit.
15
+ */
16
+ readonly nestedUpdateCount: number;
17
+ /** Reset the counter. */
18
+ reset(): void;
19
+ };
20
+ /**
21
+ * Returns a `[Wrap, counter]` pair. Wrap the component under test with `Wrap`
22
+ * to count how many times its subtree renders. Useful for asserting that a
23
+ * single user interaction (or a stable prop) does not cause cascading renders.
24
+ *
25
+ * @example
26
+ * const [Wrap, counter] = createRenderCounter()
27
+ * render(<Wrap><MyComponent /></Wrap>)
28
+ * // ... interaction ...
29
+ * expect(counter.updateCount).toBe(1)
30
+ * expect(counter.nestedUpdateCount).toBe(0)
31
+ */
32
+ export declare function createRenderCounter(id?: string): [(props: {
33
+ children: ReactElement | ReactElement[];
34
+ }) => ReactElement, RenderCounter];
35
+ //# sourceMappingURL=profiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiler.d.ts","sourceRoot":"","sources":["../../../src/utils/testing/profiler.tsx"],"names":[],"mappings":"AAAA,OAAc,EAA0C,KAAK,YAAY,EAAC,MAAM,OAAO,CAAA;AAEvF,MAAM,MAAM,aAAa,GAAG;IAC1B,gFAAgF;IAChF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,+BAA+B;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,4CAA4C;IAC5C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B;;;;;;OAMG;IACH,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAA;IAClC,yBAAyB;IACzB,KAAK,IAAI,IAAI,CAAA;CACd,CAAA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,EAAE,SAAkB,GACnB,CAAC,CAAC,KAAK,EAAE;IAAC,QAAQ,EAAE,YAAY,GAAG,YAAY,EAAE,CAAA;CAAC,KAAK,YAAY,EAAE,aAAa,CAAC,CAsCrF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260526014931",
4
+ "version": "0.0.0-20260526182004",
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",