@lynx-js/react 0.127.0 → 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 (305) hide show
  1. package/CHANGELOG.md +18 -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__/element-template/internal/legacy-internal-guardrail.test.ts +1 -1
  6. package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +39 -48
  7. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +7 -9
  8. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -3
  9. package/runtime/__test__/element-template/test-utils/mock/globals.js +6 -0
  10. package/runtime/__test__/element-template/vitest.config.ts +4 -0
  11. package/runtime/__test__/worklet-runtime/initEntry.test.js +109 -0
  12. package/runtime/__test__/worklet-runtime/object-methods.test.js +2 -3
  13. package/runtime/lazy/element-template-internal.js +0 -1
  14. package/runtime/lazy/internal.js +0 -1
  15. package/runtime/lib/core/background-function/exec-map.js.map +1 -1
  16. package/runtime/lib/core/background-function/handle.js.map +1 -1
  17. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  18. package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
  19. package/runtime/lib/core/commit-context.js.map +1 -1
  20. package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
  21. package/runtime/lib/core/compat/lynxComponent.js.map +1 -1
  22. package/runtime/lib/core/component.js.map +1 -1
  23. package/runtime/lib/core/forceRootRender.js.map +1 -1
  24. package/runtime/lib/core/globalProps.js.map +1 -1
  25. package/runtime/lib/core/hooks/mainThread.js.map +1 -1
  26. package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
  27. package/runtime/lib/core/hooks/react.js.map +1 -1
  28. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
  29. package/runtime/lib/core/initData.js.map +1 -1
  30. package/runtime/lib/core/lynx/dynamic-import.js.map +1 -1
  31. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  32. package/runtime/lib/core/lynx/runtime-backend.js.map +1 -1
  33. package/runtime/lib/core/lynx/runtime-version.js.map +1 -1
  34. package/runtime/lib/core/lynx-data-processors.js.map +1 -1
  35. package/runtime/lib/core/lynx-page-data.js.map +1 -1
  36. package/runtime/lib/core/lynx-update-data.js.map +1 -1
  37. package/runtime/lib/core/main-thread-function.js.map +1 -1
  38. package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -1
  39. package/runtime/lib/core/main-thread-object.js +1 -4
  40. package/runtime/lib/core/main-thread-object.js.map +1 -1
  41. package/runtime/lib/core/main-thread-ref-id.js.map +1 -1
  42. package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
  43. package/runtime/lib/core/main-thread-ref.js.map +1 -1
  44. package/runtime/lib/core/mts-capability.js.map +1 -1
  45. package/runtime/lib/core/performance.js.map +1 -1
  46. package/runtime/lib/core/ref.js.map +1 -1
  47. package/runtime/lib/core/reload-version.js.map +1 -1
  48. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  49. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  50. package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
  51. package/runtime/lib/document.js.map +1 -1
  52. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  53. package/runtime/lib/element-template/background/commit-context.js.map +1 -1
  54. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  55. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  56. package/runtime/lib/element-template/background/document.js.map +1 -1
  57. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  58. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  59. package/runtime/lib/element-template/background/instance.js.map +1 -1
  60. package/runtime/lib/element-template/background/manager.js.map +1 -1
  61. package/runtime/lib/element-template/background/page-root-hydrate.js.map +1 -1
  62. package/runtime/lib/element-template/background/render-scope.js.map +1 -1
  63. package/runtime/lib/element-template/client/root.js.map +1 -1
  64. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  65. package/runtime/lib/element-template/debug/elementPAPICall.js.map +1 -1
  66. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  67. package/runtime/lib/element-template/hydration-map.js.map +1 -1
  68. package/runtime/lib/element-template/index.js.map +1 -1
  69. package/runtime/lib/element-template/internal.d.ts +0 -1
  70. package/runtime/lib/element-template/internal.js +0 -1
  71. package/runtime/lib/element-template/internal.js.map +1 -1
  72. package/runtime/lib/element-template/jsx-dev-runtime/index.js.map +1 -1
  73. package/runtime/lib/element-template/jsx-runtime/index.js.map +1 -1
  74. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  75. package/runtime/lib/element-template/lynx/performance.js.map +1 -1
  76. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
  77. package/runtime/lib/element-template/native/index.js.map +1 -1
  78. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  79. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  80. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  81. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  82. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  83. package/runtime/lib/element-template/prop-adapters/event-value.js.map +1 -1
  84. package/runtime/lib/element-template/prop-adapters/event.js.map +1 -1
  85. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
  86. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  87. package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
  88. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  89. package/runtime/lib/element-template/protocol/page.js.map +1 -1
  90. package/runtime/lib/element-template/protocol/template-type.js.map +1 -1
  91. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  92. package/runtime/lib/element-template/protocol/update-event.js.map +1 -1
  93. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  94. package/runtime/lib/element-template/runtime/page/authored-page.js.map +1 -1
  95. package/runtime/lib/element-template/runtime/page/page.js.map +1 -1
  96. package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
  97. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  98. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
  99. package/runtime/lib/element-template/runtime/render/host.js.map +1 -1
  100. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  101. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
  102. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  103. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  104. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  105. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  106. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  107. package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js.map +1 -1
  108. package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +1 -1
  109. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  110. package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
  111. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  112. package/runtime/lib/element-template/runtime-marker.js.map +1 -1
  113. package/runtime/lib/index.js.map +1 -1
  114. package/runtime/lib/internal.d.ts +0 -1
  115. package/runtime/lib/internal.js +0 -1
  116. package/runtime/lib/internal.js.map +1 -1
  117. package/runtime/lib/lynx-api.js.map +1 -1
  118. package/runtime/lib/lynx.js.map +1 -1
  119. package/runtime/lib/root.js.map +1 -1
  120. package/runtime/lib/runtime-marker.js.map +1 -1
  121. package/runtime/lib/shared/attribute-name.js.map +1 -1
  122. package/runtime/lib/shared/component-stack.js.map +1 -1
  123. package/runtime/lib/shared/index-map.js.map +1 -1
  124. package/runtime/lib/shared/profile.js.map +1 -1
  125. package/runtime/lib/shared/render-constants.js.map +1 -1
  126. package/runtime/lib/snapshot/alog/elementPAPICall.js.map +1 -1
  127. package/runtime/lib/snapshot/alog/index.js.map +1 -1
  128. package/runtime/lib/snapshot/alog/render.js.map +1 -1
  129. package/runtime/lib/snapshot/compat/componentIs.js.map +1 -1
  130. package/runtime/lib/snapshot/debug/debug.js.map +1 -1
  131. package/runtime/lib/snapshot/debug/describeInvalidValue.js.map +1 -1
  132. package/runtime/lib/snapshot/debug/formatPatch.js.map +1 -1
  133. package/runtime/lib/snapshot/debug/printSnapshot.js.map +1 -1
  134. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  135. package/runtime/lib/snapshot/debug/vnodeSource.js.map +1 -1
  136. package/runtime/lib/snapshot/gesture/processGesture.js.map +1 -1
  137. package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +1 -1
  138. package/runtime/lib/snapshot/gesture/types.js.map +1 -1
  139. package/runtime/lib/snapshot/index.js.map +1 -1
  140. package/runtime/lib/snapshot/lifecycle/constant.js.map +1 -1
  141. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  142. package/runtime/lib/snapshot/lifecycle/event/delayEvents.js.map +1 -1
  143. package/runtime/lib/snapshot/lifecycle/event/delayLifecycleEvents.js.map +1 -1
  144. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
  145. package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
  146. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  147. package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
  148. package/runtime/lib/snapshot/lifecycle/patch/globalState.js.map +1 -1
  149. package/runtime/lib/snapshot/lifecycle/patch/isMainThreadHydrating.js.map +1 -1
  150. package/runtime/lib/snapshot/lifecycle/patch/nodesRefApply.js.map +1 -1
  151. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
  152. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  153. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  154. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  155. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  156. package/runtime/lib/snapshot/lifecycle/render.js.map +1 -1
  157. package/runtime/lib/snapshot/list/list.js.map +1 -1
  158. package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
  159. package/runtime/lib/snapshot/list/pendingListUpdates.js.map +1 -1
  160. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  161. package/runtime/lib/snapshot/lynx/children.js.map +1 -1
  162. package/runtime/lib/snapshot/lynx/element.js.map +1 -1
  163. package/runtime/lib/snapshot/lynx/env.js.map +1 -1
  164. package/runtime/lib/snapshot/lynx/injectLepusMethods.js.map +1 -1
  165. package/runtime/lib/snapshot/lynx/lazyBundleConstants.js.map +1 -1
  166. package/runtime/lib/snapshot/lynx/nodesRef.js.map +1 -1
  167. package/runtime/lib/snapshot/lynx/performance.js.map +1 -1
  168. package/runtime/lib/snapshot/lynx/portals.js.map +1 -1
  169. package/runtime/lib/snapshot/lynx/portalsPending.js.map +1 -1
  170. package/runtime/lib/snapshot/lynx/prepareLazyBundleMTS.js.map +1 -1
  171. package/runtime/lib/snapshot/lynx/runWithForce.js.map +1 -1
  172. package/runtime/lib/snapshot/lynx/suspense.js.map +1 -1
  173. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  174. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  175. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  176. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  177. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  178. package/runtime/lib/snapshot/snapshot/constants.js.map +1 -1
  179. package/runtime/lib/snapshot/snapshot/definition.js.map +1 -1
  180. package/runtime/lib/snapshot/snapshot/dynamicPartType.js.map +1 -1
  181. package/runtime/lib/snapshot/snapshot/event.js.map +1 -1
  182. package/runtime/lib/snapshot/snapshot/gesture.js.map +1 -1
  183. package/runtime/lib/snapshot/snapshot/index.js.map +1 -1
  184. package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
  185. package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
  186. package/runtime/lib/snapshot/snapshot/reconstructInstanceTree.js.map +1 -1
  187. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  188. package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
  189. package/runtime/lib/snapshot/snapshot/snapshotCreatorMap.js.map +1 -1
  190. package/runtime/lib/snapshot/snapshot/snapshotInstanceHydrationMap.js.map +1 -1
  191. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
  192. package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
  193. package/runtime/lib/snapshot/snapshot/types.js.map +1 -1
  194. package/runtime/lib/snapshot/snapshot/utils.js.map +1 -1
  195. package/runtime/lib/snapshot/snapshot/workletEvent.js.map +1 -1
  196. package/runtime/lib/snapshot/snapshot/workletRef.js.map +1 -1
  197. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  198. package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
  199. package/runtime/lib/snapshot/worklet/destroy.js.map +1 -1
  200. package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
  201. package/runtime/lib/snapshot/worklet/hmr.js.map +1 -1
  202. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
  203. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  204. package/runtime/lib/utils.js.map +1 -1
  205. package/runtime/lib/worklet-runtime/api/animation/animation.js.map +1 -1
  206. package/runtime/lib/worklet-runtime/api/animation/effect.js.map +1 -1
  207. package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
  208. package/runtime/lib/worklet-runtime/api/lepusQuerySelector.js.map +1 -1
  209. package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
  210. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  211. package/runtime/lib/worklet-runtime/bindings/events.js.map +1 -1
  212. package/runtime/lib/worklet-runtime/bindings/index.d.ts +0 -1
  213. package/runtime/lib/worklet-runtime/bindings/index.js +0 -1
  214. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
  215. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  216. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
  217. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
  218. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
  219. package/runtime/lib/worklet-runtime/eomImpl.js.map +1 -1
  220. package/runtime/lib/worklet-runtime/eventPropagation.js.map +1 -1
  221. package/runtime/lib/worklet-runtime/global.js.map +1 -1
  222. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  223. package/runtime/lib/worklet-runtime/index.js +6 -0
  224. package/runtime/lib/worklet-runtime/index.js.map +1 -1
  225. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  226. package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
  227. package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -1
  228. package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
  229. package/runtime/lib/worklet-runtime/utils/mainThreadFlushLoopGuard.js.map +1 -1
  230. package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
  231. package/runtime/lib/worklet-runtime/utils/version.js.map +1 -1
  232. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
  233. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  234. package/runtime/src/core/main-thread-object.ts +1 -8
  235. package/runtime/src/element-template/internal.ts +0 -1
  236. package/runtime/src/internal.ts +0 -1
  237. package/runtime/src/worklet-runtime/bindings/index.ts +0 -1
  238. package/runtime/src/worklet-runtime/index.ts +7 -0
  239. package/runtime/tsconfig.json +2 -0
  240. package/runtime/vitest.config.ts +4 -0
  241. package/testing-library/.turbo/turbo-build.log +11 -11
  242. package/testing-library/dist/env/index.js +3 -15
  243. package/testing-library/dist/plugins/index.js +10 -0
  244. package/testing-library/dist/rstest-config.js +15 -0
  245. package/testing-library/dist/setupFiles/common/worklet-runtime-init.js +11 -0
  246. package/testing-library/rstest.config.ts +3 -0
  247. package/testing-library/src/__tests__/rstest-config.test.js +34 -1
  248. package/testing-library/src/__tests__/worklet.test.jsx +41 -32
  249. package/testing-library/src/plugins/vitest.ts +5 -1
  250. package/testing-library/src/rstest-config.ts +17 -1
  251. package/testing-library/src/setupFiles/common/worklet-runtime-init.js +22 -0
  252. package/transform/.turbo/turbo-build$colon$wasm.log +113 -123
  253. package/transform/__test__/defines.spec.js +80 -12
  254. package/transform/__test__/fixture.spec.js +166 -48
  255. package/transform/__test__/object-methods.spec.js +1 -3
  256. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +26 -10
  257. package/transform/crates/swc_plugin_worklet/lib.rs +132 -148
  258. package/transform/crates/swc_plugin_worklet/napi.rs +10 -1
  259. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +4 -4
  260. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +3 -5
  261. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_lepus.js +2 -4
  262. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +4 -4
  263. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_lepus.js +3 -5
  264. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_lepus.js +2 -4
  265. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +4 -4
  266. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +2 -4
  267. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_globals.js +2 -4
  268. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +2 -4
  269. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_type_annotations.js +2 -4
  270. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_destructure_from_closure.js +2 -4
  271. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_catch_clause_params.js +2 -4
  272. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_idents_inside_of_ctx.js +2 -4
  273. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_recursively.js +2 -4
  274. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +6 -6
  275. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js +2 -4
  276. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_arrow_function.js +2 -4
  277. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_lepus.js +2 -4
  278. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_function_expr.js +2 -4
  279. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_lepus.js +2 -4
  280. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_lepus.js +2 -4
  281. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_lepus.js +2 -4
  282. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_lepus.js +2 -4
  283. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_lepus.js +2 -4
  284. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +4 -4
  285. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_alias.js +2 -4
  286. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general.js +2 -4
  287. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general_mixed.js +2 -4
  288. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets.js +3 -5
  289. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets_in_func.js +3 -5
  290. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +2 -4
  291. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_lepus.js +2 -4
  292. package/transform/dist/wasm.cjs +1 -1
  293. package/transform/index.d.ts +25 -1
  294. package/transform/src/lib.rs +193 -23
  295. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +30 -31
  296. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  297. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +195 -217
  298. package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +0 -8
  299. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +0 -23
  300. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +0 -1
  301. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +0 -25
  302. package/runtime/worklet-runtime/dev.js +0 -775
  303. package/runtime/worklet-runtime/main.js +0 -1
  304. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_inner_ident.js +0 -13
  305. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_outer_ident.js +0 -13
