@lynx-js/react 0.126.1 → 0.126.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 (271) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +3 -3
  4. package/refresh/.turbo/turbo-build.log +3 -3
  5. package/refresh/dist/index.js +1 -2
  6. package/refresh/package.json +1 -1
  7. package/runtime/__test__/element-template/debug/profile-installation.test.tsx +97 -1
  8. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -1
  9. package/runtime/__test__/element-template/fixtures/render/child-siblings/index.js.txt +15 -11
  10. package/runtime/__test__/element-template/fixtures/render/component/index.js.txt +8 -7
  11. package/runtime/__test__/element-template/fixtures/render/component-slot-content/index.js.txt +14 -10
  12. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/index.js.txt +4 -3
  13. package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/_shared.ts +2 -9
  14. package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/case.ts +2 -4
  15. package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/case.ts +20 -0
  16. 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
  17. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/case.ts +18 -0
  18. package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/case.ts +20 -0
  19. package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/case.ts +18 -0
  20. package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/case.ts +15 -0
  21. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/index.js.txt +12 -11
  22. package/runtime/__test__/element-template/fixtures/render/mixed-children/index.js.txt +8 -7
  23. package/runtime/__test__/element-template/fixtures/render/multiple-text/index.js.txt +15 -13
  24. package/runtime/__test__/element-template/fixtures/render/nested-templates/index.js.txt +9 -7
  25. package/runtime/__test__/element-template/fixtures/render/react-example/index.js.txt +17 -20
  26. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/index.js.txt +13 -10
  27. package/runtime/__test__/element-template/fixtures/render/template-dedupe/index.js.txt +14 -11
  28. package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +52 -7
  29. package/runtime/__test__/element-template/native/reload.test.ts +10 -26
  30. package/runtime/__test__/element-template/runtime/background/component-stack.test.tsx +76 -0
  31. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +87 -43
  32. package/runtime/__test__/element-template/runtime/background/instance.test.ts +14 -0
  33. package/runtime/__test__/element-template/runtime/render/compact-host-debug.test.ts +57 -0
  34. package/runtime/__test__/element-template/runtime/render/compact-host.test.ts +199 -0
  35. package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +292 -0
  36. package/runtime/__test__/element-template/runtime/render/{render-opcodes-into-element-template.et.test.tsx → render-direct-native.test.tsx} +50 -314
  37. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +378 -0
  38. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +491 -0
  39. package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -28
  40. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +21 -35
  41. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -5
  42. package/runtime/__test__/element-template/test-utils/debug/renderFixtureRunner.ts +4 -4
  43. package/runtime/__test__/element-template/vitest.config.ts +2 -1
  44. package/runtime/__test__/snapshot/debug/main-thread-children-with-same-key.test.ts +28 -0
  45. package/runtime/__test__/snapshot/debug/profile.test.jsx +108 -3
  46. package/runtime/__test__/snapshot/lazy.test.js +44 -9
  47. package/runtime/__test__/snapshot/lifecycle/reloadGc.test.jsx +66 -0
  48. package/runtime/__test__/snapshot/lynx/runtime-version.test.ts +140 -0
  49. package/runtime/__test__/snapshot/spread.test.jsx +22 -15
  50. package/runtime/__test__/snapshot/ssr.legacy-slot.test.jsx +168 -0
  51. package/runtime/__test__/snapshot/ssr.list.test.jsx +211 -0
  52. package/runtime/__test__/worklet-runtime/hydrate.test.js +92 -0
  53. package/runtime/__test__/worklet-runtime/runOnBackground.test.js +8 -6
  54. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +3 -2
  55. package/runtime/lazy/element-template-import.js +0 -4
  56. package/runtime/lazy/element-template-internal.js +18 -8
  57. package/runtime/lazy/element-template-jsx-dev-runtime.js +1 -8
  58. package/runtime/lazy/element-template-jsx-runtime.js +1 -3
  59. package/runtime/lazy/element-template.js +1 -3
  60. package/runtime/lazy/import.js +0 -4
  61. package/runtime/lazy/internal.js +15 -1
  62. package/runtime/lazy/target.js +0 -21
  63. package/runtime/lib/core/hooks/react.d.ts +2 -0
  64. package/runtime/lib/core/hooks/react.js +2 -0
  65. package/runtime/lib/core/hooks/react.js.map +1 -1
  66. package/runtime/lib/core/lynx/runtime-version.d.ts +16 -0
  67. package/runtime/lib/core/lynx/runtime-version.js +51 -0
  68. package/runtime/lib/core/lynx/runtime-version.js.map +1 -0
  69. package/runtime/lib/element-template/background/document.d.ts +1 -1
  70. package/runtime/lib/element-template/background/document.js +1 -1
  71. package/runtime/lib/element-template/background/document.js.map +1 -1
  72. package/runtime/lib/element-template/background/hydrate.js +51 -19
  73. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  74. package/runtime/lib/element-template/background/instance.js +5 -6
  75. package/runtime/lib/element-template/background/instance.js.map +1 -1
  76. package/runtime/lib/element-template/debug/profile.js +38 -22
  77. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  78. package/runtime/lib/element-template/index.d.ts +1 -1
  79. package/runtime/lib/element-template/index.js +1 -1
  80. package/runtime/lib/element-template/index.js.map +1 -1
  81. package/runtime/lib/element-template/internal.d.ts +4 -1
  82. package/runtime/lib/element-template/internal.js +6 -1
  83. package/runtime/lib/element-template/internal.js.map +1 -1
  84. package/runtime/lib/element-template/native/index.js +4 -0
  85. package/runtime/lib/element-template/native/index.js.map +1 -1
  86. package/runtime/lib/element-template/runtime/list/list.d.ts +1 -0
  87. package/runtime/lib/element-template/runtime/list/list.js +3 -0
  88. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  89. package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +7 -0
  90. package/runtime/lib/element-template/runtime/render/create-rendered-host.js +65 -0
  91. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -0
  92. package/runtime/lib/element-template/runtime/render/host.d.ts +18 -0
  93. package/runtime/lib/element-template/runtime/render/host.js +25 -0
  94. package/runtime/lib/element-template/runtime/render/host.js.map +1 -0
  95. package/runtime/lib/element-template/runtime/render/render-components.d.ts +6 -0
  96. package/runtime/lib/element-template/runtime/render/render-components.js +190 -0
  97. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -0
  98. package/runtime/lib/element-template/runtime/render/{render-opcodes.d.ts → render-direct.d.ts} +3 -1
  99. package/runtime/lib/element-template/runtime/render/render-direct.js +194 -0
  100. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -0
  101. package/runtime/lib/element-template/runtime/render/render-main-thread.js +10 -9
  102. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  103. package/runtime/lib/element-template/runtime/template/handle.d.ts +2 -1
  104. package/runtime/lib/element-template/runtime/template/handle.js +12 -4
  105. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  106. package/runtime/lib/element-template/runtime-marker.js +13 -0
  107. package/runtime/lib/element-template/runtime-marker.js.map +1 -0
  108. package/runtime/lib/index.d.ts +1 -1
  109. package/runtime/lib/index.js +1 -1
  110. package/runtime/lib/index.js.map +1 -1
  111. package/runtime/lib/internal.d.ts +3 -1
  112. package/runtime/lib/internal.js +5 -1
  113. package/runtime/lib/internal.js.map +1 -1
  114. package/runtime/lib/lynx-api.d.ts +15 -6
  115. package/runtime/lib/lynx-api.js +13 -4
  116. package/runtime/lib/lynx-api.js.map +1 -1
  117. package/runtime/lib/runtime-marker.js +13 -0
  118. package/runtime/lib/runtime-marker.js.map +1 -0
  119. package/runtime/lib/shared/component-stack.js +5 -1
  120. package/runtime/lib/shared/component-stack.js.map +1 -1
  121. package/runtime/lib/snapshot/debug/profileHooks.js +38 -22
  122. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  123. package/runtime/lib/snapshot/lifecycle/reload.js +3 -0
  124. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  125. package/runtime/lib/snapshot/lynx/calledByNative.js +3 -0
  126. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  127. package/runtime/lib/snapshot/lynx/element.d.ts +2 -0
  128. package/runtime/lib/snapshot/lynx/element.js +2 -0
  129. package/runtime/lib/snapshot/lynx/element.js.map +1 -1
  130. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +2 -1
  131. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  132. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  133. package/runtime/lib/worklet-runtime/bindings/types.d.ts +1 -1
  134. package/runtime/lib/worklet-runtime/hydrate.js +1 -1
  135. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  136. package/runtime/lib/worklet-runtime/workletRuntime.js +5 -14
  137. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  138. package/runtime/src/core/hooks/react.ts +2 -0
  139. package/runtime/src/core/lynx/runtime-version.ts +62 -0
  140. package/runtime/src/element-template/background/document.ts +3 -3
  141. package/runtime/src/element-template/background/hydrate.ts +61 -29
  142. package/runtime/src/element-template/background/instance.ts +5 -6
  143. package/runtime/src/element-template/debug/profile.ts +48 -36
  144. package/runtime/src/element-template/index.ts +1 -1
  145. package/runtime/src/element-template/internal.ts +12 -1
  146. package/runtime/src/element-template/native/index.ts +4 -0
  147. package/runtime/src/element-template/runtime/list/list.ts +4 -0
  148. package/runtime/src/element-template/runtime/render/create-rendered-host.ts +126 -0
  149. package/runtime/src/element-template/runtime/render/host.ts +51 -0
  150. package/runtime/src/element-template/runtime/render/render-components.ts +255 -0
  151. package/runtime/src/element-template/runtime/render/render-direct.ts +275 -0
  152. package/runtime/src/element-template/runtime/render/render-main-thread.ts +10 -9
  153. package/runtime/src/element-template/runtime/template/handle.ts +17 -7
  154. package/runtime/src/element-template/runtime-marker.ts +17 -0
  155. package/runtime/src/index.ts +1 -1
  156. package/runtime/src/internal.ts +10 -1
  157. package/runtime/src/lynx-api.ts +15 -6
  158. package/runtime/src/runtime-marker.ts +17 -0
  159. package/runtime/src/shared/component-stack.ts +5 -1
  160. package/runtime/src/snapshot/debug/profileHooks.ts +52 -40
  161. package/runtime/src/snapshot/lifecycle/reload.ts +4 -0
  162. package/runtime/src/snapshot/lynx/calledByNative.ts +4 -0
  163. package/runtime/src/snapshot/lynx/element.ts +2 -0
  164. package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +2 -1
  165. package/runtime/src/worklet-runtime/bindings/types.ts +1 -1
  166. package/runtime/src/worklet-runtime/hydrate.ts +1 -1
  167. package/runtime/src/worklet-runtime/workletRuntime.ts +5 -14
  168. package/runtime/types/types.d.ts +2 -0
  169. package/runtime/worklet-runtime/dev.js +4 -16
  170. package/runtime/worklet-runtime/main.js +1 -1
  171. package/testing-library/.turbo/turbo-build.log +12 -12
  172. package/testing-library/dist/env/index.js +2 -2
  173. package/testing-library/dist/index.d.ts +2 -2
  174. package/testing-library/dist/plugins/index.js +1 -1
  175. package/testing-library/dist/pure.js +45 -44
  176. package/testing-library/etc/react-lynx-testing-library.api.md +1 -1
  177. package/testing-library/node_modules/.bin/rsbuild +19 -6
  178. package/testing-library/node_modules/.bin/rspeedy +17 -4
  179. package/testing-library/node_modules/.bin/rstest +19 -6
  180. package/testing-library/package.json +2 -2
  181. package/testing-library/src/__tests__/reload/reloadGc.test.jsx +64 -0
  182. package/testing-library/src/__tests__/reload/reloadTemplate.js +39 -0
  183. package/testing-library/types/entry.d.ts +2 -2
  184. package/transform/.turbo/turbo-build$colon$wasm.log +68 -56
  185. package/transform/__test__/fixture.spec.js +17 -20
  186. package/transform/__test__/text.spec.js +75 -0
  187. package/transform/crates/swc_plugin_compat/lib.rs +4 -3
  188. package/transform/crates/swc_plugin_compat/napi.rs +4 -3
  189. package/transform/crates/swc_plugin_define_dce/napi.rs +1 -1
  190. package/transform/crates/swc_plugin_dynamic_import/lib.rs +105 -3
  191. package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_suffix_webpack_chunk_name.js +5 -0
  192. package/transform/crates/swc_plugin_element_template/host_lowering.rs +111 -0
  193. package/transform/crates/swc_plugin_element_template/lib.rs +41 -5
  194. package/transform/crates/swc_plugin_element_template/lowering.rs +39 -7
  195. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_generate_attribute_slots_for_dynamic_attributes.snap +1 -1
  196. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_background_conditional_attributes.snap +1 -1
  197. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_boolean_and_number_attributes.snap +1 -1
  198. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_complex_text_structure.snap +1 -1
  199. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dataset_attributes.snap +1 -1
  200. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_deeply_nested_user_components.snap +1 -1
  201. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dynamic_class_attributes.snap +1 -1
  202. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_events_lepus.snap +1 -1
  203. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_id_attributes.snap +1 -1
  204. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_inline_styles.snap +1 -1
  205. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_interpolated_text_with_siblings_lepus.snap +1 -1
  206. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_mixed_content.snap +1 -1
  207. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_nested_structure_and_dynamic_content.snap +1 -1
  208. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_refs_lepus.snap +1 -1
  209. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_sibling_user_components.snap +1 -1
  210. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_spread_attributes.snap +1 -1
  211. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_user_component.snap +1 -1
  212. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_isolate_arrays_with_child_slot_placeholder.snap +1 -1
  213. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_keep_code_and_template_attribute_slots_in_sync_for_spread.snap +1 -1
  214. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_element_template_simple_lepus.snap +1 -1
  215. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_template_with_static_attributes.snap +1 -1
  216. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_template_structure_complex.snap +1 -1
  217. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_text_attribute_and_child_text_slots.snap +1 -1
  218. package/transform/crates/swc_plugin_element_template/tests/element_template.rs +70 -66
  219. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +94 -8
  220. package/transform/crates/swc_plugin_shake/lib.rs +1 -1
  221. package/transform/crates/swc_plugin_shake/napi.rs +1 -1
  222. package/transform/crates/swc_plugin_text/lib.rs +57 -16
  223. package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_keep_children_for_dynamic_or_multiple_text.js +13 -0
  224. package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_transform_string_expressions_to_text_attr.js +13 -0
  225. package/transform/crates/swc_plugins_shared/jsx_helpers.rs +8 -4
  226. package/transform/dist/wasm.cjs +1 -1
  227. package/transform/index.d.ts +7 -6
  228. package/transform/node_modules/.bin/esbuild +17 -4
  229. package/transform/node_modules/.bin/napi +17 -4
  230. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
  231. package/transform/src/swc_plugin_extract_str/mod.rs +1 -1
  232. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +310 -114
  233. package/transform/swc-plugin-reactlynx/index.d.ts +2 -2
  234. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  235. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +10 -208
  236. package/transform/swc-plugin-reactlynx-compat/index.d.ts +3 -3
  237. package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
  238. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/case.ts +0 -39
  239. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/case.ts +0 -29
  240. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/case.ts +0 -42
  241. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/case.ts +0 -31
  242. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/passes-bundle-url-to-native-create/case.ts +0 -20
  243. package/runtime/__test__/element-template/runtime/render/render-to-opcodes.et.test.jsx +0 -522
  244. package/runtime/lib/element-template/runtime/render/render-opcodes.js +0 -216
  245. package/runtime/lib/element-template/runtime/render/render-opcodes.js.map +0 -1
  246. package/runtime/lib/element-template/runtime/render/render-to-opcodes.d.ts +0 -16
  247. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js +0 -324
  248. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js.map +0 -1
  249. package/runtime/lib/element-template/runtime-backend-marker.js +0 -6
  250. package/runtime/lib/element-template/runtime-backend-marker.js.map +0 -1
  251. package/runtime/lib/runtime-backend-marker.js +0 -6
  252. package/runtime/lib/runtime-backend-marker.js.map +0 -1
  253. package/runtime/src/element-template/runtime/render/render-opcodes.ts +0 -313
  254. package/runtime/src/element-template/runtime/render/render-to-opcodes.ts +0 -411
  255. package/runtime/src/element-template/runtime-backend-marker.ts +0 -7
  256. package/runtime/src/runtime-backend-marker.ts +0 -7
  257. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/native-log.txt +0 -0
  258. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/output.txt +0 -0
  259. /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
  260. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/output.txt +0 -0
  261. /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
  262. /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
  263. /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
  264. /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
  265. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/native-log.txt +0 -0
  266. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/output.txt +0 -0
  267. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/native-log.txt +0 -0
  268. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/output.txt +0 -0
  269. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/passes-bundle-url-to-native-create/native-log.txt +0 -0
  270. /package/runtime/lib/element-template/{runtime-backend-marker.d.ts → runtime-marker.d.ts} +0 -0
  271. /package/runtime/lib/{runtime-backend-marker.d.ts → runtime-marker.d.ts} +0 -0
