@lynx-js/react 0.121.2 → 0.122.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.
Files changed (151) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/package.json +2 -2
  3. package/runtime/lib/core/background-function/exec-map.d.ts +11 -0
  4. package/runtime/lib/core/background-function/exec-map.js +39 -0
  5. package/runtime/lib/core/background-function/exec-map.js.map +1 -0
  6. package/runtime/lib/core/background-function/handle.d.ts +8 -0
  7. package/runtime/lib/core/background-function/handle.js +25 -0
  8. package/runtime/lib/core/background-function/handle.js.map +1 -0
  9. package/runtime/lib/core/background-function/run-on-background.d.ts +8 -0
  10. package/runtime/lib/{snapshot/worklet/call/runOnBackground.js → core/background-function/run-on-background.js} +39 -33
  11. package/runtime/lib/core/background-function/run-on-background.js.map +1 -0
  12. package/runtime/lib/core/initData.js +35 -0
  13. package/runtime/lib/core/initData.js.map +1 -1
  14. package/runtime/lib/core/lynx-page-data.js +6 -0
  15. package/runtime/lib/core/lynx-page-data.js.map +1 -1
  16. package/runtime/lib/core/lynx-update-data.js +6 -0
  17. package/runtime/lib/core/lynx-update-data.js.map +1 -1
  18. package/runtime/lib/core/runtime-destroy.d.ts +4 -0
  19. package/runtime/lib/core/runtime-destroy.js +18 -0
  20. package/runtime/lib/core/runtime-destroy.js.map +1 -0
  21. package/runtime/lib/core/thread-function-call/main-thread.d.ts +5 -0
  22. package/runtime/lib/core/thread-function-call/main-thread.js +69 -0
  23. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -0
  24. package/runtime/lib/core/thread-function-call/return-value.d.ts +2 -0
  25. package/runtime/lib/core/thread-function-call/return-value.js +67 -0
  26. package/runtime/lib/core/thread-function-call/return-value.js.map +1 -0
  27. package/runtime/lib/element-template/background/attr-slots.d.ts +1 -1
  28. package/runtime/lib/element-template/background/attr-slots.js +8 -7
  29. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  30. package/runtime/lib/element-template/background/commit-hook.js +79 -59
  31. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  32. package/runtime/lib/element-template/background/destroy.js +4 -0
  33. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  34. package/runtime/lib/element-template/background/hydrate.js +29 -6
  35. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  36. package/runtime/lib/element-template/background/hydration-listener.js +33 -14
  37. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  38. package/runtime/lib/element-template/background/instance.d.ts +1 -1
  39. package/runtime/lib/element-template/background/instance.js +10 -3
  40. package/runtime/lib/element-template/background/instance.js.map +1 -1
  41. package/runtime/lib/element-template/background/render-scope.d.ts +4 -0
  42. package/runtime/lib/element-template/background/render-scope.js +43 -0
  43. package/runtime/lib/element-template/background/render-scope.js.map +1 -0
  44. package/runtime/lib/element-template/index.d.ts +2 -0
  45. package/runtime/lib/element-template/index.js +2 -0
  46. package/runtime/lib/element-template/index.js.map +1 -1
  47. package/runtime/lib/element-template/internal.d.ts +4 -1
  48. package/runtime/lib/element-template/internal.js +5 -5
  49. package/runtime/lib/element-template/internal.js.map +1 -1
  50. package/runtime/lib/element-template/lynx/env.js +2 -0
  51. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  52. package/runtime/lib/element-template/native/index.js +2 -0
  53. package/runtime/lib/element-template/native/index.js.map +1 -1
  54. package/runtime/lib/element-template/native/mts-destroy.js +4 -0
  55. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  56. package/runtime/lib/element-template/native/patch-listener.js +41 -16
  57. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  58. package/runtime/lib/element-template/native/reload-main-thread.js +4 -0
  59. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  60. package/runtime/lib/element-template/prop-adapters/spread.d.ts +1 -4
  61. package/runtime/lib/element-template/prop-adapters/spread.js +1 -1
  62. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  63. package/runtime/lib/element-template/protocol/template-type.d.ts +19 -0
  64. package/runtime/lib/element-template/protocol/template-type.js +23 -1
  65. package/runtime/lib/element-template/protocol/template-type.js.map +1 -1
  66. package/runtime/lib/element-template/protocol/types.d.ts +5 -2
  67. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  68. package/runtime/lib/element-template/protocol/update-event.d.ts +15 -0
  69. package/runtime/lib/element-template/protocol/update-event.js +24 -0
  70. package/runtime/lib/element-template/protocol/update-event.js.map +1 -0
  71. package/runtime/lib/element-template/runtime/patch.d.ts +1 -1
  72. package/runtime/lib/element-template/runtime/patch.js +23 -3
  73. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  74. package/runtime/lib/element-template/runtime/render/render-opcodes.js +5 -2
  75. package/runtime/lib/element-template/runtime/render/render-opcodes.js.map +1 -1
  76. package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +7 -5
  77. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
  78. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  79. package/runtime/lib/element-template/runtime/template/handle.js +7 -1
  80. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  81. package/runtime/lib/element-template/runtime/template/main-thread-background-function.d.ts +10 -0
  82. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +30 -0
  83. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -0
  84. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +15 -0
  85. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +91 -0
  86. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -0
  87. package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.d.ts +15 -0
  88. package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js +29 -0
  89. package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js.map +1 -0
  90. package/runtime/lib/element-template/runtime/template/main-thread-function.d.ts +6 -0
  91. package/runtime/lib/element-template/runtime/template/main-thread-function.js +24 -0
  92. package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +1 -0
  93. package/runtime/lib/index.d.ts +3 -1
  94. package/runtime/lib/index.js +2 -1
  95. package/runtime/lib/index.js.map +1 -1
  96. package/runtime/lib/internal.d.ts +1 -1
  97. package/runtime/lib/internal.js +1 -1
  98. package/runtime/lib/internal.js.map +1 -1
  99. package/runtime/lib/lynx-api.d.ts +1 -1
  100. package/runtime/lib/lynx-api.js +1 -1
  101. package/runtime/lib/lynx-api.js.map +1 -1
  102. package/runtime/lib/{snapshot/worklet/indexMap.d.ts → shared/index-map.d.ts} +2 -2
  103. package/runtime/lib/{snapshot/worklet/indexMap.js → shared/index-map.js} +5 -3
  104. package/runtime/lib/shared/index-map.js.map +1 -0
  105. package/runtime/lib/snapshot/lifecycle/patch/commit.js +1 -1
  106. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  107. package/runtime/lib/snapshot/lynx/children.d.ts +13 -0
  108. package/runtime/lib/snapshot/lynx/children.js +19 -0
  109. package/runtime/lib/snapshot/lynx/children.js.map +1 -0
  110. package/runtime/lib/snapshot/lynx/tt.js +1 -1
  111. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  112. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +10 -31
  113. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  114. package/runtime/lib/snapshot/worklet/ctx.js +2 -2
  115. package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
  116. package/runtime/lib/snapshot/worklet/destroy.d.ts +0 -1
  117. package/runtime/lib/snapshot/worklet/destroy.js +2 -5
  118. package/runtime/lib/snapshot/worklet/destroy.js.map +1 -1
  119. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  120. package/runtime/lib/worklet-runtime/bindings/observers.d.ts +7 -0
  121. package/runtime/lib/worklet-runtime/bindings/observers.js +14 -1
  122. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  123. package/runtime/lib/worklet-runtime/delayRunOnBackground.d.ts +2 -1
  124. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +6 -2
  125. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
  126. package/runtime/lib/worklet-runtime/hydrate.js +3 -0
  127. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  128. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +1 -1
  129. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +1 -1
  130. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  131. package/runtime/lib/worklet-runtime/workletRuntime.js +17 -2
  132. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  133. package/runtime/worklet-runtime/dev.js +26 -8
  134. package/runtime/worklet-runtime/main.js +1 -1
  135. package/transform/dist/wasm.cjs +1 -1
  136. package/types/react.docs.d.ts +14 -0
  137. package/runtime/lib/snapshot/worklet/call/delayedRunOnMainThreadData.d.ts +0 -3
  138. package/runtime/lib/snapshot/worklet/call/delayedRunOnMainThreadData.js +0 -10
  139. package/runtime/lib/snapshot/worklet/call/delayedRunOnMainThreadData.js.map +0 -1
  140. package/runtime/lib/snapshot/worklet/call/execMap.d.ts +0 -1
  141. package/runtime/lib/snapshot/worklet/call/execMap.js +0 -43
  142. package/runtime/lib/snapshot/worklet/call/execMap.js.map +0 -1
  143. package/runtime/lib/snapshot/worklet/call/functionCall.d.ts +0 -1
  144. package/runtime/lib/snapshot/worklet/call/functionCall.js +0 -33
  145. package/runtime/lib/snapshot/worklet/call/functionCall.js.map +0 -1
  146. package/runtime/lib/snapshot/worklet/call/runOnBackground.d.ts +0 -20
  147. package/runtime/lib/snapshot/worklet/call/runOnBackground.js.map +0 -1
  148. package/runtime/lib/snapshot/worklet/call/transformToWorklet.d.ts +0 -1
  149. package/runtime/lib/snapshot/worklet/call/transformToWorklet.js +0 -22
  150. package/runtime/lib/snapshot/worklet/call/transformToWorklet.js.map +0 -1
  151. package/runtime/lib/snapshot/worklet/indexMap.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @lynx-js/react
