@primer/react 38.1.0-rc.0613425e9 → 38.1.0-rc.1e88ae1e6

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
@@ -8,8 +8,6 @@
8
8
 
9
9
  - [#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
10
10
 
11
- - [#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.
12
-
13
11
  ### Patch Changes
14
12
 
15
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,21 +1,18 @@
1
1
  import React from 'react';
2
2
  /**
3
- * `useMediaUnsafeSSR` will use the given `mediaQueryString` with `matchMedia` to
3
+ * `useMedia` 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, `useMediaUnsafeSSR` will instead use the
6
+ * If `MatchMedia` is used as an ancestor, `useMedia` 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
- *
12
9
  * @example
13
10
  * function Example() {
14
- * const coarsePointer = useMediaUnsafeSSR('(pointer: coarse)');
11
+ * const coarsePointer = useMedia('(pointer: coarse)');
15
12
  * // ...
16
13
  * }
17
14
  */
18
- export declare function useMediaUnsafeSSR(mediaQueryString: string, defaultState?: boolean): boolean;
15
+ export declare function useMedia(mediaQueryString: string, defaultState?: boolean): boolean;
19
16
  type MediaQueryFeatures = {
20
17
  [key: string]: boolean | undefined;
21
18
  };
@@ -25,7 +22,7 @@ type MatchMediaProps = {
25
22
  };
26
23
  /**
27
24
  * Use `MatchMedia` to emulate media conditions by passing in feature
28
- * queries to the `features` prop. If a component uses `useMediaUnsafeSSR` with the
25
+ * queries to the `features` prop. If a component uses `useMedia` with the
29
26
  * feature passed in to `MatchMedia` it will force its value to match what is
30
27
  * provided to `MatchMedia`
31
28
  *
@@ -39,4 +36,4 @@ type MatchMediaProps = {
39
36
  */
40
37
  export declare function MatchMedia({ children, features }: MatchMediaProps): React.JSX.Element;
41
38
  export {};
42
- //# sourceMappingURL=useMediaUnsafeSSR.d.ts.map
39
+ //# sourceMappingURL=useMedia.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -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 useMediaUnsafeSSR(mediaQueryString, defaultState) {
5
+ function useMedia(mediaQueryString, defaultState) {
6
6
  const $ = c(12);
7
7
  const features = useContext(MatchMediaContext);
8
8
  let t0;
@@ -83,4 +83,4 @@ function useMediaUnsafeSSR(mediaQueryString, defaultState) {
83
83
  // unavailable through devtools
84
84
  const MatchMediaContext = /*#__PURE__*/createContext({});
85
85
 
86
- export { useMediaUnsafeSSR };
86
+ export { useMedia };
@@ -23,8 +23,6 @@ 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
- *
28
26
  * @example
29
27
  * const value = useResponsiveValue({regular: 'foo', narrow: 'bar'})
30
28
  * console.log(value) // 'bar'
@@ -1 +1 @@
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
+ {"version":3,"file":"useResponsiveValue.d.ts","sourceRoot":"","sources":["../../src/hooks/useResponsiveValue.ts"],"names":[],"mappings":"AAQA,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;;;;;;;GAOG;AAEH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC,GAAG,CAAC,CA0B7F"}
@@ -1,6 +1,4 @@
1
- import { useMediaUnsafeSSR } from './useMediaUnsafeSSR.js';
2
- import { canUseDOM } from '../utils/environment.js';
3
- import { warning } from '../utils/warning.js';
1
+ import { useMedia } from './useMedia.js';
4
2
 
5
3
  // This file contains utilities for working with responsive values.
6
4
 
@@ -35,17 +33,15 @@ function isResponsiveValue(value) {
35
33
  * Resolves responsive values based on the current viewport width.
36
34
  * For example, if the current viewport width is narrow (less than 768px), the value of `{regular: 'foo', narrow: 'bar'}` will resolve to `'bar'`.
37
35
  *
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
- *
40
36
  * @example
41
37
  * const value = useResponsiveValue({regular: 'foo', narrow: 'bar'})
42
38
  * console.log(value) // 'bar'
43
39
  */
40
+ // TODO: Improve SSR support
44
41
  function useResponsiveValue(value, fallback) {
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;
42
+ const isNarrowViewport = useMedia(viewportRanges.narrow, false);
43
+ const isRegularViewport = useMedia(viewportRanges.regular, false);
44
+ const isWideViewport = useMedia(viewportRanges.wide, false);
49
45
  if (isResponsiveValue(value)) {
50
46
  const responsiveValue = value;
51
47
  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.0613425e9",
4
+ "version": "38.1.0-rc.1e88ae1e6",
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",
@@ -1 +0,0 @@
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"}