@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
@@ -16,7 +16,7 @@ export interface WorkletRef<T> {
16
16
  interface ClosureValueType_ extends Record<string, ClosureValueType> {
17
17
  }
18
18
  export type ClosureValueType = null | undefined | string | boolean | number | Worklet | WorkletRef<unknown> | Element | (((...args: unknown[]) => unknown) & {
19
- ctxRef?: WeakRef<object>;
19
+ boundCtx?: object;
20
20
  }) | ClosureValueType_ | ClosureValueType[];
21
21
  export interface Worklet {
22
22
  _wkltId: string;
@@ -35,7 +35,7 @@ function hydrateCtxImpl(ctx, firstScreenCtx, execId) {
35
35
  }
36
36
  else {
37
37
  const firstScreenValue = typeof firstScreenCtxObj[key] === 'function'
38
- ? firstScreenCtxObj[key].ctxRef?.deref()
38
+ ? firstScreenCtxObj[key].boundCtx
39
39
  : firstScreenCtxObj[key];
40
40
  hydrateCtxImpl(ctxObj[key], firstScreenValue, execId);
41
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"hydrate.js","sourceRoot":"","sources":["../../src/worklet-runtime/hydrate.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY,EAAE,cAAuB;IAC9D,OAAO,CAAC,YAAY,EAAE,GAAG,EAAE;QACzB,cAAc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;AAED;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAC3B,KAAmB,EACnB,KAA8B;IAE9B,IAAI,YAAY,IAAI,KAAK,EAAE,CAAC;QAC1B,qCAAqC;QACrC,OAAO;IACT,CAAC;IACD,eAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;AAC1D,CAAC;AAED;;;;;GAKG;AACH,SAAS,gCAAgC,CACvC,MAAkC,EAAE,oCAAoC;AACxE,iBAA6C,EAAE,kEAAkE;AACjH,MAAc;IAEd,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAE,CAAC;QAC9B,MAAM,gBAAgB,GAA2B,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC3E,IAAI,CAAC,gBAAgB,EAAE,aAAa,EAAE,CAAC;YACrC,IAAI,gBAAgB,EAAE,CAAC;gBACrB,gBAAgB,CAAC,cAAc,GAAG,KAAK,CAAC;gBACxC,gBAAgB,CAAC,OAAO,GAAG,MAAM,CAAC;gBAClC,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;YACzC,CAAC;YACD,SAAS;QACX,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,gBAAgB,CAAC,aAAa,EAAE,CAAC;YACnD,MAAM,OAAO,GAAG,eAAgB,CAAC,yBAAyB;iBACvD,8BAA8B,CAAC,KAAK,CAAC,CAAC;YACzC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,SAAS;YACX,CAAC;YACD,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;YACvB,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -134,15 +134,14 @@ const transformWorkletInner = (value, depth, ctx) => {
134
134
  if (isWorklet) {
135
135
  const isRootWorklet = subObj === ctx;
136
136
  const boundCtx = { ...subObj };
137
- // `subObj` is worklet ctx. Shallow copy it to prevent the transformed worklet from referencing ctx.
138
- // This would result in the value of `workletCache` referencing its key.
137
+ // Keep the original context collectible. PrimJS traces WeakMap values even
138
+ // when their keys are otherwise unreachable, so the cached function must not point back to its key.
139
139
  obj[key] = lynxWorkletImpl._workletMap[subObj._wkltId]
140
140
  .bind(boundCtx);
141
141
  if (!isRootWorklet) {
142
- const ctxRef = createWeakCtxRef(subObj);
143
- if (ctxRef) {
144
- obj[key].ctxRef = ctxRef;
145
- }
142
+ // Hydration needs the same context that the function already owns through bind().
143
+ // The original nested context can disappear after its parent replaces it with this function.
144
+ obj[key].boundCtx = boundCtx;
146
145
  }
147
146
  continue;
148
147
  }
@@ -154,13 +153,5 @@ const transformWorkletInner = (value, depth, ctx) => {
154
153
  }
155
154
  }
156
155
  };
157
- function createWeakCtxRef(ctx) {
158
- try {
159
- return new WeakRef(ctx);
160
- }
161
- catch {
162
- return undefined;
163
- }
164
- }
165
156
  export { initWorklet };
166
157
  //# sourceMappingURL=workletRuntime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"workletRuntime.js","sourceRoot":"","sources":["../../src/worklet-runtime/workletRuntime.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAChG,OAAO,EA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,EAAE,WAAW,EAAE,CAAC"}
@@ -133,6 +133,7 @@ const useState: typeof usePreactState = (__BACKGROUND__ && isProfiling)
133
133
  * @param effect - Imperative function that can return a cleanup function
134
134
  * @param deps - If present, effect will only activate if the values in the list change (using ===).
135
135
  *
136
+ * @function
136
137
  * @public
137
138
  */
138
139
  const useEffect: (effect: EffectCallback, deps?: DependencyList) => void = (__BACKGROUND__ && isProfiling)
@@ -147,6 +148,7 @@ const useEffect: (effect: EffectCallback, deps?: DependencyList) => void = (__BA
147
148
  * @param effect - Imperative function that can return a cleanup function
148
149
  * @param deps - If present, effect will only activate if the values in the list change (using ===).
149
150
  *
151
+ * @function
150
152
  * @public
151
153
  *
152
154
  * @deprecated `useLayoutEffect` in the background thread cannot offer the precise timing for reading layout information and synchronously re-render, which is different from React.
@@ -0,0 +1,62 @@
1
+ // Copyright 2026 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
+ export const sRuntimeVersion: symbol = Symbol.for('__REACT_LYNX_RUNTIME_VERSION__');
6
+
7
+ function getTarget(): typeof globalThis & Record<symbol, unknown> {
8
+ return (__LEPUS__ ? globalThis : lynx) as typeof globalThis & Record<symbol, unknown>;
9
+ }
10
+
11
+ /**
12
+ * Record the `@lynx-js/react` runtime version compiled into this bundle.
13
+ *
14
+ * Every lazy bundle bundles its own copy of the `@lynx-js/react` runtime. The
15
+ * host template is loaded first, so the first registration wins and the
16
+ * recorded value reflects the host's runtime version. This function only
17
+ * records the version so it is available for later inspection; it does not
18
+ * compare versions or throw.
19
+ */
20
+ export function registerRuntimeVersion(version: string | undefined): void {
21
+ // Older versions of the build plugin do not stamp `__RUNTIME_VERSION__`, so
22
+ // there is nothing to record.
23
+ if (!version) {
24
+ return;
25
+ }
26
+
27
+ const target = getTarget();
28
+ const currentVersion = target[sRuntimeVersion] as string | undefined;
29
+
30
+ // Log host and bundle versions so online reports can diagnose mismatches.
31
+ // Only emit on the background thread — the main-thread copy would be a
32
+ // duplicate report of the same values.
33
+ // TODO: on repeated registration, compare and surface a compatibility check.
34
+ if (__JS__) {
35
+ console.alog?.(
36
+ `[ReactLynx] new runtime version: ${version}${
37
+ currentVersion === undefined ? '' : `, current version: ${currentVersion}`
38
+ }`,
39
+ );
40
+ }
41
+
42
+ // The host registers first; keep its version and let later lazy bundles be
43
+ // no-ops so the recorded value always represents the host runtime.
44
+ if (currentVersion !== undefined) {
45
+ return;
46
+ }
47
+
48
+ Object.defineProperty(target, sRuntimeVersion, {
49
+ value: version,
50
+ enumerable: false,
51
+ writable: false,
52
+ configurable: true,
53
+ });
54
+ }
55
+
56
+ /**
57
+ * Read the `@lynx-js/react` runtime version recorded by the host template, or
58
+ * `undefined` when the host was built by a plugin that does not stamp it.
59
+ */
60
+ export function getRuntimeVersion(): string | undefined {
61
+ return getTarget()[sRuntimeVersion] as string | undefined;
62
+ }
@@ -13,7 +13,7 @@ import {
13
13
  export interface BackgroundElementTemplateDocument {
14
14
  createElement(type: string): BackgroundElementTemplateInstance;
15
15
  createElementNS(ns: string, type: string): BackgroundElementTemplateInstance;
16
- createTextNode(text: string): BackgroundElementTemplateInstance;
16
+ createTextNode(text: string | number): BackgroundElementTemplateInstance;
17
17
  }
18
18
 
19
19
  export function setupBackgroundElementTemplateDocument(): BackgroundElementTemplateDocument {
@@ -30,8 +30,8 @@ export function setupBackgroundElementTemplateDocument(): BackgroundElementTempl
30
30
  }
31
31
  return new BackgroundElementTemplateInstance(type);
32
32
  },
33
- createTextNode(text: string): BackgroundElementTemplateInstance {
34
- return new BackgroundElementTemplateInstance(BUILTIN_RAW_TEXT_TEMPLATE_KEY, [text]);
33
+ createTextNode(text: string | number): BackgroundElementTemplateInstance {
34
+ return new BackgroundElementTemplateInstance(BUILTIN_RAW_TEXT_TEMPLATE_KEY, [String(text)]);
35
35
  },
36
36
  };
37
37
 
@@ -40,12 +40,17 @@ export function hydrateRootChildrenIntoContext(
40
40
  serializedChildren: SerializedEtNode[],
41
41
  root: BackgroundElementTemplateInstance,
42
42
  ): boolean {
43
- return hydrateChildListIntoContext(
44
- ELEMENT_TEMPLATE_PAGE_HANDLE_ID,
45
- ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX,
46
- serializedChildren,
47
- root.childNodes,
48
- );
43
+ try {
44
+ return hydrateChildListIntoContext(
45
+ ELEMENT_TEMPLATE_PAGE_HANDLE_ID,
46
+ ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX,
47
+ serializedChildren,
48
+ root.childNodes,
49
+ );
50
+ } finally {
51
+ // Template identities only need caching for this synchronous hydration pass.
52
+ backgroundHydrateKeys.clear();
53
+ }
49
54
  }
50
55
 
51
56
  function isSerializedCompiledNode(serialized: SerializedEtNode): serialized is SerializedCompiledNode {
@@ -57,7 +62,6 @@ function isSerializedTypedListNode(serialized: SerializedEtNode): serialized is
57
62
  }
58
63
 
59
64
  interface HydrateChildListDiff {
60
- hasChanges: boolean;
61
65
  // Background child at a new slot index that has no matching serialized child.
62
66
  insertions: Record<number, BackgroundElementTemplateInstance>;
63
67
  insertionCount: number;
@@ -73,7 +77,6 @@ function hydrateMatchingChildrenAndDiffSlot(
73
77
  ): HydrateChildListDiff | null {
74
78
  let lastPlacedIndex = 0;
75
79
  const result: HydrateChildListDiff = {
76
- hasChanges: false,
77
80
  insertions: {},
78
81
  insertionCount: 0,
79
82
  removals: [],
@@ -93,11 +96,7 @@ function hydrateMatchingChildrenAndDiffSlot(
93
96
  // Normalize the background instance's full `${entry}:${key}` type tag to the
94
97
  // same native identity the serialized side uses (sentinel folded to the main
95
98
  // card), so main-card nodes match regardless of the `__Card__` prefix.
96
- const parsedBackgroundType = parseElementTemplateType(backgroundChild.type);
97
- const backgroundKey = elementTemplateIdentityKey(
98
- parsedBackgroundType.templateKey,
99
- parsedBackgroundType.bundleUrl,
100
- );
99
+ const backgroundKey = getBackgroundNodeHydrateKey(backgroundChild.type);
101
100
  const serializedCandidates = serializedByNodeKey[backgroundKey];
102
101
  const candidateCursor = serializedCursorByNodeKey[backgroundKey] ?? 0;
103
102
  const matchedSerialized = serializedCandidates?.[candidateCursor];
@@ -110,14 +109,12 @@ function hydrateMatchingChildrenAndDiffSlot(
110
109
  }
111
110
  if (oldIndex < lastPlacedIndex) {
112
111
  result.moves[oldIndex] = { toIndex: i, instance: backgroundChild };
113
- result.hasChanges = true;
114
112
  } else {
115
113
  lastPlacedIndex = oldIndex;
116
114
  }
117
115
  } else {
118
116
  result.insertions[i] = backgroundChild;
119
117
  result.insertionCount += 1;
120
- result.hasChanges = true;
121
118
  }
122
119
  }
123
120
 
@@ -126,7 +123,6 @@ function hydrateMatchingChildrenAndDiffSlot(
126
123
  const candidateCursor = serializedCursorByNodeKey[key] ?? 0;
127
124
  for (let i = candidateCursor; i < candidates.length; i += 1) {
128
125
  result.removals.push(candidates[i]![1]);
129
- result.hasChanges = true;
130
126
  }
131
127
  }
132
128
 
@@ -160,13 +156,19 @@ function hydrateCompiledInstance(
160
156
  if (!bindHydrationHandleId(instance, handleId, serialized.templateKey)) {
161
157
  return false;
162
158
  }
163
- instance.prepareAttributeSlotsForHydration();
164
- hydrateAttributeSlots(instance.type, handleId, serialized.attributeSlots ?? [], instance.attributeSlots);
159
+ if (serialized.attributeSlots?.length || instance.attributeSlots.length) {
160
+ instance.prepareAttributeSlotsForHydration();
161
+ hydrateAttributeSlots(instance.type, handleId, serialized.attributeSlots ?? [], instance.attributeSlots);
162
+ }
165
163
 
166
164
  if (serialized.templateKey === BUILTIN_RAW_TEXT_TEMPLATE_KEY) {
167
165
  return true;
168
166
  }
169
167
 
168
+ if (!serialized.childSlots?.length && !instance.firstChild) {
169
+ return true;
170
+ }
171
+
170
172
  const serializedChildSlots = serialized.childSlots ?? [];
171
173
  const backgroundChildSlots = instance.childSlots;
172
174
  // Snapshot hydrates dynamic children through slot-filtered lists. Keeping ET
@@ -193,6 +195,19 @@ function hydrateCompiledInstance(
193
195
  return true;
194
196
  }
195
197
 
198
+ const backgroundHydrateKeys = new Map<string, string>();
199
+
200
+ function getBackgroundNodeHydrateKey(type: string): string {
201
+ const cached = backgroundHydrateKeys.get(type);
202
+ if (cached !== undefined) {
203
+ return cached;
204
+ }
205
+ const parsed = parseElementTemplateType(type);
206
+ const key = elementTemplateIdentityKey(parsed.templateKey, parsed.bundleUrl);
207
+ backgroundHydrateKeys.set(type, key);
208
+ return key;
209
+ }
210
+
196
211
  function getSerializedNodeHydrateKey(serialized: SerializedEtNode): string {
197
212
  if (!isSerializedCompiledNode(serialized)) {
198
213
  return serialized.tag;
@@ -298,15 +313,35 @@ function hydrateChildListIntoContext(
298
313
  return true;
299
314
  }
300
315
 
316
+ // Preserve the full matcher’s FIFO pairing while avoiding its temporary
317
+ // structures when every child already occupies the matching slot position.
318
+ const length = serializedChildren.length;
319
+ if (length === backgroundChildren.length) {
320
+ let samePairwise = true;
321
+ for (let i = 0; i < length; i += 1) {
322
+ if (
323
+ getSerializedNodeHydrateKey(serializedChildren[i]!)
324
+ !== getBackgroundNodeHydrateKey(backgroundChildren[i]!.type)
325
+ ) {
326
+ samePairwise = false;
327
+ break;
328
+ }
329
+ }
330
+ if (samePairwise) {
331
+ for (let i = 0; i < length; i += 1) {
332
+ if (!hydrateInstance(serializedChildren[i]!, backgroundChildren[i]!)) {
333
+ return false;
334
+ }
335
+ }
336
+ return true;
337
+ }
338
+ }
339
+
301
340
  const listDiff = hydrateMatchingChildrenAndDiffSlot(serializedChildren, backgroundChildren);
302
341
  if (listDiff === null) {
303
342
  return false;
304
343
  }
305
344
 
306
- if (!listDiff.hasChanges) {
307
- return true;
308
- }
309
-
310
345
  // Hydrate emits patches directly here. Replaying against serialized order
311
346
  // keeps insert targets in the main-thread slot without reshaping background.
312
347
  const removalIndexes = new Set(listDiff.removals);
@@ -572,23 +607,20 @@ function hydrateAttributeSlots(
572
607
  const slotCount = Math.max(beforeSlots.length, afterSlots.length);
573
608
  const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);
574
609
  for (let slotIndex = 0; slotIndex < slotCount; slotIndex += 1) {
575
- const beforeValue = beforeSlots[slotIndex];
576
- const afterValue = afterSlots[slotIndex];
610
+ // Native serialization and background preparation may represent an absent slot differently.
611
+ const beforeValue = beforeSlots[slotIndex] ?? null;
612
+ const afterValue = afterSlots[slotIndex] ?? null;
577
613
  if (
578
614
  !shouldForceMainThreadHydrateSlot(slotKinds?.get(slotIndex), afterValue)
579
615
  && isDirectOrDeepEqual(beforeValue, afterValue)
580
616
  ) {
581
617
  continue;
582
618
  }
583
- if (afterValue === undefined && beforeValue === null) {
584
- // JSON serialization turns undefined array slots into null on the main-thread payload.
585
- continue;
586
- }
587
619
  globalCommitContext.ops.push(
588
620
  getAttributeSlotUpdateOp(templateType, slotIndex),
589
621
  handleId,
590
622
  slotIndex,
591
- afterValue ?? null,
623
+ afterValue,
592
624
  );
593
625
  }
594
626
  }
@@ -178,9 +178,6 @@ export class BackgroundElementTemplateInstance {
178
178
  }
179
179
 
180
180
  private restoreManagerRegistration(): void {
181
- if (this.instanceId === ELEMENT_TEMPLATE_PAGE_HANDLE_ID) {
182
- return;
183
- }
184
181
  const instances = backgroundElementTemplateInstanceManager.values;
185
182
  const existing = instances.get(this.instanceId);
186
183
  if (existing === this) {
@@ -422,10 +419,9 @@ export class BackgroundElementTemplateInstance {
422
419
  }
423
420
 
424
421
  markMaterializedByHydration(): void {
425
- // Hydration binds this object to a template that already exists on the main
426
- // thread; future updates must treat it as materialized without emitting create.
422
+ // Hydration has already registered the stable handle through updateId.
423
+ // Future updates must not emit create for this existing main-thread template.
427
424
  this.isMaterializedOnMainThread = true;
428
- this.restoreManagerRegistration();
429
425
  }
430
426
 
431
427
  prepareAttributeSlotsForNative(options?: { publishRefEffects?: boolean }): void {
@@ -454,6 +450,9 @@ export class BackgroundElementTemplateInstance {
454
450
  }
455
451
 
456
452
  prepareAttributeSlotsForHydration(): void {
453
+ if (!this.rawAttributeSlots) {
454
+ return;
455
+ }
457
456
  // Hydrate only rebinds the selector marker to the stable handle. The ref was
458
457
  // already made visible to user effects on the pre-hydration commit path.
459
458
  this.prepareAttributeSlotsForNative({
@@ -18,7 +18,7 @@ import {
18
18
  NEXT_STATE,
19
19
  RENDER,
20
20
  } from '../../shared/render-constants.js';
21
- import { getDisplayName, hook } from '../../utils.js';
21
+ import { getDisplayName } from '../../utils.js';
22
22
  import { globalCommitContext } from '../background/commit-context.js';
23
23
 
24
24
  let installed = false;
@@ -78,26 +78,28 @@ export function initProfileHook(): void {
78
78
  };
79
79
  }
80
80
 
81
- hook(
82
- Component.prototype,
83
- 'setState',
84
- function(this: PatchedComponent & { [NEXT_STATE]: unknown }, old, state, callback) {
85
- old?.call(this, state, callback);
86
-
87
- if (this[BITS] & COMPONENT_DIRTY) {
88
- profileMark('ReactLynx::setState', {
89
- flowId: this[sFlowID] ??= profileFlowId(),
90
- args: buildSetStateProfileMarkArgs(
91
- this.state as Record<string, unknown>,
92
- this[NEXT_STATE] as Record<string, unknown>,
93
- ),
94
- });
95
- }
96
- },
97
- );
81
+ // eslint-disable-next-line @typescript-eslint/unbound-method
82
+ const oldSetState = Component.prototype.setState;
83
+ Component.prototype.setState = function(this: PatchedComponent & { [NEXT_STATE]: unknown }, state, callback) {
84
+ oldSetState?.call(this, state, callback);
85
+
86
+ if (this[BITS] & COMPONENT_DIRTY) {
87
+ profileMark('ReactLynx::setState', {
88
+ flowId: this[sFlowID] ??= profileFlowId(),
89
+ args: buildSetStateProfileMarkArgs(
90
+ this.state as Record<string, unknown>,
91
+ this[NEXT_STATE] as Record<string, unknown>,
92
+ ),
93
+ });
94
+ }
95
+ };
98
96
  }
99
97
 
100
- hook(options, DIFF2, (old, vnode, oldVNode) => {
98
+ // These hot callbacks have fixed signatures; avoid collecting and spreading
99
+ // an argument array for every host and component visited.
100
+ // eslint-disable-next-line @typescript-eslint/unbound-method
101
+ const oldDiff2 = options[DIFF2];
102
+ options[DIFF2] = (vnode, oldVNode) => {
101
103
  // We only add profiling trace for Component
102
104
  if (typeof vnode.type === 'function') {
103
105
  const profileOptions: TraceOption = {};
@@ -122,18 +124,22 @@ export function initProfileHook(): void {
122
124
  );
123
125
  }
124
126
  /* v8 ignore next */
125
- old?.(vnode, oldVNode);
126
- });
127
+ oldDiff2?.(vnode, oldVNode);
128
+ };
127
129
 
128
- hook(options, DIFFED, (old, vnode) => {
130
+ // eslint-disable-next-line @typescript-eslint/unbound-method
131
+ const oldDiffed = options[DIFFED];
132
+ options[DIFFED] = vnode => {
129
133
  if (typeof vnode.type === 'function') {
130
134
  profileEnd(); // for options[DIFF]
131
135
  }
132
- old?.(vnode);
133
- });
136
+ oldDiffed?.(vnode);
137
+ };
134
138
 
135
139
  if (__BACKGROUND__) {
136
- hook(options, COMMIT, (old, vnode, commitQueue) => {
140
+ // eslint-disable-next-line @typescript-eslint/unbound-method
141
+ const oldCommit = options[COMMIT];
142
+ options[COMMIT] = (vnode, commitQueue) => {
137
143
  const globalFlowIds = globalCommitContext.flowIds;
138
144
  const commitProfileOptions = globalFlowIds && globalFlowIds.length > 0
139
145
  ? { flowId: globalFlowIds[0], flowIds: [...globalFlowIds] }
@@ -141,15 +147,17 @@ export function initProfileHook(): void {
141
147
 
142
148
  profileStart('ReactLynx::commit', commitProfileOptions);
143
149
  /* v8 ignore next */
144
- old?.(vnode, commitQueue);
150
+ oldCommit?.(vnode, commitQueue);
145
151
  profileEnd();
146
152
  delete globalCommitContext.flowIds;
147
- });
153
+ };
148
154
  }
149
155
  }
150
156
 
151
157
  // Profile the user-provided `render`.
152
- hook(options, RENDER, (old, vnode: VNode) => {
158
+ // eslint-disable-next-line @typescript-eslint/unbound-method
159
+ const oldRender = options[RENDER];
160
+ options[RENDER] = (vnode: VNode) => {
153
161
  // eslint-disable-next-line @typescript-eslint/unbound-method
154
162
  const originalRender = vnode[COMPONENT]!.render;
155
163
  vnode[COMPONENT]!.render = function render(this, props, state, context) {
@@ -161,22 +169,26 @@ export function initProfileHook(): void {
161
169
  vnode[COMPONENT]!.render = originalRender;
162
170
  }
163
171
  };
164
- old?.(vnode);
165
- });
172
+ oldRender?.(vnode);
173
+ };
166
174
 
167
175
  if (__BACKGROUND__) {
168
176
  const sPatchLength = Symbol('PATCH_LENGTH');
169
177
 
170
178
  type PatchedVNode = VNode & { [sPatchLength]?: number };
171
179
 
172
- hook(options, DIFF, (old, vnode: PatchedVNode) => {
180
+ // eslint-disable-next-line @typescript-eslint/unbound-method
181
+ const oldDiff = options[DIFF];
182
+ options[DIFF] = (vnode: PatchedVNode) => {
173
183
  if (typeof vnode.type === 'function') {
174
184
  vnode[sPatchLength] = globalCommitContext.ops.length;
175
185
  }
176
- old?.(vnode);
177
- });
186
+ oldDiff?.(vnode);
187
+ };
178
188
 
179
- hook(options, DIFFED, (old, vnode: PatchedVNode) => {
189
+ // eslint-disable-next-line @typescript-eslint/unbound-method
190
+ const oldPatchDiffed = options[DIFFED];
191
+ options[DIFFED] = (vnode: PatchedVNode) => {
180
192
  if (typeof vnode.type === 'function') {
181
193
  if (vnode[sPatchLength] === globalCommitContext.ops.length) {
182
194
  // "NoPatch" is a conventional name in Lynx
@@ -188,7 +200,7 @@ export function initProfileHook(): void {
188
200
  }
189
201
  delete vnode[sPatchLength];
190
202
  }
191
- old?.(vnode);
192
- });
203
+ oldPatchDiffed?.(vnode);
204
+ };
193
205
  }
194
206
  }
@@ -2,7 +2,7 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
- import './runtime-backend-marker.js';
5
+ import './runtime-marker.js';
6
6
  import {
7
7
  Children,
8
8
  Component,
@@ -5,7 +5,7 @@
5
5
  // import { Suspense, createElement, lazy } from 'preact/compat';
6
6
  // import type { FC } from 'react';
7
7
 
8
- import './runtime-backend-marker.js';
8
+ import './runtime-marker.js';
9
9
  import './native/index.js';
10
10
 
11
11
  // import { factory as factory2 } from '../compat/componentIs.js';
@@ -34,6 +34,15 @@ export type { Options } from 'preact';
34
34
 
35
35
  export { loadDynamicJS, __dynamicImport } from '../core/lynx/dynamic-import.js';
36
36
 
37
+ // Re-exported so lazy bundle shells can reach the host runtime APIs
38
+ // via `target[sExportsReactInternal]`.
39
+ export { registerRuntimeVersion, getRuntimeVersion } from '../core/lynx/runtime-version.js';
40
+ export {
41
+ RUNTIME_BACKEND_ELEMENT_TEMPLATE,
42
+ RUNTIME_BACKEND_SNAPSHOT,
43
+ registerRuntimeBackend,
44
+ } from '../core/lynx/runtime-backend.js';
45
+
37
46
  export { withInitDataInState } from '../core/initData.js';
38
47
 
39
48
  export { wrapWithLynxComponent } from '../core/compat/lynxComponent.js';
@@ -67,3 +76,5 @@ export {
67
76
  adaptSpreadAttrSlot,
68
77
  } from './runtime/template/attr-slot-plan.js';
69
78
  export { __ElementTemplatePage } from './runtime/page/authored-page.js';
79
+
80
+ export { __etHost } from './runtime/render/host.js';
@@ -14,6 +14,7 @@ import { runWithForceRootRender } from '../../core/forceRootRender.js';
14
14
  import { updateGlobalProps as updateGlobalPropsCore } from '../../core/globalProps.js';
15
15
  import { installMainThreadHooks } from '../../core/hooks/mainThreadImpl.js';
16
16
  import { updateCardData } from '../../core/lynx-update-data.js';
17
+ import { setupComponentStack } from '../../shared/component-stack.js';
17
18
  import { lynxQueueMicrotask } from '../../utils.js';
18
19
  import { installElementTemplateCommitHook } from '../background/commit-hook.js';
19
20
  import { setupBackgroundElementTemplateDocument } from '../background/document.js';
@@ -64,6 +65,9 @@ function init(): void {
64
65
  }
65
66
 
66
67
  if (__BACKGROUND__) {
68
+ if (__DEV__) {
69
+ setupComponentStack();
70
+ }
67
71
  options.requestAnimationFrame = lynxQueueMicrotask;
68
72
  console.log('experimental_useElementTemplate:', __USE_ELEMENT_TEMPLATE__);
69
73
  setRoot(new BackgroundPageRootInstance());
@@ -129,6 +129,10 @@ export function registerElementTemplateListItem(
129
129
  });
130
130
  }
131
131
 
132
+ export function clearPendingElementTemplateListItems(): void {
133
+ listItemByUid.clear();
134
+ }
135
+
132
136
  export function createElementTemplateListState(
133
137
  listItemUids: readonly number[],
134
138
  attributes?: RuntimeTypedElementAttributes | null,