@primer/react 38.1.0-rc.430f77ae3 → 38.1.0-rc.6118e2738
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 +2 -0
- package/dist/hooks/{useMedia.d.ts → useMediaUnsafeSSR.d.ts} +9 -6
- package/dist/hooks/useMediaUnsafeSSR.d.ts.map +1 -0
- package/dist/hooks/{useMedia.js → useMediaUnsafeSSR.js} +2 -2
- package/dist/hooks/useResponsiveValue.d.ts +2 -0
- package/dist/hooks/useResponsiveValue.d.ts.map +1 -1
- package/dist/hooks/useResponsiveValue.js +9 -5
- package/package.json +5 -4
- package/dist/hooks/useMedia.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
- [#7063](https://github.com/primer/react/pull/7063) [`247c66a`](https://github.com/primer/react/commit/247c66a3c297afba73c6e9e3842cc15ff8a845c1) Thanks [@francinelucca](https://github.com/francinelucca)! - Feat: popover implement click outside
|
|
8
8
|
|
|
9
|
+
- [#7070](https://github.com/primer/react/pull/7070) [`f7dfa7d`](https://github.com/primer/react/commit/f7dfa7d5954961834d0ec360d6b218237e75bf96) Thanks [@hectahertz](https://github.com/hectahertz)! - Add SSR warnings to useMediaUnsafeSSR and useResponsiveValue.
|
|
10
|
+
|
|
9
11
|
### Patch Changes
|
|
10
12
|
|
|
11
13
|
- [#7060](https://github.com/primer/react/pull/7060) [`3468793`](https://github.com/primer/react/commit/3468793e15269d6d9f226ee7844921e44bfc4622) Thanks [@francinelucca](https://github.com/francinelucca)! - @primer/react: chore(Dialog): allow direct children
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
/**
|
|
3
|
-
* `
|
|
3
|
+
* `useMediaUnsafeSSR` will use the given `mediaQueryString` with `matchMedia` to
|
|
4
4
|
* determine if the document matches the media query string.
|
|
5
5
|
*
|
|
6
|
-
* If `MatchMedia` is used as an ancestor, `
|
|
6
|
+
* If `MatchMedia` is used as an ancestor, `useMediaUnsafeSSR` will instead use the
|
|
7
7
|
* value of the media query string, if available
|
|
8
8
|
*
|
|
9
|
+
* Warning: If rendering on the server, and no `defaultState` is provided,
|
|
10
|
+
* this could cause a hydration mismatch between server and client.
|
|
11
|
+
*
|
|
9
12
|
* @example
|
|
10
13
|
* function Example() {
|
|
11
|
-
* const coarsePointer =
|
|
14
|
+
* const coarsePointer = useMediaUnsafeSSR('(pointer: coarse)');
|
|
12
15
|
* // ...
|
|
13
16
|
* }
|
|
14
17
|
*/
|
|
15
|
-
export declare function
|
|
18
|
+
export declare function useMediaUnsafeSSR(mediaQueryString: string, defaultState?: boolean): boolean;
|
|
16
19
|
type MediaQueryFeatures = {
|
|
17
20
|
[key: string]: boolean | undefined;
|
|
18
21
|
};
|
|
@@ -22,7 +25,7 @@ type MatchMediaProps = {
|
|
|
22
25
|
};
|
|
23
26
|
/**
|
|
24
27
|
* Use `MatchMedia` to emulate media conditions by passing in feature
|
|
25
|
-
* queries to the `features` prop. If a component uses `
|
|
28
|
+
* queries to the `features` prop. If a component uses `useMediaUnsafeSSR` with the
|
|
26
29
|
* feature passed in to `MatchMedia` it will force its value to match what is
|
|
27
30
|
* provided to `MatchMedia`
|
|
28
31
|
*
|
|
@@ -36,4 +39,4 @@ type MatchMediaProps = {
|
|
|
36
39
|
*/
|
|
37
40
|
export declare function MatchMedia({ children, features }: MatchMediaProps): React.JSX.Element;
|
|
38
41
|
export {};
|
|
39
|
-
//# sourceMappingURL=
|
|
42
|
+
//# sourceMappingURL=useMediaUnsafeSSR.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMediaUnsafeSSR.d.ts","sourceRoot":"","sources":["../../src/hooks/useMediaUnsafeSSR.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuD,MAAM,OAAO,CAAA;AAI3E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,WAoEjF;AAED,KAAK,kBAAkB,GAAG;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAA;CACnC,CAAA;AAOD,KAAK,eAAe,GAAG;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,QAAQ,CAAC,EAAE,kBAAkB,CAAA;CAC9B,CAAA;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,EAAC,QAAQ,EAAE,QAA0B,EAAC,EAAE,eAAe,qBAGjF"}
|
|
@@ -2,7 +2,7 @@ import { c } from 'react-compiler-runtime';
|
|
|
2
2
|
import React, { useContext, createContext, useEffect } from 'react';
|
|
3
3
|
import 'react/jsx-runtime';
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function useMediaUnsafeSSR(mediaQueryString, defaultState) {
|
|
6
6
|
const $ = c(12);
|
|
7
7
|
const features = useContext(MatchMediaContext);
|
|
8
8
|
let t0;
|
|
@@ -83,4 +83,4 @@ function useMedia(mediaQueryString, defaultState) {
|
|
|
83
83
|
// unavailable through devtools
|
|
84
84
|
const MatchMediaContext = /*#__PURE__*/createContext({});
|
|
85
85
|
|
|
86
|
-
export {
|
|
86
|
+
export { useMediaUnsafeSSR };
|
|
@@ -23,6 +23,8 @@ export declare function isResponsiveValue(value: any): value is ResponsiveValue<
|
|
|
23
23
|
* Resolves responsive values based on the current viewport width.
|
|
24
24
|
* For example, if the current viewport width is narrow (less than 768px), the value of `{regular: 'foo', narrow: 'bar'}` will resolve to `'bar'`.
|
|
25
25
|
*
|
|
26
|
+
* Warning: This hook is not fully SSR compatible as it relies on `useMediaUnsafeSSR` without a `defaultState`. Using `getResponsiveAttributes` is preferred to avoid hydration mismatches.
|
|
27
|
+
*
|
|
26
28
|
* @example
|
|
27
29
|
* const value = useResponsiveValue({regular: 'foo', narrow: 'bar'})
|
|
28
30
|
* console.log(value) // 'bar'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResponsiveValue.d.ts","sourceRoot":"","sources":["../../src/hooks/useResponsiveValue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useResponsiveValue.d.ts","sourceRoot":"","sources":["../../src/hooks/useResponsiveValue.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,cAAc;;;;CAI1B,CAAA;AAED,MAAM,MAAM,eAAe,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,EAAE,KAAK,GAAG,QAAQ,IAAI;IAC5E,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,QAAQ,CAAA;IAClB,IAAI,CAAC,EAAE,KAAK,CAAA;CACb,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAChC,CAAC,CAAC,SAAS,eAAe,CAAC,MAAM,QAAQ,EAAE,MAAM,OAAO,EAAE,MAAM,KAAK,CAAC,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,CAAC,GAE5G,OAAO,CAAC,CAAC,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAA;AAEpC;;;GAGG;AAEH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,eAAe,CAAC,GAAG,CAAC,CAE3E;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC,GAAG,CAAC,CAgC7F"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMediaUnsafeSSR } from './useMediaUnsafeSSR.js';
|
|
2
|
+
import { canUseDOM } from '../utils/environment.js';
|
|
3
|
+
import { warning } from '../utils/warning.js';
|
|
2
4
|
|
|
3
5
|
// This file contains utilities for working with responsive values.
|
|
4
6
|
|
|
@@ -33,15 +35,17 @@ function isResponsiveValue(value) {
|
|
|
33
35
|
* Resolves responsive values based on the current viewport width.
|
|
34
36
|
* For example, if the current viewport width is narrow (less than 768px), the value of `{regular: 'foo', narrow: 'bar'}` will resolve to `'bar'`.
|
|
35
37
|
*
|
|
38
|
+
* Warning: This hook is not fully SSR compatible as it relies on `useMediaUnsafeSSR` without a `defaultState`. Using `getResponsiveAttributes` is preferred to avoid hydration mismatches.
|
|
39
|
+
*
|
|
36
40
|
* @example
|
|
37
41
|
* const value = useResponsiveValue({regular: 'foo', narrow: 'bar'})
|
|
38
42
|
* console.log(value) // 'bar'
|
|
39
43
|
*/
|
|
40
|
-
// TODO: Improve SSR support
|
|
41
44
|
function useResponsiveValue(value, fallback) {
|
|
42
|
-
const isNarrowViewport =
|
|
43
|
-
const isRegularViewport =
|
|
44
|
-
const isWideViewport =
|
|
45
|
+
const isNarrowViewport = useMediaUnsafeSSR(viewportRanges.narrow, false);
|
|
46
|
+
const isRegularViewport = useMediaUnsafeSSR(viewportRanges.regular, false);
|
|
47
|
+
const isWideViewport = useMediaUnsafeSSR(viewportRanges.wide, false);
|
|
48
|
+
process.env.NODE_ENV !== "production" ? warning(!canUseDOM, "`useResponsiveValue` is not fully SSR compatible as it relies on `useMediaUnsafeSSR` without a `defaultState`. Using `getResponsiveAttributes` is preferred to avoid hydration mismatches.") : void 0;
|
|
45
49
|
if (isResponsiveValue(value)) {
|
|
46
50
|
const responsiveValue = value;
|
|
47
51
|
if (isNarrowViewport && "narrow" in responsiveValue) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primer/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "38.1.0-rc.
|
|
4
|
+
"version": "38.1.0-rc.6118e2738",
|
|
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",
|
|
@@ -51,7 +51,10 @@
|
|
|
51
51
|
"type-check": "tsc --noEmit",
|
|
52
52
|
"type-css-modules": "tcm -p src/**/*.module.css"
|
|
53
53
|
},
|
|
54
|
-
"repository":
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+https://github.com/primer/react.git"
|
|
57
|
+
},
|
|
55
58
|
"keywords": [
|
|
56
59
|
"react",
|
|
57
60
|
"components",
|
|
@@ -129,7 +132,6 @@
|
|
|
129
132
|
"@types/react": "18.3.11",
|
|
130
133
|
"@types/react-dom": "18.3.1",
|
|
131
134
|
"@types/react-is": "18.3.1",
|
|
132
|
-
"@types/react-test-renderer": "18.3.1",
|
|
133
135
|
"@vitejs/plugin-react": "^4.3.3",
|
|
134
136
|
"afterframe": "^1.0.2",
|
|
135
137
|
"ajv": "8.16.0",
|
|
@@ -166,7 +168,6 @@
|
|
|
166
168
|
"react": "18.3.1",
|
|
167
169
|
"react-dom": "18.3.1",
|
|
168
170
|
"react-is": "18.3.1",
|
|
169
|
-
"react-test-renderer": "18.3.1",
|
|
170
171
|
"recast": "0.23.7",
|
|
171
172
|
"rimraf": "5.0.5",
|
|
172
173
|
"rollup": "4.52.5",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMedia.d.ts","sourceRoot":"","sources":["../../src/hooks/useMedia.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuD,MAAM,OAAO,CAAA;AAI3E;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,WAoExE;AAED,KAAK,kBAAkB,GAAG;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAA;CACnC,CAAA;AAOD,KAAK,eAAe,GAAG;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,QAAQ,CAAC,EAAE,kBAAkB,CAAA;CAC9B,CAAA;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,EAAC,QAAQ,EAAE,QAA0B,EAAC,EAAE,eAAe,qBAGjF"}
|