@lynx-js/react 0.129.2 → 0.129.4

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 (420) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +2 -2
  4. package/refresh/.turbo/turbo-build.log +3 -3
  5. package/refresh/dist/index.js +113 -20
  6. package/refresh/rslib.config.ts +13 -3
  7. package/refresh/src/index.ts +100 -0
  8. package/refresh/src/self.ts +38 -0
  9. package/runtime/__test__/{snapshot → core}/attribute-name.test.ts +1 -1
  10. package/runtime/__test__/core/background-function.test.ts +37 -0
  11. package/runtime/__test__/{shared → core}/component-stack.test.ts +4 -4
  12. package/runtime/__test__/core/ref.test.ts +218 -1
  13. package/runtime/__test__/core/sync-effect-flush.test.ts +58 -0
  14. package/runtime/__test__/element-template/debug/alog.test.ts +20 -12
  15. package/runtime/__test__/element-template/fixtures/background/hydrate/_shared.tsx +15 -34
  16. package/runtime/__test__/element-template/fixtures/background/hydrate/children.creates-missing-nodes-recursively/output.txt +2 -0
  17. package/runtime/__test__/element-template/fixtures/background/hydrate/children.iterates-existing-slots/output.txt +1 -0
  18. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-attrs-element/output.txt +6 -1
  19. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-main/output.txt +1 -0
  20. package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.move-before-child → children.reconciles-raw-text-slots}/case.tsx +1 -1
  21. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text/output.txt +1 -0
  22. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text-non-text/output.txt +1 -0
  23. package/runtime/__test__/element-template/fixtures/background/hydrate/root-key-mismatch-reconciles/output.txt +1 -0
  24. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.creates-and-inserts-new/output.txt +1 -0
  25. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.inserts-before-existing-sibling/output.txt +1 -0
  26. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.mixed-operations/output.txt +1 -0
  27. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -0
  28. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/complex-trees.deeply-nested-dynamic-content/output.txt +1 -0
  29. package/runtime/__test__/element-template/fixtures/background/instance/ops/emits-bundle-url-in-create-template/output.txt +1 -0
  30. package/runtime/__test__/element-template/fixtures/list/mts/index.tsx +185 -0
  31. package/runtime/__test__/element-template/fixtures/page/render-page/native-log.txt +1 -0
  32. package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/case.tsx +2 -0
  33. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/ops.txt +1 -0
  34. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/ops.txt +1 -0
  35. package/runtime/__test__/element-template/fixtures/render/child-siblings/papi.txt +10 -5
  36. package/runtime/__test__/element-template/fixtures/render/component/papi.txt +6 -3
  37. package/runtime/__test__/element-template/fixtures/render/component-slot-content/papi.txt +6 -3
  38. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/papi.txt +2 -1
  39. package/runtime/__test__/element-template/fixtures/render/direct-native/appends-root-text-via-append-element/native-log.txt +1 -0
  40. package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/native-log.txt +2 -0
  41. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-template-children-in-the-same-slot/native-log.txt +3 -0
  42. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +3 -0
  43. package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/native-log.txt +3 -0
  44. package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/native-log.txt +3 -0
  45. package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/native-log.txt +1 -0
  46. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/papi.txt +14 -7
  47. package/runtime/__test__/element-template/fixtures/render/mixed-children/papi.txt +8 -4
  48. package/runtime/__test__/element-template/fixtures/render/multiple-text/papi.txt +38 -19
  49. package/runtime/__test__/element-template/fixtures/render/nested-templates/papi.txt +6 -3
  50. package/runtime/__test__/element-template/fixtures/render/react-example/papi.txt +6 -3
  51. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/papi.txt +6 -3
  52. package/runtime/__test__/element-template/fixtures/render/template-dedupe/papi.txt +10 -5
  53. package/runtime/__test__/element-template/lynx/performance.test.ts +1 -0
  54. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +1 -0
  55. package/runtime/__test__/element-template/native/mts-destroy.test.ts +10 -15
  56. package/runtime/__test__/element-template/native/reload.test.ts +4 -7
  57. package/runtime/__test__/element-template/runtime/background/adapter/background-adapter.et.test.tsx +0 -32
  58. package/runtime/__test__/element-template/runtime/background/commit-context.test.ts +0 -14
  59. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +10 -0
  60. package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +22 -0
  61. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +197 -252
  62. package/runtime/__test__/element-template/runtime/background/instance.test.ts +277 -126
  63. package/runtime/__test__/element-template/runtime/background/passive-update-depth.test.tsx +496 -0
  64. package/runtime/__test__/element-template/runtime/background/render/preact.test.tsx +16 -22
  65. package/runtime/__test__/element-template/runtime/background/root-render.test.tsx +5 -3
  66. package/runtime/__test__/element-template/runtime/background/suspense.test.tsx +2 -0
  67. package/runtime/__test__/element-template/runtime/background/update/compiled-fixtures.test.tsx +1 -0
  68. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +1 -0
  69. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +3 -4
  70. package/runtime/__test__/element-template/runtime/list/list-mts-compiled.test.ts +525 -0
  71. package/runtime/__test__/element-template/runtime/page/compiled-fixtures.test.tsx +2 -0
  72. package/runtime/__test__/element-template/runtime/page/root-instance.test.ts +2 -14
  73. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +425 -1032
  74. package/runtime/__test__/element-template/runtime/patch/patch-listener-alog.test.ts +1 -0
  75. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +1 -0
  76. package/runtime/__test__/element-template/runtime/prop-adapters/event.test.ts +0 -20
  77. package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +2 -1
  78. package/runtime/__test__/element-template/runtime/prop-adapters/hydrate.test.ts +1 -0
  79. package/runtime/__test__/element-template/runtime/prop-adapters/ref.test.ts +65 -0
  80. package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +12 -4
  81. package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +2 -5
  82. package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +56 -121
  83. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +18 -17
  84. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +5 -4
  85. package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -0
  86. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +1 -60
  87. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +32 -89
  88. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +8 -6
  89. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +34 -6
  90. package/runtime/__test__/element-template/test-utils/debug/updateRunner.test.tsx +20 -12
  91. package/runtime/__test__/element-template/test-utils/debug/updateRunner.ts +2 -28
  92. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.test.ts +14 -5
  93. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.ts +1 -57
  94. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +29 -13
  95. package/runtime/__test__/element-template/vitest.config.ts +1 -0
  96. package/runtime/__test__/guardrails/snapshot-containment.test.ts +98 -77
  97. package/runtime/__test__/snapshot/compat/export.test.jsx +8 -2
  98. package/runtime/__test__/snapshot/debug/passive-update-depth.test.jsx +549 -0
  99. package/runtime/__test__/snapshot/debug/react-hooks-profile.test.jsx +3 -3
  100. package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +138 -1
  101. package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +1 -1
  102. package/runtime/__test__/snapshot/lifecycle/transfer.mts.test.jsx +194 -0
  103. package/runtime/__test__/snapshot/lifecycle/transfer.test.jsx +210 -0
  104. package/runtime/__test__/snapshot/list.test.jsx +109 -0
  105. package/runtime/__test__/snapshot/lynxQueueMicrotask.test.jsx +2 -2
  106. package/runtime/__test__/snapshot/ref.test.jsx +124 -1
  107. package/runtime/__test__/snapshot/utils/envManager.ts +5 -0
  108. package/runtime/__test__/snapshot/utils/globals.js +1 -0
  109. package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +22 -11
  110. package/runtime/__test__/worklet-runtime/hydrate.test.js +1 -0
  111. package/runtime/__test__/worklet-runtime/initEntry.test.js +12 -0
  112. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +24 -16
  113. package/runtime/__test__/worklet-runtime/runOnBackground.test.js +188 -0
  114. package/runtime/__test__/worklet-runtime/workletRef.test.js +16 -0
  115. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +53 -1
  116. package/runtime/compat/index.d.ts +17 -1
  117. package/runtime/compat/index.js +3 -2
  118. package/runtime/lazy/compat.js +1 -0
  119. package/runtime/lazy/internal.js +1 -0
  120. package/runtime/lib/core/attribute-name.js.map +1 -0
  121. package/runtime/lib/core/background-function/run-on-background.js +7 -7
  122. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  123. package/runtime/lib/{shared → core}/component-stack.js +1 -1
  124. package/runtime/lib/core/component-stack.js.map +1 -0
  125. package/runtime/lib/core/deep-equal.d.ts +1 -0
  126. package/runtime/lib/core/deep-equal.js +31 -0
  127. package/runtime/lib/core/deep-equal.js.map +1 -0
  128. package/runtime/lib/core/hooks/mainThreadImpl.js +1 -1
  129. package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
  130. package/runtime/lib/core/lynx-page-data.js +1 -1
  131. package/runtime/lib/core/lynx-page-data.js.map +1 -1
  132. package/runtime/lib/core/mts-capability.js +1 -1
  133. package/runtime/lib/core/mts-capability.js.map +1 -1
  134. package/runtime/lib/core/performance.js +2 -1
  135. package/runtime/lib/core/performance.js.map +1 -1
  136. package/runtime/lib/core/ref.d.ts +1 -2
  137. package/runtime/lib/core/ref.js +60 -9
  138. package/runtime/lib/core/ref.js.map +1 -1
  139. package/runtime/lib/core/sync-effect-flush.d.ts +9 -0
  140. package/runtime/lib/core/sync-effect-flush.js +31 -0
  141. package/runtime/lib/core/sync-effect-flush.js.map +1 -0
  142. package/runtime/lib/core/thread-function-call/main-thread.js +1 -1
  143. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  144. package/runtime/lib/element-template/background/attr-slots.d.ts +1 -0
  145. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  146. package/runtime/lib/element-template/background/commit-hook.js +1 -1
  147. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  148. package/runtime/lib/element-template/background/destroy.js +1 -1
  149. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  150. package/runtime/lib/element-template/background/hydrate.js +173 -85
  151. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  152. package/runtime/lib/element-template/background/instance.d.ts +7 -10
  153. package/runtime/lib/element-template/background/instance.js +65 -58
  154. package/runtime/lib/element-template/background/instance.js.map +1 -1
  155. package/runtime/lib/element-template/background/render-scope.js +2 -1
  156. package/runtime/lib/element-template/background/render-scope.js.map +1 -1
  157. package/runtime/lib/element-template/debug/alog.d.ts +1 -10
  158. package/runtime/lib/element-template/debug/alog.js +1 -16
  159. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  160. package/runtime/lib/element-template/debug/profile.js +1 -1
  161. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  162. package/runtime/lib/element-template/native/index.js +2 -2
  163. package/runtime/lib/element-template/native/index.js.map +1 -1
  164. package/runtime/lib/element-template/native/patch-listener.js +4 -8
  165. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  166. package/runtime/lib/element-template/native/reload-main-thread.js +0 -4
  167. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  168. package/runtime/lib/element-template/prop-adapters/ref.d.ts +2 -1
  169. package/runtime/lib/element-template/prop-adapters/ref.js +4 -4
  170. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
  171. package/runtime/lib/element-template/prop-adapters/spread.js +1 -1
  172. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  173. package/runtime/lib/element-template/protocol/opcodes.d.ts +0 -2
  174. package/runtime/lib/element-template/protocol/opcodes.js +0 -2
  175. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  176. package/runtime/lib/element-template/protocol/types.d.ts +8 -30
  177. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  178. package/runtime/lib/element-template/runtime/list/list.d.ts +14 -54
  179. package/runtime/lib/element-template/runtime/list/list.js +82 -546
  180. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  181. package/runtime/lib/element-template/runtime/list/platform-info.d.ts +2 -0
  182. package/runtime/lib/element-template/runtime/list/platform-info.js +26 -0
  183. package/runtime/lib/element-template/runtime/list/platform-info.js.map +1 -0
  184. package/runtime/lib/element-template/runtime/patch.js +42 -119
  185. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  186. package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +1 -1
  187. package/runtime/lib/element-template/runtime/render/create-rendered-host.js +24 -21
  188. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
  189. package/runtime/lib/element-template/runtime/render/render-components.d.ts +1 -1
  190. package/runtime/lib/element-template/runtime/render/render-components.js +3 -6
  191. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  192. package/runtime/lib/element-template/runtime/render/render-direct.js +21 -20
  193. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
  194. package/runtime/lib/element-template/runtime/render/render-main-thread.js +0 -13
  195. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  196. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +8 -0
  197. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  198. package/runtime/lib/element-template/runtime/template/handle.d.ts +3 -3
  199. package/runtime/lib/element-template/runtime/template/handle.js +2 -2
  200. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  201. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +1 -6
  202. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  203. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +2 -1
  204. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +44 -28
  205. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  206. package/runtime/lib/element-template/runtime/template/typed-attributes.d.ts +2 -0
  207. package/runtime/lib/element-template/runtime/template/typed-attributes.js +8 -1
  208. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  209. package/runtime/lib/internal.d.ts +1 -0
  210. package/runtime/lib/internal.js +1 -0
  211. package/runtime/lib/internal.js.map +1 -1
  212. package/runtime/lib/lynx-api.js +6 -1
  213. package/runtime/lib/lynx-api.js.map +1 -1
  214. package/runtime/lib/lynx.js +4 -4
  215. package/runtime/lib/lynx.js.map +1 -1
  216. package/runtime/lib/root.d.ts +5 -1
  217. package/runtime/lib/root.js +12 -1
  218. package/runtime/lib/root.js.map +1 -1
  219. package/runtime/lib/shared/microtask.d.ts +1 -0
  220. package/runtime/lib/shared/microtask.js +28 -0
  221. package/runtime/lib/shared/microtask.js.map +1 -0
  222. package/runtime/lib/shared/utils.d.ts +8 -0
  223. package/runtime/lib/shared/utils.js +27 -0
  224. package/runtime/lib/shared/utils.js.map +1 -0
  225. package/runtime/lib/{worklet-runtime/utils → shared}/version.d.ts +1 -0
  226. package/runtime/lib/shared/version.js +15 -0
  227. package/runtime/lib/shared/version.js.map +1 -0
  228. package/runtime/lib/snapshot/alog/render.js +1 -1
  229. package/runtime/lib/snapshot/alog/render.js.map +1 -1
  230. package/runtime/lib/snapshot/debug/profileHooks.js +1 -1
  231. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  232. package/runtime/lib/snapshot/lifecycle/destroy.js +2 -2
  233. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  234. package/runtime/lib/snapshot/lifecycle/isRendering.js +2 -1
  235. package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
  236. package/runtime/lib/snapshot/lifecycle/patch/commit.d.ts +7 -2
  237. package/runtime/lib/snapshot/lifecycle/patch/commit.js +11 -6
  238. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  239. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.d.ts +5 -0
  240. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +1 -1
  241. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  242. package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +1 -1
  243. package/runtime/lib/snapshot/lifecycle/ref/delay.js +2 -2
  244. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  245. package/runtime/lib/snapshot/lifecycle/reload.js +1 -1
  246. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  247. package/runtime/lib/snapshot/list/list.js +12 -3
  248. package/runtime/lib/snapshot/list/list.js.map +1 -1
  249. package/runtime/lib/snapshot/lynx/tt.d.ts +3 -1
  250. package/runtime/lib/snapshot/lynx/tt.js +7 -3
  251. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  252. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +1 -1
  253. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  254. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  255. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  256. package/runtime/lib/snapshot/snapshot/platformInfo.js +1 -1
  257. package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
  258. package/runtime/lib/snapshot/snapshot/ref.d.ts +1 -0
  259. package/runtime/lib/snapshot/snapshot/ref.js +2 -2
  260. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  261. package/runtime/lib/snapshot/snapshot/snapshot.js +1 -1
  262. package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
  263. package/runtime/lib/snapshot/snapshot/spread.js +3 -2
  264. package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
  265. package/runtime/lib/snapshot/transfer.d.ts +15 -0
  266. package/runtime/lib/snapshot/transfer.js +343 -0
  267. package/runtime/lib/snapshot/transfer.js.map +1 -0
  268. package/runtime/lib/snapshot/worklet/functionality.js +1 -1
  269. package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
  270. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  271. package/runtime/lib/worklet-runtime/api/element.js +1 -1
  272. package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
  273. package/runtime/lib/worklet-runtime/api/lynxApi.js +1 -1
  274. package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
  275. package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -2
  276. package/runtime/lib/worklet-runtime/bindings/bindings.js +11 -1
  277. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  278. package/runtime/lib/worklet-runtime/bindings/observers.js +9 -1
  279. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  280. package/runtime/lib/worklet-runtime/bindings/types.d.ts +1 -0
  281. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
  282. package/runtime/lib/worklet-runtime/delayWorkletEvent.d.ts +2 -4
  283. package/runtime/lib/worklet-runtime/delayWorkletEvent.js +42 -44
  284. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
  285. package/runtime/lib/worklet-runtime/global.d.ts +1 -2
  286. package/runtime/lib/worklet-runtime/global.js.map +1 -1
  287. package/runtime/lib/worklet-runtime/hydrate.js +2 -32
  288. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  289. package/runtime/lib/worklet-runtime/run-on-background/index.d.ts +28 -0
  290. package/runtime/lib/worklet-runtime/run-on-background/index.js +103 -0
  291. package/runtime/lib/worklet-runtime/run-on-background/index.js.map +1 -0
  292. package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.d.ts → run-on-background/lifecycle.d.ts} +2 -2
  293. package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.js → run-on-background/lifecycle.js} +12 -9
  294. package/runtime/lib/worklet-runtime/run-on-background/lifecycle.js.map +1 -0
  295. package/runtime/lib/worklet-runtime/workletRef.js +51 -54
  296. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
  297. package/runtime/lib/worklet-runtime/workletRuntime.js +5 -6
  298. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  299. package/runtime/src/core/background-function/run-on-background.ts +7 -7
  300. package/runtime/src/{shared → core}/component-stack.ts +1 -1
  301. package/runtime/src/core/deep-equal.ts +33 -0
  302. package/runtime/src/core/hooks/mainThreadImpl.ts +1 -1
  303. package/runtime/src/core/lynx-page-data.ts +1 -1
  304. package/runtime/src/core/mts-capability.ts +1 -1
  305. package/runtime/src/core/performance.ts +2 -1
  306. package/runtime/src/core/ref.ts +92 -15
  307. package/runtime/src/core/sync-effect-flush.ts +30 -0
  308. package/runtime/src/core/thread-function-call/main-thread.ts +1 -1
  309. package/runtime/src/element-template/background/attr-slots.ts +2 -2
  310. package/runtime/src/element-template/background/commit-hook.ts +1 -1
  311. package/runtime/src/element-template/background/destroy.ts +1 -1
  312. package/runtime/src/element-template/background/hydrate.ts +229 -119
  313. package/runtime/src/element-template/background/instance.ts +82 -82
  314. package/runtime/src/element-template/background/render-scope.ts +2 -1
  315. package/runtime/src/element-template/debug/alog.ts +2 -30
  316. package/runtime/src/element-template/debug/profile.ts +1 -1
  317. package/runtime/src/element-template/native/index.ts +2 -2
  318. package/runtime/src/element-template/native/patch-listener.ts +6 -7
  319. package/runtime/src/element-template/native/reload-main-thread.ts +0 -4
  320. package/runtime/src/element-template/prop-adapters/ref.ts +12 -5
  321. package/runtime/src/element-template/prop-adapters/spread.ts +1 -1
  322. package/runtime/src/element-template/protocol/opcodes.ts +0 -2
  323. package/runtime/src/element-template/protocol/types.ts +10 -38
  324. package/runtime/src/element-template/runtime/list/list.ts +115 -744
  325. package/runtime/src/element-template/runtime/list/platform-info.ts +31 -0
  326. package/runtime/src/element-template/runtime/patch.ts +59 -163
  327. package/runtime/src/element-template/runtime/render/create-rendered-host.ts +27 -31
  328. package/runtime/src/element-template/runtime/render/render-components.ts +2 -5
  329. package/runtime/src/element-template/runtime/render/render-direct.ts +19 -18
  330. package/runtime/src/element-template/runtime/render/render-main-thread.ts +0 -14
  331. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +9 -0
  332. package/runtime/src/element-template/runtime/template/handle.ts +3 -2
  333. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +1 -6
  334. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +44 -30
  335. package/runtime/src/element-template/runtime/template/typed-attributes.ts +17 -1
  336. package/runtime/src/element-template/types.d.ts +6 -22
  337. package/runtime/src/internal.ts +2 -0
  338. package/runtime/src/lynx-api.ts +6 -1
  339. package/runtime/src/lynx.ts +4 -4
  340. package/runtime/src/root.ts +17 -1
  341. package/runtime/src/shared/microtask.ts +26 -0
  342. package/runtime/src/shared/utils.ts +37 -0
  343. package/runtime/src/shared/version.ts +16 -0
  344. package/runtime/src/snapshot/alog/render.ts +1 -1
  345. package/runtime/src/snapshot/debug/profileHooks.ts +1 -1
  346. package/runtime/src/snapshot/lifecycle/destroy.ts +2 -2
  347. package/runtime/src/snapshot/lifecycle/isRendering.ts +2 -1
  348. package/runtime/src/snapshot/lifecycle/patch/commit.ts +28 -7
  349. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +1 -1
  350. package/runtime/src/snapshot/lifecycle/ref/delay.ts +5 -2
  351. package/runtime/src/snapshot/lifecycle/reload.ts +1 -1
  352. package/runtime/src/snapshot/list/list.ts +12 -3
  353. package/runtime/src/snapshot/lynx/tt.ts +8 -3
  354. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +1 -1
  355. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
  356. package/runtime/src/snapshot/snapshot/platformInfo.ts +1 -1
  357. package/runtime/src/snapshot/snapshot/ref.ts +7 -4
  358. package/runtime/src/snapshot/snapshot/snapshot.ts +1 -1
  359. package/runtime/src/snapshot/snapshot/spread.ts +3 -2
  360. package/runtime/src/snapshot/transfer.ts +379 -0
  361. package/runtime/src/snapshot/worklet/functionality.ts +1 -1
  362. package/runtime/src/worklet-runtime/api/element.ts +1 -1
  363. package/runtime/src/worklet-runtime/api/lynxApi.ts +1 -1
  364. package/runtime/src/worklet-runtime/bindings/bindings.ts +12 -0
  365. package/runtime/src/worklet-runtime/bindings/observers.ts +9 -1
  366. package/runtime/src/worklet-runtime/bindings/types.ts +1 -0
  367. package/runtime/src/worklet-runtime/delayWorkletEvent.ts +49 -54
  368. package/runtime/src/worklet-runtime/global.ts +1 -2
  369. package/runtime/src/worklet-runtime/hydrate.ts +2 -35
  370. package/runtime/src/worklet-runtime/run-on-background/index.ts +145 -0
  371. package/runtime/src/worklet-runtime/{jsFunctionLifecycle.ts → run-on-background/lifecycle.ts} +11 -9
  372. package/runtime/src/worklet-runtime/workletRef.ts +63 -62
  373. package/runtime/src/worklet-runtime/workletRuntime.ts +10 -10
  374. package/testing-library/.turbo/turbo-build.log +10 -10
  375. package/testing-library/dist/pure.js +7 -4
  376. package/testing-library/dist/setupFiles/common/runtime-setup.js +3 -1
  377. package/testing-library/dist/setupFiles/inner/rstest.js +1 -1
  378. package/testing-library/dist/setupFiles/inner/vitest.js +1 -1
  379. package/testing-library/src/__tests__/list.test.jsx +52 -0
  380. package/testing-library/src/__tests__/worklet.test.jsx +81 -0
  381. package/testing-library/src/pure.jsx +5 -2
  382. package/testing-library/src/setupFiles/common/runtime-setup.js +2 -0
  383. package/transform/.turbo/turbo-build$colon$wasm.log +88 -201
  384. package/transform/crates/swc_plugin_element_template/tests/element_template.rs +19 -45
  385. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +0 -19
  386. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
  387. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +129 -156
  388. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +282 -149
  389. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.move-before-child/output.txt +0 -10
  390. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.raw-text-key-branches/case.tsx +0 -5
  391. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/case.ts +0 -11
  392. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/output.txt +0 -1
  393. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/case.ts +0 -23
  394. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/output.txt +0 -6
  395. package/runtime/__test__/element-template/runtime/page/authored-page.test.ts +0 -35
  396. package/runtime/__test__/element-template/runtime/patch/update-fixture-helper.test.tsx +0 -40
  397. package/runtime/__test__/snapshot/lynx-data-processors.test.ts +0 -3
  398. package/runtime/lib/shared/attribute-name.js.map +0 -1
  399. package/runtime/lib/shared/component-stack.js.map +0 -1
  400. package/runtime/lib/snapshot/alog/index.d.ts +0 -1
  401. package/runtime/lib/snapshot/alog/index.js +0 -8
  402. package/runtime/lib/snapshot/alog/index.js.map +0 -1
  403. package/runtime/lib/utils.d.ts +0 -19
  404. package/runtime/lib/utils.js +0 -119
  405. package/runtime/lib/utils.js.map +0 -1
  406. package/runtime/lib/worklet-runtime/delayRunOnBackground.d.ts +0 -13
  407. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +0 -29
  408. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +0 -1
  409. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +0 -1
  410. package/runtime/lib/worklet-runtime/utils/version.js +0 -10
  411. package/runtime/lib/worklet-runtime/utils/version.js.map +0 -1
  412. package/runtime/src/snapshot/alog/index.ts +0 -8
  413. package/runtime/src/utils.ts +0 -134
  414. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +0 -53
  415. package/runtime/src/worklet-runtime/utils/version.ts +0 -11
  416. /package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.raw-text-key-branches → children.reconciles-raw-text-slots}/output.txt +0 -0
  417. /package/runtime/lib/{shared → core}/attribute-name.d.ts +0 -0
  418. /package/runtime/lib/{shared → core}/attribute-name.js +0 -0
  419. /package/runtime/lib/{shared → core}/component-stack.d.ts +0 -0
  420. /package/runtime/src/{shared → core}/attribute-name.ts +0 -0