@@ -21,17 +21,12 @@ import {
21
21
  } from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
22
22
  import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
23
23
 
24
- vi.mock('../../../../src/element-template/runtime/render/render-to-opcodes.js', () => ({
25
- render: vi.fn(),
24
+ vi.mock('../../../../src/element-template/runtime/render/render-direct.js', () => ({
25
+ renderToElementTemplate: vi.fn(),
26
26
  registerSlot: vi.fn(),
27
27
  }));
28
28
 
29
- vi.mock('../../../../src/element-template/runtime/render/render-opcodes.js', () => ({
30
- renderOpcodesIntoElementTemplate: vi.fn(),
31
- }));
32
-
33
- import { render as mockRender } from '../../../../src/element-template/runtime/render/render-to-opcodes.js';
34
- import { renderOpcodesIntoElementTemplate as mockRenderOpcodesIntoElementTemplate } from '../../../../src/element-template/runtime/render/render-opcodes.js';
29
+ import { renderToElementTemplate as mockRender } from '../../../../src/element-template/runtime/render/render-direct.js';
35
30
 
36
31
  describe('renderMainThread', () => {
37
32
  let dispatchEvent: ReturnType<typeof vi.fn>;
@@ -39,7 +34,6 @@ describe('renderMainThread', () => {
39
34
 
40
35
  beforeEach(() => {
41
36
  vi.mocked(mockRender).mockReset();
42
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReset();
43
37
  setRoot({ __jsx: { type: 'test-root' } });
44
38
  pageRef = { type: 'page', children: [] } as unknown as ElementTemplateHandle;
45
39
  setupPage(pageRef);
@@ -60,7 +54,7 @@ describe('renderMainThread', () => {
60
54
  destroyAllElementTemplateListStates();
61
55
  clearMainThreadDynamicAttrState();
62
56
  clearEtAttrPlanMap();
63
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
57
+ vi.mocked(mockRender).mockReturnValue({
64
58
  pageAttributes: null,
65
59
  rootRefs: [],
66
60
  rootSubtreeHandles: [],
@@ -74,7 +68,7 @@ describe('renderMainThread', () => {
74
68
  clearEtAttrPlanMap();
75
69
  });
76
70
 
77
- it('should report error when renderToOpcodes fails', () => {
71
+ it('reports a failed component render and commits an empty page', () => {
78
72
  const reportErrorSpy = vi.fn();
79
73
  const serializedPage = {
80
74
  tag: 'page',
@@ -94,21 +88,17 @@ describe('renderMainThread', () => {
94
88
  renderMainThread();
95
89
 
96
90
  expect(reportErrorSpy).toHaveBeenCalledWith(expect.objectContaining({ message: 'Render failed' }));
97
- expect(mockRenderOpcodesIntoElementTemplate).toHaveBeenCalledWith([]);
98
91
  expect(__SetAttributeOfElementTemplate).toHaveBeenCalledWith(pageRef, 0, null);
99
92
  expect(__InsertNodeToElementTemplate).not.toHaveBeenCalled();
100
93
  expect(__SerializeElementTemplate).toHaveBeenCalledWith(pageRef);
101
94
  expect(dispatchEvent).toHaveBeenCalledWith({
102
95
  type: 'rLynxElementTemplateHydrate',
103
- data: {
104
- page: serializedPage,
105
- reloadVersion: getReloadVersion(),
106
- },
96
+ data: { page: serializedPage, reloadVersion: getReloadVersion() },
107
97
  });
98
+ reportErrorSpy.mockClear();
108
99
  });
109
100
 
110
- it('should render opcodes into the current page and dispatch hydrate data', () => {
111
- const opcodes = [0, 'opcode'];
101
+ it('commits completed roots into the current page and dispatches hydrate data', () => {
112
102
  const rootRefA = { type: 'ref-a' } as unknown as ElementTemplateHandle;
113
103
  const rootRefB = { type: 'ref-b' } as unknown as ElementTemplateHandle;
114
104
  const dispatchEvent = vi.fn();
@@ -130,8 +120,7 @@ describe('renderMainThread', () => {
130
120
  childSlots: [[serializedA, serializedB]],
131
121
  uid: 0,
132
122
  };
133
- vi.mocked(mockRender).mockReturnValue(opcodes);
134
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
123
+ vi.mocked(mockRender).mockReturnValue({
135
124
  pageAttributes: null,
136
125
  rootRefs: [rootRefA, rootRefB],
137
126
  rootSubtreeHandles: [[], []],
@@ -146,9 +135,6 @@ describe('renderMainThread', () => {
146
135
 
147
136
  expect(() => renderMainThread()).not.toThrow();
148
137
  expect(mockRender).toHaveBeenCalledWith({ type: 'test-root' }, undefined);
149
- expect(mockRenderOpcodesIntoElementTemplate).toHaveBeenCalledWith(
150
- opcodes,
151
- );
152
138
  expect(__InsertNodeToElementTemplate).toHaveBeenNthCalledWith(
153
139
  1,
154
140
  pageRef,
@@ -177,13 +163,17 @@ describe('renderMainThread', () => {
177
163
  });
178
164
  });
179
165
 
180
- it('does not commit the physical page when opcode materialization fails', () => {
181
- vi.mocked(mockRender).mockReturnValue([0, 'opcode']);
182
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockImplementationOnce(() => {
166
+ it('propagates an exception from reportError without committing an empty result', () => {
167
+ vi.mocked(mockRender).mockImplementationOnce(() => {
183
168
  throw new Error('Materialization failed');
184
169
  });
185
170
 
186
- expect(() => renderMainThread()).toThrow('Materialization failed');
171
+ vi.mocked(lynx.reportError).mockImplementationOnce(() => {
172
+ throw new Error('reportError failed');
173
+ });
174
+
175
+ expect(() => renderMainThread()).toThrow('reportError failed');
176
+ expect(lynx.reportError).toHaveBeenCalledWith(expect.objectContaining({ message: 'Materialization failed' }));
187
177
  expect(__SetAttributeOfElementTemplate).not.toHaveBeenCalled();
188
178
  expect(__InsertNodeToElementTemplate).not.toHaveBeenCalled();
189
179
  expect(__SerializeElementTemplate).not.toHaveBeenCalled();
@@ -191,8 +181,7 @@ describe('renderMainThread', () => {
191
181
 
192
182
  it('applies authored page attrs before inserting rendered roots', () => {
193
183
  const rootRef = { type: 'root-ref' } as unknown as ElementTemplateHandle;
194
- vi.mocked(mockRender).mockReturnValue([]);
195
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
184
+ vi.mocked(mockRender).mockReturnValue({
196
185
  pageAttributes: {
197
186
  id: 'screen',
198
187
  bindtap: '0:0:bindtap',
@@ -249,8 +238,7 @@ describe('renderMainThread', () => {
249
238
  }]],
250
239
  uid: 0,
251
240
  };
252
- vi.mocked(mockRender).mockReturnValue([]);
253
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
241
+ vi.mocked(mockRender).mockReturnValue({
254
242
  pageAttributes: null,
255
243
  rootRefs: [rootRef],
256
244
  rootSubtreeHandles: [[]],
@@ -306,8 +294,7 @@ describe('renderMainThread', () => {
306
294
  '_et_ref',
307
295
  [{ type: 'main-thread-ref', value: ref }],
308
296
  );
309
- vi.mocked(mockRender).mockReturnValue([]);
310
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
297
+ vi.mocked(mockRender).mockReturnValue({
311
298
  pageAttributes: null,
312
299
  rootRefs: [rootRef],
313
300
  rootSubtreeHandles: [[{ uid: -1, ref: rootRef }]],
@@ -353,8 +340,7 @@ describe('renderMainThread', () => {
353
340
  '_et_ref',
354
341
  [{ type: 'main-thread-ref', value: ref }],
355
342
  );
356
- vi.mocked(mockRender).mockReturnValue([]);
357
- vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
343
+ vi.mocked(mockRender).mockReturnValue({
358
344
  pageAttributes: null,
359
345
  rootRefs: [rootRef],
360
346
  rootSubtreeHandles: [[{ uid: -1, ref: rootRef }]],
@@ -20,7 +20,8 @@ import {
20
20
  import { backgroundElementTemplateInstanceManager } from '../../../../src/element-template/background/manager.js';
21
21
  import { applyElementTemplateUpdateCommands } from '../../../../src/element-template/runtime/patch.js';
22
22
  import { ElementTemplateUpdateOps } from '../../../../src/element-template/protocol/opcodes.js';
23
- import { renderOpcodesIntoElementTemplate } from '../../../../src/element-template/runtime/render/render-opcodes.js';
23
+ import { renderToElementTemplate } from '../../../../src/element-template/runtime/render/render-direct.js';
24
+ import { resetElementTemplatePatchListener } from '../../../../src/element-template/native/patch-listener.js';
24
25
  import { resetTemplateId } from '../../../../src/element-template/runtime/template/handle.js';
25
26
  import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
26
27
  import type {
@@ -28,7 +29,6 @@ import type {
28
29
  SerializedEtNode,
29
30
  SerializedTypedListNode,
30
31
  } from '../../../../src/element-template/protocol/types.js';
31
- import { renderToString } from '../../../../src/element-template/runtime/render/render-to-opcodes.js';
32
32
  import { hydrateBackground } from '../../test-utils/debug/hydrate.js';
33
33
  import { clearTemplates, registerBuiltinRawTextTemplate, registerTemplates } from '../../test-utils/debug/registry.js';
34
34
  import { installMockNativePapi, lastMock } from '../../test-utils/mock/mockNativePapi.js';
@@ -168,8 +168,7 @@ async function compileAndRender(
168
168
  };
169
169
 
170
170
  const vnode = { type: module.App, props: {}, key: null, ref: null };
171
- const opcodes = renderToString(vnode, null);
172
- const { rootRefs } = renderOpcodesIntoElementTemplate(opcodes);
171
+ const { rootRefs } = renderToElementTemplate(vnode);
173
172
 
174
173
  expect(rootRefs).toHaveLength(1);
175
174
 
@@ -181,6 +180,7 @@ async function compileAndRender(
181
180
  code: transformedCode,
182
181
  };
183
182
  } finally {
183
+ resetElementTemplatePatchListener();
184
184
  fs.rmSync(tempDir, { recursive: true, force: true });
185
185
  }
186
186
  }
@@ -422,7 +422,8 @@ describe('render transform contract', () => {
422
422
 
423
423
  expect(result.code).toContain('DeferredListItem');
424
424
  expect(result.code).toContain('unmountRecycled');
425
- expect(result.code).toContain('__listItemPlatformInfo');
425
+ expect(result.code).toContain('__etHost');
426
+ expect(result.code).toContain('"item-key": "late"');
426
427
  });
427
428
 
428
429
  it('chains create, serialize, update, and callbacks', async () => {
@@ -4,12 +4,12 @@ import { pathToFileURL } from 'node:url';
4
4
 
5
5
  import { vi } from 'vitest';
6
6
 
7
+ import { resetElementTemplatePatchListener } from '../../../../src/element-template/native/patch-listener.js';
7
8
  import { resetElementTemplateHydrationListener } from '../../../../src/element-template/background/hydration-listener.js';
8
- import { renderOpcodesIntoElementTemplate } from '../../../../src/element-template/runtime/render/render-opcodes.js';
9
9
  import { clearEtAttrPlanMap } from '../../../../src/element-template/runtime/template/attr-slot-plan.js';
10
10
  import { resetTemplateId } from '../../../../src/element-template/runtime/template/handle.js';
11
11
  import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
12
- import { renderToString } from '../../../../src/element-template/runtime/render/render-to-opcodes.js';
12
+ import { renderToElementTemplate } from '../../../../src/element-template/runtime/render/render-direct.js';
13
13
  import {
14
14
  assertMissingFile,
15
15
  assertOrUpdateTextFile,
@@ -238,8 +238,7 @@ async function runCompiledRenderFixture(options: {
238
238
  try {
239
239
  const module = (await import(`${pathToFileURL(tempImportPath).href}?t=${Date.now()}`)) as { App: unknown };
240
240
  const vnode = { type: module.App, props: {}, key: null, ref: null };
241
- const opcodes = renderToString(vnode, null);
242
- const { rootRefs } = renderOpcodesIntoElementTemplate(opcodes);
241
+ const { rootRefs } = renderToElementTemplate(vnode, null);
243
242
  for (const rootRef of rootRefs) {
244
243
  __InsertNodeToElementTemplate(root, 0, rootRef, null);
245
244
  }
@@ -267,6 +266,7 @@ async function runCompiledRenderFixture(options: {
267
266
  expectReportErrorCount(0);
268
267
  } finally {
269
268
  resetElementTemplateHydrationListener();
269
+ resetElementTemplatePatchListener();
270
270
  clearEtAttrPlanMap();
271
271
  cleanup();
272
272
  globalThis.__USE_ELEMENT_TEMPLATE__ = undefined;
@@ -5,7 +5,7 @@ import type { Plugin, UserConfigExport } from 'vitest/config';
5
5
  import { defineConfig } from 'vitest/config';
6
6
 
7
7
  const require = createRequire(import.meta.url);
8
- const elementTemplateRuntimePkg = require.resolve('../../src/element-template/internal.ts');
8
+ const elementTemplateRuntimePkg = require.resolve('../../src/element-template/internal.ts').split(path.sep).join('/');
9
9
 
10
10
  function transformReactLynxPlugin(): Plugin {
11
11
  return {
@@ -105,6 +105,7 @@ const config: UserConfigExport = defineConfig({
105
105
  },
106
106
  test: {
107
107
  name: 'react/runtime-et',
108
+ root: path.resolve(__dirname, '../..'),
108
109
  include: ['**/__test__/element-template/**/*.{test,spec}.{js,ts,jsx,tsx}'],
109
110
  coverage: {
110
111
  include: ['src/element-template/**', 'lazy/element-template*.js'],
@@ -0,0 +1,28 @@
1
+ import { expect, it, vi } from 'vitest';
2
+
3
+ it.each([false, true])('preact/debug - Snapshot main-thread children with duplicate keys: %s', async (duplicate) => {
4
+ vi.stubGlobal('__MAIN_THREAD__', true)
5
+ .stubGlobal('__LEPUS__', true)
6
+ .stubGlobal('__BACKGROUND__', false);
7
+ await import('preact/debug');
8
+ const { h } = await import('preact');
9
+ const { jsx } = await import('../../../lepus/jsx-runtime/index.js');
10
+ const { default: renderToString } = await import('../../../src/snapshot/renderToOpcodes/index.js');
11
+ const { __root } = await import('../../../src/root.js');
12
+ const error = vi.spyOn(console, 'error').mockImplementation(() => {});
13
+ const Child = () => null;
14
+ const children = ['first', duplicate ? 'first' : 'second'].map(key => h(Child, { key }));
15
+ const host = jsx('view', { children });
16
+ try {
17
+ expect(() => renderToString(host, null, __root)).not.toThrow();
18
+ if (duplicate) {
19
+ expect(error).toHaveBeenCalledExactlyOnceWith(expect.stringContaining('same key attribute: "first"'));
20
+ expect(error.mock.calls[0]![0]).toContain('<view');
21
+ } else {
22
+ expect(error).not.toHaveBeenCalled();
23
+ }
24
+ } finally {
25
+ error.mockRestore();
26
+ vi.unstubAllGlobals();
27
+ }
28
+ });
@@ -3,14 +3,24 @@
3
3
  // Licensed under the Apache License Version 2.0 that can be found in the
4
4
  // LICENSE file in the root directory of this source tree.
5
5
  */
6
- import { render, options, Component } from 'preact';
7
- import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
6
+ import { render, options, Component, createElement } from 'preact';
7
+ import { beforeAll, beforeEach, describe, expect, onTestFinished, test, vi } from 'vitest';
8
8
 
9
9
  import { setupDocument } from '../../../src/document';
10
10
  import { setupPage, snapshotInstanceManager } from '../../../src/snapshot';
11
11
  import { initProfileHook } from '../../../src/snapshot/debug/profileHooks';
12
12
  import { useState } from '../../../src/index';
13
- import { COMPONENT, DIFF, DIFF2, DIFFED, HOOKS, LIST, RENDER, VNODE } from '../../../src/shared/render-constants';
13
+ import {
14
+ COMMIT,
15
+ COMPONENT,
16
+ DIFF,
17
+ DIFF2,
18
+ DIFFED,
19
+ HOOKS,
20
+ LIST,
21
+ RENDER,
22
+ VNODE,
23
+ } from '../../../src/shared/render-constants';
14
24
 
15
25
  describe('profile', () => {
16
26
  let scratch;
@@ -25,6 +35,101 @@ describe('profile', () => {
25
35
  lynx.performance.profileMark.mockClear();
26
36
  });
27
37
 
38
+ test.each(['main', 'background'])('preserves profiling callback contracts on %s', target => {
39
+ vi.stubGlobal('__MAIN_THREAD__', target === 'main');
40
+ vi.stubGlobal('__BACKGROUND__', target === 'background');
41
+ const previousHooks = {
42
+ [COMMIT]: options[COMMIT],
43
+ [DIFF]: options[DIFF],
44
+ [DIFF2]: options[DIFF2],
45
+ [DIFFED]: options[DIFFED],
46
+ [RENDER]: options[RENDER],
47
+ };
48
+ const previousSetState = Component.prototype.setState;
49
+ onTestFinished(() => {
50
+ Object.assign(options, previousHooks);
51
+ Component.prototype.setState = previousSetState;
52
+ vi.unstubAllGlobals();
53
+ });
54
+ const events = [];
55
+ const performance = lynx.performance;
56
+ const oldSetState = Component.prototype.setState = vi.fn(function(state, callback) {
57
+ expect(this).toBe(instance);
58
+ expect(state).toBe(nextState);
59
+ expect(callback).toBe(setStateCallback);
60
+ events.push('old setState');
61
+ });
62
+ const oldDiff = options[DIFF] = vi.fn(() => events.push('old before diff'));
63
+ const oldCommit = options[COMMIT] = vi.fn(() => {
64
+ expect(performance.profileStart).toHaveBeenLastCalledWith('ReactLynx::commit', {});
65
+ events.push('old commit');
66
+ });
67
+ const oldDiff2 = options[DIFF2] = vi.fn(() => {
68
+ expect(performance.profileStart).toHaveBeenLastCalledWith('ReactLynx::diff::Example', {});
69
+ events.push('old diff');
70
+ });
71
+ const oldDiffed = options[DIFFED] = vi.fn(() => {
72
+ expect(performance.profileEnd).toHaveBeenCalledTimes(2);
73
+ events.push('old diffed');
74
+ });
75
+ const oldRender = options[RENDER] = vi.fn(() => {
76
+ expect(instance.render).not.toBe(originalRender);
77
+ events.push('old render');
78
+ });
79
+ initProfileHook();
80
+
81
+ const failure = new Error('render failed');
82
+ class Example extends Component {
83
+ render() {
84
+ expect(this).toBe(instance);
85
+ expect(performance.profileStart).toHaveBeenLastCalledWith('ReactLynx::render::Example');
86
+ events.push('render');
87
+ throw failure;
88
+ }
89
+ }
90
+ const vnode = createElement(Example, {});
91
+ const oldVNode = createElement(Example, {});
92
+ const instance = vnode[COMPONENT] = new Example({});
93
+ const originalRender = instance.render;
94
+
95
+ const nextState = { count: 1 };
96
+ const setStateCallback = () => {};
97
+ const commitQueue = [instance];
98
+ instance.setState(nextState, setStateCallback);
99
+ options[DIFF]?.(vnode);
100
+ options[DIFF2]?.(vnode, oldVNode);
101
+ options[RENDER]?.(vnode);
102
+ expect(() => instance.render()).toThrow(failure);
103
+ expect(instance.render).toBe(originalRender);
104
+ options[DIFFED]?.(vnode);
105
+
106
+ if (target === 'background') {
107
+ options[COMMIT]?.(vnode, commitQueue);
108
+ expect(oldCommit.mock.calls).toEqual([[vnode, commitQueue]]);
109
+ expect(oldCommit.mock.contexts).toEqual([undefined]);
110
+ expect(performance.profileEnd).toHaveBeenCalledTimes(3);
111
+ expect(oldDiff.mock.contexts).toEqual([undefined]);
112
+ }
113
+ expect(oldSetState.mock.calls).toEqual([[nextState, setStateCallback]]);
114
+ expect(oldSetState.mock.contexts).toEqual([instance]);
115
+ expect(oldDiff.mock.calls).toEqual([[vnode]]);
116
+ expect(oldDiff2.mock.calls).toEqual([[vnode, oldVNode]]);
117
+ expect(oldRender.mock.calls).toEqual([[vnode]]);
118
+ expect(oldDiffed.mock.calls).toEqual([[vnode]]);
119
+ expect(oldDiff2.mock.contexts).toEqual([undefined]);
120
+ expect(oldRender.mock.contexts).toEqual([undefined]);
121
+ expect(oldDiffed.mock.contexts).toEqual([undefined]);
122
+ expect(events).toEqual([
123
+ 'old setState',
124
+ 'old before diff',
125
+ 'old diff',
126
+ 'old render',
127
+ 'render',
128
+ 'old diffed',
129
+ ...(target === 'background' ? ['old commit'] : []),
130
+ ]);
131
+ });
132
+
28
133
  test('original options hooks should be called', async () => {
29
134
  const noop = vi.fn();
30
135
 
@@ -8,13 +8,12 @@ import * as ReactInternalExports from '../../lazy/internal.js';
8
8
  import * as ReactJSXRuntimeExports from '../../lazy/jsx-runtime.js';
9
9
  import * as ReactJSXDevRuntimeExports from '../../lazy/jsx-dev-runtime.js';
10
10
  import * as ReactLegacyReactRuntimeExports from '../../lazy/legacy-react-runtime.js';
11
- import {
11
+ import { sRuntimeBackend, target } from '../../lazy/target.js';
12
+ const {
12
13
  RUNTIME_BACKEND_ELEMENT_TEMPLATE,
13
14
  RUNTIME_BACKEND_SNAPSHOT,
14
- registerLazyRuntimeBackend,
15
- sRuntimeBackend,
16
- target,
17
- } from '../../lazy/target.js';
15
+ registerRuntimeBackend,
16
+ } = ReactInternalExports;
18
17
 
19
18
  function restoreDescriptor(target, symbol, descriptor) {
20
19
  if (descriptor) {
@@ -44,6 +43,18 @@ async function withRuntimeBackend(backend, callback) {
44
43
  }
45
44
  }
46
45
 
46
+ async function withoutRecordedRuntimeVersion(callback) {
47
+ const symbol = Symbol.for('__REACT_LYNX_RUNTIME_VERSION__');
48
+ const descriptor = Object.getOwnPropertyDescriptor(target, symbol);
49
+ delete target[symbol];
50
+
51
+ try {
52
+ return await callback();
53
+ } finally {
54
+ restoreDescriptor(target, symbol, descriptor);
55
+ }
56
+ }
57
+
47
58
  describe('Lazy Exports', () => {
48
59
  test('export APIs from "react"', async () => {
49
60
  const realAPIs = Object.assign(
@@ -161,20 +172,44 @@ describe('Lazy Exports', () => {
161
172
  expect(target[sRuntimeBackend]).toBe(RUNTIME_BACKEND_SNAPSHOT);
162
173
  });
163
174
 
175
+ test('records a stamped runtime version from the host runtime marker', async () => {
176
+ await withoutRecordedRuntimeVersion(async () => {
177
+ vi.stubGlobal('__RUNTIME_VERSION__', '1.2.0');
178
+ onTestFinished(() => vi.unstubAllGlobals());
179
+ vi.resetModules();
180
+
181
+ await import('../../src/runtime-marker.ts');
182
+
183
+ expect(ReactInternalExports.getRuntimeVersion()).toBe('1.2.0');
184
+ });
185
+ });
186
+
187
+ test('records a stamped runtime version from the standalone lazy import', async () => {
188
+ await withoutRecordedRuntimeVersion(async () => {
189
+ vi.stubGlobal('__RUNTIME_VERSION__', '1.2.0');
190
+ onTestFinished(() => vi.unstubAllGlobals());
191
+ vi.resetModules();
192
+
193
+ await import('../../lazy/internal.js');
194
+
195
+ expect(ReactInternalExports.getRuntimeVersion()).toBe('1.2.0');
196
+ });
197
+ });
198
+
164
199
  test('records a lazy backend when no main template marker exists', async () => {
165
200
  await withRuntimeBackend(undefined, () => {
166
- registerLazyRuntimeBackend(RUNTIME_BACKEND_SNAPSHOT);
201
+ registerRuntimeBackend(RUNTIME_BACKEND_SNAPSHOT);
167
202
 
168
203
  expect(target[sRuntimeBackend]).toBe(RUNTIME_BACKEND_SNAPSHOT);
169
204
  });
170
205
  });
171
206
 
172
207
  test('allows matching lazy backend registration', () => {
173
- expect(() => registerLazyRuntimeBackend(RUNTIME_BACKEND_SNAPSHOT)).not.toThrow();
208
+ expect(() => registerRuntimeBackend(RUNTIME_BACKEND_SNAPSHOT)).not.toThrow();
174
209
  });
175
210
 
176
211
  test('throws when a lazy bundle backend does not match the main template backend', () => {
177
- expect(() => registerLazyRuntimeBackend(RUNTIME_BACKEND_ELEMENT_TEMPLATE)).toThrow(
212
+ expect(() => registerRuntimeBackend(RUNTIME_BACKEND_ELEMENT_TEMPLATE)).toThrow(
178
213
  'Snapshot and Element Template templates cannot share lazy bundles.',
179
214
  );
180
215
  });
@@ -192,7 +227,7 @@ describe('Lazy Exports', () => {
192
227
  await withRuntimeBackend(undefined, async () => {
193
228
  vi.resetModules();
194
229
 
195
- await import('../../src/element-template/runtime-backend-marker.ts');
230
+ await import('../../src/element-template/runtime-marker.ts');
196
231
  expect(target[sRuntimeBackend]).toBe(RUNTIME_BACKEND_ELEMENT_TEMPLATE);
197
232
 
198
233
  await expect(import('../../lazy/import.js')).rejects.toThrow(
@@ -0,0 +1,66 @@
1
+ /*
2
+ // Copyright 2026 The Lynx Authors. All rights reserved.
3
+ // Licensed under the Apache License Version 2.0 that can be found in the
4
+ // LICENSE file in the root directory of this source tree.
5
+ */
6
+ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
7
+
8
+ import { BasicMT } from './reloadMT';
9
+ import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit';
10
+ import { injectUpdateMainThread } from '../../../src/snapshot/lifecycle/patch/updateMainThread';
11
+ import { __root } from '../../../src/root';
12
+ import { setupPage } from '../../../src/snapshot';
13
+ import { globalEnvManager } from '../utils/envManager';
14
+ import { elementTree } from '../utils/nativeMethod';
15
+
16
+ beforeAll(() => {
17
+ setupPage(__CreatePage('0', 0));
18
+
19
+ replaceCommitHook();
20
+ injectUpdateMainThread();
21
+ });
22
+
23
+ beforeEach(() => {
24
+ globalEnvManager.resetEnv();
25
+ globalEnvManager.switchToMainThread();
26
+ __root.__jsx = BasicMT;
27
+ });
28
+
29
+ afterEach(() => {
30
+ delete globalThis.lepusng_gc;
31
+ globalEnvManager.resetEnv();
32
+ elementTree.clear();
33
+ });
34
+
35
+ describe('gc after the rendered tree is replaced', () => {
36
+ it('runs after reloadTemplate', () => {
37
+ globalThis.lepusng_gc = vi.fn();
38
+ renderPage({ text: 'Hello' });
39
+ expect(globalThis.lepusng_gc).not.toHaveBeenCalled();
40
+
41
+ updatePage({ text: 'Enjoy' }, { reloadTemplate: true });
42
+ expect(globalThis.lepusng_gc).toHaveBeenCalledTimes(1);
43
+ });
44
+
45
+ it('runs after an update before first-screen sync, not after one that follows it', () => {
46
+ globalThis.__FIRST_SCREEN_SYNC_TIMING__ = 'jsReady';
47
+ try {
48
+ globalThis.lepusng_gc = vi.fn();
49
+ renderPage({ text: 'Hello' });
50
+
51
+ updatePage({ text: 'Enjoy' });
52
+ expect(globalThis.lepusng_gc).toHaveBeenCalledTimes(1);
53
+
54
+ globalThis.rLynxFirstScreenSyncReady();
55
+ updatePage({ text: 'Again' });
56
+ expect(globalThis.lepusng_gc).toHaveBeenCalledTimes(1);
57
+ } finally {
58
+ globalThis.__FIRST_SCREEN_SYNC_TIMING__ = 'immediately';
59
+ }
60
+ });
61
+
62
+ it('is skipped when the engine does not expose it', () => {
63
+ renderPage({ text: 'Hello' });
64
+ expect(() => updatePage({ text: 'Enjoy' }, { reloadTemplate: true })).not.toThrow();
65
+ });
66
+ });