@open-pioneer/react-utils 4.4.0-dev-hmr.20251216142604 → 4.4.0-dev.20251222113627
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 +3 -2
- package/package.json +3 -3
- package/useEvent.js +7 -6
- package/useEvent.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# @open-pioneer/react-utils
|
|
2
2
|
|
|
3
|
-
## 4.4.0-dev
|
|
3
|
+
## 4.4.0-dev.20251222113627
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- 7087ea7: Support calling `useEvent()` callbacks in `useInsertionEffect()` or similar timings. Previously, `useEvent()` only worked correctly when used in `useLayoutEffect()` or later.
|
|
7
8
|
- 554d58e: Use `workspace:*` instead of `workspace:^` for local package references as default. This ensures that trails packages from this repository are always referenced with their exact version to avoid potential issues with version mismatches. If a project specifically wants to use other versions for some trails packages, a pnpm override can be used to force other versions.
|
|
8
9
|
- Updated dependencies [554d58e]
|
|
9
|
-
- @open-pioneer/core@4.4.0-dev
|
|
10
|
+
- @open-pioneer/core@4.4.0-dev.20251222113627
|
|
10
11
|
|
|
11
12
|
## 4.3.0
|
|
12
13
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/react-utils",
|
|
4
|
-
"version": "4.4.0-dev
|
|
4
|
+
"version": "4.4.0-dev.20251222113627",
|
|
5
5
|
"description": "Contains common react utilities used by the open pioneer trails project",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@chakra-ui/react": "^3.30.0",
|
|
18
18
|
"classnames": "^2.5.1",
|
|
19
|
-
"react": "^19.2.
|
|
20
|
-
"@open-pioneer/core": "4.4.0-dev
|
|
19
|
+
"react": "^19.2.3",
|
|
20
|
+
"@open-pioneer/core": "4.4.0-dev.20251222113627"
|
|
21
21
|
},
|
|
22
22
|
"exports": {
|
|
23
23
|
"./package.json": "./package.json",
|
package/useEvent.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { useRef,
|
|
1
|
+
import { useRef, useInsertionEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
function useEvent(handler) {
|
|
4
|
-
const handlerRef = useRef(
|
|
5
|
-
|
|
4
|
+
const handlerRef = useRef(void 0);
|
|
5
|
+
useInsertionEffect(() => {
|
|
6
6
|
handlerRef.current = handler;
|
|
7
7
|
});
|
|
8
|
-
const
|
|
8
|
+
const stableRef = useRef(void 0);
|
|
9
|
+
stableRef.current ??= function useEventHandler(...args) {
|
|
9
10
|
const currentHandler = handlerRef.current;
|
|
10
11
|
return currentHandler(...args);
|
|
11
|
-
}
|
|
12
|
-
return
|
|
12
|
+
};
|
|
13
|
+
return stableRef.current;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export { useEvent };
|
package/useEvent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEvent.js","sources":["useEvent.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"file":"useEvent.js","sources":["useEvent.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useInsertionEffect, useRef } from \"react\";\n\n/**\n * Creates an event handler with stable function identity.\n * The returned function will always invoke the most recent implementation of `handler`.\n *\n * The returned event handler can be used, for example, as an event handler in `useEffect()`.\n * Because the function identity is stable, `useEffect()` will not re-trigger if the implementation changes.\n *\n * > Warning: the function returned by `useEvent` must **not** be called during rendering.\n * > It can only be used in an effect or in a event handler callback.\n *\n * See also: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md\n */\nexport function useEvent<Args extends unknown[], Ret>(\n handler: (...args: Args) => Ret\n): typeof handler {\n const handlerRef = useRef<typeof handler>(undefined);\n\n // Earliest timing as of React 19\n useInsertionEffect(() => {\n handlerRef.current = handler;\n });\n\n // useRef instead of useMemo/useCallback for guaranteed single time construction.\n const stableRef = useRef<typeof handler>(undefined);\n stableRef.current ??= function useEventHandler(...args: Args): Ret {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const currentHandler = handlerRef.current!;\n return currentHandler(...args);\n };\n return stableRef.current;\n}\n"],"names":[],"mappings":";;AAgBO,SAAS,SACZ,OAAA,EACc;AACd,EAAA,MAAM,UAAA,GAAa,OAAuB,MAAS,CAAA;AAGnD,EAAA,kBAAA,CAAmB,MAAM;AACrB,IAAA,UAAA,CAAW,OAAA,GAAU,OAAA;AAAA,EACzB,CAAC,CAAA;AAGD,EAAA,MAAM,SAAA,GAAY,OAAuB,MAAS,CAAA;AAClD,EAAA,SAAA,CAAU,OAAA,KAAY,SAAS,eAAA,CAAA,GAAmB,IAAA,EAAiB;AAE/D,IAAA,MAAM,iBAAiB,UAAA,CAAW,OAAA;AAClC,IAAA,OAAO,cAAA,CAAe,GAAG,IAAI,CAAA;AAAA,EACjC,CAAA;AACA,EAAA,OAAO,SAAA,CAAU,OAAA;AACrB;;;;"}
|