@lynx-js/lynx-ui-common 3.131.0 → 3.133.0

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
@@ -1,5 +1,11 @@
1
1
  # @lynx-js/lynx-ui-common
2
2
 
3
+ ## 3.133.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add an experimental `usePreCommit` hook for running main-thread work before native commit. ([#188](https://github.com/lynx-family/lynx-ui/pull/188))
8
+
3
9
  ## 3.131.0
4
10
 
5
11
  ### Minor Changes
@@ -4,6 +4,7 @@ export { useLatest } from './useLatest';
4
4
  export { useRegisteredEvents } from './useRegisteredEvents';
5
5
  export { useMemoizedFn } from './useMemoizedFn';
6
6
  export { usePrevious } from './usePrevious';
7
+ export { supportUsePreCommit, usePreCommit } from './usePreCommit';
7
8
  export declare function useFirstRender(cb: () => void): boolean;
8
9
  export declare function useJSFirstRender(cb: () => void): boolean;
9
10
  export declare function useLepusFirstRender(cb: () => void): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAQtD;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAUxD;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAU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EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EAChC,KAAK,EAAE,MAAM,EACb,GAAG,UAAK,aAU+B,OAAO,EAAE,UASjD"}
@@ -5,6 +5,7 @@ import { useLatest } from "./useLatest.jsx";
5
5
  import { useRegisteredEvents } from "./useRegisteredEvents.jsx";
6
6
  import { useMemoizedFn } from "./useMemoizedFn.jsx";
7
7
  import { usePrevious } from "./usePrevious.jsx";
8
+ import { supportUsePreCommit, usePreCommit } from "./usePreCommit.jsx";
8
9
  import { useGCCollector } from "./useGCCollector.jsx";
9
10
  function useFirstRender(cb) {
10
11
  const isFirst = useRef(true);
@@ -66,6 +67,6 @@ function useThrottle(fn, delay, dep = []) {
66
67
  }
67
68
  }, dep);
68
69
  }
69
- export { useFirstRender, useGCCollector, useGlobalEventListener, useJSFirstRender, useLatest, useLepusFirstRender, useMemoizedFn, usePersistCallback, usePrevious, useRegisteredEvents, useThrottle, useUnmount };
70
+ export { supportUsePreCommit, useFirstRender, useGCCollector, useGlobalEventListener, useJSFirstRender, useLatest, useLepusFirstRender, useMemoizedFn, usePersistCallback, usePreCommit, usePrevious, useRegisteredEvents, useThrottle, useUnmount };
70
71
 
