@lynx-js/react 0.126.1 → 0.127.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (398) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/docs/directives.md +90 -0
  4. package/docs/global-events.md +50 -0
  5. package/docs/import-attributes.md +43 -0
  6. package/docs/macros.md +285 -0
  7. package/package.json +4 -3
  8. package/refresh/.turbo/turbo-build.log +4 -4
  9. package/refresh/dist/index.js +27 -8
  10. package/refresh/package.json +2 -2
  11. package/runtime/__test__/core/main-thread-object.test.js +149 -0
  12. package/runtime/__test__/element-template/debug/profile-installation.test.tsx +97 -1
  13. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -1
  14. package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +26 -3
  15. package/runtime/__test__/element-template/fixtures/render/child-siblings/index.js.txt +15 -11
  16. package/runtime/__test__/element-template/fixtures/render/component/index.js.txt +8 -7
  17. package/runtime/__test__/element-template/fixtures/render/component-slot-content/index.js.txt +14 -10
  18. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/index.js.txt +4 -3
  19. package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/_shared.ts +2 -9
  20. package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/case.ts +2 -4
  21. package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/case.ts +20 -0
  22. package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/case.ts +3 -16
  23. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/case.ts +18 -0
  24. package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/case.ts +20 -0
  25. package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/case.ts +18 -0
  26. package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/case.ts +15 -0
  27. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/index.js.txt +12 -11
  28. package/runtime/__test__/element-template/fixtures/render/mixed-children/index.js.txt +8 -7
  29. package/runtime/__test__/element-template/fixtures/render/multiple-text/index.js.txt +15 -13
  30. package/runtime/__test__/element-template/fixtures/render/nested-templates/index.js.txt +9 -7
  31. package/runtime/__test__/element-template/fixtures/render/react-example/index.js.txt +17 -20
  32. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/index.js.txt +13 -10
  33. package/runtime/__test__/element-template/fixtures/render/template-dedupe/index.js.txt +14 -11
  34. package/runtime/__test__/element-template/imports/main-thread-object-api.test.ts +10 -0
  35. package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +52 -7
  36. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +3 -0
  37. package/runtime/__test__/element-template/native/reload.test.ts +10 -26
  38. package/runtime/__test__/element-template/runtime/background/component-stack.test.tsx +76 -0
  39. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +87 -43
  40. package/runtime/__test__/element-template/runtime/background/instance.test.ts +14 -0
  41. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +4 -0
  42. package/runtime/__test__/element-template/runtime/render/compact-host-debug.test.ts +57 -0
  43. package/runtime/__test__/element-template/runtime/render/compact-host.test.ts +199 -0
  44. package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +292 -0
  45. package/runtime/__test__/element-template/runtime/render/{render-opcodes-into-element-template.et.test.tsx → render-direct-native.test.tsx} +50 -314
  46. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +378 -0
  47. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +491 -0
  48. package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -28
  49. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +21 -35
  50. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -5
  51. package/runtime/__test__/element-template/test-utils/debug/renderFixtureRunner.ts +4 -4
  52. package/runtime/__test__/element-template/vitest.config.ts +2 -1
  53. package/runtime/__test__/snapshot/ctxNotFound.test.ts +271 -0
  54. package/runtime/__test__/snapshot/debug/main-thread-children-with-same-key.test.ts +28 -0
  55. package/runtime/__test__/snapshot/debug/profile.test.jsx +108 -3
  56. package/runtime/__test__/snapshot/event.test.jsx +7 -7
  57. package/runtime/__test__/snapshot/lazy.test.js +114 -7
  58. package/runtime/__test__/snapshot/lifecycle/reloadGc.test.jsx +66 -0
  59. package/runtime/__test__/snapshot/lynx/portals.test.jsx +75 -37
  60. package/runtime/__test__/snapshot/lynx/runtime-version.test.ts +140 -0
  61. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +59 -47
  62. package/runtime/__test__/snapshot/spread.test.jsx +32 -25
  63. package/runtime/__test__/snapshot/ssr.legacy-slot.test.jsx +168 -0
  64. package/runtime/__test__/snapshot/ssr.list.test.jsx +211 -0
  65. package/runtime/__test__/snapshot/worklet/main-thread-object.test.jsx +306 -0
  66. package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +1 -0
  67. package/runtime/__test__/worklet-runtime/hydrate.test.js +92 -0
  68. package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +182 -0
  69. package/runtime/__test__/worklet-runtime/object-methods.test.js +60 -0
  70. package/runtime/__test__/worklet-runtime/runOnBackground.test.js +8 -6
  71. package/runtime/__test__/worklet-runtime/workletRef.test.js +362 -2
  72. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +249 -3
  73. package/runtime/lazy/compat.js +2 -0
  74. package/runtime/lazy/element-template-import.js +0 -4
  75. package/runtime/lazy/element-template-internal.js +19 -8
  76. package/runtime/lazy/element-template-jsx-dev-runtime.js +1 -8
  77. package/runtime/lazy/element-template-jsx-runtime.js +1 -3
  78. package/runtime/lazy/element-template.js +3 -3
  79. package/runtime/lazy/import.js +0 -4
  80. package/runtime/lazy/internal.js +17 -1
  81. package/runtime/lazy/react.js +2 -0
  82. package/runtime/lazy/target.js +0 -21
  83. package/runtime/lib/core/background-function/run-on-background.d.ts +16 -0
  84. package/runtime/lib/core/background-function/run-on-background.js +16 -0
  85. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  86. package/runtime/lib/core/capture-main-thread-object.js +16 -0
  87. package/runtime/lib/core/capture-main-thread-object.js.map +1 -0
  88. package/runtime/lib/core/globalProps.d.ts +2 -0
  89. package/runtime/lib/core/globalProps.js.map +1 -1
  90. package/runtime/lib/core/hooks/react.d.ts +6 -0
  91. package/runtime/lib/core/hooks/react.js +6 -0
  92. package/runtime/lib/core/hooks/react.js.map +1 -1
  93. package/runtime/lib/core/hooks/useLynxGlobalEventListener.d.ts +2 -0
  94. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +2 -0
  95. package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
  96. package/runtime/lib/core/initData.d.ts +2 -0
  97. package/runtime/lib/core/initData.js +2 -0
  98. package/runtime/lib/core/initData.js.map +1 -1
  99. package/runtime/lib/core/lynx/runtime-version.d.ts +16 -0
  100. package/runtime/lib/core/lynx/runtime-version.js +51 -0
  101. package/runtime/lib/core/lynx/runtime-version.js.map +1 -0
  102. package/runtime/lib/core/main-thread-object-handle-registry.d.ts +3 -0
  103. package/runtime/lib/core/main-thread-object-handle-registry.js +17 -0
  104. package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -0
  105. package/runtime/lib/core/main-thread-object.d.ts +77 -0
  106. package/runtime/lib/core/main-thread-object.js +261 -0
  107. package/runtime/lib/core/main-thread-object.js.map +1 -0
  108. package/runtime/lib/core/main-thread-ref-id.js +14 -0
  109. package/runtime/lib/core/main-thread-ref-id.js.map +1 -0
  110. package/runtime/lib/core/main-thread-ref-init-value.d.ts +1 -1
  111. package/runtime/lib/core/main-thread-ref-init-value.js +4 -2
  112. package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
  113. package/runtime/lib/core/main-thread-ref.d.ts +4 -0
  114. package/runtime/lib/core/main-thread-ref.js +5 -8
  115. package/runtime/lib/core/main-thread-ref.js.map +1 -1
  116. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  117. package/runtime/lib/element-template/background/document.d.ts +1 -1
  118. package/runtime/lib/element-template/background/document.js +1 -1
  119. package/runtime/lib/element-template/background/document.js.map +1 -1
  120. package/runtime/lib/element-template/background/hydrate.js +51 -19
  121. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  122. package/runtime/lib/element-template/background/instance.js +5 -6
  123. package/runtime/lib/element-template/background/instance.js.map +1 -1
  124. package/runtime/lib/element-template/debug/profile.js +38 -22
  125. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  126. package/runtime/lib/element-template/index.d.ts +3 -1
  127. package/runtime/lib/element-template/index.js +2 -1
  128. package/runtime/lib/element-template/index.js.map +1 -1
  129. package/runtime/lib/element-template/internal.d.ts +5 -1
  130. package/runtime/lib/element-template/internal.js +7 -1
  131. package/runtime/lib/element-template/internal.js.map +1 -1
  132. package/runtime/lib/element-template/native/index.js +4 -0
  133. package/runtime/lib/element-template/native/index.js.map +1 -1
  134. package/runtime/lib/element-template/protocol/types.d.ts +1 -1
  135. package/runtime/lib/element-template/runtime/list/list.d.ts +1 -0
  136. package/runtime/lib/element-template/runtime/list/list.js +3 -0
  137. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  138. package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +7 -0
  139. package/runtime/lib/element-template/runtime/render/create-rendered-host.js +65 -0
  140. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -0
  141. package/runtime/lib/element-template/runtime/render/host.d.ts +18 -0
  142. package/runtime/lib/element-template/runtime/render/host.js +25 -0
  143. package/runtime/lib/element-template/runtime/render/host.js.map +1 -0
  144. package/runtime/lib/element-template/runtime/render/render-components.d.ts +6 -0
  145. package/runtime/lib/element-template/runtime/render/render-components.js +190 -0
  146. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -0
  147. package/runtime/lib/element-template/runtime/render/{render-opcodes.d.ts → render-direct.d.ts} +3 -1
  148. package/runtime/lib/element-template/runtime/render/render-direct.js +194 -0
  149. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -0
  150. package/runtime/lib/element-template/runtime/render/render-main-thread.js +10 -9
  151. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  152. package/runtime/lib/element-template/runtime/template/handle.d.ts +2 -1
  153. package/runtime/lib/element-template/runtime/template/handle.js +12 -4
  154. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  155. package/runtime/lib/element-template/runtime-marker.d.ts +1 -0
  156. package/runtime/lib/element-template/runtime-marker.js +13 -0
  157. package/runtime/lib/element-template/runtime-marker.js.map +1 -0
  158. package/runtime/lib/index.d.ts +1 -1
  159. package/runtime/lib/index.js +1 -1
  160. package/runtime/lib/index.js.map +1 -1
  161. package/runtime/lib/internal.d.ts +4 -1
  162. package/runtime/lib/internal.js +6 -1
  163. package/runtime/lib/internal.js.map +1 -1
  164. package/runtime/lib/lynx-api.d.ts +49 -6
  165. package/runtime/lib/lynx-api.js +34 -4
  166. package/runtime/lib/lynx-api.js.map +1 -1
  167. package/runtime/lib/lynx.js +4 -1
  168. package/runtime/lib/lynx.js.map +1 -1
  169. package/runtime/lib/runtime-marker.d.ts +1 -0
  170. package/runtime/lib/runtime-marker.js +13 -0
  171. package/runtime/lib/runtime-marker.js.map +1 -0
  172. package/runtime/lib/shared/component-stack.js +5 -1
  173. package/runtime/lib/shared/component-stack.js.map +1 -1
  174. package/runtime/lib/snapshot/debug/profileHooks.js +38 -22
  175. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  176. package/runtime/lib/snapshot/lifecycle/patch/error.d.ts +11 -1
  177. package/runtime/lib/snapshot/lifecycle/patch/error.js +24 -16
  178. package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
  179. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.d.ts +1 -1
  180. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +29 -7
  181. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  182. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +2 -2
  183. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  184. package/runtime/lib/snapshot/lifecycle/reload.js +3 -0
  185. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  186. package/runtime/lib/snapshot/lynx/calledByNative.js +3 -0
  187. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  188. package/runtime/lib/snapshot/lynx/children.d.ts +2 -0
  189. package/runtime/lib/snapshot/lynx/children.js.map +1 -1
  190. package/runtime/lib/snapshot/lynx/element.d.ts +10 -0
  191. package/runtime/lib/snapshot/lynx/element.js +6 -0
  192. package/runtime/lib/snapshot/lynx/element.js.map +1 -1
  193. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +2 -1
  194. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  195. package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +2 -0
  196. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +2 -0
  197. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  198. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
  199. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  200. package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -3
  201. package/runtime/lib/worklet-runtime/bindings/bindings.js +9 -1
  202. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  203. package/runtime/lib/worklet-runtime/bindings/types.d.ts +3 -6
  204. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
  205. package/runtime/lib/worklet-runtime/hydrate.js +27 -8
  206. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  207. package/runtime/lib/worklet-runtime/mainThreadObject.d.ts +8 -0
  208. package/runtime/lib/worklet-runtime/mainThreadObject.js +67 -0
  209. package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -0
  210. package/runtime/lib/worklet-runtime/workletRef.d.ts +11 -7
  211. package/runtime/lib/worklet-runtime/workletRef.js +72 -9
  212. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
  213. package/runtime/lib/worklet-runtime/workletRuntime.js +69 -19
  214. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  215. package/runtime/package.json +2 -3
  216. package/runtime/src/core/background-function/run-on-background.ts +16 -0
  217. package/runtime/src/core/capture-main-thread-object.ts +17 -0
  218. package/runtime/src/core/globalProps.ts +2 -0
  219. package/runtime/src/core/hooks/react.ts +6 -0
  220. package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +2 -0
  221. package/runtime/src/core/initData.ts +2 -0
  222. package/runtime/src/core/lynx/runtime-version.ts +62 -0
  223. package/runtime/src/core/main-thread-object-handle-registry.ts +25 -0
  224. package/runtime/src/core/main-thread-object.ts +387 -0
  225. package/runtime/src/core/main-thread-ref-id.ts +16 -0
  226. package/runtime/src/core/main-thread-ref-init-value.ts +12 -4
  227. package/runtime/src/core/main-thread-ref.ts +7 -8
  228. package/runtime/src/element-template/background/commit-hook.ts +1 -1
  229. package/runtime/src/element-template/background/document.ts +3 -3
  230. package/runtime/src/element-template/background/hydrate.ts +61 -29
  231. package/runtime/src/element-template/background/instance.ts +5 -6
  232. package/runtime/src/element-template/debug/profile.ts +48 -36
  233. package/runtime/src/element-template/index.ts +7 -1
  234. package/runtime/src/element-template/internal.ts +14 -1
  235. package/runtime/src/element-template/native/index.ts +4 -0
  236. package/runtime/src/element-template/protocol/types.ts +1 -1
  237. package/runtime/src/element-template/runtime/list/list.ts +4 -0
  238. package/runtime/src/element-template/runtime/render/create-rendered-host.ts +126 -0
  239. package/runtime/src/element-template/runtime/render/host.ts +51 -0
  240. package/runtime/src/element-template/runtime/render/render-components.ts +255 -0
  241. package/runtime/src/element-template/runtime/render/render-direct.ts +275 -0
  242. package/runtime/src/element-template/runtime/render/render-main-thread.ts +10 -9
  243. package/runtime/src/element-template/runtime/template/handle.ts +17 -7
  244. package/runtime/src/element-template/runtime-marker.ts +17 -0
  245. package/runtime/src/index.ts +1 -1
  246. package/runtime/src/internal.ts +11 -1
  247. package/runtime/src/lynx-api.ts +53 -6
  248. package/runtime/src/lynx.ts +5 -1
  249. package/runtime/src/runtime-marker.ts +17 -0
  250. package/runtime/src/shared/component-stack.ts +5 -1
  251. package/runtime/src/snapshot/debug/profileHooks.ts +52 -40
  252. package/runtime/src/snapshot/lifecycle/patch/error.ts +36 -19
  253. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +29 -7
  254. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +2 -2
  255. package/runtime/src/snapshot/lifecycle/reload.ts +4 -0
  256. package/runtime/src/snapshot/lynx/calledByNative.ts +4 -0
  257. package/runtime/src/snapshot/lynx/children.ts +2 -0
  258. package/runtime/src/snapshot/lynx/element.ts +10 -0
  259. package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +2 -1
  260. package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +2 -0
  261. package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +1 -1
  262. package/runtime/src/worklet-runtime/bindings/bindings.ts +17 -2
  263. package/runtime/src/worklet-runtime/bindings/types.ts +7 -11
  264. package/runtime/src/worklet-runtime/hydrate.ts +44 -11
  265. package/runtime/src/worklet-runtime/mainThreadObject.ts +117 -0
  266. package/runtime/src/worklet-runtime/workletRef.ts +120 -19
  267. package/runtime/src/worklet-runtime/workletRuntime.ts +84 -21
  268. package/runtime/types/types.d.ts +2 -0
  269. package/runtime/worklet-runtime/dev.js +155 -30
  270. package/runtime/worklet-runtime/main.js +1 -1
  271. package/testing-library/.turbo/turbo-build.log +12 -12
  272. package/testing-library/dist/env/index.js +2 -2
  273. package/testing-library/dist/index.d.ts +167 -4
  274. package/testing-library/dist/plugins/index.js +1 -1
  275. package/testing-library/dist/pure.js +45 -44
  276. package/testing-library/etc/react-lynx-testing-library.api.md +1 -1
  277. package/testing-library/package.json +4 -3
  278. package/testing-library/src/__tests__/lynx.test.jsx +1 -1
  279. package/testing-library/src/__tests__/reload/reloadGc.test.jsx +64 -0
  280. package/testing-library/src/__tests__/reload/reloadTemplate.js +39 -0
  281. package/testing-library/src/__tests__/worklet.test.jsx +46 -1
  282. package/testing-library/tsconfig.docs.json +9 -0
  283. package/testing-library/typedoc.json +22 -0
  284. package/testing-library/types/entry.d.ts +2 -2
  285. package/transform/.turbo/turbo-build$colon$wasm.log +151 -67
  286. package/transform/__test__/fixture.spec.js +89 -50
  287. package/transform/__test__/object-methods.spec.js +84 -0
  288. package/transform/__test__/text.spec.js +75 -0
  289. package/transform/crates/swc_plugin_compat/lib.rs +4 -3
  290. package/transform/crates/swc_plugin_compat/napi.rs +4 -3
  291. package/transform/crates/swc_plugin_define_dce/napi.rs +1 -1
  292. package/transform/crates/swc_plugin_dynamic_import/lib.rs +105 -3
  293. package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_suffix_webpack_chunk_name.js +5 -0
  294. package/transform/crates/swc_plugin_element_template/host_lowering.rs +111 -0
  295. package/transform/crates/swc_plugin_element_template/lib.rs +41 -5
  296. package/transform/crates/swc_plugin_element_template/lowering.rs +39 -7
  297. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_generate_attribute_slots_for_dynamic_attributes.snap +1 -1
  298. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_background_conditional_attributes.snap +1 -1
  299. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_boolean_and_number_attributes.snap +1 -1
  300. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_complex_text_structure.snap +1 -1
  301. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dataset_attributes.snap +1 -1
  302. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_deeply_nested_user_components.snap +1 -1
  303. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dynamic_class_attributes.snap +1 -1
  304. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_events_lepus.snap +1 -1
  305. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_id_attributes.snap +1 -1
  306. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_inline_styles.snap +1 -1
  307. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_interpolated_text_with_siblings_lepus.snap +1 -1
  308. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_mixed_content.snap +1 -1
  309. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_nested_structure_and_dynamic_content.snap +1 -1
  310. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_refs_lepus.snap +1 -1
  311. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_sibling_user_components.snap +1 -1
  312. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_spread_attributes.snap +1 -1
  313. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_user_component.snap +1 -1
  314. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_isolate_arrays_with_child_slot_placeholder.snap +1 -1
  315. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_keep_code_and_template_attribute_slots_in_sync_for_spread.snap +1 -1
  316. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_element_template_simple_lepus.snap +1 -1
  317. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_template_with_static_attributes.snap +1 -1
  318. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_template_structure_complex.snap +1 -1
  319. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_text_attribute_and_child_text_slots.snap +1 -1
  320. package/transform/crates/swc_plugin_element_template/tests/element_template.rs +70 -66
  321. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +94 -8
  322. package/transform/crates/swc_plugin_shake/lib.rs +1 -1
  323. package/transform/crates/swc_plugin_shake/napi.rs +1 -1
  324. package/transform/crates/swc_plugin_text/lib.rs +57 -16
  325. package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_keep_children_for_dynamic_or_multiple_text.js +13 -0
  326. package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_transform_string_expressions_to_text_attr.js +13 -0
  327. package/transform/crates/swc_plugin_worklet/decl_collect.rs +10 -0
  328. package/transform/crates/swc_plugin_worklet/extract_ident.rs +14 -0
  329. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +202 -3
  330. package/transform/crates/swc_plugin_worklet/lib.rs +468 -3
  331. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +8 -1
  332. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +10 -5
  333. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_js.js +27 -0
  334. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +45 -0
  335. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +16 -14
  336. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +16 -16
  337. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +7 -5
  338. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +7 -7
  339. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +24 -0
  340. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +16 -0
  341. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +42 -0
  342. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +58 -0
  343. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +3 -1
  344. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +3 -3
  345. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_js.js +9 -0
  346. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +16 -0
  347. package/transform/crates/swc_plugins_shared/jsx_helpers.rs +8 -4
  348. package/transform/dist/wasm.cjs +1 -1
  349. package/transform/index.d.ts +7 -6
  350. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
  351. package/transform/src/swc_plugin_extract_str/mod.rs +1 -1
  352. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +63 -270
  353. package/transform/swc-plugin-reactlynx/index.d.ts +2 -2
  354. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  355. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +306 -170
  356. package/transform/swc-plugin-reactlynx-compat/index.d.ts +3 -3
  357. package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
  358. package/transform/vitest.config.ts +5 -1
  359. package/types/react.docs.d.ts +130 -11
  360. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/case.ts +0 -39
  361. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/case.ts +0 -29
  362. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/case.ts +0 -42
  363. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/case.ts +0 -31
  364. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/passes-bundle-url-to-native-create/case.ts +0 -20
  365. package/runtime/__test__/element-template/runtime/render/render-to-opcodes.et.test.jsx +0 -522
  366. package/runtime/lib/element-template/runtime/render/render-opcodes.js +0 -216
  367. package/runtime/lib/element-template/runtime/render/render-opcodes.js.map +0 -1
  368. package/runtime/lib/element-template/runtime/render/render-to-opcodes.d.ts +0 -16
  369. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js +0 -324
  370. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js.map +0 -1
  371. package/runtime/lib/element-template/runtime-backend-marker.js +0 -6
  372. package/runtime/lib/element-template/runtime-backend-marker.js.map +0 -1
  373. package/runtime/lib/runtime-backend-marker.js +0 -6
  374. package/runtime/lib/runtime-backend-marker.js.map +0 -1
  375. package/runtime/src/element-template/runtime/render/render-opcodes.ts +0 -313
  376. package/runtime/src/element-template/runtime/render/render-to-opcodes.ts +0 -411
  377. package/runtime/src/element-template/runtime-backend-marker.ts +0 -7
  378. package/runtime/src/runtime-backend-marker.ts +0 -7
  379. package/testing-library/node_modules/.bin/rsbuild +0 -55
  380. package/testing-library/node_modules/.bin/rspeedy +0 -55
  381. package/testing-library/node_modules/.bin/rstest +0 -55
  382. package/transform/node_modules/.bin/esbuild +0 -46
  383. package/transform/node_modules/.bin/napi +0 -55
  384. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/native-log.txt +0 -0
  385. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/output.txt +0 -0
  386. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/native-log.txt +0 -0
  387. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/output.txt +0 -0
  388. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/native-log.txt +0 -0
  389. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/output.txt +0 -0
  390. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +0 -0
  391. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/output.txt +0 -0
  392. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/native-log.txt +0 -0
  393. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/output.txt +0 -0
  394. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/native-log.txt +0 -0
  395. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/output.txt +0 -0
  396. /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/passes-bundle-url-to-native-create/native-log.txt +0 -0
  397. /package/runtime/lib/{element-template/runtime-backend-marker.d.ts → core/capture-main-thread-object.d.ts} +0 -0
  398. /package/runtime/lib/{runtime-backend-marker.d.ts → core/main-thread-ref-id.d.ts} +0 -0
