@lynx-js/react 0.126.1 → 0.127.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 (398) hide show
  1. package/CHANGELOG.md +40 -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 +4 -3
  8. package/refresh/.turbo/turbo-build.log +4 -4
  9. package/refresh/dist/index.js +27 -8
  10. package/refresh/package.json +2 -2
  11. package/runtime/__test__/core/main-thread-object.test.js +149 -0
  12. package/runtime/__test__/element-template/debug/profile-installation.test.tsx +97 -1
  13. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -1
  14. package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +26 -3
  15. package/runtime/__test__/element-template/fixtures/render/child-siblings/index.js.txt +15 -11
  16. package/runtime/__test__/element-template/fixtures/render/component/index.js.txt +8 -7
  17. package/runtime/__test__/element-template/fixtures/render/component-slot-content/index.js.txt +14 -10
  18. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/index.js.txt +4 -3
  19. package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/_shared.ts +2 -9
  20. package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/case.ts +2 -4
  21. package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/case.ts +20 -0
  22. package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/case.ts +3 -16
  23. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/case.ts +18 -0
  24. package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/case.ts +20 -0
  25. package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/case.ts +18 -0
  26. package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/case.ts +15 -0
  27. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/index.js.txt +12 -11
  28. package/runtime/__test__/element-template/fixtures/render/mixed-children/index.js.txt +8 -7
  29. package/runtime/__test__/element-template/fixtures/render/multiple-text/index.js.txt +15 -13
  30. package/runtime/__test__/element-template/fixtures/render/nested-templates/index.js.txt +9 -7
  31. package/runtime/__test__/element-template/fixtures/render/react-example/index.js.txt +17 -20
  32. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/index.js.txt +13 -10
  33. package/runtime/__test__/element-template/fixtures/render/template-dedupe/index.js.txt +14 -11
  34. package/runtime/__test__/element-template/imports/main-thread-object-api.test.ts +10 -0
  35. package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +52 -7
  36. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +3 -0
  37. package/runtime/__test__/element-template/native/reload.test.ts +10 -26
  38. package/runtime/__test__/element-template/runtime/background/component-stack.test.tsx +76 -0
  39. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +87 -43
  40. package/runtime/__test__/element-template/runtime/background/instance.test.ts +14 -0
  41. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +4 -0
  42. package/runtime/__test__/element-template/runtime/render/compact-host-debug.test.ts +57 -0
  43. package/runtime/__test__/element-template/runtime/render/compact-host.test.ts +199 -0
  44. package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +292 -0
  45. package/runtime/__test__/element-template/runtime/render/{render-opcodes-into-element-template.et.test.tsx → render-direct-native.test.tsx} +50 -314
  46. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +378 -0
  47. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +491 -0
  48. package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -28
  49. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +21 -35
  50. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -5
  51. package/runtime/__test__/element-template/test-utils/debug/renderFixtureRunner.ts +4 -4
  52. package/runtime/__test__/element-template/vitest.config.ts +2 -1
  53. package/runtime/__test__/snapshot/ctxNotFound.test.ts +271 -0
  54. package/runtime/__test__/snapshot/debug/main-thread-children-with-same-key.test.ts +28 -0
  55. package/runtime/__test__/snapshot/debug/profile.test.jsx +108 -3
  56. package/runtime/__test__/snapshot/event.test.jsx +7 -7
  57. package/runtime/__test__/snapshot/lazy.test.js +114 -7
  58. package/runtime/__test__/snapshot/lifecycle/reloadGc.test.jsx +66 -0
  59. package/runtime/__test__/snapshot/lynx/portals.test.jsx +75 -37
  60. package/runtime/__test__/snapshot/lynx/runtime-version.test.ts +140 -0
  61. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +59 -47
  62. package/runtime/__test__/snapshot/spread.test.jsx +32 -25
  63. package/runtime/__test__/snapshot/ssr.legacy-slot.test.jsx +168 -0
  64. package/runtime/__test__/snapshot/ssr.list.test.jsx +211 -0
  65. package/runtime/__test__/snapshot/worklet/main-thread-object.test.jsx +306 -0
  66. package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +1 -0
  67. package/runtime/__test__/worklet-runtime/hydrate.test.js +92 -0
  68. package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +182 -0
  69. package/runtime/__test__/worklet-runtime/object-methods.test.js +60 -0
  70. package/runtime/__test__/worklet-runtime/runOnBackground.test.js +8 -6
  71. package/runtime/__test__/worklet-runtime/workletRef.test.js +362 -2
  72. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +249 -3
  73. package/runtime/lazy/compat.js +2 -0
  74. package/runtime/lazy/element-template-import.js +0 -4
  75. package/runtime/lazy/element-template-internal.js +19 -8
  76. package/runtime/lazy/element-template-jsx-dev-runtime.js +1 -8
  77. package/runtime/lazy/element-template-jsx-runtime.js +1 -3
  78. package/runtime/lazy/element-template.js +3 -3
  79. package/runtime/lazy/import.js +0 -4
  80. package/runtime/lazy/internal.js +17 -1
  81. package/runtime/lazy/react.js +2 -0
  82. package/runtime/lazy/target.js +0 -21
  83. package/runtime/lib/core/background-function/run-on-background.d.ts +16 -0
  84. package/runtime/lib/core/background-function/run-on-background.js +16 -0
  85. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  86. package/runtime/lib/core/capture-main-thread-object.js +16 -0
  87. package/runtime/lib/core/capture-main-thread-object.js.map +1 -0
  88. package/runtime/lib/core/globalProps.d.ts +2 -0
  89. package/runtime/lib/core/globalProps.js.map +1 -1
  90. package/runtime/lib/core/hooks/react.d.ts +6 -0
  91. package/runtime/lib/core/hooks/react.js +6 -0
  92. package/runtime/lib/core/hooks/react.js.map +1 -1
  93. package/runtime/lib/core/hooks/useLynxGlobalEventListener.d.ts +2 -0
  94. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +2 -0
  95. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
  96. package/runtime/lib/core/initData.d.ts +2 -0
  97. package/runtime/lib/core/initData.js +2 -0
  98. package/runtime/lib/core/initData.js.map +1 -1
  99. package/runtime/lib/core/lynx/runtime-version.d.ts +16 -0
  100. package/runtime/lib/core/lynx/runtime-version.js +51 -0
  101. package/runtime/lib/core/lynx/runtime-version.js.map +1 -0
  102. package/runtime/lib/core/main-thread-object-handle-registry.d.ts +3 -0
  103. package/runtime/lib/core/main-thread-object-handle-registry.js +17 -0
  104. package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -0
  105. package/runtime/lib/core/main-thread-object.d.ts +77 -0
  106. package/runtime/lib/core/main-thread-object.js +261 -0
  107. package/runtime/lib/core/main-thread-object.js.map +1 -0
  108. package/runtime/lib/core/main-thread-ref-id.js +14 -0
  109. package/runtime/lib/core/main-thread-ref-id.js.map +1 -0
  110. package/runtime/lib/core/main-thread-ref-init-value.d.ts +1 -1
  111. package/runtime/lib/core/main-thread-ref-init-value.js +4 -2
  112. package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
  113. package/runtime/lib/core/main-thread-ref.d.ts +4 -0
  114. package/runtime/lib/core/main-thread-ref.js +5 -8
  115. package/runtime/lib/core/main-thread-ref.js.map +1 -1
  116. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  117. package/runtime/lib/element-template/background/document.d.ts +1 -1
  118. package/runtime/lib/element-template/background/document.js +1 -1
  119. package/runtime/lib/element-template/background/document.js.map +1 -1
  120. package/runtime/lib/element-template/background/hydrate.js +51 -19
  121. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  122. package/runtime/lib/element-template/background/instance.js +5 -6
  123. package/runtime/lib/element-template/background/instance.js.map +1 -1
  124. package/runtime/lib/element-template/debug/profile.js +38 -22
  125. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  126. package/runtime/lib/element-template/index.d.ts +3 -1
  127. package/runtime/lib/element-template/index.js +2 -1
  128. package/runtime/lib/element-template/index.js.map +1 -1
  129. package/runtime/lib/element-template/internal.d.ts +5 -1
  130. package/runtime/lib/element-template/internal.js +7 -1
  131. package/runtime/lib/element-template/internal.js.map +1 -1
  132. package/runtime/lib/element-template/native/index.js +4 -0
  133. package/runtime/lib/element-template/native/index.js.map +1 -1
  134. package/runtime/lib/element-template/protocol/types.d.ts +1 -1
  135. package/runtime/lib/element-template/runtime/list/list.d.ts +1 -0
  136. package/runtime/lib/element-template/runtime/list/list.js +3 -0
  137. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  138. package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +7 -0
  139. package/runtime/lib/element-template/runtime/render/create-rendered-host.js +65 -0
  140. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -0
  141. package/runtime/lib/element-template/runtime/render/host.d.ts +18 -0
  142. package/runtime/lib/element-template/runtime/render/host.js +25 -0
  143. package/runtime/lib/element-template/runtime/render/host.js.map +1 -0
  144. package/runtime/lib/element-template/runtime/render/render-components.d.ts +6 -0
  145. package/runtime/lib/element-template/runtime/render/render-components.js +190 -0
  146. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -0
  147. package/runtime/lib/element-template/runtime/render/{render-opcodes.d.ts → render-direct.d.ts} +3 -1
  148. package/runtime/lib/element-template/runtime/render/render-direct.js +194 -0
  149. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -0
  150. package/runtime/lib/element-template/runtime/render/render-main-thread.js +10 -9
  151. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  152. package/runtime/lib/element-template/runtime/template/handle.d.ts +2 -1
  153. package/runtime/lib/element-template/runtime/template/handle.js +12 -4
  154. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  155. package/runtime/lib/element-template/runtime-marker.d.ts +1 -0
  156. package/runtime/lib/element-template/runtime-marker.js +13 -0
  157. package/runtime/lib/element-template/runtime-marker.js.map +1 -0
  158. package/runtime/lib/index.d.ts +1 -1
  159. package/runtime/lib/index.js +1 -1
  160. package/runtime/lib/index.js.map +1 -1
  161. package/runtime/lib/internal.d.ts +4 -1
  162. package/runtime/lib/internal.js +6 -1
  163. package/runtime/lib/internal.js.map +1 -1
  164. package/runtime/lib/lynx-api.d.ts +49 -6
  165. package/runtime/lib/lynx-api.js +34 -4
  166. package/runtime/lib/lynx-api.js.map +1 -1
  167. package/runtime/lib/lynx.js +4 -1
  168. package/runtime/lib/lynx.js.map +1 -1
  169. package/runtime/lib/runtime-marker.d.ts +1 -0
  170. package/runtime/lib/runtime-marker.js +13 -0
  171. package/runtime/lib/runtime-marker.js.map +1 -0
  172. package/runtime/lib/shared/component-stack.js +5 -1
  173. package/runtime/lib/shared/component-stack.js.map +1 -1
  174. package/runtime/lib/snapshot/debug/profileHooks.js +38 -22
  175. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  176. package/runtime/lib/snapshot/lifecycle/patch/error.d.ts +11 -1
  177. package/runtime/lib/snapshot/lifecycle/patch/error.js +24 -16
  178. package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
  179. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.d.ts +1 -1
  180. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +29 -7
  181. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  182. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +2 -2
  183. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  184. package/runtime/lib/snapshot/lifecycle/reload.js +3 -0
  185. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  186. package/runtime/lib/snapshot/lynx/calledByNative.js +3 -0
  187. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  188. package/runtime/lib/snapshot/lynx/children.d.ts +2 -0
  189. package/runtime/lib/snapshot/lynx/children.js.map +1 -1
  190. package/runtime/lib/snapshot/lynx/element.d.ts +10 -0
  191. package/runtime/lib/snapshot/lynx/element.js +6 -0
  192. package/runtime/lib/snapshot/lynx/element.js.map +1 -1
  193. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +2 -1
  194. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  195. package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +2 -0
  196. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +2 -0
  197. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  198. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
  199. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  200. package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -3
  201. package/runtime/lib/worklet-runtime/bindings/bindings.js +9 -1
  202. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  203. package/runtime/lib/worklet-runtime/bindings/types.d.ts +3 -6
  204. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
  205. package/runtime/lib/worklet-runtime/hydrate.js +27 -8
  206. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  207. package/runtime/lib/worklet-runtime/mainThreadObject.d.ts +8 -0
  208. package/runtime/lib/worklet-runtime/mainThreadObject.js +67 -0
  209. package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -0
  210. package/runtime/lib/worklet-runtime/workletRef.d.ts +11 -7
  211. package/runtime/lib/worklet-runtime/workletRef.js +72 -9
  212. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
  213. package/runtime/lib/worklet-runtime/workletRuntime.js +69 -19
  214. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  215. package/runtime/package.json +2 -3
  216. package/runtime/src/core/background-function/run-on-background.ts +16 -0
  217. package/runtime/src/core/capture-main-thread-object.ts +17 -0
  218. package/runtime/src/core/globalProps.ts +2 -0
  219. package/runtime/src/core/hooks/react.ts +6 -0
  220. package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +2 -0
  221. package/runtime/src/core/initData.ts +2 -0
  222. package/runtime/src/core/lynx/runtime-version.ts +62 -0
  223. package/runtime/src/core/main-thread-object-handle-registry.ts +25 -0
  224. package/runtime/src/core/main-thread-object.ts +387 -0
  225. package/runtime/src/core/main-thread-ref-id.ts +16 -0
  226. package/runtime/src/core/main-thread-ref-init-value.ts +12 -4
  227. package/runtime/src/core/main-thread-ref.ts +7 -8
  228. package/runtime/src/element-template/background/commit-hook.ts +1 -1
  229. package/runtime/src/element-template/background/document.ts +3 -3
  230. package/runtime/src/element-template/background/hydrate.ts +61 -29
  231. package/runtime/src/element-template/background/instance.ts +5 -6
  232. package/runtime/src/element-template/debug/profile.ts +48 -36
  233. package/runtime/src/element-template/index.ts +7 -1
  234. package/runtime/src/element-template/internal.ts +14 -1
  235. package/runtime/src/element-template/native/index.ts +4 -0
  236. package/runtime/src/element-template/protocol/types.ts +1 -1
  237. package/runtime/src/element-template/runtime/list/list.ts +4 -0
  238. package/runtime/src/element-template/runtime/render/create-rendered-host.ts +126 -0
  239. package/runtime/src/element-template/runtime/render/host.ts +51 -0
  240. package/runtime/src/element-template/runtime/render/render-components.ts +255 -0
  241. package/runtime/src/element-template/runtime/render/render-direct.ts +275 -0
  242. package/runtime/src/element-template/runtime/render/render-main-thread.ts +10 -9
  243. package/runtime/src/element-template/runtime/template/handle.ts +17 -7
  244. package/runtime/src/element-template/runtime-marker.ts +17 -0
  245. package/runtime/src/index.ts +1 -1
  246. package/runtime/src/internal.ts +11 -1
  247. package/runtime/src/lynx-api.ts +53 -6
  248. package/runtime/src/lynx.ts +5 -1
  249. package/runtime/src/runtime-marker.ts +17 -0
  250. package/runtime/src/shared/component-stack.ts +5 -1
  251. package/runtime/src/snapshot/debug/profileHooks.ts +52 -40
  252. package/runtime/src/snapshot/lifecycle/patch/error.ts +36 -19
  253. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +29 -7
  254. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +2 -2
  255. package/runtime/src/snapshot/lifecycle/reload.ts +4 -0
  256. package/runtime/src/snapshot/lynx/calledByNative.ts +4 -0
  257. package/runtime/src/snapshot/lynx/children.ts +2 -0
  258. package/runtime/src/snapshot/lynx/element.ts +10 -0
  259. package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +2 -1
  260. package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +2 -0
  261. package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +1 -1
  262. package/runtime/src/worklet-runtime/bindings/bindings.ts +17 -2
  263. package/runtime/src/worklet-runtime/bindings/types.ts +7 -11
  264. package/runtime/src/worklet-runtime/hydrate.ts +44 -11
  265. package/runtime/src/worklet-runtime/mainThreadObject.ts +117 -0
  266. package/runtime/src/worklet-runtime/workletRef.ts +120 -19
  267. package/runtime/src/worklet-runtime/workletRuntime.ts +84 -21
  268. package/runtime/types/types.d.ts +2 -0
  269. package/runtime/worklet-runtime/dev.js +155 -30
  270. package/runtime/worklet-runtime/main.js +1 -1
  271. package/testing-library/.turbo/turbo-build.log +12 -12
  272. package/testing-library/dist/env/index.js +2 -2
  273. package/testing-library/dist/index.d.ts +167 -4
  274. package/testing-library/dist/plugins/index.js +1 -1
  275. package/testing-library/dist/pure.js +45 -44
  276. package/testing-library/etc/react-lynx-testing-library.api.md +1 -1
  277. package/testing-library/package.json +4 -3
  278. package/testing-library/src/__tests__/lynx.test.jsx +1 -1
  279. package/testing-library/src/__tests__/reload/reloadGc.test.jsx +64 -0
  280. package/testing-library/src/__tests__/reload/reloadTemplate.js +39 -0
  281. package/testing-library/src/__tests__/worklet.test.jsx +46 -1
  282. package/testing-library/tsconfig.docs.json +9 -0
  283. package/testing-library/typedoc.json +22 -0
  284. package/testing-library/types/entry.d.ts +2 -2
  285. package/transform/.turbo/turbo-build$colon$wasm.log +151 -67
  286. package/transform/__test__/fixture.spec.js +89 -50
  287. package/transform/__test__/object-methods.spec.js +84 -0
  288. package/transform/__test__/text.spec.js +75 -0
  289. package/transform/crates/swc_plugin_compat/lib.rs +4 -3
  290. package/transform/crates/swc_plugin_compat/napi.rs +4 -3
  291. package/transform/crates/swc_plugin_define_dce/napi.rs +1 -1
  292. package/transform/crates/swc_plugin_dynamic_import/lib.rs +105 -3
  293. package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_suffix_webpack_chunk_name.js +5 -0
  294. package/transform/crates/swc_plugin_element_template/host_lowering.rs +111 -0
  295. package/transform/crates/swc_plugin_element_template/lib.rs +41 -5
  296. package/transform/crates/swc_plugin_element_template/lowering.rs +39 -7
  297. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_generate_attribute_slots_for_dynamic_attributes.snap +1 -1
  298. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_background_conditional_attributes.snap +1 -1
  299. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_boolean_and_number_attributes.snap +1 -1
  300. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_complex_text_structure.snap +1 -1
  301. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dataset_attributes.snap +1 -1
  302. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_deeply_nested_user_components.snap +1 -1
  303. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dynamic_class_attributes.snap +1 -1
  304. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_events_lepus.snap +1 -1
  305. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_id_attributes.snap +1 -1
  306. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_inline_styles.snap +1 -1
  307. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_interpolated_text_with_siblings_lepus.snap +1 -1
  308. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_mixed_content.snap +1 -1
  309. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_nested_structure_and_dynamic_content.snap +1 -1
  310. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_refs_lepus.snap +1 -1
  311. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_sibling_user_components.snap +1 -1
  312. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_spread_attributes.snap +1 -1
  313. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_user_component.snap +1 -1
  314. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_isolate_arrays_with_child_slot_placeholder.snap +1 -1
  315. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_keep_code_and_template_attribute_slots_in_sync_for_spread.snap +1 -1
  316. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_element_template_simple_lepus.snap +1 -1
  317. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_template_with_static_attributes.snap +1 -1
  318. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_template_structure_complex.snap +1 -1
  319. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_text_attribute_and_child_text_slots.snap +1 -1
  320. package/transform/crates/swc_plugin_element_template/tests/element_template.rs +70 -66
  321. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +94 -8
  322. package/transform/crates/swc_plugin_shake/lib.rs +1 -1
  323. package/transform/crates/swc_plugin_shake/napi.rs +1 -1
  324. package/transform/crates/swc_plugin_text/lib.rs +57 -16
  325. package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_keep_children_for_dynamic_or_multiple_text.js +13 -0
  326. package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_transform_string_expressions_to_text_attr.js +13 -0
  327. package/transform/crates/swc_plugin_worklet/decl_collect.rs +10 -0
  328. package/transform/crates/swc_plugin_worklet/extract_ident.rs +14 -0
  329. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +202 -3
  330. package/transform/crates/swc_plugin_worklet/lib.rs +468 -3
  331. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +8 -1
  332. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +10 -5
  333. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_js.js +27 -0
  334. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +45 -0
  335. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +16 -14
  336. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +16 -16
  337. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +7 -5
  338. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +7 -7
  339. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +24 -0
  340. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +16 -0
  341. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +42 -0
  342. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +58 -0
  343. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +3 -1
  344. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +3 -3
  345. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_js.js +9 -0
  346. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +16 -0
  347. package/transform/crates/swc_plugins_shared/jsx_helpers.rs +8 -4
  348. package/transform/dist/wasm.cjs +1 -1
  349. package/transform/index.d.ts +7 -6
  350. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
  351. package/transform/src/swc_plugin_extract_str/mod.rs +1 -1
  352. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +63 -270
  353. package/transform/swc-plugin-reactlynx/index.d.ts +2 -2
  354. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  355. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +306 -170
  356. package/transform/swc-plugin-reactlynx-compat/index.d.ts +3 -3
  357. package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
  358. package/transform/vitest.config.ts +5 -1
  359. package/types/react.docs.d.ts +130 -11
  360. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/case.ts +0 -39
  361. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/case.ts +0 -29
  362. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/case.ts +0 -42
  363. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/case.ts +0 -31
  364. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/passes-bundle-url-to-native-create/case.ts +0 -20
  365. package/runtime/__test__/element-template/runtime/render/render-to-opcodes.et.test.jsx +0 -522
  366. package/runtime/lib/element-template/runtime/render/render-opcodes.js +0 -216
  367. package/runtime/lib/element-template/runtime/render/render-opcodes.js.map +0 -1
  368. package/runtime/lib/element-template/runtime/render/render-to-opcodes.d.ts +0 -16
  369. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js +0 -324
  370. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js.map +0 -1
  371. package/runtime/lib/element-template/runtime-backend-marker.js +0 -6
  372. package/runtime/lib/element-template/runtime-backend-marker.js.map +0 -1
  373. package/runtime/lib/runtime-backend-marker.js +0 -6
  374. package/runtime/lib/runtime-backend-marker.js.map +0 -1
  375. package/runtime/src/element-template/runtime/render/render-opcodes.ts +0 -313
  376. package/runtime/src/element-template/runtime/render/render-to-opcodes.ts +0 -411
  377. package/runtime/src/element-template/runtime-backend-marker.ts +0 -7
  378. package/runtime/src/runtime-backend-marker.ts +0 -7
  379. package/testing-library/node_modules/.bin/rsbuild +0 -55
  380. package/testing-library/node_modules/.bin/rspeedy +0 -55
  381. package/testing-library/node_modules/.bin/rstest +0 -55
  382. package/transform/node_modules/.bin/esbuild +0 -46
  383. package/transform/node_modules/.bin/napi +0 -55
  384. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/native-log.txt +0 -0
  385. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/output.txt +0 -0
  386. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/native-log.txt +0 -0
  387. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/output.txt +0 -0
  388. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/native-log.txt +0 -0
  389. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/output.txt +0 -0
  390. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +0 -0
  391. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/output.txt +0 -0
  392. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/native-log.txt +0 -0
  393. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/output.txt +0 -0
  394. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/native-log.txt +0 -0
  395. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/output.txt +0 -0
  396. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/passes-bundle-url-to-native-create/native-log.txt +0 -0
  397. /package/runtime/lib/{element-template/runtime-backend-marker.d.ts → core/capture-main-thread-object.d.ts} +0 -0
  398. /package/runtime/lib/{runtime-backend-marker.d.ts → core/main-thread-ref-id.d.ts} +0 -0