71
72
  //# sourceMappingURL=index.jsx.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks/index.jsx","sources":["webpack://@lynx-js/lynx-ui-common/./src/hooks/index.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useCallback, useEffect, useMemo, useRef } from '@lynx-js/react'\n\nexport { useUnmount } from './useUnmount'\nexport { useGlobalEventListener } from './useGlobalEventListener'\nexport { useLatest } from './useLatest'\nexport { useRegisteredEvents } from './useRegisteredEvents'\n\nexport { useMemoizedFn } from './useMemoizedFn'\nexport { usePrevious } from './usePrevious'\n\nexport function useFirstRender(cb: () => void): boolean {\n const isFirst = useRef(true)\n if (isFirst.current) {\n cb?.()\n isFirst.current = false\n return true\n }\n return isFirst.current\n}\n\nexport function useJSFirstRender(cb: () => void): boolean {\n const isJSFirst = useRef(true)\n if (isJSFirst.current) {\n if (!__LEPUS__) {\n cb?.()\n }\n isJSFirst.current = false\n return true\n }\n return isJSFirst.current\n}\n\nexport function useLepusFirstRender(cb: () => void): boolean {\n const isLepusFirst = useRef(true)\n if (isLepusFirst.current) {\n if (__LEPUS__) {\n cb?.()\n }\n isLepusFirst.current = false\n return true\n }\n return isLepusFirst.current\n}\n\n/**\n * @deprecated use useMemoizedFn instead\n */\nexport function usePersistCallback(fn: (...args: unknown[]) => void) {\n const ref = useRef<(...args: unknown[]) => void>(fn)\n ref.current = useMemo(\n function() {\n return fn\n },\n [fn],\n )\n return useCallback(\n function(...arg: unknown[]) {\n const fnn: (...arg2: unknown[]) => void = ref.current\n typeof ref.current === 'function' && fnn(...arg)\n },\n [ref],\n )\n}\n\nexport { useGCCollector, type UseGCCollectorOptions } from './useGCCollector'\n\nexport function useThrottle(\n fn: (...args: unknown[]) => void,\n delay: number,\n dep = [],\n) {\n const { current } = useRef({ fn, timer: 0 })\n useEffect(\n function() {\n current.fn = fn\n },\n [fn],\n )\n\n return useCallback(function f(...args: unknown[]) {\n if (!current.timer) {\n current.timer = setTimeout(() => {\n // @ts-expect-error Error\n delete current.timer\n }, delay) as unknown as number\n current.fn(...args)\n }\n }, dep)\n}\n"],"names":["useFirstRender","cb","isFirst","useRef","useJSFirstRender","isJSFirst","__LEPUS__","useLepusFirstRender","isLepusFirst","usePersistCallback","fn","ref","useMemo","useCallback","arg","fnn","useThrottle","delay","dep","current","useEffect","args","setTimeout"],"mappings":";;;;;;;;AAcO,SAASA,eAAeC,EAAc;IAC3C,MAAMC,UAAUC,OAAO;IACvB,IAAID,QAAQ,OAAO,EAAE;QACnBD;QACAC,QAAQ,OAAO,GAAG;QAClB,OAAO;IACT;IACA,OAAOA,QAAQ,OAAO;AACxB;AAEO,SAASE,iBAAiBH,EAAc;IAC7C,MAAMI,YAAYF,OAAO;IACzB,IAAIE,UAAU,OAAO,EAAE;QACrB,IAAI,CAACC,WACHL;QAEFI,UAAU,OAAO,GAAG;QACpB,OAAO;IACT;IACA,OAAOA,UAAU,OAAO;AAC1B;AAEO,SAASE,oBAAoBN,EAAc;IAChD,MAAMO,eAAeL,OAAO;IAC5B,IAAIK,aAAa,OAAO,EAAE;QACxB,IAAIF,WACFL;QAEFO,aAAa,OAAO,GAAG;QACvB,OAAO;IACT;IACA,OAAOA,aAAa,OAAO;AAC7B;AAKO,SAASC,mBAAmBC,EAAgC;IACjE,MAAMC,MAAMR,OAAqCO;IACjDC,IAAI,OAAO,GAAGC,QACZ;QACE,OAAOF;IACT,GACA;QAACA;KAAG;IAEN,OAAOG,YACL,SAAS,GAAGC,GAAc;QACxB,MAAMC,MAAoCJ,IAAI,OAAO;QAC9B,cAAvB,OAAOA,IAAI,OAAO,IAAmBI,OAAOD;IAC9C,GACA;QAACH;KAAI;AAET;AAIO,SAASK,YACdN,EAAgC,EAChCO,KAAa,EACbC,MAAM,EAAE;IAER,MAAM,EAAEC,OAAO,EAAE,GAAGhB,OAAO;QAAEO;QAAI,OAAO;IAAE;IAC1CU,UACE;QACED,QAAQ,EAAE,GAAGT;IACf,GACA;QAACA;KAAG;IAGN,OAAOG,YAAY,SAAW,GAAGQ,IAAe;QAC9C,IAAI,CAACF,QAAQ,KAAK,EAAE;YAClBA,QAAQ,KAAK,GAAGG,WAAW;gBAEzB,OAAOH,QAAQ,KAAK;YACtB,GAAGF;YACHE,QAAQ,EAAE,IAAIE;QAChB;IACF,GAAGH;AACL"}
