@lynx-js/react 0.127.0 → 0.129.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (428) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +6 -14
  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/reload-scoped-dual-thread-communication.test.ts +129 -0
  7. package/runtime/__test__/core/thread-function-call.test.ts +1 -0
  8. package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +2 -0
  9. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -1
  10. package/runtime/__test__/element-template/native/index.test.ts +8 -0
  11. package/runtime/__test__/element-template/native/main-thread-ref-init-value.test.ts +100 -0
  12. package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +101 -0
  13. package/runtime/__test__/element-template/native/reload.test.ts +50 -1
  14. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +104 -47
  15. package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +39 -48
  16. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +14 -10
  17. package/runtime/__test__/element-template/runtime/background/re-eval-reload.test.ts +69 -0
  18. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +31 -5
  19. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +17 -3
  20. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +8 -3
  21. package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +89 -2
  22. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +5 -0
  23. package/runtime/__test__/element-template/test-utils/mock/globals.js +6 -0
  24. package/runtime/__test__/element-template/vitest.config.ts +4 -0
  25. package/runtime/__test__/snapshot/lifecycle/re-eval-reload.test.jsx +114 -0
  26. package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +169 -0
  27. package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +63 -0
  28. package/runtime/__test__/snapshot/lifecycle/reload-delayed-main-thread.test.jsx +103 -0
  29. package/runtime/__test__/snapshot/lifecycle.test.jsx +61 -1
  30. package/runtime/__test__/snapshot/lynx/lazy-effect-scheduling.test.jsx +105 -0
  31. package/runtime/__test__/snapshot/ssr.test.jsx +2 -2
  32. package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +6 -11
  33. package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +1 -1
  34. package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +24 -1
  35. package/runtime/__test__/worklet-runtime/initEntry.test.js +109 -0
  36. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +15 -1
  37. package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +46 -0
  38. package/runtime/__test__/worklet-runtime/object-methods.test.js +2 -3
  39. package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +3 -3
  40. package/runtime/lazy/element-template-internal.js +0 -1
  41. package/runtime/lazy/internal.js +0 -1
  42. package/runtime/lib/core/background-function/exec-map.d.ts +2 -0
  43. package/runtime/lib/core/background-function/exec-map.js +7 -0
  44. package/runtime/lib/core/background-function/exec-map.js.map +1 -1
  45. package/runtime/lib/core/background-function/handle.js.map +1 -1
  46. package/runtime/lib/core/background-function/run-on-background.js +15 -16
  47. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  48. package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
  49. package/runtime/lib/core/card-lifetime.d.ts +5 -0
  50. package/runtime/lib/core/card-lifetime.js +17 -0
  51. package/runtime/lib/core/card-lifetime.js.map +1 -0
  52. package/runtime/lib/core/commit-context.js.map +1 -1
  53. package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
  54. package/runtime/lib/core/compat/lynxComponent.js.map +1 -1
  55. package/runtime/lib/core/component.js.map +1 -1
  56. package/runtime/lib/core/entry-reload.d.ts +7 -0
  57. package/runtime/lib/core/entry-reload.js +49 -0
  58. package/runtime/lib/core/entry-reload.js.map +1 -0
  59. package/runtime/lib/core/forceRootRender.js.map +1 -1
  60. package/runtime/lib/core/globalProps.js.map +1 -1
  61. package/runtime/lib/core/hooks/mainThread.js.map +1 -1
  62. package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
  63. package/runtime/lib/core/hooks/react.js.map +1 -1
  64. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
  65. package/runtime/lib/core/initData.js.map +1 -1
  66. package/runtime/lib/core/lynx/dynamic-import.js.map +1 -1
  67. package/runtime/lib/core/lynx/lazy-bundle.js +4 -1
  68. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  69. package/runtime/lib/core/lynx/runtime-backend.js.map +1 -1
  70. package/runtime/lib/core/lynx/runtime-version.js.map +1 -1
  71. package/runtime/lib/core/lynx-data-processors.js.map +1 -1
  72. package/runtime/lib/core/lynx-page-data.js.map +1 -1
  73. package/runtime/lib/core/lynx-update-data.js.map +1 -1
  74. package/runtime/lib/core/main-thread-function.js.map +1 -1
  75. package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -1
  76. package/runtime/lib/core/main-thread-object.js +1 -4
  77. package/runtime/lib/core/main-thread-object.js.map +1 -1
  78. package/runtime/lib/core/main-thread-ref-id.js +4 -4
  79. package/runtime/lib/core/main-thread-ref-id.js.map +1 -1
  80. package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
  81. package/runtime/lib/core/main-thread-ref.js.map +1 -1
  82. package/runtime/lib/core/mts-capability.js.map +1 -1
  83. package/runtime/lib/core/performance.js.map +1 -1
  84. package/runtime/lib/core/ref.js.map +1 -1
  85. package/runtime/lib/core/reload-scoped-event.d.ts +5 -0
  86. package/runtime/lib/core/reload-scoped-event.js +26 -0
  87. package/runtime/lib/core/reload-scoped-event.js.map +1 -0
  88. package/runtime/lib/core/reload-version.js +4 -3
  89. package/runtime/lib/core/reload-version.js.map +1 -1
  90. package/runtime/lib/core/runtime-destroy.d.ts +2 -0
  91. package/runtime/lib/core/runtime-destroy.js +9 -0
  92. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  93. package/runtime/lib/core/thread-function-call/main-thread.js +5 -4
  94. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  95. package/runtime/lib/core/thread-function-call/return-value.js +6 -5
  96. package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
  97. package/runtime/lib/document.js.map +1 -1
  98. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  99. package/runtime/lib/element-template/background/commit-context.js.map +1 -1
  100. package/runtime/lib/element-template/background/commit-hook.js +19 -16
  101. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  102. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  103. package/runtime/lib/element-template/background/document.js.map +1 -1
  104. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  105. package/runtime/lib/element-template/background/hydration-listener.js +2 -6
  106. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  107. package/runtime/lib/element-template/background/instance.js.map +1 -1
  108. package/runtime/lib/element-template/background/manager.js.map +1 -1
  109. package/runtime/lib/element-template/background/page-root-hydrate.js.map +1 -1
  110. package/runtime/lib/element-template/background/render-scope.js.map +1 -1
  111. package/runtime/lib/element-template/client/root.js.map +1 -1
  112. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  113. package/runtime/lib/element-template/debug/elementPAPICall.js.map +1 -1
  114. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  115. package/runtime/lib/element-template/hydration-map.js.map +1 -1
  116. package/runtime/lib/element-template/index.js.map +1 -1
  117. package/runtime/lib/element-template/internal.d.ts +0 -1
  118. package/runtime/lib/element-template/internal.js +0 -1
  119. package/runtime/lib/element-template/internal.js.map +1 -1
  120. package/runtime/lib/element-template/jsx-dev-runtime/index.js.map +1 -1
  121. package/runtime/lib/element-template/jsx-runtime/index.js.map +1 -1
  122. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  123. package/runtime/lib/element-template/lynx/performance.js.map +1 -1
  124. package/runtime/lib/element-template/main-thread-ref-init-value.d.ts +3 -0
  125. package/runtime/lib/element-template/main-thread-ref-init-value.js +38 -0
  126. package/runtime/lib/element-template/main-thread-ref-init-value.js.map +1 -0
  127. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
  128. package/runtime/lib/element-template/native/index.js +2 -0
  129. package/runtime/lib/element-template/native/index.js.map +1 -1
  130. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  131. package/runtime/lib/element-template/native/mts-destroy.js +2 -0
  132. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  133. package/runtime/lib/element-template/native/patch-listener.js +1 -4
  134. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  135. package/runtime/lib/element-template/native/reload-background.d.ts +1 -1
  136. package/runtime/lib/element-template/native/reload-background.js +12 -1
  137. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  138. package/runtime/lib/element-template/native/reload-main-thread.d.ts +6 -0
  139. package/runtime/lib/element-template/native/reload-main-thread.js +18 -2
  140. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  141. package/runtime/lib/element-template/prop-adapters/event-value.js.map +1 -1
  142. package/runtime/lib/element-template/prop-adapters/event.js.map +1 -1
  143. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
  144. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  145. package/runtime/lib/element-template/protocol/lifecycle-constant.d.ts +2 -1
  146. package/runtime/lib/element-template/protocol/lifecycle-constant.js +1 -0
  147. package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
  148. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  149. package/runtime/lib/element-template/protocol/page.js.map +1 -1
  150. package/runtime/lib/element-template/protocol/template-type.js.map +1 -1
  151. package/runtime/lib/element-template/protocol/types.d.ts +0 -2
  152. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  153. package/runtime/lib/element-template/protocol/update-event.js.map +1 -1
  154. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  155. package/runtime/lib/element-template/runtime/page/authored-page.js.map +1 -1
  156. package/runtime/lib/element-template/runtime/page/page.js.map +1 -1
  157. package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
  158. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  159. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
  160. package/runtime/lib/element-template/runtime/render/host.js.map +1 -1
  161. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  162. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
  163. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  164. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  165. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  166. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  167. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  168. package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js.map +1 -1
  169. package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +1 -1
  170. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  171. package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
  172. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  173. package/runtime/lib/element-template/runtime-marker.js.map +1 -1
  174. package/runtime/lib/index.js.map +1 -1
  175. package/runtime/lib/internal.d.ts +0 -1
  176. package/runtime/lib/internal.js +0 -1
  177. package/runtime/lib/internal.js.map +1 -1
  178. package/runtime/lib/lynx-api.js.map +1 -1
  179. package/runtime/lib/lynx.js.map +1 -1
  180. package/runtime/lib/root.js.map +1 -1
  181. package/runtime/lib/runtime-marker.js.map +1 -1
  182. package/runtime/lib/shared/attribute-name.js.map +1 -1
  183. package/runtime/lib/shared/component-stack.js.map +1 -1
  184. package/runtime/lib/shared/index-map.d.ts +4 -1
  185. package/runtime/lib/shared/index-map.js +5 -2
  186. package/runtime/lib/shared/index-map.js.map +1 -1
  187. package/runtime/lib/shared/profile.js.map +1 -1
  188. package/runtime/lib/shared/render-constants.js.map +1 -1
  189. package/runtime/lib/snapshot/alog/elementPAPICall.js.map +1 -1
  190. package/runtime/lib/snapshot/alog/index.js.map +1 -1
  191. package/runtime/lib/snapshot/alog/render.js.map +1 -1
  192. package/runtime/lib/snapshot/compat/componentIs.js.map +1 -1
  193. package/runtime/lib/snapshot/debug/debug.js.map +1 -1
  194. package/runtime/lib/snapshot/debug/describeInvalidValue.js.map +1 -1
  195. package/runtime/lib/snapshot/debug/formatPatch.js.map +1 -1
  196. package/runtime/lib/snapshot/debug/printSnapshot.js.map +1 -1
  197. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  198. package/runtime/lib/snapshot/debug/vnodeSource.js.map +1 -1
  199. package/runtime/lib/snapshot/gesture/processGesture.js.map +1 -1
  200. package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +1 -1
  201. package/runtime/lib/snapshot/gesture/types.js.map +1 -1
  202. package/runtime/lib/snapshot/index.js.map +1 -1
  203. package/runtime/lib/snapshot/lifecycle/constant.js.map +1 -1
  204. package/runtime/lib/snapshot/lifecycle/destroy.js +6 -0
  205. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  206. package/runtime/lib/snapshot/lifecycle/event/delayEvents.js.map +1 -1
  207. package/runtime/lib/snapshot/lifecycle/event/delayLifecycleEvents.js.map +1 -1
  208. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.d.ts +6 -2
  209. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js +21 -18
  210. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
  211. package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
  212. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  213. package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
  214. package/runtime/lib/snapshot/lifecycle/patch/globalState.js.map +1 -1
  215. package/runtime/lib/snapshot/lifecycle/patch/isMainThreadHydrating.js.map +1 -1
  216. package/runtime/lib/snapshot/lifecycle/patch/nodesRefApply.js.map +1 -1
  217. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
  218. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  219. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  220. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  221. package/runtime/lib/snapshot/lifecycle/reload.d.ts +9 -2
  222. package/runtime/lib/snapshot/lifecycle/reload.js +29 -8
  223. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  224. package/runtime/lib/snapshot/lifecycle/render.js.map +1 -1
  225. package/runtime/lib/snapshot/list/list.js +3 -2
  226. package/runtime/lib/snapshot/list/list.js.map +1 -1
  227. package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
  228. package/runtime/lib/snapshot/list/pendingListUpdates.js.map +1 -1
  229. package/runtime/lib/snapshot/lynx/calledByNative.js +3 -3
  230. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  231. package/runtime/lib/snapshot/lynx/children.js.map +1 -1
  232. package/runtime/lib/snapshot/lynx/element.js.map +1 -1
  233. package/runtime/lib/snapshot/lynx/env.js.map +1 -1
  234. package/runtime/lib/snapshot/lynx/injectLepusMethods.js.map +1 -1
  235. package/runtime/lib/snapshot/lynx/lazyBundleConstants.js.map +1 -1
  236. package/runtime/lib/snapshot/lynx/nodesRef.js.map +1 -1
  237. package/runtime/lib/snapshot/lynx/performance.js.map +1 -1
  238. package/runtime/lib/snapshot/lynx/portals.js.map +1 -1
  239. package/runtime/lib/snapshot/lynx/portalsPending.js.map +1 -1
  240. package/runtime/lib/snapshot/lynx/prepareLazyBundleMTS.js.map +1 -1
  241. package/runtime/lib/snapshot/lynx/runWithForce.js.map +1 -1
  242. package/runtime/lib/snapshot/lynx/suspense.js.map +1 -1
  243. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  244. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  245. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  246. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  247. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  248. package/runtime/lib/snapshot/snapshot/constants.js.map +1 -1
  249. package/runtime/lib/snapshot/snapshot/definition.js.map +1 -1
  250. package/runtime/lib/snapshot/snapshot/dynamicPartType.js.map +1 -1
  251. package/runtime/lib/snapshot/snapshot/event.js.map +1 -1
  252. package/runtime/lib/snapshot/snapshot/gesture.js.map +1 -1
  253. package/runtime/lib/snapshot/snapshot/index.js.map +1 -1
  254. package/runtime/lib/snapshot/snapshot/list.js +2 -1
  255. package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
  256. package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
  257. package/runtime/lib/snapshot/snapshot/reconstructInstanceTree.js.map +1 -1
  258. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  259. package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
  260. package/runtime/lib/snapshot/snapshot/snapshotCreatorMap.js.map +1 -1
  261. package/runtime/lib/snapshot/snapshot/snapshotInstanceHydrationMap.js.map +1 -1
  262. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.d.ts +4 -2
  263. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js +11 -11
  264. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
  265. package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
  266. package/runtime/lib/snapshot/snapshot/types.js.map +1 -1
  267. package/runtime/lib/snapshot/snapshot/utils.js.map +1 -1
  268. package/runtime/lib/snapshot/snapshot/workletEvent.js.map +1 -1
  269. package/runtime/lib/snapshot/snapshot/workletRef.js.map +1 -1
  270. package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +1 -0
  271. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +6 -1
  272. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  273. package/runtime/lib/snapshot/worklet/ctx.d.ts +1 -1
  274. package/runtime/lib/snapshot/worklet/ctx.js +6 -1
  275. package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
  276. package/runtime/lib/snapshot/worklet/destroy.js.map +1 -1
  277. package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
  278. package/runtime/lib/snapshot/worklet/hmr.js.map +1 -1
  279. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js +6 -0
  280. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
  281. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  282. package/runtime/lib/utils.js.map +1 -1
  283. package/runtime/lib/worklet-runtime/api/animation/animation.js.map +1 -1
  284. package/runtime/lib/worklet-runtime/api/animation/effect.js.map +1 -1
  285. package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
  286. package/runtime/lib/worklet-runtime/api/lepusQuerySelector.js.map +1 -1
  287. package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
  288. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  289. package/runtime/lib/worklet-runtime/bindings/events.js.map +1 -1
  290. package/runtime/lib/worklet-runtime/bindings/index.d.ts +0 -1
  291. package/runtime/lib/worklet-runtime/bindings/index.js +0 -1
  292. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
  293. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  294. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
  295. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +3 -1
  296. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
  297. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
  298. package/runtime/lib/worklet-runtime/eomImpl.js.map +1 -1
  299. package/runtime/lib/worklet-runtime/eventPropagation.js.map +1 -1
  300. package/runtime/lib/worklet-runtime/global.js.map +1 -1
  301. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  302. package/runtime/lib/worklet-runtime/index.js +6 -0
  303. package/runtime/lib/worklet-runtime/index.js.map +1 -1
  304. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +2 -1
  305. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  306. package/runtime/lib/worklet-runtime/listeners.js +2 -2
  307. package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
  308. package/runtime/lib/worklet-runtime/mainThreadObject.js +3 -1
  309. package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -1
  310. package/runtime/lib/worklet-runtime/runOnMainThread.js +4 -3
  311. package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
  312. package/runtime/lib/worklet-runtime/utils/mainThreadFlushLoopGuard.js.map +1 -1
  313. package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
  314. package/runtime/lib/worklet-runtime/utils/version.js.map +1 -1
  315. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
  316. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  317. package/runtime/src/core/background-function/exec-map.ts +9 -0
  318. package/runtime/src/core/background-function/run-on-background.ts +14 -16
  319. package/runtime/src/core/card-lifetime.ts +18 -0
  320. package/runtime/src/core/entry-reload.ts +63 -0
  321. package/runtime/src/core/lynx/lazy-bundle.ts +4 -1
  322. package/runtime/src/core/main-thread-object.ts +1 -8
  323. package/runtime/src/core/main-thread-ref-id.ts +5 -4
  324. package/runtime/src/core/reload-scoped-event.ts +35 -0
  325. package/runtime/src/core/reload-version.ts +5 -3
  326. package/runtime/src/core/runtime-destroy.ts +11 -0
  327. package/runtime/src/core/thread-function-call/main-thread.ts +4 -4
  328. package/runtime/src/core/thread-function-call/return-value.ts +6 -5
  329. package/runtime/src/element-template/background/commit-hook.ts +20 -17
  330. package/runtime/src/element-template/background/hydration-listener.ts +2 -6
  331. package/runtime/src/element-template/internal.ts +0 -1
  332. package/runtime/src/element-template/main-thread-ref-init-value.ts +44 -0
  333. package/runtime/src/element-template/native/index.ts +2 -0
  334. package/runtime/src/element-template/native/mts-destroy.ts +3 -0
  335. package/runtime/src/element-template/native/patch-listener.ts +0 -5
  336. package/runtime/src/element-template/native/reload-background.ts +13 -1
  337. package/runtime/src/element-template/native/reload-main-thread.ts +30 -2
  338. package/runtime/src/element-template/protocol/lifecycle-constant.ts +1 -0
  339. package/runtime/src/element-template/protocol/types.ts +0 -2
  340. package/runtime/src/internal.ts +0 -1
  341. package/runtime/src/shared/index-map.ts +3 -2
  342. package/runtime/src/snapshot/lifecycle/destroy.ts +7 -0
  343. package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +26 -19
  344. package/runtime/src/snapshot/lifecycle/reload.ts +47 -11
  345. package/runtime/src/snapshot/list/list.ts +9 -2
  346. package/runtime/src/snapshot/lynx/calledByNative.ts +3 -4
  347. package/runtime/src/snapshot/snapshot/list.ts +5 -1
  348. package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +19 -12
  349. package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +10 -1
  350. package/runtime/src/snapshot/worklet/ctx.ts +10 -1
  351. package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +6 -0
  352. package/runtime/src/worklet-runtime/README.md +13 -0
  353. package/runtime/src/worklet-runtime/bindings/index.ts +0 -1
  354. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +3 -1
  355. package/runtime/src/worklet-runtime/index.ts +7 -0
  356. package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +2 -1
  357. package/runtime/src/worklet-runtime/listeners.ts +4 -7
  358. package/runtime/src/worklet-runtime/mainThreadObject.ts +2 -1
  359. package/runtime/src/worklet-runtime/runOnMainThread.ts +4 -3
  360. package/runtime/tsconfig.json +2 -0
  361. package/runtime/types/types.d.ts +3 -1
  362. package/runtime/vitest.config.ts +4 -0
  363. package/testing-library/.turbo/turbo-build.log +12 -12
  364. package/testing-library/dist/env/index.js +3 -15
  365. package/testing-library/dist/plugins/index.js +10 -0
  366. package/testing-library/dist/rstest-config.js +15 -0
  367. package/testing-library/dist/setupFiles/common/worklet-runtime-init.js +11 -0
  368. package/testing-library/rstest.config.ts +3 -0
  369. package/testing-library/src/__tests__/rstest-config.test.js +34 -1
  370. package/testing-library/src/__tests__/worklet.test.jsx +51 -37
  371. package/testing-library/src/plugins/vitest.ts +5 -1
  372. package/testing-library/src/rstest-config.ts +17 -1
  373. package/testing-library/src/setupFiles/common/worklet-runtime-init.js +22 -0
  374. package/transform/.turbo/turbo-build$colon$wasm.log +345 -150
  375. package/transform/__test__/defines.spec.js +187 -12
  376. package/transform/__test__/fixture.spec.js +166 -48
  377. package/transform/__test__/object-methods.spec.js +1 -3
  378. package/transform/crates/swc_plugin_worklet/definition_imports.rs +97 -0
  379. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +26 -10
  380. package/transform/crates/swc_plugin_worklet/lib.rs +138 -153
  381. package/transform/crates/swc_plugin_worklet/napi.rs +10 -1
  382. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +4 -4
  383. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +3 -5
  384. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_lepus.js +2 -4
  385. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +4 -4
  386. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_lepus.js +3 -5
  387. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_lepus.js +2 -4
  388. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +4 -4
  389. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +2 -4
  390. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_globals.js +2 -4
  391. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +2 -4
  392. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_type_annotations.js +2 -4
  393. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_destructure_from_closure.js +2 -4
  394. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_catch_clause_params.js +2 -4
  395. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_idents_inside_of_ctx.js +2 -4
  396. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_recursively.js +2 -4
  397. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +6 -6
  398. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js +2 -4
  399. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_arrow_function.js +2 -4
  400. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_lepus.js +2 -4
  401. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_function_expr.js +2 -4
  402. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_lepus.js +2 -4
  403. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_lepus.js +2 -4
  404. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_lepus.js +2 -4
  405. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_lepus.js +2 -4
  406. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_lepus.js +2 -4
  407. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +4 -4
  408. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_alias.js +2 -4
  409. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general.js +2 -4
  410. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general_mixed.js +2 -4
  411. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets.js +3 -5
  412. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets_in_func.js +3 -5
  413. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +2 -4
  414. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_lepus.js +2 -4
  415. package/transform/dist/wasm.cjs +1 -1
  416. package/transform/index.d.ts +27 -1
  417. package/transform/src/lib.rs +354 -23
  418. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +53 -52
  419. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  420. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +63 -293
  421. package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +0 -8
  422. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +0 -23
  423. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +0 -1
  424. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +0 -25
  425. package/runtime/worklet-runtime/dev.js +0 -775
  426. package/runtime/worklet-runtime/main.js +0 -1
  427. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_inner_ident.js +0 -13
  428. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_outer_ident.js +0 -13
