@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
@@ -0,0 +1,491 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import { Component, createContext, h, options } from 'preact';
6
+ import { useContext, useId, useState } from 'preact/hooks';
7
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
8
+
9
+ import { DIFF2 } from '../../../../src/shared/render-constants.js';
10
+ import { destroyAllElementTemplateListStates } from '../../../../src/element-template/runtime/list/list.js';
11
+ import { __ElementTemplatePage } from '../../../../src/element-template/runtime/page/authored-page.js';
12
+ import { createElementTemplatePage, setupPage } from '../../../../src/element-template/runtime/page/page.js';
13
+ import { setRoot } from '../../../../src/element-template/runtime/page/root-instance.js';
14
+ import { renderMainThread } from '../../../../src/element-template/runtime/render/render-main-thread.js';
15
+ import { renderToElementTemplate } from '../../../../src/element-template/runtime/render/render-direct.js';
16
+ import {
17
+ __etAttrPlanMap,
18
+ adaptEventAttrSlot,
19
+ adaptMTRefAttrSlot,
20
+ clearEtAttrPlanMap,
21
+ } from '../../../../src/element-template/runtime/template/attr-slot-plan.js';
22
+ import { resetTemplateId } from '../../../../src/element-template/runtime/template/handle.js';
23
+ import { clearMainThreadDynamicAttrState } from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
24
+ import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
25
+ import { registerBuiltinRawTextTemplate, registerTemplates } from '../../test-utils/debug/registry.js';
26
+
27
+ beforeEach(() => {
28
+ globalThis.__MAIN_THREAD__ = true;
29
+ globalThis.__BACKGROUND__ = false;
30
+ resetTemplateId();
31
+ elementTemplateRegistry.clear();
32
+ clearEtAttrPlanMap();
33
+ clearMainThreadDynamicAttrState();
34
+ registerBuiltinRawTextTemplate();
35
+ registerTemplates([
36
+ {
37
+ templateId: '_et_direct_root',
38
+ compiledTemplate: {
39
+ kind: 'element',
40
+ type: 'view',
41
+ children: [{ kind: 'childSlot', type: 'slot', elementSlotIndex: 0 }],
42
+ },
43
+ },
44
+ {
45
+ templateId: '_et_direct_leaf',
46
+ compiledTemplate: {
47
+ kind: 'element',
48
+ type: 'view',
49
+ attributesArray: [{ kind: 'slot', key: 'id', attrSlotIndex: 0 }],
50
+ },
51
+ },
52
+ ]);
53
+ setupPage(createElementTemplatePage());
54
+ });
55
+
56
+ afterEach(() => {
57
+ vi.restoreAllMocks();
58
+ clearEtAttrPlanMap();
59
+ clearMainThreadDynamicAttrState();
60
+ destroyAllElementTemplateListStates();
61
+ });
62
+
63
+ describe('direct first-screen materialization', () => {
64
+ it('creates completed hosts before later sibling render, but commits roots and MTRefs afterward', () => {
65
+ const events: string[] = [];
66
+ const mtRef = { _wvid: 123 };
67
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
68
+ globalThis.lynxWorkletImpl = {
69
+ ...previousWorkletImpl,
70
+ _refImpl: { updateWorkletRef: () => events.push('attach-ref') },
71
+ } as typeof globalThis.lynxWorkletImpl;
72
+ __etAttrPlanMap['__Card__:_et_direct_leaf'] = [1, adaptMTRefAttrSlot];
73
+ const create = globalThis.__CreateElementTemplate;
74
+ vi.spyOn(globalThis, '__CreateElementTemplate').mockImplementation((...args) => {
75
+ events.push(`create:${args[0]}`);
76
+ return create(...args);
77
+ });
78
+ const insert = globalThis.__InsertNodeToElementTemplate;
79
+ vi.spyOn(globalThis, '__InsertNodeToElementTemplate').mockImplementation((...args) => {
80
+ events.push('commit-root');
81
+ return insert(...args);
82
+ });
83
+ function First() {
84
+ events.push('render-first');
85
+ return h('__Card__:_et_direct_leaf', { attributeSlots: ['first', mtRef] });
86
+ }
87
+ function Second() {
88
+ events.push('render-second');
89
+ return h('__Card__:_et_direct_leaf', { attributeSlots: ['second'] });
90
+ }
91
+ setRoot({ __jsx: h('_et_direct_root', { $0: [h(First, null), h(Second, null)] }) });
92
+
93
+ try {
94
+ renderMainThread();
95
+ expect(events).toEqual([
96
+ 'render-first',
97
+ 'create:_et_direct_leaf',
98
+ 'render-second',
99
+ 'create:_et_direct_leaf',
100
+ 'create:_et_direct_root',
101
+ 'commit-root',
102
+ 'attach-ref',
103
+ ]);
104
+ } finally {
105
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
106
+ }
107
+ });
108
+
109
+ it('preserves context, class derived state, function hooks and transparent authored page metadata', () => {
110
+ const Context = createContext('default');
111
+ class Derived extends Component<{ initial: number }, { value: number }> {
112
+ static getDerivedStateFromProps(props: { initial: number }) {
113
+ return { value: props.initial + 1 };
114
+ }
115
+ override render() {
116
+ return h(Reader, { value: this.state.value });
117
+ }
118
+ }
119
+ function Reader(props: { value: number }) {
120
+ const context = useContext(Context);
121
+ const [value] = useState(props.value);
122
+ return h('__Card__:_et_direct_leaf', { attributeSlots: [`${context}:${value}`] });
123
+ }
124
+ const result = renderToElementTemplate(
125
+ h(__ElementTemplatePage, {
126
+ attributes: { id: 'page-id' },
127
+ $0: h(Context.Provider, { value: 'provided', children: h(Derived, { initial: 41 }) }),
128
+ }),
129
+ undefined,
130
+ );
131
+
132
+ expect(result.pageAttributes).toEqual({ id: 'page-id' });
133
+ expect(__SerializeElementTemplate(result.rootRefs[0]!)).toMatchObject({
134
+ templateKey: '_et_direct_leaf',
135
+ attributeSlots: ['provided:42'],
136
+ });
137
+ });
138
+
139
+ it('renders numeric slots in order even when named props were inserted in reverse order', () => {
140
+ registerTemplates([{
141
+ templateId: '_et_direct_slots',
142
+ compiledTemplate: {
143
+ kind: 'element',
144
+ type: 'view',
145
+ children: [
146
+ { kind: 'childSlot', type: 'slot', elementSlotIndex: 0 },
147
+ { kind: 'childSlot', type: 'slot', elementSlotIndex: 1 },
148
+ ],
149
+ },
150
+ }]);
151
+ const order: number[] = [];
152
+ function Child({ index }: { index: number }) {
153
+ order.push(index);
154
+ return h('_et_direct_leaf', { attributeSlots: [String(index)] });
155
+ }
156
+ const result = renderToElementTemplate(
157
+ h('_et_direct_slots', {
158
+ $1: h(Child, { index: 1 }),
159
+ $0: h(Child, { index: 0 }),
160
+ }),
161
+ undefined,
162
+ );
163
+
164
+ expect(order).toEqual([0, 1]);
165
+ expect(__SerializeElementTemplate(result.rootRefs[0]!)).toMatchObject({
166
+ childSlots: [
167
+ [{ templateKey: '_et_direct_leaf', attributeSlots: ['0'] }],
168
+ [{ templateKey: '_et_direct_leaf', attributeSlots: ['1'] }],
169
+ ],
170
+ });
171
+ });
172
+
173
+ it.each([
174
+ { name: 'missing', props: {}, childSlots: null },
175
+ { name: 'null', props: { $0: null }, childSlots: null },
176
+ { name: 'undefined', props: { $0: undefined }, childSlots: null },
177
+ { name: 'true', props: { $0: true }, childSlots: null },
178
+ { name: 'false', props: { $0: false }, childSlots: null },
179
+ { name: 'multiple empty slots', props: { $3: false, $1: true, $2: undefined, $0: null }, childSlots: null },
180
+ { name: 'empty array', props: { $0: [] }, childSlots: [[]] },
181
+ { name: 'empty string', props: { $0: '' }, childSlots: [[]] },
182
+ { name: 'function', props: { $0: () => {} }, childSlots: [[]] },
183
+ ])('preserves the native child-slot shape for $name children', ({ props, childSlots }) => {
184
+ const create = vi.spyOn(globalThis, '__CreateElementTemplate');
185
+
186
+ const result = renderToElementTemplate(h('_et_direct_root', props));
187
+
188
+ expect(create).toHaveBeenCalledTimes(1);
189
+ expect(create.mock.calls[0]?.[3]).toStrictEqual(childSlots);
190
+ expect(__SerializeElementTemplate(result.rootRefs[0]!)).toMatchObject({ childSlots: [[]] });
191
+ });
192
+
193
+ it.each([null, undefined, true, false])('preserves sparse slots and omits a trailing %s slot', (trailing) => {
194
+ registerTemplates([{
195
+ templateId: '_et_direct_sparse',
196
+ compiledTemplate: {
197
+ kind: 'element',
198
+ type: 'view',
199
+ children: [
200
+ { kind: 'childSlot', type: 'slot', elementSlotIndex: 0 },
201
+ { kind: 'childSlot', type: 'slot', elementSlotIndex: 2 },
202
+ { kind: 'childSlot', type: 'slot', elementSlotIndex: 4 },
203
+ ],
204
+ },
205
+ }]);
206
+ const create = vi.spyOn(globalThis, '__CreateElementTemplate');
207
+
208
+ const result = renderToElementTemplate(h('_et_direct_sparse', {
209
+ $4: trailing,
210
+ $2: h('_et_direct_leaf', { attributeSlots: ['child'] }),
211
+ $0: null,
212
+ }));
213
+
214
+ expect(create.mock.calls.map(args => args[0])).toEqual(['_et_direct_leaf', '_et_direct_sparse']);
215
+ const childSlots = new Array<ElementTemplateHandle[]>(3);
216
+ childSlots[2] = [create.mock.results[0]!.value];
217
+ expect(create.mock.calls[1]?.[3]).toStrictEqual(childSlots);
218
+ expect(__SerializeElementTemplate(result.rootRefs[0]!).childSlots?.[2]).toMatchObject([
219
+ { templateKey: '_et_direct_leaf', attributeSlots: ['child'] },
220
+ ]);
221
+ });
222
+
223
+ it('keeps reused vnode child arrays separate from each render native child slots', () => {
224
+ const leaf = h('_et_direct_leaf', { attributeSlots: ['child'] });
225
+ const nestedChildren = ['text'];
226
+ const children = [leaf, false, nestedChildren];
227
+ const vnode = h('_et_direct_root', { $0: children });
228
+ const create = vi.spyOn(globalThis, '__CreateElementTemplate');
229
+
230
+ const first = renderToElementTemplate(vnode);
231
+ const second = renderToElementTemplate(vnode);
232
+
233
+ expect(vnode.props['$0']).toBe(children);
234
+ expect(children).toEqual([leaf, false, nestedChildren]);
235
+ expect(nestedChildren).toEqual(['text']);
236
+ const rootCalls = create.mock.calls.filter(args => args[0] === '_et_direct_root');
237
+ expect(rootCalls).toHaveLength(2);
238
+ const firstSlots = rootCalls[0]![3]!;
239
+ const secondSlots = rootCalls[1]![3]!;
240
+ expect(firstSlots).not.toBe(children);
241
+ expect(firstSlots[0]).not.toBe(children);
242
+ expect(secondSlots).not.toBe(firstSlots);
243
+ expect(secondSlots[0]).not.toBe(firstSlots[0]);
244
+ expect(secondSlots[0]?.[0]).not.toBe(firstSlots[0]?.[0]);
245
+ for (const result of [first, second]) {
246
+ expect(__SerializeElementTemplate(result.rootRefs[0]!)).toMatchObject({
247
+ childSlots: [[
248
+ { templateKey: '_et_direct_leaf', attributeSlots: ['child'] },
249
+ { templateKey: '_et_builtin_raw_text', attributeSlots: ['text'] },
250
+ ]],
251
+ });
252
+ }
253
+ });
254
+
255
+ it('preserves sparse ordered inputs and named-slot native output across repeated renders', () => {
256
+ registerTemplates([{
257
+ templateId: '_et_ordered',
258
+ compiledTemplate: {
259
+ kind: 'element',
260
+ type: 'view',
261
+ children: Array.from(
262
+ { length: 9 },
263
+ (_, elementSlotIndex) => ({ kind: 'childSlot' as const, type: 'slot', elementSlotIndex }),
264
+ ),
265
+ },
266
+ }]);
267
+ const slots: unknown[] = [];
268
+ slots[1] = '';
269
+ slots[2] = 0;
270
+ slots[3] = false;
271
+ slots[4] = null;
272
+ slots[5] = Object.freeze(['first', Object.freeze([null, 'second'])]);
273
+ slots[6] = Object.freeze([]);
274
+ slots[8] = undefined;
275
+ Object.freeze(slots);
276
+ const named: Record<string, unknown> = {};
277
+ for (const index of Object.keys(slots)) named[`$${index}`] = slots[+index];
278
+ const create = vi.spyOn(globalThis, '__CreateElementTemplate');
279
+ const normalize = (input: Record<string, unknown>) => {
280
+ renderToElementTemplate(h('_et_ordered', input));
281
+ const call = create.mock.calls.findLast(args => args[0] === '_et_ordered')!;
282
+ return call[3]?.map(refs => refs.map(ref => __SerializeElementTemplate(ref).attributeSlots));
283
+ };
284
+ const expected = normalize(named);
285
+ expect(normalize({ slotChildren: slots })).toStrictEqual(expected);
286
+ expect(normalize({ slotChildren: slots })).toStrictEqual(expected);
287
+ expect(Object.keys(slots)).toEqual(['1', '2', '3', '4', '5', '6', '8']);
288
+ });
289
+
290
+ it('preserves context and unique hook IDs through ordered slot ancestors', () => {
291
+ const Context = createContext('default');
292
+ const seen: { id: string; value: string; count: number }[] = [];
293
+ function Reader() {
294
+ const id = useId();
295
+ const value = useContext(Context);
296
+ const [count] = useState(7);
297
+ seen.push({ id, value, count });
298
+ return id;
299
+ }
300
+ const makeTree = () =>
301
+ h(Context.Provider, {
302
+ value: 'provided',
303
+ children: h('_et_direct_root', {
304
+ slotChildren: [[
305
+ h(Reader, {}),
306
+ h('_et_direct_root', { slotChildren: [h(Reader, {})] }),
307
+ ]],
308
+ }),
309
+ });
310
+ renderToElementTemplate(makeTree());
311
+ expect(seen).toEqual([
312
+ { id: 'P0-0', value: 'provided', count: 7 },
313
+ { id: 'P0-1', value: 'provided', count: 7 },
314
+ ]);
315
+ seen.length = 0;
316
+ renderToElementTemplate(makeTree());
317
+ expect(seen.map(item => item.id)).toEqual(['P0-0', 'P0-1']);
318
+ });
319
+
320
+ it('keeps a reused vnode attribute array raw while preparing handle-specific event markers', () => {
321
+ const callback = vi.fn();
322
+ const attributes = ['ready', callback];
323
+ __etAttrPlanMap['__Card__:_et_direct_leaf'] = [1, adaptEventAttrSlot];
324
+ const vnode = h('__Card__:_et_direct_leaf', { attributeSlots: attributes });
325
+ const create = vi.spyOn(globalThis, '__CreateElementTemplate');
326
+
327
+ renderToElementTemplate(vnode, undefined);
328
+ renderToElementTemplate(vnode, undefined);
329
+
330
+ expect(attributes).toEqual(['ready', callback]);
331
+ expect(create.mock.calls[0]?.[2]).not.toBe(attributes);
332
+ expect(create.mock.calls[1]?.[2]).not.toBe(attributes);
333
+ expect(create.mock.calls[0]?.[2]?.[1]).not.toEqual(create.mock.calls[1]?.[2]?.[1]);
334
+ });
335
+
336
+ it('runs the second diff hook during direct traversal', () => {
337
+ const hooks = options as typeof options & { [DIFF2]?: (vnode: unknown, context: unknown) => void };
338
+ const previous = hooks[DIFF2];
339
+ const diff = vi.fn();
340
+ hooks[DIFF2] = diff;
341
+ const vnode = h('_et_direct_leaf', { attributeSlots: ['hook'] });
342
+ try {
343
+ renderToElementTemplate(vnode);
344
+ expect(diff).toHaveBeenCalledTimes(1);
345
+ expect(diff).toHaveBeenNthCalledWith(1, vnode, {});
346
+ } finally {
347
+ hooks[DIFF2] = previous;
348
+ }
349
+ });
350
+
351
+ it.each([null, undefined, true, false, '', () => {}])('ignores a non-rendering root value (%s)', (value) => {
352
+ const create = vi.spyOn(globalThis, '__CreateElementTemplate');
353
+ expect(renderToElementTemplate(value)).toMatchObject({
354
+ pageAttributes: null,
355
+ rootRefs: [],
356
+ rootSubtreeHandles: [],
357
+ });
358
+ expect(create).not.toHaveBeenCalled();
359
+ });
360
+
361
+ it('creates root text without a materialized host wrapper', () => {
362
+ const result = renderToElementTemplate('root text');
363
+ expect(result.rootSubtreeHandles).toEqual([[]]);
364
+ expect(__SerializeElementTemplate(result.rootRefs[0]!)).toMatchObject({
365
+ templateKey: '_et_builtin_raw_text',
366
+ attributeSlots: ['root text'],
367
+ });
368
+ });
369
+
370
+ it.each([
371
+ [h('view', {}), 'uncompiled host vnode: view'],
372
+ [{ type: 42, props: {} }, 'invalid vnode'],
373
+ ])('rejects an unsupported host input', (vnode, message) => {
374
+ expect(() => renderToElementTemplate(vnode)).toThrow(message as string);
375
+ });
376
+
377
+ it.each([
378
+ [
379
+ h('_et_direct_root', { $0: h(__ElementTemplatePage, { $0: null }) }),
380
+ 'must be the outermost element',
381
+ ],
382
+ [
383
+ [h(__ElementTemplatePage, { $0: null }), h(__ElementTemplatePage, { $0: null })],
384
+ 'does not support multiple authored <page /> elements',
385
+ ],
386
+ [
387
+ [h('_et_direct_leaf', {}), h(__ElementTemplatePage, { $0: null })],
388
+ 'must wrap all materialized roots',
389
+ ],
390
+ [
391
+ [h(__ElementTemplatePage, { $0: null }), h('_et_direct_leaf', {})],
392
+ 'must wrap all materialized roots',
393
+ ],
394
+ [
395
+ [h(__ElementTemplatePage, { $0: null }), 'outside page'],
396
+ 'must wrap all materialized roots',
397
+ ],
398
+ ])('rejects an authored page outside its root boundary', (vnode, message) => {
399
+ expect(() => renderToElementTemplate(vnode)).toThrow(message as string);
400
+ });
401
+
402
+ it('passes typed-list item handles in logical order while keeping item refs detached', () => {
403
+ const create = vi.spyOn(globalThis, '__CreateTypedElementTemplate');
404
+ const result = renderToElementTemplate(h('list', {
405
+ attributes: { id: 'feed' },
406
+ $0: [
407
+ h('_et_direct_leaf', { attributeSlots: ['a'], __listItemPlatformInfo: { 'item-key': 'a' } }),
408
+ h('_et_direct_leaf', { attributeSlots: ['b'], __listItemPlatformInfo: { 'item-key': 'b' } }),
409
+ ],
410
+ }));
411
+ expect(create).toHaveBeenCalledWith(
412
+ 'list',
413
+ expect.objectContaining({ id: 'feed', 'component-at-index': expect.any(Function) }),
414
+ null,
415
+ -3,
416
+ { listChildren: [elementTemplateRegistry.get(-1), elementTemplateRegistry.get(-2)] },
417
+ );
418
+ expect(result.rootRefs).toEqual([elementTemplateRegistry.get(-3)]);
419
+ expect(result.rootSubtreeHandles).toEqual([[]]);
420
+ });
421
+
422
+ it.each([undefined, true, false])('creates an empty typed list for a non-rendering slot (%s)', (children) => {
423
+ const create = vi.spyOn(globalThis, '__CreateTypedElementTemplate');
424
+ const result = renderToElementTemplate(h('list', { $0: children }));
425
+ expect(create.mock.calls[0]?.[4]).toEqual({ listChildren: [] });
426
+ expect(result.rootRefs).toHaveLength(1);
427
+ });
428
+
429
+ it.each([
430
+ [{ $1: h('_et_direct_leaf', {}) }, 'only supports logical slot $0'],
431
+ [{ $0: 'text item' }, 'received text logical child'],
432
+ [{ $0: h('_et_direct_leaf', {}) }, 'received a non-list-item root'],
433
+ [
434
+ { $0: h('_et_direct_leaf', { isReady: false, __listItemPlatformInfo: {} }) },
435
+ 'does not support deferred list items',
436
+ ],
437
+ ])('rejects unsupported typed-list children', (props, message) => {
438
+ const create = vi.spyOn(globalThis, '__CreateElementTemplate');
439
+ const createTyped = vi.spyOn(globalThis, '__CreateTypedElementTemplate');
440
+ const flush = vi.spyOn(globalThis, '__FlushElementTree');
441
+ const lifecycle = vi.fn();
442
+ vi.stubGlobal('__OnLifecycleEvent', lifecycle);
443
+
444
+ try {
445
+ expect(() => renderToElementTemplate(h('list', props))).toThrow(message as string);
446
+ expect(create).not.toHaveBeenCalled();
447
+ expect(createTyped).not.toHaveBeenCalled();
448
+ expect(flush).not.toHaveBeenCalled();
449
+ expect(lifecycle).not.toHaveBeenCalled();
450
+ } finally {
451
+ vi.unstubAllGlobals();
452
+ }
453
+ });
454
+
455
+ it('reports native creation failures at the lifecycle boundary and serializes an empty page', () => {
456
+ const reportError = vi.spyOn(lynx, 'reportError').mockImplementation(() => {});
457
+ vi.spyOn(globalThis, '__CreateElementTemplate').mockImplementation(() => {
458
+ throw new Error('native create failed');
459
+ });
460
+ const attributes = vi.spyOn(globalThis, '__SetAttributeOfElementTemplate');
461
+ const insert = vi.spyOn(globalThis, '__InsertNodeToElementTemplate');
462
+ const serialize = vi.spyOn(globalThis, '__SerializeElementTemplate');
463
+ setRoot({ __jsx: h('__Card__:_et_direct_leaf', { attributeSlots: ['ready'] }) });
464
+
465
+ renderMainThread();
466
+ expect(reportError).toHaveBeenCalledWith(expect.objectContaining({ message: 'native create failed' }));
467
+ expect(attributes).toHaveBeenCalledTimes(1);
468
+ expect(insert).not.toHaveBeenCalled();
469
+ expect(serialize).toHaveBeenCalledTimes(1);
470
+ expect(serialize.mock.results[0]?.value).toMatchObject({ tag: 'page', attributes: null, childSlots: null });
471
+ });
472
+
473
+ it('does not attach a completed earlier sibling if a later component throws', () => {
474
+ const insert = vi.spyOn(globalThis, '__InsertNodeToElementTemplate');
475
+ const serialize = vi.spyOn(globalThis, '__SerializeElementTemplate');
476
+ const reportError = vi.spyOn(lynx, 'reportError').mockImplementation(() => {});
477
+ function Failure(): never {
478
+ throw new Error('later sibling failed');
479
+ }
480
+ setRoot({ __jsx: [h('__Card__:_et_direct_leaf', { attributeSlots: ['ready'] }), h(Failure, null)] });
481
+
482
+ renderMainThread();
483
+
484
+ expect(insert).not.toHaveBeenCalled();
485
+ expect(serialize).toHaveBeenCalledTimes(1);
486
+ expect(serialize.mock.results[0]?.value).toMatchObject({ tag: 'page', attributes: null, childSlots: null });
487
+ expect(reportError).toHaveBeenCalledWith(expect.objectContaining({ message: 'later sibling failed' }));
488
+ // Native creation can precede the failure, but no root from that pass commits.
489
+ reportError.mockClear();
490
+ });
491
+ });
@@ -1,21 +1,7 @@
1
1
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
2
 