@@ -3,8 +3,11 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
5
 
6
+ import { clearDelayedRunOnBackgroundFunctions } from '../../src/worklet-runtime/bindings/observers';
6
7
  import { initWorklet } from '../../src/worklet-runtime/workletRuntime';
7
8
 
9
+ const originalLynx = globalThis.lynx;
10
+
8
11
  beforeEach(() => {
9
12
  globalThis.SystemInfo = {
10
13
  lynxSdkVersion: '2.16',
@@ -13,6 +16,9 @@ beforeEach(() => {
13
16
  });
14
17
 
15
18
  afterEach(() => {
19
+ vi.restoreAllMocks();
20
+ globalThis.lynx = originalLynx;
21
+ globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.dispose();
16
22
  delete globalThis.lynxWorkletImpl;
17
23
  });
18
24
 
@@ -130,6 +136,8 @@ describe('runOnBackground', () => {
130
136
  {
131
137
  "jsFnHandle": {
132
138
  "_execId": 8,
139
+ "_hydratedEpoch": 0,
140
+ "_isFirstScreen": false,
133
141
  "_jsFnId": 1,
134
142
  },
135
143
  "task": [MockFunction spy],
@@ -185,4 +193,184 @@ describe('runOnBackground', () => {
185
193
  });
186
194
  expect(task).not.toHaveBeenCalled();
187
195
  });
196
+
197
+ it('transitions queued first-screen handles for subsequent calls and retains ownership until collected', async () => {
198
+ const releasedExecIds = [];
199
+ globalThis.lynx = {
200
+ getJSContext: () => ({
201
+ dispatchEvent: (event) => {
202
+ if (event.type === 'Lynx.Worklet.releaseBackgroundWorkletCtx') {
203
+ releasedExecIds.push(...event.data);
204
+ }
205
+ },
206
+ }),
207
+ };
208
+
209
+ const registered = [];
210
+ vi.spyOn(globalThis, 'FinalizationRegistry').mockImplementation(function(cleanup) {
211
+ return {
212
+ register(target, heldValue) {
213
+ registered.push({ target, heldValue, cleanup, finalized: false });
214
+ },
215
+ };
216
+ });
217
+ initWorklet();
218
+
219
+ function finalizeExcept(liveTargets) {
220
+ const live = new Set(liveTargets);
221
+ for (const entry of registered) {
222
+ if (!entry.finalized && !live.has(entry.target)) {
223
+ entry.finalized = true;
224
+ entry.cleanup(entry.heldValue);
225
+ }
226
+ }
227
+ }
228
+
229
+ // Mode A (queued before hydration) & Mode B (first called after hydration) on the same retained closure
230
+ let tick;
231
+ globalThis.registerWorklet('main-thread', 'timer-ref', function(element) {
232
+ if (!element || this._c.started.current) return;
233
+ this._c.started.current = true;
234
+ const { onQueued, onPostHydrate } = this._jsFn;
235
+ tick = (mode, value) => {
236
+ const handle = mode === 'queued' ? onQueued : onPostHydrate;
237
+ if (handle._isFirstScreen) {
238
+ globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground(
239
+ handle,
240
+ (fnId, execId) => dispatched.push({ mode, value, fnId, execId }),
241
+ );
242
+ return;
243
+ }
244
+ dispatched.push({ mode, value, fnId: handle._jsFnId, execId: handle._execId });
245
+ };
246
+ tick('queued', 1);
247
+ tick('queued', 2);
248
+ });
249
+
250
+ const dispatched = [];
251
+ let activeSlot = {
252
+ _wkltId: 'timer-ref',
253
+ _c: { started: { _wvid: -1, _initValue: false, _type: 'main-thread' } },
254
+ _jsFn: {
255
+ onQueued: { _isFirstScreen: true },
256
+ onPostHydrate: { _isFirstScreen: true },
257
+ },
258
+ };
259
+ const retainedQueuedHandle = activeSlot._jsFn.onQueued;
260
+ const retainedPostHandle = activeSlot._jsFn.onPostHydrate;
261
+ globalThis.runWorklet(activeSlot, [{ elementRefptr: {} }]);
262
+ expect(dispatched).toEqual([]);
263
+ expect(retainedQueuedHandle._delayIndices).toEqual([0, 1]);
264
+
265
+ // Hydrate with execId = 10
266
+ globalThis.lynxWorkletImpl._refImpl.updateWorkletRefInitValueChanges([[1, false, 'main-thread']]);
267
+ const hydratedSlot = {
268
+ _wkltId: 'timer-ref',
269
+ _execId: 10,
270
+ _c: { started: { _wvid: 1, _type: 'main-thread' } },
271
+ _jsFn: { onQueued: { _jsFnId: 1 }, onPostHydrate: { _jsFnId: 2 } },
272
+ };
273
+ globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.addRef(10, hydratedSlot);
274
+ globalThis.lynxWorkletImpl._hydrateCtx(hydratedSlot, activeSlot);
275
+ globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.runDelayedBackgroundFunctions();
276
+ expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(0);
277
+ activeSlot = hydratedSlot;
278
+ globalThis.runWorklet(activeSlot, [{ elementRefptr: {} }]);
279
+
280
+ expect(dispatched).toEqual([
281
+ { mode: 'queued', value: 1, fnId: 1, execId: 10 },
282
+ { mode: 'queued', value: 2, fnId: 1, execId: 10 },
283
+ ]);
284
+ expect(retainedQueuedHandle).not.toHaveProperty('_delayIndices');
285
+ expect(retainedQueuedHandle).toMatchObject({ _isFirstScreen: false, _hydratedEpoch: 0, _jsFnId: 1, _execId: 10 });
286
+ expect(retainedPostHandle).toMatchObject({ _isFirstScreen: false, _hydratedEpoch: 0, _jsFnId: 2, _execId: 10 });
287
+
288
+ // Rerender replaces slot with execId = 11, then MTS GC collects hydratedSlot while `tick` stays alive
289
+ const rerenderSlot = {
290
+ _wkltId: 'timer-ref',
291
+ _execId: 11,
292
+ _c: { started: { _wvid: 1, _type: 'main-thread' } },
293
+ _jsFn: { onQueued: { _jsFnId: 3 }, onPostHydrate: { _jsFnId: 4 } },
294
+ };
295
+ globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.addRef(11, rerenderSlot);
296
+ activeSlot = rerenderSlot;
297
+ globalThis.runWorklet(activeSlot, [{ elementRefptr: {} }]);
298
+
299
+ finalizeExcept([activeSlot, retainedQueuedHandle, retainedPostHandle]);
300
+ await Promise.resolve();
301
+ expect(releasedExecIds).toEqual([]);
302
+
303
+ // Post-hydration calls on both handles dispatch directly without re-entering delay queue
304
+ tick('queued', 3);
305
+ tick('post', 4);
306
+ expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(0);
307
+ expect(dispatched.slice(2)).toEqual([
308
+ { mode: 'queued', value: 3, fnId: 1, execId: 10 },
309
+ { mode: 'post', value: 4, fnId: 2, execId: 10 },
310
+ ]);
311
+
312
+ // Cancel timer and unmount slot: both execId 10 and 11 must now be released
313
+ tick = undefined;
314
+ activeSlot = undefined;
315
+ finalizeExcept([]);
316
+ await Promise.resolve();
317
+ expect(releasedExecIds.sort((a, b) => a - b)).toEqual([10, 11]);
318
+ });
319
+
320
+ it('binds a shared first-screen handle once per epoch, rebinds on reload, and ignores orphaned delays', () => {
321
+ const sharedHandle = { _isFirstScreen: true };
322
+ const nonFirstScreenHandle = { _jsFnId: 9, _execId: 4 };
323
+ const sharedFirstScreen = {
324
+ _wkltId: 'shared',
325
+ _jsFn: { cb: sharedHandle, existing: nonFirstScreenHandle },
326
+ };
327
+ const slotA = { _wkltId: 'shared', _execId: 21, _jsFn: { cb: { _jsFnId: 5 }, existing: { _jsFnId: 9 } } };
328
+ const slotB = { _wkltId: 'shared', _execId: 22, _jsFn: { cb: { _jsFnId: 5 } } };
329
+
330
+ globalThis.lynxWorkletImpl._hydrateCtx(slotA, sharedFirstScreen);
331
+ globalThis.lynxWorkletImpl._hydrateCtx(slotB, sharedFirstScreen);
332
+
333
+ expect(sharedHandle).toMatchObject({ _isFirstScreen: false, _hydratedEpoch: 0, _jsFnId: 5, _execId: 21 });
334
+ expect(nonFirstScreenHandle).toEqual({ _jsFnId: 9, _execId: 4 });
335
+ expect(slotB._jsFn.cb._execId).toBe(22);
336
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(21)).toBe(1);
337
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(22)).toBeUndefined();
338
+
339
+ // Once hydration finishes, an orphaned unhydrated first-screen handle does not grow the delay queue
340
+ globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.runDelayedBackgroundFunctions();
341
+ const orphan = { _isFirstScreen: true };
342
+ const orphanTask = vi.fn();
343
+ globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground(orphan, orphanTask);
344
+ expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(0);
345
+ expect(orphan).not.toHaveProperty('_delayIndices');
346
+
347
+ // Reload recreates the lifecycle manager, clears stale _delayIndices, advances epoch, and rebinds handles
348
+ const epoch0Manager = globalThis.lynxWorkletImpl._jsFunctionLifecycleManager;
349
+ clearDelayedRunOnBackgroundFunctions();
350
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager).not.toBe(epoch0Manager);
351
+ const staleTask = vi.fn();
352
+ globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground(sharedHandle, staleTask);
353
+ expect(sharedHandle._delayIndices).toEqual([0]);
354
+
355
+ // Aborting pre-hydration via another reload must clear sharedHandle._delayIndices so it cannot overwrite index 0
356
+ clearDelayedRunOnBackgroundFunctions();
357
+ expect(sharedHandle).not.toHaveProperty('_delayIndices');
358
+ globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground(orphan, orphanTask);
359
+ expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(1);
360
+
361
+ const epoch2Slot = {
362
+ _wkltId: 'shared',
363
+ _execId: 30,
364
+ _jsFn: { cb: { _jsFnId: 6 }, orphan: { _jsFnId: 7 } },
365
+ };
366
+ globalThis.lynxWorkletImpl._hydrateCtx(epoch2Slot, {
367
+ _wkltId: 'shared',
368
+ _jsFn: { cb: sharedHandle, orphan },
369
+ });
370
+ globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.runDelayedBackgroundFunctions();
371
+ expect(staleTask).not.toHaveBeenCalled();
372
+ expect(orphanTask).toHaveBeenCalledExactlyOnceWith(7, 30);
373
+ expect(sharedHandle).toMatchObject({ _isFirstScreen: false, _hydratedEpoch: 2, _jsFnId: 6, _execId: 30 });
374
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(30)).toBe(2);
375
+ });
188
376
  });
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
5
 