@@ -507,6 +507,9 @@ describe('jsx', () => {
507
507
  "definesForSnapshot": [],
508
508
  "definesForWorklet": [],
509
509
  "errors": [],
510
+ "runtimeRequirements": {
511
+ "mainThreadProgrammability": false,
512
+ },
510
513
  "uiSourceMapRecords": [],
511
514
  "warnings": [],
512
515
  }
@@ -611,6 +614,9 @@ describe('jsx', () => {
611
614
  ],
612
615
  "definesForWorklet": [],
613
616
  "errors": [],
617
+ "runtimeRequirements": {
618
+ "mainThreadProgrammability": false,
619
+ },
614
620
  "uiSourceMapRecords": [],
615
621
  "warnings": [],
616
622
  }
@@ -717,6 +723,9 @@ describe('errors and warnings', () => {
717
723
  "text": "Expected '</', got '<eof>'",
718
724
  },
719
725
  ],
726
+ "runtimeRequirements": {
727
+ "mainThreadProgrammability": false,
728
+ },
720
729
  "uiSourceMapRecords": [],
721
730
  "warnings": [],
722
731
  }
@@ -758,6 +767,9 @@ Component, View
758
767
  "definesForSnapshot": [],
759
768
  "definesForWorklet": [],
760
769
  "errors": [],