2
2
 
3
+ ## 0.122.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Expose the `Children` API from ReactLynx and freeze the arrays returned by `Children.map`, `Children.forEach`, and `Children.toArray`. ([#2376](https://github.com/lynx-family/lynx-stack/pull/2376))
8
+
9
+ Allow `@lynx-js/react` 0.121 and newer in GenUI peer dependency ranges.
10
+
11
+ ### Patch Changes
12
+
13
+ - Report a development error when a page-data reset is combined with `withInitDataInState`. ([#2869](https://github.com/lynx-family/lynx-stack/pull/2869))
14
+
15
+ `withInitDataInState` merges `lynx.__initData` into the wrapped component's state, so resetting the page data — `updatePage(..., { resetPageData: true })` on the main thread, or `updateData(..., { type: 'reset' })` on the background thread — cannot drop the keys the reset removed; the component keeps rendering the stale keys. A dev-only error is now reported (once per reset path) on both threads, pointing to `useInitData()` instead. The check is gated by `__DEV__` and is fully removed from production builds.
16
+
17
+ - Fix `withInitDataInState` not refreshing the component state on a main-thread re-render. ([#2868](https://github.com/lynx-family/lynx-stack/pull/2868))
18
+
19
+ `withInitDataInState` injected `lynx.__initData` into the class component's state only in the constructor, and its `onDataChanged` listener was active on the background thread only. On the main thread the component instance is reused across an `updatePage` re-render (the constructor never re-runs), so the injected state stayed frozen at the data from the first render. This surfaces whenever the main thread re-renders the screen itself before hydration (an `updatePage` while `firstScreenSyncTiming` is `'jsReady'`). The HOC now re-reads `lynx.__initData` on every render via `getDerivedStateFromProps`, composing with — and not overriding — the wrapped component's own `getDerivedStateFromProps`.
20
+
3
21
  ## 0.121.2
4
22
 
5
23
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/react",
3
- "version": "0.121.2",
3
+ "version": "0.122.0",
4
4
  "description": "ReactLynx is a framework for developing Lynx applications with familiar React.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -223,7 +223,7 @@
223
223
  "preact": "npm:@lynx-js/internal-preact@10.29.1-20260519060144-e6da44c"
224
224
  },
225
225
  "devDependencies": {
226
- "@lynx-js/types": "3.7.0",
226
+ "@lynx-js/types": "4.0.0",
227
227
  "@microsoft/api-extractor": "7.58.2",
228
228
  "@types/react": "^18.3.28"
229
229
  },
@@ -0,0 +1,11 @@
1
+ import { IndexMap } from '../../shared/index-map.js';
2
+ import type { JsFnHandle, Worklet } from '../../worklet-runtime/bindings/types.js';
3
+ /**
4
+ * Keeps the background-thread worklet ctx alive while main thread still holds
5
+ * a handle to one of its background functions.
6
+ */
7
+ export declare class BackgroundFunctionExecMap extends IndexMap<Worklet> {
8
+ add(worklet: Worklet): number;
9
+ findJsFnHandle(execId: number, fnId: number): JsFnHandle | undefined;
10
+ private findJsFnHandleInValue;
11
+ }
@@ -0,0 +1,39 @@
1
+ // Copyright 2024 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
+ import { IndexMap } from '../../shared/index-map.js';
5
+ /**
6
+ * Keeps the background-thread worklet ctx alive while main thread still holds
7
+ * a handle to one of its background functions.
8
+ */
9
+ export class BackgroundFunctionExecMap extends IndexMap {
10
+ add(worklet) {
11
+ const execId = super.add(worklet);
12
+ worklet._execId = execId;
13
+ return execId;
14
+ }
15
+ findJsFnHandle(execId, fnId) {
16
+ const worklet = this.get(execId);
17
+ if (!worklet) {
18
+ return undefined;
19
+ }
20
+ return this.findJsFnHandleInValue(worklet, fnId);
21
+ }
22
+ findJsFnHandleInValue(value, fnId) {
23
+ if (value === null || typeof value !== 'object') {
24
+ return undefined;
25
+ }
26
+ const obj = value;
27
+ if ('_jsFnId' in obj && obj['_jsFnId'] === fnId) {
28
+ return obj;
29
+ }
30
+ for (const i in obj) {
31
+ const result = this.findJsFnHandleInValue(obj[i], fnId);
32
+ if (result) {
33
+ return result;
34
+ }
35
+ }
36
+ return undefined;
37
+ }
38
+ }
39
+ //# sourceMappingURL=exec-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec-map.js","sourceRoot":"","sources":["../../../src/core/background-function/exec-map.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD;;;GAGG;AACH,MAAM,OAAO,yBAA0B,SAAQ,QAAiB;IAC9C,GAAG,CAAC,OAAgB;QAClC,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAClC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;QACzB,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,cAAc,CAAC,MAAc,EAAE,IAAY;QAChD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAEO,qBAAqB,CAAC,KAAc,EAAE,IAAY;QACxD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAChD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,GAAG,GAAG,KAAgC,CAAC;QAC7C,IAAI,SAAS,IAAI,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;YAChD,OAAO,GAAiB,CAAC;QAC3B,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;YACxD,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ import type { JsFnHandle } from '../../worklet-runtime/bindings/types.js';
2
+ /**
3
+ * Creates the serializable handle used by main-thread code to call a background function.
4
+ */
5
+ export declare function createBackgroundFunctionHandle(obj: ((...args: any[]) => any) & {
6
+ toJSON?: () => string;
7
+ }): JsFnHandle;
8
+ export declare function resetBackgroundFunctionHandleIdForTesting(): void;
@@ -0,0 +1,25 @@
1
+ // Copyright 2024 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
+ let lastId = 0;
5
+ /**
6
+ * Creates the serializable handle used by main-thread code to call a background function.
7
+ */
8
+ export function createBackgroundFunctionHandle(obj) {
9
+ const id = ++lastId;
10
+ if (typeof obj !== 'function') {
11
+ return {
12
+ _jsFnId: id,
13
+ _error: `Argument of runOnBackground should be a function, but got [${typeof obj}] instead`,
14
+ };
15
+ }
16
+ obj.toJSON ??= () => '[BackgroundFunction]';
17
+ return {
18
+ _jsFnId: id,
19
+ _fn: obj,
20
+ };
21
+ }
22
+ export function resetBackgroundFunctionHandleIdForTesting() {
23
+ lastId = 0;
24
+ }
25
+ //# sourceMappingURL=handle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle.js","sourceRoot":"","sources":["../../../src/core/background-function/handle.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,IAAI,MAAM,GAAG,CAAC,CAAC;AAEf;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAC5C,GAA0D;IAE1D,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC;IACpB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO;YACL,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,8DAA8D,OAAO,GAAG,WAAW;SAC5F,CAAC;IACJ,CAAC;IACD,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC,sBAAsB,CAAC;IAC5C,OAAO;QACL,OAAO,EAAE,EAAE;QACX,GAAG,EAAE,GAAG;KACT,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yCAAyC;IACvD,MAAM,GAAG,CAAC,CAAC;AACb,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare function resetBackgroundFunctionRuntime(): void;
2
+ /**
3
+ * `runOnBackground` allows triggering js functions on the background thread asynchronously.
4
+ * @param f - The js function to be called.
5
+ * @returns A function. Calling which with the arguments to be passed to the js function to trigger it on the background thread. This function returns a promise that resolves to the return value of the js function.
6
+ * @public
7
+ */
8
+ export declare function runOnBackground<R, Fn extends (...args: any[]) => R>(f: Fn): (...args: Parameters<Fn>) => Promise<R>;
@@ -1,30 +1,35 @@
1
1
  // Copyright 2024 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
- import { WorkletEvents, delayRunOnBackground } from '@lynx-js/react/worklet-runtime/bindings';
5
- import { destroyTasks } from '../destroy.js';
6
- import { WorkletExecIdMap } from './execMap.js';
7
- import { isRunOnBackgroundEnabled } from '../functionality.js';
8
- import { onFunctionCall } from './functionCall.js';
4
+ import { BackgroundFunctionExecMap } from './exec-map.js';
5
+ import { isSdkVersionGt } from '../../utils.js';
6
+ import { delayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';
7
+ import { WorkletEvents } from '../../worklet-runtime/bindings/events.js';
8
+ import { registerDestroyTask } from '../runtime-destroy.js';
9
+ import { onFunctionCall } from '../thread-function-call/return-value.js';
9
10
  let execIdMap;
10
- function init() {
11
+ let cleanupBackgroundFunctionRuntime;
12
+ let unregisterBackgroundFunctionCleanup;
13
+ function initBackgroundFunctionRuntime() {
11
14
  'background only';
12
15
  if (execIdMap) {
13
16
  return;
14
17
  }
15
- execIdMap = new WorkletExecIdMap();
16
- lynx.getCoreContext().addEventListener(WorkletEvents.runOnBackground, runJSFunction);
17
- lynx.getCoreContext().addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundWorkletCtx);
18
- destroyTasks.push(() => {
19
- lynx.getCoreContext().removeEventListener(WorkletEvents.runOnBackground, runJSFunction);
20
- lynx.getCoreContext().removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundWorkletCtx);
18
+ execIdMap = new BackgroundFunctionExecMap();
19
+ const context = lynx.getCoreContext();
20
+ context.addEventListener(WorkletEvents.runOnBackground, runBackgroundFunction);
21
+ context.addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);
22
+ cleanupBackgroundFunctionRuntime = () => {
23
+ context.removeEventListener(WorkletEvents.runOnBackground, runBackgroundFunction);
24
+ context.removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);
21
25
  execIdMap = undefined;
22
- });
26
+ cleanupBackgroundFunctionRuntime = undefined;
27
+ };
23
28
  }
24
29
  /**
25
30
  * @internal
26
31
  */
27
- function runJSFunction(event) {
32
+ export function runBackgroundFunction(event) {
28
33
  'background only';
29
34
  const data = JSON.parse(event.data);
30
35
  const obj = execIdMap.findJsFnHandle(data.obj._execId, data.obj._jsFnId);
@@ -41,7 +46,7 @@ function runJSFunction(event) {
41
46
  }),
42
47
  });
