@lynx-js/react 0.121.1 → 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 (240) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/package.json +5 -5
  3. package/runtime/lazy/element-template-import.js +73 -0
  4. package/runtime/lazy/import.js +4 -0
  5. package/runtime/lazy/target.js +23 -0
  6. package/runtime/lib/core/background-function/exec-map.d.ts +11 -0
  7. package/runtime/lib/core/background-function/exec-map.js +39 -0
  8. package/runtime/lib/core/background-function/exec-map.js.map +1 -0
  9. package/runtime/lib/core/background-function/handle.d.ts +8 -0
  10. package/runtime/lib/core/background-function/handle.js +25 -0
  11. package/runtime/lib/core/background-function/handle.js.map +1 -0
  12. package/runtime/lib/core/background-function/run-on-background.d.ts +8 -0
  13. package/runtime/lib/{snapshot/worklet/call/runOnBackground.js → core/background-function/run-on-background.js} +39 -33
  14. package/runtime/lib/core/background-function/run-on-background.js.map +1 -0
  15. package/runtime/lib/{snapshot/legacy-react-runtime/index.d.ts → core/compat/legacy-react-runtime.d.ts} +4 -4
  16. package/runtime/lib/{snapshot/legacy-react-runtime/index.js → core/compat/legacy-react-runtime.js} +6 -6
  17. package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -0
  18. package/runtime/lib/{snapshot → core}/compat/lynxComponent.d.ts +2 -1
  19. package/runtime/lib/{snapshot → core}/compat/lynxComponent.js +11 -5
  20. package/runtime/lib/core/compat/lynxComponent.js.map +1 -0
  21. package/runtime/lib/core/component.d.ts +2 -0
  22. package/runtime/lib/{snapshot/lynx → core}/component.js +37 -31
  23. package/runtime/lib/core/component.js.map +1 -0
  24. package/runtime/lib/core/initData.js +35 -0
  25. package/runtime/lib/core/initData.js.map +1 -1
  26. package/runtime/lib/{snapshot/lynx/dynamic-js.js → core/lynx/dynamic-import.js} +1 -1
  27. package/runtime/lib/core/lynx/dynamic-import.js.map +1 -0
  28. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -0
  29. package/runtime/lib/core/lynx/runtime-backend.d.ts +5 -0
  30. package/runtime/lib/core/lynx/runtime-backend.js +20 -0
  31. package/runtime/lib/core/lynx/runtime-backend.js.map +1 -0
  32. package/runtime/lib/core/lynx-page-data.js +6 -0
  33. package/runtime/lib/core/lynx-page-data.js.map +1 -1
  34. package/runtime/lib/core/lynx-update-data.js +6 -0
  35. package/runtime/lib/core/lynx-update-data.js.map +1 -1
  36. package/runtime/lib/core/performance.d.ts +30 -0
  37. package/runtime/lib/core/performance.js +145 -0
  38. package/runtime/lib/core/performance.js.map +1 -0
  39. package/runtime/lib/core/runtime-destroy.d.ts +4 -0
  40. package/runtime/lib/core/runtime-destroy.js +18 -0
  41. package/runtime/lib/core/runtime-destroy.js.map +1 -0
  42. package/runtime/lib/core/thread-function-call/main-thread.d.ts +5 -0
  43. package/runtime/lib/core/thread-function-call/main-thread.js +69 -0
  44. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -0
  45. package/runtime/lib/core/thread-function-call/return-value.d.ts +2 -0
  46. package/runtime/lib/core/thread-function-call/return-value.js +67 -0
  47. package/runtime/lib/core/thread-function-call/return-value.js.map +1 -0
  48. package/runtime/lib/element-template/background/attr-slots.d.ts +1 -1
  49. package/runtime/lib/element-template/background/attr-slots.js +8 -7
  50. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  51. package/runtime/lib/element-template/background/commit-hook.js +81 -61
  52. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  53. package/runtime/lib/element-template/background/destroy.js +4 -0
  54. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  55. package/runtime/lib/element-template/background/document.js +7 -1
  56. package/runtime/lib/element-template/background/document.js.map +1 -1
  57. package/runtime/lib/element-template/background/hydrate.d.ts +2 -3
  58. package/runtime/lib/element-template/background/hydrate.js +237 -58
  59. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  60. package/runtime/lib/element-template/background/hydration-listener.js +38 -38
  61. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  62. package/runtime/lib/element-template/background/instance.d.ts +31 -4
  63. package/runtime/lib/element-template/background/instance.js +219 -31
  64. package/runtime/lib/element-template/background/instance.js.map +1 -1
  65. package/runtime/lib/element-template/background/render-scope.d.ts +4 -0
  66. package/runtime/lib/element-template/background/render-scope.js +43 -0
  67. package/runtime/lib/element-template/background/render-scope.js.map +1 -0
  68. package/runtime/lib/element-template/debug/alog.d.ts +14 -0
  69. package/runtime/lib/element-template/debug/alog.js +23 -0
  70. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  71. package/runtime/lib/element-template/debug/elementPAPICall.js +1 -0
  72. package/runtime/lib/element-template/debug/elementPAPICall.js.map +1 -1
  73. package/runtime/lib/element-template/index.d.ts +5 -2
  74. package/runtime/lib/element-template/index.js +8 -7
  75. package/runtime/lib/element-template/index.js.map +1 -1
  76. package/runtime/lib/element-template/internal.d.ts +7 -0
  77. package/runtime/lib/element-template/internal.js +9 -9
  78. package/runtime/lib/element-template/internal.js.map +1 -1
  79. package/runtime/lib/element-template/lynx/env.js +2 -0
  80. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  81. package/runtime/lib/element-template/lynx/performance.d.ts +0 -21
  82. package/runtime/lib/element-template/lynx/performance.js +4 -121
  83. package/runtime/lib/element-template/lynx/performance.js.map +1 -1
  84. package/runtime/lib/element-template/native/index.js +3 -1
  85. package/runtime/lib/element-template/native/index.js.map +1 -1
  86. package/runtime/lib/element-template/native/main-thread-api.js +1 -1
  87. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  88. package/runtime/lib/element-template/native/mts-destroy.js +6 -0
  89. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  90. package/runtime/lib/element-template/native/patch-listener.js +42 -17
  91. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  92. package/runtime/lib/element-template/native/reload-background.d.ts +1 -0
  93. package/runtime/lib/element-template/native/{reload.js → reload-background.js} +1 -26
  94. package/runtime/lib/element-template/native/reload-background.js.map +1 -0
  95. package/runtime/lib/element-template/native/{reload.d.ts → reload-main-thread.d.ts} +0 -1
  96. package/runtime/lib/element-template/native/reload-main-thread.js +39 -0
  97. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -0
  98. package/runtime/lib/element-template/prop-adapters/spread.d.ts +1 -4
  99. package/runtime/lib/element-template/prop-adapters/spread.js +1 -1
  100. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  101. package/runtime/lib/element-template/protocol/opcodes.d.ts +3 -0
  102. package/runtime/lib/element-template/protocol/opcodes.js +3 -0
  103. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  104. package/runtime/lib/element-template/protocol/template-type.d.ts +25 -0
  105. package/runtime/lib/element-template/protocol/template-type.js +42 -0
  106. package/runtime/lib/element-template/protocol/template-type.js.map +1 -0
  107. package/runtime/lib/element-template/protocol/types.d.ts +38 -15
  108. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  109. package/runtime/lib/element-template/protocol/update-event.d.ts +15 -0
  110. package/runtime/lib/element-template/protocol/update-event.js +24 -0
  111. package/runtime/lib/element-template/protocol/update-event.js.map +1 -0
  112. package/runtime/lib/element-template/runtime/list/list.d.ts +65 -0
  113. package/runtime/lib/element-template/runtime/list/list.js +587 -0
  114. package/runtime/lib/element-template/runtime/list/list.js.map +1 -0
  115. package/runtime/lib/element-template/runtime/patch.d.ts +1 -1
  116. package/runtime/lib/element-template/runtime/patch.js +198 -75
  117. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  118. package/runtime/lib/element-template/runtime/render/render-main-thread.js +13 -0
  119. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  120. package/runtime/lib/element-template/runtime/render/render-opcodes.js +83 -43
  121. package/runtime/lib/element-template/runtime/render/render-opcodes.js.map +1 -1
  122. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js +32 -1
  123. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js.map +1 -1
  124. package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +7 -5
  125. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
  126. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  127. package/runtime/lib/element-template/runtime/template/handle.d.ts +3 -2
  128. package/runtime/lib/element-template/runtime/template/handle.js +11 -0
  129. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  130. package/runtime/lib/element-template/runtime/template/main-thread-background-function.d.ts +10 -0
  131. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +30 -0
  132. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -0
  133. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +15 -0
  134. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +91 -0
  135. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -0
  136. package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.d.ts +15 -0
  137. package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js +29 -0
  138. package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js.map +1 -0
  139. package/runtime/lib/element-template/runtime/template/main-thread-function.d.ts +6 -0
  140. package/runtime/lib/element-template/runtime/template/main-thread-function.js +24 -0
  141. package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +1 -0
  142. package/runtime/lib/element-template/runtime/template/registry.d.ts +2 -0
  143. package/runtime/lib/element-template/runtime/template/registry.js +5 -0
  144. package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
  145. package/runtime/lib/element-template/runtime-backend-marker.js +6 -0
  146. package/runtime/lib/element-template/runtime-backend-marker.js.map +1 -0
  147. package/runtime/lib/index.d.ts +4 -2
  148. package/runtime/lib/index.js +5 -2
  149. package/runtime/lib/index.js.map +1 -1
  150. package/runtime/lib/internal.d.ts +5 -4
  151. package/runtime/lib/internal.js +6 -5
  152. package/runtime/lib/internal.js.map +1 -1
  153. package/runtime/lib/lynx-api.d.ts +1 -1
  154. package/runtime/lib/lynx-api.js +1 -1
  155. package/runtime/lib/lynx-api.js.map +1 -1
  156. package/runtime/lib/runtime-backend-marker.js +6 -0
  157. package/runtime/lib/runtime-backend-marker.js.map +1 -0
  158. package/runtime/lib/{snapshot/worklet/indexMap.d.ts → shared/index-map.d.ts} +2 -2
  159. package/runtime/lib/{snapshot/worklet/indexMap.js → shared/index-map.js} +5 -3
  160. package/runtime/lib/shared/index-map.js.map +1 -0
  161. package/runtime/lib/snapshot/lifecycle/patch/commit.js +2 -2
  162. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  163. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +1 -1
  164. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  165. package/runtime/lib/snapshot/lynx/calledByNative.js +1 -1
  166. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  167. package/runtime/lib/snapshot/lynx/children.d.ts +13 -0
  168. package/runtime/lib/snapshot/lynx/children.js +19 -0
  169. package/runtime/lib/snapshot/lynx/children.js.map +1 -0
  170. package/runtime/lib/snapshot/lynx/performance.d.ts +0 -21
  171. package/runtime/lib/snapshot/lynx/performance.js +7 -121
  172. package/runtime/lib/snapshot/lynx/performance.js.map +1 -1
  173. package/runtime/lib/snapshot/lynx/tt.js +2 -2
  174. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  175. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  176. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  177. package/runtime/lib/snapshot/snapshot/snapshot.js +1 -1
  178. package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
  179. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +10 -31
  180. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  181. package/runtime/lib/snapshot/worklet/ctx.js +2 -2
  182. package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
  183. package/runtime/lib/snapshot/worklet/destroy.d.ts +0 -1
  184. package/runtime/lib/snapshot/worklet/destroy.js +2 -5
  185. package/runtime/lib/snapshot/worklet/destroy.js.map +1 -1
  186. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  187. package/runtime/lib/worklet-runtime/bindings/observers.d.ts +7 -0
  188. package/runtime/lib/worklet-runtime/bindings/observers.js +14 -1
  189. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  190. package/runtime/lib/worklet-runtime/delayRunOnBackground.d.ts +2 -1
  191. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +6 -2
  192. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
  193. package/runtime/lib/worklet-runtime/hydrate.js +3 -0
  194. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  195. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +1 -1
  196. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +1 -1
  197. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  198. package/runtime/lib/worklet-runtime/workletRuntime.js +17 -2
  199. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  200. package/runtime/worklet-runtime/dev.js +26 -9
  201. package/runtime/worklet-runtime/main.js +1 -1
  202. package/testing-library/dist/{rslib-runtime.js → 0~rslib-runtime.js} +14 -13
  203. package/testing-library/dist/env/vitest.js +1 -1
  204. package/testing-library/dist/plugins/index.js +1 -1
  205. package/testing-library/dist/pure.js +18 -18
  206. package/testing-library/dist/rstest-config.js +2 -4
  207. package/testing-library/dist/setupFiles/common/bootstrap.js +1 -0
  208. package/testing-library/dist/setupFiles/common/runtime-setup.js +1 -1
  209. package/testing-library/dist/setupFiles/inner/rstest.js +2 -1
  210. package/testing-library/dist/setupFiles/inner/vitest.js +2 -1
  211. package/testing-library/dist/type-entry/index.js +1 -0
  212. package/transform/dist/wasm.cjs +113 -40
  213. package/types/react.docs.d.ts +14 -0
  214. package/runtime/lib/element-template/native/reload.js.map +0 -1
  215. package/runtime/lib/snapshot/compat/lynxComponent.js.map +0 -1
  216. package/runtime/lib/snapshot/legacy-react-runtime/index.js.map +0 -1
  217. package/runtime/lib/snapshot/lynx/component.js.map +0 -1
  218. package/runtime/lib/snapshot/lynx/dynamic-js.js.map +0 -1
  219. package/runtime/lib/snapshot/lynx/lazy-bundle.js.map +0 -1
  220. package/runtime/lib/snapshot/worklet/call/delayedRunOnMainThreadData.d.ts +0 -3
  221. package/runtime/lib/snapshot/worklet/call/delayedRunOnMainThreadData.js +0 -10
  222. package/runtime/lib/snapshot/worklet/call/delayedRunOnMainThreadData.js.map +0 -1
  223. package/runtime/lib/snapshot/worklet/call/execMap.js +0 -43
  224. package/runtime/lib/snapshot/worklet/call/execMap.js.map +0 -1
  225. package/runtime/lib/snapshot/worklet/call/functionCall.d.ts +0 -1
  226. package/runtime/lib/snapshot/worklet/call/functionCall.js +0 -33
  227. package/runtime/lib/snapshot/worklet/call/functionCall.js.map +0 -1
  228. package/runtime/lib/snapshot/worklet/call/runOnBackground.d.ts +0 -20
  229. package/runtime/lib/snapshot/worklet/call/runOnBackground.js.map +0 -1
  230. package/runtime/lib/snapshot/worklet/call/transformToWorklet.d.ts +0 -1
  231. package/runtime/lib/snapshot/worklet/call/transformToWorklet.js +0 -22
  232. package/runtime/lib/snapshot/worklet/call/transformToWorklet.js.map +0 -1
  233. package/runtime/lib/snapshot/worklet/indexMap.js.map +0 -1
  234. package/testing-library/dist/881.js +0 -1
  235. /package/runtime/lib/{snapshot/lynx/dynamic-js.d.ts → core/lynx/dynamic-import.d.ts} +0 -0
  236. /package/runtime/lib/{snapshot → core}/lynx/lazy-bundle.d.ts +0 -0
  237. /package/runtime/lib/{snapshot → core}/lynx/lazy-bundle.js +0 -0
  238. /package/runtime/lib/{snapshot/lynx/component.d.ts → element-template/runtime-backend-marker.d.ts} +0 -0
  239. /package/runtime/lib/{snapshot/worklet/call/execMap.d.ts → runtime-backend-marker.d.ts} +0 -0
  240. /package/testing-library/dist/{0~123.js → 0~@rstest/adapter-rsbuild.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
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
+
21
+ ## 0.121.2
22
+
23
+ ### Patch Changes
24
+
25
+ - Fix `addComponentElement` compat transforms so explicit `removeComponentElement={true}` is honored consistently even when it appears before a JSX spread like `{...props}`. ([#2758](https://github.com/lynx-family/lynx-stack/pull/2758))
26
+
27
+ Previously, the compat transform could short-circuit while scanning opening attributes and treat:
28
+
29
+ ```jsx
30
+ <Component removeComponentElement={true} {...props} />;
31
+ ```
32
+
33
+ differently from:
34
+
35
+ ```jsx
36
+ <Component {...props} removeComponentElement={true} />;
37
+ ```
38
+
39
+ The transform now collects the full opening-attribute state first, so both prop orders compile the same way in normal and `compilerOnly` modes.
40
+
41
+ - Fix directive DCE for TypeScript async output with nested `"background only"` directives. ([#2830](https://github.com/lynx-family/lynx-stack/pull/2830))
42
+
43
+ - Rename the `bundle-url` element attribute to `lazy-bundle-url`. ([#2723](https://github.com/lynx-family/lynx-stack/pull/2723))
44
+
45
+ The attribute set on lazy bundle border elements (when a child belongs to a different lazy bundle entry than its parent) is renamed from `bundle-url` to `lazy-bundle-url` to make its purpose explicit.
46
+
3
47
  ## 0.121.1
4
48
 
5
49
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/react",
3
- "version": "0.121.1",
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",
@@ -112,9 +112,9 @@
112
112
  "default": "./runtime/lib/worklet-runtime/bindings/index.js"
113
113
  },
114
114
  "./legacy-react-runtime": {
115
- "types": "./runtime/lib/snapshot/legacy-react-runtime/index.d.ts",
115
+ "types": "./runtime/lib/core/compat/legacy-react-runtime.d.ts",
116
116
  "lazy": "./runtime/lazy/legacy-react-runtime.js",
117
- "default": "./runtime/lib/snapshot/legacy-react-runtime/index.js"
117
+ "default": "./runtime/lib/core/compat/legacy-react-runtime.js"
118
118
  },
119
119
  "./testing-library": {
120
120
  "types": "./testing-library/types/index.d.ts",
@@ -202,7 +202,7 @@
202
202
  "./runtime/lib/worklet-runtime/bindings/index.d.ts"
203
203
  ],
204
204
  "legacy-react-runtime": [
205
- "./runtime/lib/snapshot/legacy-react-runtime/index.d.ts"
205
+ "./runtime/lib/core/compat/legacy-react-runtime.d.ts"
206
206
  ]
207
207
  }
208
208
  },
@@ -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,73 @@
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 * as ReactAPIs from '@lynx-js/react/element-template';
5
+ import * as ReactCompatAPIS from '@lynx-js/react/compat';
6
+ import * as ReactInternal from '@lynx-js/react/element-template/internal';
7
+ import * as ReactJSXDevRuntime from '@lynx-js/react/jsx-dev-runtime';
8
+ import * as ReactJSXRuntime from '@lynx-js/react/jsx-runtime';
9
+ import * as ReactLegacyReactRuntime from '@lynx-js/react/legacy-react-runtime';
10
+
11
+ import {
12
+ RUNTIME_BACKEND_ELEMENT_TEMPLATE,
13
+ registerLazyRuntimeBackend,
14
+ sExportsJSXDevRuntime,
15
+ sExportsJSXRuntime,
16
+ sExportsLegacyReactRuntime,
17
+ sExportsReact,
18
+ sExportsReactCompat,
19
+ sExportsReactInternal,
20
+ sExportsReactLepus,
21
+ target,
22
+ } from './target.js';
23
+
24
+ registerLazyRuntimeBackend(RUNTIME_BACKEND_ELEMENT_TEMPLATE);
25
+
26
+ Object.defineProperty(target, sExportsReact, {
27
+ value: ReactAPIs,
28
+ enumerable: false,
29
+ writable: false,
30
+ configurable: true,
31
+ });
32
+
33
+ Object.defineProperty(target, sExportsReactLepus, {
34
+ value: ReactAPIs,
35
+ enumerable: false,
36
+ writable: false,
37
+ configurable: true,
38
+ });
39
+
40
+ Object.defineProperty(target, sExportsReactCompat, {
41
+ value: ReactCompatAPIS,
42
+ enumerable: false,
43
+ writable: false,
44
+ configurable: true,
45
+ });
46
+
47
+ Object.defineProperty(target, sExportsReactInternal, {
48
+ value: ReactInternal,
49
+ enumerable: false,
50
+ writable: false,
51
+ configurable: true,
52
+ });
53
+
54
+ Object.defineProperty(target, sExportsJSXRuntime, {
55
+ value: ReactJSXRuntime,
56
+ enumerable: false,
57
+ writable: false,
58
+ configurable: true,
59
+ });
60
+
61
+ Object.defineProperty(target, sExportsJSXDevRuntime, {
62
+ value: ReactJSXDevRuntime,
63
+ enumerable: false,
64
+ writable: false,
65
+ configurable: true,
66
+ });
67
+
68
+ Object.defineProperty(target, sExportsLegacyReactRuntime, {
69
+ value: ReactLegacyReactRuntime,
70
+ enumerable: false,
71
+ writable: false,
72
+ configurable: true,
73
+ });
@@ -10,6 +10,8 @@ import * as ReactLegacyReactRuntime from '@lynx-js/react/legacy-react-runtime';
10
10
  import * as ReactLepusAPIs from '@lynx-js/react/lepus';
11
11
 
12
12
  import {
13
+ RUNTIME_BACKEND_SNAPSHOT,
14
+ registerLazyRuntimeBackend,
13
15
  sExportsJSXDevRuntime,
14
16
  sExportsJSXRuntime,
15
17
  sExportsLegacyReactRuntime,
@@ -20,6 +22,8 @@ import {
20
22
  target,
21
23
  } from './target.js';
22
24
 
25
+ registerLazyRuntimeBackend(RUNTIME_BACKEND_SNAPSHOT);
26
+
23
27
  Object.defineProperty(target, sExportsReact, {
24
28
  value: ReactAPIs,
25
29
  enumerable: false,
@@ -3,6 +3,10 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  export const target = __LEPUS__ ? globalThis : lynx;
5
5
 
6
+ export const RUNTIME_BACKEND_SNAPSHOT = 'Snapshot';
7
+ export const RUNTIME_BACKEND_ELEMENT_TEMPLATE = 'Element Template';
8
+ export const sRuntimeBackend = Symbol.for('__REACT_LYNX_RUNTIME_BACKEND__');
9
+
6
10
  export const sExportsReact = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react)');
7
11
  export const sExportsReactCompat = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/compat)');
8
12
  export const sExportsReactLepus = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/lepus)');
@@ -10,3 +14,22 @@ export const sExportsReactInternal = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js
10
14
  export const sExportsJSXRuntime = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/jsx-runtime)');
11
15
  export const sExportsJSXDevRuntime = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/jsx-dev-runtime)');
12
16
  export const sExportsLegacyReactRuntime = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/legacy-react-runtime)');
17
+
18
+ export function registerLazyRuntimeBackend(backend) {
19
+ const currentBackend = target[sRuntimeBackend];
20
+
21
+ if (currentBackend !== undefined && currentBackend !== backend) {
22
+ throw new Error(
23
+ `ReactLynx runtime backend mismatch: the current template uses ${
24
+ String(currentBackend)
25
+ }, but this bundle was built for ${backend}. Snapshot and Element Template templates cannot share lazy bundles. Rebuild the main template and lazy bundle with the same elementTemplate setting.`,
26
+ );
27
+ }
28
+
29
+ Object.defineProperty(target, sRuntimeBackend, {
30
+ value: backend,
31
+ enumerable: false,
32
+ writable: false,
33
+ configurable: true,
34
+ });
35
+ }
@@ -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;AAGzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAWzE,IAAI,SAAgD,CAAC;AACrD,IAAI,gCAA0D,CAAC;AAC/D,IAAI,mCAA6D,CAAC;AAElE,SAAS,6BAA6B;IACpC,iBAAiB,CAAC;IAClB,IAAI,SAAS,EAAE,CAAC;QACd,OAAO;IACT,CAAC;IAED,SAAS,GAAG,IAAI,yBAAyB,EAAE,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;IACtC,OAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC,eAAe,EAAE,qBAAqB,CAAC,CAAC;IAC/E,OAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC,2BAA2B,EAAE,4BAA4B,CAAC,CAAC;IAElG,gCAAgC,GAAG,GAAG,EAAE;QACtC,OAAO,CAAC,mBAAmB,CAAC,aAAa,CAAC,eAAe,EAAE,qBAAqB,CAAC,CAAC;QAClF,OAAO,CAAC,mBAAmB,CAAC,aAAa,CAAC,2BAA2B,EAAE,4BAA4B,C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S,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"}
@@ -1,9 +1,9 @@
1
1
  import { createRef } from 'preact';
2
- import { useRef } from '../../core/hooks/react.js';
2
+ import { useRef } from '../hooks/react.js';
3
3
  declare function __runInJS<T>(value: T): T | undefined | null;
4
- export { ComponentFromReactRuntime as Component } from '../compat/lynxComponent.js';
5
- export { ComponentFromReactRuntime as PureComponent } from '../compat/lynxComponent.js';
4
+ export { ComponentFromReactRuntime as Component } from './lynxComponent.js';
5
+ export { ComponentFromReactRuntime as PureComponent } from './lynxComponent.js';
6
6
  export { createContext } from 'preact';
7
7
  export { lazy } from 'preact/compat';
8
- export { useState, useReducer, useEffect, useMemo, useCallback } from '../../core/hooks/react.js';
8
+ export { useState, useReducer, useEffect, useMemo, useCallback } from '../hooks/react.js';
9
9
  export { __runInJS, createRef, useRef };
@@ -3,18 +3,18 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { createContext, createRef } from 'preact';
5
5
  import { lazy } from 'preact/compat';
6
- import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from '../../core/hooks/react.js';
7
- import { ComponentFromReactRuntime as Component, ComponentFromReactRuntime as PureComponent, } from '../compat/lynxComponent.js';
6
+ import { ComponentFromReactRuntime as Component, ComponentFromReactRuntime as PureComponent } from './lynxComponent.js';
7
+ import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from '../hooks/react.js';
8
8
  /* v8 ignore next 3 */
9
9
  function __runInJS(value) {
10
10
  return value;
11
11
  }
12
12
  // should mirror @lynx-js/react-runtime's exports
13
- export { ComponentFromReactRuntime as Component } from '../compat/lynxComponent.js';
14
- export { ComponentFromReactRuntime as PureComponent } from '../compat/lynxComponent.js';
13
+ export { ComponentFromReactRuntime as Component } from './lynxComponent.js';
14
+ export { ComponentFromReactRuntime as PureComponent } from './lynxComponent.js';
15
15
  export { createContext } from 'preact';
16
16
  export { lazy } from 'preact/compat';
17
- export { useState, useReducer, useEffect, useMemo, useCallback /*, useInstance */ } from '../../core/hooks/react.js';
17
+ export { useState, useReducer, useEffect, useMemo, useCallback /*, useInstance */ } from '../hooks/react.js';
18
18
  export { __runInJS, createRef, useRef };
19
19
  /**
20
20
  * @internal
@@ -33,4 +33,4 @@ export default {
33
33
  useCallback,
34
34
  __runInJS,
35
35
  };
36
- //# sourceMappingURL=index.js.map
36
+ //# sourceMappingURL=legacy-react-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-react-runtime.js","sourceRoot":"","sources":["../../../src/core/compat/legacy-react-runtime.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,OAAO,EAAE,yBAAyB,IAAI,SAAS,EAAE,yBAAyB,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElG,sBAAsB;AACtB,SAAS,SAAS,CAAI,KAAQ;IAC5B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,iDAAiD;AACjD,OAAO,EAAE,yBAAyB,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,yBAAyB,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC7G,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AAExC;;GAEG;AACH,eAAe;IACb,SAAS;IACT,aAAa;IACb,aAAa;IACb,SAAS;IACT,IAAI;IACJ,QAAQ;IACR,UAAU;IACV,MAAM;IACN,SAAS;IACT,OAAO;IACP,WAAW;IACX,SAAS;CACV,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { Component } from 'preact';
2
2
  import type { ReactNode } from 'react';
3
- export declare function wrapWithLynxComponent(jsxSnapshot: (c: ReactNode, spread?: Record<string, any>) => ReactNode, jsxComponent: any): ReactNode;
3
+ export declare function wrapWithLynxComponent(jsxSnapshot: (c: ReactNode, spread?: Record<string, unknown>) => ReactNode, jsxComponent: ReactNode): ReactNode;
4
4
  export declare class ComponentFromReactRuntime extends Component {
5
+ render(): null;
5
6
  }
@@ -3,22 +3,28 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { Component } from 'preact';
5
5
  export function wrapWithLynxComponent(jsxSnapshot, jsxComponent) {
6
- const C = jsxComponent.type;
7
- if (typeof C === 'function' && (C === ComponentFromReactRuntime || C.prototype instanceof ComponentFromReactRuntime)) {
6
+ const componentVNode = jsxComponent;
7
+ const C = componentVNode.type;
8
+ if (typeof C === 'function'
9
+ && (C === ComponentFromReactRuntime
10
+ || C.prototype instanceof ComponentFromReactRuntime)) {
8
11
  if (jsxSnapshot.length === 1) {
9
12
  return jsxSnapshot(jsxComponent);
10
13
  }
11
14
  else {
12
15
  // spread
13
- if (!jsxComponent.props.removeComponentElement) {
14
- return jsxSnapshot(jsxComponent, takeComponentAttributes(jsxComponent));
16
+ if (!componentVNode.props['removeComponentElement']) {
17
+ return jsxSnapshot(jsxComponent, takeComponentAttributes(componentVNode));
15
18
  }
16
19
  }
17
20
  }
18
21
  return jsxComponent;
19
22
  }
20
- // @ts-expect-error
21
23
  export class ComponentFromReactRuntime extends Component {
24
+ /* v8 ignore next 3 -- marker component, never rendered directly. */
25
+ render() {
26
+ return null;
27
+ }
22
28
  }
23
29
  const __COMPONENT_ATTRIBUTES__ = /* @__PURE__ */ new Set([
24
30
  'name',
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lynxComponent.js","sourceRoot":"","sources":["../../../src/core/compat/lynxComponent.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAQnC,MAAM,UAAU,qBAAqB,CACnC,WAA0E,EAC1E,YAAuB;IAEvB,MAAM,cAAc,GAAG,YAAoC,CAAC;IAC5D,MAAM,CAAC,GAAG,cAAc,CAAC,IAAI,CAAC;IAC9B,IACE,OAAO,CAAC,KAAK,UAAU;WACpB,CAAC,CAAC,KAAK,yBAAyB;eAC7B,CAA6B,CAAC,SAAS,YAAY,yBAAyB,CAAC,EACnF,CAAC;QACD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,WAAW,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,SAAS;YACT,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,wBAAwB,CAAC,EAAE,CAAC;gBACpD,OAAO,WAAW,CAAC,YAAY,EAAE,uBAAuB,CAAC,cAAc,CAAC,CAAC,CAAC;YAC5E,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IACtD,oEAAoE;IACpE,MAAM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