770
+ "runtimeRequirements": {
771
+ "mainThreadProgrammability": false,
772
+ },
761
773
  "uiSourceMapRecords": [],
762
774
  "warnings": [
763
775
  {
@@ -1935,6 +1947,7 @@ class X extends Component {
1935
1947
  });
1936
1948
 
1937
1949
  describe('worklet', () => {
1950
+ const internalWorkletRuntimePkg = '@lynx-js/react/internal';
1938
1951
  const lepusWorkletOptions = {
1939
1952
  pluginName: '',
1940
1953
  filename: '',
@@ -1954,7 +1967,7 @@ describe('worklet', () => {
1954
1967
  worklet: {
1955
1968
  target: 'LEPUS',
1956
1969
  filename: '',
1957
- runtimePkg: '@lynx-js/react',
1970
+ runtimePkg: internalWorkletRuntimePkg,
1958
1971
  },
1959
1972
  };
1960
1973
 
@@ -1986,7 +1999,7 @@ export function bar() {
1986
1999
  worklet: {
1987
2000
  target: 'LEPUS',
1988
2001
  filename: '',
1989
- runtimePkg: '@lynx-js/react',
2002
+ runtimePkg: internalWorkletRuntimePkg,
1990
2003
  },
1991
2004
  },
1992
2005
  );
@@ -2065,7 +2078,7 @@ export function bar() {
2065
2078
  worklet: {
2066
2079
  target: 'LEPUS',
2067
2080
  filename: '',
2068
- runtimePkg: '@lynx-js/react',
2081
+ runtimePkg: internalWorkletRuntimePkg,
2069
2082
  },
2070
2083
  },
2071
2084
  );
@@ -2104,7 +2117,7 @@ export function bar() {
2104
2117
  worklet: {
2105
2118
  target: 'LEPUS',
2106
2119
  filename: '',
2107
- runtimePkg: '@lynx-js/react',
2120
+ runtimePkg: internalWorkletRuntimePkg,
2108
2121
  },
2109
2122
  },
2110
2123
  );
@@ -2116,7 +2129,7 @@ export function bar() {
2116
2129
  });
2117
2130
 
2118
2131
  it('should not inject runtime when no worklet exists', async () => {
2119
- const { code } = await transformReactLynx(
2132
+ const { code, runtimeRequirements } = await transformReactLynx(
2120
2133
  `\
2121
2134
  export function getCurrentDelta(event) {
2122
2135
  return foo.bar.baz;
@@ -2125,14 +2138,17 @@ export function getCurrentDelta(event) {
2125
2138
  lepusWorkletOptions,
2126
2139
  );
2127
2140
 
2128
- expect(code).not.toContain('loadWorkletRuntime');
2141
+ expect(code).not.toContain('@lynx-js/react/worklet-runtime/init');
2129
2142
  expect(code).not.toContain('registerWorkletInternal');
2130
2143
  expect(code).not.toContain('_wkltId');
2144
+ expect(runtimeRequirements).toEqual({
2145
+ mainThreadProgrammability: false,
2146
+ });
2131
2147
  });
2132
2148
 
2133
2149
  for (const target of ['LEPUS', 'JS', 'MIXED']) {
2134
2150
  it('member expression', async () => {
2135
- const { code } = await transformReactLynx(
2151
+ const { code, runtimeRequirements } = await transformReactLynx(
2136
2152
  `\
2137
2153
  export function getCurrentDelta(event) {
2138
2154
  "main thread";
@@ -2158,15 +2174,16 @@ export function getCurrentDelta(event) {
2158
2174
  worklet: {
2159
2175
  target,
2160
2176
  filename: '',
2161
- runtimePkg: '@lynx-js/react',
2177
+ runtimePkg: internalWorkletRuntimePkg,
2162
2178
  },
2163
2179
  },
2164
2180
  );
2165
2181
 
2166
2182
  if (target === 'LEPUS') {
2167
2183
  expect(code).toMatchInlineSnapshot(`
2168
- "import { captureMainThreadObject as __captureMainThreadObject, loadWorkletRuntime as __loadWorkletRuntime } from "@lynx-js/react";
2169
- var captureMainThreadObject = __captureMainThreadObject, loadWorkletRuntime = __loadWorkletRuntime;
2184
+ "import { registerWorklet as __registerWorklet } from "@lynx-js/react/worklet-runtime/init";
2185
+ import { captureMainThreadObject as __captureMainThreadObject } from "@lynx-js/react/internal";
2186
+ var captureMainThreadObject = __captureMainThreadObject;
2170
2187
  export let getCurrentDelta = {
2171
2188
  _c: {
2172
2189
  foo: captureMainThreadObject(foo) ?? {
@@ -2177,8 +2194,7 @@ export function getCurrentDelta(event) {
2177
2194
  },
2178
2195
  _wkltId: "da39:75a1b:1"
2179
2196
  };
2180
- const __workletRuntimeLoaded = loadWorkletRuntime(typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry);
2181
- __workletRuntimeLoaded && registerWorkletInternal("main-thread", "da39:75a1b:1", function(event) {
2197
+ __registerWorklet("main-thread", "da39:75a1b:1", function(event) {
2182
2198
  const getCurrentDelta = lynxWorkletImpl._workletMap["da39:75a1b:1"].bind(this);
2183
2199
  let { foo } = this["_c"];
2184
2200
  "main thread";
@@ -2186,11 +2202,9 @@ export function getCurrentDelta(event) {
2186
2202
  });
2187
2203
  "
2188
2204
  `);
2189
- expect(code).toContain('loadWorkletRuntime');
2190
- expect(code).toContain('registerWorkletInternal("main-thread"');
2191
2205
  } else if (target === 'JS') {
2192
2206
  expect(code).toMatchInlineSnapshot(`
2193
- "import { captureMainThreadObject as __captureMainThreadObject } from "@lynx-js/react";
2207
+ "import { captureMainThreadObject as __captureMainThreadObject } from "@lynx-js/react/internal";
2194
2208
  var captureMainThreadObject = __captureMainThreadObject;
2195
2209
  export let getCurrentDelta = {
2196
2210
  _c: {
@@ -2204,12 +2218,11 @@ export function getCurrentDelta(event) {
2204
2218
  };
2205
2219
  "
2206
2220
  `);
2207
- expect(code).not.toContain('loadWorkletRuntime');
2208
- expect(code).not.toContain('registerWorkletInternal');
2209
2221
  } else if (target === 'MIXED') {
2210
2222
  expect(code).toMatchInlineSnapshot(`
2211
- "import { captureMainThreadObject as __captureMainThreadObject, loadWorkletRuntime as __loadWorkletRuntime } from "@lynx-js/react";
2212
- var captureMainThreadObject = __captureMainThreadObject, loadWorkletRuntime = __loadWorkletRuntime;
2223
+ "import { registerWorklet as __registerWorklet } from "@lynx-js/react/worklet-runtime/init";
2224
+ import { captureMainThreadObject as __captureMainThreadObject } from "@lynx-js/react/internal";
2225
+ var captureMainThreadObject = __captureMainThreadObject;
2213
2226
  export let getCurrentDelta = {
2214
2227
  _c: {
2215
2228
  foo: captureMainThreadObject(foo) ?? {
@@ -2220,8 +2233,7 @@ export function getCurrentDelta(event) {
2220
2233
  },
2221
2234
  _wkltId: "da39:75a1b:1"
2222
2235
  };
2223
- const __workletRuntimeLoaded = loadWorkletRuntime(typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry);
2224
- __workletRuntimeLoaded && registerWorkletInternal("main-thread", "da39:75a1b:1", function(event) {
2236
+ __registerWorklet("main-thread", "da39:75a1b:1", function(event) {
2225
2237
  const getCurrentDelta = lynxWorkletImpl._workletMap["da39:75a1b:1"].bind(this);
2226
2238
  let { foo } = this["_c"];
2227
2239
  "main thread";
@@ -2229,14 +2241,15 @@ export function getCurrentDelta(event) {
2229
2241
  });
2230
2242
  "
2231
2243
  `);
2232
- expect(code).toContain('loadWorkletRuntime');
2233
- expect(code).toContain('registerWorkletInternal("main-thread"');
2234
2244
  }
2245
+ expect(runtimeRequirements).toEqual({
2246
+ mainThreadProgrammability: target !== 'JS',
2247
+ });
2235
2248
  });
2236
2249
  }
2237
2250
 
2238
2251
  it('member expression with multiple times', async () => {
2239
- const { code } = await transformReactLynx(
2252
+ const { code, runtimeRequirements } = await transformReactLynx(
2240
2253
  `\
2241
2254
  export function foo(event) {
2242
2255
  "main thread";
@@ -2262,14 +2275,15 @@ export function foo(event) {
2262
2275
  worklet: {
2263
2276
  target: 'LEPUS',
2264
2277
  filename: '',
2265
- runtimePkg: '@lynx-js/react',
2278
+ runtimePkg: internalWorkletRuntimePkg,
2266
2279
  },
2267
2280
  },
2268
2281
  );
2269
2282
 
2270
2283
  expect(code).toMatchInlineSnapshot(`
2271
- "import { captureMainThreadObject as __captureMainThreadObject, loadWorkletRuntime as __loadWorkletRuntime } from "@lynx-js/react";
2272
- var captureMainThreadObject = __captureMainThreadObject, loadWorkletRuntime = __loadWorkletRuntime;
2284
+ "import { registerWorklet as __registerWorklet } from "@lynx-js/react/worklet-runtime/init";
2285
+ import { captureMainThreadObject as __captureMainThreadObject } from "@lynx-js/react/internal";
2286
+ var captureMainThreadObject = __captureMainThreadObject;
2273
2287
  export let foo = {
2274
2288
  _c: {
2275
2289
  bar: captureMainThreadObject(bar) ?? {
@@ -2288,8 +2302,7 @@ export function foo(event) {
2288
2302
  },
2289
2303
  _wkltId: "da39:64631:1"
2290
2304
  };
2291
- const __workletRuntimeLoaded = loadWorkletRuntime(typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry);
2292
- __workletRuntimeLoaded && registerWorkletInternal("main-thread", "da39:64631:1", function(event) {
2305
+ __registerWorklet("main-thread", "da39:64631:1", function(event) {
2293
2306
  const foo = lynxWorkletImpl._workletMap["da39:64631:1"].bind(this);
2294
2307
  let { bar, qux } = this["_c"];
2295
2308
  "main thread";
@@ -2297,12 +2310,13 @@ export function foo(event) {
2297
2310
  });
2298
2311
  "
2299
2312
  `);
2300
- expect((code.match(/registerWorkletInternal/g) ?? []).length).toBe(1);
2301
- expect((code.match(/const __workletRuntimeLoaded = loadWorkletRuntime/g) ?? []).length).toBe(1);
2313
+ expect(runtimeRequirements).toEqual({
2314
+ mainThreadProgrammability: true,
2315
+ });
2302
2316
  });
2303
2317
 
2304
2318
  it('nested', async () => {
2305
- const { code } = await transformReactLynx(
2319
+ const { code, runtimeRequirements } = await transformReactLynx(
2306
2320
  `\
2307
2321
  function foo() {
2308
2322
  "main thread";
@@ -2333,14 +2347,13 @@ console.log(bar)
2333
2347
  worklet: {
2334
2348
  target: 'LEPUS',
2335
2349
  filename: '',
2336
- runtimePkg: '@lynx-js/react',
2350
+ runtimePkg: internalWorkletRuntimePkg,
2337
2351
  },
2338
2352
  },
2339
2353
  );
2340
2354
 
2341
2355
  expect(code).toMatchInlineSnapshot(`
2342
- "import { loadWorkletRuntime as __loadWorkletRuntime } from "@lynx-js/react";
2343
- var loadWorkletRuntime = __loadWorkletRuntime;
2356
+ "import { registerWorklet as __registerWorklet } from "@lynx-js/react/worklet-runtime/init";
2344
2357
  let foo = {
2345
2358
  _wkltId: "da39:80ef4:1"
2346
2359
  };
@@ -2351,13 +2364,12 @@ console.log(bar)
2351
2364
  _wkltId: "da39:80ef4:2"
2352
2365
  };
2353
2366
  console.log(bar);
2354
- const __workletRuntimeLoaded = loadWorkletRuntime(typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry);
2355
- __workletRuntimeLoaded && registerWorkletInternal("main-thread", "da39:80ef4:1", function() {
2367
+ __registerWorklet("main-thread", "da39:80ef4:1", function() {
2356
2368
  const foo = lynxWorkletImpl._workletMap["da39:80ef4:1"].bind(this);
2357
2369
  "main thread";
2358
2370
  return null;
2359
2371
  });
2360
- __workletRuntimeLoaded && registerWorkletInternal("main-thread", "da39:80ef4:2", function() {
2372
+ __registerWorklet("main-thread", "da39:80ef4:2", function() {
2361
2373
  const bar = lynxWorkletImpl._workletMap["da39:80ef4:2"].bind(this);
2362
2374
  let { foo } = this["_c"];
2363
2375
  "main thread";
@@ -2365,12 +2377,13 @@ console.log(bar)
2365
2377
  });
2366
2378
  "
2367
2379
  `);
2368
- expect((code.match(/registerWorkletInternal/g) ?? []).length).toBe(2);
2369
- expect((code.match(/const __workletRuntimeLoaded = loadWorkletRuntime/g) ?? []).length).toBe(1);
2380
+ expect(runtimeRequirements).toEqual({
2381
+ mainThreadProgrammability: true,
2382
+ });
2370
2383
  });
2371
2384
 
2372
2385
  it('use multiple times', async () => {
2373
- const { code } = await transformReactLynx(
2386
+ const { code, runtimeRequirements } = await transformReactLynx(
2374
2387
  `\
2375
2388
  function getCurrentDelta(event) {
2376
2389
  "main thread";
@@ -2399,16 +2412,14 @@ function getCurrentDelta(event) {
2399
2412
  worklet: {
2400
2413
  target: 'LEPUS',
2401
2414
  filename: '',
2402
- runtimePkg: '@lynx-js/react',
2415
+ runtimePkg: internalWorkletRuntimePkg,
2403
2416
  },
2404
2417
  },
2405
2418
  );
2406
2419
 
2407
2420
  expect(code).toMatchInlineSnapshot(`
2408
- "import { loadWorkletRuntime as __loadWorkletRuntime } from "@lynx-js/react";
2409
- var loadWorkletRuntime = __loadWorkletRuntime;
2410
- const __workletRuntimeLoaded = loadWorkletRuntime(typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry);
2411
- __workletRuntimeLoaded && registerWorkletInternal("main-thread", "da39:059d0:1", function(event) {
2421
+ "import { registerWorklet as __registerWorklet } from "@lynx-js/react/worklet-runtime/init";
2422
+ __registerWorklet("main-thread", "da39:059d0:1", function(event) {
2412
2423
  lynxWorkletImpl._workletMap["da39:059d0:1"].bind(this);
2413
2424
  let { foo, a, b } = this["_c"];
2414
2425
  "main thread";
@@ -2417,8 +2428,115 @@ function getCurrentDelta(event) {
2417
2428
  });
2418
2429
  "
2419
2430
  `);
2420
- expect((code.match(/registerWorkletInternal/g) ?? []).length).toBe(1);
2421
- expect((code.match(/const __workletRuntimeLoaded = loadWorkletRuntime/g) ?? []).length).toBe(1);
2431
+ expect(runtimeRequirements).toEqual({
2432
+ mainThreadProgrammability: true,
2433
+ });
2434
+ });
2435
+
2436
+ it('should use the canonical runtime init request with default worklet options', async () => {
2437
+ const { code, runtimeRequirements } = await transformReactLynx(
2438
+ `\
2439
+ export function foo() {
2440
+ "main thread";
2441
+ }
2442
+ `,
2443
+ {
2444
+ ...lepusWorkletOptions,
2445
+ worklet: true,
2446
+ },
2447
+ );
2448
+
2449
+ expect(
2450
+ (code.match(/from "@lynx-js\/react\/worklet-runtime\/init"/g) ?? []).length,
2451
+ ).toBe(1);
2452
+ expect(code).not.toContain('NoDiff/worklet-runtime/init');
2453
+ expect(runtimeRequirements).toEqual({
2454
+ mainThreadProgrammability: true,
2455
+ });
2456
+ });
2457
+
2458
+ it.each([
2459
+ ['custom-runtime', 'custom-runtime/worklet-runtime/init'],
2460
+ ['custom-runtime/internal', 'custom-runtime/worklet-runtime/init'],
2461
+ ['@custom/react', '@custom/react/worklet-runtime/init'],
2462
+ ['@custom/react/internal', '@custom/react/worklet-runtime/init'],
2463
+ ['@custom/internal-tools/internal', '@custom/internal-tools/worklet-runtime/init'],
2464
+ ['@custom/internal', '@custom/internal/worklet-runtime/init'],
2465
+ ])('should resolve runtime init from %s', async (customRuntimePkg, initRequest) => {
2466
+ const { code, runtimeRequirements } = await transformReactLynx(
2467
+ `\
2468
+ function backgroundFunction() {}
2469
+ export function foo() {
2470
+ "main thread";
2471
+ runOnBackground(backgroundFunction);
2472
+ }
2473
+ `,
2474
+ {
2475
+ ...lepusWorkletOptions,
2476
+ worklet: {
2477
+ target: 'MIXED',
2478
+ filename: '',
2479
+ runtimePkg: customRuntimePkg,
2480
+ },
2481
+ },
2482
+ );
2483
+
2484
+ expect(code.split(`from "${initRequest}";`)).toHaveLength(2);
2485
+ expect(code).not.toContain('@lynx-js/react');
2486
+ expect(code).toContain(
2487
+ `import { transformToWorklet as __transformToWorklet } from "${customRuntimePkg}"`,
2488
+ );
2489
+ expect(runtimeRequirements).toEqual({
2490
+ mainThreadProgrammability: true,
2491
+ });
2492
+ });
2493
+
2494
+ it.each(['@lynx-js/react', '@custom/internal-tools'])(
2495
+ 'should not duplicate an existing runtime init import for %s',
2496
+ async runtimePkg => {
2497
+ const { code, runtimeRequirements } = await transformReactLynx(
2498
+ `\
2499
+ import '${runtimePkg}/worklet-runtime/init';
2500
+ export function foo() {
2501
+ "main thread";
2502
+ }
2503
+ `,
2504
+ {
2505
+ ...lepusWorkletOptions,
2506
+ worklet: {
2507
+ ...lepusWorkletOptions.worklet,
2508
+ runtimePkg: `${runtimePkg}/internal`,
2509
+ },
2510
+ },
2511
+ );
2512
+
2513
+ expect(code.split(`from "${runtimePkg}/worklet-runtime/init";`)).toHaveLength(2);
2514
+ expect(runtimeRequirements).toEqual({
2515
+ mainThreadProgrammability: true,
2516
+ });
2517
+ },
2518
+ );
2519
+
2520
+ it('should reset runtime requirements between transforms', async () => {
2521
+ const withMainThreadUnit = await transformReactLynx(
2522
+ `\
2523
+ export function foo() {
2524
+ "main thread";
2525
+ }
2526
+ `,
2527
+ lepusWorkletOptions,
2528
+ );
2529
+ const withoutMainThreadUnit = await transformReactLynx(
2530
+ 'export function foo() {}',
2531
+ lepusWorkletOptions,
2532
+ );
2533
+
2534
+ expect(withMainThreadUnit.runtimeRequirements).toEqual({
2535
+ mainThreadProgrammability: true,
2536
+ });
2537
+ expect(withoutMainThreadUnit.runtimeRequirements).toEqual({
2538
+ mainThreadProgrammability: false,
2539
+ });
2422
2540
  });
2423
2541
 
2424
2542
  it('should keep webpack runtime variables', async () => {
@@ -45,11 +45,9 @@ describe('object method captures', () => {
45
45
  );
46
46
  const functions = new Map();
47
47
  const valueType = new Function(
48
- '__loadWorkletRuntime',
49
- 'registerWorkletInternal',
48
+ '__registerWorklet',
50
49
  `${result.code.replace(/^import .*;$/gm, '').replace(/^export /gm, '')}\nreturn valueType;`,
51
50
  )(
52
- () => true,
53
51
  (_type, id, fn) => functions.set(id, fn),
54
52
  );
55
53
  expect(valueType.create._c).toEqual({ nestedName: 'read' });
@@ -0,0 +1,97 @@
1
+ use rustc_hash::FxHashSet;
2
+ use swc_core::ecma::ast::*;
3
+ use swc_core::ecma::visit::{Visit, VisitWith};
4
+
5
+ #[derive(Default)]
6
+ struct References {
7
+ used: FxHashSet<Id>,
8
+ declared: FxHashSet<Id>,
9
+ }
10
+
11
+ impl Visit for References {
12
+ fn visit_ident(&mut self, ident: &Ident) {
13
+ self.used.insert(ident.to_id());
14
+ }
15
+
16
+ fn visit_binding_ident(&mut self, ident: &BindingIdent) {
17
+ self.declared.insert(ident.to_id());
18
+ }
19
+ }
20
+
21
+ pub fn collect_imports(stmt: &Stmt, imports: &[ImportDecl]) -> Vec<ModuleItem> {
22
+ let mut references = References::default();
23
+ stmt.visit_with(&mut references);
24
+ let mut items = vec![];
25
+ for import in imports {
26
+ if import.type_only {
27
+ continue;
28
+ }
29
+ let mut import = import.clone();
30
+ import.specifiers.retain(|specifier| {
31
+ if matches!(specifier, ImportSpecifier::Named(named) if named.is_type_only) {
32
+ return false;
33
+ }
34
+ let id = specifier.local().to_id();
35
+ references.used.contains(&id) && !references.declared.contains(&id)
36
+ });
37
+ if !import.specifiers.is_empty() {
38
+ items.push(ModuleItem::ModuleDecl(ModuleDecl::Import(import)));
39
+ }
40
+ }
41
+ items
42
+ }
43
+
44
+ #[cfg(test)]
45
+ mod tests {
46
+ use super::*;
47
+ use swc_core::common::DUMMY_SP;
48
+ use swc_core::quote;
49
+
50
+ #[test]
51
+ fn excludes_type_only_unused_and_locally_declared_bindings() {
52
+ let named = |name: &str, is_type_only| {
53
+ ImportSpecifier::Named(ImportNamedSpecifier {
54
+ span: DUMMY_SP,
55
+ local: Ident::new_no_ctxt(name.into(), DUMMY_SP),
56
+ imported: None,
57
+ is_type_only,
58
+ })
59
+ };
60
+ let import = ImportDecl {
61
+ span: DUMMY_SP,
62
+ phase: ImportPhase::Evaluation,
63
+ specifiers: vec![named("needed", false)],
64
+ src: Box::new("./values.js".into()),
65
+ type_only: false,
66
+ with: None,
67
+ };
68
+ let stmt = quote!("function handler(captured) { return [needed, captured]; }" as Stmt);
69
+ let collected = collect_imports(
70
+ &stmt,
71
+ &[
72
+ ImportDecl {
73
+ type_only: true,
74
+ ..import.clone()
75
+ },
76
+ ImportDecl {
77
+ specifiers: vec![named("needed", true)],
78
+ ..import.clone()
79
+ },
80
+ ImportDecl {
81
+ specifiers: vec![
82
+ named("needed", false),
83
+ named("captured", false),
84
+ named("unused", false),
85
+ ],
86
+ ..import
87
+ },
88
+ ],
89
+ );
90
+ assert_eq!(collected.len(), 1);
91
+ let ModuleItem::ModuleDecl(ModuleDecl::Import(import)) = &collected[0] else {
92
+ panic!("expected a dependency import");
93
+ };
94
+ assert_eq!(import.specifiers.len(), 1);
95
+ assert_eq!(import.specifiers[0].local().sym, "needed");
96
+ }
97
+ }
@@ -47,7 +47,8 @@ struct RegisterWorkletParams<'a> {
47
47
  hash: Expr,
48
48
  is_class_member: bool,
49
49
  named_imports: &'a mut HashSet<String>,
50
- worklet_runtime_loaded_ident: Ident,
50
+ requires_main_thread_runtime: &'a mut bool,
51
+ register_worklet: &'a Ident,
51
52
  }
52
53
 
53
54
  impl StmtGen {
@@ -62,7 +63,8 @@ impl StmtGen {
62
63
  ident_collector: &mut ExtractingIdentsCollector,
63
64
  is_class_member: bool,
64
65
  named_imports: &mut HashSet<String>,
65
- worklet_runtime_loaded_ident: Ident,
66
+ requires_main_thread_runtime: &mut bool,
67
+ register_worklet: &Ident,
66
68
  collect_main_thread: bool,
67
69
  ) -> (Box<Expr>, Stmt, Option<Stmt>) {
68
70
  let hash = Expr::Lit(hash.into());
@@ -80,19 +82,26 @@ impl StmtGen {
80
82
  let extracted_js_fns = ident_collector.take_js_fns();
81
83
 
82
84
  let main_thread_stmt = collect_main_thread.then(|| {
85
+ // The injected definition passes through the main-thread transform again.
86
+ // Its function is already lowered; do not leave an authored directive
87
+ // that could turn an anonymous registration into a second worklet.
88
+ let mut collected_function = function.clone();
89
+ collected_function.body.as_mut().unwrap().stmts.remove(0);
83
90
  let mut collected_imports = HashSet::new();
91
+ let mut collected_runtime_requirement = false;
84
92
  StmtGen::gen_register_worklet_stmt(RegisterWorkletParams {
85
93
  mode,
86
94
  target: TransformTarget::LEPUS,
87
95
  worklet_type: worklet_type.clone(),
88
96
  function_name: function_name.clone(),
89
- function: function.clone(),
97
+ function: collected_function,
90
98
  extracted_idents: extracted_idents.clone(),
91
99
  extracted_js_fns: extracted_js_fns.clone(),
92
100
  hash: hash.clone(),
93
101
  is_class_member,
94
102
  named_imports: &mut collected_imports,
95
- worklet_runtime_loaded_ident: worklet_runtime_loaded_ident.clone(),
103
+ requires_main_thread_runtime: &mut collected_runtime_requirement,
104
+ register_worklet,
96
105
  })
97
106
  });
98
107
 
@@ -124,7 +133,8 @@ impl StmtGen {
124
133
  hash,
125
134
  is_class_member,
126
135
  named_imports,
127
- worklet_runtime_loaded_ident,
136
+ requires_main_thread_runtime,
137
+ register_worklet,
128
138
  }),
129
139
  main_thread_stmt,
130
140
  )
@@ -407,7 +417,8 @@ impl StmtGen {
407
417
  hash,
408
418
  is_class_member,
409
419
  named_imports,
410
- worklet_runtime_loaded_ident,
420
+ requires_main_thread_runtime,
421
+ register_worklet,
411
422
  } = params;
412
423
 
413
424
  let function_to_register = Box::new(StmtGen::gen_function_to_register(
@@ -420,16 +431,21 @@ impl StmtGen {
420
431
  ));
421
432
 
422
433
  if target == TransformTarget::LEPUS {
423
- named_imports.insert("loadWorkletRuntime".into());
424
- quote!("$loaded && registerWorkletInternal($type_, $hash, $fn_)" as Stmt,
425
- loaded: Expr = Expr::Ident(worklet_runtime_loaded_ident.clone()),
434
+ *requires_main_thread_runtime = true;
435
+ let registration = quote_expr!("$register($type_, $hash, $fn_)",
436
+ register: Ident = register_worklet.clone(),
426
437
  type_: Expr = Expr::Lit(worklet_type.type_str().into()),
427
438
  hash: Expr = hash,
428
439
  fn_: Expr = Expr::Fn(FnExpr {
429
440
  ident: None,
430
441
  function: function_to_register,
431
442
  }),
432
- )
443
+ );
444
+ ExprStmt {
445
+ span: DUMMY_SP,
446
+ expr: registration,
447
+ }
448
+ .into()
433
449
  } else if mode == TransformMode::Development {
434
450
  named_imports.insert("registerWorkletOnBackground".into());
435
451
  quote!("registerWorkletOnBackground($type_, $hash, $fn_)" as Stmt,