@lynx-js/react 0.128.0 → 0.129.1

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 (334) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +3 -4
  4. package/refresh/.turbo/turbo-build.log +1 -1
  5. package/runtime/__test__/core/entry-re-eval.test.ts +161 -0
  6. package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
  7. package/runtime/__test__/core/reload-scoped-dual-thread-communication.test.ts +129 -0
  8. package/runtime/__test__/core/thread-function-call.test.ts +1 -0
  9. package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +2 -0
  10. package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
  11. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
  12. package/runtime/__test__/element-template/native/index.test.ts +8 -0
  13. package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
  14. package/runtime/__test__/element-template/native/main-thread-ref-init-value.test.ts +100 -0
  15. package/runtime/__test__/element-template/native/mts-destroy.test.ts +83 -0
  16. package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +104 -0
  17. package/runtime/__test__/element-template/native/reload.test.ts +79 -1
  18. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +104 -47
  19. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +7 -1
  20. package/runtime/__test__/element-template/runtime/background/re-eval-reload.test.ts +69 -0
  21. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
  22. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +31 -5
  23. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +214 -10
  24. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
  25. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
  26. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
  27. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
  28. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +2 -0
  29. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
  30. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +121 -26
  31. package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +89 -2
  32. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +5 -0
  33. package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
  34. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
  35. package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
  36. package/runtime/__test__/shared/component-stack.test.ts +211 -0
  37. package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
  38. package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
  39. package/runtime/__test__/snapshot/lifecycle/re-eval-reload.test.jsx +114 -0
  40. package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +169 -0
  41. package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +63 -0
  42. package/runtime/__test__/snapshot/lifecycle/reload-delayed-main-thread.test.jsx +103 -0
  43. package/runtime/__test__/snapshot/lifecycle.test.jsx +61 -1
  44. package/runtime/__test__/snapshot/lynx/lazy-effect-scheduling.test.jsx +105 -0
  45. package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
  46. package/runtime/__test__/snapshot/preact.test.jsx +0 -3
  47. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
  48. package/runtime/__test__/snapshot/ssr.test.jsx +2 -2
  49. package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +6 -11
  50. package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +1 -1
  51. package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +24 -1
  52. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +27 -1
  53. package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
  54. package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +46 -0
  55. package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +3 -3
  56. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
  57. package/runtime/lazy/element-template-internal.js +0 -1
  58. package/runtime/lazy/internal.js +1 -1
  59. package/runtime/lazy/jsx-dev-runtime.js +1 -1
  60. package/runtime/lazy/jsx-runtime.js +1 -1
  61. package/runtime/lazy/legacy-react-runtime.js +1 -1
  62. package/runtime/lazy/react-lepus.js +1 -1
  63. package/runtime/lazy/react.js +1 -1
  64. package/runtime/lib/core/background-function/exec-map.d.ts +2 -0
  65. package/runtime/lib/core/background-function/exec-map.js +7 -0
  66. package/runtime/lib/core/background-function/exec-map.js.map +1 -1
  67. package/runtime/lib/core/background-function/run-on-background.js +15 -16
  68. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  69. package/runtime/lib/core/capture-main-thread-object.js +2 -1
  70. package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
  71. package/runtime/lib/core/card-lifetime.d.ts +5 -0
  72. package/runtime/lib/core/card-lifetime.js +17 -0
  73. package/runtime/lib/core/card-lifetime.js.map +1 -0
  74. package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
  75. package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
  76. package/runtime/lib/core/entry-reload.d.ts +7 -0
  77. package/runtime/lib/core/entry-reload.js +49 -0
  78. package/runtime/lib/core/entry-reload.js.map +1 -0
  79. package/runtime/lib/core/lynx/lazy-bundle.js +5 -2
  80. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  81. package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
  82. package/runtime/lib/core/lynx-data-processors.js +3 -0
  83. package/runtime/lib/core/lynx-data-processors.js.map +1 -1
  84. package/runtime/lib/core/main-thread-ref-id.js +4 -4
  85. package/runtime/lib/core/main-thread-ref-id.js.map +1 -1
  86. package/runtime/lib/core/reload-scoped-event.d.ts +5 -0
  87. package/runtime/lib/core/reload-scoped-event.js +26 -0
  88. package/runtime/lib/core/reload-scoped-event.js.map +1 -0
  89. package/runtime/lib/core/reload-version.js +4 -3
  90. package/runtime/lib/core/reload-version.js.map +1 -1
  91. package/runtime/lib/core/runtime-destroy.d.ts +2 -0
  92. package/runtime/lib/core/runtime-destroy.js +10 -1
  93. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  94. package/runtime/lib/core/thread-function-call/main-thread.js +5 -4
  95. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  96. package/runtime/lib/core/thread-function-call/return-value.js +6 -5
  97. package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
  98. package/runtime/lib/document.js +0 -5
  99. package/runtime/lib/document.js.map +1 -1
  100. package/runtime/lib/element-template/background/commit-hook.js +24 -22
  101. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  102. package/runtime/lib/element-template/background/hydration-listener.js +2 -6
  103. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  104. package/runtime/lib/element-template/client/root.d.ts +1 -1
  105. package/runtime/lib/element-template/client/root.js.map +1 -1
  106. package/runtime/lib/element-template/index.d.ts +2 -2
  107. package/runtime/lib/element-template/index.js.map +1 -1
  108. package/runtime/lib/element-template/internal.d.ts +1 -1
  109. package/runtime/lib/element-template/internal.js +0 -13
  110. package/runtime/lib/element-template/internal.js.map +1 -1
  111. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  112. package/runtime/lib/element-template/main-thread-ref-init-value.d.ts +3 -0
  113. package/runtime/lib/element-template/main-thread-ref-init-value.js +38 -0
  114. package/runtime/lib/element-template/main-thread-ref-init-value.js.map +1 -0
  115. package/runtime/lib/element-template/native/flush.d.ts +1 -0
  116. package/runtime/lib/element-template/native/flush.js +9 -0
  117. package/runtime/lib/element-template/native/flush.js.map +1 -0
  118. package/runtime/lib/element-template/native/index.js +2 -0
  119. package/runtime/lib/element-template/native/index.js.map +1 -1
  120. package/runtime/lib/element-template/native/main-thread-api.js +3 -7
  121. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  122. package/runtime/lib/element-template/native/mts-destroy.js +10 -2
  123. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  124. package/runtime/lib/element-template/native/patch-listener.js +58 -54
  125. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  126. package/runtime/lib/element-template/native/reload-background.d.ts +1 -1
  127. package/runtime/lib/element-template/native/reload-background.js +12 -1
  128. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  129. package/runtime/lib/element-template/native/reload-main-thread.d.ts +6 -0
  130. package/runtime/lib/element-template/native/reload-main-thread.js +20 -3
  131. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  132. package/runtime/lib/element-template/protocol/lifecycle-constant.d.ts +2 -1
  133. package/runtime/lib/element-template/protocol/lifecycle-constant.js +1 -0
  134. package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
  135. package/runtime/lib/element-template/protocol/types.d.ts +0 -2
  136. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  137. package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
  138. package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
  139. package/runtime/lib/element-template/runtime/patch.js +4 -0
  140. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  141. package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
  142. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  143. package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
  144. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  145. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -1
  146. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  147. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +1 -0
  148. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +41 -21
  149. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  150. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +1 -1
  151. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  152. package/runtime/lib/internal.d.ts +1 -1
  153. package/runtime/lib/internal.js +1 -1
  154. package/runtime/lib/internal.js.map +1 -1
  155. package/runtime/lib/lynx-api.d.ts +2 -125
  156. package/runtime/lib/lynx-api.js.map +1 -1
  157. package/runtime/lib/shared/component-stack.d.ts +0 -4
  158. package/runtime/lib/shared/component-stack.js +21 -5
  159. package/runtime/lib/shared/component-stack.js.map +1 -1
  160. package/runtime/lib/shared/index-map.d.ts +4 -1
  161. package/runtime/lib/shared/index-map.js +5 -2
  162. package/runtime/lib/shared/index-map.js.map +1 -1
  163. package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
  164. package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
  165. package/runtime/lib/snapshot/lifecycle/destroy.js +6 -0
  166. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  167. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.d.ts +6 -2
  168. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js +21 -18
  169. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
  170. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
  171. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
  172. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
  173. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
  174. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  175. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
  176. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  177. package/runtime/lib/snapshot/lifecycle/reload.d.ts +9 -2
  178. package/runtime/lib/snapshot/lifecycle/reload.js +29 -8
  179. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  180. package/runtime/lib/snapshot/list/list.js +3 -2
  181. package/runtime/lib/snapshot/list/list.js.map +1 -1
  182. package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
  183. package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
  184. package/runtime/lib/snapshot/lynx/calledByNative.js +14 -11
  185. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  186. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
  187. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  188. package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
  189. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  190. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
  191. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  192. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  193. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  194. package/runtime/lib/snapshot/snapshot/list.js +2 -1
  195. package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
  196. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.d.ts +4 -2
  197. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js +11 -11
  198. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
  199. package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +1 -0
  200. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +6 -1
  201. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  202. package/runtime/lib/snapshot/worklet/ctx.d.ts +1 -1
  203. package/runtime/lib/snapshot/worklet/ctx.js +6 -1
  204. package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
  205. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js +6 -0
  206. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
  207. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  208. package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
  209. package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
  210. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
  211. package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
  212. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
  213. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
  214. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +3 -1
  215. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
  216. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
  217. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +8 -1
  218. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  219. package/runtime/lib/worklet-runtime/listeners.js +2 -2
  220. package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
  221. package/runtime/lib/worklet-runtime/mainThreadObject.js +3 -1
  222. package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -1
  223. package/runtime/lib/worklet-runtime/runOnMainThread.js +4 -3
  224. package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
  225. package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
  226. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  227. package/runtime/package.json +2 -3
  228. package/runtime/src/core/background-function/exec-map.ts +9 -0
  229. package/runtime/src/core/background-function/run-on-background.ts +14 -16
  230. package/runtime/src/core/capture-main-thread-object.ts +2 -1
  231. package/runtime/src/core/card-lifetime.ts +18 -0
  232. package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
  233. package/runtime/src/core/entry-reload.ts +63 -0
  234. package/runtime/src/core/lynx/lazy-bundle.ts +5 -2
  235. package/runtime/src/core/lynx-data-processors.ts +124 -1
  236. package/runtime/src/core/main-thread-ref-id.ts +5 -4
  237. package/runtime/src/core/reload-scoped-event.ts +35 -0
  238. package/runtime/src/core/reload-version.ts +5 -3
  239. package/runtime/src/core/runtime-destroy.ts +12 -1
  240. package/runtime/src/core/thread-function-call/main-thread.ts +4 -4
  241. package/runtime/src/core/thread-function-call/return-value.ts +6 -5
  242. package/runtime/src/document.ts +0 -6
  243. package/runtime/src/element-template/background/commit-hook.ts +32 -23
  244. package/runtime/src/element-template/background/hydration-listener.ts +2 -6
  245. package/runtime/src/element-template/client/root.ts +1 -3
  246. package/runtime/src/element-template/index.ts +2 -2
  247. package/runtime/src/element-template/internal.ts +0 -20
  248. package/runtime/src/element-template/lynx/env.ts +1 -1
  249. package/runtime/src/element-template/main-thread-ref-init-value.ts +44 -0
  250. package/runtime/src/element-template/native/flush.ts +10 -0
  251. package/runtime/src/element-template/native/index.ts +2 -0
  252. package/runtime/src/element-template/native/main-thread-api.ts +3 -6
  253. package/runtime/src/element-template/native/mts-destroy.ts +10 -2
  254. package/runtime/src/element-template/native/patch-listener.ts +62 -62
  255. package/runtime/src/element-template/native/reload-background.ts +13 -1
  256. package/runtime/src/element-template/native/reload-main-thread.ts +32 -3
  257. package/runtime/src/element-template/protocol/lifecycle-constant.ts +1 -0
  258. package/runtime/src/element-template/protocol/types.ts +0 -15
  259. package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
  260. package/runtime/src/element-template/runtime/patch.ts +5 -0
  261. package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
  262. package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
  263. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
  264. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +51 -21
  265. package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +2 -2
  266. package/runtime/src/element-template/types.d.ts +6 -0
  267. package/runtime/src/internal.ts +1 -1
  268. package/runtime/src/lynx-api.ts +2 -124
  269. package/runtime/src/shared/component-stack.ts +22 -5
  270. package/runtime/src/shared/index-map.ts +3 -2
  271. package/runtime/src/snapshot/lifecycle/destroy.ts +7 -0
  272. package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +26 -19
  273. package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
  274. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
  275. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
  276. package/runtime/src/snapshot/lifecycle/reload.ts +47 -11
  277. package/runtime/src/snapshot/list/list.ts +9 -2
  278. package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
  279. package/runtime/src/snapshot/lynx/calledByNative.ts +14 -13
  280. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
  281. package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
  282. package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
  283. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
  284. package/runtime/src/snapshot/snapshot/list.ts +5 -1
  285. package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +19 -12
  286. package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +10 -1
  287. package/runtime/src/snapshot/worklet/ctx.ts +10 -1
  288. package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +6 -0
  289. package/runtime/src/worklet-runtime/README.md +33 -0
  290. package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
  291. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
  292. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +3 -1
  293. package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +8 -1
  294. package/runtime/src/worklet-runtime/listeners.ts +4 -7
  295. package/runtime/src/worklet-runtime/mainThreadObject.ts +2 -1
  296. package/runtime/src/worklet-runtime/runOnMainThread.ts +4 -3
  297. package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
  298. package/runtime/types/types.d.ts +3 -1
  299. package/runtime/vitest.config.ts +0 -2
  300. package/testing-library/.turbo/turbo-build.log +7 -7
  301. package/testing-library/src/__tests__/act.test.jsx +0 -7
  302. package/testing-library/src/__tests__/alog.test.jsx +12 -54
  303. package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
  304. package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
  305. package/testing-library/src/__tests__/worklet.test.jsx +59 -5
  306. package/transform/.turbo/turbo-build$colon$wasm.log +63 -136
  307. package/transform/__test__/defines.spec.js +137 -0
  308. package/transform/__test__/object-methods.spec.js +79 -0
  309. package/transform/crates/swc_plugin_worklet/definition_imports.rs +97 -0
  310. package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
  311. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +56 -48
  312. package/transform/crates/swc_plugin_worklet/lib.rs +400 -595
  313. package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
  314. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +6 -1
  315. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -1
  316. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +9 -0
  317. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +12 -1
  318. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +1 -1
  319. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +1 -1
  320. package/transform/dist/wasm.cjs +1 -1
  321. package/transform/index.d.ts +3 -1
  322. package/transform/package.json +0 -1
  323. package/transform/src/lib.rs +173 -12
  324. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +105 -32
  325. package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
  326. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  327. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +193 -194
  328. package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
  329. package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
  330. package/runtime/lib/snapshot/worklet/hmr.js +0 -28
  331. package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
  332. package/runtime/src/snapshot/worklet/hmr.ts +0 -34
  333. /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
  334. /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
