@primer/react 0.0.0-20260427204434 → 0.0.0-20260427220854

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,14 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260427204434
3
+ ## 0.0.0-20260427220854
4
+
5
+ ### Patch Changes
6
+
7
+ - [#7770](https://github.com/primer/react/pull/7770) [`619175c`](https://github.com/primer/react/commit/619175c00dece144573fe5afbe4cd51e524a6c3d) Thanks [@LisaKr](https://github.com/LisaKr)! - Defer `useAnchoredPosition` initial mount setState from useLayoutEffect to useEffect when overlay is closed, eliminating unnecessary cascading re-renders that block paint.
8
+
9
+ - Fake entry to force publishing
10
+
11
+ ## 38.21.0
4
12
 
5
13
  ### Minor Changes
6
14
 
@@ -23,7 +31,7 @@
23
31
 
24
32
  This enables consumers to query and test components using stable selectors like `[data-component="Table.Row"]`.
25
33
 
26
- - [#7766](https://github.com/primer/react/pull/7766) [`6770095`](https://github.com/primer/react/commit/67700952bec8373c01843b88e39ccb6dfe5b108c) Thanks [@TylerJDev](https://github.com/TylerJDev)! - AnchoredOverlay: (Behind feature flag) Make popover API usage opt-in
34
+ - [#7766](https://github.com/primer/react/pull/7766) [`b3f06f1`](https://github.com/primer/react/commit/b3f06f1e2c91125c7b6b035bd019f534219d358f) Thanks [@TylerJDev](https://github.com/TylerJDev)! - AnchoredOverlay: (Behind feature flag) Make popover API usage opt-in
27
35
 
28
36
  - [#7763](https://github.com/primer/react/pull/7763) [`b288d6e`](https://github.com/primer/react/commit/b288d6e2dc9d1eef345ef4d16f6b0fba4f165955) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Add borderRadius prop to Card component.
29
37
 
@@ -33,12 +41,8 @@
33
41
 
34
42
  - [#7754](https://github.com/primer/react/pull/7754) [`9e3fe4b`](https://github.com/primer/react/commit/9e3fe4b501ce5affb558bf92697e5c79341903ca) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Breadcrumbs: On narrow viewports, only show the current page breadcrumb and the overflow menu when `overflow="menu"` is set.
35
43
 
36
- - Fake entry to force publishing
37
-
38
44
  - [#7757](https://github.com/primer/react/pull/7757) [`ed82a1e`](https://github.com/primer/react/commit/ed82a1e0399b98428d4b794239bb37649806b5cc) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - SelectPanel: Lock body scroll when modal variant is on.
39
45
 
40
- - [#7775](https://github.com/primer/react/pull/7775) [`2199b7f`](https://github.com/primer/react/commit/2199b7f18f1a47e79e9b21cf04f1599d5af8836a) Thanks [@TylerJDev](https://github.com/TylerJDev)! - AnchoredOverlay: Ensure styles persist on anchors even when re-mounted (behind feature flag)
41
-
42
46
  - [#7734](https://github.com/primer/react/pull/7734) [`421ebf0`](https://github.com/primer/react/commit/421ebf0a54558a29f1efbe1850036f80b1bbe126) Thanks [@llastflowers](https://github.com/llastflowers)! - add data-component attributes for Avatar, AvatarStack, Banner, & BaseStyles
43
47
 
44
48
  ## 38.20.0
@@ -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;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Y,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,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,CA8OnF,CAAA"}
@@ -1,4 +1,5 @@
1
- import { useState, useCallback, useEffect } from 'react';
1
+ import { useRef, useCallback, useEffect } from 'react';
2
+ import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
2
3
  import { useFocusTrap } from '../hooks/useFocusTrap.js';
3
4
  import { useFocusZone } from '../hooks/useFocusZone.js';
4
5
  import { useId } from '../hooks/useId.js';
@@ -51,29 +52,13 @@ const AnchoredOverlay = ({
51
52
  renderAs = 'portal'
52
53
  }) => {
53
54
  const cssAnchorPositioningFlag = useFeatureFlag('primer_react_css_anchor_positioning');
54
- // Lazy initial state so feature detection runs once per mount on the client.
55
- // Guarded for SSR where `document` is undefined.
56
- const [supportsNativeCSSAnchorPositioning] = useState(() => typeof document !== 'undefined' && 'anchorName' in document.documentElement.style);
57
- const cssAnchorPositioning = cssAnchorPositioningFlag && supportsNativeCSSAnchorPositioning;
55
+ const supportsNativeCSSAnchorPositioning = useRef(false);
56
+ // eslint-disable-next-line react-hooks/refs
57
+ const cssAnchorPositioning = cssAnchorPositioningFlag && supportsNativeCSSAnchorPositioning.current;
58
58
  // Only use Popover API when both CSS anchor positioning is enabled AND renderAs is true
59
59
  const shouldRenderAsPopover = cssAnchorPositioning && renderAs === 'popover';
60
60
  const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
61
- // Track the current anchor DOM element in state so that effects depending on
62
- // its identity (e.g. applying `anchor-name` for CSS anchor positioning) re-run
63
- // when a consumer remounts/replaces the anchor element while keeping the same
64
- // `anchorRef` object. Refs alone don't notify React when `.current` changes.
65
- const [anchorElement, setAnchorElement] = useState(null);
66
- // Detect when `anchorRef.current` has been mutated by a consumer (e.g. via
67
- // their own `ref={anchorRef}`) without React's ref system notifying us.
68
- // Reading the ref during render and conditionally calling setState is the
69
- // documented React pattern for syncing external mutable state, but the
70
- // react-hooks/refs lint rule is conservative and disallows it.
71
- // eslint-disable-next-line react-hooks/refs
72
- if (anchorRef.current !== anchorElement) {
73
- setAnchorElement(anchorRef.current);
74
- }
75
61
  const [overlayRef, updateOverlayRef] = useRenderForcingRef();
76
- const [overlayElement, setOverlayElement] = useState(null);
77
62
  const anchorId = useId(externalAnchorId);
78
63
  const onClickOutside = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose('click-outside'), [onClose]);
79
64
  const onEscape = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose('escape'), [onClose]);
@@ -85,14 +70,14 @@ const AnchoredOverlay = ({
85
70
  }
86
71
  }
87
72
  }, [open, onOpen]);
88
- const onAnchorClick = useCallback(event => {
89
- if (event.defaultPrevented || event.button !== 0) {
73
+ const onAnchorClick = useCallback(event_0 => {
74
+ if (event_0.defaultPrevented || event_0.button !== 0) {
90
75
  return;
91
76
  }
92
77
  // Prevent the browser's native popovertarget toggle so React
93
78
  // stays the single source of truth for popover visibility.
94
79
  if (cssAnchorPositioning) {
95
- event.preventDefault();
80
+ event_0.preventDefault();
96
81
  }
97
82
  if (!open) {
98
83
  onOpen === null || onOpen === void 0 ? void 0 : onOpen('anchor-click');
@@ -108,7 +93,7 @@ const AnchoredOverlay = ({
108
93
  }
109
94
  };
110
95
  const {
111
- position
96
+ position: position_0
112
97
  } = useAnchoredPosition({
113
98
  anchorElementRef: anchorRef,
114
99
  floatingElementRef: overlayRef,
@@ -118,13 +103,13 @@ const AnchoredOverlay = ({
118
103
  alignmentOffset,
119
104
  anchorOffset,
120
105
  displayInViewport,
121
- onPositionChange: positionChange,
122
- // When native CSS anchor positioning is active, skip JS-based position
123
- // computation, scroll listeners, and resize observers since the browser
124
- // handles repositioning natively.
125
- enabled: !cssAnchorPositioning
126
- }, [overlayElement]);
106
+ onPositionChange: positionChange
107
+ },
108
+ // eslint-disable-next-line react-hooks/refs
109
+ [overlayRef.current]);
127
110
  useEffect(() => {
111
+ supportsNativeCSSAnchorPositioning.current = 'anchorName' in document.documentElement.style;
112
+
128
113
  // ensure overlay ref gets cleared when closed, so position can reset between closing/re-opening
129
114
  if (!open && overlayRef.current) {
130
115
  updateOverlayRef(null);
@@ -132,64 +117,64 @@ const AnchoredOverlay = ({
132
117
  }, [open, overlayRef, updateOverlayRef]);
133
118
  useFocusZone({
134
119
  containerRef: overlayRef,
135
- disabled: !open || !position && !cssAnchorPositioning,
120
+ disabled: !open || !position_0,
136
121
  ...focusZoneSettings
137
122
  });
138
123
  useFocusTrap({
139
124
  containerRef: overlayRef,
140
- disabled: !open || !position && !cssAnchorPositioning,
125
+ disabled: !open || !position_0,
141
126
  ...focusTrapSettings
142
127
  });
143
128
  const popoverId = useId();
144
129
  const id = popoverId.replaceAll(':', '_'); // popoverId can contain colons which are invalid in CSS custom property names, so we replace them with underscores
145
130
 
146
131
  useEffect(() => {
147
- if (!cssAnchorPositioning || !anchorElement) return;
148
- const currentOverlay = overlayRef.current;
149
-
150
- // Link the anchor and the overlay (when present) via CSS anchor positioning.
151
- anchorElement.style.setProperty('anchor-name', `--anchored-overlay-anchor-${id}`);
152
- let rafId = null;
153
- if (open && currentOverlay) {
154
- currentOverlay.style.setProperty('position-anchor', `--anchored-overlay-anchor-${id}`);
132
+ if (!cssAnchorPositioning || !anchorRef.current) return;
133
+ const anchor = anchorRef.current;
134
+ const overlay = overlayRef.current;
135
+ anchor.style.setProperty('anchor-name', `--anchored-overlay-anchor-${id}`);
136
+ return () => {
137
+ anchor.style.removeProperty('anchor-name');
138
+ if (overlay) {
139
+ overlay.style.removeProperty('position-anchor');
140
+ }
141
+ };
142
+ // eslint-disable-next-line react-hooks/refs
143
+ }, [cssAnchorPositioning, anchorRef, overlayRef, id, open]);
155
144
 
156
- // Defer the getBoundingClientRect read into a rAF so the style write above
157
- // does not force a synchronous layout. This matters when many overlays open
158
- // simultaneously: each effect would otherwise trigger a full-document layout
159
- // immediately after writing `anchor-name`/`position-anchor`.
160
- rafId = requestAnimationFrame(() => {
161
- rafId = null;
162
- const overlayWidth = width ? parseInt(widthMap[width]) : null;
163
- const result = getDefaultPosition(anchorElement, overlayWidth);
164
- currentOverlay.setAttribute('data-align', result.horizontal);
145
+ // Track the overlay element so we can re-run the effect when it changes.
146
+ // The overlay unmounts when closed, so each open creates a new DOM node -
147
+ // that needs showPopover() called.
148
+ // eslint-disable-next-line react-hooks/refs
149
+ const overlayElement = overlayRef.current;
150
+ useIsomorphicLayoutEffect(() => {
151
+ // Read ref inside effect to get the value after child refs are attached
152
+ const currentOverlay = overlayRef.current;
153
+ if (!cssAnchorPositioning || !open || !currentOverlay) return;
154
+ currentOverlay.style.setProperty('position-anchor', `--anchored-overlay-anchor-${id}`);
155
+ const anchorElement = anchorRef.current;
156
+ if (anchorElement) {
157
+ const overlayWidth = width ? parseInt(widthMap[width]) : null;
158
+ const result = getDefaultPosition(anchorElement, overlayWidth);
159
+ currentOverlay.setAttribute('data-align', result.horizontal);
165
160
 
166
- // Apply offset only when viewport is too narrow
167
- const offset = result.horizontal === 'left' ? result.leftOffset : result.rightOffset;
168
- currentOverlay.style.setProperty(`--anchored-overlay-anchor-offset-${result.horizontal}`, `${offset || 0}px`);
169
- });
161
+ // Apply offset only when viewport is too narrow
162
+ const offset = result.horizontal === 'left' ? result.leftOffset : result.rightOffset;
163
+ currentOverlay.style.setProperty(`--anchored-overlay-anchor-offset-${result.horizontal}`, `${offset || 0}px`);
164
+ }
170
165
 
171
- // Only call showPopover when shouldRenderAsPopover is enabled
172
- if (shouldRenderAsPopover) {
173
- try {
174
- if (!currentOverlay.matches(':popover-open')) {
175
- currentOverlay.showPopover();
176
- }
177
- } catch {
178
- // Ignore if popover is already showing or not supported
166
+ // Only call showPopover when renderAs is enabled
167
+ if (shouldRenderAsPopover) {
168
+ try {
169
+ if (!currentOverlay.matches(':popover-open')) {
170
+ currentOverlay.showPopover();
179
171
  }
172
+ } catch {
173
+ // Ignore if popover is already showing or not supported
180
174
  }
181
175
  }
182
- return () => {
183
- if (rafId !== null) cancelAnimationFrame(rafId);
184
- anchorElement.style.removeProperty('anchor-name');
185
- // The overlay may no longer be in the DOM at this point, so we need to check for its presence before trying to update it.
186
- if (currentOverlay) {
187
- currentOverlay.style.removeProperty('position-anchor');
188
- }
189
- };
190
- // overlayRef is a stable ref object; including it in deps is unnecessary.
191
- // eslint-disable-next-line react-hooks/exhaustive-deps
192
- }, [cssAnchorPositioning, shouldRenderAsPopover, open, anchorElement, overlayElement, id, width]);
176
+ // eslint-disable-next-line react-hooks/refs
177
+ }, [cssAnchorPositioning, shouldRenderAsPopover, open, overlayElement, id, overlayRef, anchorRef, width]);
193
178
  const showXIcon = onClose && variant.narrow === 'fullscreen' && displayCloseButton;
194
179
  const XButtonAriaLabelledBy = closeButtonProps['aria-labelledby'];
195
180
  const XButtonAriaLabel = closeButtonProps['aria-label'];
@@ -200,8 +185,6 @@ const AnchoredOverlay = ({
200
185
  } = overlayProps || {};
201
186
  return /*#__PURE__*/jsxs(Fragment, {
202
187
  children: [renderAnchor &&
203
- // anchorRef is a ref object passed as a JSX `ref` prop on the rendered
204
- // anchor; React writes to it at commit time, it is not read during render.
205
188
  // eslint-disable-next-line react-hooks/refs
206
189
  renderAnchor({
207
190
  ref: anchorRef,
@@ -220,13 +203,13 @@ const AnchoredOverlay = ({
220
203
  ignoreClickRefs: [anchorRef],
221
204
  onEscape: onEscape,
222
205
  role: "none",
223
- visibility: cssAnchorPositioning || position ? 'visible' : 'hidden',
206
+ visibility: cssAnchorPositioning || position_0 ? 'visible' : 'hidden',
224
207
  height: height,
225
208
  width: width,
226
- top: cssAnchorPositioning ? undefined : (position === null || position === void 0 ? void 0 : position.top) || 0,
227
- left: cssAnchorPositioning ? undefined : (position === null || position === void 0 ? void 0 : position.left) || 0,
209
+ top: cssAnchorPositioning ? undefined : (position_0 === null || position_0 === void 0 ? void 0 : position_0.top) || 0,
210
+ left: cssAnchorPositioning ? undefined : (position_0 === null || position_0 === void 0 ? void 0 : position_0.left) || 0,
228
211
  responsiveVariant: variant.narrow === 'fullscreen' ? 'fullscreen' : undefined,
229
- anchorSide: cssAnchorPositioning ? undefined : position === null || position === void 0 ? void 0 : position.anchorSide,
212
+ anchorSide: cssAnchorPositioning ? undefined : position_0 === null || position_0 === void 0 ? void 0 : position_0.anchorSide,
230
213
  className: clsx(className, overlayClassName, cssAnchorPositioning ? classes.AnchoredOverlay : undefined),
231
214
  preventOverflow: preventOverflow,
232
215
  "data-component": "AnchoredOverlay",
@@ -243,10 +226,9 @@ const AnchoredOverlay = ({
243
226
  assignRef(overlayProps.ref, node);
244
227
  }
245
228
  updateOverlayRef(node);
246
- setOverlayElement(node);
247
229
  },
248
230
  "data-anchor-position": cssAnchorPositioning,
249
- "data-side": cssAnchorPositioning ? side : position === null || position === void 0 ? void 0 : position.anchorSide,
231
+ "data-side": cssAnchorPositioning ? side : position_0 === null || position_0 === void 0 ? void 0 : position_0.anchorSide,
250
232
  children: [showXIcon ? /*#__PURE__*/jsx("div", {
251
233
  className: classes.ResponsiveCloseButtonContainer,
252
234
  children: /*#__PURE__*/jsx(IconButton, {
@@ -5,12 +5,6 @@ export interface AnchoredPositionHookSettings extends Partial<PositionSettings>
5
5
  anchorElementRef?: React.RefObject<Element | null>;
6
6
  pinPosition?: boolean;
7
7
  onPositionChange?: (position: AnchorPosition | undefined) => void;
8
- /**
9
- * When false, skips position computation, scroll listeners, and resize
10
- * observers. Useful when an external mechanism (e.g. native CSS anchor
11
- * positioning) is handling positioning instead. Defaults to true.
12
- */
13
- enabled?: boolean;
14
8
  }
15
9
  /**
16
10
  * Calculates the top and left values for an absolutely-positioned floating element
@@ -1 +1 @@
1
- {"version":3,"file":"useAnchoredPosition.d.ts","sourceRoot":"","sources":["../../src/hooks/useAnchoredPosition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAA;AA0BvE,MAAM,WAAW,4BAA6B,SAAQ,OAAO,CAAC,gBAAgB,CAAC;IAC7E,kBAAkB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IACpD,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAClD,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,cA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D,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAA;CACrC,CA8HA"}
@@ -34,10 +34,8 @@ function getScrollableAncestors(element) {
34
34
  * floating element.
35
35
  */
36
36
  function useAnchoredPosition(settings, dependencies = []) {
37
- var _settings$enabled;
38
37
  const floatingElementRef = useProvidedRefOrCreate(settings === null || settings === void 0 ? void 0 : settings.floatingElementRef);
39
38
  const anchorElementRef = useProvidedRefOrCreate(settings === null || settings === void 0 ? void 0 : settings.anchorElementRef);
40
- const enabled = (_settings$enabled = settings === null || settings === void 0 ? void 0 : settings.enabled) !== null && _settings$enabled !== void 0 ? _settings$enabled : true;
41
39
  const savedOnPositionChange = React.useRef(settings === null || settings === void 0 ? void 0 : settings.onPositionChange);
42
40
  const [position, setPosition] = React.useState(undefined);
43
41
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -64,7 +62,6 @@ function useAnchoredPosition(settings, dependencies = []) {
64
62
  };
65
63
  const updatePosition = React.useCallback(() => {
66
64
  var _floatingElementRef$c5;
67
- if (!enabled) return;
68
65
  if (floatingElementRef.current instanceof Element && anchorElementRef.current instanceof Element) {
69
66
  const newPosition = getAnchoredPosition(floatingElementRef.current, anchorElementRef.current, settings);
70
67
  setPosition(prev => {
@@ -91,18 +88,35 @@ function useAnchoredPosition(settings, dependencies = []) {
91
88
  setPrevHeight((_floatingElementRef$c5 = floatingElementRef.current) === null || _floatingElementRef$c5 === void 0 ? void 0 : _floatingElementRef$c5.clientHeight);
92
89
  },
93
90
  // eslint-disable-next-line react-hooks/exhaustive-deps, react-hooks/use-memo
94
- [floatingElementRef, anchorElementRef, enabled, ...dependencies]);
91
+ [floatingElementRef, anchorElementRef, ...dependencies]);
95
92
  useIsomorphicLayoutEffect(() => {
96
93
  savedOnPositionChange.current = settings === null || settings === void 0 ? void 0 : settings.onPositionChange;
97
94
  }, [settings === null || settings === void 0 ? void 0 : settings.onPositionChange]);
98
- useIsomorphicLayoutEffect(updatePosition, [updatePosition]);
95
+
96
+ // Defer the first updatePosition to useEffect when the overlay is closed on
97
+ // mount, avoiding paint-blocking cascading setState. If the overlay is already
98
+ // open on mount, run synchronously in useLayoutEffect to prevent a flash.
99
+ // After mount (including Suspense reappear), only call updatePosition when
100
+ // both refs are attached — skipping closed overlays avoids unnecessary setState.
101
+ const hasMountedRef = React.useRef(false);
102
+ useIsomorphicLayoutEffect(() => {
103
+ if (floatingElementRef.current instanceof Element && anchorElementRef.current instanceof Element) {
104
+ hasMountedRef.current = true;
105
+ updatePosition();
106
+ }
107
+ }, [updatePosition, floatingElementRef, anchorElementRef]);
108
+ React.useEffect(() => {
109
+ if (!hasMountedRef.current) {
110
+ hasMountedRef.current = true;
111
+ updatePosition();
112
+ }
113
+ }, [updatePosition]);
99
114
  useResizeObserver(updatePosition); // watches for changes in window size
100
115
  useResizeObserver(updatePosition, floatingElementRef); // watches for changes in floating element size
101
116
 
102
117
  // Recalculate position when any scrollable ancestor of the anchor scrolls.
103
118
  // Uses requestAnimationFrame to avoid layout thrashing during scroll.
104
119
  React.useEffect(() => {
105
- if (!enabled) return;
106
120
  const anchorEl = anchorElementRef.current;
107
121
  if (!anchorEl) return;
108
122
  let rafId = null;
@@ -126,7 +140,7 @@ function useAnchoredPosition(settings, dependencies = []) {
126
140
  cancelAnimationFrame(rafId);
127
141
  }
128
142
  };
129
- }, [anchorElementRef, updatePosition, enabled]);
143
+ }, [anchorElementRef, updatePosition]);
130
144
  return {
131
145
  floatingElementRef,
132
146
  anchorElementRef,
@@ -1174,7 +1174,7 @@
1174
1174
  },
1175
1175
  {
1176
1176
  "id": "components-avatar-features--square",
1177
- "code": "() => (\n <Avatar\n square\n alt=\"primer\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n)"
1177
+ "code": "() => (\n <Avatar\n square\n alt=\"primer\"\n src=\"https://avatars.githubusercontent.com/u/7143434?v=4\"\n />\n)"
1178
1178
  },
1179
1179
  {
1180
1180
  "id": "components-avatar-features--size",
@@ -1224,35 +1224,35 @@
1224
1224
  "stories": [
1225
1225
  {
1226
1226
  "id": "components-avatarstack-features--align-left",
1227
- "code": "() => (\n <AvatarStack>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
1227
+ "code": "() => (\n <AvatarStack>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/u/7143434?v=4\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/u/13171334?v=4\"\n />\n </AvatarStack>\n)"
1228
1228
  },
1229
1229
  {
1230
1230
  "id": "components-avatarstack-features--align-right",
1231
- "code": "() => (\n <AvatarStack alignRight>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
1231
+ "code": "() => (\n <AvatarStack alignRight>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/u/7143434?v=4\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/u/13171334?v=4\"\n />\n </AvatarStack>\n)"
1232
1232
  },
1233
1233
  {
1234
1234
  "id": "components-avatarstack-features--disable-expand-on-hover",
1235
- "code": "() => (\n <AvatarStack disableExpand>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
1235
+ "code": "() => (\n <AvatarStack disableExpand>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/u/7143434?v=4\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/u/13171334?v=4\"\n />\n </AvatarStack>\n)"
1236
1236
  },
1237
1237
  {
1238
1238
  "id": "components-avatarstack-features--custom-size-on-parent",
1239
- "code": "() => (\n <AvatarStack size={32}>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
1239
+ "code": "() => (\n <AvatarStack size={32}>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/u/7143434?v=4\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/u/13171334?v=4\"\n />\n </AvatarStack>\n)"
1240
1240
  },
1241
1241
  {
1242
1242
  "id": "components-avatarstack-features--custom-size-on-parent-responsive",
1243
- "code": "() => (\n <AvatarStack\n size={{\n narrow: 32,\n regular: 48,\n wide: 64,\n }}\n >\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
1243
+ "code": "() => (\n <AvatarStack\n size={{\n narrow: 32,\n regular: 48,\n wide: 64,\n }}\n >\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/u/7143434?v=4\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/u/13171334?v=4\"\n />\n </AvatarStack>\n)"
1244
1244
  },
1245
1245
  {
1246
1246
  "id": "components-avatarstack-features--custom-size-on-children",
1247
- "code": "() => (\n <AvatarStack>\n <Avatar\n size={20}\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n size={32}\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar\n size={48}\n alt=\"Atom logo\"\n src=\"https://avatars.githubusercontent.com/atom\"\n />\n <Avatar\n size={64}\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
1247
+ "code": "() => (\n <AvatarStack>\n <Avatar\n size={20}\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/u/7143434?v=4\"\n />\n <Avatar\n size={32}\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar\n size={48}\n alt=\"Atom logo\"\n src=\"https://avatars.githubusercontent.com/atom\"\n />\n <Avatar\n size={64}\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/u/13171334?v=4\"\n />\n </AvatarStack>\n)"
1248
1248
  },
1249
1249
  {
1250
1250
  "id": "components-avatarstack-features--custom-size-on-children-responsive",
1251
- "code": "() => (\n <AvatarStack>\n <Avatar\n size={{\n narrow: 16,\n regular: 32,\n wide: 48,\n }}\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n size={{\n narrow: 32,\n regular: 48,\n wide: 64,\n }}\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar\n size={{\n narrow: 48,\n regular: 64,\n wide: 96,\n }}\n alt=\"Atom logo\"\n src=\"https://avatars.githubusercontent.com/atom\"\n />\n <Avatar\n size={{\n narrow: 64,\n regular: 96,\n wide: 120,\n }}\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
1251
+ "code": "() => (\n <AvatarStack>\n <Avatar\n size={{\n narrow: 16,\n regular: 32,\n wide: 48,\n }}\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/u/7143434?v=4\"\n />\n <Avatar\n size={{\n narrow: 32,\n regular: 48,\n wide: 64,\n }}\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar\n size={{\n narrow: 48,\n regular: 64,\n wide: 96,\n }}\n alt=\"Atom logo\"\n src=\"https://avatars.githubusercontent.com/atom\"\n />\n <Avatar\n size={{\n narrow: 64,\n regular: 96,\n wide: 120,\n }}\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/u/13171334?v=4\"\n />\n </AvatarStack>\n)"
1252
1252
  },
1253
1253
  {
1254
1254
  "id": "components-avatarstack-features--with-single-avatar",
1255
- "code": "() => (\n <AvatarStack>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n </AvatarStack>\n)"
1255
+ "code": "() => (\n <AvatarStack>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/u/7143434?v=4\"\n />\n </AvatarStack>\n)"
1256
1256
  }
1257
1257
  ],
1258
1258
  "importPath": "@primer/react",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260427204434",
4
+ "version": "0.0.0-20260427220854",
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",