@@ -56,8 +56,10 @@ const sExportsLegacyReactRuntime = Symbol.for(
56
56
  '__REACT_LYNX_EXPORTS__(@lynx-js/react/legacy-react-runtime)',
57
57
  );
58
58
  const sRuntimeBackend = Symbol.for('__REACT_LYNX_RUNTIME_BACKEND__');
59
+ const sRuntimeVersion = Symbol.for('__REACT_LYNX_RUNTIME_VERSION__');
59
60
  const lazyTargetSymbols = [
60
61
  sRuntimeBackend,
62
+ sRuntimeVersion,
61
63
  sExportsReact,
62
64
  sExportsReactCompat,
63
65
  sExportsReactLepus,
@@ -118,6 +120,30 @@ function clearLazyTargetSymbols(): void {
118
120
  }
119
121
  }
120
122
 
123
+ async function withRuntimeVersion(
124
+ version: string,
125
+ callback: () => Promise<void>,
126
+ ): Promise<void> {
127
+ const target = globalThis as typeof globalThis & {
128
+ __RUNTIME_VERSION__?: string;
129
+ };
130
+ const descriptor = Object.getOwnPropertyDescriptor(target, '__RUNTIME_VERSION__');
131
+ Object.defineProperty(target, '__RUNTIME_VERSION__', {
132
+ value: version,
133
+ configurable: true,
134
+ });
135
+
136
+ try {
137
+ await callback();
138
+ } finally {
139
+ if (descriptor) {
140
+ Object.defineProperty(target, '__RUNTIME_VERSION__', descriptor);
141
+ } else {
142
+ delete target.__RUNTIME_VERSION__;
143
+ }
144
+ }
145
+ }
146
+
121
147
  describe('element-template Suspense and lazy imports', () => {
122
148
  let originalQueryComponent: LynxWithDynamicImportMocks['QueryComponent'];
123
149
  let originalRequireModuleAsync: LynxWithDynamicImportMocks['requireModuleAsync'];
@@ -175,6 +201,30 @@ describe('element-template Suspense and lazy imports', () => {
175
201
  expect('snapshotCreatorMap' in ElementTemplateInternal).toBe(false);
176
202
  });
177
203
 
204
+ it('records a stamped runtime version from the ET runtime marker', async () => {
205
+ clearLazyTargetSymbols();
206
+
207
+ await withRuntimeVersion('1.2.0', async () => {
208
+ vi.resetModules();
209
+ await import('../../../src/element-template/runtime-marker.js');
210
+
211
+ expect(ElementTemplateInternal.getRuntimeVersion()).toBe('1.2.0');
212
+ });
213
+ });
214
+
215
+ it('records a stamped runtime version from the standalone ET lazy import', async () => {
216
+ clearLazyTargetSymbols();
217
+ vi.resetModules();
218
+ await import('../../../lazy/element-template-import.js');
219
+
220
+ await withRuntimeVersion('1.2.0', async () => {
221
+ vi.resetModules();
222
+ await import('../../../lazy/element-template-internal.js');
223
+
224
+ expect(ElementTemplateInternal.getRuntimeVersion()).toBe('1.2.0');
225
+ });
226
+ });
227
+
178
228
  it('routes ET component dynamic imports through loadLazyBundle', async () => {
179
229
  const QueryComponent = vi.fn((source: string, callback: QueryComponentCallback) => {
180
230
  callback({ code: 0, detail: { schema: source } });
@@ -273,12 +323,7 @@ describe('element-template Suspense and lazy imports', () => {
273
323
  expect(Object.getOwnPropertyDescriptors(lynx.getApp())).toEqual(appDescriptors);
274
324
  });
275
325
 
276
- it.each([
277
- '../../../lazy/element-template.js',
278
- '../../../lazy/element-template-internal.js',
279
- '../../../lazy/element-template-jsx-runtime.js',
280
- '../../../lazy/element-template-jsx-dev-runtime.js',
281
- ])('rejects a Snapshot host before reading exports from %s', async (entry) => {
326
+ it('rejects a Snapshot host before reading exports from element-template-import.js', async () => {
282
327
  clearLazyTargetSymbols();
283
328
  vi.resetModules();
284
329
  Object.defineProperty(lynx, sRuntimeBackend, {
@@ -287,7 +332,7 @@ describe('element-template Suspense and lazy imports', () => {
287
332
  });
288
333
  const appDescriptors = Object.getOwnPropertyDescriptors(lynx.getApp());
289
334
 
290
- await expect(import(entry)).rejects.toThrow(
335
+ await expect(import('../../../lazy/element-template-import.js')).rejects.toThrow(
291
336
  'Snapshot and Element Template templates cannot share lazy bundles.',
292
337
  );
293
338
  expect(Object.getOwnPropertyDescriptors(lynx.getApp())).toEqual(appDescriptors);
@@ -22,6 +22,9 @@ describe('legacy internal guardrail', () => {
22
22
  expect(ElementTemplateInternal.loadWorkletRuntime).toBeTypeOf('function');
23
23
  expect('loadWorkletRuntime' in ElementTemplateRuntime).toBe(false);
24
24
 
25
+ expect(ElementTemplateInternal.captureMainThreadObject({ value: 1 })).toBeUndefined();
26
+ expect('captureMainThreadObject' in ElementTemplateRuntime).toBe(false);
27
+
25
28
  expect(ElementTemplateInternal.registerWorkletOnBackground).toBeTypeOf('function');
26
29
  expect(() => ElementTemplateInternal.registerWorkletOnBackground('main-thread', 'hash', () => {})).not.toThrow();
27
30
  expect('registerWorkletOnBackground' in ElementTemplateRuntime).toBe(false);
@@ -27,8 +27,7 @@ import {
27
27
  clearEtAttrPlanMap,
28
28
  } from '../../../src/element-template/runtime/template/attr-slot-plan.js';
29
29
  import { renderMainThread } from '../../../src/element-template/runtime/render/render-main-thread.js';
30
- import { render as mockRender } from '../../../src/element-template/runtime/render/render-to-opcodes.js';
31
- import { renderOpcodesIntoElementTemplate as mockRenderOpcodesIntoElementTemplate } from '../../../src/element-template/runtime/render/render-opcodes.js';
30
+ import { renderToElementTemplate as mockRender } from '../../../src/element-template/runtime/render/render-direct.js';
32
31
  import { render as preactRender } from 'preact';
33
32
 
34
33
  const mockedState = vi.hoisted(() => ({
@@ -59,13 +58,8 @@ vi.mock('../../../src/element-template/runtime/page/root-instance.js', () => ({
59
58
  }),
60
59
  }));
61
60
 
62
- vi.mock('../../../src/element-template/runtime/render/render-to-opcodes.js', () => ({
63
- render: vi.fn(),
64
- registerSlot: vi.fn(),
65
- }));
66
-
67
- vi.mock('../../../src/element-template/runtime/render/render-opcodes.js', () => ({
68
- renderOpcodesIntoElementTemplate: vi.fn(),
61
+ vi.mock('../../../src/element-template/runtime/render/render-direct.js', () => ({
62
+ renderToElementTemplate: vi.fn(),
69
63
  }));
70
64
 
71
65
  vi.mock('../../../src/element-template/runtime/template/registry.js', () => ({
@@ -181,7 +175,6 @@ describe('ElementTemplate reloadMainThread', () => {
181
175
  childSlots: [[oldSerializedRoot]],
182
176
  uid: 0,
183
177
  };
184
- const opcodes = [0, 'opcode'];
185
178
  const rootRef = { type: 'ref-a' } as unknown as ElementTemplateHandle;
186
179
  const serializedRoot = {
187
180
  templateKey: '_et_reload',
@@ -224,8 +217,7 @@ describe('ElementTemplate reloadMainThread', () => {
224
217
  attachMainThreadDynamicAttrRefsForSubtree([{ uid: -1, ref: oldRootRef }]);
225
218
  expect(getMainThreadDynamicAttrState(-1, 0)).toBeDefined();
226
219
  expect(getMainThreadDynamicAttrState(-1, 1)).toBeDefined();
227
- vi.mocked(mockRender).mockReturnValueOnce(['old-opcode']);
228
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValueOnce({
220
+ vi.mocked(mockRender).mockReturnValueOnce({
229
221
  pageAttributes: { id: 'background' },
230
222
  rootRefs: [oldRootRef],
231
223
  rootSubtreeHandles: [[]],
@@ -243,10 +235,8 @@ describe('ElementTemplate reloadMainThread', () => {
243
235
  vi.mocked(__SetAttributeOfElementTemplate).mockClear();
244
236
  vi.mocked(__SerializeElementTemplate).mockClear();
245
237
  vi.mocked(mockRender).mockClear();
246
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockClear();
247
238
  dispatchEvent.mockClear();
248
- vi.mocked(mockRender).mockReturnValue(opcodes);
249
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
239
+ vi.mocked(mockRender).mockReturnValue({
250
240
  pageAttributes: null,
251
241
  rootRefs: [rootRef],
252
242
  rootSubtreeHandles: [[]],
@@ -279,7 +269,6 @@ describe('ElementTemplate reloadMainThread', () => {
279
269
  expect(__root.__jsx).toBe(jsx);
280
270
  expect(__root).not.toHaveProperty('stale');
281
271
  expect(mockRender).toHaveBeenCalledWith(jsx, undefined);
282
- expect(mockRenderOpcodesIntoElementTemplate).toHaveBeenCalledWith(opcodes);
283
272
  expect(__InsertNodeToElementTemplate).toHaveBeenCalledWith(page, 0, rootRef, null);
284
273
  expect(__SerializeElementTemplate).toHaveBeenCalledTimes(2);
285
274
  expect(__SerializeElementTemplate).toHaveBeenNthCalledWith(1, page);
@@ -308,8 +297,7 @@ describe('ElementTemplate reloadMainThread', () => {
308
297
 
309
298
  it('rebuilds when the physical page has no root slot', () => {
310
299
  mockedState.root = { __jsx: null };
311
- vi.mocked(mockRender).mockReturnValue([]);
312
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
300
+ vi.mocked(mockRender).mockReturnValue({
313
301
  pageAttributes: null,
314
302
  rootRefs: [],
315
303
  rootSubtreeHandles: [],
@@ -347,8 +335,7 @@ describe('ElementTemplate reloadMainThread', () => {
347
335
  },
348
336
  } as typeof globalThis.lynxWorkletImpl;
349
337
  mockedState.root = { __jsx: null };
350
- vi.mocked(mockRender).mockReturnValue([]);
351
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
338
+ vi.mocked(mockRender).mockReturnValue({
352
339
  pageAttributes: null,
353
340
  rootRefs: [],
354
341
  rootSubtreeHandles: [],
@@ -369,8 +356,7 @@ describe('ElementTemplate reloadMainThread', () => {
369
356
  mockedState.page = { type: 'page', id: '0', children: [] };
370
357
  const ctx = { _wkltId: 'new' };
371
358
  const rootRef = { type: 'ref-a' } as unknown as ElementTemplateHandle;
372
- vi.mocked(mockRender).mockReturnValue(['opcode']);
373
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockImplementationOnce(() => {
359
+ vi.mocked(mockRender).mockImplementationOnce(() => {
374
360
  __etAttrPlanMap._et_reload = [0, adaptMTEventAttrSlot];
375
361
  initializeMainThreadDynamicAttrSlots(
376
362
  -2,
@@ -494,8 +480,7 @@ describe('ElementTemplate reloadMainThread', () => {
494
480
  mockedState.root = { __jsx: { type: 'App' } };
495
481
  lynx.__initData = { stale: true, msg: 'init' };
496
482
  mockedState.page = { type: 'page', id: '0', children: [] };
497
- vi.mocked(mockRender).mockReturnValue([]);
498
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
483
+ vi.mocked(mockRender).mockReturnValue({
499
484
  pageAttributes: null,
500
485
  rootRefs: [],
501
486
  rootSubtreeHandles: [],
@@ -509,8 +494,7 @@ describe('ElementTemplate reloadMainThread', () => {
509
494
  it('profiles main-thread reload when profiling is enabled', () => {
510
495
  vi.stubGlobal('__PROFILE__', true);
511
496
  mockedState.root = { __jsx: null };
512
- vi.mocked(mockRender).mockReturnValue([]);
513
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
497
+ vi.mocked(mockRender).mockReturnValue({
514
498
  pageAttributes: null,
515
499
  rootRefs: [],
516
500
  rootSubtreeHandles: [],
@@ -0,0 +1,76 @@
1
+ import { options } from 'preact';
2
+ import type { ComponentChildren } from 'preact';
3
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
4
+
5
+ import { installElementTemplateHydrationListener } from '../../../../src/element-template/background/hydration-listener.js';
6
+ import { isElementTemplateRendering } from '../../../../src/element-template/background/render-scope.js';
7
+ import { injectCalledByNative } from '../../../../src/element-template/native/main-thread-api.js';
8
+ import { ElementTemplateEnvManager } from '../../test-utils/debug/envManager.js';
9
+
10
+ describe('ElementTemplate background component stack', () => {
11
+ const envManager = new ElementTemplateEnvManager();
12
+
13
+ beforeEach(() => {
14
+ vi.clearAllMocks();
15
+ envManager.resetEnv('background');
16
+ });
17
+
18
+ it('reports component owners for circular attributes in hydrated background updates', async () => {
19
+ const scheduledRenders: Array<() => void> = [];
20
+ const previousDebounce = options.debounceRendering;
21
+ const previousProfile = globalThis.__PROFILE__;
22
+ const dispatchEvent = vi.spyOn(lynx.getCoreContext(), 'dispatchEvent');
23
+ options.debounceRendering = callback => scheduledRenders.push(callback);
24
+ globalThis.__PROFILE__ = false;
25
+ const { root, useState } = await import('../../../../src/element-template/index.js');
26
+ const { renderCompiledFixtureOnMainThread } = await import('../../test-utils/debug/compiledThreadRunner.js');
27
+ let updateValue: (value: Record<string, unknown>) => void;
28
+
29
+ function PassThrough({ children }: { children: ComponentChildren }) {
30
+ return children;
31
+ }
32
+
33
+ function AttributeOwner() {
34
+ const [value, setValue] = useState<Record<string, unknown>>({ count: 0 });
35
+ if (__BACKGROUND__) updateValue = setValue;
36
+ return (
37
+ <view>
38
+ <text>prefix</text>
39
+ <view data-value={value} />
40
+ </view>
41
+ );
42
+ }
43
+
44
+ function App() {
45
+ return (
46
+ <PassThrough>
47
+ <AttributeOwner />
48
+ </PassThrough>
49
+ );
50
+ }
51
+
52
+ try {
53
+ installElementTemplateHydrationListener();
54
+ injectCalledByNative();
55
+ root.render(<App />);
56
+ renderCompiledFixtureOnMainThread({ App }, envManager);
57
+ dispatchEvent.mockClear();
58
+
59
+ updateValue!({ count: 1 });
60
+ scheduledRenders.shift()!();
61
+ expect(isElementTemplateRendering()).toBe(false);
62
+ expect(dispatchEvent).toHaveBeenCalled();
63
+
64
+ const circular: Record<string, unknown> = {};
65
+ circular['self'] = circular;
66
+ updateValue!(circular);
67
+ expect(() => scheduledRenders.shift()!()).toThrowError(
68
+ /Converting circular structure to JSON[\s\S]*in AttributeOwner\n in App\n/,
69
+ );
70
+ } finally {
71
+ options.debounceRendering = previousDebounce;
72
+ globalThis.__PROFILE__ = previousProfile;
73
+ dispatchEvent.mockRestore();
74
+ }
75
+ });
76
+ });
@@ -212,13 +212,13 @@ describe('hydrate', () => {
212
212
  expect(stream).toEqual([]);
213
213
  });
214
214
 
215
- it('forces MTRef hydrate clears when native serialization already contains null', () => {
215
+ it.each([null, undefined])('forces MTRef hydrate clears when native serialization contains %s', (before) => {
216
216
  __etAttrPlanMap.root = [0, adaptMTRefAttrSlot];
217
217
  const root = new BackgroundElementTemplateInstance('root', [null]);
218
218
 
219
219
  const stream = hydrate(
220
220
  createHydrationTemplate(root.instanceId, 'root', {
221
- attributeSlots: [null],
221
+ attributeSlots: [before],
222
222
  }),
223
223
  root,
224
224
  );
@@ -1206,41 +1206,51 @@ describe('hydrate', () => {
1206
1206
  (globalThis as { __LYNX_REPORT_ERROR_CALLS?: Error[] }).__LYNX_REPORT_ERROR_CALLS = [];
1207
1207
  });
1208
1208
 
1209
- it('drops the hydrate stream when a matched child fails to hydrate', () => {
1210
- const oldReportError = lynx.reportError;
1211
- const reportError = vi.fn();
1212
- lynx.reportError = reportError;
1213
-
1214
- try {
1215
- const root = new BackgroundElementTemplateInstance('root', ['after-root']);
1216
- const child = new BackgroundElementTemplateInstance('child');
1217
- root.appendChild(child);
1218
- const oldRootId = root.instanceId;
1219
- const oldChildId = child.instanceId;
1220
-
1221
- const stream = hydrate(
1222
- createHydrationTemplate(-1, 'root', {
1223
- attributeSlots: ['before-root'],
1224
- childSlots: [[
1225
- createHydrationChild(-1, 'child'),
1226
- ]],
1227
- }),
1228
- root,
1229
- );
1230
-
1231
- expect(stream).toEqual([]);
1232
- expect(reportError).toHaveBeenCalledTimes(1);
1233
- expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
1234
- 'invalid uid -1 for \'child\'',
1235
- );
1236
- expect(backgroundElementTemplateInstanceManager.get(oldRootId)).toBeUndefined();
1237
- expect(backgroundElementTemplateInstanceManager.get(-1)).toBe(root);
1238
- expect(backgroundElementTemplateInstanceManager.get(oldChildId)).toBe(child);
1239
- } finally {
1240
- lynx.reportError = oldReportError;
1241
- (globalThis as { __LYNX_REPORT_ERROR_CALLS?: Error[] }).__LYNX_REPORT_ERROR_CALLS = [];
1242
- }
1243
- });
1209
+ it.each(['matching', 'reordered'])(
1210
+ 'drops the hydrate stream when a matched child fails with %s siblings',
1211
+ (order) => {
1212
+ const oldReportError = lynx.reportError;
1213
+ const reportError = vi.fn();
1214
+ lynx.reportError = reportError;
1215
+
1216
+ try {
1217
+ const root = new BackgroundElementTemplateInstance('root', ['after-root']);
1218
+ const child = new BackgroundElementTemplateInstance('child');
1219
+ const sibling = new BackgroundElementTemplateInstance('sibling');
1220
+ root.appendChild(child);
1221
+ root.appendChild(sibling);
1222
+ const serializedChildren = [
1223
+ createHydrationChild(-1, 'child'),
1224
+ createHydrationChild(-10, 'sibling'),
1225
+ ];
1226
+ if (order === 'reordered') {
1227
+ serializedChildren.reverse();
1228
+ }
1229
+ const oldRootId = root.instanceId;
1230
+ const oldChildId = child.instanceId;
1231
+
1232
+ const stream = hydrate(
1233
+ createHydrationTemplate(-1, 'root', {
1234
+ attributeSlots: ['before-root'],
1235
+ childSlots: [serializedChildren],
1236
+ }),
1237
+ root,
1238
+ );
1239
+
1240
+ expect(stream).toEqual([]);
1241
+ expect(reportError).toHaveBeenCalledTimes(1);
1242
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
1243
+ 'invalid uid -1 for \'child\'',
1244
+ );
1245
+ expect(backgroundElementTemplateInstanceManager.get(oldRootId)).toBeUndefined();
1246
+ expect(backgroundElementTemplateInstanceManager.get(-1)).toBe(root);
1247
+ expect(backgroundElementTemplateInstanceManager.get(oldChildId)).toBe(child);
1248
+ } finally {
1249
+ lynx.reportError = oldReportError;
1250
+ (globalThis as { __LYNX_REPORT_ERROR_CALLS?: Error[] }).__LYNX_REPORT_ERROR_CALLS = [];
1251
+ }
1252
+ },
1253
+ );
1244
1254
 
1245
1255
  it('treats missing serialized slot arrays as empty', () => {
1246
1256
  const root = new BackgroundElementTemplateInstance('root');
@@ -1299,18 +1309,52 @@ describe('hydrate', () => {
1299
1309
  expect(stream).toEqual([]);
1300
1310
  });
1301
1311
 
1302
- it('does not patch serialized null when the background attribute slot is missing', () => {
1303
- const root = new BackgroundElementTemplateInstance('root');
1312
+ it.each([
1313
+ { before: [null], after: [] },
1314
+ { before: [], after: [null] },
1315
+ { before: [undefined], after: [undefined] },
1316
+ { before: [undefined], after: [null] },
1317
+ { before: [null], after: [undefined] },
1318
+ ])('does not patch absent hydration slots: $before -> $after', ({ before, after }) => {
1319
+ const root = new BackgroundElementTemplateInstance('root', after);
1320
+ const stream = hydrate(
1321
+ createHydrationTemplate(root.instanceId, 'root', { attributeSlots: before }),
1322
+ root,
1323
+ );
1324
+ expect(stream).toEqual([]);
1325
+ expect(root.attributeSlots).toEqual(after.map(value => value ?? null));
1326
+ });
1304
1327
 
1328
+ it('preserves real changes and removals around absent hydration slots', () => {
1329
+ const root = new BackgroundElementTemplateInstance('root', [undefined, 0, false, '', '1']);
1305
1330
  const stream = hydrate(
1306
1331
  createHydrationTemplate(root.instanceId, 'root', {
1307
- attributeSlots: [null],
1332
+ attributeSlots: ['remove', undefined, null, undefined, 1],
1308
1333
  }),
1309
1334
  root,
1310
1335
  );
1311
-
1312
- expect(stream).toEqual([]);
1313
- expect(root.attributeSlots).toEqual([]);
1336
+ expect(stream).toEqual([
1337
+ ElementTemplateUpdateOps.setAttribute,
1338
+ root.instanceId,
1339
+ 0,
1340
+ null,
1341
+ ElementTemplateUpdateOps.setAttribute,
1342
+ root.instanceId,
1343
+ 1,
1344
+ 0,
1345
+ ElementTemplateUpdateOps.setAttribute,
1346
+ root.instanceId,
1347
+ 2,
1348
+ false,
1349
+ ElementTemplateUpdateOps.setAttribute,
1350
+ root.instanceId,
1351
+ 3,
1352
+ '',
1353
+ ElementTemplateUpdateOps.setAttribute,
1354
+ root.instanceId,
1355
+ 4,
1356
+ '1',
1357
+ ]);
1314
1358
  });
1315
1359
 
1316
1360
  it('skips sparse background slot indexes when checking trailing slots', () => {
@@ -203,6 +203,20 @@ describe('BackgroundElementTemplateInstance', () => {
203
203
  expect(doc.createElement('_et_item')).not.toBeInstanceOf(BackgroundTypedElementTemplateInstance);
204
204
  });
205
205
 
206
+ it.each([0, 1500, -3.5, '1500', ''])('hydrates document text %j without rewriting unchanged content', (value) => {
207
+ const doc = setupBackgroundElementTemplateDocument();
208
+ const text = doc.createTextNode(value);
209
+ const serialized = { templateKey: BUILTIN_RAW_TEXT_TEMPLATE_KEY, uid: -10, attributeSlots: [String(value)] };
210
+ expect(hydrateBackground(serialized, text)).toEqual([]);
211
+ expect(text.attributeSlots).toEqual([String(value)]);
212
+ markElementTemplateHydrated();
213
+ globalCommitContext.ops = [];
214
+ text.data = String(value);
215
+ expect(globalCommitContext.ops).toEqual([]);
216
+ text.data = 'changed';
217
+ expect(globalCommitContext.ops).toEqual([ElementTemplateUpdateOps.setAttribute, -10, 0, 'changed']);
218
+ });
219
+
206
220
  it('emits exact list create as typed holder with logical children in command options', () => {
207
221
  const list = new BackgroundListElementTemplateInstance();
208
222
  const item = new BackgroundElementTemplateInstance('_et_list_item');
@@ -174,12 +174,16 @@ describe('Compiled runOnMainThread background fixtures', () => {
174
174
  });
175
175
 
176
176
  expect(backgroundArtifact.code).toContain('runOnMainThread');
177
+ expect(backgroundArtifact.code).toContain('captureMainThreadObject');
178
+ expect(backgroundArtifact.code).toContain('defineMainThreadObjectType');
179
+ expect(backgroundArtifact.code).toContain('useMainThreadObject');
177
180
  expect(backgroundArtifact.code).toContain('from \'@lynx-js/react\'');
178
181
  expect(backgroundArtifact.code).not.toContain('snapshot/');
179
182
  expect(backgroundArtifact.code).not.toContain('__globalSnapshotPatch');
180
183
  expect(backgroundArtifact.code).not.toContain('PatchList');
181
184
  expect(backgroundArtifact.code).not.toContain('isRendering');
182
185
  expect(mainArtifact.code).toContain('loadWorkletRuntime');
186
+ expect(mainArtifact.code).toContain('element-template-formatter');
183
187
  expect(mainArtifact.code).toContain('registerWorkletInternal("main-thread"');
184
188
  expect(mainArtifact.code).not.toContain('snapshot/');
185
189
  });
@@ -0,0 +1,57 @@
1
+ import 'preact/debug';
2
+ import { expect, it, vi } from 'vitest';
3
+
4
+ import { __etHost } from '../../../../src/element-template/runtime/render/host.js';
5
+ import { renderToElementTemplate } from '../../../../src/element-template/runtime/render/render-direct.js';
6
+ import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
7
+ import { registerTemplates } from '../../test-utils/debug/registry.js';
8
+
9
+ it.each(
10
+ [
11
+ [undefined, false],
12
+ [undefined, true],
13
+ [true, false],
14
+ [true, true],
15
+ ] as const,
16
+ )('preact/debug - plain=%s children with duplicate keys: %s', (plain, duplicate) => {
17
+ globalThis.__MAIN_THREAD__ = true;
18
+ globalThis.__BACKGROUND__ = false;
19
+ elementTemplateRegistry.clear();
20
+ registerTemplates([
21
+ {
22
+ templateId: '_et_debug_root',
23
+ compiledTemplate: {
24
+ kind: 'element',
25
+ type: 'view',
26
+ children: [{ kind: 'childSlot', type: 'slot', elementSlotIndex: 0 }],
27
+ },
28
+ },
29
+ { templateId: '_et_debug_leaf', compiledTemplate: { kind: 'element', type: 'view' } },
30
+ ]);
31
+ const error = vi.spyOn(console, 'error').mockImplementation(() => {});
32
+ const children = ['first', duplicate ? 'first' : 'second'].map(key =>
33
+ __etHost('_et_debug_leaf', '_et_debug_leaf', '__Card__', key, undefined, undefined, undefined, plain)
34
+ );
35
+ const host = __etHost(
36
+ '_et_debug_root',
37
+ '_et_debug_root',
38
+ '__Card__',
39
+ undefined,
40
+ undefined,
41
+ [children],
42
+ undefined,
43
+ plain,
44
+ );
45
+ try {
46
+ const result = renderToElementTemplate(host);
47
+ expect(__SerializeElementTemplate(result.rootRefs[0]!).childSlots?.[0]).toHaveLength(2);
48
+ if (duplicate) {
49
+ expect(error).toHaveBeenCalledExactlyOnceWith(expect.stringContaining('same key attribute: "first"'));
50
+ expect(error.mock.calls[0]![0]).toContain('<_et_debug_root');
51
+ } else {
52
+ expect(error).not.toHaveBeenCalled();
53
+ }
54
+ } finally {
55
+ error.mockRestore();
56
+ }
57
+ });