@lynx-js/react 0.129.0 → 0.129.2

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 (282) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +3 -4
  4. package/refresh/.turbo/turbo-build.log +1 -1
  5. package/runtime/__test__/core/globalProps.test.ts +27 -6
  6. package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
  7. package/runtime/__test__/element-template/fixtures/gesture/direct/index.tsx +33 -0
  8. package/runtime/__test__/element-template/fixtures/spread/mts/index.tsx +197 -0
  9. package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
  10. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
  11. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +89 -3
  12. package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
  13. package/runtime/__test__/element-template/native/mts-destroy.test.ts +88 -0
  14. package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +3 -0
  15. package/runtime/__test__/element-template/native/reload.test.ts +118 -2
  16. package/runtime/__test__/element-template/runtime/background/global-props/compiled-fixtures.test.tsx +5 -5
  17. package/runtime/__test__/element-template/runtime/background/global-props.test.tsx +1 -1
  18. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +70 -0
  19. package/runtime/__test__/element-template/runtime/background/ref/compiled-fixtures.test.tsx +3 -4
  20. package/runtime/__test__/element-template/runtime/background/reload.test.ts +74 -0
  21. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
  22. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +212 -7
  23. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
  24. package/runtime/__test__/element-template/runtime/prop-adapters/gesture-compiled.test.ts +200 -0
  25. package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +420 -0
  26. package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +527 -0
  27. package/runtime/__test__/element-template/runtime/prop-adapters/spread.test.ts +185 -6
  28. package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +21 -1
  29. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
  30. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
  31. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
  32. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
  33. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +309 -26
  34. package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
  35. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
  36. package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
  37. package/runtime/__test__/shared/component-stack.test.ts +211 -0
  38. package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
  39. package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
  40. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.event.test.jsx +2 -2
  41. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx +3 -3
  42. package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
  43. package/runtime/__test__/snapshot/preact.test.jsx +0 -3
  44. package/runtime/__test__/snapshot/ref.test.jsx +30 -0
  45. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
  46. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +12 -0
  47. package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
  48. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
  49. package/runtime/lazy/element-template-internal.js +1 -1
  50. package/runtime/lazy/internal.js +1 -1
  51. package/runtime/lazy/jsx-dev-runtime.js +1 -1
  52. package/runtime/lazy/jsx-runtime.js +1 -1
  53. package/runtime/lazy/legacy-react-runtime.js +1 -1
  54. package/runtime/lazy/react-lepus.js +1 -1
  55. package/runtime/lazy/react.js +1 -1
  56. package/runtime/lib/core/capture-main-thread-object.js +2 -1
  57. package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
  58. package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
  59. package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
  60. package/runtime/lib/core/globalProps.js +1 -1
  61. package/runtime/lib/core/globalProps.js.map +1 -1
  62. package/runtime/lib/core/lynx/lazy-bundle.js +1 -1
  63. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  64. package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
  65. package/runtime/lib/core/lynx-data-processors.js +3 -0
  66. package/runtime/lib/core/lynx-data-processors.js.map +1 -1
  67. package/runtime/lib/core/runtime-destroy.js +1 -1
  68. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  69. package/runtime/lib/document.js +0 -5
  70. package/runtime/lib/document.js.map +1 -1
  71. package/runtime/lib/element-template/background/attr-slots.js +5 -2
  72. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  73. package/runtime/lib/element-template/background/commit-hook.js +11 -12
  74. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  75. package/runtime/lib/element-template/background/destroy.js +16 -11
  76. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  77. package/runtime/lib/element-template/background/hydrate.js +23 -0
  78. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  79. package/runtime/lib/element-template/client/root.d.ts +1 -1
  80. package/runtime/lib/element-template/client/root.js.map +1 -1
  81. package/runtime/lib/element-template/debug/alog.d.ts +1 -1
  82. package/runtime/lib/element-template/debug/alog.js +4 -1
  83. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  84. package/runtime/lib/element-template/index.d.ts +2 -2
  85. package/runtime/lib/element-template/index.js.map +1 -1
  86. package/runtime/lib/element-template/internal.d.ts +2 -2
  87. package/runtime/lib/element-template/internal.js +1 -14
  88. package/runtime/lib/element-template/internal.js.map +1 -1
  89. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  90. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js +6 -1
  91. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
  92. package/runtime/lib/element-template/native/flush.d.ts +1 -0
  93. package/runtime/lib/element-template/native/flush.js +9 -0
  94. package/runtime/lib/element-template/native/flush.js.map +1 -0
  95. package/runtime/lib/element-template/native/main-thread-api.js +3 -7
  96. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  97. package/runtime/lib/element-template/native/mts-destroy.js +8 -2
  98. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  99. package/runtime/lib/element-template/native/patch-listener.js +57 -50
  100. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  101. package/runtime/lib/element-template/native/reload-background.js +1 -1
  102. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  103. package/runtime/lib/element-template/native/reload-main-thread.js +35 -10
  104. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  105. package/runtime/lib/element-template/prop-adapters/gesture.d.ts +23 -0
  106. package/runtime/lib/element-template/prop-adapters/gesture.js +97 -0
  107. package/runtime/lib/element-template/prop-adapters/gesture.js.map +1 -0
  108. package/runtime/lib/element-template/prop-adapters/spread.d.ts +6 -1
  109. package/runtime/lib/element-template/prop-adapters/spread.js +72 -2
  110. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  111. package/runtime/lib/element-template/protocol/opcodes.d.ts +1 -0
  112. package/runtime/lib/element-template/protocol/opcodes.js +1 -0
  113. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  114. package/runtime/lib/element-template/protocol/types.d.ts +7 -1
  115. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  116. package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
  117. package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
  118. package/runtime/lib/element-template/runtime/patch.js +31 -2
  119. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  120. package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
  121. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  122. package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
  123. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  124. package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +4 -2
  125. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
  126. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  127. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -1
  128. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  129. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +7 -1
  130. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +380 -50
  131. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  132. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +3 -2
  133. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js +10 -1
  134. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  135. package/runtime/lib/element-template/runtime/template/typed-attributes.js +3 -3
  136. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  137. package/runtime/lib/internal.d.ts +1 -1
  138. package/runtime/lib/internal.js +1 -1
  139. package/runtime/lib/internal.js.map +1 -1
  140. package/runtime/lib/lynx-api.d.ts +2 -125
  141. package/runtime/lib/lynx-api.js.map +1 -1
  142. package/runtime/lib/shared/component-stack.d.ts +0 -4
  143. package/runtime/lib/shared/component-stack.js +21 -5
  144. package/runtime/lib/shared/component-stack.js.map +1 -1
  145. package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
  146. package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
  147. package/runtime/lib/snapshot/lifecycle/destroy.js +23 -17
  148. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  149. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
  150. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
  151. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
  152. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
  153. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  154. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
  155. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  156. package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +5 -0
  157. package/runtime/lib/snapshot/lifecycle/ref/delay.js +1 -1
  158. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  159. package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
  160. package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
  161. package/runtime/lib/snapshot/lynx/calledByNative.js +11 -8
  162. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  163. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
  164. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  165. package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
  166. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  167. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
  168. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  169. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  170. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  171. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  172. package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
  173. package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
  174. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
  175. package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
  176. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
  177. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
  178. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
  179. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +6 -0
  180. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  181. package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
  182. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  183. package/runtime/package.json +2 -3
  184. package/runtime/src/core/capture-main-thread-object.ts +2 -1
  185. package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
  186. package/runtime/src/core/globalProps.ts +1 -1
  187. package/runtime/src/core/lynx/lazy-bundle.ts +1 -1
  188. package/runtime/src/core/lynx-data-processors.ts +124 -1
  189. package/runtime/src/core/runtime-destroy.ts +1 -1
  190. package/runtime/src/document.ts +0 -6
  191. package/runtime/src/element-template/background/attr-slots.ts +5 -1
  192. package/runtime/src/element-template/background/commit-hook.ts +18 -12
  193. package/runtime/src/element-template/background/destroy.ts +16 -13
  194. package/runtime/src/element-template/background/hydrate.ts +23 -0
  195. package/runtime/src/element-template/client/root.ts +1 -3
  196. package/runtime/src/element-template/debug/alog.ts +5 -2
  197. package/runtime/src/element-template/index.ts +2 -2
  198. package/runtime/src/element-template/internal.ts +1 -20
  199. package/runtime/src/element-template/lynx/env.ts +1 -1
  200. package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +5 -1
  201. package/runtime/src/element-template/native/flush.ts +10 -0
  202. package/runtime/src/element-template/native/main-thread-api.ts +3 -6
  203. package/runtime/src/element-template/native/mts-destroy.ts +7 -2
  204. package/runtime/src/element-template/native/patch-listener.ts +62 -57
  205. package/runtime/src/element-template/native/reload-background.ts +1 -1
  206. package/runtime/src/element-template/native/reload-main-thread.ts +32 -11
  207. package/runtime/src/element-template/prop-adapters/gesture.ts +144 -0
  208. package/runtime/src/element-template/prop-adapters/spread.ts +110 -2
  209. package/runtime/src/element-template/protocol/opcodes.ts +1 -0
  210. package/runtime/src/element-template/protocol/types.ts +8 -13
  211. package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
  212. package/runtime/src/element-template/runtime/patch.ts +38 -0
  213. package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
  214. package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
  215. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +31 -4
  216. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
  217. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +456 -50
  218. package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +14 -4
  219. package/runtime/src/element-template/runtime/template/typed-attributes.ts +3 -3
  220. package/runtime/src/element-template/types.d.ts +6 -0
  221. package/runtime/src/internal.ts +1 -1
  222. package/runtime/src/lynx-api.ts +2 -124
  223. package/runtime/src/shared/component-stack.ts +22 -5
  224. package/runtime/src/snapshot/lifecycle/destroy.ts +23 -18
  225. package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
  226. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
  227. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
  228. package/runtime/src/snapshot/lifecycle/ref/delay.ts +1 -1
  229. package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
  230. package/runtime/src/snapshot/lynx/calledByNative.ts +11 -9
  231. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
  232. package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
  233. package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
  234. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
  235. package/runtime/src/worklet-runtime/README.md +30 -10
  236. package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
  237. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
  238. package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +6 -0
  239. package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
  240. package/runtime/types/types.d.ts +2 -1
  241. package/runtime/vitest.config.ts +0 -2
  242. package/testing-library/.turbo/turbo-build.log +7 -7
  243. package/testing-library/src/__tests__/act.test.jsx +0 -7
  244. package/testing-library/src/__tests__/alog.test.jsx +12 -54
  245. package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
  246. package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
  247. package/testing-library/src/__tests__/worklet.test.jsx +49 -0
  248. package/transform/.turbo/turbo-build$colon$wasm.log +133 -297
  249. package/transform/__test__/defines.spec.js +30 -0
  250. package/transform/__test__/fixture.spec.js +11 -11
  251. package/transform/__test__/main-thread-object-compat.spec.js +111 -0
  252. package/transform/__test__/object-methods.spec.js +79 -0
  253. package/transform/crates/swc_plugin_element_template/lib.rs +11 -0
  254. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +113 -0
  255. package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
  256. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +63 -57
  257. package/transform/crates/swc_plugin_worklet/lib.rs +393 -589
  258. package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
  259. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +3 -3
  260. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +3 -3
  261. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +11 -6
  262. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +12 -6
  263. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +14 -5
  264. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +17 -6
  265. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +5 -5
  266. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +5 -5
  267. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +1 -1
  268. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +1 -1
  269. package/transform/dist/wasm.cjs +1 -1
  270. package/transform/package.json +0 -1
  271. package/transform/src/lib.rs +1 -1
  272. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +167 -69
  273. package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
  274. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  275. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +226 -132
  276. package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
  277. package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
  278. package/runtime/lib/snapshot/worklet/hmr.js +0 -28
  279. package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
  280. package/runtime/src/snapshot/worklet/hmr.ts +0 -34
  281. /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
  282. /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