@@ -4,24 +4,24 @@ Rslib v1.0.2
4
4
  info build started...
5
5
  start generating declaration files... (esm0)
6
6
  start generating declaration files... (esm2)
7
- ready built in 0.86s (esm2)
8
- ready built in 0.97s (esm1)
9
- ready built in 1.52s (esm0)
10
- info declaration files prepared with tsgo in 1.58 s (esm2)
11
- ready declaration files bundled successfully: dist/index.d.ts in 3.82 s (esm2)
12
- ready declaration files generated in 7.63 s (esm0)
7
+ ready built in 0.68s (esm2)
8
+ ready built in 0.80s (esm1)
9
+ ready built in 1.18s (esm0)
10
+ info declaration files prepared with tsgo in 1.61 s (esm2)
11
+ ready declaration files bundled successfully: dist/index.d.ts in 3.30 s (esm2)
12
+ ready declaration files generated in 7.27 s (esm0)
13
13
 
14
14
  File (esm0) Size
15
15
  dist/rslib-runtime-0.js 1.6 kB
16
- dist/rstest-config.js 3.2 kB
17
16
  dist/@rstest/adapter-rsbuild~0.js 3.7 kB
18
- dist/plugins/index.js 12.1 kB
19
- dist/env/index.js 26.7 kB
17
+ dist/rstest-config.js 3.8 kB
18
+ dist/plugins/index.js 12.6 kB
19
+ dist/env/index.js 26.1 kB
20
20
  dist/pure.js 539.1 kB
