@primer/react 38.46.0-rc.18db27ff8 → 38.46.0-rc.4db999d82

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
@@ -10,6 +10,8 @@
10
10
 
11
11
  - [#8628](https://github.com/primer/react/pull/8628) [`41f29c8`](https://github.com/primer/react/commit/41f29c845663936043618af29dcb71de4c9384b2) Thanks [@joshblack](https://github.com/joshblack)! - SkeletonAvatar, SkeletonText: Preserve the requested size and shape regardless of stylesheet load order
12
12
 
13
+ - [#8562](https://github.com/primer/react/pull/8562) [`ee46232`](https://github.com/primer/react/commit/ee46232fafa24701415b21eed60cca68e589cf1c) Thanks [@joshblack](https://github.com/joshblack)! - useOnEscapePress, useOnOutsideClick: Improve performance when callbacks change between renders.
14
+
13
15
  ## 38.45.0
14
16
 
15
17
  ### Minor Changes
@@ -12,6 +12,8 @@
12
12
  * callback. Each callback has the chance to call `.preventDefault()` on the
13
13
  * event to prevent further callbacks.
14
14
  *
15
+ * Callback changes do not re-register the document listener.
16
+ *
15
17
  * @param callback {(e: KeyboardEvent) => void} The callback that gets executed
16
18
  * when the Escape key is pressed. The KeyboardEvent generated by the Escape
17
19
  * keypress is passed as the only argument.
@@ -1,4 +1,5 @@
1
- import { useCallback, useEffect, useMemo } from "react";
1
+ import { useEffectCallback } from "../internal/hooks/useEffectCallback.js";
2
+ import { useCallback, useEffect, useState } from "react";
2
3
  //#region src/hooks/useOnEscapePress.ts
3
4
  /**
4
5
  * Calls all handlers in reverse order
@@ -31,6 +32,8 @@ let handlerId = 0;
31
32
  * callback. Each callback has the chance to call `.preventDefault()` on the
32
33
  * event to prevent further callbacks.
33
34
  *
35
+ * Callback changes do not re-register the document listener.
36
+ *
34
37
  * @param callback {(e: KeyboardEvent) => void} The callback that gets executed
35
38
  * when the Escape key is pressed. The KeyboardEvent generated by the Escape
36
39
  * keypress is passed as the only argument.
@@ -41,10 +44,14 @@ let handlerId = 0;
41
44
  */
42
45
  const useOnEscapePress = (onEscape, callbackDependencies = [onEscape]) => {
43
46
  const escapeCallback = useCallback(onEscape, callbackDependencies);
44
- const handler = useCallback((event) => {
47
+ const handler = useEffectCallback((event) => {
45
48
  if (event.key === "Escape") escapeCallback(event);
46
- }, [escapeCallback]);
47
- const id = useMemo(() => handlerId++, []);
49
+ });
50
+ const [id] = useState(() => {
51
+ const id = handlerId;
52
+ handlerId += 1;
53
+ return id;
54
+ });
48
55
  useEffect(() => {
49
56
  if (Object.keys(registry).length === 0) document.addEventListener("keydown", handleEscape);
50
57
  register(id, handler);
@@ -1,4 +1,5 @@
1
1
  import { c } from "../utils/react-compiler-runtime.js";
2
+ import { useEffectCallback } from "../internal/hooks/useEffectCallback.js";
2
3
  import { useEffect, useState } from "react";
3
4
  //#region src/hooks/useOnOutsideClick.tsx
4
5
  const stopPropagation = true;
@@ -40,7 +41,7 @@ const useOnOutsideClick = (t0) => {
40
41
  $[2] = onClickOutside;
41
42
  $[3] = t1;
42
43
  } else t1 = $[3];
43
- const handler = t1;
44
+ const handler = useEffectCallback(t1);
44
45
  let t2;
45
46
  let t3;
46
47
  if ($[4] !== handler || $[5] !== id_0) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "38.46.0-rc.18db27ff8",
4
+ "version": "38.46.0-rc.4db999d82",
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",