@@ -1,7 +1,10 @@
1
1
  import { afterEach, describe, expect, it, vi } from 'vitest';
2
2
 
3
3
  import { getEventValue } from '../../../../src/element-template/prop-adapters/event-value.js';
4
- import { prepareSpreadAttrSlot } from '../../../../src/element-template/prop-adapters/spread.js';
4
+ import {
5
+ prepareSpreadAttrSlot,
6
+ prepareTypedSpreadAttrSlot,
7
+ } from '../../../../src/element-template/prop-adapters/spread.js';
5
8
 
6
9
  afterEach(() => {
7
10
  lynx.__runtime_configs__ = { transformBuiltinAttributeNames: false };
@@ -74,7 +77,7 @@ describe('ElementTemplate spread prop adapter', () => {
74
77
  __spread: true,
75
78
  ref,
76
79
  bindtap: handleTap,
77
- 'main-thread:bindtap': unsupportedWorkletEvent,
80
+ 'worklet:bindtap': unsupportedWorkletEvent,
78
81
  onReady: unsupportedFunctionProp,
79
82
  },
80
83
  );
@@ -145,16 +148,192 @@ describe('ElementTemplate spread prop adapter', () => {
145
148
  expect(prepareSpreadAttrSlot(-4, 0, false)).toBeNull();
146
149
  });
147
150
 
148
- it('ignores non-host spread props', () => {
151
+ it('ignores non-host spread props and isolates typed host spreads from main-thread capabilities', () => {
149
152
  const prepared = prepareSpreadAttrSlot(-5, 0, {
150
153
  'worklet:ref': vi.fn(),
151
- 'main-thread:ref': vi.fn(),
152
- 'main-thread:bindtap': vi.fn(),
153
- 'main-thread:gesture': {},
154
+ 'worklet:bindtap': vi.fn(),
155
+ 'worklet:gesture': {},
156
+ 'main-thread:custom': () => {},
154
157
  onReady: vi.fn(),
155
158
  title: 'hello',
156
159
  });
157
160
 
158
161
  expect(prepared).toEqual({ title: 'hello' });
162
+
163
+ const typedPrepared = prepareTypedSpreadAttrSlot(-5, 0, {
164
+ 'main-thread:ref': { _wvid: 1 },
165
+ 'main-thread:bindtap': { _wkltId: 'tap' },
166
+ 'main-thread:gesture': { __isGesture: true, id: 1, type: 0, callbacks: {} },
167
+ title: 'typed',
168
+ });
169
+
170
+ expect(typedPrepared).toEqual({ title: 'typed' });
171
+ });
172
+
173
+ it('prepares main-thread events, MTRef, and Gesture in compiled spread slots while ignoring inherited keys', () => {
174
+ const tapWorklet = { _wkltId: 'tap-wklt' };
175
+ const captureCatchWorklet = { _wkltId: 'capture-catch-wklt' };
176
+ const globalWorklet = { _wkltId: 'global-wklt' };
177
+ const mtRef = { _wvid: 9 };
178
+ const panGesture = {
179
+ __isGesture: true,
180
+ id: 3,
181
+ type: 0,
182
+ config: { minDistance: 8 },
183
+ callbacks: { onUpdate: { _wkltId: 'pan-update' } },
184
+ };
185
+
186
+ const rawSpread = Object.assign(
187
+ Object.create({
188
+ 'main-thread:bindinherited': { _wkltId: 'inherited-event' },
189
+ 'main-thread:ref': { _wvid: 99 },
190
+ 'main-thread:gesture': panGesture,
191
+ }) as Record<string, unknown>,
192
+ {
193
+ id: 'card',
194
+ 'main-thread:bindtap': tapWorklet,
195
+ 'main-thread:capture-catchtouchmove': captureCatchWorklet,
196
+ 'main-thread:global-bindCustom': globalWorklet,
197
+ 'main-thread:catchtouchend': null,
198
+ 'main-thread:ref': mtRef,
199
+ 'main-thread:gesture': panGesture,
200
+ },
201
+ );
202
+
203
+ const firstPrepared = prepareSpreadAttrSlot(-6, 1, rawSpread) as Record<string, any>;
204
+ expect(firstPrepared).toMatchObject({
205
+ id: 'card',
206
+ 'main-thread:bindtap': { type: 'worklet', value: { _wkltId: 'tap-wklt' } },
207
+ 'main-thread:capture-catchtouchmove': { type: 'worklet', value: { _wkltId: 'capture-catch-wklt' } },
208
+ 'main-thread:global-bindCustom': { type: 'worklet', value: { _wkltId: 'global-wklt' } },
209
+ 'main-thread:catchtouchend': null,
210
+ 'main-thread:ref': { type: 'main-thread-ref', value: mtRef },
211
+ 'main-thread:gesture': {
212
+ type: 'gesture',
213
+ value: [{ id: 3, type: 0, config: { minDistance: 8 } }],
214
+ },
215
+ });
216
+ expect(firstPrepared).not.toHaveProperty('main-thread:bindinherited');
217
+
218
+ // Re-preparing with identical raw callback identities reuses prepared wrappers.
219
+ const nextRawSpread = { ...rawSpread, id: 'card-next' };
220
+ const secondPrepared = prepareSpreadAttrSlot(-6, 1, nextRawSpread, {
221
+ previousPreparedSlots: [null, firstPrepared],
222
+ previousRawSlots: [null, rawSpread],
223
+ }) as Record<string, any>;
224
+ expect(secondPrepared['main-thread:bindtap']).toBe(firstPrepared['main-thread:bindtap']);
225
+ expect(secondPrepared['main-thread:ref']).toBe(firstPrepared['main-thread:ref']);
226
+ expect(
227
+ secondPrepared['main-thread:gesture'].value[0].callbacks[0].callback,
228
+ ).toBe(firstPrepared['main-thread:gesture'].value[0].callbacks[0].callback);
229
+
230
+ expect(
231
+ prepareSpreadAttrSlot(-6, 1, {
232
+ 'main-thread:ref': undefined,
233
+ 'main-thread:gesture': false,
234
+ 'main-thread:bindtap': undefined,
235
+ }),
236
+ ).toEqual({
237
+ 'main-thread:ref': null,
238
+ 'main-thread:gesture': null,
239
+ 'main-thread:bindtap': null,
240
+ });
241
+
242
+ expect(() => prepareSpreadAttrSlot(-6, 1, { 'main-thread:ref': vi.fn() })).toThrow(
243
+ 'ElementTemplate main-thread:ref expects a MainThreadRef object or a main-thread function.',
244
+ );
245
+ expect(() => prepareSpreadAttrSlot(-6, 1, { 'main-thread:gesture': {} })).toThrow(
246
+ 'ElementTemplate main-thread:gesture expects a Gesture object.',
247
+ );
248
+
249
+ const inheritedOnlySpread = Object.create({
250
+ 'main-thread:ref': mtRef,
251
+ 'main-thread:gesture': panGesture,
252
+ 'main-thread:bindtap': tapWorklet,
253
+ }) as Record<string, unknown>;
254
+ inheritedOnlySpread.id = 'own-only';
255
+ const inheritedPrepared = prepareSpreadAttrSlot(-6, 1, inheritedOnlySpread) as Record<string, any>;
256
+ expect(inheritedPrepared).toEqual({ id: 'own-only' });
257
+
258
+ const addedMtsRaw = {
259
+ id: 'added-mts',
260
+ 'main-thread:ref': mtRef,
261
+ 'main-thread:gesture': panGesture,
262
+ 'main-thread:bindtap': tapWorklet,
263
+ };
264
+ const addedFromEmpty = prepareSpreadAttrSlot(-6, 1, addedMtsRaw, {
265
+ previousPreparedSlots: [null, { id: 'own-only', 'main-thread:gesture': null }],
266
+ previousRawSlots: [null, { id: 'own-only', 'main-thread:gesture': null }],
267
+ }) as Record<string, any>;
268
+ expect(addedFromEmpty['main-thread:ref']).toEqual({ type: 'main-thread-ref', value: mtRef });
269
+ expect(addedFromEmpty['main-thread:gesture']).toMatchObject({ type: 'gesture' });
270
+ expect(addedFromEmpty['main-thread:bindtap']).toMatchObject({ type: 'worklet' });
271
+ });
272
+
273
+ it('reports invalid main-thread event handlers in development and normalizes them to null', () => {
274
+ const oldReportError = lynx.reportError;
275
+ const reportError = vi.fn();
276
+ lynx.reportError = reportError;
277
+ const originalDev = globalThis.__DEV__;
278
+
279
+ try {
280
+ globalThis.__DEV__ = true;
281
+ expect(prepareSpreadAttrSlot(-7, 2, { 'main-thread:bindtap': () => {} })).toEqual({
282
+ 'main-thread:bindtap': null,
283
+ });
284
+ expect(reportError).toHaveBeenCalledTimes(1);
285
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
286
+ 'ElementTemplate main-thread event slot -7:2 (main-thread:bindtap) expects a worklet ctx object.',
287
+ );
288
+
289
+ reportError.mockClear();
290
+ globalThis.__DEV__ = false;
291
+ expect(prepareSpreadAttrSlot(-7, 2, { 'main-thread:bindtap': () => {} })).toEqual({
292
+ 'main-thread:bindtap': null,
293
+ });
294
+ expect(reportError).not.toHaveBeenCalled();
295
+ } finally {
296
+ globalThis.__DEV__ = originalDev;
297
+ lynx.reportError = oldReportError;
298
+ }
299
+ });
300
+
301
+ it('re-prepares MTEvent, MTRef, and Gesture when caller mutates a reused spread object in place', () => {
302
+ const firstTap = { _wkltId: 'first-tap' };
303
+ const nextTap = { _wkltId: 'next-tap' };
304
+ const firstRef = { _wvid: 1 };
305
+ const nextRef = { _wvid: 2 };
306
+ const firstGestureCb = { _wkltId: 'first-pan' };
307
+ const nextGestureCb = { _wkltId: 'next-pan' };
308
+
309
+ const spread: Record<string, any> = {
310
+ id: 'mutable',
311
+ 'main-thread:bindtap': firstTap,
312
+ 'main-thread:ref': firstRef,
313
+ 'main-thread:gesture': {
314
+ __isGesture: true,
315
+ id: 1,
316
+ type: 0,
317
+ callbacks: { onUpdate: firstGestureCb },
318
+ },
319
+ };
320
+
321
+ const firstPrepared = prepareSpreadAttrSlot(1, 0, spread) as Record<string, any>;
322
+
323
+ // Mutate the same spread object and nested gesture callbacks in place.
324
+ spread['main-thread:bindtap'] = nextTap;
325
+ spread['main-thread:ref'] = nextRef;
326
+ spread['main-thread:gesture'].callbacks.onUpdate = nextGestureCb;
327
+
328
+ const secondPrepared = prepareSpreadAttrSlot(1, 0, spread, {
329
+ previousRawSlots: [spread],
330
+ previousPreparedSlots: [firstPrepared],
331
+ }) as Record<string, any>;
332
+
333
+ expect(secondPrepared['main-thread:bindtap']).not.toBe(firstPrepared['main-thread:bindtap']);
334
+ expect(secondPrepared['main-thread:bindtap'].value._wkltId).toBe('next-tap');
335
+ expect(secondPrepared['main-thread:ref']).not.toBe(firstPrepared['main-thread:ref']);
336
+ expect(secondPrepared['main-thread:ref'].value._wvid).toBe(2);
337
+ expect(secondPrepared['main-thread:gesture'].value[0].callbacks[0].callback._wkltId).toBe('next-pan');
159
338
  });
160
339
  });
@@ -512,7 +512,7 @@ describe('direct renderer native contracts', () => {
512
512
  __etAttrPlanMap._et_spread = [0, adaptSpreadAttrSlot];
513
513
 
514
514
  renderToElementTemplate(
515
- h('_et_spread', { attributeSlots: [{ id: 'cta', ref, 'main-thread:ref': vi.fn(), 'worklet:ref': vi.fn() }] }),
515
+ h('_et_spread', { attributeSlots: [{ id: 'cta', ref, 'custom:ref': vi.fn(), 'worklet:ref': vi.fn() }] }),
516
516
  );
517
517
 
518
518
  expect(createElementTemplate).toHaveBeenCalledWith(
@@ -524,4 +524,24 @@ describe('direct renderer native contracts', () => {
524
524
  );
525
525
  expect(ref).not.toHaveBeenCalled();
526
526
  });
527
+
528
+ it('strips spread main-thread:ref from native create while adding layout-only and flatten guards', () => {
529
+ const rootRef = { kind: 'root-ref' };
530
+ const mtRef = { _wvid: 1 };
531
+ createElementTemplate.mockReturnValue(rootRef);
532
+ __etAttrPlanMap['__Card__:_et_spread'] = [0, adaptSpreadAttrSlot];
533
+
534
+ const rendered = renderToElementTemplate(
535
+ h('__Card__:_et_spread', { attributeSlots: [{ id: 'cta', 'main-thread:ref': mtRef }] }),
536
+ );
537
+
538
+ expect(createElementTemplate).toHaveBeenCalledWith(
539
+ '_et_spread',
540
+ null,
541
+ [{ id: 'cta', 'has-react-ref': true, flatten: false }],
542
+ null,
543
+ -1,
544
+ );
545
+ expect(rendered.rootSubtreeHandles).toEqual([[{ uid: -1, ref: rootRef }]]);
546
+ });
527
547
  });
@@ -61,7 +61,10 @@ beforeEach(() => {
61
61
  compiledTemplate: {
62
62
  kind: 'element',
63
63
  type: 'view',
64
- attributesArray: [{ kind: 'slot', key: 'id', attrSlotIndex: 0 }],
64
+ attributesArray: [
65
+ { kind: 'slot', key: 'id', attrSlotIndex: 0 },
66
+ { kind: 'slot', key: 'main-thread:ref', attrSlotIndex: 1 },
67
+ ],
65
68
  },
66
69
  },
67
70
  ]);