21
21
 
22
- Total: 586.4 kB
22
+ Total: 586.8 kB
23
23
 
24
- 10 files generated in dist, total: 8.5 kB (esm1)
24
+ 11 files generated in dist, total: 8.9 kB (esm1)
25
25
 
26
26
  File (esm2) Size
27
27
  dist/type-entry/index.js 0.01 kB
@@ -464,26 +464,16 @@ function createPolyfills() {
464
464
  mainThreadContexts.JsContext.dispatchEvent = ({ type, data })=>deliverEvent(backgroundThreadContexts.CoreContext, 'background', type, data, 'CoreContext');
465
465
  backgroundThreadContexts.CoreContext.dispatchEvent = ({ type, data })=>deliverEvent(mainThreadContexts.JsContext, 'main', type, data, 'JSContext');
466
466
  backgroundThreadContexts.JsContext.dispatchEvent = ({ type, data })=>deliverEvent(backgroundThreadContexts.JsContext, 'background', type, data, 'JSContext');
467
- function __LoadLepusChunk(chunkName, _options) {
468
- const isBackground = !__MAIN_THREAD__;
469
- globalThis.lynxTestingEnv.switchToMainThread();
470
- let ans;
471
- if ('worklet-runtime' === chunkName) ans = globalThis.onInitWorkletRuntime?.();
472
- else throw new Error(`__LoadLepusChunk: Unknown chunk name: ${chunkName}`);
473
- if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
474
- return ans;
475
- }
476
467
  return {
477
468
  app,
478
469
  performance,
479
470
  mainThreadContexts,
480
- backgroundThreadContexts,
481
- __LoadLepusChunk
471
+ backgroundThreadContexts
482
472
  };
483
473
  }
