@lynx-js/react 0.126.2 → 0.128.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 (425) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/docs/directives.md +90 -0
  4. package/docs/global-events.md +50 -0
  5. package/docs/import-attributes.md +43 -0
  6. package/docs/macros.md +285 -0
  7. package/package.json +7 -14
  8. package/refresh/.turbo/turbo-build.log +2 -2
  9. package/refresh/dist/index.js +26 -6
  10. package/refresh/package.json +1 -1
  11. package/runtime/__test__/core/main-thread-object.test.js +149 -0
  12. package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +26 -3
  13. package/runtime/__test__/element-template/imports/main-thread-object-api.test.ts +10 -0
  14. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +4 -1
  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 +11 -9
  17. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -3
  18. package/runtime/__test__/element-template/test-utils/mock/globals.js +6 -0
  19. package/runtime/__test__/element-template/vitest.config.ts +4 -0
  20. package/runtime/__test__/snapshot/ctxNotFound.test.ts +271 -0
  21. package/runtime/__test__/snapshot/event.test.jsx +7 -7
  22. package/runtime/__test__/snapshot/lazy.test.js +73 -1
  23. package/runtime/__test__/snapshot/lynx/portals.test.jsx +75 -37
  24. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +59 -47
  25. package/runtime/__test__/snapshot/spread.test.jsx +10 -10
  26. package/runtime/__test__/snapshot/worklet/main-thread-object.test.jsx +306 -0
  27. package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +1 -0
  28. package/runtime/__test__/worklet-runtime/initEntry.test.js +109 -0
  29. package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +182 -0
  30. package/runtime/__test__/worklet-runtime/object-methods.test.js +59 -0
  31. package/runtime/__test__/worklet-runtime/workletRef.test.js +362 -2
  32. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +246 -1
  33. package/runtime/lazy/compat.js +2 -0
  34. package/runtime/lazy/element-template-internal.js +1 -1
  35. package/runtime/lazy/element-template.js +2 -0
  36. package/runtime/lazy/internal.js +2 -1
  37. package/runtime/lazy/react.js +2 -0
  38. package/runtime/lib/core/background-function/exec-map.js.map +1 -1
  39. package/runtime/lib/core/background-function/handle.js.map +1 -1
  40. package/runtime/lib/core/background-function/run-on-background.d.ts +16 -0
  41. package/runtime/lib/core/background-function/run-on-background.js +16 -0
  42. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  43. package/runtime/lib/core/capture-main-thread-object.d.ts +1 -0
  44. package/runtime/lib/core/capture-main-thread-object.js +16 -0
  45. package/runtime/lib/core/capture-main-thread-object.js.map +1 -0
  46. package/runtime/lib/core/commit-context.js.map +1 -1
  47. package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
  48. package/runtime/lib/core/compat/lynxComponent.js.map +1 -1
  49. package/runtime/lib/core/component.js.map +1 -1
  50. package/runtime/lib/core/forceRootRender.js.map +1 -1
  51. package/runtime/lib/core/globalProps.d.ts +2 -0
  52. package/runtime/lib/core/globalProps.js.map +1 -1
  53. package/runtime/lib/core/hooks/mainThread.js.map +1 -1
  54. package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
  55. package/runtime/lib/core/hooks/react.d.ts +4 -0
  56. package/runtime/lib/core/hooks/react.js +4 -0
  57. package/runtime/lib/core/hooks/react.js.map +1 -1
  58. package/runtime/lib/core/hooks/useLynxGlobalEventListener.d.ts +2 -0
  59. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +2 -0
  60. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
  61. package/runtime/lib/core/initData.d.ts +2 -0
  62. package/runtime/lib/core/initData.js +2 -0
  63. package/runtime/lib/core/initData.js.map +1 -1
  64. package/runtime/lib/core/lynx/dynamic-import.js.map +1 -1
  65. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  66. package/runtime/lib/core/lynx/runtime-backend.js.map +1 -1
  67. package/runtime/lib/core/lynx/runtime-version.js.map +1 -1
  68. package/runtime/lib/core/lynx-data-processors.js.map +1 -1
  69. package/runtime/lib/core/lynx-page-data.js.map +1 -1
  70. package/runtime/lib/core/lynx-update-data.js.map +1 -1
  71. package/runtime/lib/core/main-thread-function.js.map +1 -1
  72. package/runtime/lib/core/main-thread-object-handle-registry.d.ts +3 -0
  73. package/runtime/lib/core/main-thread-object-handle-registry.js +17 -0
  74. package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -0
  75. package/runtime/lib/core/main-thread-object.d.ts +77 -0
  76. package/runtime/lib/core/main-thread-object.js +258 -0
  77. package/runtime/lib/core/main-thread-object.js.map +1 -0
  78. package/runtime/lib/core/main-thread-ref-id.d.ts +1 -0
  79. package/runtime/lib/core/main-thread-ref-id.js +14 -0
  80. package/runtime/lib/core/main-thread-ref-id.js.map +1 -0
  81. package/runtime/lib/core/main-thread-ref-init-value.d.ts +1 -1
  82. package/runtime/lib/core/main-thread-ref-init-value.js +4 -2
  83. package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
  84. package/runtime/lib/core/main-thread-ref.d.ts +4 -0
  85. package/runtime/lib/core/main-thread-ref.js +5 -8
  86. package/runtime/lib/core/main-thread-ref.js.map +1 -1
  87. package/runtime/lib/core/mts-capability.js.map +1 -1
  88. package/runtime/lib/core/performance.js.map +1 -1
  89. package/runtime/lib/core/ref.js.map +1 -1
  90. package/runtime/lib/core/reload-version.js.map +1 -1
  91. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  92. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  93. package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
  94. package/runtime/lib/document.js.map +1 -1
  95. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  96. package/runtime/lib/element-template/background/commit-context.js.map +1 -1
  97. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  98. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  99. package/runtime/lib/element-template/background/document.js.map +1 -1
  100. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  101. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  102. package/runtime/lib/element-template/background/instance.js.map +1 -1
  103. package/runtime/lib/element-template/background/manager.js.map +1 -1
  104. package/runtime/lib/element-template/background/page-root-hydrate.js.map +1 -1
  105. package/runtime/lib/element-template/background/render-scope.js.map +1 -1
  106. package/runtime/lib/element-template/client/root.js.map +1 -1
  107. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  108. package/runtime/lib/element-template/debug/elementPAPICall.js.map +1 -1
  109. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  110. package/runtime/lib/element-template/hydration-map.js.map +1 -1
  111. package/runtime/lib/element-template/index.d.ts +2 -0
  112. package/runtime/lib/element-template/index.js +1 -0
  113. package/runtime/lib/element-template/index.js.map +1 -1
  114. package/runtime/lib/element-template/internal.d.ts +1 -1
  115. package/runtime/lib/element-template/internal.js +1 -1
  116. package/runtime/lib/element-template/internal.js.map +1 -1
  117. package/runtime/lib/element-template/jsx-dev-runtime/index.js.map +1 -1
  118. package/runtime/lib/element-template/jsx-runtime/index.js.map +1 -1
  119. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  120. package/runtime/lib/element-template/lynx/performance.js.map +1 -1
  121. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
  122. package/runtime/lib/element-template/native/index.js.map +1 -1
  123. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  124. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  125. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  126. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  127. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  128. package/runtime/lib/element-template/prop-adapters/event-value.js.map +1 -1
  129. package/runtime/lib/element-template/prop-adapters/event.js.map +1 -1
  130. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
  131. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  132. package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
  133. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  134. package/runtime/lib/element-template/protocol/page.js.map +1 -1
  135. package/runtime/lib/element-template/protocol/template-type.js.map +1 -1
  136. package/runtime/lib/element-template/protocol/types.d.ts +1 -1
  137. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  138. package/runtime/lib/element-template/protocol/update-event.js.map +1 -1
  139. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  140. package/runtime/lib/element-template/runtime/page/authored-page.js.map +1 -1
  141. package/runtime/lib/element-template/runtime/page/page.js.map +1 -1
  142. package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
  143. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  144. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
  145. package/runtime/lib/element-template/runtime/render/host.js.map +1 -1
  146. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  147. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
  148. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  149. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  150. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  151. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  152. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  153. package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js.map +1 -1
  154. package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +1 -1
  155. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  156. package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
  157. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  158. package/runtime/lib/element-template/runtime-marker.js.map +1 -1
  159. package/runtime/lib/index.js.map +1 -1
  160. package/runtime/lib/internal.d.ts +1 -1
  161. package/runtime/lib/internal.js +1 -1
  162. package/runtime/lib/internal.js.map +1 -1
  163. package/runtime/lib/lynx-api.d.ts +34 -0
  164. package/runtime/lib/lynx-api.js +21 -0
  165. package/runtime/lib/lynx-api.js.map +1 -1
  166. package/runtime/lib/lynx.js +4 -1
  167. package/runtime/lib/lynx.js.map +1 -1
  168. package/runtime/lib/root.js.map +1 -1
  169. package/runtime/lib/runtime-marker.js.map +1 -1
  170. package/runtime/lib/shared/attribute-name.js.map +1 -1
  171. package/runtime/lib/shared/component-stack.js.map +1 -1
  172. package/runtime/lib/shared/index-map.js.map +1 -1
  173. package/runtime/lib/shared/profile.js.map +1 -1
  174. package/runtime/lib/shared/render-constants.js.map +1 -1
  175. package/runtime/lib/snapshot/alog/elementPAPICall.js.map +1 -1
  176. package/runtime/lib/snapshot/alog/index.js.map +1 -1
  177. package/runtime/lib/snapshot/alog/render.js.map +1 -1
  178. package/runtime/lib/snapshot/compat/componentIs.js.map +1 -1
  179. package/runtime/lib/snapshot/debug/debug.js.map +1 -1
  180. package/runtime/lib/snapshot/debug/describeInvalidValue.js.map +1 -1
  181. package/runtime/lib/snapshot/debug/formatPatch.js.map +1 -1
  182. package/runtime/lib/snapshot/debug/printSnapshot.js.map +1 -1
  183. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  184. package/runtime/lib/snapshot/debug/vnodeSource.js.map +1 -1
  185. package/runtime/lib/snapshot/gesture/processGesture.js.map +1 -1
  186. package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +1 -1
  187. package/runtime/lib/snapshot/gesture/types.js.map +1 -1
  188. package/runtime/lib/snapshot/index.js.map +1 -1
  189. package/runtime/lib/snapshot/lifecycle/constant.js.map +1 -1
  190. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  191. package/runtime/lib/snapshot/lifecycle/event/delayEvents.js.map +1 -1
  192. package/runtime/lib/snapshot/lifecycle/event/delayLifecycleEvents.js.map +1 -1
  193. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
  194. package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
  195. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  196. package/runtime/lib/snapshot/lifecycle/patch/error.d.ts +11 -1
  197. package/runtime/lib/snapshot/lifecycle/patch/error.js +24 -16
  198. package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
  199. package/runtime/lib/snapshot/lifecycle/patch/globalState.js.map +1 -1
  200. package/runtime/lib/snapshot/lifecycle/patch/isMainThreadHydrating.js.map +1 -1
  201. package/runtime/lib/snapshot/lifecycle/patch/nodesRefApply.js.map +1 -1
  202. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
  203. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.d.ts +1 -1
  204. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +29 -7
  205. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  206. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +2 -2
  207. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  208. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  209. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  210. package/runtime/lib/snapshot/lifecycle/render.js.map +1 -1
  211. package/runtime/lib/snapshot/list/list.js.map +1 -1
  212. package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
  213. package/runtime/lib/snapshot/list/pendingListUpdates.js.map +1 -1
  214. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  215. package/runtime/lib/snapshot/lynx/children.d.ts +2 -0
  216. package/runtime/lib/snapshot/lynx/children.js.map +1 -1
  217. package/runtime/lib/snapshot/lynx/element.d.ts +8 -0
  218. package/runtime/lib/snapshot/lynx/element.js +4 -0
  219. package/runtime/lib/snapshot/lynx/element.js.map +1 -1
  220. package/runtime/lib/snapshot/lynx/env.js.map +1 -1
  221. package/runtime/lib/snapshot/lynx/injectLepusMethods.js.map +1 -1
  222. package/runtime/lib/snapshot/lynx/lazyBundleConstants.js.map +1 -1
  223. package/runtime/lib/snapshot/lynx/nodesRef.js.map +1 -1
  224. package/runtime/lib/snapshot/lynx/performance.js.map +1 -1
  225. package/runtime/lib/snapshot/lynx/portals.js.map +1 -1
  226. package/runtime/lib/snapshot/lynx/portalsPending.js.map +1 -1
  227. package/runtime/lib/snapshot/lynx/prepareLazyBundleMTS.js.map +1 -1
  228. package/runtime/lib/snapshot/lynx/runWithForce.js.map +1 -1
  229. package/runtime/lib/snapshot/lynx/suspense.js.map +1 -1
  230. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  231. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  232. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  233. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  234. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  235. package/runtime/lib/snapshot/snapshot/constants.js.map +1 -1
  236. package/runtime/lib/snapshot/snapshot/definition.js.map +1 -1
  237. package/runtime/lib/snapshot/snapshot/dynamicPartType.js.map +1 -1
  238. package/runtime/lib/snapshot/snapshot/event.js.map +1 -1
  239. package/runtime/lib/snapshot/snapshot/gesture.js.map +1 -1
  240. package/runtime/lib/snapshot/snapshot/index.js.map +1 -1
  241. package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
  242. package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
  243. package/runtime/lib/snapshot/snapshot/reconstructInstanceTree.js.map +1 -1
  244. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  245. package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
  246. package/runtime/lib/snapshot/snapshot/snapshotCreatorMap.js.map +1 -1
  247. package/runtime/lib/snapshot/snapshot/snapshotInstanceHydrationMap.js.map +1 -1
  248. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
  249. package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
  250. package/runtime/lib/snapshot/snapshot/types.js.map +1 -1
  251. package/runtime/lib/snapshot/snapshot/utils.js.map +1 -1
  252. package/runtime/lib/snapshot/snapshot/workletEvent.js.map +1 -1
  253. package/runtime/lib/snapshot/snapshot/workletRef.js.map +1 -1
  254. package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +2 -0
  255. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +2 -0
  256. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  257. package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
  258. package/runtime/lib/snapshot/worklet/destroy.js.map +1 -1
  259. package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
  260. package/runtime/lib/snapshot/worklet/hmr.js.map +1 -1
  261. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
  262. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  263. package/runtime/lib/utils.js.map +1 -1
  264. package/runtime/lib/worklet-runtime/api/animation/animation.js.map +1 -1
  265. package/runtime/lib/worklet-runtime/api/animation/effect.js.map +1 -1
  266. package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
  267. package/runtime/lib/worklet-runtime/api/lepusQuerySelector.js.map +1 -1
  268. package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
  269. package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -3
  270. package/runtime/lib/worklet-runtime/bindings/bindings.js +9 -1
  271. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  272. package/runtime/lib/worklet-runtime/bindings/events.js.map +1 -1
  273. package/runtime/lib/worklet-runtime/bindings/index.d.ts +0 -1
  274. package/runtime/lib/worklet-runtime/bindings/index.js +0 -1
  275. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
  276. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  277. package/runtime/lib/worklet-runtime/bindings/types.d.ts +3 -6
  278. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
  279. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
  280. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
  281. package/runtime/lib/worklet-runtime/eomImpl.js.map +1 -1
  282. package/runtime/lib/worklet-runtime/eventPropagation.js.map +1 -1
  283. package/runtime/lib/worklet-runtime/global.js.map +1 -1
  284. package/runtime/lib/worklet-runtime/hydrate.js +26 -7
  285. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  286. package/runtime/lib/worklet-runtime/index.js +6 -0
  287. package/runtime/lib/worklet-runtime/index.js.map +1 -1
  288. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  289. package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
  290. package/runtime/lib/worklet-runtime/mainThreadObject.d.ts +8 -0
  291. package/runtime/lib/worklet-runtime/mainThreadObject.js +67 -0
  292. package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -0
  293. package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
  294. package/runtime/lib/worklet-runtime/utils/mainThreadFlushLoopGuard.js.map +1 -1
  295. package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
  296. package/runtime/lib/worklet-runtime/utils/version.js.map +1 -1
  297. package/runtime/lib/worklet-runtime/workletRef.d.ts +11 -7
  298. package/runtime/lib/worklet-runtime/workletRef.js +72 -9
  299. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
  300. package/runtime/lib/worklet-runtime/workletRuntime.js +68 -9
  301. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  302. package/runtime/package.json +2 -3
  303. package/runtime/src/core/background-function/run-on-background.ts +16 -0
  304. package/runtime/src/core/capture-main-thread-object.ts +17 -0
  305. package/runtime/src/core/globalProps.ts +2 -0
  306. package/runtime/src/core/hooks/react.ts +4 -0
  307. package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +2 -0
  308. package/runtime/src/core/initData.ts +2 -0
  309. package/runtime/src/core/main-thread-object-handle-registry.ts +25 -0
  310. package/runtime/src/core/main-thread-object.ts +380 -0
  311. package/runtime/src/core/main-thread-ref-id.ts +16 -0
  312. package/runtime/src/core/main-thread-ref-init-value.ts +12 -4
  313. package/runtime/src/core/main-thread-ref.ts +7 -8
  314. package/runtime/src/element-template/background/commit-hook.ts +1 -1
  315. package/runtime/src/element-template/index.ts +6 -0
  316. package/runtime/src/element-template/internal.ts +2 -1
  317. package/runtime/src/element-template/protocol/types.ts +1 -1
  318. package/runtime/src/internal.ts +1 -1
  319. package/runtime/src/lynx-api.ts +38 -0
  320. package/runtime/src/lynx.ts +5 -1
  321. package/runtime/src/snapshot/lifecycle/patch/error.ts +36 -19
  322. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +29 -7
  323. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +2 -2
  324. package/runtime/src/snapshot/lynx/children.ts +2 -0
  325. package/runtime/src/snapshot/lynx/element.ts +8 -0
  326. package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +2 -0
  327. package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +1 -1
  328. package/runtime/src/worklet-runtime/bindings/bindings.ts +17 -2
  329. package/runtime/src/worklet-runtime/bindings/index.ts +0 -1
  330. package/runtime/src/worklet-runtime/bindings/types.ts +7 -11
  331. package/runtime/src/worklet-runtime/hydrate.ts +43 -10
  332. package/runtime/src/worklet-runtime/index.ts +7 -0
  333. package/runtime/src/worklet-runtime/mainThreadObject.ts +117 -0
  334. package/runtime/src/worklet-runtime/workletRef.ts +120 -19
  335. package/runtime/src/worklet-runtime/workletRuntime.ts +83 -11
  336. package/runtime/tsconfig.json +2 -0
  337. package/runtime/vitest.config.ts +4 -0
  338. package/testing-library/.turbo/turbo-build.log +11 -11
  339. package/testing-library/dist/env/index.js +3 -15
  340. package/testing-library/dist/index.d.ts +165 -2
  341. package/testing-library/dist/plugins/index.js +10 -0
  342. package/testing-library/dist/rstest-config.js +15 -0
  343. package/testing-library/dist/setupFiles/common/worklet-runtime-init.js +11 -0
  344. package/testing-library/package.json +2 -1
  345. package/testing-library/rstest.config.ts +3 -0
  346. package/testing-library/src/__tests__/lynx.test.jsx +1 -1
  347. package/testing-library/src/__tests__/rstest-config.test.js +34 -1
  348. package/testing-library/src/__tests__/worklet.test.jsx +87 -33
  349. package/testing-library/src/plugins/vitest.ts +5 -1
  350. package/testing-library/src/rstest-config.ts +17 -1
  351. package/testing-library/src/setupFiles/common/worklet-runtime-init.js +22 -0
  352. package/testing-library/tsconfig.docs.json +9 -0
  353. package/testing-library/typedoc.json +22 -0
  354. package/transform/.turbo/turbo-build$colon$wasm.log +135 -73
  355. package/transform/__test__/defines.spec.js +80 -12
  356. package/transform/__test__/fixture.spec.js +231 -71
  357. package/transform/__test__/object-methods.spec.js +82 -0
  358. package/transform/crates/swc_plugin_worklet/decl_collect.rs +10 -0
  359. package/transform/crates/swc_plugin_worklet/extract_ident.rs +14 -0
  360. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +228 -13
  361. package/transform/crates/swc_plugin_worklet/lib.rs +599 -150
  362. package/transform/crates/swc_plugin_worklet/napi.rs +10 -1
  363. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +8 -1
  364. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +12 -7
  365. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_js.js +27 -0
  366. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +43 -0
  367. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_lepus.js +2 -4
  368. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +16 -14
  369. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +18 -18
  370. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_lepus.js +3 -5
  371. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_lepus.js +2 -4
  372. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +7 -5
  373. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +9 -9
  374. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +22 -0
  375. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_globals.js +2 -4
  376. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +14 -0
  377. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_type_annotations.js +2 -4
  378. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_destructure_from_closure.js +2 -4
  379. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_catch_clause_params.js +2 -4
  380. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_idents_inside_of_ctx.js +2 -4
  381. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_recursively.js +2 -4
  382. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +42 -0
  383. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +58 -0
  384. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js +2 -4
  385. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_arrow_function.js +2 -4
  386. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_lepus.js +2 -4
  387. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_function_expr.js +2 -4
  388. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_lepus.js +2 -4
  389. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_lepus.js +2 -4
  390. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_lepus.js +2 -4
  391. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_lepus.js +2 -4
  392. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +3 -1
  393. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_lepus.js +2 -4
  394. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +5 -5
  395. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_alias.js +2 -4
  396. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general.js +2 -4
  397. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general_mixed.js +2 -4
  398. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets.js +3 -5
  399. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets_in_func.js +3 -5
  400. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_js.js +9 -0
  401. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +14 -0
  402. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_lepus.js +2 -4
  403. package/transform/dist/wasm.cjs +1 -1
  404. package/transform/index.d.ts +25 -1
  405. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
  406. package/transform/src/lib.rs +193 -23
  407. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +63 -467
  408. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  409. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +340 -28
  410. package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
  411. package/transform/vitest.config.ts +5 -1
  412. package/types/react.docs.d.ts +130 -11
  413. package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +0 -8
  414. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +0 -23
  415. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +0 -1
  416. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +0 -25
  417. package/runtime/worklet-runtime/dev.js +0 -638
  418. package/runtime/worklet-runtime/main.js +0 -1
  419. package/testing-library/node_modules/.bin/rsbuild +0 -68
  420. package/testing-library/node_modules/.bin/rspeedy +0 -68
  421. package/testing-library/node_modules/.bin/rstest +0 -68
  422. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_inner_ident.js +0 -13
  423. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_outer_ident.js +0 -13
  424. package/transform/node_modules/.bin/esbuild +0 -59
  425. package/transform/node_modules/.bin/napi +0 -68
