@primer/react 38.25.0-rc.89740d738 → 38.25.0-rc.c42b3864e

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
@@ -6,6 +6,10 @@
6
6
 
7
7
  - [#7852](https://github.com/primer/react/pull/7852) [`5504680`](https://github.com/primer/react/commit/5504680614bacc2ce3eecaaa55d10887e6fb152d) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Card: Add `data-component` attributes to `Card` and its subcomponents (`Icon`, `Image`, `Heading`, `Description`, `Metadata`, `Menu`). Add an `as` prop (`'div' | 'section'`) so standalone Cards can render as a labelled region landmark; `as="section"` requires `aria-label` or `aria-labelledby`. `Card` now requires `children`. Also improves docs and stories.
8
8
 
9
+ ### Patch Changes
10
+
11
+ - [#7843](https://github.com/primer/react/pull/7843) [`fc571fd`](https://github.com/primer/react/commit/fc571fd8c3899f19a1dd9e77b8a22f6528d776e2) Thanks [@joshblack](https://github.com/joshblack)! - Update useMergedRefs so that in React 18 no warning is emitted
12
+
9
13
  ## 38.24.0
10
14
 
11
15
  ### Minor Changes
@@ -29,7 +29,7 @@ import type { ForwardedRef, Ref as StandardRef } from 'react';
29
29
  * return <button ref={combinedRef} />
30
30
  * }
31
31
  */
32
- export declare function useMergedRefs<T>(refA: Ref<T | null>, refB: Ref<T | null>): (value: T | null) => () => void;
32
+ export declare function useMergedRefs<T>(refA: Ref<T | null>, refB: Ref<T | null>): (value: T | null) => (() => void) | undefined;
33
33
  type CleanupFunction = () => void;
34
34
  /**
35
35
  * React 19 supports callback refs that can return a cleanup function. If a cleanup function is returned, the
@@ -1 +1 @@
1
- {"version":3,"file":"useMergedRefs.d.ts","sourceRoot":"","sources":["../../src/hooks/useMergedRefs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,GAAG,IAAI,WAAW,EAAmB,MAAM,OAAO,CAAA;AAG7E;;;;;;;;;;;;;;;;;;;;;;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CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA"}
@@ -1,5 +1,15 @@
1
1
  import { c } from 'react-compiler-runtime';
2
2
  import 'react';
3
+ import { reactMajorVersion, isExperimentalReactVersion } from '../utils/environment.js';
4
+
5
+ /**
6
+ * Cleanup functions for refs were introduced in React 19. For feature detection,
7
+ * we look to see if current version of React is >= 19 or if it is an
8
+ * experimental version of React
9
+ *
10
+ * @see https://react.dev/blog/2024/12/05/react-19
11
+ */
12
+ const supportsRefCleanup = reactMajorVersion >= 19 || isExperimentalReactVersion;
3
13
 
4
14
  /**
5
15
  * Combine two refs of matching type (typically an external or forwarded ref and an internal `useRef` object or
@@ -38,6 +48,9 @@ function useMergedRefs(refA, refB) {
38
48
  t0 = value => {
39
49
  const cleanupA = setRef(refA, value);
40
50
  const cleanupB = setRef(refB, value);
51
+ if (!supportsRefCleanup) {
52
+ return;
53
+ }
41
54
  return () => {
42
55
  if (cleanupA) {
43
56
  cleanupA();
@@ -3,5 +3,8 @@
3
3
  *
4
4
  * @see https://github.com/facebook/fbjs/blob/4d1751311d3f67af2dcce2e40df8512a23c7b9c6/packages/fbjs/src/core/ExecutionEnvironment.js#L12
5
5
  */
6
- export const canUseDOM: boolean;
6
+ declare const canUseDOM: boolean;
7
+ declare const reactMajorVersion: number;
8
+ declare const isExperimentalReactVersion: boolean;
9
+ export { canUseDOM, reactMajorVersion, isExperimentalReactVersion };
7
10
  //# sourceMappingURL=environment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gCAA8G"}
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,QAAA,MAAM,SAAS,SAAwF,CAAA;AAWvG,QAAA,MAAM,iBAAiB,QAAgC,CAAA;AAGvD,QAAA,MAAM,0BAA0B,SAAiD,CAAA;AAEjF,OAAO,EAAC,SAAS,EAAE,iBAAiB,EAAE,0BAA0B,EAAC,CAAA"}
@@ -1,9 +1,24 @@
1
+ import { version } from 'react';
2
+
1
3
  /**
2
4
  * Indicate whether current execution environment can access the DOM.
3
5
  *
4
6
  * @see https://github.com/facebook/fbjs/blob/4d1751311d3f67af2dcce2e40df8512a23c7b9c6/packages/fbjs/src/core/ExecutionEnvironment.js#L12
5
7
  */
6
- // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
8
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition,ssr-friendly/no-dom-globals-in-module-scope
7
9
  const canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
8
10
 
9
- export { canUseDOM };
11
+ // Grab the major version from react. This could be formatted as any valid
12
+ // semver version, e.g.:
13
+ //
14
+ // - 19.0.0
15
+ // - 19.0.0-rc.1
16
+ // - 0.0.0-{channel}-{commit}-{time}
17
+ //
18
+ // So we only pull the first part of the version and parse it.
19
+ const reactVersion = version.split('.');
20
+ const reactMajorVersion = parseInt(reactVersion[0], 10);
21
+ const EXPERIMENTAL_REACT_VERSION_REGEX = /^0\.0\.0-experimental-[a-f0-9]{8}-\d{8}$/;
22
+ const isExperimentalReactVersion = EXPERIMENTAL_REACT_VERSION_REGEX.test(version);
23
+
24
+ export { canUseDOM, isExperimentalReactVersion, reactMajorVersion };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "38.25.0-rc.89740d738",
4
+ "version": "38.25.0-rc.c42b3864e",
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",