@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
@@ -1,522 +0,0 @@
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
- import { Component, Fragment, createContext, h, options } from 'preact';
5
- import { Suspense, use } from 'preact/compat';
6
- import { useState } from '@lynx-js/react/lepus/hooks';
7
- import { describe, expect, it } from 'vitest';
8
-
9
- import {
10
- __OpAttr,
11
- __OpBegin,
12
- __OpEnd,
13
- __OpPageEnd,
14
- __OpPageStart,
15
- __OpSlot,
16
- __OpText,
17
- renderToString,
18
- } from '../../../../src/element-template/runtime/render/render-to-opcodes';
19
- import { __ElementTemplatePage } from '../../../../src/element-template/runtime/page/authored-page';
20
- import { DIFFED, PARENT } from '../../../../src/shared/render-constants';
21
-
22
- describe('Element Template renderToOpcodes', () => {
23
- it('should export correct opcodes', () => {
24
- expect(__OpBegin).toBe(0);
25
- expect(__OpEnd).toBe(1);
26
- expect(__OpAttr).toBe(2);
27
- expect(__OpText).toBe(3);
28
- expect(__OpSlot).toBe(4);
29
- expect(__OpPageStart).toBe(5);
30
- expect(__OpPageEnd).toBe(6);
31
- });
32
-
33
- it('lets use() read a context', () => {
34
- const Ctx = createContext('default');
35
-
36
- function Reader() {
37
- return use(Ctx);
38
- }
39
-
40
- expect(
41
- renderToString(h(Ctx.Provider, { value: 'provided' }, h(Reader, null))),
42
- ).toContain('provided');
43
- expect(renderToString(h(Reader, null))).toContain('default');
44
- });
45
-
46
- it('lets use() read a context from a class that declares contextType', () => {
47
- const Ctx = createContext('default');
48
- const seen = [];
49
-
50
- class Reader extends Component {
51
- static contextType = Ctx;
52
- render() {
53
- seen.push(['this.context', this.context], ['use', use(Ctx)]);
54
- return 'ok';
55
- }
56
- }
57
-
58
- renderToString(h(Ctx.Provider, { value: 'provided' }, h(Reader, null)));
59
-
60
- expect(seen).toEqual([['this.context', 'provided'], ['use', 'provided']]);
61
- });
62
-
63
- it('lets use() read a context from a function that declares contextType', () => {
64
- const Ctx = createContext('default');
65
- const seen = [];
66
-
67
- function Reader(_props, context) {
68
- seen.push(['arg', context], ['use', use(Ctx)]);
69
- return 'ok';
70
- }
71
- Reader.contextType = Ctx;
72
-
73
- renderToString(h(Ctx.Provider, { value: 'provided' }, h(Reader, null)));
74
-
75
- // `context` is the resolved contextType value here, so `use` has to read
76
- // the provider map from `_globalContext` instead.
77
- expect(seen).toEqual([['arg', 'provided'], ['use', 'provided']]);
78
- });
79
-
80
- it('emits slot opcodes for ET host nodes using $N named props', () => {
81
- const Template = '_et_test_root';
82
- const opcodes = renderToString(<Template $3='marker' />);
83
-
84
- expect(opcodes[0]).toBe(__OpBegin);
85
- expect(opcodes).toContain(__OpSlot);
86
- expect(opcodes[opcodes.indexOf(__OpSlot) + 1]).toBe(3);
87
- expect(opcodes).toContain(__OpEnd);
88
- });
89
-
90
- it.each([
91
- ['_et_compiled', 'attributeSlots', ['title']],
92
- ['list', 'attributes', { id: 'feed' }],
93
- ])('emits one attribute payload for %s without a name entry', (type, propName, attributes) => {
94
- const opcodes = renderToString(h(type, { [propName]: attributes }));
95
-
96
- expect(opcodes).toEqual([
97
- __OpBegin,
98
- expect.objectContaining({ type }),
99
- __OpAttr,
100
- attributes,
101
- __OpEnd,
102
- ]);
103
- expect(opcodes[3]).toBe(attributes);
104
- expect(renderToString(h(type, {}))).toEqual([
105
- __OpBegin,
106
- expect.objectContaining({ type }),
107
- __OpEnd,
108
- ]);
109
- });
110
-
111
- it('emits prepared outermost page attrs as root metadata and keeps children transparent', () => {
112
- const Template = '_et_page_child';
113
- const opcodes = renderToString(
114
- <__ElementTemplatePage
115
- attributes={{ id: 'screen' }}
116
- $0={<Template />}
117
- />,
118
- );
119
-
120
- expect(opcodes.slice(0, 2)).toEqual([
121
- __OpPageStart,
122
- { id: 'screen' },
123
- ]);
124
- expect(opcodes[2]).toBe(__OpBegin);
125
- expect(opcodes[3]).toMatchObject({ type: Template });
126
- expect(opcodes.at(-2)).toBe(__OpEnd);
127
- expect(opcodes.at(-1)).toBe(__OpPageEnd);
128
- });
129
-
130
- it.each(['direct', 'spread'])('prepares %s page refs from typed attributes', mode => {
131
- const ref = () => {};
132
- const attributes = mode === 'direct'
133
- ? { id: 'screen', ref }
134
- : { id: 'screen', ...{ ref } };
135
- const vnode = h(__ElementTemplatePage, { attributes });
136
-
137
- expect(renderToString(vnode).slice(0, 2)).toEqual([
138
- __OpPageStart,
139
- { id: 'screen', ref: '0-0' },
140
- ]);
141
- });
142
-
143
- it('does not emit the development page-end instruction in production', () => {
144
- const originalDev = globalThis.__DEV__;
145
- globalThis.__DEV__ = false;
146
- try {
147
- const opcodes = renderToString(
148
- <__ElementTemplatePage attributes={{ id: 'screen' }} $0='content' />,
149
- );
150
-
151
- expect(opcodes.slice(0, 2)).toEqual([
152
- __OpPageStart,
153
- { id: 'screen' },
154
- ]);
155
- expect(opcodes.at(-2)).toBe(__OpText);
156
- expect(opcodes.at(-1)).toBe('content');
157
- expect(opcodes).not.toContain(__OpPageEnd);
158
- } finally {
159
- globalThis.__DEV__ = originalDev;
160
- }
161
- });
162
-
163
- it('skips empty $N slots and renders only the populated indices', () => {
164
- const Template = '_et_test_root';
165
- const opcodes = renderToString(
166
- <Template $0={false} $1='first' $2={null} $3 $4='second' />,
167
- );
168
-
169
- const normalized = opcodes.map(item => (typeof item === 'object' ? '<vnode>' : item));
170
- expect(normalized).toEqual([
171
- __OpBegin,
172
- '<vnode>',
173
- __OpSlot,
174
- 1,
175
- __OpText,
176
- 'first',
177
- __OpSlot,
178
- 4,
179
- __OpText,
180
- 'second',
181
- __OpEnd,
182
- ]);
183
- });
184
-
185
- it('ignores function values in render output', () => {
186
- expect(renderToString(() => {})).toEqual([]);
187
- });
188
-
189
- it('throws in development when a plain host vnode reaches the ET render path', () => {
190
- expect(() => renderToString(h('view', null))).toThrow(
191
- 'Element Template main-thread renderer received an uncompiled host vnode: view',
192
- );
193
- });
194
-
195
- it('emits typed list attributes and logical children through slot 0', () => {
196
- const ItemTemplate = '_et_list_item';
197
- const attributes = { id: 'feed' };
198
- const itemPlatformInfo = { 'item-key': 'a' };
199
-
200
- const opcodes = renderToString(
201
- h('list', {
202
- attributes,
203
- $0: <ItemTemplate __listItemPlatformInfo={itemPlatformInfo} />,
204
- }),
205
- );
206
-
207
- expect(opcodes[0]).toBe(__OpBegin);
208
- expect(opcodes[1]).toMatchObject({ type: 'list' });
209
- expect(opcodes[2]).toBe(__OpAttr);
210
- expect(opcodes[3]).toBe(attributes);
211
- expect(opcodes[4]).toBe(__OpSlot);
212
- expect(opcodes[5]).toBe(0);
213
- expect(opcodes[6]).toBe(__OpBegin);
214
- expect(opcodes[7]).toMatchObject({
215
- type: ItemTemplate,
216
- props: {
217
- __listItemPlatformInfo: itemPlatformInfo,
218
- },
219
- });
220
- expect(opcodes.at(-1)).toBe(__OpEnd);
221
- });
222
-
223
- it('rejects non-zero typed list logical slots in development', () => {
224
- const ItemTemplate = '_et_list_item';
225
-
226
- expect(() =>
227
- renderToString(
228
- h('list', {
229
- $1: <ItemTemplate __listItemPlatformInfo={{ 'item-key': 'a' }} />,
230
- }),
231
- )
232
- ).toThrow('Element Template typed list only supports logical slot $0.');
233
- });
234
-
235
- it('rejects non-list uncompiled hosts outside development too', () => {
236
- const originalDev = globalThis.__DEV__;
237
- globalThis.__DEV__ = false;
238
- try {
239
- expect(() => renderToString(h('view', null))).toThrow(
240
- 'Element Template main-thread renderer received an uncompiled host vnode: view',
241
- );
242
- } finally {
243
- globalThis.__DEV__ = originalDev;
244
- }
245
- });
246
-
247
- it('throws in development when an invalid vnode reaches the ET render path', () => {
248
- expect(() => renderToString({ type: null, props: {} })).toThrow(
249
- 'Element Template main-thread renderer received an invalid vnode.',
250
- );
251
- });
252
-
253
- it('cleans vnodes before throwing development renderer invariant errors', () => {
254
- const previousDiffed = options[DIFFED];
255
- const cleaned = [];
256
- const plainHostVNode = h('view', null);
257
- const invalidVNode = { type: null, props: {} };
258
- options[DIFFED] = vnode => {
259
- cleaned.push(vnode);
260
- };
261
-
262
- try {
263
- expect(() => renderToString(plainHostVNode)).toThrow(
264
- 'Element Template main-thread renderer received an uncompiled host vnode: view',
265
- );
266
- expect(() => renderToString(invalidVNode)).toThrow(
267
- 'Element Template main-thread renderer received an invalid vnode.',
268
- );
269
- } finally {
270
- options[DIFFED] = previousDiffed;
271
- }
272
-
273
- expect(cleaned).toEqual([plainHostVNode, invalidVNode]);
274
- expect(plainHostVNode[PARENT]).toBeUndefined();
275
- expect(invalidVNode[PARENT]).toBeUndefined();
276
- });
277
-
278
- it('calls the unmount option while cleaning rendered vnodes', () => {
279
- const previousUnmount = options.unmount;
280
- let unmountCount = 0;
281
- options.unmount = () => {
282
- unmountCount += 1;
283
- };
284
-
285
- try {
286
- renderToString(h('_et_builtin_raw_text', { attributeSlots: ['cleanup'] }));
287
- } finally {
288
- options.unmount = previousUnmount;
289
- }
290
-
291
- expect(unmountCount).toBeGreaterThan(0);
292
- });
293
-
294
- it('renders direct fragments', () => {
295
- expect(renderToString(
296
- h(Fragment, null, 'direct-fragment'),
297
- )).toContain('direct-fragment');
298
- });
299
-
300
- it('unwraps unkeyed top-level fragments returned from components', () => {
301
- function UnkeyedFragment() {
302
- return h(Fragment, null, 'unkeyed-fragment');
303
- }
304
-
305
- expect(renderToString(h(UnkeyedFragment, null))).toContain('unkeyed-fragment');
306
- });
307
-
308
- it('reuses class component instances and reapplies derived state from props', () => {
309
- class DerivedMessage extends Component {
310
- state = {
311
- value: 'seed',
312
- };
313
-
314
- static getDerivedStateFromProps(props, state) {
315
- return {
316
- value: `${props.label}:${state.value}`,
317
- };
318
- }
319
-
320
- render() {
321
- return this.state.value;
322
- }
323
- }
324
-
325
- const vnode = h(DerivedMessage, { label: 'Ada' });
326
- expect(renderToString(vnode)).toContain('Ada:seed');
327
-
328
- vnode.props = { label: 'Linus' };
329
- expect(renderToString(vnode)).toContain('Linus:seed');
330
- });
331
-
332
- it('passes both modern and legacy context into component rendering', () => {
333
- const ThemeContext = createContext('light');
334
-
335
- class LegacyProvider extends Component {
336
- getChildContext() {
337
- return {
338
- legacyTheme: 'legacy-dark',
339
- };
340
- }
341
-
342
- render() {
343
- return this.props.children;
344
- }
345
- }
346
-
347
- class ModernReader extends Component {
348
- static contextType = ThemeContext;
349
-
350
- render() {
351
- return this.context;
352
- }
353
- }
354
-
355
- function LegacyReader(_props, context) {
356
- return context.legacyTheme;
357
- }
358
-
359
- function FragmentWrapper() {
360
- return h(
361
- Fragment,
362
- null,
363
- h(ModernReader, null),
364
- h(LegacyReader, null),
365
- );
366
- }
367
-
368
- const opcodes = renderToString(
369
- h(
370
- ThemeContext.Provider,
371
- { value: 'modern-dark' },
372
- h(
373
- LegacyProvider,
374
- null,
375
- h(FragmentWrapper, null),
376
- ),
377
- ),
378
- );
379
-
380
- expect(opcodes).toContain('modern-dark');
381
- expect(opcodes).toContain('legacy-dark');
382
- });
383
-
384
- it('renders suspense fallbacks when a child throws a promise', () => {
385
- function AsyncText() {
386
- throw Promise.resolve();
387
- }
388
-
389
- const opcodes = renderToString(
390
- h(
391
- Suspense,
392
- { fallback: 'loading' },
393
- h(AsyncText, null),
394
- ),
395
- );
396
-
397
- expect(opcodes).toContain('loading');
398
- });
399
-
400
- it('renders every Fragment fallback child when a child suspends', () => {
401
- function AsyncText() {
402
- throw Promise.resolve();
403
- }
404
-
405
- const opcodes = renderToString(
406
- h(
407
- Suspense,
408
- {
409
- fallback: h(
410
- Fragment,
411
- null,
412
- 'loading 1',
413
- 'loading 2',
414
- ),
415
- },
416
- h(AsyncText, null),
417
- ),
418
- );
419
-
420
- expect(opcodes).toContain('loading 1');
421
- expect(opcodes).toContain('loading 2');
422
- });
423
-
424
- it('renders resolved outer content with the nearest inner Suspense fallback', () => {
425
- function AsyncText() {
426
- throw Promise.resolve();
427
- }
428
-
429
- function OuterContent() {
430
- return h(
431
- Fragment,
432
- null,
433
- 'before',
434
- h(
435
- Suspense,
436
- { fallback: 'inner loading' },
437
- h(AsyncText, null),
438
- ),
439
- 'after',
440
- );
441
- }
442
-
443
- const opcodes = renderToString(
444
- h(
445
- Suspense,
446
- { fallback: 'outer loading' },
447
- h(OuterContent, null),
448
- ),
449
- );
450
-
451
- expect(opcodes).toContain('before');
452
- expect(opcodes).toContain('inner loading');
453
- expect(opcodes).toContain('after');
454
- expect(opcodes).not.toContain('outer loading');
455
- });
456
-
457
- it('renders already resolved Suspense content without fallback', async () => {
458
- let resolved = false;
459
- const pending = Promise.resolve();
460
- void pending.then(() => {
461
- resolved = true;
462
- });
463
-
464
- function Suspender() {
465
- if (!resolved) {
466
- throw pending;
467
- }
468
- return 'ready';
469
- }
470
-
471
- const pendingOpcodes = renderToString(
472
- h(
473
- Suspense,
474
- { fallback: 'loading' },
475
- h(Suspender, null),
476
- ),
477
- );
478
-
479
- expect(pendingOpcodes).toContain('loading');
480
- expect(pendingOpcodes).not.toContain('ready');
481
-
482
- await pending;
483
-
484
- const resolvedOpcodes = renderToString(
485
- h(
486
- Suspense,
487
- { fallback: 'loading' },
488
- h(Suspender, null),
489
- ),
490
- );
491
-
492
- expect(resolvedOpcodes).toContain('ready');
493
- expect(resolvedOpcodes).not.toContain('loading');
494
- });
495
-
496
- it('does not re-render function components when main-thread hooks schedule an update during render', () => {
497
- function DirtyHookComponent() {
498
- const [count, setCount] = useState(0);
499
- if (count === 0) {
500
- setCount(1);
501
- }
502
- return String(count);
503
- }
504
-
505
- expect(renderToString(h(DirtyHookComponent, null))).toContain('0');
506
- });
507
-
508
- it('falls back to the default context value when no provider is mounted', () => {
509
- const ThemeContext = createContext('default-theme');
510
-
511
- class ThemeReader extends Component {
512
- static contextType = ThemeContext;
513
-
514
- render() {
515
- return this.context;
516
- }
517
- }
518
-
519
- const opcodes = renderToString(h(ThemeReader, null));
520
- expect(opcodes).toContain('default-theme');
521
- });
522
- });