@primer/react 0.0.0-20260707163701 → 0.0.0-20260707164108
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,15 +1,15 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20260707164108
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- [#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).
|
|
8
|
-
|
|
9
7
|
- Fake entry to force publishing
|
|
10
8
|
|
|
11
9
|
- [#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
10
|
|
|
11
|
+
- [#8023](https://github.com/primer/react/pull/8023) [`e2e7d77`](https://github.com/primer/react/commit/e2e7d7712b79dfe1c3c60d8b461e55a0e7cd8c58) Thanks [@mattcosta7](https://github.com/mattcosta7)! - FormControl: Avoid an extra re-render when showing a validation message.
|
|
12
|
+
|
|
13
13
|
## 38.31.0
|
|
14
14
|
|
|
15
15
|
### Minor Changes
|
|
@@ -99,11 +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
|
-
|
|
103
|
-
if (prevOpen !== open) {
|
|
104
|
-
setPrevOpen(open);
|
|
102
|
+
useEffect(() => {
|
|
105
103
|
setIntermediateSelected(isSingleSelectModal ? selected : void 0);
|
|
106
|
-
}
|
|
104
|
+
}, [
|
|
105
|
+
isSingleSelectModal,
|
|
106
|
+
open,
|
|
107
|
+
selected
|
|
108
|
+
]);
|
|
107
109
|
const onListContainerRefChanged = useCallback((node) => {
|
|
108
110
|
setListContainerElement(node);
|
|
109
111
|
if (!node && needsNoItemsAnnouncement) setNeedsNoItemsAnnouncement(false);
|
|
@@ -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);
|
|
183
182
|
let t8;
|
|
184
183
|
let t9;
|
|
185
184
|
if ($[31] !== isLoadingLabelVisible || $[32] !== loading || $[33] !== loadingLabelDelay || $[34] !== safeSetTimeout) {
|
|
186
185
|
t8 = () => {
|
|
187
|
-
if (loading &&
|
|
186
|
+
if (!loading && isLoadingLabelVisible) setIsLoadingLabelVisible(false);
|
|
187
|
+
else if (loading && !isLoadingLabelVisible) safeSetTimeout(() => {
|
|
188
188
|
setIsLoadingLabelVisible(true);
|
|
189
189
|
}, loadingLabelDelay);
|
|
190
190
|
};
|
package/dist/hooks/useMedia.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { canUseDOM } from "../utils/environment.js";
|
|
1
2
|
import { warning } from "../utils/warning.js";
|
|
2
3
|
import { MatchMediaContext } from "./MatchMediaContext.js";
|
|
3
4
|
import { c } from "react-compiler-runtime";
|
|
4
|
-
import { useContext,
|
|
5
|
+
import React, { useContext, useEffect } from "react";
|
|
5
6
|
//#region src/hooks/useMedia.ts
|
|
6
7
|
/**
|
|
7
8
|
* `useMedia` will use the given `mediaQueryString` with `matchMedia` to
|
|
@@ -17,54 +18,52 @@ import { useContext, useSyncExternalStore } from "react";
|
|
|
17
18
|
* }
|
|
18
19
|
*/
|
|
19
20
|
function useMedia(mediaQueryString, defaultState) {
|
|
20
|
-
const $ = c(
|
|
21
|
-
const
|
|
21
|
+
const $ = c(8);
|
|
22
|
+
const features = useContext(MatchMediaContext);
|
|
22
23
|
let t0;
|
|
23
|
-
if ($[0] !==
|
|
24
|
-
t0 = (
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
mediaQueryList.removeEventListener("change", onStoreChange);
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
mediaQueryList.addListener(onStoreChange);
|
|
34
|
-
return () => {
|
|
35
|
-
mediaQueryList.removeListener(onStoreChange);
|
|
36
|
-
};
|
|
24
|
+
if ($[0] !== defaultState || $[1] !== features || $[2] !== mediaQueryString) {
|
|
25
|
+
t0 = () => {
|
|
26
|
+
if (features[mediaQueryString] !== void 0) return features[mediaQueryString];
|
|
27
|
+
if (defaultState !== void 0) return defaultState;
|
|
28
|
+
if (canUseDOM) return window.matchMedia(mediaQueryString).matches;
|
|
29
|
+
warning(true, "`useMedia` When server side rendering, defaultState should be defined to prevent a hydration mismatches.");
|
|
30
|
+
return false;
|
|
37
31
|
};
|
|
38
|
-
$[0] =
|
|
39
|
-
$[1] =
|
|
40
|
-
$[2] =
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
$[0] = defaultState;
|
|
33
|
+
$[1] = features;
|
|
34
|
+
$[2] = mediaQueryString;
|
|
35
|
+
$[3] = t0;
|
|
36
|
+
} else t0 = $[3];
|
|
37
|
+
const [matches, setMatches] = React.useState(t0);
|
|
38
|
+
if (features[mediaQueryString] !== void 0 && matches !== features[mediaQueryString]) setMatches(features[mediaQueryString]);
|
|
43
39
|
let t1;
|
|
44
|
-
if ($[3] !== contextValue || $[4] !== mediaQueryString) {
|
|
45
|
-
t1 = () => {
|
|
46
|
-
if (contextValue !== void 0) return contextValue;
|
|
47
|
-
return window.matchMedia(mediaQueryString).matches;
|
|
48
|
-
};
|
|
49
|
-
$[3] = contextValue;
|
|
50
|
-
$[4] = mediaQueryString;
|
|
51
|
-
$[5] = t1;
|
|
52
|
-
} else t1 = $[5];
|
|
53
|
-
const getSnapshot = t1;
|
|
54
40
|
let t2;
|
|
55
|
-
if ($[
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
if ($[4] !== features || $[5] !== mediaQueryString) {
|
|
42
|
+
t1 = () => {
|
|
43
|
+
if (features[mediaQueryString] !== void 0) return;
|
|
44
|
+
const listener = function listener(event) {
|
|
45
|
+
setMatches(event.matches);
|
|
46
|
+
};
|
|
47
|
+
const mediaQueryList = window.matchMedia(mediaQueryString);
|
|
48
|
+
if (mediaQueryList.addEventListener) mediaQueryList.addEventListener("change", listener);
|
|
49
|
+
else mediaQueryList.addListener(listener);
|
|
50
|
+
setMatches(mediaQueryList.matches);
|
|
51
|
+
return () => {
|
|
52
|
+
if (mediaQueryList.addEventListener) mediaQueryList.removeEventListener("change", listener);
|
|
53
|
+
else mediaQueryList.removeListener(listener);
|
|
54
|
+
};
|
|
61
55
|
};
|
|
62
|
-
|
|
63
|
-
$[
|
|
64
|
-
$[
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
t2 = [features, mediaQueryString];
|
|
57
|
+
$[4] = features;
|
|
58
|
+
$[5] = mediaQueryString;
|
|
59
|
+
$[6] = t1;
|
|
60
|
+
$[7] = t2;
|
|
61
|
+
} else {
|
|
62
|
+
t1 = $[6];
|
|
63
|
+
t2 = $[7];
|
|
64
|
+
}
|
|
65
|
+
useEffect(t1, t2);
|
|
66
|
+
return matches;
|
|
67
67
|
}
|
|
68
|
-
function _temp() {}
|
|
69
68
|
//#endregion
|
|
70
69
|
export { useMedia };
|
|
@@ -4,23 +4,41 @@ import { jsx } from "react/jsx-runtime";
|
|
|
4
4
|
import { useState } from "react";
|
|
5
5
|
//#region src/internal/components/ValidationAnimationContainer.tsx
|
|
6
6
|
const ValidationAnimationContainer = (t0) => {
|
|
7
|
-
const $ = c(
|
|
8
|
-
|
|
7
|
+
const $ = c(14);
|
|
8
|
+
let children;
|
|
9
|
+
let rest;
|
|
10
|
+
let show;
|
|
11
|
+
let style;
|
|
12
|
+
if ($[0] !== t0) {
|
|
13
|
+
({show, children, style, ...rest} = t0);
|
|
14
|
+
$[0] = t0;
|
|
15
|
+
$[1] = children;
|
|
16
|
+
$[2] = rest;
|
|
17
|
+
$[3] = show;
|
|
18
|
+
$[4] = style;
|
|
19
|
+
} else {
|
|
20
|
+
children = $[1];
|
|
21
|
+
rest = $[2];
|
|
22
|
+
show = $[3];
|
|
23
|
+
style = $[4];
|
|
24
|
+
}
|
|
9
25
|
const [shouldRender, setRender] = useState(show);
|
|
10
26
|
if (show && !shouldRender) setRender(true);
|
|
11
27
|
let t1;
|
|
12
|
-
if ($[
|
|
28
|
+
if ($[5] !== show) {
|
|
13
29
|
t1 = () => {
|
|
14
30
|
if (!show) setRender(false);
|
|
15
31
|
};
|
|
16
|
-
$[
|
|
17
|
-
$[
|
|
18
|
-
} else t1 = $[
|
|
32
|
+
$[5] = show;
|
|
33
|
+
$[6] = t1;
|
|
34
|
+
} else t1 = $[6];
|
|
19
35
|
const onAnimationEnd = t1;
|
|
20
36
|
let t2;
|
|
21
|
-
if ($[
|
|
37
|
+
if ($[7] !== children || $[8] !== onAnimationEnd || $[9] !== rest || $[10] !== shouldRender || $[11] !== show || $[12] !== style) {
|
|
22
38
|
t2 = shouldRender ? /*#__PURE__*/ jsx("div", {
|
|
39
|
+
...rest,
|
|
23
40
|
style: {
|
|
41
|
+
...style,
|
|
24
42
|
height: show ? "auto" : 0,
|
|
25
43
|
overflow: "hidden"
|
|
26
44
|
},
|
|
@@ -31,12 +49,14 @@ const ValidationAnimationContainer = (t0) => {
|
|
|
31
49
|
children
|
|
32
50
|
})
|
|
33
51
|
}) : null;
|
|
34
|
-
$[
|
|
35
|
-
$[
|
|
36
|
-
$[
|
|
37
|
-
$[
|
|
38
|
-
$[
|
|
39
|
-
|
|
52
|
+
$[7] = children;
|
|
53
|
+
$[8] = onAnimationEnd;
|
|
54
|
+
$[9] = rest;
|
|
55
|
+
$[10] = shouldRender;
|
|
56
|
+
$[11] = show;
|
|
57
|
+
$[12] = style;
|
|
58
|
+
$[13] = t2;
|
|
59
|
+
} else t2 = $[13];
|
|
40
60
|
return t2;
|
|
41
61
|
};
|
|
42
62
|
//#endregion
|
package/package.json
CHANGED