@primer/react 0.0.0-20260707162815 → 0.0.0-20260707162849

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260707162815
3
+ ## 0.0.0-20260707162849
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - Fake entry to force publishing
8
8
 
9
- - [#8025](https://github.com/primer/react/pull/8025) [`5abc62f`](https://github.com/primer/react/commit/5abc62f90cac33cd67396d78f01bf91b703db45c) Thanks [@mattcosta7](https://github.com/mattcosta7)! - SelectPanel: Reset the single-select modal's intermediate selection during render instead of in an effect, avoiding an extra re-render when the panel opens or the selection changes.
9
+ - [#8116](https://github.com/primer/react/pull/8116) [`064b105`](https://github.com/primer/react/commit/064b105604e31486806b8f4ab432540aaca10465) Thanks [@mattcosta7](https://github.com/mattcosta7)! - `useAnchoredPosition`: improve performance by caching the scrollable-ancestor walk per anchor, reducing repositioning work for overlays, menus, and tooltips.
10
10
 
11
11
  - [#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.
12
12
 
@@ -99,20 +99,13 @@ function Panel({ open, onOpenChange, renderAnchor = defaultRenderAnchor, anchorR
99
99
  const selectedValueId = id ? `${id}-selected-value` : void 0;
100
100
  const isSingleSelectModal = variant === "modal" && !isMultiSelectVariant(selected);
101
101
  const [intermediateSelected, setIntermediateSelected] = useState(isSingleSelectModal ? selected : void 0);
102
- const nextIntermediateSelected = isSingleSelectModal ? selected : void 0;
103
- const [intermediateSelectedResetKey, setIntermediateSelectedResetKey] = useState({
102
+ useEffect(() => {
103
+ setIntermediateSelected(isSingleSelectModal ? selected : void 0);
104
+ }, [
105
+ isSingleSelectModal,
104
106
  open,
105
- selected,
106
- isSingleSelectModal
107
- });
108
- if ((intermediateSelectedResetKey.open !== open || intermediateSelectedResetKey.selected !== selected || intermediateSelectedResetKey.isSingleSelectModal !== isSingleSelectModal) && intermediateSelected !== nextIntermediateSelected) {
109
- setIntermediateSelectedResetKey({
110
- open,
111
- selected,
112
- isSingleSelectModal
113
- });
114
- setIntermediateSelected(nextIntermediateSelected);
115
- }
107
+ selected
108
+ ]);
116
109
  const onListContainerRefChanged = useCallback((node) => {
117
110
  setListContainerElement(node);
118
111
  if (!node && needsNoItemsAnnouncement) setNeedsNoItemsAnnouncement(false);
@@ -106,6 +106,10 @@ function useAnchoredPosition(settings, dependencies = []) {
106
106
  }, [updatePosition]);
107
107
  useResizeObserver(updatePosition, void 0, [], enabled);
108
108
  useResizeObserver(updatePosition, floatingElementRef, [], enabled);
109
+ const scrollAncestorsCacheRef = React.useRef({
110
+ anchor: null,
111
+ scrollables: []
112
+ });
109
113
  React.useEffect(() => {
110
114
  if (!enabled) return;
111
115
  const anchorEl = anchorElementRef.current;
@@ -118,7 +122,16 @@ function useAnchoredPosition(settings, dependencies = []) {
118
122
  updatePosition();
119
123
  });
120
124
  };
121
- const scrollables = getScrollableAncestors(anchorEl);
125
+ const cache = scrollAncestorsCacheRef.current;
126
+ let scrollables;
127
+ if (cache.anchor === anchorEl) scrollables = cache.scrollables;
128
+ else {
129
+ scrollables = getScrollableAncestors(anchorEl);
130
+ scrollAncestorsCacheRef.current = {
131
+ anchor: anchorEl,
132
+ scrollables
133
+ };
134
+ }
122
135
  for (const scrollable of scrollables) scrollable.addEventListener("scroll", handleScroll);
123
136
  return () => {
124
137
  for (const scrollable of scrollables) scrollable.removeEventListener("scroll", handleScroll);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260707162815",
4
+ "version": "0.0.0-20260707162849",
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",