1
+ {"version":3,"file":"hooks/index.jsx","sources":["webpack://@lynx-js/lynx-ui-common/./src/hooks/index.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useCallback, useEffect, useMemo, useRef } from '@lynx-js/react'\n\nexport { useUnmount } from './useUnmount'\nexport { useGlobalEventListener } from './useGlobalEventListener'\nexport { useLatest } from './useLatest'\nexport { useRegisteredEvents } from './useRegisteredEvents'\n\nexport { useMemoizedFn } from './useMemoizedFn'\nexport { usePrevious } from './usePrevious'\nexport { supportUsePreCommit, usePreCommit } from './usePreCommit'\n\nexport function useFirstRender(cb: () => void): boolean {\n const isFirst = useRef(true)\n if (isFirst.current) {\n cb?.()\n isFirst.current = false\n return true\n }\n return isFirst.current\n}\n\nexport function useJSFirstRender(cb: () => void): boolean {\n const isJSFirst = useRef(true)\n if (isJSFirst.current) {\n if (!__LEPUS__) {\n cb?.()\n }\n isJSFirst.current = false\n return true\n }\n return isJSFirst.current\n}\n\nexport function useLepusFirstRender(cb: () => void): boolean {\n const isLepusFirst = useRef(true)\n if (isLepusFirst.current) {\n if (__LEPUS__) {\n cb?.()\n }\n isLepusFirst.current = false\n return true\n }\n return isLepusFirst.current\n}\n\n/**\n * @deprecated use useMemoizedFn instead\n */\nexport function usePersistCallback(fn: (...args: unknown[]) => void) {\n const ref = useRef<(...args: unknown[]) => void>(fn)\n ref.current = useMemo(\n function() {\n return fn\n },\n [fn],\n )\n return useCallback(\n function(...arg: unknown[]) {\n const fnn: (...arg2: unknown[]) => void = ref.current\n typeof ref.current === 'function' && fnn(...arg)\n },\n [ref],\n )\n}\n\nexport { useGCCollector, type UseGCCollectorOptions } from './useGCCollector'\n\nexport function useThrottle(\n fn: (...args: unknown[]) => void,\n delay: number,\n dep = [],\n) {\n const { current } = useRef({ fn, timer: 0 })\n useEffect(\n function() {\n current.fn = fn\n },\n [fn],\n )\n\n return useCallback(function f(...args: unknown[]) {\n if (!current.timer) {\n current.timer = setTimeout(() => {\n // @ts-expect-error Error\n delete current.timer\n }, delay) as unknown as number\n current.fn(...args)\n }\n }, dep)\n}\n"],"names":["useFirstRender","cb","isFirst","useRef","useJSFirstRender","isJSFirst","__LEPUS__","useLepusFirstRender","isLepusFirst","usePersistCallback","fn","ref","useMemo","useCallback","arg","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ACF,GAAGH;AACL"}
@@ -0,0 +1,15 @@
1
+ import type { DependencyList } from '@lynx-js/react';
2
+ declare global {
3
+ var __setEomShouldFlushElementTree: ((value: boolean) => void) | undefined;
4
+ var __eomFlushHoldCount: number | undefined;
5
+ }
6
+ export declare function supportUsePreCommit(): boolean;
7
+ /**
8
+ * An experimental hook dedicated to make MTS run on firstScreenPaint
9
+ * Can be used starting from ReactLynx 0.113.0
10
+ * @experimental
11
+ * @param cb A main-thread callback to run on firstScreen
12
+ * @param deps Dependency array - callback only executes when dependencies change
13
+ */
14
+ export declare function usePreCommit(cb: () => void, deps?: DependencyList): void;
15
+ //# sourceMappingURL=usePreCommit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePreCommit.d.ts","sourceRoot":"","sources":["../../src/hooks/usePreCommit.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAUpD,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;IAC1E,IAAI,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5C;AAiCD,wBAAgB,mBAAmB,YAElC;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,IAAI,CAAC,EAAE,cAAc,QAgDjE"}
@@ -0,0 +1,49 @@
1
+ import { runOnMainThread, useRef } from "@lynx-js/react";
2
+ import { runWorkletCtx, setEomShouldFlushElementTree } from "@lynx-js/react/worklet-runtime/bindings";
3
+ import { areDepsEqual } from "../utils/areDepsEqual.jsx";
4
+ const setEomShouldFlush = setEomShouldFlushElementTree;
5
+ let eomFlushHoldCount = 0;
6
+ function holdEomFlush() {
7
+ eomFlushHoldCount += 1;
8
+ if (1 === eomFlushHoldCount) setEomShouldFlush(false);
9
+ }
10
+ function releaseEomFlush() {
11
+ if (0 === eomFlushHoldCount) return;
12
+ eomFlushHoldCount -= 1;
13
+ if (0 === eomFlushHoldCount) setEomShouldFlush(true);
14
+ }
15
+ if (__MAIN_THREAD__) globalThis.__setEomShouldFlushElementTree = setEomShouldFlush;
16
+ function supportUsePreCommit() {
17
+ return 'function' == typeof setEomShouldFlushElementTree;
18
+ }
19
+ function usePreCommit(cb, deps) {
20
+ const prevDepsRef = useRef(void 0);
21
+ const depsChanged = !areDepsEqual(prevDepsRef.current, deps);
22
+ prevDepsRef.current = deps;
23
+ if (!depsChanged) return;
24
+ if (__MAIN_THREAD__) {
25
+ holdEomFlush();
26
+ Promise.resolve().then(()=>{
27
+ try {
28
+ runWorkletCtx(cb, []);
29
+ } catch (e) {
30
+ console.error('Error occurred in preCommit hook', e);
31
+ } finally{
32
+ releaseEomFlush();
33
+ }
34
+ });
35
+ } else runOnMainThread(()=>{
36
+ 'main thread';
37
+ globalThis.__eomFlushHoldCount = (globalThis.__eomFlushHoldCount ?? 0) + 1;
38
+ if (1 === globalThis.__eomFlushHoldCount) globalThis.__setEomShouldFlushElementTree?.(false);
39
+ try {
40
+ cb();
41
+ } finally{
42
+ globalThis.__eomFlushHoldCount = Math.max((globalThis.__eomFlushHoldCount ?? 1) - 1, 0);
43
+ if (0 === globalThis.__eomFlushHoldCount) globalThis.__setEomShouldFlushElementTree?.(true);
44
+ }
45
+ })();
46
+ }
47
+ export { supportUsePreCommit, usePreCommit };
48
+
49
+ //# sourceMappingURL=usePreCommit.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/usePreCommit.jsx","sources":["webpack://@lynx-js/lynx-ui-common/./src/hooks/usePreCommit.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { runOnMainThread, useRef } from '@lynx-js/react'\nimport type { DependencyList } from '@lynx-js/react'\n\nimport {\n runWorkletCtx,\n setEomShouldFlushElementTree,\n} from '@lynx-js/react/worklet-runtime/bindings'\nimport type { Worklet } from '@lynx-js/react/worklet-runtime/bindings'\n\nimport { areDepsEqual } from '../utils/areDepsEqual'\n\ndeclare global {\n var __setEomShouldFlushElementTree: ((value: boolean) => void) | undefined\n var __eomFlushHoldCount: number | undefined\n}\n\nconst setEomShouldFlush = setEomShouldFlushElementTree as unknown as (\n value: boolean,\n) => void\n\nlet eomFlushHoldCount = 0\n\nfunction holdEomFlush() {\n eomFlushHoldCount += 1\n if (eomFlushHoldCount === 1) {\n setEomShouldFlush(false)\n }\n}\n\nfunction releaseEomFlush() {\n if (eomFlushHoldCount === 0) {\n return\n }\n\n eomFlushHoldCount -= 1\n if (eomFlushHoldCount === 0) {\n setEomShouldFlush(true)\n }\n}\n\n/**\n * Use this hack to prevent setEomShouldFlushElementTree being in the MTS closure\n */\nif (__MAIN_THREAD__) {\n globalThis.__setEomShouldFlushElementTree = setEomShouldFlush\n}\n\nexport function supportUsePreCommit() {\n return typeof setEomShouldFlushElementTree === 'function'\n}\n\n/**\n * An experimental hook dedicated to make MTS run on firstScreenPaint\n * Can be used starting from ReactLynx 0.113.0\n * @experimental\n * @param cb A main-thread callback to run on firstScreen\n * @param deps Dependency array - callback only executes when dependencies change\n */\nexport function usePreCommit(cb: () => void, deps?: DependencyList) {\n const prevDepsRef = useRef<DependencyList | undefined>(undefined)\n\n // Check if dependencies have changed\n const depsChanged = !areDepsEqual(prevDepsRef.current, deps)\n\n // Update the previous deps for next render\n prevDepsRef.current = deps\n\n // Only run if dependencies changed\n if (!depsChanged) {\n return\n }\n\n // For the Initial Frame Render\n if (__MAIN_THREAD__) {\n holdEomFlush()\n Promise.resolve().then(() => {\n try {\n runWorkletCtx(cb as unknown as Worklet, [])\n } catch (e) {\n console.error('Error occurred in preCommit hook', e)\n } finally {\n releaseEomFlush()\n }\n })\n } else {\n runOnMainThread(() => {\n 'main thread'\n\n globalThis.__eomFlushHoldCount = (globalThis.__eomFlushHoldCount ?? 0) + 1\n if (globalThis.__eomFlushHoldCount === 1) {\n globalThis.__setEomShouldFlushElementTree?.(false)\n }\n\n try {\n cb()\n } finally {\n globalThis.__eomFlushHoldCount = Math.max(\n (globalThis.__eomFlushHoldCount ?? 1) - 1,\n 0,\n )\n if (globalThis.__eomFlushHoldCount === 0) {\n globalThis.__setEomShouldFlushElementTree?.(true)\n }\n }\n })()\n }\n}\n"],"names":["setEomShouldFlush","setEomShouldFlushElementTree","eomFlushHoldCount","holdEomFlush","releaseEomFlush","__MAIN_THREAD__","globalThis","supportUsePreCommit","usePreCommit","cb","deps","prevDepsRef","useRef","undefined","depsChanged","areDepsEqual","Promise","runWorkletCtx","e","console","runOnMainThread","Math"],"mappings":";;;AAoBA,MAAMA,oBAAoBC;AAI1B,IAAIC,oBAAoB;AAExB,SAASC;IACPD,qBAAqB;IACrB,IAAIA,AAAsB,MAAtBA,mBACFF,kBAAkB;AAEtB;AAEA,SAASI;IACP,IAAIF,AAAsB,MAAtBA,mBACF;IAGFA,qBAAqB;IACrB,IAAIA,AAAsB,MAAtBA,mBACFF,kBAAkB;AAEtB;AAKA,IAAIK,iBACFC,WAAW,8BAA8B,GAAGN;AAGvC,SAASO;IACd,OAAO,AAAwC,cAAxC,OAAON;AAChB;AASO,SAASO,aAAaC,EAAc,EAAEC,IAAqB;IAChE,MAAMC,cAAcC,OAAmCC;IAGvD,MAAMC,cAAc,CAACC,aAAaJ,YAAY,OAAO,EAAED;IAGvDC,YAAY,OAAO,GAAGD;IAGtB,IAAI,CAACI,aACH;IAIF,IAAIT,iBAAiB;QACnBF;QACAa,QAAQ,OAAO,GAAG,IAAI,CAAC;YACrB,IAAI;gBACFC,cAAcR,IAA0B,EAAE;YAC5C,EAAE,OAAOS,GAAG;gBACVC,QAAQ,KAAK,CAAC,oCAAoCD;YACpD,SAAU;gBACRd;YACF;QACF;IACF,OACEgB,gBAAgB;QACd;QAEAd,WAAW,mBAAmB,GAAIA,AAAAA,CAAAA,WAAW,mBAAmB,IAAI,KAAK;QACzE,IAAIA,AAAmC,MAAnCA,WAAW,mBAAmB,EAChCA,WAAW,8BAA8B,GAAG;QAG9C,IAAI;YACFG;QACF,SAAU;YACRH,WAAW,mBAAmB,GAAGe,KAAK,GAAG,CACtCf,AAAAA,CAAAA,WAAW,mBAAmB,IAAI,KAAK,GACxC;YAEF,IAAIA,AAAmC,MAAnCA,WAAW,mBAAmB,EAChCA,WAAW,8BAA8B,GAAG;QAEhD;IACF;AAEJ"}
@@ -0,0 +1,6 @@
1
+ import type { DependencyList } from '@lynx-js/react';
2
+ /**
3
+ * Compares two dependency arrays
4
+ */
5
+ export declare function areDepsEqual(prevDeps: DependencyList | undefined, nextDeps: DependencyList | undefined): boolean;
6
+ //# sourceMappingURL=areDepsEqual.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"areDepsEqual.d.ts","sourceRoot":"","sources":["../../src/utils/areDepsEqual.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;GAEG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,cAAc,GAAG,SAAS,EACpC,QAAQ,EAAE,cAAc,GAAG,SAAS,GACnC,OAAO,CAaT"}
@@ -0,0 +1,9 @@
1
+ function areDepsEqual(prevDeps, nextDeps) {
2
+ if (void 0 === prevDeps || void 0 === nextDeps) return false;
3
+ if (prevDeps.length !== nextDeps.length) return false;
4
+ for(let i = 0; i < prevDeps.length; i++)if (!Object.is(prevDeps[i], nextDeps[i])) return false;
5
+ return true;
6
+ }
7
+ export { areDepsEqual };
8
+
9
+ //# sourceMappingURL=areDepsEqual.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/areDepsEqual.jsx","sources":["webpack://@lynx-js/lynx-ui-common/./src/utils/areDepsEqual.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { DependencyList } from '@lynx-js/react'\n\n/**\n * Compares two dependency arrays\n */\nexport function areDepsEqual(\n prevDeps: DependencyList | undefined,\n nextDeps: DependencyList | undefined,\n): boolean {\n if (prevDeps === undefined || nextDeps === undefined) {\n return false\n }\n if (prevDeps.length !== nextDeps.length) {\n return false\n }\n for (let i = 0; i < prevDeps.length; i++) {\n if (!Object.is(prevDeps[i], nextDeps[i])) {\n return false\n }\n }\n return true\n}\n"],"names":["areDepsEqual","prevDeps","nextDeps","undefined","i","Object"],"mappings":"AASO,SAASA,aACdC,QAAoC,EACpCC,QAAoC;IAEpC,IAAID,AAAaE,WAAbF,YAA0BC,AAAaC,WAAbD,UAC5B,OAAO;IAET,IAAID,SAAS,MAAM,KAAKC,SAAS,MAAM,EACrC,OAAO;IAET,IAAK,IAAIE,IAAI,GAAGA,IAAIH,SAAS,MAAM,EAAEG,IACnC,IAAI,CAACC,OAAO,EAAE,CAACJ,QAAQ,CAACG,EAAE,EAAEF,QAAQ,CAACE,EAAE,GACrC,OAAO;IAGX,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/lynx-ui-common",
3
- "version": "3.131.0",
3
+ "version": "3.133.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lynx-family/lynx-ui.git",
@@ -26,10 +26,10 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@lynx-js/gesture-runtime": "2.1.1",
29
- "@lynx-js/react-use": "0.0.7"
29
+ "@lynx-js/react-use": "0.1.3"
30
30
  },