@@ -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
  );
@@ -1997,6 +2010,46 @@ export function bar() {
1997
2010
  );
1998
2011
  });
1999
2012
 
2013
+ it('should error when an object Main Thread Function uses super', async () => {
2014
+ const result = await transformReactLynx(
2015
+ `\
2016
+ const valueType = defineMainThreadObjectType({
2017
+ type: 'example',
2018
+ create() {
2019
+ "main thread";
2020
+ return super.create();
2021
+ },
2022
+ });
2023
+ `,
2024
+ lepusWorkletOptions,
2025
+ );
2026
+
2027
+ expect(result.errors.map((error) => error.text)).toContain(
2028
+ '`super` is not supported in Main Thread object methods.',
2029
+ );
2030
+ });
2031
+
2032
+ it('should not reject super in a nested object method', async () => {
2033
+ const result = await transformReactLynx(
2034
+ `\
2035
+ const valueType = defineMainThreadObjectType({
2036
+ type: 'example',
2037
+ create() {
2038
+ "main thread";
2039
+ return {
2040
+ nested() {
2041
+ return super.create();
2042
+ },
2043
+ };
2044
+ },
2045
+ });
2046
+ `,
2047
+ lepusWorkletOptions,
2048
+ );
2049
+
2050
+ expect(result.errors).toEqual([]);
2051
+ });
2052
+
2000
2053
  it('should error on non-string runtime import attribute', async () => {
2001
2054
  const result = await transformReactLynx(
2002
2055
  `\
@@ -2025,7 +2078,7 @@ export function bar() {
2025
2078
  worklet: {
2026
2079
  target: 'LEPUS',
2027
2080
  filename: '',
2028
- runtimePkg: '@lynx-js/react',
2081
+ runtimePkg: internalWorkletRuntimePkg,
2029
2082
  },
2030
2083
  },
2031
2084
  );
@@ -2064,7 +2117,7 @@ export function bar() {
2064
2117
  worklet: {
2065
2118
  target: 'LEPUS',
2066
2119
  filename: '',
2067
- runtimePkg: '@lynx-js/react',
2120
+ runtimePkg: internalWorkletRuntimePkg,
2068
2121
  },
2069
2122
  },
2070
2123
  );
@@ -2076,7 +2129,7 @@ export function bar() {
2076
2129
  });
2077
2130
 
2078
2131
  it('should not inject runtime when no worklet exists', async () => {
2079
- const { code } = await transformReactLynx(
2132
+ const { code, runtimeRequirements } = await transformReactLynx(
2080
2133
  `\
2081
2134
  export function getCurrentDelta(event) {
2082
2135
  return foo.bar.baz;
@@ -2085,14 +2138,17 @@ export function getCurrentDelta(event) {
2085
2138
  lepusWorkletOptions,
2086
2139
  );
2087
2140
 
2088
- expect(code).not.toContain('loadWorkletRuntime');
2141
+ expect(code).not.toContain('@lynx-js/react/worklet-runtime/init');
2089
2142
  expect(code).not.toContain('registerWorkletInternal');
2090
2143
  expect(code).not.toContain('_wkltId');
2144
+ expect(runtimeRequirements).toEqual({
2145
+ mainThreadProgrammability: false,
2146
+ });
2091
2147
  });
2092
2148
 
2093
2149
  for (const target of ['LEPUS', 'JS', 'MIXED']) {
2094
2150
  it('member expression', async () => {
2095
- const { code } = await transformReactLynx(
2151
+ const { code, runtimeRequirements } = await transformReactLynx(
2096
2152
  `\
2097
2153
  export function getCurrentDelta(event) {
2098
2154
  "main thread";
@@ -2118,27 +2174,27 @@ export function getCurrentDelta(event) {
2118
2174
  worklet: {
2119
2175
  target,
2120
2176
  filename: '',
2121
- runtimePkg: '@lynx-js/react',
2177
+ runtimePkg: internalWorkletRuntimePkg,
2122
2178
  },
2123
2179
  },
2124
2180
  );
2125
2181
 
2126
2182
  if (target === 'LEPUS') {
2127
2183
  expect(code).toMatchInlineSnapshot(`
2128
- "import { loadWorkletRuntime as __loadWorkletRuntime } from "@lynx-js/react";
2129
- var 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;
2130
2187
  export let getCurrentDelta = {
2131
2188
  _c: {
2132
- foo: {
2133
- bar: {
2134
- baz: foo.bar.baz
2135
- }
2189
+ foo: captureMainThreadObject(foo) ?? {
2190
+ bar: ((__mainThreadObjectSource)=>captureMainThreadObject(__mainThreadObjectSource) ?? {
2191
+ baz: __mainThreadObjectSource.baz
2192
+ })(foo.bar)
2136
2193
  }
2137
2194
  },
2138
2195
  _wkltId: "da39:75a1b:1"
2139
2196
  };
2140
- const __workletRuntimeLoaded = loadWorkletRuntime(typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry);
2141
- __workletRuntimeLoaded && registerWorkletInternal("main-thread", "da39:75a1b:1", function(event) {
2197
+ __registerWorklet("main-thread", "da39:75a1b:1", function(event) {
2142
2198
  const getCurrentDelta = lynxWorkletImpl._workletMap["da39:75a1b:1"].bind(this);
2143
2199
  let { foo } = this["_c"];
2144
2200
  "main thread";
@@ -2146,40 +2202,38 @@ export function getCurrentDelta(event) {
2146
2202
  });
2147
2203
  "
2148
2204
  `);
2149
- expect(code).toContain('loadWorkletRuntime');
2150
- expect(code).toContain('registerWorkletInternal("main-thread"');
2151
2205
  } else if (target === 'JS') {
2152
2206
  expect(code).toMatchInlineSnapshot(`
2153
- "export let getCurrentDelta = {
2207
+ "import { captureMainThreadObject as __captureMainThreadObject } from "@lynx-js/react/internal";
2208
+ var captureMainThreadObject = __captureMainThreadObject;
2209
+ export let getCurrentDelta = {
2154
2210
  _c: {
2155
- foo: {
2156
- bar: {
2157
- baz: foo.bar.baz
2158
- }
2211
+ foo: captureMainThreadObject(foo) ?? {
2212
+ bar: ((__mainThreadObjectSource)=>captureMainThreadObject(__mainThreadObjectSource) ?? {
2213
+ baz: __mainThreadObjectSource.baz
2214
+ })(foo.bar)
2159
2215
  }
2160
2216
  },
2161
2217
  _wkltId: "da39:75a1b:1"
2162
2218
  };
2163
2219
  "
2164
2220
  `);
2165
- expect(code).not.toContain('loadWorkletRuntime');
2166
- expect(code).not.toContain('registerWorkletInternal');
2167
2221
  } else if (target === 'MIXED') {
2168
2222
  expect(code).toMatchInlineSnapshot(`
2169
- "import { loadWorkletRuntime as __loadWorkletRuntime } from "@lynx-js/react";
2170
- var 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;
2171
2226
  export let getCurrentDelta = {
2172
2227
  _c: {
2173
- foo: {
2174
- bar: {
2175
- baz: foo.bar.baz
2176
- }
2228
+ foo: captureMainThreadObject(foo) ?? {
2229
+ bar: ((__mainThreadObjectSource)=>captureMainThreadObject(__mainThreadObjectSource) ?? {
2230
+ baz: __mainThreadObjectSource.baz
2231
+ })(foo.bar)
2177
2232
  }
2178
2233
  },
2179
2234
  _wkltId: "da39:75a1b:1"
2180
2235
  };
2181
- const __workletRuntimeLoaded = loadWorkletRuntime(typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry);
2182
- __workletRuntimeLoaded && registerWorkletInternal("main-thread", "da39:75a1b:1", function(event) {
2236
+ __registerWorklet("main-thread", "da39:75a1b:1", function(event) {
2183
2237
  const getCurrentDelta = lynxWorkletImpl._workletMap["da39:75a1b:1"].bind(this);
2184
2238
  let { foo } = this["_c"];
2185
2239
  "main thread";
@@ -2187,14 +2241,15 @@ export function getCurrentDelta(event) {
2187
2241
  });
2188
2242
  "
2189
2243
  `);
2190
- expect(code).toContain('loadWorkletRuntime');
2191
- expect(code).toContain('registerWorkletInternal("main-thread"');
2192
2244
  }
2245
+ expect(runtimeRequirements).toEqual({
2246
+ mainThreadProgrammability: target !== 'JS',
2247
+ });
2193
2248
  });
2194
2249
  }
2195
2250
 
2196
2251
  it('member expression with multiple times', async () => {
2197
- const { code } = await transformReactLynx(
2252
+ const { code, runtimeRequirements } = await transformReactLynx(
2198
2253
  `\
2199
2254
  export function foo(event) {
2200
2255
  "main thread";
@@ -2220,34 +2275,34 @@ export function foo(event) {
2220
2275
  worklet: {
2221
2276
  target: 'LEPUS',
2222
2277
  filename: '',
2223
- runtimePkg: '@lynx-js/react',
2278
+ runtimePkg: internalWorkletRuntimePkg,
2224
2279
  },
2225
2280
  },
2226
2281
  );
2227
2282
 
2228
2283
  expect(code).toMatchInlineSnapshot(`
2229
- "import { loadWorkletRuntime as __loadWorkletRuntime } from "@lynx-js/react";
2230
- var 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;
2231
2287
  export let foo = {
2232
2288
  _c: {
2233
- bar: {
2234
- baz: {
2235
- 'qux': bar.baz['qux']
2236
- },
2237
- qux: {
2238
- 'baz': bar.qux['baz']
2239
- }
2289
+ bar: captureMainThreadObject(bar) ?? {
2290
+ baz: ((__mainThreadObjectSource)=>captureMainThreadObject(__mainThreadObjectSource) ?? {
2291
+ 'qux': __mainThreadObjectSource['qux']
2292
+ })(bar.baz),
2293
+ qux: ((__mainThreadObjectSource)=>captureMainThreadObject(__mainThreadObjectSource) ?? {
2294
+ 'baz': __mainThreadObjectSource['baz']
2295
+ })(bar.qux)
2240
2296
  },
2241
- qux: {
2242
- bar: {
2243
- baz: qux.bar.baz
2244
- }
2297
+ qux: captureMainThreadObject(qux) ?? {
2298
+ bar: ((__mainThreadObjectSource)=>captureMainThreadObject(__mainThreadObjectSource) ?? {
2299
+ baz: __mainThreadObjectSource.baz
2300
+ })(qux.bar)
2245
2301
  }
2246
2302
  },
2247
2303
  _wkltId: "da39:64631:1"
2248
2304
  };
2249
- const __workletRuntimeLoaded = loadWorkletRuntime(typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry);
2250
- __workletRuntimeLoaded && registerWorkletInternal("main-thread", "da39:64631:1", function(event) {
2305
+ __registerWorklet("main-thread", "da39:64631:1", function(event) {
2251
2306
  const foo = lynxWorkletImpl._workletMap["da39:64631:1"].bind(this);
2252
2307
  let { bar, qux } = this["_c"];
2253
2308
  "main thread";
@@ -2255,12 +2310,13 @@ export function foo(event) {
2255
2310
  });
2256
2311
  "
2257
2312
  `);
2258
- expect((code.match(/registerWorkletInternal/g) ?? []).length).toBe(1);
2259
- expect((code.match(/const __workletRuntimeLoaded = loadWorkletRuntime/g) ?? []).length).toBe(1);
2313
+ expect(runtimeRequirements).toEqual({
2314
+ mainThreadProgrammability: true,
2315
+ });
2260
2316
  });
2261
2317
 
2262
2318
  it('nested', async () => {
2263
- const { code } = await transformReactLynx(
2319
+ const { code, runtimeRequirements } = await transformReactLynx(
2264
2320
  `\
2265
2321
  function foo() {
2266
2322
  "main thread";
@@ -2291,14 +2347,13 @@ console.log(bar)
2291
2347
  worklet: {
2292
2348
  target: 'LEPUS',
2293
2349
  filename: '',
2294
- runtimePkg: '@lynx-js/react',
2350
+ runtimePkg: internalWorkletRuntimePkg,
2295
2351
  },
2296
2352
  },
2297
2353
  );
2298
2354
 
2299
2355
  expect(code).toMatchInlineSnapshot(`
2300
- "import { loadWorkletRuntime as __loadWorkletRuntime } from "@lynx-js/react";
2301
- var loadWorkletRuntime = __loadWorkletRuntime;
2356
+ "import { registerWorklet as __registerWorklet } from "@lynx-js/react/worklet-runtime/init";
2302
2357
  let foo = {
2303
2358
  _wkltId: "da39:80ef4:1"
2304
2359
  };
@@ -2309,13 +2364,12 @@ console.log(bar)
2309
2364
  _wkltId: "da39:80ef4:2"
2310
2365
  };
2311
2366
  console.log(bar);
2312
- const __workletRuntimeLoaded = loadWorkletRuntime(typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry);
2313
- __workletRuntimeLoaded && registerWorkletInternal("main-thread", "da39:80ef4:1", function() {
2367
+ __registerWorklet("main-thread", "da39:80ef4:1", function() {
2314
2368
  const foo = lynxWorkletImpl._workletMap["da39:80ef4:1"].bind(this);
2315
2369
  "main thread";
2316
2370
  return null;
2317
2371
  });
2318
- __workletRuntimeLoaded && registerWorkletInternal("main-thread", "da39:80ef4:2", function() {
2372
+ __registerWorklet("main-thread", "da39:80ef4:2", function() {
2319
2373
  const bar = lynxWorkletImpl._workletMap["da39:80ef4:2"].bind(this);
2320
2374
  let { foo } = this["_c"];
2321
2375
  "main thread";
@@ -2323,12 +2377,13 @@ console.log(bar)
2323
2377
  });
2324
2378
  "
2325
2379
  `);
2326
- expect((code.match(/registerWorkletInternal/g) ?? []).length).toBe(2);
2327
- expect((code.match(/const __workletRuntimeLoaded = loadWorkletRuntime/g) ?? []).length).toBe(1);
2380
+ expect(runtimeRequirements).toEqual({
2381
+ mainThreadProgrammability: true,
2382
+ });
2328
2383
  });
2329
2384
 
2330
2385
  it('use multiple times', async () => {
2331
- const { code } = await transformReactLynx(
2386
+ const { code, runtimeRequirements } = await transformReactLynx(
2332
2387
  `\
2333
2388
  function getCurrentDelta(event) {
2334
2389
  "main thread";
@@ -2357,16 +2412,14 @@ function getCurrentDelta(event) {
2357
2412
  worklet: {
2358
2413
  target: 'LEPUS',
2359
2414
  filename: '',
2360
- runtimePkg: '@lynx-js/react',
2415
+ runtimePkg: internalWorkletRuntimePkg,
2361
2416
  },
2362
2417
  },
2363
2418
  );
2364
2419
 
2365
2420
  expect(code).toMatchInlineSnapshot(`
2366
- "import { loadWorkletRuntime as __loadWorkletRuntime } from "@lynx-js/react";
2367
- var loadWorkletRuntime = __loadWorkletRuntime;
2368
- const __workletRuntimeLoaded = loadWorkletRuntime(typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry);
2369
- __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) {
2370
2423
  lynxWorkletImpl._workletMap["da39:059d0:1"].bind(this);
2371
2424
  let { foo, a, b } = this["_c"];
2372
2425
  "main thread";
@@ -2375,8 +2428,115 @@ function getCurrentDelta(event) {
2375
2428
  });
2376
2429
  "
2377
2430
  `);
2378
- expect((code.match(/registerWorkletInternal/g) ?? []).length).toBe(1);
2379
- 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
+ });
2380
2540
  });
2381
2541
 
2382
2542
  it('should keep webpack runtime variables', async () => {
@@ -0,0 +1,82 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import { describe, expect, it } from 'vitest';
6
+
7
+ import { transformReactLynx } from '../main.js';
8
+
9
+ const replacementCallback = () => 2;
10
+
11
+ function options(target) {
12
+ return {
13
+ mode: 'test',
14
+ pluginName: '',
15
+ filename: 'test.jsx',
16
+ sourcemap: false,
17
+ cssScope: false,
18
+ shake: false,
19
+ compat: false,
20
+ refresh: false,
21
+ defineDCE: false,
22
+ directiveDCE: false,
23
+ worklet: {
24
+ target,
25
+ filename: 'test.jsx',
26
+ runtimePkg: '@lynx-js/react/internal',
27
+ },
28
+ };
29
+ }
30
+
31
+ describe('object method captures', () => {
32
+ it('captures nested computed keys in the enclosing worklet scope', async () => {
33
+ const result = await transformReactLynx(
34
+ `
35
+ const name = 'create';
36
+ const nestedName = 'read';
37
+ export const valueType = {
38
+ [name]() {
39
+ 'main thread';
40
+ return { [nestedName](nestedName) { return nestedName; } };
41
+ },
42
+ };
43
+ `,
44
+ options('LEPUS'),
45
+ );
46
+ const functions = new Map();
47
+ const valueType = new Function(
48
+ '__registerWorklet',
49
+ `${result.code.replace(/^import .*;$/gm, '').replace(/^export /gm, '')}\nreturn valueType;`,
50
+ )(
51
+ (_type, id, fn) => functions.set(id, fn),
52
+ );
53
+ expect(valueType.create._c).toEqual({ nestedName: 'read' });
54
+ const nested = functions.get(valueType.create._wkltId).call(valueType.create);
55
+ expect(nested.read(42)).toBe(42);
56
+ });
57
+
58
+ it('reads background callbacks from the actual object method receiver', async () => {
59
+ const result = await transformReactLynx(
60
+ `
61
+ export const valueType = {
62
+ callback: () => 1,
63
+ create() {
64
+ 'main thread';
65
+ runOnBackground(this.callback)();
66
+ },
67
+ };
68
+ `,
69
+ options('JS'),
70
+ );
71
+ const valueType = new Function(
72
+ '__transformToWorklet',
73
+ `${result.code.replace(/^import .*;$/gm, '').replace(/^export /gm, '')}\nreturn valueType;`,
74
+ )(fn => fn);
75
+ expect(valueType.create._jsFn._jsFn1).toBe(valueType.callback);
76
+ valueType.callback = replacementCallback;
77
+ expect(valueType.create._jsFn._jsFn1).toBe(replacementCallback);
78
+ const other = { callback: () => 3 };
79
+ expect(Object.getOwnPropertyDescriptor(valueType, 'create').get.call(other)._jsFn._jsFn1)
80
+ .toBe(other.callback);
81
+ });
82
+ });
@@ -119,6 +119,16 @@ impl Visit for BindingCollector {
119
119
  }
120
120
  }
121
121
 
122
+ fn visit_method_prop(&mut self, node: &MethodProp) {
123
+ if self.should_enter_ctx {
124
+ self.should_enter_ctx = false;
125
+ self.enter_next_block = true;
126
+ // An object method's key is evaluated in the enclosing scope. Only the
127
+ // function parameters and body belong to the method's local scope.
128
+ node.function.visit_with(self);
129
+ }
130
+ }
131
+
122
132
  fn visit_catch_clause(&mut self, node: &CatchClause) {
123
133
  if self.should_enter_ctx {
124
134
  self.should_enter_ctx = false;
@@ -404,6 +404,20 @@ impl VisitMut for ExtractingIdentsCollector {
404
404
  self.pop_scope();
405
405
  }
406
406
 
407
+ fn visit_mut_method_prop(&mut self, n: &mut MethodProp) {
408
+ // Only the outer worklet's key is evaluated at its definition site.
409
+ // Nested method keys execute inside the worklet, in the enclosing scope
410
+ // rather than the nested method's parameter/body scope.
411
+ if !self.scope_env.last().unwrap().is_worklet_fn_scope {
412
+ n.key.visit_mut_with(self);
413
+ }
414
+ self.push_fn_scope(collect_inner_scope_decls(n));
415
+ self.next_block_decls_collected = true;
416
+ n.function.visit_mut_with(self);
417
+ self.next_block_decls_collected = false;
418
+ self.pop_scope();
419
+ }
420
+
407
421
  fn visit_mut_class_method(&mut self, n: &mut ClassMethod) {
408
422
  self.push_fn_scope(collect_inner_scope_decls(n));
409
423
  self.next_block_decls_collected = true;