package/docs/macros.md ADDED
@@ -0,0 +1,285 @@
1
+ ---
2
+ title: Built-in macros
3
+ group: Documents
4
+ ---
5
+
6
+ # Built-in Macros
7
+
8
+ The `@lynx-js/react` package processes built-in macro definitions such as `__BACKGROUND__` and `__MAIN_THREAD__`. During compilation, code blocks with `false` conditions are automatically removed.
9
+
10
+ ## `__BACKGROUND__`
11
+
12
+ - Type: `boolean`
13
+ - Purpose: Controls code execution in background thread environment. Used to determine which code segments should be preserved in background thread code after compilation.
14
+
15
+ ### Usage Examples
16
+
17
+ #### In Function Components
18
+
19
+ Here's an example using the `App` component:
20
+
21
+ ```tsx
22
+ import { noop } from 'lodash-es';
23
+ import { useEffect } from '@lynx-js/react';
24
+
25
+ function App() {
26
+ const showToast = __BACKGROUND__
27
+ ? () => {
28
+ bridge.call('showToast', {
29
+ message: t('toast'),
30
+ icon: 'success',
31
+ });
32
+ }
33
+ : noop;
34
+
35
+ useEffect(showToast, []);
36
+ return <view />;
37
+ }
38
+ ```
39
+
40
+ After compilation, this code is transformed into:
41
+
42
+ - Background thread code (`background.js` in the compilation intermediate directory):
43
+
44
+ ```tsx
45
+ function App() {
46
+ const showToast = () => {
47
+ bridge.call('showToast', {
48
+ message: t('toast'),
49
+ icon: 'success',
50
+ });
51
+ };
52
+ useEffect(showToast, []);
53
+ return createSnapshotInstance(__snapshot_5ab440, null, []);
54
+ }
55
+ ```
56
+
57
+ - Main thread code (`main-thread.js` in the compilation intermediate directory):
58
+
59
+ ```tsx
60
+ function App() {
61
+ const showToast = noop_default;
62
+
63
+ useEffect();
64
+ return createSnapshotInstance(__snapshot_5ab440, null, []);
65
+ }
66
+ ```
67
+
68
+ #### In Class Components
69
+
70
+ Here's an example using the `Conversations` component:
71
+
72
+ ```tsx
73
+ import { AppLoggerFactory } from '../utils/appLoggerFactory';
74
+
75
+ class Conversations extends Component<Props, State> {
76
+ appLogger: AppLogger;
77
+
78
+ constructor(props: Props) {
79
+ super(props);
80
+ this.state = {
81
+ showConversationItemAction: false,
82
+ loading: true,
83
+ };
84
+ if (__BACKGROUND__) {
85
+ this.appLogger = AppLoggerFactory();
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ After compilation, this code is transformed into:
92
+
93
+ - Background thread code (`background.js` in the compilation intermediate directory):
94
+
95
+ ```tsx
96
+ class Conversations extends Component<Props, State> {
97
+ appLogger: AppLogger;
98
+
99
+ constructor(props: Props) {
100
+ super(props);
101
+ this.state = {
102
+ showConversationItemAction: false,
103
+ loading: true,
104
+ };
105
+ this.appLogger = AppLoggerFactory();
106
+ }
107
+ }
108
+ ```
109
+
110
+ - Main thread code (`main-thread.js` in the compilation intermediate directory):
111
+
112
+ ```tsx
113
+ class Conversations extends Component<Props, State> {
114
+ appLogger: AppLogger;
115
+
116
+ constructor(props: Props) {
117
+ super(props);
118
+ this.state = {
119
+ showConversationItemAction: false,
120
+ loading: true,
121
+ };
122
+ }
123
+ }
124
+ ```
125
+
126
+ ## `__MAIN_THREAD__`
127
+
128
+ - Type: `boolean`
129
+ - Purpose: Controls code execution in main thread environment. Used to determine which code segments should be preserved in main thread code during compilation.
130
+
131
+ ### Usage Examples
132
+
133
+ #### In Function Components
134
+
135
+ Here's an example using the `App` component:
136
+
137
+ ```tsx
138
+ import { noop } from 'lodash-es';
139
+ import { useEffect } from '@lynx-js/react';
140
+
141
+ function App() {
142
+ const showToast = !__MAIN_THREAD__
143
+ ? () => {
144
+ bridge.call('showToast', {
145
+ message: t('toast'),
146
+ icon: 'success',
147
+ });
148
+ }
149
+ : noop;
150
+
151
+ useEffect(showToast, []);
152
+ return <view />;
153
+ }
154
+ ```
155
+
156
+ After compilation, this code is transformed into:
157
+
158
+ - Background thread code (`background.js` in the compilation intermediate directory):
159
+
160
+ ```tsx
161
+ function App() {
162
+ const showToast = () => {
163
+ bridge.call('showToast', {
164
+ message: t('toast'),
165
+ icon: 'success',
166
+ });
167
+ };
168
+ useEffect(showToast, []);
169
+ return createSnapshotInstance(__snapshot_5ab440, null, []);
170
+ }
171
+ ```
172
+
173
+ - Main thread code (`main-thread.js` in the compilation intermediate directory):
174
+
175
+ ```tsx
176
+ function App() {
177
+ const showToast = noop_default;
178
+
179
+ useEffect();
180
+ return createSnapshotInstance(__snapshot_5ab440, null, []);
181
+ }
182
+ ```
183
+
184
+ #### In Class Components
185
+
186
+ Here's an example using the `Conversations` component:
187
+
188
+ ```tsx
189
+ import { AppLoggerFactory } from '../utils/appLoggerFactory';
190
+
191
+ class Conversations extends Component<Props, State> {
192
+ appLogger: AppLogger;
193
+
194
+ constructor(props: Props) {
195
+ super(props);
196
+ this.state = {
197
+ showConversationItemAction: false,
198
+ loading: true,
199
+ };
200
+ if (!__MAIN_THREAD__) {
201
+ this.appLogger = AppLoggerFactory();
202
+ }
203
+ }
204
+ }
205
+ ```
206
+
207
+ After compilation, this code is transformed into:
208
+
209
+ - Background thread code (`background.js` in the compilation intermediate directory):
210
+
211
+ ```tsx
212
+ class Conversations extends Component<Props, State> {
213
+ appLogger: AppLogger;
214
+
215
+ constructor(props: Props) {
216
+ super(props);
217
+ this.state = {
218
+ showConversationItemAction: false,
219
+ loading: true,
220
+ };
221
+ this.appLogger = AppLoggerFactory();
222
+ }
223
+ }
224
+ ```
225
+
226
+ - Main thread code (`main-thread.js` in the compilation intermediate directory):
227
+
228
+ ```tsx
229
+ class Conversations extends Component<Props, State> {
230
+ appLogger: AppLogger;
231
+
232
+ constructor(props: Props) {
233
+ super(props);
234
+ this.state = {
235
+ showConversationItemAction: false,
236
+ loading: true,
237
+ };
238
+ }
239
+ }
240
+ ```
241
+
242
+ ## `__JS__`
243
+
244
+ - Type: `boolean`
245
+ - Purpose: Alias of [`__BACKGROUND__`](#__background__).
246
+
247
+ :::warning Deprecated
248
+ Use `__BACKGROUND__` instead.
249
+ :::
250
+
251
+ ## `__LEPUS__`
252
+
253
+ - Type: `boolean`
254
+ - Purpose: Alias of [`__MAIN_THREAD__`](#__main_thread__).
255
+
256
+ :::warning Deprecated
257
+ Use `__MAIN_THREAD__` instead.
258
+ :::
259
+
260
+ ## `__DEV__`
261
+
262
+ - Type: `boolean`
263
+ - Purpose: `true` in development builds, `false` in production. Use it to guard development-only code — prop validation, invariant checks, friendlier error messages — so none of it reaches production.
264
+
265
+ ```tsx
266
+ if (__DEV__) {
267
+ // Stripped from production builds.
268
+ console.log('debug only');
269
+ }
270
+ ```
271
+
272
+ ## `__PROFILE__`
273
+
274
+ - Type: `boolean`
275
+ - Purpose: `true` when the build carries profiling instrumentation. It is on by default in development and off in production. See [Performance Profiling](https://lynxjs.org/react/performance/profiling.mdx) for the traces it produces, and [Runtime Profiling](https://lynxjs.org/rspeedy/runtime-profiling.md) for how to turn it on for a production build.
276
+
277
+ ## `__REACT_DEVTOOL__`
278
+
279
+ - Type: `boolean | undefined`
280
+ - Purpose: `true` when the runtime hooks that [Preact DevTools](https://lynxjs.org/guide/devtool/panels/preact-devtools-panel.mdx) depends on are compiled in. Enabled by default in development; in production it can be enabled with the `REACT_DEVTOOL=true` environment variable.
281
+
282
+ ## `__LAZY_BUNDLE_FETCHER__`
283
+
284
+ - Type: `'FetchBundle' | 'QueryComponent'`
285
+ - Purpose: Which lazy bundle fetcher the build is wired up to. `'FetchBundle'` enables the `lynx.fetchBundle`-based path (and `import(..., { with: { mode } })` mode hints); `'QueryComponent'` is the legacy `lynx.QueryComponent` path. How the value is selected, the `REACT_LAZY_BUNDLE_FETCHER` override and the version scope are documented in [Lazy bundle loaders](https://lynxjs.org/react/code-splitting.md#lazy-bundle-loaders).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/react",
3
- "version": "0.126.1",
3
+ "version": "0.127.0",
4
4
  "description": "ReactLynx is a framework for developing Lynx applications with familiar React.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -218,6 +218,7 @@
218
218
  "types",
219
219
  "docs",
220
220
  "testing-library",
221
+ "!**/node_modules/**",
221
222
  "CHANGELOG.md",
222
223
  "internal.js",
223
224
  "README.md",
@@ -228,7 +229,7 @@
228
229
  },
229
230
  "devDependencies": {
230
231
  "@lynx-js/types": "4.1.0",
231
- "@microsoft/api-extractor": "7.58.12",
232
+ "@microsoft/api-extractor": "7.59.2",
232
233
  "@types/react": "^19.2.18"
233
234
  },
234
235
  "peerDependencies": {
@@ -242,6 +243,6 @@
242
243
  },
243
244
  "scripts": {
244
245
  "api-extractor": "api-extractor run --verbose",
245
- "build": "rslib build"
246
+ "build": "rslib"
246
247
  }
247
248
  }
@@ -1,9 +1,9 @@
1
- $ rslib build
2
- Rslib v1.0.0
1
+ $ rslib
2
+ Rslib v1.0.2
3
3
 
4
4
  info build started...
5
- ready built in 0.12s
5
+ ready built in 0.15s
6
6
 
7
7
  File (esm) Size
8
- dist/index.js 10.2 kB
8
+ dist/index.js 10.9 kB
9
9
 
@@ -29,6 +29,23 @@ options.debounceRendering = (process)=>{
29
29
  const vnodesForComponent = new WeakMap();
30
30
  const mappedVNodes = new WeakMap();
31
31
  const lastSeen = new Map();
32
+ const lastSeenByInstance = new WeakMap();
33
+ const setLastSeen = (vnode)=>{
34
+ const component = vnode.__c;
35
+ if (component) {
36
+ if (lastSeenByInstance.has(component)) lastSeen.delete(lastSeenByInstance.get(component));
37
+ lastSeenByInstance.set(component, vnode.__v);
38
+ }
39
+ lastSeen.set(vnode.__v, vnode);
40
+ };
41
+ const clearLastSeen = (vnode)=>{
42
+ lastSeen.delete(vnode.__v);
43
+ const component = vnode.__c;
44
+ if (component && lastSeenByInstance.has(component)) {
45
+ lastSeen.delete(lastSeenByInstance.get(component));
46
+ lastSeenByInstance.delete(component);
47
+ }
48
+ };
32
49
  const getMappedVnode = (type)=>{
33
50
  if (mappedVNodes.has(type)) return getMappedVnode(mappedVNodes.get(type));
34
51
  return type;
@@ -65,7 +82,7 @@ const oldDiffed = options.diffed;
65
82
  options.diffed = (vnode)=>{
66
83
  if (vnode && 'function' == typeof vnode.type) {
67
84
  const vnodes = vnodesForComponent.get(vnode.type);
68
- lastSeen.set(vnode.__v, vnode);
85
+ setLastSeen(vnode);
69
86
  if (vnodes) {
70
87
  const matchingDom = vnodes.filter((p)=>p.__c === vnode.__c);
71
88
  if (matchingDom.length > 1) {
@@ -79,11 +96,14 @@ options.diffed = (vnode)=>{
79
96
  const oldUnmount = options.unmount;
80
97
  options.unmount = (vnode)=>{
81
98
  const type = (vnode || {}).type;
82
- if ('function' == typeof type && vnodesForComponent.has(type)) {
83
- const vnodes = vnodesForComponent.get(type);
84
- if (vnodes) {
85
- const index = vnodes.indexOf(vnode);
86
- if (-1 !== index) vnodes.splice(index, 1);
99
+ if ('function' == typeof type) {
100
+ clearLastSeen(vnode);
101
+ if (vnodesForComponent.has(type)) {
102
+ const vnodes = vnodesForComponent.get(type);
103
+ if (vnodes) {
104
+ const index = vnodes.indexOf(vnode);
105
+ if (-1 !== index) vnodes.splice(index, 1);
106
+ }
87
107
  }
88
108
  }
89
109
  if (oldUnmount) oldUnmount(vnode);
@@ -126,8 +146,7 @@ function sign(type, key, forceReset, getCustomHooks, status) {
126
146
  getCustomHooks: getCustomHooks || (()=>[])
127
147
  });
128
148
  return 'needsHooks';
129
- }
130
- if ('needsHooks' === status) {
149
+ } else if ('needsHooks' === status) {
131
150
  if (signature) signature.fullKey = computeKey(signature);
132
151
  }
133
152
  }
@@ -10,11 +10,11 @@
10
10
  "src"
11
11
  ],
12
12
  "scripts": {
13
- "build": "rslib build"
13
+ "build": "rslib"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@lynx-js/react": "workspace:*",
17
- "@prefresh/core": "^1.5.10",
17
+ "@prefresh/core": "^1.5.11",
18
18
  "@prefresh/utils": "^1.2.1",
19
19
  "preact": "catalog:lynxjs"
20
20
  }
@@ -0,0 +1,149 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ import { defineMainThreadObjectType } from '../../src/core/main-thread-object.js';
4
+
5
+ beforeEach(() => {
6
+ vi.stubGlobal('__DEV__', true);
7
+ vi.stubGlobal('__JS__', true);
8
+ vi.stubGlobal('__LEPUS__', false);
9
+ vi.stubGlobal('lynxWorkletImpl', {
10
+ _refImpl: { registerMainThreadObjectType: vi.fn() },
11
+ });
12
+ });
13
+
14
+ afterEach(() => {
15
+ vi.unstubAllGlobals();
16
+ });
17
+
18
+ describe('core/main-thread-object definition', () => {
19
+ it('registers a type during main-thread module evaluation without rendering its hook', () => {
20
+ const create = value => ({ value });
21
+ const register = globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType;
22
+
23
+ vi.stubGlobal('__JS__', false);
24
+ vi.stubGlobal('__LEPUS__', true);
25
+ const type = defineMainThreadObjectType({
26
+ type: '@test/lazy-module-value',
27
+ create,
28
+ });
29
+
30
+ expect(register).toHaveBeenCalledWith(
31
+ '@test/lazy-module-value',
32
+ create,
33
+ );
34
+ expect(type).not.toHaveProperty('create');
35
+ });
36
+
37
+ it.each([true, false])('validates and freezes object type definitions (__JS__=%s)', (isJS) => {
38
+ vi.stubGlobal('__JS__', isJS);
39
+ vi.stubGlobal('__LEPUS__', !isJS);
40
+ expect(() =>
41
+ defineMainThreadObjectType({
42
+ type: '',
43
+ create: value => ({ value }),
44
+ })
45
+ ).toThrow('MainThreadObject type must be a non-empty string.');
46
+ expect(() =>
47
+ defineMainThreadObjectType({
48
+ type: 'main-thread',
49
+ create: value => ({ value }),
50
+ })
51
+ ).toThrow(
52
+ 'MainThreadObject type "main-thread" is reserved for MainThreadRef.',
53
+ );
54
+ expect(() =>
55
+ defineMainThreadObjectType({
56
+ type: '@test/missing-create',
57
+ })
58
+ ).toThrow(
59
+ 'MainThreadObject type "@test/missing-create" must provide a create Main Thread Function.',
60
+ );
61
+ expect(() =>
62
+ defineMainThreadObjectType({
63
+ type: '@test/capturing-create',
64
+ create: {
65
+ _wkltId: 'capturing-create',
66
+ _c: { mutableValue: 1 },
67
+ },
68
+ })
69
+ ).toThrow(
70
+ 'MainThreadObject create function for "@test/capturing-create" must not capture values. Import dependencies from a shared-runtime module instead.',
71
+ );
72
+ expect(() =>
73
+ defineMainThreadObjectType({
74
+ type: '@test/js-function-capture',
75
+ create: {
76
+ _wkltId: 'js-function-capture',
77
+ _jsFn: { callback: { _jsFnId: 1 } },
78
+ },
79
+ })
80
+ ).toThrow(
81
+ 'MainThreadObject create function for "@test/js-function-capture" must not capture values. Import dependencies from a shared-runtime module instead.',
82
+ );
83
+ expect(() =>
84
+ defineMainThreadObjectType({
85
+ type: '@test/this-capture',
86
+ create: {
87
+ _wkltId: 'this-capture',
88
+ helper: { stop() {} },
89
+ },
90
+ })
91
+ ).toThrow(
92
+ 'MainThreadObject create function for "@test/this-capture" must not capture values. Import dependencies from a shared-runtime module instead.',
93
+ );
94
+ const hiddenCapture = { _wkltId: 'hidden-capture' };
95
+ Object.defineProperty(hiddenCapture, 'helper', { value: 1 });
96
+ expect(() =>
97
+ defineMainThreadObjectType({
98
+ type: '@test/hidden-capture',
99
+ create: hiddenCapture,
100
+ })
101
+ ).toThrow(
102
+ 'MainThreadObject create function for "@test/hidden-capture" must not capture values. Import dependencies from a shared-runtime module instead.',
103
+ );
104
+ const symbolCapture = {
105
+ _wkltId: 'symbol-capture',
106
+ [Symbol('helper')]: 1,
107
+ };
108
+ expect(() =>
109
+ defineMainThreadObjectType({
110
+ type: '@test/symbol-capture',
111
+ create: symbolCapture,
112
+ })
113
+ ).toThrow(
114
+ 'MainThreadObject create function for "@test/symbol-capture" must not capture values. Import dependencies from a shared-runtime module instead.',
115
+ );
116
+ const accessorClosure = {
117
+ _wkltId: 'accessor-closure',
118
+ get _c() {
119
+ return {};
120
+ },
121
+ };
122
+ expect(() =>
123
+ defineMainThreadObjectType({
124
+ type: '@test/accessor-closure',
125
+ create: accessorClosure,
126
+ })
127
+ ).toThrow(
128
+ 'MainThreadObject create function for "@test/accessor-closure" must not capture values. Import dependencies from a shared-runtime module instead.',
129
+ );
130
+ const type = defineMainThreadObjectType({
131
+ type: '@test/frozen',
132
+ create: value => ({ value }),
133
+ });
134
+ expect(Object.isFrozen(type)).toBe(true);
135
+
136
+ vi.stubGlobal('__DEV__', false);
137
+ const ownKeys = vi.fn(Reflect.ownKeys);
138
+ const create = new Proxy({
139
+ _wkltId: 'production-create',
140
+ _c: { mutableValue: 1 },
141
+ }, { ownKeys });
142
+ const productionType = defineMainThreadObjectType({
143
+ type: '@test/production',
144
+ create,
145
+ });
146
+ expect(productionType.type).toBe('@test/production');
147
+ expect(ownKeys).not.toHaveBeenCalled();
148
+ });
149
+ });
@@ -1,4 +1,4 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
1
+ import { afterEach, beforeEach, describe, expect, it, onTestFinished, vi } from 'vitest';
2
2
 
3
3
  import { ElementTemplateEnvManager } from '../test-utils/debug/envManager.js';
4
4
 
@@ -15,6 +15,102 @@ describe('initProfileHook installation', () => {
15
15
  vi.resetModules();
16
16
  });
17
17
 
18
+ it.each(['main', 'background'] as const)('preserves profiling callback contracts on %s', async target => {
19
+ envManager.resetEnv(target);
20
+ const { Component, createElement, options } = await import('preact');
21
+ const { COMMIT, COMPONENT, DIFF, DIFF2, DIFFED, RENDER } = await import('../../../src/shared/render-constants.js');
22
+ const previousHooks = {
23
+ [COMMIT]: options[COMMIT],
24
+ [DIFF]: options[DIFF],
25
+ [DIFF2]: options[DIFF2],
26
+ [DIFFED]: options[DIFFED],
27
+ [RENDER]: options[RENDER],
28
+ };
29
+ const previousSetState = Component.prototype.setState;
30
+ onTestFinished(() => {
31
+ Object.assign(options, previousHooks);
32
+ Component.prototype.setState = previousSetState;
33
+ });
34
+ const events: string[] = [];
35
+ const performance = lynx.performance;
36
+ const oldSetState = Component.prototype.setState = vi.fn(function(state, callback) {
37
+ expect(this).toBe(instance);
38
+ expect(state).toBe(nextState);
39
+ expect(callback).toBe(setStateCallback);
40
+ events.push('old setState');
41
+ });
42
+ const oldDiff = options[DIFF] = vi.fn(() => events.push('old before diff'));
43
+ const oldCommit = options[COMMIT] = vi.fn(() => {
44
+ expect(performance.profileStart).toHaveBeenLastCalledWith('ReactLynx::commit', {});
45
+ events.push('old commit');
46
+ });
47
+ const oldDiff2 = options[DIFF2] = vi.fn(() => {
48
+ expect(performance.profileStart).toHaveBeenLastCalledWith('ReactLynx::diff::Example', {});
49
+ events.push('old diff');
50
+ });
51
+ const oldDiffed = options[DIFFED] = vi.fn(() => {
52
+ expect(performance.profileEnd).toHaveBeenCalledTimes(2);
53
+ events.push('old diffed');
54
+ });
55
+ const oldRender = options[RENDER] = vi.fn(() => {
56
+ expect(instance.render).not.toBe(originalRender);
57
+ events.push('old render');
58
+ });
59
+ const { initProfileHook } = await import('../../../src/element-template/debug/profile.js');
60
+ initProfileHook();
61
+
62
+ const failure = new Error('render failed');
63
+ class Example extends Component {
64
+ override render() {
65
+ expect(this).toBe(instance);
66
+ expect(performance.profileStart).toHaveBeenLastCalledWith('ReactLynx::render::Example');
67
+ events.push('render');
68
+ throw failure;
69
+ }
70
+ }
71
+ const vnode = createElement(Example, {});
72
+ const oldVNode = createElement(Example, {});
73
+ const instance = vnode[COMPONENT] = new Example({});
74
+ const originalRender = instance.render;
75
+
76
+ const nextState = { count: 1 };
77
+ const setStateCallback = () => {};
78
+ const commitQueue = [instance];
79
+ instance.setState(nextState, setStateCallback);
80
+ options[DIFF]?.(vnode);
81
+ options[DIFF2]?.(vnode, oldVNode);
82
+ options[RENDER]?.(vnode);
83
+ expect(() => instance.render()).toThrow(failure);
84
+ expect(instance.render).toBe(originalRender);
85
+ options[DIFFED]?.(vnode);
86
+
87
+ if (target === 'background') {
88
+ options[COMMIT]?.(vnode, commitQueue);
89
+ expect(oldCommit.mock.calls).toEqual([[vnode, commitQueue]]);
90
+ expect(oldCommit.mock.contexts).toEqual([undefined]);
91
+ expect(performance.profileEnd).toHaveBeenCalledTimes(3);
92
+ expect(oldDiff.mock.contexts).toEqual([undefined]);
93
+ }
94
+ expect(oldSetState.mock.calls).toEqual([[nextState, setStateCallback]]);
95
+ expect(oldSetState.mock.contexts).toEqual([instance]);
96
+ expect(oldDiff.mock.calls).toEqual([[vnode]]);
97
+ expect(oldDiff2.mock.calls).toEqual([[vnode, oldVNode]]);
98
+ expect(oldRender.mock.calls).toEqual([[vnode]]);
99
+ expect(oldDiffed.mock.calls).toEqual([[vnode]]);
100
+ expect(oldDiff2.mock.contexts).toEqual([undefined]);
101
+ expect(oldRender.mock.contexts).toEqual([undefined]);
102
+ expect(oldDiffed.mock.contexts).toEqual([undefined]);
103
+ expect(events).toEqual([
104
+ 'old setState',
105
+ 'old before diff',
106
+ 'old diff',
107
+ 'old render',
108
+ 'render',
109
+ 'old diffed',
110
+ ...(target === 'background' ? ['old commit'] : []),
111
+ ]);
112
+ });
113
+
18
114
  it('can retry installation after profiling apis become available', async () => {
19
115
  const performance = globalThis.lynx.performance;
20
116
  const originalProfileStart = performance.profileStart;
@@ -2,7 +2,7 @@ Object {
2
2
  "ops": Array [
3
3
  Object {
4
4
  "attributeSlots": Array [
5
- 2,
5
+ "2",
6
6
  ],
7
7
  "bundleUrl": null,
8
8
  "childSlots": Array [],