6
6
  import {
7
7
  getFromWorkletRefMap,
8
+ initWorkletRef,
8
9
  isHydratedWorkletValue,
9
10
  removeValueFromWorkletRefMap,
10
11
  updateWorkletRefInitValueChanges,
@@ -685,4 +686,19 @@ describe('WorkletRef', () => {
685
686
  'background-thread-init-2',
686
687
  );
687
688
  });
689
+
690
+ it('keeps ref maps isolated per RefImpl instance', () => {
691
+ const first = initWorkletRef();
692
+ const second = initWorkletRef();
693
+
694
+ first.updateWorkletRefInitValueChanges([[1, 'first-value']]);
695
+ second.updateWorkletRefInitValueChanges([[1, 'second-value']]);
696
+ first.updateWorkletRef({ _wvid: -1 }, 'first-element');
697
+ second.clearFirstScreenWorkletRefMap();
698
+
699
+ expect(first._workletRefMap[1].current).toBe('first-value');
700
+ expect(second._workletRefMap[1].current).toBe('second-value');
701
+ expect(first._firstScreenWorkletRefMap[-1].current.element).toBe('first-element');
702
+ expect(second._firstScreenWorkletRefMap).toEqual({});
703
+ });
688
704
  });
@@ -1,7 +1,7 @@
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 { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
4
+ import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
5
 
6
6
  import { Element } from '../../src/worklet-runtime/api/element';
7
7
  import { initApiEnv } from '../../src/worklet-runtime/api/lynxApi';
@@ -14,6 +14,11 @@ import {
14
14
  } from '../../src/worklet-runtime/workletRef';
15
15
  import { initWorklet } from '../../src/worklet-runtime/workletRuntime';
16
16
 
17
+ afterEach(() => {
18
+ globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.dispose();
19
+ delete globalThis.lynxWorkletImpl;
20
+ });
21
+
17
22
  describe('Worklet', () => {
18
23
  const consoleMock = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
19
24
 
@@ -21,6 +26,7 @@ describe('Worklet', () => {
21
26
  globalThis.SystemInfo = {
22
27
  lynxSdkVersion: '2.16',
23
28
  };
29
+ globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.dispose();
24
30
  delete globalThis.lynxWorkletImpl;
25
31
  globalThis.lynx = {
26
32
  requestAnimationFrame: vi.fn(),
@@ -808,3 +814,49 @@ it('requestAnimationFrame should throw error before 2.16 2', async () => {
808
814
  globalThis.runWorklet(worklet, [1]);
809
815
  expect(fn).toBeCalled();
810
816
  });
817
+
818
+ it('preserves an already-bound handle execId and skips unbound handles without a root execId', () => {
819
+ globalThis.SystemInfo = { lynxSdkVersion: '2.16' };
820
+ initWorklet();
821
+ globalThis.registerWorklet('main-thread', 'capture-handles', function() {
822
+ return this._jsFn;
823
+ });
824
+
825
+ const prebound = { _jsFnId: 1, _execId: 4 };
826
+ globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.addRef(4, prebound);
827
+ const unbound = { _jsFnId: 2 };
828
+
829
+ // Root without `_execId` preserves `prebound._execId` and leaves `unbound` uncounted.
830
+ const withoutExec = { _wkltId: 'capture-handles', _jsFn: { prebound, unbound } };
831
+ globalThis.runWorklet(withoutExec, []);
832
+ expect(prebound._execId).toBe(4);
833
+ expect(unbound._execId).toBeUndefined();
834
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(4)).toBe(1);
835
+
836
+ // Another root with `_execId = 9` still does not overwrite `prebound._execId`.
837
+ const withOtherExec = { _wkltId: 'capture-handles', _execId: 9, _jsFn: { prebound } };
838
+ globalThis.runWorklet(withOtherExec, []);
839
+ expect(prebound._execId).toBe(4);
840
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(4)).toBe(1);
841
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(9)).toBeUndefined();
842
+
843
+ // A hydrated handle from an older reload epoch must not register its retired `_execId` before re-hydration.
844
+ const staleEpochHandle = { _jsFnId: 3, _execId: 7, _isFirstScreen: false, _hydratedEpoch: 0 };
845
+ globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.clearDelayedBackgroundFunctions();
846
+ globalThis.runWorklet({ _wkltId: 'capture-handles', _jsFn: { staleEpochHandle } }, []);
847
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(7)).toBeUndefined();
848
+
849
+ // Short-circuit checks: a prebound handle without `_hydratedEpoch` must neither read root `_execId`
850
+ // nor dereference `_runOnBackgroundDelayImpl.epoch`.
851
+ globalThis.registerWorklet('main-thread', 'capture-arg-handle', function(cb) {
852
+ return cb._execId;
853
+ });
854
+ const args = [{ _jsFnId: 4, _execId: 12 }];
855
+ Object.defineProperty(args, '_execId', {
856
+ get() {
857
+ throw new Error('root _execId should not be read for prebound handle');
858
+ },
859
+ });
860
+ delete globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl;
861
+ expect(globalThis.runWorklet({ _wkltId: 'capture-arg-handle' }, args)).toBe(12);
862
+ });
@@ -51,6 +51,21 @@ declare function useTransition(): [false, typeof startTransition];
51
51
  */
52
52
  declare function use<T>(resource: Promise<T> | Context<T>): T;
53
53
 
54
+ /**
55
+ * Returns a deferred copy of a value.
56
+ *
57
+ * Note: This is Preact's `useDeferredValue` implementation, which differs from React's:
58
+ * - React defers the value with interruptible, low-priority rendering
59
+ * - Preact returns the previous value first and updates it in a follow-up render
60
+ * once the current one has finished, without true concurrent rendering
61
+ *
62
+ * @param value - The value to defer
63
+ * @returns The deferred value
64
+ *
65
+ * @public
66
+ */
67
+ declare function useDeferredValue<T>(value: T): T;
68
+
54
69
  /**
55
70
  * Runs an effect whose write is meant to be visible to the effects that read it.
56
71
  *
@@ -75,12 +90,13 @@ declare function use<T>(resource: Promise<T> | Context<T>): T;
75
90
  * @deprecated `useInsertionEffect` in the background thread is an alias of `useEffect` and cannot offer React's insertion-phase timing: the effect has not run when `render` returns, and its cleanup is deferred to a later flush instead of running inside the unmount commit.
76
91
  */
77
92
  declare const useInsertionEffect: typeof import('@lynx-js/react').useEffect;
78
- export { startTransition, use, useInsertionEffect, useTransition };
93
+ export { startTransition, use, useDeferredValue, useInsertionEffect, useTransition };
79
94
 
80
95
  // type for the default export
81
96
  declare const _default: typeof import('@lynx-js/react') & {
82
97
  startTransition: typeof startTransition;
83
98
  use: typeof use;
99
+ useDeferredValue: typeof useDeferredValue;
84
100
  useInsertionEffect: typeof useInsertionEffect;
85
101
  useTransition: typeof useTransition;
86
102
  };
@@ -1,7 +1,7 @@
1
1
  // Copyright 2025 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 { startTransition, use, useTransition } from 'preact/compat';
4
+ import { startTransition, use, useDeferredValue, useTransition } from 'preact/compat';
5
5
 
6
6
  /* eslint-disable-next-line import/default */
7
7
  import ReactLynx, { useEffect } from '@lynx-js/react';
@@ -11,9 +11,10 @@ const useInsertionEffect = useEffect;
11
11
  export default /*#__PURE__*/ Object.assign({}, ReactLynx, {
12
12
  startTransition,
13
13
  use,
14
+ useDeferredValue,
14
15
  useInsertionEffect,
15
16
  useTransition,
16
17
  });
17
18
 
18
19
  export * from '@lynx-js/react';
19
- export { startTransition, use, useInsertionEffect, useTransition };
20
+ export { startTransition, use, useDeferredValue, useInsertionEffect, useTransition };
@@ -54,6 +54,7 @@ export const {
54
54
  // compat
55
55
  startTransition,
56
56
  use,
57
+ useDeferredValue,
57
58
  useInsertionEffect,
58
59
  useTransition,
59
60
  } = target[sExportsReactCompat];
@@ -56,6 +56,7 @@ export const {
56
56
  snapshotManager,
57
57
  snapshotCreatorMap,
58
58
  SnapshotInstance,
59
+ TransferRegistry,
59
60
  transformRef,
60
61
  transformToWorklet,
61
62
  updateEvent,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribute-name.js","sourceRoot":"","sources":["../../src/core/attribute-name.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,4BAA4B,GAAG,kEAAkE,CAAC;AACxG,MAAM,wBAAwB,GAAG,6EAA6E,CAAC;AAE/G,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,OAAO,4BAA4B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,GAAW;IAClD,OAAO,wBAAwB,CAAC,IAAI,CAA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B,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;YACjC,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;IAC9C,CAAC;IAED,+DAA+D;IAC/D,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","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\nconst lynxEventAttributeNameRegExp = /^(?:global-bind|bind|catch|capture-bind|capture-catch)[A-Za-z]+$/;\nconst namespacedEventKeyRegExp = /^[A-Za-z-]+:(?:global-bind|bind|catch|capture-bind|capture-catch)[A-Za-z]+$/;\n\nexport function isEventPropKey(key: string): boolean {\n return lynxEventAttributeNameRegExp.test(key);\n}\n\nexport function isNamespacedEventPropKey(key: string): boolean {\n return namespacedEventKeyRegExp.test(key);\n}\n\nfunction isReactEventAttributeName(name: string): boolean {\n if (\n name.length <= 2\n || !name.startsWith('on')\n ) {\n return false;\n }\n\n let code = name.charCodeAt(2);\n if (code < 65 || code > 90) {\n return false;\n }\n for (let index = 3; index < name.length; index++) {\n code = name.charCodeAt(index);\n if (\n (code < 65 || code > 90)\n && (code < 97 || code > 122)\n ) {\n return false;\n }\n }\n return true;\n}\n\nfunction toDashCase(name: string): string {\n let index = 0;\n for (; index < name.length; index++) {\n const code = name.charCodeAt(index);\n if (code >= 65 && code <= 90) {\n break;\n }\n }\n\n if (index === name.length) {\n return name;\n }\n\n let transformed = name.slice(0, index);\n for (; index < name.length; index++) {\n const code = name.charCodeAt(index);\n if (code >= 65 && code <= 90) {\n if (index !== 0) {\n transformed += '-';\n }\n transformed += name[index]!.toLowerCase();\n } else {\n transformed += name[index];\n }\n }\n return transformed;\n}\n\nexport function transformAttrName(name: string): string {\n const config = lynx.__runtime_configs__?.transformBuiltinAttributeNames;\n\n // A disabled config keeps every name unchanged.\n if (!config) {\n return name;\n }\n\n // An object config applies rules in `rename > preserve > mode` order.\n if (config !== true) {\n if (\n config.rename\n && Object.prototype.hasOwnProperty.call(config.rename, name)\n ) {\n return config.rename[name]!;\n }\n if (\n config.preserve?.includes(name)\n || config.mode === 'mapping-only'\n ) {\n return name;\n }\n }\n\n // Enabled configs keep native Lynx event names unchanged.\n if (isEventPropKey(name) || isNamespacedEventPropKey(name)) {\n return name;\n }\n\n // `true` and the default dash-case mode apply React-style event mappings.\n if (isReactEventAttributeName(name)) {\n if (name === 'onClick') {\n return 'bindtap';\n } else if (name === 'onCatchTap') {\n return 'catchtap';\n }\n return `bind${name.slice(2).toLowerCase()}`;\n }\n\n // Remaining names use dash-case when the transform is enabled.\n return toDashCase(name);\n}\n"]}
@@ -2,8 +2,8 @@
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
4
  import { BackgroundFunctionExecMap } from './exec-map.js';
5
- import { isSdkVersionGt } from '../../utils.js';
6
- import { delayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';
5
+ import { isSdkVersionGt } from '../../shared/version.js';
6
+ import { delayRunOnBackground, shouldDelayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';
7
7
  import { WorkletEvents } from '../../worklet-runtime/bindings/events.js';
8
8
  import { addReloadScopedEventListener, dispatchReloadScopedEvent } from '../reload-scoped-event.js';
9
9
  import { isRuntimeDestroyed, registerDestroyTask } from '../runtime-destroy.js';
@@ -108,18 +108,18 @@ export function runOnBackground(f) {
108
108
  return new Promise((resolve) => {
109
109
  if (isRuntimeDestroyed())
110
110
  return;
111
- const resolveId = onFunctionCall(resolve);
112
- if (obj._isFirstScreen) {
111
+ if (shouldDelayRunOnBackground(obj)) {
113
112
  delayRunOnBackground(obj, (fnId, execId) => {
114
- dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId);
113
+ dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolve);
115
114
  });
116
115
  return;
117
116
  }
118
- dispatchRunBackgroundFunctionEvent(obj._jsFnId, params, obj._execId, resolveId);
117
+ dispatchRunBackgroundFunctionEvent(obj._jsFnId, params, obj._execId, resolve);
119
118
  });
120
119
  };
121
120
  }
122
- function dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId) {
121
+ function dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolve) {
122
+ const resolveId = onFunctionCall(resolve);
123
123
  dispatchReloadScopedEvent(lynx.getJSContext(), {
124
124
  type: WorkletEvents.runOnBackground,
125
125
  data: {
@@ -1 +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,4BAA4B,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAChF,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,gCAAgC,EAAE,CAAC;QACrC,OAAO;IACT,CAAC;IAED,SAAS,KAAK,IAAI,yBAAyB,EAAE,CAAC;IAC9C,MAAM,OAA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C,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,yBAAyB,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE;QAC7C,IAAI,EAAE,aAAa,CAAC,eAAe;QACnC,IAAI,EAAE;YACJ,GAAG,EAAE;gBACH,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,MAAM;aAChB;YACD,MAAM;YACN,SAAS;SACa;KACzB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 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 { BackgroundFunctionExecMap } from './exec-map.js';\nimport { isSdkVersionGt } from '../../utils.js';\nimport { delayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';\nimport { WorkletEvents } from '../../worklet-runtime/bindings/events.js';\nimport type { RunWorkletCtxRetData } from '../../worklet-runtime/bindings/events.js';\nimport type { ClosureValueType, JsFnHandle, Worklet } from '../../worklet-runtime/bindings/types.js';\nimport { addReloadScopedEventListener, dispatchReloadScopedEvent } from '../reload-scoped-event.js';\nimport { isRuntimeDestroyed, registerDestroyTask } from '../runtime-destroy.js';\nimport { onFunctionCall } from '../thread-function-call/return-value.js';\n\n/**\n * @internal\n */\ninterface RunOnBackgroundData {\n obj: JsFnHandle;\n params: unknown[];\n resolveId: number;\n}\n\nlet execIdMap: BackgroundFunctionExecMap | undefined;\nlet cleanupBackgroundFunctionRuntime: (() => void) | undefined;\nlet unregisterBackgroundFunctionCleanup: (() => void) | undefined;\n\nfunction initBackgroundFunctionRuntime(): void {\n 'background only';\n if (cleanupBackgroundFunctionRuntime) {\n return;\n }\n\n execIdMap ??= new BackgroundFunctionExecMap();\n const context = lynx.getCoreContext();\n const removeListener = addReloadScopedEventListener(context, WorkletEvents.runOnBackground, runBackgroundFunction);\n context.addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n\n cleanupBackgroundFunctionRuntime = () => {\n removeListener();\n context.removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n execIdMap!.clear();\n cleanupBackgroundFunctionRuntime = undefined;\n };\n}\n\n/**\n * @internal\n */\nexport function runBackgroundFunction(data: RunOnBackgroundData): void {\n 'background only';\n const obj = execIdMap!.findJsFnHandle(data.obj._execId!, data.obj._jsFnId!);\n const f = obj?._fn;\n if (!f) {\n throw new Error('runOnBackground: JS function not found: ' + JSON.stringify(data.obj));\n }\n const returnValue = f(...data.params);\n dispatchReloadScopedEvent(lynx.getCoreContext(), {\n type: WorkletEvents.FunctionCallRet,\n data: { resolveId: data.resolveId, returnValue } satisfies RunWorkletCtxRetData,\n });\n}\n\nfunction releaseBackgroundFunctionCtx(event: RuntimeProxy.Event): void {\n 'background only';\n for (const id of event.data) {\n execIdMap!.remove(id as number);\n }\n}\n\n/**\n * @internal\n */\nexport function registerBackgroundFunctionCtx(ctx: Worklet): void {\n 'background only';\n initBackgroundFunctionRuntime();\n ensureBackgroundFunctionCleanup();\n execIdMap!.add(ctx);\n}\n\nfunction ensureBackgroundFunctionCleanup(): void {\n if (unregisterBackgroundFunctionCleanup) {\n return;\n }\n unregisterBackgroundFunctionCleanup = registerDestroyTask(() => {\n resetBackgroundFunctionRuntime();\n });\n}\n\nexport function resetBackgroundFunctionRuntime(): void {\n cleanupBackgroundFunctionRuntime?.();\n unregisterBackgroundFunctionCleanup?.();\n unregisterBackgroundFunctionCleanup = undefined;\n}\n\n/**\n * `runOnBackground` allows triggering js functions on the background thread asynchronously.\n * @param f - The js function to be called.\n * @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.\n * @public\n *\n * @example\n *\n * ```ts\n * import { runOnBackground } from '@lynx-js/react';\n *\n * async function someMainthreadFunction() {\n * 'main thread';\n * const fn = runOnBackground(() => {\n * return 'hello';\n * });\n * const result = await fn();\n * }\n * ```\n *\n * @group Functions\n */\nexport function runOnBackground<R, Fn extends (...args: any[]) => R>(\n f: Fn,\n): (...args: Parameters<Fn>) => Promise<R> {\n if (!isSdkVersionGt(2, 15)) {\n throw new Error('runOnBackground requires Lynx sdk version 2.16.');\n }\n if (__JS__) {\n throw new Error('runOnBackground can only be used on the main thread.');\n }\n const obj = f as any as JsFnHandle;\n if (obj._error) {\n throw new Error(obj._error);\n }\n return async (...params: ClosureValueType[]): Promise<R> => {\n return new Promise((resolve) => {\n if (isRuntimeDestroyed()) return;\n const resolveId = onFunctionCall(resolve);\n\n if (obj._isFirstScreen) {\n delayRunOnBackground(obj, (fnId: number, execId: number) => {\n dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId);\n });\n return;\n }\n\n dispatchRunBackgroundFunctionEvent(obj._jsFnId!, params, obj._execId!, resolveId);\n });\n };\n}\n\nfunction dispatchRunBackgroundFunctionEvent(\n fnId: number,\n params: ClosureValueType[],\n execId: number,\n resolveId: number,\n): void {\n dispatchReloadScopedEvent(lynx.getJSContext(), {\n type: WorkletEvents.runOnBackground,\n data: {\n obj: {\n _jsFnId: fnId,\n _execId: execId,\n },\n params,\n resolveId,\n } as RunOnBackgroundData,\n });\n}\n"]}
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;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AE,IAAI;gBACb,OAAO,EAAE,MAAM;aAChB;YACD,MAAM;YACN,SAAS;SACa;KACzB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 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 { BackgroundFunctionExecMap } from './exec-map.js';\nimport { isSdkVersionGt } from '../../shared/version.js';\nimport { delayRunOnBackground, shouldDelayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';\nimport { WorkletEvents } from '../../worklet-runtime/bindings/events.js';\nimport type { RunWorkletCtxRetData } from '../../worklet-runtime/bindings/events.js';\nimport type { ClosureValueType, JsFnHandle, Worklet } from '../../worklet-runtime/bindings/types.js';\nimport { addReloadScopedEventListener, dispatchReloadScopedEvent } from '../reload-scoped-event.js';\nimport { isRuntimeDestroyed, registerDestroyTask } from '../runtime-destroy.js';\nimport { onFunctionCall } from '../thread-function-call/return-value.js';\n\n/**\n * @internal\n */\ninterface RunOnBackgroundData {\n obj: JsFnHandle;\n params: unknown[];\n resolveId: number;\n}\n\nlet execIdMap: BackgroundFunctionExecMap | undefined;\nlet cleanupBackgroundFunctionRuntime: (() => void) | undefined;\nlet unregisterBackgroundFunctionCleanup: (() => void) | undefined;\n\nfunction initBackgroundFunctionRuntime(): void {\n 'background only';\n if (cleanupBackgroundFunctionRuntime) {\n return;\n }\n\n execIdMap ??= new BackgroundFunctionExecMap();\n const context = lynx.getCoreContext();\n const removeListener = addReloadScopedEventListener(context, WorkletEvents.runOnBackground, runBackgroundFunction);\n context.addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n\n cleanupBackgroundFunctionRuntime = () => {\n removeListener();\n context.removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n execIdMap!.clear();\n cleanupBackgroundFunctionRuntime = undefined;\n };\n}\n\n/**\n * @internal\n */\nexport function runBackgroundFunction(data: RunOnBackgroundData): void {\n 'background only';\n const obj = execIdMap!.findJsFnHandle(data.obj._execId!, data.obj._jsFnId!);\n const f = obj?._fn;\n if (!f) {\n throw new Error('runOnBackground: JS function not found: ' + JSON.stringify(data.obj));\n }\n const returnValue = f(...data.params);\n dispatchReloadScopedEvent(lynx.getCoreContext(), {\n type: WorkletEvents.FunctionCallRet,\n data: { resolveId: data.resolveId, returnValue } satisfies RunWorkletCtxRetData,\n });\n}\n\nfunction releaseBackgroundFunctionCtx(event: RuntimeProxy.Event): void {\n 'background only';\n for (const id of event.data) {\n execIdMap!.remove(id as number);\n }\n}\n\n/**\n * @internal\n */\nexport function registerBackgroundFunctionCtx(ctx: Worklet): void {\n 'background only';\n initBackgroundFunctionRuntime();\n ensureBackgroundFunctionCleanup();\n execIdMap!.add(ctx);\n}\n\nfunction ensureBackgroundFunctionCleanup(): void {\n if (unregisterBackgroundFunctionCleanup) {\n return;\n }\n unregisterBackgroundFunctionCleanup = registerDestroyTask(() => {\n resetBackgroundFunctionRuntime();\n });\n}\n\nexport function resetBackgroundFunctionRuntime(): void {\n cleanupBackgroundFunctionRuntime?.();\n unregisterBackgroundFunctionCleanup?.();\n unregisterBackgroundFunctionCleanup = undefined;\n}\n\n/**\n * `runOnBackground` allows triggering js functions on the background thread asynchronously.\n * @param f - The js function to be called.\n * @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.\n * @public\n *\n * @example\n *\n * ```ts\n * import { runOnBackground } from '@lynx-js/react';\n *\n * async function someMainthreadFunction() {\n * 'main thread';\n * const fn = runOnBackground(() => {\n * return 'hello';\n * });\n * const result = await fn();\n * }\n * ```\n *\n * @group Functions\n */\nexport function runOnBackground<R, Fn extends (...args: any[]) => R>(\n f: Fn,\n): (...args: Parameters<Fn>) => Promise<R> {\n if (!isSdkVersionGt(2, 15)) {\n throw new Error('runOnBackground requires Lynx sdk version 2.16.');\n }\n if (__JS__) {\n throw new Error('runOnBackground can only be used on the main thread.');\n }\n const obj = f as any as JsFnHandle;\n if (obj._error) {\n throw new Error(obj._error);\n }\n return async (...params: ClosureValueType[]): Promise<R> => {\n return new Promise((resolve) => {\n if (isRuntimeDestroyed()) return;\n\n if (shouldDelayRunOnBackground(obj)) {\n delayRunOnBackground(obj, (fnId: number, execId: number) => {\n dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolve);\n });\n return;\n }\n\n dispatchRunBackgroundFunctionEvent(obj._jsFnId!, params, obj._execId!, resolve);\n });\n };\n}\n\nfunction dispatchRunBackgroundFunctionEvent(\n fnId: number,\n params: ClosureValueType[],\n execId: number,\n resolve: (value: any) => void,\n): void {\n const resolveId = onFunctionCall(resolve);\n dispatchReloadScopedEvent(lynx.getJSContext(), {\n type: WorkletEvents.runOnBackground,\n data: {\n obj: {\n _jsFnId: fnId,\n _execId: execId,\n },\n params,\n resolveId,\n } as RunOnBackgroundData,\n });\n}\n"]}
@@ -26,7 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
26
  SOFTWARE.
27
27
  */
28
28
  import { Fragment, options } from 'preact';
29
- import { DIFF, DIFFED, RENDER, ROOT } from './render-constants.js';
29
+ import { DIFF, DIFFED, RENDER, ROOT } from '../shared/render-constants.js';
30
30
  /**
31
31
  * Get human readable name of the component/dom node
32
32
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-stack.js","sourceRoot":"","sources":["../../src/core/component-stack.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAG3C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAW3E;;GAEG;AACH,SAAS,mBAAmB,CAAC,KAAmB;IAC9C,IAAI,KAAK,CAAC,IAAI,KA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CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2025 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\n/**\n * @license\nThe MIT License (MIT)\n\nCopyright (c) 2015-present Jason Miller\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n */\n\nimport { Fragment, options } from 'preact';\nimport type { VNode } from 'preact';\n\nimport { DIFF, DIFFED, RENDER, ROOT } from '../shared/render-constants.js';\n\ninterface PatchedVNode extends VNode {\n _owner?: PatchedVNode | null;\n\n __source?: {\n fileName: string;\n lineNumber: number;\n };\n}\n\n/**\n * Get human readable name of the component/dom node\n */\nfunction getVNodeDisplayName(vnode: PatchedVNode): string {\n if (vnode.type === Fragment) {\n return 'Fragment';\n } else if (typeof vnode.type == 'function') {\n return vnode.type.displayName ?? vnode.type.name;\n } else if (typeof vnode.type == 'string') {\n return vnode.type;\n }\n\n return '#text';\n}\n\n/**\n * Used to keep track of the currently rendered `vnode` and print it\n * in debug messages.\n */\nconst renderStack: PatchedVNode[] = [];\n\n/**\n * Keep track of the current owners. An owner describes a component\n * which was responsible to render a specific `vnode`. This exclude\n * children that are passed via `props.children`, because they belong\n * to the parent owner.\n *\n * ```jsx\n * const Foo = props => <div>{props.children}</div> // div's owner is Foo\n * const Bar = props => {\n * return (\n * <Foo><span /></Foo> // Foo's owner is Bar, span's owner is Bar\n * )\n * }\n * ```\n *\n * Note: A `vnode` may be hoisted to the root scope due to compiler\n * optimization. In these cases the `_owner` will be different.\n */\nlet ownerStack: PatchedVNode[] = [];\nlet didInstallComponentStack = false;\n\n/**\n * Get the currently rendered `vnode`\n */\nexport function getCurrentVNode(): PatchedVNode | null {\n return renderStack.length > 0 ? renderStack[renderStack.length - 1]! : null;\n}\n\n/**\n * Check if a `vnode` is a possible owner.\n */\nfunction isPossibleOwner(vnode: PatchedVNode) {\n return typeof vnode.type == 'function' && vnode.type != Fragment;\n}\n\n/**\n * Return the component stack that was captured up to this point.\n */\nexport function getOwnerStack(vnode: PatchedVNode): string {\n const stack = [vnode];\n let next = vnode;\n while (next._owner != null) {\n stack.push(next._owner);\n next = next._owner;\n }\n\n return stack.reduce((acc, owner) => {\n acc += ` in ${getVNodeDisplayName(owner)}`;\n\n const source = owner.__source;\n if (source) {\n acc += ` (at ${source.fileName}:${source.lineNumber})`;\n }\n\n return (acc += '\\n');\n }, '');\n}\n\n/**\n * Setup code to capture the component trace while rendering. Note that\n * we cannot simply traverse `vnode._parent` upwards, because we have some\n * debug messages for `this.setState` where the `vnode` is `undefined`.\n */\nexport function setupComponentStack(): void {\n renderStack.length = 0;\n ownerStack = [];\n if (didInstallComponentStack) {\n return;\n }\n didInstallComponentStack = true;\n\n /* eslint-disable @typescript-eslint/unbound-method */\n const oldDiff = options[DIFF];\n const oldDiffed = options[DIFFED];\n const oldRoot = options[ROOT];\n const oldVNode = options.vnode;\n const oldRender = options[RENDER];\n /* eslint-enable @typescript-eslint/unbound-method */\n\n options[DIFFED] = vnode => {\n if (isPossibleOwner(vnode)) {\n const ownerIndex = ownerStack.lastIndexOf(vnode);\n if (ownerIndex !== -1) {\n ownerStack.length = ownerIndex;\n }\n const renderIndex = renderStack.lastIndexOf(vnode);\n if (renderIndex !== -1) {\n renderStack.length = renderIndex;\n }\n }\n if (oldDiffed) oldDiffed(vnode);\n };\n\n options[DIFF] = vnode => {\n if (isPossibleOwner(vnode)) {\n renderStack.push(vnode);\n }\n if (oldDiff) oldDiff(vnode);\n };\n\n options[ROOT] = (vnode, parent) => {\n if (!(parent as { parentNode?: unknown } | null | undefined)?.parentNode) {\n renderStack.length = 0;\n ownerStack = [];\n }\n if (oldRoot) oldRoot(vnode, parent);\n };\n\n options.vnode = (vnode: PatchedVNode) => {\n // Scheduled component updates clone the vnode before entering its render scope.\n // Preserve the original owner when Preact invokes this hook for that clone.\n if (vnode._owner === undefined) {\n vnode._owner = ownerStack.length > 0 ? ownerStack[ownerStack.length - 1]! : null;\n }\n if (oldVNode) oldVNode(vnode);\n };\n\n options[RENDER] = vnode => {\n if (isPossibleOwner(vnode)) {\n ownerStack.push(vnode);\n }\n\n if (oldRender) oldRender(vnode);\n };\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function isDirectOrDeepEqual(a: unknown, b: unknown): boolean;
@@ -0,0 +1,31 @@
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 { getCurrentVNode, getOwnerStack } from './component-stack.js';
5
+ export function isDirectOrDeepEqual(a, b) {
6
+ if (a === b) {
7
+ return true;
8
+ }
9
+ try {
10
+ if (typeof a == 'object' && a !== null && typeof b == 'object' && b !== null
11
+ && JSON.stringify(a) === JSON.stringify(b)) {
12
+ return true;
13
+ }
14
+ }
15
+ catch (error) {
16
+ if (__DEV__ && /circular|cyclic/i.test(error.message)) {
17
+ // JavaScript engines give this different errors name and messages:
18
+ // PrimJS: "circular reference"
19
+ // JavaScriptCore: "JSON.stringify cannot serialize cyclic structures"
20
+ // V8: "Converting circular structure to JSON"
21
+ const vnode = getCurrentVNode();
22
+ if (vnode) {
23
+ const stack = getOwnerStack(vnode);
24
+ error.message += `\n\n${stack}`;
25
+ }
26
+ }
27
+ throw error;
28
+ }
29
+ return false;
30
+ }
31
+ //# sourceMappingURL=deep-equal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-equal.js","sourceRoot":"","sources":["../../src/core/deep-equal.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEtE,MAAM,UAAU,mBAAmB,CAAC,CAAU,EAAE,CAAU;IACxD,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC;QACH,IACE,OAAO,CAAC,IAAI,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,QAAQ,IAAI,CAAC,KAAK,IAAI;eACrE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAC1C,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAE,KAAe,CAAC,OAAO,CAAC,EAAE,CAAC;YACjE,mEAAmE;YACnE,+BAA+B;YAC/B,sEAAsE;YACtE,8CAA8C;YAC9C,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;YAChC,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;gBAClC,KAAe,CAAC,OAAO,IAAI,OAAO,KAAK,EAAE,CAAC;YAC7C,CAAC;QACH,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright 2024 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 { getCurrentVNode, getOwnerStack } from './component-stack.js';\n\nexport function isDirectOrDeepEqual(a: unknown, b: unknown): boolean {\n if (a === b) {\n return true;\n }\n try {\n if (\n typeof a == 'object' && a !== null && typeof b == 'object' && b !== null\n && JSON.stringify(a) === JSON.stringify(b)\n ) {\n return true;\n }\n } catch (error) {\n if (__DEV__ && /circular|cyclic/i.test((error as Error).message)) {\n // JavaScript engines give this different errors name and messages:\n // PrimJS: \"circular reference\"\n // JavaScriptCore: \"JSON.stringify cannot serialize cyclic structures\"\n // V8: \"Converting circular structure to JSON\"\n const vnode = getCurrentVNode();\n if (vnode) {\n const stack = getOwnerStack(vnode);\n (error as Error).message += `\\n\\n${stack}`;\n }\n }\n throw error;\n }\n return false;\n}\n"]}
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { options } from 'preact';
11
11
  import { CHILDREN, COMPONENT, DIFF, DIFFED, HOOK, HOOKS, LIST, MASK, PARENT, PENDING_EFFECTS, RENDER, ROOT, VALUE, VNODE, } from '../../shared/render-constants.js';
12
- import { noop } from '../../utils.js';
12
+ import { noop } from '../../shared/utils.js';
13
13
  let currentIndex;
14
14
  let currentComponent;
15
15
  let currentHook;
@@ -1 +1 @@
1
- {"version":3,"file":"mainThreadImpl.js","sourceRoot":"","sources":["../../../src/core/hooks/mainThreadImpl.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAUjC,OAAO,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,eAAe,EACf,MAAM,EACN,IAAI,EACJ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AM,CAAC,KAAK,IAAI,EAAE,CAAC;YAC/D,IAAI,GAAG,IAAK,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;QACD;;;;WAIG;QACH,MAAM,IAAI,GAAG,IAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACnD,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAW,CAAC;AAChC,CAAC;AAED,mBAAmB;AACnB,MAAM,SAAS,GAAG,IAA4B,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAkC,CAAC;AAC3D,MAAM,mBAAmB,GAAG,IAAsC,CAAC;AAEnE,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,UAAU,EACV,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,UAAU,EACV,MAAM,EACN,QAAQ,GACT,CAAC","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\n/**\n * Implements hooks in the main thread.\n * This module is modified from preact/hooks\n *\n * internal-preact/hooks/dist/hooks.mjs\n */\n\nimport { options } from 'preact';\nimport type { Component, ErrorInfo, PreactContext } from 'preact';\nimport type {\n Dispatch,\n useEffect as useEffectType,\n useErrorBoundary as useErrorBoundaryType,\n useImperativeHandle as useImperativeHandleType,\n useLayoutEffect as useLayoutEffectType,\n} from 'preact/hooks';\n\nimport {\n CHILDREN,\n COMPONENT,\n DIFF,\n DIFFED,\n HOOK,\n HOOKS,\n LIST,\n MASK,\n PARENT,\n PENDING_EFFECTS,\n RENDER,\n ROOT,\n VALUE,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { noop } from '../../utils.js';\n\nlet currentIndex: number;\nlet currentComponent: Component | null | undefined;\nlet currentHook: number;\nlet hooksInstalled = false;\nlet oldBeforeDiff: ((vnode: any) => void) | undefined;\nlet oldBeforeRender: ((vnode: any) => void) | undefined;\nlet oldAfterDiff: ((vnode: any) => void) | undefined;\nlet oldRoot: ((vnode: any, parentDom: any) => void) | undefined;\n\nfunction installMainThreadHooks(): void {\n if (hooksInstalled) {\n return;\n }\n hooksInstalled = true;\n /* eslint-disable @typescript-eslint/unbound-method */\n oldBeforeDiff = options[DIFF];\n oldBeforeRender = options[RENDER];\n oldAfterDiff = options[DIFFED];\n oldRoot = options[ROOT];\n /* eslint-enable @typescript-eslint/unbound-method */\n\n options[DIFF] = function(vnode) {\n currentComponent = null;\n if (oldBeforeDiff) oldBeforeDiff(vnode);\n };\n\n /* v8 ignore start */\n options[ROOT] = function(vnode, parentDom) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (vnode && parentDom[CHILDREN] && parentDom[CHILDREN][MASK]) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n vnode[MASK] = parentDom[CHILDREN][MASK] as [number, number];\n }\n if (oldRoot) oldRoot(vnode, parentDom);\n };\n /* v8 ignore stop */\n\n options[RENDER] = function(vnode) {\n if (oldBeforeRender) oldBeforeRender(vnode);\n currentComponent = vnode[COMPONENT];\n currentIndex = 0;\n };\n\n options[DIFFED] = function(vnode) {\n if (oldAfterDiff) oldAfterDiff(vnode);\n currentComponent = null;\n };\n}\n\nfunction getHookState(index: number, type: number) {\n if (options[HOOK]) {\n options[HOOK](currentComponent!, index, currentHook || type);\n }\n currentHook = 0;\n const hooks = currentComponent![HOOKS] ?? (currentComponent![HOOKS] = {\n [LIST]: [],\n [PENDING_EFFECTS]: [],\n });\n if (index >= hooks[LIST]!.length) {\n hooks[LIST]!.push({});\n }\n return hooks[LIST]![index];\n}\n\nfunction invokeOrReturn(arg: unknown, f: (...args: unknown[]) => unknown) {\n return typeof f == 'function' ? f(arg) : f;\n}\n\nfunction useState<S>(initialState: S | (() => S)) {\n currentHook = 1;\n return useReducer(noop, initialState) as [S, Dispatch<unknown>];\n}\n\nfunction useReducer<S, A>(\n _reducer: (prevState: S, action: A) => S,\n initialState: S | (() => S),\n init?: (initialState: S) => S,\n) {\n const hookState = getHookState(currentIndex++, 2)!;\n if (!hookState[COMPONENT]) {\n hookState[VALUE] = [\n /* v8 ignore start */\n init ? init(initialState as S) : invokeOrReturn(undefined, initialState as (() => S)),\n /* v8 ignore stop */\n function(_action: A) {\n if (__DEV__) {\n console.error('Cannot update state in main thread!');\n }\n },\n ];\n hookState[COMPONENT] = currentComponent;\n }\n return hookState[VALUE] as [S, Dispatch<A>];\n}\n\nfunction useRef<T>(initialValue?: T): { current: T | undefined } {\n currentHook = 5;\n return useMemo(function() {\n return {\n current: initialValue,\n };\n }, []);\n}\n\n// used for first screen and need not to cache value by args\nfunction useMemo<T>(factory: () => T, _args: ReadonlyArray<unknown>): T {\n const state = getHookState(currentIndex++, 7)!;\n state[VALUE] = factory();\n return state[VALUE] as T;\n}\n\nfunction useCallback<T>(callback: T, args: ReadonlyArray<unknown>): T {\n currentHook = 8;\n return useMemo(function() {\n return callback;\n }, args);\n}\n\nfunction useContext<T>(context: PreactContext<T>): T {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const provider = currentComponent!.context[context.__c] as {\n props: {\n value: T;\n };\n };\n const state = getHookState(currentIndex++, 9)!;\n state['c'] = context;\n /* v8 ignore start */\n if (!provider) return context.__;\n /* v8 ignore stop */\n state[VALUE] = true;\n return provider.props.value;\n}\n\nfunction useDebugValue<T>(value: T, formatter?: (value: T) => string | number): void {\n if (options.useDebugValue) {\n /* v8 ignore start */\n options.useDebugValue(formatter ? formatter(value) : value as string | number);\n /* v8 ignore stop */\n }\n}\n\nfunction useErrorBoundary(cb: (error: any, errorInfo: ErrorInfo) => Promise<void> | void) {\n const state = getHookState(currentIndex++, 10)!;\n state[VALUE] = cb;\n return [undefined, noop] as ReturnType<typeof useErrorBoundaryType>;\n}\n\nfunction useId(): string {\n const state = getHookState(currentIndex++, 11)!;\n if (!state[VALUE]) {\n // Grab either the root node or the nearest async boundary node.\n let root = currentComponent![VNODE];\n while (root !== null && !root![MASK] && root![PARENT] !== null) {\n root = root![PARENT];\n }\n /**\n * init mask to [0, 0]\n * mask[0] will not change\n * mask[1] will auto increase\n */\n const mask = root![MASK] ?? (root![MASK] = [0, 0]);\n state[VALUE] = 'P' + mask[0] + '-' + mask[1]++;\n }\n return state[VALUE] as string;\n}\n\n// background hooks\nconst useEffect = noop as typeof useEffectType;\nconst useLayoutEffect = noop as typeof useLayoutEffectType;\nconst useImperativeHandle = noop as typeof useImperativeHandleType;\n\nexport {\n installMainThreadHooks,\n useCallback,\n useContext,\n useDebugValue,\n useEffect,\n useErrorBoundary,\n useId,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n};\n"]}
1
+ {"version":3,"file":"mainThreadImpl.js","sourceRoot":"","sources":["../../../src/core/hooks/mainThreadImpl.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAUjC,OAAO,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,eAAe,EACf,MAAM,EACN,IAAI,EACJ,KAAK,EACL,KAAK,GACN,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,IAAI,YAAoB,CAAC;AACzB,IAAI,gBAA8C,CAAC;AACnD,IAAI,WAAmB,CAAC;AACxB,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,aAAiD,CAAC;AACtD,IAAI,eAAmD,CA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KAAK,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAW,CAAC;AAChC,CAAC;AAED,mBAAmB;AACnB,MAAM,SAAS,GAAG,IAA4B,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAkC,CAAC;AAC3D,MAAM,mBAAmB,GAAG,IAAsC,CAAC;AAEnE,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,UAAU,EACV,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,UAAU,EACV,MAAM,EACN,QAAQ,GACT,CAAC","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\n/**\n * Implements hooks in the main thread.\n * This module is modified from preact/hooks\n *\n * internal-preact/hooks/dist/hooks.mjs\n */\n\nimport { options } from 'preact';\nimport type { Component, ErrorInfo, PreactContext } from 'preact';\nimport type {\n Dispatch,\n useEffect as useEffectType,\n useErrorBoundary as useErrorBoundaryType,\n useImperativeHandle as useImperativeHandleType,\n useLayoutEffect as useLayoutEffectType,\n} from 'preact/hooks';\n\nimport {\n CHILDREN,\n COMPONENT,\n DIFF,\n DIFFED,\n HOOK,\n HOOKS,\n LIST,\n MASK,\n PARENT,\n PENDING_EFFECTS,\n RENDER,\n ROOT,\n VALUE,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { noop } from '../../shared/utils.js';\n\nlet currentIndex: number;\nlet currentComponent: Component | null | undefined;\nlet currentHook: number;\nlet hooksInstalled = false;\nlet oldBeforeDiff: ((vnode: any) => void) | undefined;\nlet oldBeforeRender: ((vnode: any) => void) | undefined;\nlet oldAfterDiff: ((vnode: any) => void) | undefined;\nlet oldRoot: ((vnode: any, parentDom: any) => void) | undefined;\n\nfunction installMainThreadHooks(): void {\n if (hooksInstalled) {\n return;\n }\n hooksInstalled = true;\n /* eslint-disable @typescript-eslint/unbound-method */\n oldBeforeDiff = options[DIFF];\n oldBeforeRender = options[RENDER];\n oldAfterDiff = options[DIFFED];\n oldRoot = options[ROOT];\n /* eslint-enable @typescript-eslint/unbound-method */\n\n options[DIFF] = function(vnode) {\n currentComponent = null;\n if (oldBeforeDiff) oldBeforeDiff(vnode);\n };\n\n /* v8 ignore start */\n options[ROOT] = function(vnode, parentDom) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (vnode && parentDom[CHILDREN] && parentDom[CHILDREN][MASK]) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n vnode[MASK] = parentDom[CHILDREN][MASK] as [number, number];\n }\n if (oldRoot) oldRoot(vnode, parentDom);\n };\n /* v8 ignore stop */\n\n options[RENDER] = function(vnode) {\n if (oldBeforeRender) oldBeforeRender(vnode);\n currentComponent = vnode[COMPONENT];\n currentIndex = 0;\n };\n\n options[DIFFED] = function(vnode) {\n if (oldAfterDiff) oldAfterDiff(vnode);\n currentComponent = null;\n };\n}\n\nfunction getHookState(index: number, type: number) {\n if (options[HOOK]) {\n options[HOOK](currentComponent!, index, currentHook || type);\n }\n currentHook = 0;\n const hooks = currentComponent![HOOKS] ?? (currentComponent![HOOKS] = {\n [LIST]: [],\n [PENDING_EFFECTS]: [],\n });\n if (index >= hooks[LIST]!.length) {\n hooks[LIST]!.push({});\n }\n return hooks[LIST]![index];\n}\n\nfunction invokeOrReturn(arg: unknown, f: (...args: unknown[]) => unknown) {\n return typeof f == 'function' ? f(arg) : f;\n}\n\nfunction useState<S>(initialState: S | (() => S)) {\n currentHook = 1;\n return useReducer(noop, initialState) as [S, Dispatch<unknown>];\n}\n\nfunction useReducer<S, A>(\n _reducer: (prevState: S, action: A) => S,\n initialState: S | (() => S),\n init?: (initialState: S) => S,\n) {\n const hookState = getHookState(currentIndex++, 2)!;\n if (!hookState[COMPONENT]) {\n hookState[VALUE] = [\n /* v8 ignore start */\n init ? init(initialState as S) : invokeOrReturn(undefined, initialState as (() => S)),\n /* v8 ignore stop */\n function(_action: A) {\n if (__DEV__) {\n console.error('Cannot update state in main thread!');\n }\n },\n ];\n hookState[COMPONENT] = currentComponent;\n }\n return hookState[VALUE] as [S, Dispatch<A>];\n}\n\nfunction useRef<T>(initialValue?: T): { current: T | undefined } {\n currentHook = 5;\n return useMemo(function() {\n return {\n current: initialValue,\n };\n }, []);\n}\n\n// used for first screen and need not to cache value by args\nfunction useMemo<T>(factory: () => T, _args: ReadonlyArray<unknown>): T {\n const state = getHookState(currentIndex++, 7)!;\n state[VALUE] = factory();\n return state[VALUE] as T;\n}\n\nfunction useCallback<T>(callback: T, args: ReadonlyArray<unknown>): T {\n currentHook = 8;\n return useMemo(function() {\n return callback;\n }, args);\n}\n\nfunction useContext<T>(context: PreactContext<T>): T {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const provider = currentComponent!.context[context.__c] as {\n props: {\n value: T;\n };\n };\n const state = getHookState(currentIndex++, 9)!;\n state['c'] = context;\n /* v8 ignore start */\n if (!provider) return context.__;\n /* v8 ignore stop */\n state[VALUE] = true;\n return provider.props.value;\n}\n\nfunction useDebugValue<T>(value: T, formatter?: (value: T) => string | number): void {\n if (options.useDebugValue) {\n /* v8 ignore start */\n options.useDebugValue(formatter ? formatter(value) : value as string | number);\n /* v8 ignore stop */\n }\n}\n\nfunction useErrorBoundary(cb: (error: any, errorInfo: ErrorInfo) => Promise<void> | void) {\n const state = getHookState(currentIndex++, 10)!;\n state[VALUE] = cb;\n return [undefined, noop] as ReturnType<typeof useErrorBoundaryType>;\n}\n\nfunction useId(): string {\n const state = getHookState(currentIndex++, 11)!;\n if (!state[VALUE]) {\n // Grab either the root node or the nearest async boundary node.\n let root = currentComponent![VNODE];\n while (root !== null && !root![MASK] && root![PARENT] !== null) {\n root = root![PARENT];\n }\n /**\n * init mask to [0, 0]\n * mask[0] will not change\n * mask[1] will auto increase\n */\n const mask = root![MASK] ?? (root![MASK] = [0, 0]);\n state[VALUE] = 'P' + mask[0] + '-' + mask[1]++;\n }\n return state[VALUE] as string;\n}\n\n// background hooks\nconst useEffect = noop as typeof useEffectType;\nconst useLayoutEffect = noop as typeof useLayoutEffectType;\nconst useImperativeHandle = noop as typeof useImperativeHandleType;\n\nexport {\n installMainThreadHooks,\n useCallback,\n useContext,\n useDebugValue,\n useEffect,\n useErrorBoundary,\n useId,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n};\n"]}