31
31
  "devDependencies": {
32
- "@lynx-js/react": "0.113.0",
32
+ "@lynx-js/react": "0.114.0",
33
33
  "@lynx-js/types": "3.6.0",
34
34
  "@rslib/core": "^0.16.0",
35
35
  "@types/react": "^18.3.8",
@@ -1,2 +1 @@
1
1
  # useBounce
2
-
@@ -1,2 +1 @@
1
1
  # useRefresh
2
-
@@ -11,6 +11,7 @@ export { useRegisteredEvents } from './useRegisteredEvents'
11
11
 
12
12
  export { useMemoizedFn } from './useMemoizedFn'
13
13
  export { usePrevious } from './usePrevious'
14
+ export { supportUsePreCommit, usePreCommit } from './usePreCommit'
14
15
 
15
16
  export function useFirstRender(cb: () => void): boolean {
16
17
  const isFirst = useRef(true)
@@ -0,0 +1,111 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import { runOnMainThread, useRef } from '@lynx-js/react'
6
+ import type { DependencyList } from '@lynx-js/react'
7
+
8
+ import {
9
+ runWorkletCtx,
10
+ setEomShouldFlushElementTree,
11
+ } from '@lynx-js/react/worklet-runtime/bindings'
12
+ import type { Worklet } from '@lynx-js/react/worklet-runtime/bindings'
13
+
14
+ import { areDepsEqual } from '../utils/areDepsEqual'
15
+
16
+ declare global {
17
+ var __setEomShouldFlushElementTree: ((value: boolean) => void) | undefined
18
+ var __eomFlushHoldCount: number | undefined
19
+ }
20
+
21
+ const setEomShouldFlush = setEomShouldFlushElementTree as unknown as (
22
+ value: boolean,
23
+ ) => void
24
+
25
+ let eomFlushHoldCount = 0
26
+
27
+ function holdEomFlush() {
28
+ eomFlushHoldCount += 1
29
+ if (eomFlushHoldCount === 1) {
30
+ setEomShouldFlush(false)
31
+ }
32
+ }
33
+
34
+ function releaseEomFlush() {
35
+ if (eomFlushHoldCount === 0) {
36
+ return
37
+ }
38
+
39
+ eomFlushHoldCount -= 1
40
+ if (eomFlushHoldCount === 0) {
41
+ setEomShouldFlush(true)
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Use this hack to prevent setEomShouldFlushElementTree being in the MTS closure
47
+ */
48
+ if (__MAIN_THREAD__) {
49
+ globalThis.__setEomShouldFlushElementTree = setEomShouldFlush
50
+ }
51
+
52
+ export function supportUsePreCommit() {
53
+ return typeof setEomShouldFlushElementTree === 'function'
54
+ }
55
+
56
+ /**
57
+ * An experimental hook dedicated to make MTS run on firstScreenPaint
58
+ * Can be used starting from ReactLynx 0.113.0
59
+ * @experimental
60
+ * @param cb A main-thread callback to run on firstScreen
61
+ * @param deps Dependency array - callback only executes when dependencies change
62
+ */
63
+ export function usePreCommit(cb: () => void, deps?: DependencyList) {
64
+ const prevDepsRef = useRef<DependencyList | undefined>(undefined)
65
+
66
+ // Check if dependencies have changed
67
+ const depsChanged = !areDepsEqual(prevDepsRef.current, deps)
68
+
69
+ // Update the previous deps for next render
70
+ prevDepsRef.current = deps
71
+
72
+ // Only run if dependencies changed
73
+ if (!depsChanged) {
74
+ return
75
+ }
76
+
77
+ // For the Initial Frame Render
78
+ if (__MAIN_THREAD__) {
79
+ holdEomFlush()
80
+ Promise.resolve().then(() => {
81
+ try {
82
+ runWorkletCtx(cb as unknown as Worklet, [])
83
+ } catch (e) {
84
+ console.error('Error occurred in preCommit hook', e)
85
+ } finally {
86
+ releaseEomFlush()
87
+ }
88
+ })
89
+ } else {
90
+ runOnMainThread(() => {
91
+ 'main thread'
92
+
93
+ globalThis.__eomFlushHoldCount = (globalThis.__eomFlushHoldCount ?? 0) + 1
94
+ if (globalThis.__eomFlushHoldCount === 1) {
95
+ globalThis.__setEomShouldFlushElementTree?.(false)
96
+ }
97
+
98
+ try {
99
+ cb()
100
+ } finally {
101
+ globalThis.__eomFlushHoldCount = Math.max(
102
+ (globalThis.__eomFlushHoldCount ?? 1) - 1,
103
+ 0,
104
+ )
105
+ if (globalThis.__eomFlushHoldCount === 0) {
106
+ globalThis.__setEomShouldFlushElementTree?.(true)
107
+ }
108
+ }
109
+ })()
110
+ }
111
+ }
@@ -0,0 +1,26 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import type { DependencyList } from '@lynx-js/react'
6
+
7
+ /**
8
+ * Compares two dependency arrays
9
+ */
10
+ export function areDepsEqual(
11
+ prevDeps: DependencyList | undefined,
12
+ nextDeps: DependencyList | undefined,
13
+ ): boolean {
14
+ if (prevDeps === undefined || nextDeps === undefined) {
15
+ return false
16
+ }
17
+ if (prevDeps.length !== nextDeps.length) {
18
+ return false
19
+ }
20
+ for (let i = 0; i < prevDeps.length; i++) {
21
+ if (!Object.is(prevDeps[i], nextDeps[i])) {
22
+ return false
23
+ }
24
+ }
25
+ return true
26
+ }