@primer/react 0.0.0-20260707192909 → 0.0.0-20260707192929

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260707192909
3
+ ## 0.0.0-20260707192929
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -17,12 +17,12 @@
17
17
 
18
18
  ### Patch Changes
19
19
 
20
+ - [#8001](https://github.com/primer/react/pull/8001) [`4e6cf0d`](https://github.com/primer/react/commit/4e6cf0d1715e0371169b291be7a503f2d15f7bc5) Thanks [@mattcosta7](https://github.com/mattcosta7)! - Derive state during render instead of in effects for `useMedia`, `ToggleSwitch`, `SelectPanel`, and the internal validation animation container, removing redundant render passes. Note: `useMedia` now returns the live `matchMedia` value on the first client render; `defaultState` is only used for the SSR/hydration snapshot (no public API changes).
21
+
20
22
  - Fake entry to force publishing
21
23
 
22
24
  - [#8115](https://github.com/primer/react/pull/8115) [`07c530a`](https://github.com/primer/react/commit/07c530a1686ef16b68b2f2fe692b7a3327bdc02b) Thanks [@mattcosta7](https://github.com/mattcosta7)! - Improve rendering performance in Safari by removing expensive `:has()` selectors from ActionList/NavList, Breadcrumbs, SelectPanel, and SegmentedControl. No visual or API changes.
23
25
 
24
- - [#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.
25
-
26
26
  - [#8035](https://github.com/primer/react/pull/8035) [`723f4d6`](https://github.com/primer/react/commit/723f4d6db12710e2b94f56b945a937158fcbb127) Thanks [@mattcosta7](https://github.com/mattcosta7)! - UnderlineNav, ActionBar: Detect item overflow with a single shared IntersectionObserver per component instead of one observer per item, reducing observer churn during resize. No public API changes.
27
27
 
28
28
  ## 38.31.0
@@ -99,19 +99,10 @@ 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({
104
- 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);
102
+ const [prevOpen, setPrevOpen] = useState(open);
103
+ if (prevOpen !== open) {
104
+ setPrevOpen(open);
105
+ setIntermediateSelected(isSingleSelectModal ? selected : void 0);
115
106
  }
116
107
  const onListContainerRefChanged = useCallback((node) => {
117
108
  setListContainerElement(node);
@@ -179,12 +179,12 @@ const ToggleSwitch = /*#__PURE__*/ React.forwardRef(function ToggleSwitch(props,
179
179
  t7 = $[30];
180
180
  }
181
181
  useEffect(t6, t7);
182
+ if (!loading && isLoadingLabelVisible) setIsLoadingLabelVisible(false);
182
183
  let t8;
183
184
  let t9;
184
185
  if ($[31] !== isLoadingLabelVisible || $[32] !== loading || $[33] !== loadingLabelDelay || $[34] !== safeSetTimeout) {
185
186
  t8 = () => {
186
- if (!loading && isLoadingLabelVisible) setIsLoadingLabelVisible(false);
187
- else if (loading && !isLoadingLabelVisible) safeSetTimeout(() => {
187
+ if (loading && !isLoadingLabelVisible) safeSetTimeout(() => {
188
188
  setIsLoadingLabelVisible(true);
189
189
  }, loadingLabelDelay);
190
190
  };
@@ -1,8 +1,7 @@
1
- import { canUseDOM } from "../utils/environment.js";
2
1
  import { warning } from "../utils/warning.js";
3
2
  import { MatchMediaContext } from "./MatchMediaContext.js";
4
3
  import { c } from "react-compiler-runtime";
5
- import React, { useContext, useEffect } from "react";
4
+ import { useContext, useSyncExternalStore } from "react";
6
5
  //#region src/hooks/useMedia.ts
7
6
  /**
8
7
  * `useMedia` will use the given `mediaQueryString` with `matchMedia` to
@@ -18,52 +17,54 @@ import React, { useContext, useEffect } from "react";
18
17
  * }
19
18
  */
20
19
  function useMedia(mediaQueryString, defaultState) {
21
- const $ = c(8);
22
- const features = useContext(MatchMediaContext);
20
+ const $ = c(9);
21
+ const contextValue = useContext(MatchMediaContext)[mediaQueryString];
23
22
  let t0;
24
- if ($[0] !== defaultState || $[1] !== features || $[2] !== mediaQueryString) {
25
- t0 = () => {
26
- if (features[mediaQueryString] !== void 0) return features[mediaQueryString];
27
- if (defaultState !== void 0) return defaultState;
28
- if (canUseDOM) return window.matchMedia(mediaQueryString).matches;
29
- warning(true, "`useMedia` When server side rendering, defaultState should be defined to prevent a hydration mismatches.");
30
- return false;
31
- };
32
- $[0] = defaultState;
33
- $[1] = features;
34
- $[2] = mediaQueryString;
35
- $[3] = t0;
36
- } else t0 = $[3];
37
- const [matches, setMatches] = React.useState(t0);
38
- if (features[mediaQueryString] !== void 0 && matches !== features[mediaQueryString]) setMatches(features[mediaQueryString]);
39
- let t1;
40
- let t2;
41
- if ($[4] !== features || $[5] !== mediaQueryString) {
42
- t1 = () => {
43
- if (features[mediaQueryString] !== void 0) return;
44
- const listener = function listener(event) {
45
- setMatches(event.matches);
46
- };
23
+ if ($[0] !== contextValue || $[1] !== mediaQueryString) {
24
+ t0 = (onStoreChange) => {
25
+ if (contextValue !== void 0) return _temp;
47
26
  const mediaQueryList = window.matchMedia(mediaQueryString);
48
- if (mediaQueryList.addEventListener) mediaQueryList.addEventListener("change", listener);
49
- else mediaQueryList.addListener(listener);
50
- setMatches(mediaQueryList.matches);
27
+ if (mediaQueryList.addEventListener) {
28
+ mediaQueryList.addEventListener("change", onStoreChange);
29
+ return () => {
30
+ mediaQueryList.removeEventListener("change", onStoreChange);
31
+ };
32
+ }
33
+ mediaQueryList.addListener(onStoreChange);
51
34
  return () => {
52
- if (mediaQueryList.addEventListener) mediaQueryList.removeEventListener("change", listener);
53
- else mediaQueryList.removeListener(listener);
35
+ mediaQueryList.removeListener(onStoreChange);
54
36
  };
55
37
  };
56
- t2 = [features, mediaQueryString];
57
- $[4] = features;
58
- $[5] = mediaQueryString;
59
- $[6] = t1;
60
- $[7] = t2;
61
- } else {
62
- t1 = $[6];
63
- t2 = $[7];
64
- }
65
- useEffect(t1, t2);
66
- return matches;
38
+ $[0] = contextValue;
39
+ $[1] = mediaQueryString;
40
+ $[2] = t0;
41
+ } else t0 = $[2];
42
+ const subscribe = t0;
43
+ let t1;
44
+ if ($[3] !== contextValue || $[4] !== mediaQueryString) {
45
+ t1 = () => {
46
+ if (contextValue !== void 0) return contextValue;
47
+ return window.matchMedia(mediaQueryString).matches;
48
+ };
49
+ $[3] = contextValue;
50
+ $[4] = mediaQueryString;
51
+ $[5] = t1;
52
+ } else t1 = $[5];
53
+ const getSnapshot = t1;
54
+ let t2;
55
+ if ($[6] !== contextValue || $[7] !== defaultState) {
56
+ t2 = () => {
57
+ if (contextValue !== void 0) return contextValue;
58
+ if (defaultState !== void 0) return defaultState;
59
+ warning(typeof window === "undefined", "`useMedia` When server side rendering, defaultState should be defined to prevent a hydration mismatches.");
60
+ return false;
61
+ };
62
+ $[6] = contextValue;
63
+ $[7] = defaultState;
64
+ $[8] = t2;
65
+ } else t2 = $[8];
66
+ return useSyncExternalStore(subscribe, getSnapshot, t2);
67
67
  }
68
+ function _temp() {}
68
69
  //#endregion
69
70
  export { useMedia };
@@ -1,39 +1,25 @@
1
1
  import ValidationAnimationContainer_module_css_default from "./ValidationAnimationContainer.module.css.js";
2
2
  import { c } from "react-compiler-runtime";
3
3
  import { jsx } from "react/jsx-runtime";
4
- import { useEffect, useState } from "react";
4
+ import { useState } from "react";
5
5
  //#region src/internal/components/ValidationAnimationContainer.tsx
6
6
  const ValidationAnimationContainer = (t0) => {
7
- const $ = c(10);
7
+ const $ = c(7);
8
8
  const { show, children } = t0;
9
9
  const [shouldRender, setRender] = useState(show);
10
+ if (show && !shouldRender) setRender(true);
10
11
  let t1;
11
- let t2;
12
12
  if ($[0] !== show) {
13
13
  t1 = () => {
14
- if (show) setRender(true);
14
+ if (!show) setRender(false);
15
15
  };
16
- t2 = [show];
17
16
  $[0] = show;
18
17
  $[1] = t1;
19
- $[2] = t2;
20
- } else {
21
- t1 = $[1];
22
- t2 = $[2];
23
- }
24
- useEffect(t1, t2);
25
- let t3;
26
- if ($[3] !== show) {
27
- t3 = () => {
28
- if (!show) setRender(false);
29
- };
30
- $[3] = show;
31
- $[4] = t3;
32
- } else t3 = $[4];
33
- const onAnimationEnd = t3;
34
- let t4;
35
- if ($[5] !== children || $[6] !== onAnimationEnd || $[7] !== shouldRender || $[8] !== show) {
36
- t4 = shouldRender ? /*#__PURE__*/ jsx("div", {
18
+ } else t1 = $[1];
19
+ const onAnimationEnd = t1;
20
+ let t2;
21
+ if ($[2] !== children || $[3] !== onAnimationEnd || $[4] !== shouldRender || $[5] !== show) {
22
+ t2 = shouldRender ? /*#__PURE__*/ jsx("div", {
37
23
  style: {
38
24
  height: show ? "auto" : 0,
39
25
  overflow: "hidden"
@@ -45,13 +31,13 @@ const ValidationAnimationContainer = (t0) => {
45
31
  children
46
32
  })
47
33
  }) : null;
48
- $[5] = children;
49
- $[6] = onAnimationEnd;
50
- $[7] = shouldRender;
51
- $[8] = show;
52
- $[9] = t4;
53
- } else t4 = $[9];
54
- return t4;
34
+ $[2] = children;
35
+ $[3] = onAnimationEnd;
36
+ $[4] = shouldRender;
37
+ $[5] = show;
38
+ $[6] = t2;
39
+ } else t2 = $[6];
40
+ return t2;
55
41
  };
56
42
  //#endregion
57
43
  export { ValidationAnimationContainer as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260707192909",
4
+ "version": "0.0.0-20260707192929",
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",