@@ -17,26 +17,6 @@ export interface ListUpdateInfo {
17
17
  onSetAttribute(child: SnapshotInstance, attr: any, oldAttr: any): void;
18
18
  }
19
19
 
20
- // class ListUpdateInfoDiffing implements ListUpdateInfo {
21
- // private oldChildNodes: SnapshotInstance[];
22
- // constructor(private list: SnapshotInstance) {
23
- // this.oldChildNodes = list.childNodes;
24
- // }
25
- // flush(): void {
26
- // Object.defineProperty(SnapshotInstance.prototype, "key", {
27
- // get: function () {
28
- // return this.values[0]["item-key"];
29
- // },
30
- // });
31
-
32
- // }
33
- // onInsertBefore(newNode: SnapshotInstance, existingNode?: SnapshotInstance | undefined): void {}
34
- // onRemoveChild(child: SnapshotInstance): void {}
35
- // onSetAttribute(child: SnapshotInstance, attr: any): void {
36
- // throw new Error("Method not implemented.");
37
- // }
38
- // }
39
-
40
20
  interface InsertAction {
41
21
  position: number;
42
22
  type: string;
@@ -58,30 +38,14 @@ interface ListOperations {
58
38
  export class ListUpdateInfoRecording implements ListUpdateInfo {
59
39
  constructor(private list: SnapshotInstance) {
60
40
  this.oldChildNodes = list.childNodes;
61
- // this.oldChildNodesSet = new Set(this.oldChildNodes);
62
41
  }
63
42
 
64
- // private __commitAndReset() {
65
- // (this.__pendingAttributes ??= []).push(this.__toAttribute());
66
- // this.oldChildNodes = this.list.childNodes;
67
- // this.oldChildNodesSet = new Set(this.oldChildNodes);
68
- // this.removeChild1.clear();
69
- // this.removeChild2.clear();
70
- // this.insertBefore.clear();
71
- // this.appendChild.length = 0;
72
- // this.platformInfoUpdate.clear();
73
- // }
74
-
75
43
  flush(): undefined | number {
76
44
  if (!this.list.__elements) {
77
45
  return undefined;
78
46
  }
79
47
  const elementIndex = this.list.__snapshot_def.slot[0]![1];
80
48
  const listElement = this.list.__elements[elementIndex]!;
81
- // this.__pendingAttributes?.forEach(pendingAttribute => {
82
- // __SetAttribute(listElement, "update-list-info", pendingAttribute);
83
- // __FlushElementTree(listElement);
84
- // });
85
49
  const updateListInfo = this.__toAttribute();
86
50
 
87
51
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
@@ -132,7 +96,6 @@ export class ListUpdateInfoRecording implements ListUpdateInfo {
132
96
  }
133
97
 
134
98
  private oldChildNodes: SnapshotInstance[];
135
- // private oldChildNodesSet: Set<SnapshotInstance>;
136
99
  private removeChild = new Set<SnapshotInstance>();
137
100
  private insertBefore = new Map<SnapshotInstance, SnapshotInstance[]>(); // insert V before K
138
101
  private appendChild = [] as SnapshotInstance[];
@@ -140,15 +103,9 @@ export class ListUpdateInfoRecording implements ListUpdateInfo {
140
103
 
141
104
  onInsertBefore(newNode: SnapshotInstance, existingNode?: SnapshotInstance): void {
142
105
  if (newNode.parentNode) {
143
- // if (!this.oldChildNodesSet.has(newNode)) {
144
- // this.__commitAndReset();
145
- // }
146
106
  this.removeChild.add(newNode);
147
107
  }
148
108
  if (existingNode) {
149
- // if (!this.oldChildNodesSet.has(existingNode)) {
150
- // this.__commitAndReset();
151
- // }
152
109
  const newChildren = this.insertBefore.get(existingNode) ?? [];
153
110
  newChildren.push(newNode);
154
111
  this.insertBefore.set(existingNode, newChildren);
@@ -158,9 +115,6 @@ export class ListUpdateInfoRecording implements ListUpdateInfo {
158
115
  }
159
116
 
160
117
  onRemoveChild(child: SnapshotInstance): void {
161
- // if (!this.oldChildNodesSet.has(child)) {
162
- // this.__commitAndReset();
163
- // }
164
118
  this.removeChild.add(child);
165
119
  }
166
120
 
@@ -254,12 +208,6 @@ export class ListUpdateInfoRecording implements ListUpdateInfo {
254
208
  }
255
209
 
256
210
  toJSON(): [ListOperations] {
257
- // if (this.__pendingAttributes) {
258
- // return [...this.__pendingAttributes, this.__toAttribute()];
259
- // } else {
260
- // return [this.__toAttribute()];
261
- // }
262
-
263
211
  return [this.__toAttribute()] as const;
264
212
  }
265
213
  }
@@ -6,8 +6,7 @@ import { markTiming, setPipeline } from '../../core/performance.js';
6
6
  import { __root, setRoot } from '../../root.js';
7
7
  import { LifecycleConstant } from '../lifecycle/constant.js';
8
8
  import {
9
- firstScreenEventIdSwap,
10
- isFirstScreenSynced,
9
+ firstScreenSync,
11
10
  onFirstScreenSyncReady,
12
11
  onFirstScreenTreeReady,
13
12
  resetFirstScreenSyncState,
@@ -126,7 +125,7 @@ function updatePage(data: Record<string, unknown> | undefined, options?: UpdateP
126
125
  applyUpdatePageData(data, options);
127
126
 
128
127
  const flushOptions = options ?? {};
129
- if (!isFirstScreenSynced) {
128
+ if (!firstScreenSync.isSynced) {
130
129
  if (__FIRST_SCREEN_SYNC_TIMING__ === 'manual') {
131
130
  // a `markFirstScreenSyncReady` call during the re-render below must not
132
131
  // sync the half-rendered tree; it is deferred to `onFirstScreenTreeReady`
@@ -139,7 +138,7 @@ function updatePage(data: Record<string, unknown> | undefined, options?: UpdateP
139
138
 
140
139
  setPipeline(options?.pipelineOptions);
141
140
  markTiming('updateDiffVdomStart');
142
- {
141
+ try {
143
142
  __pendingListUpdates.clearAttachedLists();
144
143
  renderMainThread();
145
144
  // As said by codename `firstScreenEventIdSwap`, this swap will only be used for event remap,
@@ -147,23 +146,25 @@ function updatePage(data: Record<string, unknown> | undefined, options?: UpdateP
147
146
  hydrate(
148
147
  oldRoot as SnapshotInstance,
149
148
  __root as SnapshotInstance,
150
- { skipUnRef: true, swap: firstScreenEventIdSwap },
149
+ { skipUnRef: true, swap: firstScreenSync.eventIdSwap },
151
150
  );
152
151
 
153
152
  // always call this before `__FlushElementTree`
154
153
  __pendingListUpdates.flush();
155
154
  applyRefQueue();
156
- }
157
155
 
158
- if (__FIRST_SCREEN_SYNC_TIMING__ === 'manual') {
159
- onFirstScreenTreeReady();
160
- }
156
+ if (__FIRST_SCREEN_SYNC_TIMING__ === 'manual') {
157
+ onFirstScreenTreeReady();
158
+ }
161
159
 
162
- flushOptions.triggerDataUpdated = true;
163
- markTiming('updateDiffVdomEnd');
160
+ flushOptions.triggerDataUpdated = true;
161
+ markTiming('updateDiffVdomEnd');
164
162
 
165
- if (typeof lepusng_gc === 'function') {
166
- lepusng_gc();
163
+ if (typeof lepusng_gc === 'function') {
164
+ lepusng_gc();
165
+ }
166
+ } finally {
167
+ setPipeline(undefined);
167
168
  }
168
169
  }
169
170
 
@@ -99,64 +99,6 @@ export function diffArrayLepus<A extends Typed, B extends Typed>(
99
99
  return result;
100
100
  }
101
101
 
102
- // export function diffIterableLepus<A extends Typed, B extends Typed>(
103
- // before: A[],
104
- // after: Iterable<B>,
105
- // isSameType: (a: A, b: B) => boolean,
106
- // onDiffChildren: (a: A, b: B) => void
107
- // ): DiffResult<B> {
108
- // let returnResult = EMPTY_DIFF_RESULT as DiffResult<B>;
109
- // let lastPlacedIndex = 0;
110
- // const result: DiffResult<B> = {
111
- // $$diff: true,
112
- // i: {},
113
- // r: [],
114
- // m: {},
115
- // };
116
- // const beforeMap: Record<string, Set<[A, number]>> = {};
117
-
118
- // for (let i = 0; i < before.length; i++) {
119
- // let node = before[i];
120
- // (beforeMap[node.type] ??= new Set()).add([node, i]);
121
- // }
122
-
123
- // let i = 0;
124
- // for (const afterNode of after) {
125
- // const beforeNodes = beforeMap[afterNode.type];
126
- // let beforeNode: [A, number];
127
-
128
- // if (beforeNodes && (([beforeNode] = beforeNodes), beforeNode) && isSameType(beforeNode[0], afterNode)) {
129
- // // Reuse old node
130
- // beforeNodes.delete(beforeNode);
131
-
132
- // const oldIndex = beforeNode[1];
133
- // onDiffChildren(beforeNode[0], afterNode);
134
- // if (oldIndex < lastPlacedIndex) {
135
- // result.m[oldIndex] = i;
136
- // returnResult = result;
137
- // i++;
138
- // continue;
139
- // } else {
140
- // lastPlacedIndex = oldIndex;
141
- // }
142
- // } else {
143
- // // Create new node
144
- // result.i[i] = afterNode;
145
- // returnResult = result;
146
- // }
147
- // i++;
148
- // }
149
- // // delete
150
- // for (const k in beforeMap) {
151
- // for (const [, i] of beforeMap[k]) {
152
- // result.r.push(i);
153
- // returnResult = result;
154
- // }
155
- // }
156
-
157
- // return result;
158
- // }
159
-
160
102
  export function diffArrayAction<T, K>(
161
103
  before: T[],
162
104
  diffResult: DiffResult<K>,
@@ -39,7 +39,7 @@ const isArray = /* @__PURE__ */ Array.isArray;
39
39
  const assign = /* @__PURE__ */ Object.assign;
40
40
 
41
41
  // Global state for the current render pass
42
- let beforeDiff, beforeDiff2, afterDiff, renderHook, ummountHook;
42
+ let beforeDiff, beforeDiff2, afterDiff, renderHook, unmountHook;
43
43
 
44
44
  /**
45
45
  * Render Preact JSX + Components to an HTML string.
@@ -60,7 +60,7 @@ export function renderToString(vnode: any, context: any, into: SnapshotInstance)
60
60
  beforeDiff2 = options[DIFF2];
61
61
  afterDiff = options[DIFFED];
62
62
  renderHook = options[RENDER];
63
- ummountHook = options.unmount;
63
+ unmountHook = options.unmount;
64
64
 
65
65
  const parent = h(Fragment, null);
66
66
  parent[CHILDREN] = [vnode];
@@ -194,7 +194,7 @@ function _renderToString(
194
194
  opcodes,
195
195
  /* v8 ignore start */
196
196
  __ENABLE_SSR__ ? opcodes.length : 0,
197
- /* v8 ignore end */
197
+ /* v8 ignore stop */
198
198
  into,
199
199
  );
200
200
  }
@@ -282,7 +282,7 @@ function _renderToString(
282
282
  opcodes,
283
283
  /* v8 ignore start */
284
284
  __ENABLE_SSR__ ? opcodes.length : 0,
285
- /* v8 ignore end */
285
+ /* v8 ignore stop */
286
286
  into,
287
287
  );
288
288
  } catch (e) {
@@ -312,7 +312,7 @@ function _renderToString(
312
312
  opcodes,
313
313
  /* v8 ignore start */
314
314
  __ENABLE_SSR__ ? opcodes.length : 0,
315
- /* v8 ignore end */
315
+ /* v8 ignore stop */
316
316
  into,
317
317
  );
318
318
  }
@@ -323,7 +323,7 @@ function _renderToString(
323
323
  if (afterDiff) afterDiff(vnode);
324
324
  vnode[PARENT] = undefined;
325
325
 
326
- if (ummountHook) ummountHook(vnode);
326
+ if (unmountHook) unmountHook(vnode);
327
327
  }
328
328
 
329
329
  return;
@@ -406,14 +406,14 @@ function _renderToString(
406
406
  opcodes,
407
407
  /* v8 ignore start */
408
408
  __ENABLE_SSR__ ? opcodes.length : 0,
409
- /* v8 ignore end */
409
+ /* v8 ignore stop */
410
410
  vnode,
411
411
  );
412
412
  }
413
413
 
414
414
  if (afterDiff) afterDiff(vnode);
415
415
  vnode[PARENT] = undefined;
416
- if (ummountHook) ummountHook(vnode);
416
+ if (unmountHook) unmountHook(vnode);
417
417
 
418
418
  if (__ENABLE_SSR__) {
419
419
  opcodes.push(__OpEnd);
@@ -97,60 +97,3 @@ export function ssrHydrateByOpcodes(
97
97
  }
98
98
  }
99
99
  }
100
-
101
- // export function renderOpcodesInto(opcodes: any[], into: SnapshotInstance): void {
102
- // let top: SnapshotInstance = into;
103
- // const stack: SnapshotInstance[] = [into];
104
- // for (let i = 0; i < opcodes.length;) {
105
- // const opcode = opcodes[i];
106
- // switch (opcode) {
107
- // case OpcodeBegin: {
108
- // const p = top;
109
- // top = opcodes[i + 1];
110
- // // @ts-ignore
111
- // if (top.__parent) {
112
- // // already inserted
113
- // top = new SnapshotInstance(top.type);
114
- // opcodes[i + 1] = top;
115
- // }
116
- // p.insertBefore(top);
117
- // stack.push(top);
118
-
119
- // i += 2;
120
- // break;
121
- // }
122
- // case OpcodeEnd: {
123
- // // @ts-ignore
124
- // top[CHILDREN] = undefined;
125
-
126
- // stack.pop();
127
- // const p = stack[stack.length - 1];
128
- // top = p!;
129
-
130
- // i += 1;
131
- // break;
132
- // }
133
- // case OpcodeAttr: {
134
- // const key = opcodes[i + 1];
135
- // const value = opcodes[i + 2];
136
- // top.setAttribute(key, value);
137
-
138
- // i += 3;
139
- // break;
140
- // }
141
- // case OpcodeText: {
142
- // const text = opcodes[i + 1];
143
- // const s = new SnapshotInstance(null as unknown as string);
144
- // if (__ENABLE_SSR__) {
145
- // // We need store the just created SnapshotInstance, or it will be lost when we leave the function
146
- // opcodes[i + 1] = [s, text];
147
- // }
148
- // s.setAttribute(0, text);
149
- // top.insertBefore(s);
150
-
151
- // i += 2;
152
- // break;
153
- // }
154
- // }
155
- // }
156
- // }
@@ -28,7 +28,7 @@ import { globalPipelineOptions } from '../../core/performance.js';
28
28
  import { profileEnd, profileStart } from '../../shared/profile.js';
29
29
  import { isDirectOrDeepEqual } from '../../utils.js';
30
30
  import { clearSnapshotVNodeSource, getSnapshotVNodeSource, moveSnapshotVNodeSource } from '../debug/vnodeSource.js';
31
- import { prepareGestureForCommit } from '../gesture/processGestureBagkround.js';
31
+ import { prepareGestureForCommit } from '../gesture/processGestureBackground.js';
32
32
  import type { GestureKind } from '../gesture/types.js';
33
33
  import { globalBackgroundSnapshotInstancesToRemove } from '../lifecycle/patch/globalState.js';
34
34
  import {
@@ -2,11 +2,15 @@
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
 
5
+ import { cardLifetime } from '../../core/card-lifetime.js';
5
6
  import { componentAtIndexFactory, enqueueComponentFactory, gRecycleMap, gSignMap } from '../list/list.js';
6
7
  import { hydrate } from '../renderToOpcodes/hydrate.js';
7
8
  import type { SnapshotInstance } from '../snapshot/snapshot.js';
8
9
 
9
- const destroyLifetimeHandlerMap = /*#__PURE__*/ new Map<number, () => void>();
10
+ const destroyLifetimeHandlerMap = /*#__PURE__*/ cardLifetime(
11
+ 'listDestroyLifetimeHandlerMap',
12
+ () => new Map<number, () => void>(),
13
+ );
10
14
 
11
15
  export function snapshotCreateList(
12
16
  pageId: number,
@@ -3,20 +3,27 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
5
  import type { SnapshotInstance } from './snapshot.js';
6
+ import { cardLifetime } from '../../core/card-lifetime.js';
6
7
  import { clearSnapshotVNodeSource } from '../debug/vnodeSource.js';
7
8
 
8
- export const snapshotInstanceManager: {
9
+ interface SnapshotInstanceManager {
9
10
  nextId: number;
10
11
  values: Map<number, SnapshotInstance>;
11
12
  clear(): void;
12
- } = {
13
- nextId: 0,
14
- values: /* @__PURE__ */ new Map<number, SnapshotInstance>(),
15
- clear() {
16
- // not resetting `nextId` to prevent id collision
17
- this.values.clear();
18
- if (__DEV__) {
19
- clearSnapshotVNodeSource();
20
- }
21
- },
22
- };
13
+ }
14
+
15
+ function clear(this: SnapshotInstanceManager): void {
16
+ // not resetting `nextId` to prevent id collision
17
+ this.values.clear();
18
+ if (__DEV__) {
19
+ clearSnapshotVNodeSource();
20
+ }
21
+ }
22
+
23
+ export const snapshotInstanceManager: SnapshotInstanceManager = /*#__PURE__*/ cardLifetime(
24
+ 'snapshotInstanceManager',
25
+ () => ({ nextId: 0, values: new Map<number, SnapshotInstance>(), clear }),
26
+ );
27
+
28
+ // Rebound so that it clears the debug state of the current entry.
29
+ snapshotInstanceManager.clear = clear;
@@ -2,7 +2,11 @@
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
 
5
- import { createRunOnMainThread } from '../../../core/thread-function-call/main-thread.js';
5
+ import {
6
+ createRunOnMainThread,
7
+ takeDelayedRunOnMainThreadData,
8
+ } from '../../../core/thread-function-call/main-thread.js';
9
+ import { resetFunctionCallReturnListener } from '../../../core/thread-function-call/return-value.js';
6
10
  import { isRendering } from '../../lifecycle/isRendering.js';
7
11
  import { __globalSnapshotPatch } from '../../lifecycle/patch/snapshotPatch.js';
8
12
 
@@ -37,3 +41,8 @@ export function runOnMainThread<R, Fn extends (...args: any[]) => R>(
37
41
  ): (...args: Parameters<Fn>) => Promise<R> {
38
42
  return runOnMainThreadImpl(fn);
39
43
  }
44
+
45
+ export function resetSnapshotMainThreadFunctionRuntime(): void {
46
+ takeDelayedRunOnMainThreadData();
47
+ resetFunctionCallReturnListener();
48
+ }
@@ -4,7 +4,11 @@
4
4
  import type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';
5
5
 
6
6
  import { isMtsEnabled, isRunOnBackgroundEnabled } from './functionality.js';
7
- import { registerBackgroundFunctionCtx } from '../../core/background-function/run-on-background.js';
7
+ import {
8
+ registerBackgroundFunctionCtx,
9
+ resetBackgroundFunctionRuntime,
10
+ } from '../../core/background-function/run-on-background.js';
11
+ import { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';
8
12
 
9
13
  /**
10
14
  * @internal
@@ -20,3 +24,8 @@ export function onPostWorkletCtx(afterValue: Worklet | null): Worklet | null {
20
24
  registerBackgroundFunctionCtx(afterValue);
21
25
  return afterValue;
22
26
  }
27
+
28
+ export function resetSnapshotBackgroundFunctionRuntime(): void {
29
+ resetBackgroundFunctionRuntime();
30
+ resetFunctionCallReturnListener();
31
+ }
@@ -12,6 +12,9 @@ function updateMTRefInitValue({ data }: { data: string }): void {
12
12
  // This update ignores reloadVersion check.
13
13
  // MainThreadRefs created before reloadTemplate may still be referenced by user in some cases after reloadTemplate.
14
14
  const patch = JSON.parse(data) as MainThreadRefInitValuePatch;
15
+ if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
16
+ console.alog?.('[ReactLynxDebug] Snapshot MTS updateMTRefInitValue:\n' + data);
17
+ }
15
18
  updateWorkletRefInitValueChanges(patch);
16
19
  }
17
20
 
@@ -26,5 +29,8 @@ export function sendMTRefInitValueToMainThread(): void {
26
29
  }
27
30
 
28
31
  const data = JSON.stringify(patch);
32
+ if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
33
+ console.alog?.('[ReactLynxDebug] Snapshot BTS -> MTS sendMTRefInitValue:\n' + data);
34
+ }
29
35
  lynx.getNativeApp().callLepusMethod(LifecycleConstant.updateMTRefInitValue, { data });
30
36
  }
@@ -0,0 +1,33 @@
1
+ # Element Template worklet identity
2
+
3
+ Element Template Native storage must preserve the original JavaScript worklet
4
+ context in declared main-thread event slots, as Snapshot does. Native may snapshot
5
+ the event wrapper and ordinary attribute data, but it must retain the wrapper's
6
+ `value` as a live MTS object. Background element preparation must exclude live
7
+ event and gesture values from both its task input and prepared result.
8
+
9
+ `runWorklet` transforms the context delivered by Native directly. The original
10
+ context and its captured callback objects remain ordinary JavaScript objects
11
+ accepted by `FinalizationRegistry.register`; no context identifier or reverse
12
+ lookup is needed. This runtime requires the corresponding Native storage behavior.
13
+ Older ET Native implementations that deep-copy worklet contexts are unsupported by
14
+ this integration.
15
+
16
+ Track a background input before calling Native. If Native rejects it, collecting
17
+ that input must still release its already-registered background execution. Only
18
+ Native success commits the slot's strong reference and hydration handoff;
19
+ committing does not register the context again. Removal drops the slot's reference.
20
+ Escaped callbacks follow the existing Snapshot capture and GC behavior.
21
+
22
+ Retire the previous lifecycle manager to stop old finalizers from sending release
23
+ events into the new runtime. Native event ingress must reject detached old
24
+ bindings so they cannot dispatch into a replacement runtime; `runWorklet` does not
25
+ reject contexts based on the lifecycle manager that originally retained them.
26
+ Snapshot observers continue to track references through the same lifecycle manager.
27
+
28
+ This integration keeps Snapshot's existing callback transformation, first-screen
29
+ hydration, and delayed-call replay semantics. It does not add per-binding callback
30
+ materialization, shared-capture isolation, or a new delayed queue representation.
31
+ Shared first-screen context mutation and escaped-callback lifetime limitations
32
+ that also occur in Snapshot remain unchanged. Registration atomicity and
33
+ consumed-queue cleanup remain unchanged.
@@ -2,6 +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
 
5
+ export { loadWorkletRuntime } from './loadRuntime.js';
6
+
5
7
  export * from './bindings.js';
6
8
 
7
9
  export * from './observers.js';
@@ -0,0 +1,25 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import '../global.js';
6
+
7
+ /**
8
+ * Loads the legacy main-thread worklet chunk or reuses an initialized runtime.
9
+ * @param __schema - The dynamic component entry for loading the Lepus chunk.
10
+ * @returns Whether the worklet runtime was loaded and initialized successfully.
11
+ */
12
+ function loadWorkletRuntime(__schema?: string): boolean {
13
+ if (typeof __LoadLepusChunk === 'undefined') {
14
+ return false;
15
+ }
16
+ if (globalThis.lynxWorkletImpl) {
17
+ return true;
18
+ }
19
+ return __LoadLepusChunk('worklet-runtime', {
20
+ dynamicComponentEntry: __schema,
21
+ chunkType: 0,
22
+ });
23
+ }
24
+
25
+ export { loadWorkletRuntime };
@@ -36,7 +36,9 @@ function delayRunOnBackground(fnObj: JsFnHandle, task: (fnId: number, execId: nu
36
36
  }
37
37
 
38
38
  function clearDelayedBackgroundFunctions(): void {
39
- impl!.delayedBackgroundFunctionArray.length = 0;
39
+ // PrimJS can keep truncated array storage alive; drop the consumed queue so
40
+ // its tasks and hydrated handles stop retaining their background executions.
41
+ impl!.delayedBackgroundFunctionArray = [];
40
42
  }
41
43
 
42
44
  function runDelayedBackgroundFunctions(): void {
@@ -16,6 +16,7 @@ class JsFunctionLifecycleManager {
16
16
  private execIdSetToFire = new Set<number>();
17
17
  private retainedObjects = new WeakSet<object>();
18
18
  private willFire = false;
19
+ private active = true;
19
20
  private registry: FinalizationRegistry<number>;
20
21
 
21
22
  constructor() {
@@ -26,12 +27,13 @@ class JsFunctionLifecycleManager {
26
27
  if (this.retainedObjects.has(objToRef)) {
27
28
  return;
28
29
  }
30
+ // A failed engine registration must leave the target eligible for a retry.
31
+ this.registry.register(objToRef, execId);
29
32
  this.retainedObjects.add(objToRef);
30
33
  this.execIdRefCount.set(
31
34
  execId,
32
35
  (this.execIdRefCount.get(execId) ?? 0) + 1,
33
36
  );
34
- this.registry.register(objToRef, execId);
35
37
  }
36
38
 
37
39
  removeRef(execId: number): void {
@@ -50,7 +52,12 @@ class JsFunctionLifecycleManager {
50
52
  }
51
53
  }
52
54
 
55
+ dispose(): void {
56
+ this.active = false;
57
+ }
58
+
53
59
  fire(): void {
60
+ if (!this.active) return;
54
61
  profile('JsFunctionLifecycleManager.fire', () => {
55
62
  lynx.getJSContext().dispatchEvent({
56
63
  type: WorkletEvents.releaseBackgroundWorkletCtx,
@@ -1,6 +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 { addReloadScopedEventListener } from '../core/reload-scoped-event.js';
4
5
  import { WorkletEvents } from './bindings/events.js';
5
6
  import type { ReleaseWorkletRefData, RunWorkletCtxData } from './bindings/events.js';
6
7
  import type { ClosureValueType } from './bindings/types.js';
@@ -10,13 +11,9 @@ import { removeValueFromWorkletRefMap } from './workletRef.js';
10
11
 
11
12
  function initEventListeners(): void {
12
13
  const jsContext = lynx.getJSContext();
13
- jsContext.addEventListener(
14
- WorkletEvents.runWorkletCtx,
15
- (event: Event) => {
16
- const data = JSON.parse(event.data as string) as RunWorkletCtxData;
17
- runRunOnMainThreadTask(data.worklet, data.params as ClosureValueType[], data.resolveId);
18
- },
19
- );
14
+ addReloadScopedEventListener(jsContext, WorkletEvents.runWorkletCtx, (data: RunWorkletCtxData) => {
15
+ runRunOnMainThreadTask(data.worklet, data.params as ClosureValueType[], data.resolveId);
16
+ });
20
17
  jsContext.addEventListener(
21
18
  WorkletEvents.releaseWorkletRef,
22
19
  (event: Event) => {
@@ -33,8 +33,9 @@ function registerMainThreadObjectType(
33
33
  `Conflicting MainThreadObject registration for type "${type}". A type key must always use the same create function.`,
34
34
  );
35
35
  }
36
- return;
36
+ if (registered.create === create) return;
37
37
  }
38
+ // A re-evaluated module brings a factory bound to its own module state.
38
39
  mainThreadObjectDefinitions.set(type, { create });
39
40
  }
40
41