43
48
  }
44
- function releaseBackgroundWorkletCtx(event) {
49
+ function releaseBackgroundFunctionCtx(event) {
45
50
  'background only';
46
51
  for (const id of event.data) {
47
52
  execIdMap.remove(id);
@@ -50,31 +55,33 @@ function releaseBackgroundWorkletCtx(event) {
50
55
  /**
51
56
  * @internal
52
57
  */
53
- function registerWorkletCtx(ctx) {
58
+ export function registerBackgroundFunctionCtx(ctx) {
54
59
  'background only';
55
- init();
60
+ initBackgroundFunctionRuntime();
61
+ ensureBackgroundFunctionCleanup();
56
62
  execIdMap.add(ctx);
57
63
  }
64
+ function ensureBackgroundFunctionCleanup() {
65
+ if (unregisterBackgroundFunctionCleanup) {
66
+ return;
67
+ }
68
+ unregisterBackgroundFunctionCleanup = registerDestroyTask(() => {
69
+ resetBackgroundFunctionRuntime();
70
+ });
71
+ }
72
+ export function resetBackgroundFunctionRuntime() {
73
+ cleanupBackgroundFunctionRuntime?.();
74
+ unregisterBackgroundFunctionCleanup?.();
75
+ unregisterBackgroundFunctionCleanup = undefined;
76
+ }
58
77
  /**
59
78
  * `runOnBackground` allows triggering js functions on the background thread asynchronously.
60
79
  * @param f - The js function to be called.
61
80
  * @returns A function. Calling which with the arguments to be passed to the js function to trigger it on the background thread. This function returns a promise that resolves to the return value of the js function.
62
- * @example
63
- * ```ts
64
- * import { runOnBackground } from '@lynx-js/react';
65
- *
66
- * async function someMainthreadFunction() {
67
- * 'main thread';
68
- * const fn = runOnBackground(() => {
69
- * return 'hello';
70
- * });
71
- * const result = await fn();
72
- }
73
- * ```
74
81
  * @public
75
82
  */
76
- function runOnBackground(f) {
77
- if (!isRunOnBackgroundEnabled()) {
83
+ export function runOnBackground(f) {
84
+ if (!isSdkVersionGt(2, 15)) {
78
85
  throw new Error('runOnBackground requires Lynx sdk version 2.16.');
79
86
  }
80
87
  if (__JS__) {
@@ -110,5 +117,4 @@ function dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId) {
110
117
  }),
111
118
  });
112
119
  }
113
- export { registerWorkletCtx, runJSFunction, runOnBackground };
114
- //# sourceMappingURL=runOnBackground.js.map
120
+ //# sourceMappingURL=run-on-background.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-on-background.js","sourceRoot":"","sources":["../../../src/core/background-function/run-on-background.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC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AI,MAAM,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IACD,MAAM,GAAG,GAAG,CAAsB,CAAC;IACnC,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,EAAE,GAAG,MAA0B,EAAc,EAAE;QACzD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,MAAM,SAAS,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;YAE1C,IAAI,GAAG,CAAC,cAAc,EAAE,CAAC;gBACvB,oBAAoB,CAAC,GAAG,EAAE,CAAC,IAAY,EAAE,MAAc,EAAE,EAAE;oBACzD,kCAAkC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;gBACtE,CAAC,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YAED,kCAAkC,CAAC,GAAG,CAAC,OAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,OAAQ,EAAE,SAAS,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,kCAAkC,CACzC,IAAY,EACZ,MAA0B,EAC1B,MAAc,EACd,SAAiB;IAEjB,IAAI,CAAC,YAAY,EAAE,CAAC,aAAa,CAAC;QAChC,IAAI,EAAE,aAAa,CAAC,eAAe;QACnC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,GAAG,EAAE;gBACH,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,MAAM;aAChB;YACD,MAAM;YACN,SAAS;SACa,CAAC;KAC1B,CAAC,CAAC;AACL,CAAC"}
@@ -40,6 +40,20 @@ export function factory({ createContext, useState, createElement, useLynxGlobalE
40
40
  useChanged: () => useChanged,
41
41
  };
42
42
  }
43
+ // dev-only: lets the page-data reset paths report an error when a reset meets this HOC.
44
+ let usesWithInitDataInState = false;
45
+ /**
46
+ * @internal
47
+ */
48
+ export function hasWithInitDataInStateUsage() {
49
+ return usesWithInitDataInState;
50
+ }
51
+ /**
52
+ * @internal
53
+ */
54
+ export const RESET_WITH_INIT_DATA_IN_STATE_ERROR = 'Resetting page data does not clear the state injected by `withInitDataInState`: the HOC merges '
55
+ + '`lynx.__initData` into the component state and cannot drop keys removed by the reset. '
56
+ + 'Use `useInitData()` instead, or avoid combining a data reset with `withInitDataInState`.';
43
57
  /**
44
58
  * Higher-Order Component (HOC) that injects `initData` into the state of the given class component.
45
59
  *
@@ -76,6 +90,9 @@ export function withInitDataInState(App) {
76
90
  h;
77
91
  constructor(props) {
78
92
  super(props);
93
+ if (__DEV__) {
94
+ usesWithInitDataInState = true;
95
+ }
79
96
  this.state = {
80
97
  ...this.state,
81
98
  ...lynx.__initData,
@@ -95,6 +112,24 @@ export function withInitDataInState(App) {
95
112
  }
96
113
  }
97
114
  }
115
+ // Installed on the main thread only. There, `renderToString` reuses this component
116
+ // instance across an `updatePage` re-render (the constructor never re-runs) and there
117
+ // is no `onDataChanged` listener, so the constructor's one-time `initData` injection
118
+ // goes stale; refresh it on every render, mirroring how `useInitData` re-reads
119
+ // `lynx.__initData`. It is not installed on the background thread because defining
120
+ // `getDerivedStateFromProps` at all would disable the wrapped component's legacy
121
+ // `componentWillMount` / `componentWillReceiveProps` lifecycles — and the background
122
+ // path already refreshes the state via its `onDataChanged` listener.
123
+ if (__LEPUS__) {
124
+ C.getDerivedStateFromProps = (props, state) => {
125
+ const base = { ...state, ...lynx.__initData };
126
+ // Compose with the wrapped component's own (or inherited) `getDerivedStateFromProps`
127
+ // — passing it the freshened `initData` and letting its derived values win, matching
128
+ // how it runs (and wins) on the background thread.
129
+ const derived = App.getDerivedStateFromProps?.(props, base) ?? null;
130
+ return { ...base, ...derived };
131
+ };
132
+ }
98
133
  return C;
99
134
  }
100
135
  //# sourceMappingURL=initData.js.map
@@ -1 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,EAAE,KAAQ,EAAc,EAAE;YACxF,MAAM,IAAI,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,UAAU,EAAO,CAAC;YACnD,qFAAqF;YACrF,qFAAqF;YACrF,mDAAmD;YACnD,MAAM,OAAO,GAAG,GAAG,CAAC,wBAAwB,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC;YACpE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,EAAgB,CAAC;QAC/C,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -1,9 +1,15 @@
1
1
  // Copyright 2026 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
+ import { RESET_WITH_INIT_DATA_IN_STATE_ERROR, hasWithInitDataInStateUsage } from './initData.js';
4
5
  import { isEmptyObject } from '../utils.js';
6
+ let hasReportedResetWithInitDataInState = false;
5
7
  export function applyUpdatePageData(data, options) {
6
8
  if (options?.resetPageData) {
9
+ if (__DEV__ && !hasReportedResetWithInitDataInState && hasWithInitDataInStateUsage()) {
10
+ hasReportedResetWithInitDataInState = true;
11
+ lynx.reportError(new Error(RESET_WITH_INIT_DATA_IN_STATE_ERROR));
12
+ }
7
13
  lynx.__initData = {};
8
14
  }
9
15
  if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {
@@ -1 +1 @@
1
- {"version":3,"file":"lynx-page-data.js","sourceRoot":"","sources":["../../src/core/lynx-page-data.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,UAAU,mBAAmB,CAAC,IAAa,EAAE,OAAiD;IAClG,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,IAAI,IAAI,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACrE,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC;QACvB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"lynx-page-data.js","sourceRoot":"","sources":["../../src/core/lynx-page-data.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,mCAAmC,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,IAAI,mCAAmC,GAAG,KAAK,CAAC;AAEhD,MAAM,UAAU,mBAAmB,CAAC,IAAa,EAAE,OAAiD;IAClG,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;QAC3B,IAAI,OAAO,IAAI,CAAC,mCAAmC,IAAI,2BAA2B,EAAE,EAAE,CAAC;YACrF,mCAAmC,GAAG,IAAI,CAAC;YAC3C,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,IAAI,IAAI,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACrE,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC;QACvB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
@@ -1,6 +1,8 @@
1
1
  // Copyright 2026 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
+ import { RESET_WITH_INIT_DATA_IN_STATE_ERROR, hasWithInitDataInStateUsage } from './initData.js';
5
+ let hasReportedResetWithInitDataInState = false;
4
6
  export const NativeUpdateDataType = {
5
7
  UPDATE: 0,
6
8
  RESET: 1,
@@ -12,6 +14,10 @@ export function updateCardData(newData, options) {
12
14
  }
13
15
  const { type = NativeUpdateDataType.UPDATE } = options ?? {};
14
16
  if (type == NativeUpdateDataType.RESET) {
17
+ if (__DEV__ && !hasReportedResetWithInitDataInState && hasWithInitDataInStateUsage()) {
18
+ hasReportedResetWithInitDataInState = true;
19
+ lynx.reportError(new Error(RESET_WITH_INIT_DATA_IN_STATE_ERROR));
20
+ }
15
21
  lynx.__initData = {};
16
22
  }
17
23
  // COW keeps provider/consumer readers aligned with Snapshot updateData behavior.
@@ -1 +1 @@
1
- {"version":3,"file":"lynx-update-data.js","sourceRoot":"","sources":["../../src/core/lynx-update-data.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;CACA,CAAC;AAUX,MAAM,UAAU,cAAc,CAC5B,OAAsB,EACtB,OAAiC;IAEjC,MAAM,EAAE,CAAC,oBAAoB,CAAC,EAAE,qBAAqB,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;IAClF,IAAI,qBAAqB,EAAE,CAAC;QAC1B,IAAI,CAAC,WAAW,CACd,IAAI,KAAK,CACP,uEAAuE,qBAAqB,gCAAgC,CAC7H,CACF,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,IAAI,GAAG,oBAAoB,CAAC,MAAM,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAC7D,IAAI,IAAI,IAAI,oBAAoB,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,iFAAiF;IACjF,IAAI,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IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAElE,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,4 @@
1
+ type DestroyTask = () => void;
2
+ export declare function registerDestroyTask(task: DestroyTask): () => void;
3
+ export declare function runDestroyTasks(): void;
4
+ export {};
@@ -0,0 +1,18 @@
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
+ const destroyTasks = new Set();
5
+ export function registerDestroyTask(task) {
6
+ destroyTasks.add(task);
7
+ return () => {
8
+ destroyTasks.delete(task);
9
+ };
10
+ }
11
+ export function runDestroyTasks() {
12
+ const tasks = Array.from(destroyTasks);
13
+ for (const task of tasks) {
14
+ task();
15
+ }
16
+ destroyTasks.clear();
17
+ }
18
+ //# sourceMappingURL=runtime-destroy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-destroy.js","sourceRoot":"","sources":["../../src/core/runtime-destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,MAAM,YAAY,GAAG,IAAI,GAAG,EAAe,CAAC;AAE5C,MAAM,UAAU,mBAAmB,CAAC,IAAiB;IACnD,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,GAAG,EAAE;QACV,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,EAAE,CAAC;IACT,CAAC;IACD,YAAY,CAAC,KAAK,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { RunWorkletCtxData } from '../../worklet-runtime/bindings/events.js';
2
+ export type RunOnMainThread = <R, Fn extends (...args: any[]) => R>(fn: Fn) => (...args: Parameters<Fn>) => Promise<R>;
3
+ export declare let delayedRunOnMainThreadData: RunWorkletCtxData[];
4
+ export declare function enqueueDelayedRunOnMainThreadData(data: RunWorkletCtxData): void;
5
+ export declare function takeDelayedRunOnMainThreadData(): typeof delayedRunOnMainThreadData;
@@ -0,0 +1,69 @@
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
+ import { onFunctionCall } from './return-value.js';
5
+ import { isSdkVersionGt } from '../../utils.js';
6
+ import { WorkletEvents } from '../../worklet-runtime/bindings/events.js';
7
+ import { registerBackgroundFunctionCtx } from '../background-function/run-on-background.js';
8
+ export let delayedRunOnMainThreadData = [];
9
+ export function enqueueDelayedRunOnMainThreadData(data) {
10
+ delayedRunOnMainThreadData.push(data);
11
+ }
12
+ export function takeDelayedRunOnMainThreadData() {
13
+ const data = delayedRunOnMainThreadData;
14
+ delayedRunOnMainThreadData = [];
15
+ return data;
16
+ }
17
+ /**
18
+ * @internal
19
+ */
20
+ export function createRunOnMainThread(options) {
21
+ return (fn) => {
22
+ if (__LEPUS__) {
23
+ throw new Error('runOnMainThread can only be used on the background thread.');
24
+ }
25
+ if (!isMainThreadFunctionSupported()) {
26
+ throw new Error('runOnMainThread requires Lynx sdk version 2.14.');
27
+ }
28
+ return async (...params) => {
29
+ return new Promise((resolve) => {
30
+ const worklet = fn;
31
+ prepareMainThreadFunctionCtx(worklet);
32
+ const data = {
33
+ worklet,
34
+ params,
35
+ resolveId: onFunctionCall(resolve),
36
+ };
37
+ if (options.shouldDispatchRunOnMainThreadDirectly()) {
38
+ dispatchRunOnMainThreadEvent(data);
39
+ return;
40
+ }
41
+ enqueueDelayedRunOnMainThreadData(data);
42
+ });
43
+ };
44
+ };
45
+ }
46
+ function isMainThreadFunctionSupported() {
47
+ return isSdkVersionGt(2, 13);
48
+ }
49
+ function isRunOnBackgroundSupported() {
50
+ return isSdkVersionGt(2, 15);
51
+ }
52
+ function isMainThreadFunctionCtx(value) {
53
+ return value != null
54
+ && typeof value === 'object'
55
+ && !Array.isArray(value)
56
+ && typeof value._wkltId === 'string';
57
+ }
58
+ function prepareMainThreadFunctionCtx(worklet) {
59
+ if (isMainThreadFunctionCtx(worklet) && isRunOnBackgroundSupported()) {
60
+ registerBackgroundFunctionCtx(worklet);
61
+ }
62
+ }
63
+ function dispatchRunOnMainThreadEvent(data) {
64
+ lynx.getCoreContext().dispatchEvent({
65
+ type: WorkletEvents.runWorkletCtx,
66
+ data: JSON.stringify(data),
67
+ });
68
+ }
69
+ //# sourceMappingURL=main-thread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main-thread.js","sourceRoot":"","sources":["../../../src/core/thread-function-call/main-thread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAGzE,OAAO,EAAE,6BAA6B,EAAE,MAAM,6CAA6C,CAAC;AAQ5F,MAAM,CAAC,IAAI,0BAA0B,GAAwB,EAAE,CAAC;AAEhE,MAAM,UAAU,iCAAiC,CAAC,IAAuB;IACvE,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,MAAM,IAAI,GAAG,0BAA0B,CAAC;IACxC,0BAA0B,GAAG,EAAE,CAAC;IAChC,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAE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AO,CAAC,IAAI,0BAA0B,EAAE,EAAE,CAAC;QACrE,6BAA6B,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;AACH,CAAC;AAED,SAAS,4BAA4B,CAAC,IAAuB;IAC3D,IAAI,CAAC,cAAc,EAAE,CAAC,aAAa,CAAC;QAClC,IAAI,EAAE,aAAa,CAAC,aAAa;QACjC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;KAC3B,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function resetFunctionCallReturnListener(): void;
2
+ export declare function dropFunctionCallReturnIds(resolveIds: readonly number[]): void;
@@ -0,0 +1,67 @@
1
+ // Copyright 2025 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
+ import { IndexMap } from '../../shared/index-map.js';
5
+ import { WorkletEvents } from '../../worklet-runtime/bindings/events.js';
6
+ import { registerDestroyTask } from '../runtime-destroy.js';
7
+ let resolveMap;
8
+ let cleanupReturnValueListener;
9
+ let unregisterReturnValueCleanup;
10
+ function initReturnValueListener() {
11
+ const context = __JS__ ? lynx.getCoreContext() : lynx.getJSContext();
12
+ resolveMap = new IndexMap();
13
+ context.addEventListener(WorkletEvents.FunctionCallRet, onFunctionCallRet);
14
+ cleanupReturnValueListener = () => {
15
+ context.removeEventListener(WorkletEvents.FunctionCallRet, onFunctionCallRet);
16
+ resolveMap = undefined;
17
+ cleanupReturnValueListener = undefined;
18
+ };
19
+ }
20
+ /**
21
+ * @internal
22
+ */
23
+ export function onFunctionCall(resolve) {
24
+ ensureFunctionCallReturnCleanup();
25
+ if (!resolveMap) {
26
+ initReturnValueListener();
27
+ }
28
+ return resolveMap.add(resolve);
29
+ }
30
+ function ensureFunctionCallReturnCleanup() {
31
+ if (unregisterReturnValueCleanup) {
32
+ return;
33
+ }
34
+ unregisterReturnValueCleanup = registerDestroyTask(() => {
35
+ resetFunctionCallReturnListener();
36
+ });
37
+ }
38
+ export function resetFunctionCallReturnListener() {
39
+ cleanupReturnValueListener?.();
40
+ unregisterReturnValueCleanup?.();
41
+ unregisterReturnValueCleanup = undefined;
42
+ }
43
+ export function dropFunctionCallReturnIds(resolveIds) {
44
+ if (!resolveMap) {
45
+ return;
46
+ }
47
+ for (const resolveId of resolveIds) {
48
+ resolveMap.remove(resolveId);
49
+ }
50
+ if (resolveMap.size === 0) {
51
+ resetFunctionCallReturnListener();
52
+ }
53
+ }
54
+ function onFunctionCallRet(event) {
55
+ const data = JSON.parse(event.data);
56
+ const map = resolveMap;
57
+ if (!map) {
58
+ return;
59
+ }
60
+ const resolve = map.get(data.resolveId);
61
+ if (!resolve) {
62
+ return;
63
+ }
64
+ map.remove(data.resolveId);
65
+ resolve(data.returnValue);
66
+ }
67
+ //# sourceMappingURL=return-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"return-value.js","sourceRoot":"","sources":["../../../src/core/thread-function-call/return-value.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAEzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,IAAI,UAAsD,CAAC;AAC3D,IAAI,0BAAoD,CAAC;AACzD,IAAI,4BAAsD,CAAC;AAE3D,SAAS,uBAAuB;IAC9B,MAAM,OAAO,GAAiB,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;IAEnF,UAAU,GAAG,IAAI,QAAQ,EAAE,CAAC;IAC5B,OAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;IAE3E,0BAA0B,GAAG,GAAG,EAAE;QAChC,OAAO,CAAC,mBAA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C,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;IACT,CAAC;IACD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC5B,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import type { SerializableValue } from '../protocol/types.js';
2
2
  export interface PrepareAttributeSlotsOptions {
3
+ previousPreparedSlots?: readonly unknown[];
3
4
  previousRawSlots?: readonly unknown[];
4
- queueRefEffects?: boolean;
5
5
  }
6
6
  export declare function prepareAttributeSlots(templateKey: string, handleId: number, rawSlots: readonly unknown[], options?: PrepareAttributeSlotsOptions): SerializableValue[];
7
7
  export declare function queueRefAttributeSlotUpdates(templateKey: string, handleId: number, previousRawSlots?: readonly unknown[], nextRawSlots?: readonly unknown[]): void;
@@ -42,18 +42,19 @@ export function prepareAttributeSlots(templateKey, handleId, rawSlots, options)
42
42
  const preparedSlots = normalizedSlots === rawSlots
43
43
  ? rawSlots.slice()
44
44
  : normalizedSlots;
45
- const shouldQueueRefEffects = options?.queueRefEffects === true;
45
+ const previousPreparedSlots = options?.previousPreparedSlots;
46
46
  const previousRawSlots = options?.previousRawSlots;
47
+ const adapterContext = previousPreparedSlots && previousRawSlots
48
+ ? {
49
+ previousPreparedSlots,
50
+ previousRawSlots,
51
+ }
52
+ : undefined;
47
53
  for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {
48
54
  const attrSlotIndex = attrPlan[planIndex];
49
55
  const adapter = attrPlan[planIndex + 1];
50
56
  const rawValue = rawSlots[attrSlotIndex];
51
- preparedSlots[attrSlotIndex] = adapter(handleId, attrSlotIndex, rawValue);
52
- }
53
- if (shouldQueueRefEffects) {
54
- // Ref effects compare raw user refs, not prepared marker strings or the
55
- // spread wrapper object.
56
- queuePlannedRefAttributeSlotUpdates(handleId, attrPlan, previousRawSlots, rawSlots);
57
+ preparedSlots[attrSlotIndex] = adapter(handleId, attrSlotIndex, rawValue, adapterContext);
57
58
  }
58
59
  return preparedSlots;
59
60
  }