484
474
  function injectMainThreadGlobals(target, polyfills) {
485
475
  __injectElementApi(target);
486
- const { performance, mainThreadContexts, __LoadLepusChunk } = polyfills || {};
476
+ const { performance, mainThreadContexts } = polyfills || {};
487
477
  if (void 0 === target) target = globalThis;
488
478
  target.__DEV__ = true;
489
479
  target.__PROFILE__ = true;
@@ -531,7 +521,6 @@ function injectMainThreadGlobals(target, polyfills) {
531
521
  target.console.profile = console.profile = ()=>{};
532
522
  target.console.profileEnd = console.profileEnd = ()=>{};
533
523
  target.console.alog = console.alog = ()=>{};
534
- target.__LoadLepusChunk = __LoadLepusChunk;
535
524
  globalThis.onInjectMainThreadGlobals?.(target);
536
525
  }
537
526
  const IGNORE_LIST_GLOBALS = [
@@ -565,7 +554,7 @@ class NodesRef {
565
554
  }
566
555
  }
567
556
  function injectBackgroundThreadGlobals(target, polyfills) {
568
- const { app, performance, backgroundThreadContexts, __LoadLepusChunk } = polyfills || {};
557
+ const { app, performance, backgroundThreadContexts } = polyfills || {};
569
558
  if (void 0 === target) target = globalThis;
570
559
  target.__DEV__ = true;
571
560
  target.__PROFILE__ = true;
@@ -630,7 +619,6 @@ function injectBackgroundThreadGlobals(target, polyfills) {
630
619
  runtimeType: 'quickjs',
631
620
  lynxSdkVersion: '3.0'
632
621
  };
633
- target.__LoadLepusChunk = __LoadLepusChunk;
634
622
  globalThis.onInjectBackgroundThreadGlobals?.(target);
635
623
  }
636
624
  class LynxTestingEnv {
@@ -23,6 +23,15 @@ function testingLibraryPlugin(options) {
23
23
  const runtimeOSSAlias = generateAlias(runtimeOSSPkgName, runtimeOSSDir, runtimeDir);
24
24
  let runtimeAlias = [];
25
25
  if (runtimePkgName !== runtimeOSSPkgName) runtimeAlias = generateAlias(runtimePkgName, runtimeDir, vitest_dirname);
26
+ const workletRuntimeInitAliases = [
27
+ ...new Set([
28
+ runtimeOSSPkgName,
29
+ runtimePkgName
30
+ ])
31
+ ].map((pkgName)=>({
32
+ find: new RegExp('^' + pkgName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '/worklet-runtime/init$'),
33
+ replacement: vitest_require.resolve('../setupFiles/common/worklet-runtime-init.js')
34
+ }));
26
35
  const preactAlias = generateAlias('preact', preactDir, runtimeOSSDir);
27
36
  preactAlias.forEach((alias)=>{
28
37
  alias.replacement = alias.replacement.replace(/\.js$/, '.mjs');
@@ -230,6 +239,7 @@ function testingLibraryPlugin(options) {
230
239
  vitest_require.resolve('../setupFiles/vitest')
231
240
  ],
232
241
  alias: [
242
+ ...workletRuntimeInitAliases,
233
243
  ...runtimeOSSAlias,
234
244
  ...runtimeAlias,
235
245
  ...preactAlias,
@@ -5,6 +5,20 @@ const rstest_config_require = createRequire(import.meta.url);
5
5
  function createDefaultRstestConfig() {
6
6
  return {
7
7
  testEnvironment: 'jsdom',
8
+ plugins: [
9
+ {
10
+ name: 'lynx:testing-runtime-init',
11
+ pre: [
12
+ 'lynx:react',
13
+ 'lynx:react-alias'
14
+ ],
15
+ setup (api) {
16
+ api.modifyBundlerChain((chain)=>{
17
+ chain.resolve.alias.set('@lynx-js/react/worklet-runtime/init$', rstest_config_require.resolve('./setupFiles/common/worklet-runtime-init.js'));
18
+ });
19
+ }
20
+ }
21
+ ],
8
22
  setupFiles: [
9
23
  rstest_config_require.resolve('./setupFiles/rstest')
10
24
  ],
@@ -75,6 +89,7 @@ function withLynxConfig(options) {
75
89
  ...defaultConfig,
76
90
  plugins: [
77
91
  ...rstestConfig.plugins || [],
92
+ ...defaultConfig.plugins || [],
78
93
  {
79
94
  name: 'lynx-adapter:remove-useless-plugins',
80
95
  remove: [
@@ -0,0 +1,11 @@
1
+ const isBackground = !__MAIN_THREAD__;
2
+ globalThis.lynxTestingEnv.switchToMainThread();
3
+ try {
4
+ if (void 0 === globalThis.lynxWorkletImpl) globalThis.onInitWorkletRuntime();
5
+ } finally{
6
+ if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
7
+ }
8
+ function registerWorklet(type, id, worklet) {
9
+ globalThis.registerWorkletInternal(type, id, worklet);
10
+ }
11
+ export { registerWorklet };
@@ -1,7 +1,10 @@
1
+ import { createRequire } from 'node:module';
1
2
  import { defineConfig } from '@rstest/core';
2
3
  import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';
3
4
  import { withDefaultConfig } from './src/rstest-config.ts';
4
5
 
6
+ const require = createRequire(import.meta.url);
7
+
5
8
  export default defineConfig({
6
9
  extends: withDefaultConfig({
7
10
  modifyRstestConfig(config) {
@@ -1,6 +1,9 @@
1
+ import { join } from 'node:path';
2
+
3
+ import { createRsbuild } from '@rsbuild/core';
1
4
  import { describe, expect, it } from 'vitest';
2
5
 
3
- import { isRspeedyProject } from '../rstest-config.js';
6
+ import { isRspeedyProject, withDefaultConfig } from '../rstest-config.js';
4
7
 
5
8
  const hasLynxConfig = (path) => path.endsWith('lynx.config.ts');
6
9
  const hasNothing = () => false;
@@ -29,3 +32,33 @@ describe('isRspeedyProject', () => {
29
32
  expect(isRspeedyProject(undefined, hasNothing)).toBe(false);
30
33
  });
31
34
  });
35
+
36
+ describe('testing runtime init ordering', () => {
37
+ it.each(['lynx:react', 'lynx:react-alias'])(
38
+ 'preserves the testing init alias when defaults precede %s',
39
+ async (name) => {
40
+ const defaults = await withDefaultConfig()({});
41
+ const rsbuild = await createRsbuild({
42
+ rsbuildConfig: {
43
+ plugins: [
44
+ ...defaults.plugins,
45
+ {
46
+ name,
47
+ setup(api) {
48
+ api.modifyBundlerChain(chain => {
49
+ chain.resolve.alias.set(
50
+ '@lynx-js/react/worklet-runtime/init$',
51
+ '/production-runtime.js',
52
+ );
53
+ });
54
+ },
55
+ },
56
+ ],
57
+ },
58
+ });
59
+ const [config] = await rsbuild.initConfigs();
60
+ expect(config.resolve.alias['@lynx-js/react/worklet-runtime/init$'])
61
+ .toContain(join('setupFiles', 'common', 'worklet-runtime-init.js'));
62
+ },
63
+ );
64
+ });
@@ -17,6 +17,23 @@ const guardedClassCaptureType = defineMainThreadObjectType({
17
17
  });
18
18
 
19
19
  describe('worklet', () => {
20
+ it('resolves the registration owner when a MIXED module imports the init entry on BTS', async () => {
21
+ expect(__MAIN_THREAD__).toBe(false);
22
+ const { registerWorklet } = await import('@lynx-js/react/worklet-runtime/init');
23
+ expect(__MAIN_THREAD__).toBe(false);
24
+
25
+ const owner = vi.spyOn(globalThis, 'registerWorkletInternal');
26
+ const worklet = vi.fn(() => 42);
27
+ try {
28
+ registerWorklet('main-thread', 'mixed-init-entry', worklet);
29
+ expect(owner).toHaveBeenCalledWith('main-thread', 'mixed-init-entry', worklet);
30
+ expect(globalThis.lynxWorkletImpl._workletMap['mixed-init-entry']).toBe(worklet);
31
+ } finally {
32
+ owner.mockRestore();
33
+ delete globalThis.lynxWorkletImpl._workletMap['mixed-init-entry'];
34
+ }
35
+ });
36
+
20
37
  it('main-thread script should work', async () => {
21
38
  const cb = vi.fn();
22
39
  const Comp = () => {
@@ -62,9 +79,8 @@ describe('worklet', () => {
62
79
  `);
63
80
  });
64
81
  it('main-thread script should not throw when enable background thread', async () => {
65
- vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
66
- const callLepusMethodCalls = lynx.getNativeApp().callLepusMethod.mock.calls;
67
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
82
+ const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
83
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
68
84
 
69
85
  globalThis.cb = vi.fn();
70
86
  const mainThreadFn = () => {
@@ -87,7 +103,7 @@ describe('worklet', () => {
87
103
  enableBackgroundThread: true,
88
104
  });
89
105
 
90
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`
106
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`
91
107
  [
92
108
  [
93
109
  "rLynxChange",
@@ -130,9 +146,8 @@ describe('worklet', () => {
130
146
  vi.resetAllMocks();
131
147
  });
132
148
  it('main-thread script should not update MTS function when enable background', async () => {
133
- vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
134
- const callLepusMethodCalls = lynx.getNativeApp().callLepusMethod.mock.calls;
135
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
149
+ const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
150
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
136
151
 
137
152
  globalThis.cb = vi.fn();
138
153
  const mainThreadFn = (e) => {
@@ -169,7 +184,7 @@ describe('worklet', () => {
169
184
  enableBackgroundThread: true,
170
185
  });
171
186
 
172
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`
187
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`
173
188
  [
174
189
  [
175
190
  "rLynxChange",
@@ -220,9 +235,8 @@ describe('worklet', () => {
220
235
  });
221
236
 
222
237
  it('main thread script props', () => {
223
- vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
224
- const callLepusMethodCalls = lynx.getNativeApp().callLepusMethod.mock.calls;
225
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
238
+ const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
239
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
226
240
 
227
241
  globalThis.cb = vi.fn();
228
242
  const mainThreadFn = (e) => {
@@ -259,7 +273,7 @@ describe('worklet', () => {
259
273
  </page>
260
274
  `);
261
275
 
262
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`
276
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`
263
277
  [
264
278
  [
265
279
  "rLynxChange",
@@ -295,9 +309,8 @@ describe('worklet', () => {
295
309
  });
296
310
 
297
311
  it('runOnMainThread works', async () => {
298
- vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
299
- const callLepusMethodCalls = lynx.getNativeApp().callLepusMethod.mock.calls;
300
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
312
+ const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
313
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
301
314
  const Comp = () => {
302
315
  return (
303
316
  <view
@@ -326,9 +339,8 @@ describe('worklet', () => {
326
339
  });
327
340
 
328
341
  it('runOnBackground works', async () => {
329
- vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
330
- const callLepusMethodCalls = lynx.getNativeApp().callLepusMethod.mock.calls;
331
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
342
+ const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
343
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
332
344
 
333
345
  const cb = vi.fn();
334
346
  globalThis.receiveRunOnBackgroundResp = vi.fn();
@@ -353,7 +365,7 @@ describe('worklet', () => {
353
365
  enableMainThread: true,
354
366
  enableBackgroundThread: true,
355
367
  });
356
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`
368
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`
357
369
  [
358
370
  [
359
371
  "rLynxChange",
@@ -408,9 +420,8 @@ describe('worklet', () => {
408
420
  });
409
421
 
410
422
  it('worklet ref should work', async () => {
411
- vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
412
- const callLepusMethodCalls = lynx.getNativeApp().callLepusMethod.mock.calls;
413
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
423
+ const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
424
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
414
425
  globalThis.cb = vi.fn();
415
426
  const Comp = () => {
416
427
  const ref = useMainThreadRef(null);
@@ -451,7 +462,7 @@ describe('worklet', () => {
451
462
  </view>
452
463
  </page>
453
464
  `);
454
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`
465
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`
455
466
  [
456
467
  [
457
468
  "rLynxChangeRefInitValue",
@@ -493,9 +504,8 @@ describe('worklet', () => {
493
504
  });
494
505
 
495
506
  it('nest runOnMainThread->runOnBackground works', async () => {
496
- vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
497
- const callLepusMethodCalls = lynx.getNativeApp().callLepusMethod.mock.calls;
498
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
507
+ const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
508
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
499
509
  const Comp = () => {
500
510
  return (
501
511
  <view
@@ -568,9 +578,8 @@ describe('worklet', () => {
568
578
  });
569
579
 
570
580
  it('multiple main-thread worklets should work together when background thread is enabled', () => {
571
- vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
572
- const callLepusMethodCalls = lynx.getNativeApp().callLepusMethod.mock.calls;
573
- expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
581
+ const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
582
+ expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
574
583
 
575
584
  globalThis.firstCb = vi.fn();
576
585
  globalThis.secondCb = vi.fn();
@@ -603,10 +612,10 @@ describe('worklet', () => {
603
612
  enableBackgroundThread: true,
604
613
  });
605
614
 
606
- expect(callLepusMethodCalls).toHaveLength(1);
607
- expect(callLepusMethodCalls[0][0]).toBe('rLynxChange');
615
+ expect(callLepusMethod.mock.calls).toHaveLength(1);
616
+ expect(callLepusMethod.mock.calls[0][0]).toBe('rLynxChange');
608
617
 
609
- const patchData = JSON.parse(callLepusMethodCalls[0][1].data);
618
+ const patchData = JSON.parse(callLepusMethod.mock.calls[0][1].data);
610
619
  const workletIds = patchData.patchList
611
620
  .flatMap(item => Array.isArray(item.snapshotPatch) ? item.snapshotPatch : [])
612
621
  .filter(item => typeof item === 'object' && item !== null && '_wkltId' in item)
@@ -67,6 +67,10 @@ export function testingLibraryPlugin(
67
67
  if (runtimePkgName !== runtimeOSSPkgName) {
68
68
  runtimeAlias = generateAlias(runtimePkgName, runtimeDir, __dirname);
69
69
  }
70
+ const workletRuntimeInitAliases = [...new Set([runtimeOSSPkgName, runtimePkgName])].map(pkgName => ({
71
+ find: new RegExp('^' + pkgName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '/worklet-runtime/init$'),
72
+ replacement: require.resolve('../setupFiles/common/worklet-runtime-init.js'),
73
+ }));
70
74
  const preactAlias = generateAlias('preact', preactDir, runtimeOSSDir);
71
75
  preactAlias.forEach((alias) => {
72
76
  alias.replacement = alias.replacement.replace(/\.js$/, '.mjs');
@@ -314,7 +318,7 @@ export function testingLibraryPlugin(
314
318
  setupFiles: [
315
319
  require.resolve('../setupFiles/vitest'),
316
320
  ],
317
- alias: [...runtimeOSSAlias, ...runtimeAlias, ...preactAlias, ...reactAlias],
321
+ alias: [...workletRuntimeInitAliases, ...runtimeOSSAlias, ...runtimeAlias, ...preactAlias, ...reactAlias],
318
322
  // Force any module that touches `preact` (or its forks like
319
323
  // `@lynx-js/internal-preact`, `@lynx-js/react-signals`) through Vite's
320
324
  // transform pipeline so the aliases above can redirect every
@@ -2,7 +2,7 @@ import type { ExtendConfig, ExtendConfigFn } from '@rstest/core';
2
2
  import { existsSync } from 'node:fs';
3
3
  import { createRequire } from 'node:module';
4
4
  import { join } from 'node:path';
5
- import type { RsbuildConfig } from '@rsbuild/core';
5
+ import type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core';
6
6
 
7
7
  export interface LynxConfigOptions {
8
8
  /**
@@ -43,6 +43,21 @@ const require = createRequire(import.meta.url);
43
43
  function createDefaultRstestConfig(): ExtendConfig {
44
44
  return {
45
45
  testEnvironment: 'jsdom',
46
+ plugins: [
47
+ {
48
+ name: 'lynx:testing-runtime-init',
49
+ // Integrations can embed the alias plugin inside a React wrapper.
50
+ pre: ['lynx:react', 'lynx:react-alias'],
51
+ setup(api) {
52
+ api.modifyBundlerChain(chain => {
53
+ chain.resolve.alias.set(
54
+ '@lynx-js/react/worklet-runtime/init$',
55
+ require.resolve('./setupFiles/common/worklet-runtime-init.js'),
56
+ );
57
+ });
58
+ },
59
+ } satisfies RsbuildPlugin,
60
+ ],
46
61
  setupFiles: [require.resolve('./setupFiles/rstest')],
47
62
  globals: true,
48
63
  };
@@ -153,6 +168,7 @@ export function withLynxConfig(
153
168
  ...defaultConfig,
154
169
  plugins: [
155
170
  ...(rstestConfig.plugins || []),
171
+ ...(defaultConfig.plugins || []),
156
172
  {
157
173
  name: 'lynx-adapter:remove-useless-plugins',
158
174
  // `lynx:rsbuild:target` builds for Lynx, but the tests run in jsdom
@@ -0,0 +1,22 @@
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
+ // MIXED test modules can evaluate on the background thread. Initialize the
5
+ // emulated main-thread runtime, then restore the caller's thread.
6
+ const isBackground = !__MAIN_THREAD__;
7
+ globalThis.lynxTestingEnv.switchToMainThread();
8
+ try {
9
+ if (globalThis.lynxWorkletImpl === undefined) {
10
+ globalThis.onInitWorkletRuntime();
11
+ }
12
+ } finally {
13
+ if (isBackground) {
14
+ globalThis.lynxTestingEnv.switchToBackgroundThread();
15
+ }
16
+ }
17
+
18
+ // Resolve the owner when registration runs: MIXED modules can import this entry
19
+ // before the main-thread globals are active.
20
+ export function registerWorklet(type, id, worklet) {
21
+ globalThis.registerWorkletInternal(type, id, worklet);
22
+ }