3
- vi.mock('../../../../src/element-template/runtime/render/render-to-opcodes.js', async () => {
4
- const actual = await vi.importActual('../../../../src/element-template/runtime/render/render-to-opcodes.js');
5
- return {
6
- ...actual,
7
- render: vi.fn(),
8
- };
9
- });
3
+ import { h } from 'preact';
10
4
 
11
- import {
12
- __OpAttr,
13
- __OpBegin,
14
- __OpEnd,
15
- __OpSlot,
16
- __OpText,
17
- render as mockRender,
18
- } from '../../../../src/element-template/runtime/render/render-to-opcodes.js';
19
5
  import { renderMainThread } from '../../../../src/element-template/runtime/render/render-main-thread.js';
20
6
  import type { ElementTemplateHydrateCommitContext } from '../../../../src/element-template/protocol/types.js';
21
7
  import { createElementTemplatePage, setupPage } from '../../../../src/element-template/runtime/page/page.js';
@@ -53,7 +39,7 @@ describe('renderMainThread contract', () => {
53
39
 
54
40
  resetTemplateId();
55
41
  elementTemplateRegistry.clear();
56
- setRoot({ __jsx: { type: 'test-root' } });
42
+ setRoot({ __jsx: h('_et_contract_root', { attributeSlots: ['main', 'lazy-entry'], $0: 'hello' }) });
57
43
  setupPage(createElementTemplatePage());
58
44
  globalThis.__MAIN_THREAD__ = true;
59
45
  globalThis.__BACKGROUND__ = false;
@@ -73,18 +59,6 @@ describe('renderMainThread contract', () => {
73
59
  getJSContext?: () => { dispatchEvent: typeof dispatchEvent };
74
60
  }).getJSContext = vi.fn(() => ({ dispatchEvent }));
75
61
 
76
- vi.mocked(mockRender).mockReturnValue([
77
- __OpBegin,
78
- { type: '_et_contract_root' },
79
- __OpAttr,
80
- ['main', 'lazy-entry'],
81
- __OpSlot,
82
- 0,
83
- __OpText,
84
- 'hello',
85
- __OpEnd,
86
- ]);
87
-
88
62
  renderMainThread();
89
63
 
90
64
  const nativeLog = lastMock!.nativeLog;