@@ -46,7 +46,10 @@ beforeEach(() => {
46
46
  compiledTemplate: {
47
47
  kind: 'element',
48
48
  type: 'view',
49
- attributesArray: [{ kind: 'slot', key: 'id', attrSlotIndex: 0 }],
49
+ attributesArray: [
50
+ { kind: 'slot', key: 'id', attrSlotIndex: 0 },
51
+ { kind: 'slot', key: 'main-thread:ref', attrSlotIndex: 1 },
52
+ ],
50
53
  },
51
54
  },
52
55
  ]);
@@ -15,9 +15,11 @@ import {
15
15
  clearEtAttrPlanMap,
16
16
  } from '../../../../src/element-template/runtime/template/attr-slot-plan.js';
17
17
  import {
18
+ applyPendingMainThreadRefAttachments,
18
19
  clearMainThreadDynamicAttrState,
19
20
  getMainThreadDynamicAttrState,
20
21
  initializeMainThreadDynamicAttrSlots,
22
+ updateMainThreadRefAttrSlot,
21
23
  } from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
22
24
  import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
23
25
 
@@ -50,6 +52,7 @@ describe('renderMainThread', () => {
50
52
  vi.stubGlobal('__InsertNodeToElementTemplate', vi.fn());
51
53
  vi.stubGlobal('__SetAttributeOfElementTemplate', vi.fn());
52
54
  vi.stubGlobal('__SerializeElementTemplate', vi.fn());
55
+ vi.stubGlobal('__FlushElementTree', vi.fn());
53
56
  elementTemplateRegistry.clear();
54
57
  destroyAllElementTemplateListStates();
55
58
  clearMainThreadDynamicAttrState();
@@ -281,6 +284,8 @@ describe('renderMainThread', () => {
281
284
 
282
285
  it('attaches root MTRef state only after page insertion succeeds', () => {
283
286
  const rootRef = { type: 'root-ref' } as unknown as ElementTemplateHandle;
287
+ const target = { type: 'actual-element' } as unknown as ElementRef;
288
+ vi.mocked(__GetElementByAttrSlot).mockReturnValue(target);
284
289
  const ref = { _wvid: 80 };
285
290
  const updateWorkletRef = vi.fn();
286
291
  const previousWorkletImpl = globalThis.lynxWorkletImpl;
@@ -312,7 +317,12 @@ describe('renderMainThread', () => {
312
317
  try {
313
318
  renderMainThread();
314
319
 
315
- expect(updateWorkletRef).toHaveBeenCalledWith(ref, rootRef);
320
+ expect(updateWorkletRef).toHaveBeenCalledWith(ref, target);
321
+ expect(__FlushElementTree).not.toHaveBeenCalled();
322
+ expect(updateWorkletRef.mock.invocationCallOrder[0]).toBeLessThan(
323
+ vi.mocked(__SerializeElementTemplate).mock.invocationCallOrder[0]!,
324
+ );
325
+ expect(updateWorkletRef.mock.invocationCallOrder[0]).toBeLessThan(dispatchEvent.mock.invocationCallOrder[0]!);
316
326
  expect(vi.mocked(__InsertNodeToElementTemplate).mock.invocationCallOrder[0]).toBeLessThan(
317
327
  updateWorkletRef.mock.invocationCallOrder[0]!,
318
328
  );
@@ -325,6 +335,96 @@ describe('renderMainThread', () => {
325
335
  }
326
336
  });
327
337
 
338
+ it('delivers first-screen callback effects before a synchronous hydrate roundtrip', () => {
339
+ const rootRef = {} as ElementTemplateHandle;
340
+ const target = {} as ElementRef;
341
+ const first = { _wkltId: 'ref-callback', initialized: false, delayIndices: [] as number[] };
342
+ const hydrated = { _wkltId: 'ref-callback' };
343
+ const events: string[] = [];
344
+ const previousRunWorklet = globalThis.runWorklet;
345
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
346
+ globalThis.runWorklet = vi.fn().mockImplementationOnce(() => {
347
+ events.push('first attach');
348
+ first.initialized = true;
349
+ first.delayIndices.push(0);
350
+ return () => events.push('first cleanup');
351
+ }).mockImplementation(() => {
352
+ events.push('hydrated attach');
353
+ });
354
+ globalThis.lynxWorkletImpl = {
355
+ ...previousWorkletImpl,
356
+ _hydrateCtx: vi.fn((_next, previous) => {
357
+ expect(previous).toBe(first);
358
+ expect(first.initialized).toBe(true);
359
+ expect(first.delayIndices).toEqual([0]);
360
+ events.push('hydrate context');
361
+ }),
362
+ } as typeof globalThis.lynxWorkletImpl;
363
+ __etAttrPlanMap._et_ref = [0, adaptMTRefAttrSlot];
364
+ initializeMainThreadDynamicAttrSlots(-1, '_et_ref', [{ type: 'main-thread-ref', value: first }]);
365
+ vi.mocked(mockRender).mockReturnValue({
366
+ pageAttributes: null,
367
+ rootRefs: [rootRef],
368
+ rootSubtreeHandles: [[{ uid: -1, ref: rootRef }]],
369
+ });
370
+ vi.mocked(__GetElementByAttrSlot).mockReturnValue(target);
371
+ vi.mocked(__SerializeElementTemplate).mockImplementation(() => {
372
+ events.push('serialize');
373
+ return {} as ReturnType<typeof __SerializeElementTemplate>;
374
+ });
375
+ dispatchEvent.mockImplementation(() => {
376
+ events.push('dispatch hydrate');
377
+ updateMainThreadRefAttrSlot(-1, 0, { type: 'main-thread-ref', value: hydrated }, rootRef, true);
378
+ applyPendingMainThreadRefAttachments();
379
+ });
380
+ try {
381
+ renderMainThread();
382
+ expect(events).toEqual([
383
+ 'first attach',
384
+ 'serialize',
385
+ 'dispatch hydrate',
386
+ 'first cleanup',
387
+ 'hydrate context',
388
+ 'hydrated attach',
389
+ ]);
390
+ clearMainThreadDynamicAttrState();
391
+ } finally {
392
+ globalThis.runWorklet = previousRunWorklet;
393
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
394
+ }
395
+ });
396
+
397
+ it.each(['missing target', 'callback throws'])(
398
+ 'does not serialize or dispatch hydration when first-screen %s',
399
+ failure => {
400
+ const rootRef = {} as ElementTemplateHandle;
401
+ const previousRunWorklet = globalThis.runWorklet;
402
+ globalThis.runWorklet = vi.fn(() => {
403
+ throw new Error('ref callback failed');
404
+ });
405
+ __etAttrPlanMap._et_ref = [0, adaptMTRefAttrSlot];
406
+ initializeMainThreadDynamicAttrSlots(-1, '_et_ref', [{
407
+ type: 'main-thread-ref',
408
+ value: { _wkltId: 'failed-ref' },
409
+ }]);
410
+ vi.mocked(mockRender).mockReturnValue({
411
+ pageAttributes: null,
412
+ rootRefs: [rootRef],
413
+ rootSubtreeHandles: [[{ uid: -1, ref: rootRef }]],
414
+ });
415
+ vi.mocked(__GetElementByAttrSlot).mockReturnValue(failure === 'missing target' ? null : {} as ElementRef);
416
+ try {
417
+ expect(() => renderMainThread()).toThrow(
418
+ failure === 'missing target' ? 'could not be materialized' : 'ref callback failed',
419
+ );
420
+ expect(__SerializeElementTemplate).not.toHaveBeenCalled();
421
+ expect(dispatchEvent).not.toHaveBeenCalled();
422
+ } finally {
423
+ globalThis.runWorklet = previousRunWorklet;
424
+ }
425
+ },
426
+ );
427
+
328
428
  it('keeps root MTRef state blocked when page insertion throws', () => {
329
429
  const rootRef = { type: 'root-ref' } as unknown as ElementTemplateHandle;
330
430
  const ref = { _wvid: 81 };
@@ -23,6 +23,7 @@ import {
23
23
  clearMainThreadDynamicAttrState,
24
24
  getMainThreadDynamicAttrState,
25
25
  } from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
26
+ import { JsFunctionLifecycleManager } from '../../../../src/worklet-runtime/jsFunctionLifecycle.js';
26
27
  import { resetTemplateId } from '../../../../src/element-template/runtime/template/handle.js';
27
28
 
28
29
  describe('ElementTemplateHandle', () => {
@@ -102,6 +103,37 @@ describe('ElementTemplateHandle', () => {
102
103
  });
103
104
  });
104
105
 
106
+ it.each(['success', 'null', 'throw'])(
107
+ 'prepares and tracks create input before Native %s without advancing failed state',
108
+ (outcome) => {
109
+ const previous = globalThis.lynxWorkletImpl;
110
+ const manager = new JsFunctionLifecycleManager();
111
+ globalThis.lynxWorkletImpl = { ...previous, _jsFunctionLifecycleManager: manager };
112
+ const ctx = { _wkltId: 'tap', _execId: 21 };
113
+ const retain = vi.spyOn(manager, 'addRef');
114
+ const error = new Error('create failed');
115
+ __etAttrPlanMap['__Card__:_et_test'] = [0, adaptMTEventAttrSlot];
116
+ mockCreateCompiledElementTemplate.mockImplementationOnce((_key, _url, slots) => {
117
+ expect(slots[0].value).toBe(ctx);
118
+ expect(retain).toHaveBeenCalledExactlyOnceWith(21, ctx);
119
+ expect(getMainThreadDynamicAttrState(-1, 0)).toBeUndefined();
120
+ if (outcome === 'throw') throw error;
121
+ return outcome === 'null' ? null : mockCreatedNativeRef;
122
+ });
123
+ try {
124
+ const create = () =>
125
+ createElementTemplateWithReservedHandle(-1, '_et_test', null, [{ type: 'worklet', value: ctx }], null);
126
+ if (outcome === 'throw') expect(create).toThrow(error);
127
+ else expect(create()).toBe(outcome === 'null' ? null : mockCreatedNativeRef);
128
+ expect(retain).toHaveBeenCalledExactlyOnceWith(21, ctx);
129
+ expect(getMainThreadDynamicAttrState(-1, 0)?.nativeHeldValue).toBe(outcome === 'success' ? ctx : undefined);
130
+ } finally {
131
+ manager.dispose();
132
+ globalThis.lynxWorkletImpl = previous;
133
+ }
134
+ },
135
+ );
136
+
105
137
  it('records dynamic-entry main-thread dynamic attr state with the full template identity', () => {
106
138
  const id = reserveElementTemplateId();
107
139
  const ctx = { _wkltId: 'tap' };