@lynx-js/react 0.126.0 → 0.126.1

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 (1220) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +202 -0
  3. package/components/.gitignore +3 -0
  4. package/components/.npmignore +5 -0
  5. package/components/tsconfig.json +17 -0
  6. package/components/tsconfig.tsbuildinfo +1 -0
  7. package/package.json +5 -1
  8. package/refresh/.gitignore +1 -0
  9. package/refresh/.npmignore +3 -0
  10. package/refresh/.turbo/turbo-build.log +9 -0
  11. package/refresh/package.json +21 -0
  12. package/refresh/rslib.config.ts +24 -0
  13. package/refresh/tsconfig.json +4 -0
  14. package/refresh/turbo.json +16 -0
  15. package/runtime/.gitignore +4 -0
  16. package/runtime/.npmignore +15 -0
  17. package/runtime/.prettierrc +6 -0
  18. package/runtime/.turbo/turbo-build.log +1 -0
  19. package/runtime/CHANGELOG.md +7 -0
  20. package/runtime/__test__/core/background-function.test.ts +133 -0
  21. package/runtime/__test__/core/commit-context.test.ts +37 -0
  22. package/runtime/__test__/core/forceRootRender.test.ts +65 -0
  23. package/runtime/__test__/core/globalProps.test.ts +141 -0
  24. package/runtime/__test__/core/hooks/mainThread.test.tsx +279 -0
  25. package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +168 -0
  26. package/runtime/__test__/core/lynx-data-processors.test.ts +131 -0
  27. package/runtime/__test__/core/lynx-page-data.test.ts +62 -0
  28. package/runtime/__test__/core/lynx-update-data.test.ts +97 -0
  29. package/runtime/__test__/core/main-thread-function.test.ts +13 -0
  30. package/runtime/__test__/core/main-thread-ref.test.ts +102 -0
  31. package/runtime/__test__/core/ref.test.ts +261 -0
  32. package/runtime/__test__/core/reload-version.test.ts +14 -0
  33. package/runtime/__test__/core/thread-function-call.test.ts +182 -0
  34. package/runtime/__test__/element-template/debug/alog.test.ts +214 -0
  35. package/runtime/__test__/element-template/debug/elementPAPICall.test.ts +157 -0
  36. package/runtime/__test__/element-template/debug/profile-hook.test.tsx +67 -0
  37. package/runtime/__test__/element-template/debug/profile-installation.test.tsx +49 -0
  38. package/runtime/__test__/element-template/fixtures/background/event/conditional-direct-event/index.tsx +8 -0
  39. package/runtime/__test__/element-template/fixtures/background/event/direct-event/index.tsx +7 -0
  40. package/runtime/__test__/element-template/fixtures/background/event/main-thread-direct-event/index.tsx +11 -0
  41. package/runtime/__test__/element-template/fixtures/background/event/main-thread-run-on-background-event/index.tsx +14 -0
  42. package/runtime/__test__/element-template/fixtures/background/event/spread-event/index.tsx +20 -0
  43. package/runtime/__test__/element-template/fixtures/background/global-props/direct-read/index.tsx +7 -0
  44. package/runtime/__test__/element-template/fixtures/background/global-props/event-hook/index.tsx +34 -0
  45. package/runtime/__test__/element-template/fixtures/background/hydrate/_shared.tsx +584 -0
  46. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.adds-background-only/case.tsx +5 -0
  47. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.adds-background-only/output.txt +11 -0
  48. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.aligns-ids-and-patches/case.tsx +5 -0
  49. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.aligns-ids-and-patches/output.txt +12 -0
  50. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.array-diff/case.tsx +5 -0
  51. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.array-diff/output.txt +13 -0
  52. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.batch-multiple-patches/case.tsx +5 -0
  53. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.batch-multiple-patches/output.txt +12 -0
  54. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.nullish-values/case.tsx +5 -0
  55. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.nullish-values/output.txt +10 -0
  56. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.object-value-updates/case.tsx +5 -0
  57. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.object-value-updates/output.txt +13 -0
  58. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.patches-nested-component/case.tsx +5 -0
  59. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.patches-nested-component/output.txt +13 -0
  60. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.removes-missing/case.tsx +5 -0
  61. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.removes-missing/output.txt +10 -0
  62. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.skips-identical/case.tsx +5 -0
  63. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.skips-identical/output.txt +3 -0
  64. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.style-object-updates/case.tsx +5 -0
  65. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.style-object-updates/output.txt +13 -0
  66. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.type-diff/case.tsx +5 -0
  67. package/runtime/__test__/element-template/fixtures/background/hydrate/attrs.type-diff/output.txt +10 -0
  68. package/runtime/__test__/element-template/fixtures/background/hydrate/children.creates-missing-nodes-recursively/case.tsx +5 -0
  69. package/runtime/__test__/element-template/fixtures/background/hydrate/children.creates-missing-nodes-recursively/output.txt +39 -0
  70. package/runtime/__test__/element-template/fixtures/background/hydrate/children.iterates-existing-slots/case.tsx +5 -0
  71. package/runtime/__test__/element-template/fixtures/background/hydrate/children.iterates-existing-slots/output.txt +16 -0
  72. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-attrs-element/case.tsx +5 -0
  73. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-attrs-element/output.txt +3 -0
  74. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-background/case.tsx +5 -0
  75. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-background/output.txt +11 -0
  76. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-main/case.tsx +5 -0
  77. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-main/output.txt +16 -0
  78. package/runtime/__test__/element-template/fixtures/background/hydrate/children.raw-text-instance-empty-text/case.tsx +5 -0
  79. package/runtime/__test__/element-template/fixtures/background/hydrate/children.raw-text-instance-empty-text/output.txt +4 -0
  80. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text/case.tsx +5 -0
  81. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text/output.txt +12 -0
  82. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text-non-text/case.tsx +5 -0
  83. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text-non-text/output.txt +10 -0
  84. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.move-before-child/case.tsx +5 -0
  85. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.move-before-child/output.txt +10 -0
  86. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.raw-text-key-branches/case.tsx +5 -0
  87. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.raw-text-key-branches/output.txt +22 -0
  88. package/runtime/__test__/element-template/fixtures/background/hydrate/full-flow.dispatches-update-event/case.tsx +5 -0
  89. package/runtime/__test__/element-template/fixtures/background/hydrate/full-flow.dispatches-update-event/output.txt +5 -0
  90. package/runtime/__test__/element-template/fixtures/background/hydrate/root-key-mismatch-reconciles/case.tsx +5 -0
  91. package/runtime/__test__/element-template/fixtures/background/hydrate/root-key-mismatch-reconciles/output.txt +24 -0
  92. package/runtime/__test__/element-template/fixtures/background/hydrate/updates-raw-text-instance-id/case.tsx +5 -0
  93. package/runtime/__test__/element-template/fixtures/background/hydrate/updates-raw-text-instance-id/output.txt +5 -0
  94. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.creates-and-inserts-new/index.tsx +14 -0
  95. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.creates-and-inserts-new/output.txt +20 -0
  96. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.inserts-before-existing-sibling/index.tsx +39 -0
  97. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.inserts-before-existing-sibling/output.txt +20 -0
  98. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.mixed-operations/index.tsx +38 -0
  99. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.mixed-operations/output.txt +29 -0
  100. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.moves-before-existing-sibling/index.tsx +40 -0
  101. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.moves-before-existing-sibling/output.txt +12 -0
  102. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/index.tsx +14 -0
  103. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +22 -0
  104. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.removes-missing/index.tsx +14 -0
  105. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.removes-missing/output.txt +13 -0
  106. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.reorders-when-order-differs/index.tsx +34 -0
  107. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.reorders-when-order-differs/output.txt +12 -0
  108. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.reuses-by-type-ignoring-keys/index.tsx +18 -0
  109. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.reuses-by-type-ignoring-keys/output.txt +16 -0
  110. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/complex-trees.deeply-nested-dynamic-content/index.tsx +33 -0
  111. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/complex-trees.deeply-nested-dynamic-content/output.txt +26 -0
  112. package/runtime/__test__/element-template/fixtures/background/init-data/update/index.tsx +11 -0
  113. package/runtime/__test__/element-template/fixtures/background/instance/_shared.ts +30 -0
  114. package/runtime/__test__/element-template/fixtures/background/instance/ops/does-not-emit-patch-when-attrs-reference-reused/case.ts +24 -0
  115. package/runtime/__test__/element-template/fixtures/background/instance/ops/does-not-emit-patch-when-attrs-reference-reused/output.txt +1 -0
  116. package/runtime/__test__/element-template/fixtures/background/instance/ops/emits-bundle-url-in-create-template/case.ts +11 -0
  117. package/runtime/__test__/element-template/fixtures/background/instance/ops/emits-bundle-url-in-create-template/output.txt +8 -0
  118. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/case.ts +11 -0
  119. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/output.txt +1 -0
  120. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-non-object-attrs-entry-as-empty-object/case.ts +23 -0
  121. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-non-object-attrs-entry-as-empty-object/output.txt +6 -0
  122. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/case.ts +23 -0
  123. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/output.txt +6 -0
  124. package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +24 -0
  125. package/runtime/__test__/element-template/fixtures/background/ref/direct-ref/index.tsx +7 -0
  126. package/runtime/__test__/element-template/fixtures/background/ref/multi-ref/index.tsx +20 -0
  127. package/runtime/__test__/element-template/fixtures/background/ref/spread-ref/index.tsx +14 -0
  128. package/runtime/__test__/element-template/fixtures/background/ref/unsupported-ref/index.tsx +12 -0
  129. package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +85 -0
  130. package/runtime/__test__/element-template/fixtures/background/render/constructs-shadow-tree/case.tsx +5 -0
  131. package/runtime/__test__/element-template/fixtures/background/render/constructs-shadow-tree/output.txt +7 -0
  132. package/runtime/__test__/element-template/fixtures/background/render/supports-slot-component-materiality/case.tsx +5 -0
  133. package/runtime/__test__/element-template/fixtures/background/render/supports-slot-component-materiality/output.txt +13 -0
  134. package/runtime/__test__/element-template/fixtures/background/update/keyed/compiled-keyed-list/index.tsx +15 -0
  135. package/runtime/__test__/element-template/fixtures/background/update/keyed/compiled-keyed-subtree-list/index.tsx +19 -0
  136. package/runtime/__test__/element-template/fixtures/background/update/sparse/compiled-element-slot/index.tsx +26 -0
  137. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/_shared.tsx +169 -0
  138. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/multiple-root-instances/case.tsx +5 -0
  139. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/multiple-root-instances/output.txt +14 -0
  140. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/nested-instances/case.tsx +5 -0
  141. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/nested-instances/output.txt +8 -0
  142. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/simple-element/case.tsx +5 -0
  143. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/simple-element/output.txt +10 -0
  144. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/sub-components/case.tsx +5 -0
  145. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/sub-components/output.txt +28 -0
  146. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/sub-components/source.tsx +15 -0
  147. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/text-children/case.tsx +5 -0
  148. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/text-children/output.txt +19 -0
  149. package/runtime/__test__/element-template/fixtures/hydration/hydration-data/text-children/source.tsx +8 -0
  150. package/runtime/__test__/element-template/fixtures/page/render-page/case.tsx +41 -0
  151. package/runtime/__test__/element-template/fixtures/page/render-page/native-log.txt +31 -0
  152. package/runtime/__test__/element-template/fixtures/page/render-page/output.txt +5 -0
  153. package/runtime/__test__/element-template/fixtures/page-compiled/authored-page/index.tsx +67 -0
  154. package/runtime/__test__/element-template/fixtures/patch/_shared.tsx +270 -0
  155. package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/after-jsx.txt +7 -0
  156. package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/before-jsx.txt +8 -0
  157. package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/case.tsx +100 -0
  158. package/runtime/__test__/element-template/fixtures/patch/props-update/after-jsx.txt +3 -0
  159. package/runtime/__test__/element-template/fixtures/patch/props-update/before-jsx.txt +3 -0
  160. package/runtime/__test__/element-template/fixtures/patch/props-update/case.tsx +42 -0
  161. package/runtime/__test__/element-template/fixtures/patch/props-update/ops.txt +8 -0
  162. package/runtime/__test__/element-template/fixtures/patch/state-update/after-jsx.txt +3 -0
  163. package/runtime/__test__/element-template/fixtures/patch/state-update/before-jsx.txt +3 -0
  164. package/runtime/__test__/element-template/fixtures/patch/state-update/case.tsx +64 -0
  165. package/runtime/__test__/element-template/fixtures/patch/state-update/ops.txt +8 -0
  166. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/after-jsx.txt +7 -0
  167. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/before-jsx.txt +6 -0
  168. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/index.tsx +39 -0
  169. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/ops.txt +14 -0
  170. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/after-jsx.txt +10 -0
  171. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/before-jsx.txt +9 -0
  172. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/index.tsx +47 -0
  173. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/ops.txt +34 -0
  174. package/runtime/__test__/element-template/fixtures/render/child-siblings/index.js.txt +21 -0
  175. package/runtime/__test__/element-template/fixtures/render/child-siblings/index.tsx +16 -0
  176. package/runtime/__test__/element-template/fixtures/render/child-siblings/output.txt +8 -0
  177. package/runtime/__test__/element-template/fixtures/render/child-siblings/papi.txt +128 -0
  178. package/runtime/__test__/element-template/fixtures/render/child-siblings/templates.json.txt +66 -0
  179. package/runtime/__test__/element-template/fixtures/render/component/index.js.txt +12 -0
  180. package/runtime/__test__/element-template/fixtures/render/component/index.tsx +17 -0
  181. package/runtime/__test__/element-template/fixtures/render/component/output.txt +7 -0
  182. package/runtime/__test__/element-template/fixtures/render/component/papi.txt +67 -0
  183. package/runtime/__test__/element-template/fixtures/render/component/templates.json.txt +68 -0
  184. package/runtime/__test__/element-template/fixtures/render/component-slot-content/index.js.txt +16 -0
  185. package/runtime/__test__/element-template/fixtures/render/component-slot-content/index.tsx +18 -0
  186. package/runtime/__test__/element-template/fixtures/render/component-slot-content/output.txt +6 -0
  187. package/runtime/__test__/element-template/fixtures/render/component-slot-content/papi.txt +85 -0
  188. package/runtime/__test__/element-template/fixtures/render/component-slot-content/templates.json.txt +78 -0
  189. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/fixture.config.json +5 -0
  190. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/index.js.txt +6 -0
  191. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/index.tsx +9 -0
  192. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/output.txt +3 -0
  193. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/papi.txt +25 -0
  194. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/templates.json.txt +57 -0
  195. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/index.js.txt +18 -0
  196. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/index.tsx +13 -0
  197. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/output.txt +17 -0
  198. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/papi.txt +214 -0
  199. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/templates.json.txt +63 -0
  200. package/runtime/__test__/element-template/fixtures/render/mixed-children/index.js.txt +15 -0
  201. package/runtime/__test__/element-template/fixtures/render/mixed-children/index.tsx +15 -0
  202. package/runtime/__test__/element-template/fixtures/render/mixed-children/output.txt +7 -0
  203. package/runtime/__test__/element-template/fixtures/render/mixed-children/papi.txt +86 -0
  204. package/runtime/__test__/element-template/fixtures/render/mixed-children/templates.json.txt +51 -0
  205. package/runtime/__test__/element-template/fixtures/render/multiple-text/index.js.txt +23 -0
  206. package/runtime/__test__/element-template/fixtures/render/multiple-text/index.tsx +22 -0
  207. package/runtime/__test__/element-template/fixtures/render/multiple-text/output.txt +38 -0
  208. package/runtime/__test__/element-template/fixtures/render/multiple-text/papi.txt +454 -0
  209. package/runtime/__test__/element-template/fixtures/render/multiple-text/templates.json.txt +131 -0
  210. package/runtime/__test__/element-template/fixtures/render/nested-templates/index.js.txt +19 -0
  211. package/runtime/__test__/element-template/fixtures/render/nested-templates/index.tsx +19 -0
  212. package/runtime/__test__/element-template/fixtures/render/nested-templates/output.txt +5 -0
  213. package/runtime/__test__/element-template/fixtures/render/nested-templates/papi.txt +80 -0
  214. package/runtime/__test__/element-template/fixtures/render/nested-templates/templates.json.txt +34 -0
  215. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/_shared.ts +131 -0
  216. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/appends-root-text-via-append-element/case.ts +19 -0
  217. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/appends-root-text-via-append-element/native-log.txt +27 -0
  218. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/appends-root-text-via-append-element/output.txt +12 -0
  219. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/case.ts +39 -0
  220. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/native-log.txt +49 -0
  221. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/output.txt +34 -0
  222. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-template-children-in-the-same-slot/case.ts +34 -0
  223. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-template-children-in-the-same-slot/native-log.txt +56 -0
  224. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-template-children-in-the-same-slot/output.txt +11 -0
  225. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/case.ts +29 -0
  226. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +64 -0
  227. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/output.txt +20 -0
  228. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/case.ts +42 -0
  229. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/native-log.txt +84 -0
  230. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/output.txt +42 -0
  231. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/case.ts +31 -0
  232. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/native-log.txt +66 -0
  233. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/output.txt +41 -0
  234. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/passes-bundle-url-to-native-create/case.ts +20 -0
  235. package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/passes-bundle-url-to-native-create/native-log.txt +25 -0
  236. package/runtime/__test__/element-template/fixtures/render/react-example/index.js.txt +39 -0
  237. package/runtime/__test__/element-template/fixtures/render/react-example/index.tsx +51 -0
  238. package/runtime/__test__/element-template/fixtures/render/react-example/output.txt +24 -0
  239. package/runtime/__test__/element-template/fixtures/render/react-example/papi.txt +70 -0
  240. package/runtime/__test__/element-template/fixtures/render/react-example/templates.json.txt +280 -0
  241. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/index.js.txt +14 -0
  242. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/index.tsx +17 -0
  243. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/output.txt +10 -0
  244. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/papi.txt +81 -0
  245. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/templates.json.txt +97 -0
  246. package/runtime/__test__/element-template/fixtures/render/template-dedupe/index.js.txt +28 -0
  247. package/runtime/__test__/element-template/fixtures/render/template-dedupe/index.tsx +28 -0
  248. package/runtime/__test__/element-template/fixtures/render/template-dedupe/output.txt +12 -0
  249. package/runtime/__test__/element-template/fixtures/render/template-dedupe/papi.txt +144 -0
  250. package/runtime/__test__/element-template/fixtures/render/template-dedupe/templates.json.txt +57 -0
  251. package/runtime/__test__/element-template/imports/global-props-api.test.ts +23 -0
  252. package/runtime/__test__/element-template/imports/init-data-api.test.ts +19 -0
  253. package/runtime/__test__/element-template/imports/jsx-runtime.test.ts +76 -0
  254. package/runtime/__test__/element-template/imports/legacy-react-runtime.test.ts +100 -0
  255. package/runtime/__test__/element-template/imports/main-thread-ref-api.test.ts +10 -0
  256. package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +415 -0
  257. package/runtime/__test__/element-template/imports/register-data-processors.test.ts +34 -0
  258. package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +295 -0
  259. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +35 -0
  260. package/runtime/__test__/element-template/lynx/env.test.ts +242 -0
  261. package/runtime/__test__/element-template/lynx/lazy-bundle.test.ts +294 -0
  262. package/runtime/__test__/element-template/lynx/performance.test.ts +161 -0
  263. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +107 -0
  264. package/runtime/__test__/element-template/native/index.test.ts +224 -0
  265. package/runtime/__test__/element-template/native/init-timing-api.test.ts +29 -0
  266. package/runtime/__test__/element-template/native/main-thread-api.test.ts +202 -0
  267. package/runtime/__test__/element-template/native/mts-destroy.test.ts +226 -0
  268. package/runtime/__test__/element-template/native/reload.test.ts +588 -0
  269. package/runtime/__test__/element-template/runtime/background/adapter/background-adapter.et.test.tsx +65 -0
  270. package/runtime/__test__/element-template/runtime/background/commit-context.test.ts +91 -0
  271. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +800 -0
  272. package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +867 -0
  273. package/runtime/__test__/element-template/runtime/background/global-props/compiled-fixtures.test.tsx +220 -0
  274. package/runtime/__test__/element-template/runtime/background/global-props.test.tsx +173 -0
  275. package/runtime/__test__/element-template/runtime/background/hydrate/compiled-fixtures.test.ts +43 -0
  276. package/runtime/__test__/element-template/runtime/background/hydrate/fixtures.test.ts +16 -0
  277. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +2179 -0
  278. package/runtime/__test__/element-template/runtime/background/init-data/compiled-fixtures.test.tsx +129 -0
  279. package/runtime/__test__/element-template/runtime/background/instance/fixtures.test.ts +16 -0
  280. package/runtime/__test__/element-template/runtime/background/instance.test.ts +2751 -0
  281. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +287 -0
  282. package/runtime/__test__/element-template/runtime/background/manager.test.ts +142 -0
  283. package/runtime/__test__/element-template/runtime/background/page-root-hydrate.test.ts +75 -0
  284. package/runtime/__test__/element-template/runtime/background/ref/compiled-fixtures.test.tsx +339 -0
  285. package/runtime/__test__/element-template/runtime/background/reload.test.ts +79 -0
  286. package/runtime/__test__/element-template/runtime/background/render/fixtures.test.ts +16 -0
  287. package/runtime/__test__/element-template/runtime/background/render/preact.test.tsx +268 -0
  288. package/runtime/__test__/element-template/runtime/background/root-render.test.tsx +265 -0
  289. package/runtime/__test__/element-template/runtime/background/suspense.test.tsx +940 -0
  290. package/runtime/__test__/element-template/runtime/background/update/compiled-fixtures.test.tsx +277 -0
  291. package/runtime/__test__/element-template/runtime/background/update/sparse-fixtures.test.tsx +163 -0
  292. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +127 -0
  293. package/runtime/__test__/element-template/runtime/hydration/fixtures.test.ts +16 -0
  294. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +1249 -0
  295. package/runtime/__test__/element-template/runtime/page/authored-page.test.ts +35 -0
  296. package/runtime/__test__/element-template/runtime/page/compiled-fixtures.test.tsx +560 -0
  297. package/runtime/__test__/element-template/runtime/page/fixtures.test.ts +16 -0
  298. package/runtime/__test__/element-template/runtime/page/page.test.ts +25 -0
  299. package/runtime/__test__/element-template/runtime/page/root-instance.test.ts +25 -0
  300. package/runtime/__test__/element-template/runtime/patch/compiled-fixtures.test.ts +40 -0
  301. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +3704 -0
  302. package/runtime/__test__/element-template/runtime/patch/fixtures.test.ts +16 -0
  303. package/runtime/__test__/element-template/runtime/patch/patch-listener-alog.test.ts +80 -0
  304. package/runtime/__test__/element-template/runtime/patch/update-fixture-helper.test.tsx +40 -0
  305. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +203 -0
  306. package/runtime/__test__/element-template/runtime/prop-adapters/event.test.ts +183 -0
  307. package/runtime/__test__/element-template/runtime/prop-adapters/hydrate.test.ts +246 -0
  308. package/runtime/__test__/element-template/runtime/prop-adapters/ref.test.ts +155 -0
  309. package/runtime/__test__/element-template/runtime/prop-adapters/spread.test.ts +160 -0
  310. package/runtime/__test__/element-template/runtime/protocol/template-type.test.ts +40 -0
  311. package/runtime/__test__/element-template/runtime/render/fixtures.test.ts +18 -0
  312. package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +143 -0
  313. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +377 -0
  314. package/runtime/__test__/element-template/runtime/render/render-opcodes-into-element-template.et.test.tsx +791 -0
  315. package/runtime/__test__/element-template/runtime/render/render-to-opcodes.et.test.jsx +522 -0
  316. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +564 -0
  317. package/runtime/__test__/element-template/runtime/template/element-template-attr-slot-plan.test.ts +373 -0
  318. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +228 -0
  319. package/runtime/__test__/element-template/runtime/template/element-template-registry.test.ts +65 -0
  320. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +567 -0
  321. package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +280 -0
  322. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureApp.ts +26 -0
  323. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureCompiler.ts +76 -0
  324. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +74 -0
  325. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureRegistry.ts +22 -0
  326. package/runtime/__test__/element-template/test-utils/debug/compiledHydrationScenario.ts +82 -0
  327. package/runtime/__test__/element-template/test-utils/debug/compiledThreadRunner.ts +70 -0
  328. package/runtime/__test__/element-template/test-utils/debug/envManager.ts +96 -0
  329. package/runtime/__test__/element-template/test-utils/debug/fixtureRunner.ts +284 -0
  330. package/runtime/__test__/element-template/test-utils/debug/hydrate.ts +23 -0
  331. package/runtime/__test__/element-template/test-utils/debug/registry.ts +43 -0
  332. package/runtime/__test__/element-template/test-utils/debug/renderFixtureRunner.ts +337 -0
  333. package/runtime/__test__/element-template/test-utils/debug/serializer.ts +79 -0
  334. package/runtime/__test__/element-template/test-utils/debug/updateRunner.test.tsx +148 -0
  335. package/runtime/__test__/element-template/test-utils/debug/updateRunner.ts +303 -0
  336. package/runtime/__test__/element-template/test-utils/mock/globals.js +35 -0
  337. package/runtime/__test__/element-template/test-utils/mock/jscontext-mock.test.ts +142 -0
  338. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/context.ts +305 -0
  339. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.test.ts +187 -0
  340. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.ts +745 -0
  341. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +432 -0
  342. package/runtime/__test__/element-template/test-utils/mock/performance.js +68 -0
  343. package/runtime/__test__/element-template/test-utils/setup.js +100 -0
  344. package/runtime/__test__/element-template/vitest.config.ts +128 -0
  345. package/runtime/__test__/guardrails/snapshot-containment.test.ts +198 -0
  346. package/runtime/__test__/shared/profile.test.ts +88 -0
  347. package/runtime/__test__/snapshot/alog/elementPAPICall.test.js +50 -0
  348. package/runtime/__test__/snapshot/attribute-name.test.ts +78 -0
  349. package/runtime/__test__/snapshot/basic.test.jsx +718 -0
  350. package/runtime/__test__/snapshot/children.test.jsx +476 -0
  351. package/runtime/__test__/snapshot/clone.test.jsx +959 -0
  352. package/runtime/__test__/snapshot/commit-context.test.ts +29 -0
  353. package/runtime/__test__/snapshot/compat/export.test.jsx +42 -0
  354. package/runtime/__test__/snapshot/compat/hooks.test.jsx +45 -0
  355. package/runtime/__test__/snapshot/compat/initData.test.jsx +195 -0
  356. package/runtime/__test__/snapshot/compat/use-insertion-effect.test.jsx +128 -0
  357. package/runtime/__test__/snapshot/compat/use.test.jsx +111 -0
  358. package/runtime/__test__/snapshot/compat.test.jsx +199 -0
  359. package/runtime/__test__/snapshot/createElement.test.jsx +1352 -0
  360. package/runtime/__test__/snapshot/createSuspender.jsx +26 -0
  361. package/runtime/__test__/snapshot/css/compat.test.jsx +164 -0
  362. package/runtime/__test__/snapshot/css/remove-scoped-lazy-bundle.test.jsx +40 -0
  363. package/runtime/__test__/snapshot/css/remove-scoped-main-bundle.test.jsx +27 -0
  364. package/runtime/__test__/snapshot/css/scoped-lazy-bundle.test.jsx +45 -0
  365. package/runtime/__test__/snapshot/css/scoped-main-bundle.test.jsx +36 -0
  366. package/runtime/__test__/snapshot/debug/backgroundSnapshot-profile.test.jsx +366 -0
  367. package/runtime/__test__/snapshot/debug/children-with-same-key.test.jsx +43 -0
  368. package/runtime/__test__/snapshot/debug/describeInvalidValue.test.ts +32 -0
  369. package/runtime/__test__/snapshot/debug/formatPatch.test.ts +89 -0
  370. package/runtime/__test__/snapshot/debug/hooks-in-render.test.jsx +13 -0
  371. package/runtime/__test__/snapshot/debug/hooks-invalid-args.test.jsx +42 -0
  372. package/runtime/__test__/snapshot/debug/jsx-twice.test.jsx +55 -0
  373. package/runtime/__test__/snapshot/debug/missing-suspense.test.jsx +35 -0
  374. package/runtime/__test__/snapshot/debug/object-as-child.test.jsx +35 -0
  375. package/runtime/__test__/snapshot/debug/printSnapshot.test.jsx +155 -0
  376. package/runtime/__test__/snapshot/debug/profile.test.jsx +348 -0
  377. package/runtime/__test__/snapshot/debug/react-hooks-profile.test.jsx +285 -0
  378. package/runtime/__test__/snapshot/debug/set-state-in-ctor.test.jsx +40 -0
  379. package/runtime/__test__/snapshot/debug/too-many-rerenders.test.jsx +33 -0
  380. package/runtime/__test__/snapshot/debug/undefined-component.test.jsx +40 -0
  381. package/runtime/__test__/snapshot/debug/vnodeSource.test.ts +120 -0
  382. package/runtime/__test__/snapshot/delayed-lifecycle-events.test.jsx +62 -0
  383. package/runtime/__test__/snapshot/dynamicPartType.test.jsx +690 -0
  384. package/runtime/__test__/snapshot/element.test.jsx +46 -0
  385. package/runtime/__test__/snapshot/event.test.jsx +1294 -0
  386. package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +86 -0
  387. package/runtime/__test__/snapshot/gesture/processGesture.test.ts +326 -0
  388. package/runtime/__test__/snapshot/gesture.test.jsx +1446 -0
  389. package/runtime/__test__/snapshot/hydrate.test.jsx +372 -0
  390. package/runtime/__test__/snapshot/jsx-runtime-lepus.test.jsx +89 -0
  391. package/runtime/__test__/snapshot/lazy.test.js +203 -0
  392. package/runtime/__test__/snapshot/legacySlot.legacy-slot.test.jsx +437 -0
  393. package/runtime/__test__/snapshot/lifecycle/commitHook.test.jsx +112 -0
  394. package/runtime/__test__/snapshot/lifecycle/destroy.test.jsx +47 -0
  395. package/runtime/__test__/snapshot/lifecycle/emptyPatch.test.jsx +104 -0
  396. package/runtime/__test__/snapshot/lifecycle/isRendering.test.jsx +114 -0
  397. package/runtime/__test__/snapshot/lifecycle/reload.test.jsx +1908 -0
  398. package/runtime/__test__/snapshot/lifecycle/reloadBG.jsx +79 -0
  399. package/runtime/__test__/snapshot/lifecycle/reloadMT.jsx +76 -0
  400. package/runtime/__test__/snapshot/lifecycle/resetPageDataError.test.jsx +79 -0
  401. package/runtime/__test__/snapshot/lifecycle/updateData.test.jsx +1688 -0
  402. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.event.test.jsx +226 -0
  403. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx +382 -0
  404. package/runtime/__test__/snapshot/lifecycle.test.jsx +675 -0
  405. package/runtime/__test__/snapshot/list.test.jsx +4956 -0
  406. package/runtime/__test__/snapshot/lynx/component-compat.test.ts +188 -0
  407. package/runtime/__test__/snapshot/lynx/dynamic-import.test.ts +111 -0
  408. package/runtime/__test__/snapshot/lynx/injectLepusMethods.test.jsx +81 -0
  409. package/runtime/__test__/snapshot/lynx/lazy-bundle-fetchbundle.test.js +659 -0
  410. package/runtime/__test__/snapshot/lynx/lazy-bundle.test.js +576 -0
  411. package/runtime/__test__/snapshot/lynx/portals.test.jsx +677 -0
  412. package/runtime/__test__/snapshot/lynx/prepareLazyBundleMTS.test.js +212 -0
  413. package/runtime/__test__/snapshot/lynx/processEvalResult.test.js +23 -0
  414. package/runtime/__test__/snapshot/lynx/runtime-backend.test.ts +81 -0
  415. package/runtime/__test__/snapshot/lynx/suspense.test.jsx +1641 -0
  416. package/runtime/__test__/snapshot/lynx/timing.test.jsx +1011 -0
  417. package/runtime/__test__/snapshot/lynx-data-processors.test.ts +3 -0
  418. package/runtime/__test__/snapshot/lynxQueueMicrotask.test.jsx +38 -0
  419. package/runtime/__test__/snapshot/mtf-execid-churn.test.jsx +216 -0
  420. package/runtime/__test__/snapshot/page.test.jsx +417 -0
  421. package/runtime/__test__/snapshot/preact.test.jsx +930 -0
  422. package/runtime/__test__/snapshot/ref-parity.test.jsx +78 -0
  423. package/runtime/__test__/snapshot/ref.test.jsx +2368 -0
  424. package/runtime/__test__/snapshot/render.test.jsx +148 -0
  425. package/runtime/__test__/snapshot/renderToOpcodes.test.jsx +1618 -0
  426. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +1798 -0
  427. package/runtime/__test__/snapshot/spread.test.jsx +771 -0
  428. package/runtime/__test__/snapshot/ssr.test.jsx +574 -0
  429. package/runtime/__test__/snapshot/use-main-thread.test.jsx +141 -0
  430. package/runtime/__test__/snapshot/utils/debug.js +41 -0
  431. package/runtime/__test__/snapshot/utils/envManager.ts +109 -0
  432. package/runtime/__test__/snapshot/utils/globals.js +224 -0
  433. package/runtime/__test__/snapshot/utils/inject.ts +31 -0
  434. package/runtime/__test__/snapshot/utils/jsModule.ts +49 -0
  435. package/runtime/__test__/snapshot/utils/nativeMethod.ts +498 -0
  436. package/runtime/__test__/snapshot/utils/runtimeProxy.test.js +36 -0
  437. package/runtime/__test__/snapshot/utils/runtimeProxy.ts +73 -0
  438. package/runtime/__test__/snapshot/utils/setup.js +72 -0
  439. package/runtime/__test__/snapshot/worklet/onPost.test.js +30 -0
  440. package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +234 -0
  441. package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +402 -0
  442. package/runtime/__test__/snapshot/worklet/transform.test.js +35 -0
  443. package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +292 -0
  444. package/runtime/__test__/snapshot/workletEvent.test.jsx +1286 -0
  445. package/runtime/__test__/snapshot/workletLifecycle.test.ts +198 -0
  446. package/runtime/__test__/snapshot/workletRef.test.jsx +831 -0
  447. package/runtime/__test__/snapshot/workletRefBG.jsx +95 -0
  448. package/runtime/__test__/snapshot/workletRefMT.jsx +99 -0
  449. package/runtime/__test__/test-utils/lynx-event-emitter.ts +63 -0
  450. package/runtime/__test__/tsconfig.json +9 -0
  451. package/runtime/__test__/worklet-runtime/api/element.test.js +274 -0
  452. package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +89 -0
  453. package/runtime/__test__/worklet-runtime/eventPropagation.test.js +89 -0
  454. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +89 -0
  455. package/runtime/__test__/worklet-runtime/mainThreadFlushLoopGuard.test.js +235 -0
  456. package/runtime/__test__/worklet-runtime/observers.test.js +119 -0
  457. package/runtime/__test__/worklet-runtime/profile.test.js +27 -0
  458. package/runtime/__test__/worklet-runtime/runOnBackground.test.js +186 -0
  459. package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +66 -0
  460. package/runtime/__test__/worklet-runtime/workletRef.test.js +328 -0
  461. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +534 -0
  462. package/runtime/compat/index.d.ts +1 -1
  463. package/runtime/lazy/element-template-internal.js +35 -0
  464. package/runtime/lazy/element-template-jsx-dev-runtime.js +19 -0
  465. package/runtime/lazy/element-template-jsx-runtime.js +14 -0
  466. package/runtime/lazy/element-template.js +53 -0
  467. package/runtime/lib/core/ref.d.ts +7 -5
  468. package/runtime/lib/core/ref.js +22 -11
  469. package/runtime/lib/core/ref.js.map +1 -1
  470. package/runtime/lib/element-template/background/attr-slots.d.ts +3 -1
  471. package/runtime/lib/element-template/background/attr-slots.js +5 -5
  472. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  473. package/runtime/lib/element-template/background/commit-context.d.ts +1 -1
  474. package/runtime/lib/element-template/background/commit-context.js +8 -9
  475. package/runtime/lib/element-template/background/commit-context.js.map +1 -1
  476. package/runtime/lib/element-template/background/hydrate.js +19 -17
  477. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  478. package/runtime/lib/element-template/background/instance.d.ts +4 -4
  479. package/runtime/lib/element-template/background/instance.js +10 -10
  480. package/runtime/lib/element-template/background/instance.js.map +1 -1
  481. package/runtime/lib/element-template/background/page-root-hydrate.js +1 -1
  482. package/runtime/lib/element-template/background/page-root-hydrate.js.map +1 -1
  483. package/runtime/lib/element-template/debug/alog.d.ts +4 -4
  484. package/runtime/lib/element-template/debug/alog.js +8 -8
  485. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  486. package/runtime/lib/element-template/native/index.js +3 -1
  487. package/runtime/lib/element-template/native/index.js.map +1 -1
  488. package/runtime/lib/element-template/native/main-thread-api.js +3 -3
  489. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  490. package/runtime/lib/element-template/native/patch-listener.js +1 -2
  491. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  492. package/runtime/lib/element-template/native/reload-main-thread.js +3 -3
  493. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  494. package/runtime/lib/element-template/prop-adapters/ref.d.ts +3 -1
  495. package/runtime/lib/element-template/prop-adapters/ref.js +2 -2
  496. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
  497. package/runtime/lib/element-template/protocol/types.d.ts +27 -20
  498. package/runtime/lib/element-template/runtime/list/list.d.ts +5 -5
  499. package/runtime/lib/element-template/runtime/list/list.js +8 -7
  500. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  501. package/runtime/lib/element-template/runtime/page/page.d.ts +3 -3
  502. package/runtime/lib/element-template/runtime/page/page.js +1 -1
  503. package/runtime/lib/element-template/runtime/page/page.js.map +1 -1
  504. package/runtime/lib/element-template/runtime/patch.js +35 -40
  505. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  506. package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -2
  507. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  508. package/runtime/lib/element-template/runtime/render/render-opcodes.d.ts +1 -1
  509. package/runtime/lib/element-template/runtime/render/render-opcodes.js +21 -21
  510. package/runtime/lib/element-template/runtime/render/render-opcodes.js.map +1 -1
  511. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js +10 -8
  512. package/runtime/lib/element-template/runtime/render/render-to-opcodes.js.map +1 -1
  513. package/runtime/lib/element-template/runtime/template/handle.d.ts +4 -4
  514. package/runtime/lib/element-template/runtime/template/handle.js +6 -6
  515. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  516. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +2 -2
  517. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  518. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +1 -1
  519. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  520. package/runtime/lib/element-template/runtime/template/registry.d.ts +6 -6
  521. package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
  522. package/runtime/lib/shared/render-constants.d.ts +1 -0
  523. package/runtime/lib/shared/render-constants.js +1 -0
  524. package/runtime/lib/shared/render-constants.js.map +1 -1
  525. package/runtime/lib/snapshot/renderToOpcodes/index.js +5 -3
  526. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  527. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +18 -25
  528. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  529. package/runtime/lib/snapshot/snapshot/ref.d.ts +3 -2
  530. package/runtime/lib/snapshot/snapshot/ref.js +4 -7
  531. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  532. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  533. package/runtime/package.json +37 -0
  534. package/runtime/src/core/background-function/exec-map.ts +44 -0
  535. package/runtime/src/core/background-function/handle.ts +31 -0
  536. package/runtime/src/core/background-function/run-on-background.ts +151 -0
  537. package/runtime/src/core/commit-context.ts +26 -0
  538. package/runtime/src/core/compat/legacy-react-runtime.ts +39 -0
  539. package/runtime/src/core/compat/lynxComponent.ts +91 -0
  540. package/runtime/src/core/component.ts +152 -0
  541. package/runtime/src/core/forceRootRender.ts +52 -0
  542. package/runtime/src/core/globalProps.ts +111 -0
  543. package/runtime/src/core/hooks/mainThread.ts +9 -0
  544. package/runtime/src/core/hooks/mainThreadImpl.ts +226 -0
  545. package/runtime/src/core/hooks/react.ts +172 -0
  546. package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +59 -0
  547. package/runtime/src/core/initData.ts +191 -0
  548. package/runtime/src/core/lynx/dynamic-import.ts +37 -0
  549. package/runtime/src/core/lynx/lazy-bundle.ts +352 -0
  550. package/runtime/src/core/lynx/runtime-backend.ts +30 -0
  551. package/runtime/src/core/lynx-data-processors.ts +85 -0
  552. package/runtime/src/core/lynx-page-data.ts +22 -0
  553. package/runtime/src/core/lynx-update-data.ts +47 -0
  554. package/runtime/src/core/main-thread-function.ts +12 -0
  555. package/runtime/src/core/main-thread-ref-init-value.ts +29 -0
  556. package/runtime/src/core/main-thread-ref.ts +225 -0
  557. package/runtime/src/core/mts-capability.ts +21 -0
  558. package/runtime/src/core/performance.ts +186 -0
  559. package/runtime/src/core/ref.ts +181 -0
  560. package/runtime/src/core/reload-version.ts +13 -0
  561. package/runtime/src/core/runtime-destroy.ts +22 -0
  562. package/runtime/src/core/thread-function-call/main-thread.ts +81 -0
  563. package/runtime/src/core/thread-function-call/return-value.ts +77 -0
  564. package/runtime/src/document.ts +86 -0
  565. package/runtime/src/element-template/background/attr-slots.ts +132 -0
  566. package/runtime/src/element-template/background/commit-context.ts +47 -0
  567. package/runtime/src/element-template/background/commit-hook.ts +211 -0
  568. package/runtime/src/element-template/background/destroy.ts +34 -0
  569. package/runtime/src/element-template/background/document.ts +41 -0
  570. package/runtime/src/element-template/background/hydrate.ts +605 -0
  571. package/runtime/src/element-template/background/hydration-listener.ts +198 -0
  572. package/runtime/src/element-template/background/instance.ts +820 -0
  573. package/runtime/src/element-template/background/manager.ts +89 -0
  574. package/runtime/src/element-template/background/page-root-hydrate.ts +23 -0
  575. package/runtime/src/element-template/background/render-scope.ts +52 -0
  576. package/runtime/src/element-template/client/root.ts +71 -0
  577. package/runtime/src/element-template/debug/alog.ts +238 -0
  578. package/runtime/src/element-template/debug/elementPAPICall.ts +89 -0
  579. package/runtime/src/element-template/debug/profile.ts +194 -0
  580. package/runtime/src/element-template/hydration-map.ts +13 -0
  581. package/runtime/src/element-template/index.ts +138 -0
  582. package/runtime/src/element-template/internal.ts +69 -0
  583. package/runtime/src/element-template/jsx-dev-runtime/index.ts +4 -0
  584. package/runtime/src/element-template/jsx-runtime/index.ts +86 -0
  585. package/runtime/src/element-template/lynx/env.ts +59 -0
  586. package/runtime/src/element-template/lynx/performance.ts +20 -0
  587. package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +10 -0
  588. package/runtime/src/element-template/native/index.ts +92 -0
  589. package/runtime/src/element-template/native/main-thread-api.ts +55 -0
  590. package/runtime/src/element-template/native/mts-destroy.ts +46 -0
  591. package/runtime/src/element-template/native/patch-listener.ts +136 -0
  592. package/runtime/src/element-template/native/reload-background.ts +43 -0
  593. package/runtime/src/element-template/native/reload-main-thread.ts +76 -0
  594. package/runtime/src/element-template/prop-adapters/event-value.ts +11 -0
  595. package/runtime/src/element-template/prop-adapters/event.ts +87 -0
  596. package/runtime/src/element-template/prop-adapters/ref.ts +148 -0
  597. package/runtime/src/element-template/prop-adapters/spread.ts +66 -0
  598. package/runtime/src/element-template/protocol/lifecycle-constant.ts +8 -0
  599. package/runtime/src/element-template/protocol/opcodes.ts +18 -0
  600. package/runtime/src/element-template/protocol/page.ts +7 -0
  601. package/runtime/src/element-template/protocol/template-type.ts +56 -0
  602. package/runtime/src/element-template/protocol/types.ts +229 -0
  603. package/runtime/src/element-template/protocol/update-event.ts +46 -0
  604. package/runtime/src/element-template/runtime/list/list.ts +829 -0
  605. package/runtime/src/element-template/runtime/page/authored-page.ts +53 -0
  606. package/runtime/src/element-template/runtime/page/page.ts +21 -0
  607. package/runtime/src/element-template/runtime/page/root-instance.ts +25 -0
  608. package/runtime/src/element-template/runtime/patch.ts +517 -0
  609. package/runtime/src/element-template/runtime/render/render-main-thread.ts +81 -0
  610. package/runtime/src/element-template/runtime/render/render-opcodes.ts +313 -0
  611. package/runtime/src/element-template/runtime/render/render-to-opcodes.ts +411 -0
  612. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +153 -0
  613. package/runtime/src/element-template/runtime/template/handle.ts +95 -0
  614. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +48 -0
  615. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +242 -0
  616. package/runtime/src/element-template/runtime/template/main-thread-event-ctx.ts +46 -0
  617. package/runtime/src/element-template/runtime/template/main-thread-function.ts +32 -0
  618. package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +95 -0
  619. package/runtime/src/element-template/runtime/template/registry.ts +72 -0
  620. package/runtime/src/element-template/runtime/template/typed-attributes.ts +25 -0
  621. package/runtime/src/element-template/runtime-backend-marker.ts +7 -0
  622. package/runtime/src/element-template/types.d.ts +128 -0
  623. package/runtime/src/index.ts +95 -0
  624. package/runtime/src/internal.ts +102 -0
  625. package/runtime/src/lynx-api.ts +563 -0
  626. package/runtime/src/lynx.ts +93 -0
  627. package/runtime/src/root.ts +38 -0
  628. package/runtime/src/runtime-backend-marker.ts +7 -0
  629. package/runtime/src/shared/attribute-name.ts +109 -0
  630. package/runtime/src/shared/component-stack.ts +168 -0
  631. package/runtime/src/shared/index-map.ts +26 -0
  632. package/runtime/src/shared/profile.ts +36 -0
  633. package/runtime/src/shared/render-constants.ts +42 -0
  634. package/runtime/src/snapshot/alog/elementPAPICall.ts +132 -0
  635. package/runtime/src/snapshot/alog/index.ts +8 -0
  636. package/runtime/src/snapshot/alog/render.ts +33 -0
  637. package/runtime/src/snapshot/compat/componentIs.ts +30 -0
  638. package/runtime/src/snapshot/debug/debug.ts +9 -0
  639. package/runtime/src/snapshot/debug/describeInvalidValue.ts +25 -0
  640. package/runtime/src/snapshot/debug/formatPatch.ts +28 -0
  641. package/runtime/src/snapshot/debug/printSnapshot.ts +63 -0
  642. package/runtime/src/snapshot/debug/profileHooks.ts +271 -0
  643. package/runtime/src/snapshot/debug/vnodeSource.ts +82 -0
  644. package/runtime/src/snapshot/gesture/processGesture.ts +274 -0
  645. package/runtime/src/snapshot/gesture/processGestureBagkround.ts +94 -0
  646. package/runtime/src/snapshot/gesture/types.ts +46 -0
  647. package/runtime/src/snapshot/index.ts +5 -0
  648. package/runtime/src/snapshot/lifecycle/constant.ts +29 -0
  649. package/runtime/src/snapshot/lifecycle/destroy.ts +38 -0
  650. package/runtime/src/snapshot/lifecycle/event/delayEvents.ts +11 -0
  651. package/runtime/src/snapshot/lifecycle/event/delayLifecycleEvents.ts +15 -0
  652. package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +97 -0
  653. package/runtime/src/snapshot/lifecycle/isRendering.ts +27 -0
  654. package/runtime/src/snapshot/lifecycle/patch/commit.ts +278 -0
  655. package/runtime/src/snapshot/lifecycle/patch/error.ts +66 -0
  656. package/runtime/src/snapshot/lifecycle/patch/globalState.ts +16 -0
  657. package/runtime/src/snapshot/lifecycle/patch/isMainThreadHydrating.ts +13 -0
  658. package/runtime/src/snapshot/lifecycle/patch/nodesRefApply.ts +119 -0
  659. package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +97 -0
  660. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +170 -0
  661. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +115 -0
  662. package/runtime/src/snapshot/lifecycle/ref/delay.ts +82 -0
  663. package/runtime/src/snapshot/lifecycle/reload.ts +95 -0
  664. package/runtime/src/snapshot/lifecycle/render.ts +36 -0
  665. package/runtime/src/snapshot/list/list.ts +320 -0
  666. package/runtime/src/snapshot/list/listUpdateInfo.ts +265 -0
  667. package/runtime/src/snapshot/list/pendingListUpdates.ts +44 -0
  668. package/runtime/src/snapshot/lynx/calledByNative.ts +180 -0
  669. package/runtime/src/snapshot/lynx/children.ts +40 -0
  670. package/runtime/src/snapshot/lynx/element.ts +217 -0
  671. package/runtime/src/snapshot/lynx/env.ts +58 -0
  672. package/runtime/src/snapshot/lynx/injectLepusMethods.ts +53 -0
  673. package/runtime/src/snapshot/lynx/lazyBundleConstants.ts +9 -0
  674. package/runtime/src/snapshot/lynx/nodesRef.ts +47 -0
  675. package/runtime/src/snapshot/lynx/performance.ts +20 -0
  676. package/runtime/src/snapshot/lynx/portals.ts +203 -0
  677. package/runtime/src/snapshot/lynx/portalsPending.ts +62 -0
  678. package/runtime/src/snapshot/lynx/prepareLazyBundleMTS.ts +68 -0
  679. package/runtime/src/snapshot/lynx/runWithForce.ts +18 -0
  680. package/runtime/src/snapshot/lynx/suspense.ts +58 -0
  681. package/runtime/src/snapshot/lynx/tt.ts +281 -0
  682. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +465 -0
  683. package/runtime/src/snapshot/renderToOpcodes/index.ts +445 -0
  684. package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +155 -0
  685. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +822 -0
  686. package/runtime/src/snapshot/snapshot/constants.ts +27 -0
  687. package/runtime/src/snapshot/snapshot/definition.ts +258 -0
  688. package/runtime/src/snapshot/snapshot/dynamicPartType.ts +40 -0
  689. package/runtime/src/snapshot/snapshot/event.ts +33 -0
  690. package/runtime/src/snapshot/snapshot/gesture.ts +31 -0
  691. package/runtime/src/snapshot/snapshot/index.ts +8 -0
  692. package/runtime/src/snapshot/snapshot/list.ts +66 -0
  693. package/runtime/src/snapshot/snapshot/platformInfo.ts +109 -0
  694. package/runtime/src/snapshot/snapshot/reconstructInstanceTree.ts +46 -0
  695. package/runtime/src/snapshot/snapshot/ref.ts +116 -0
  696. package/runtime/src/snapshot/snapshot/snapshot.ts +627 -0
  697. package/runtime/src/snapshot/snapshot/snapshotCreatorMap.ts +33 -0
  698. package/runtime/src/snapshot/snapshot/snapshotInstanceHydrationMap.ts +17 -0
  699. package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +22 -0
  700. package/runtime/src/snapshot/snapshot/spread.ts +378 -0
  701. package/runtime/src/snapshot/snapshot/types.ts +29 -0
  702. package/runtime/src/snapshot/snapshot/utils.ts +59 -0
  703. package/runtime/src/snapshot/snapshot/workletEvent.ts +73 -0
  704. package/runtime/src/snapshot/snapshot/workletRef.ts +97 -0
  705. package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +37 -0
  706. package/runtime/src/snapshot/worklet/ctx.ts +22 -0
  707. package/runtime/src/snapshot/worklet/destroy.ts +14 -0
  708. package/runtime/src/snapshot/worklet/functionality.ts +22 -0
  709. package/runtime/src/snapshot/worklet/hmr.ts +34 -0
  710. package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +30 -0
  711. package/runtime/src/utils.ts +134 -0
  712. package/runtime/src/worklet-runtime/api/animation/animation.ts +48 -0
  713. package/runtime/src/worklet-runtime/api/animation/effect.ts +20 -0
  714. package/runtime/src/worklet-runtime/api/element.ts +152 -0
  715. package/runtime/src/worklet-runtime/api/lepusQuerySelector.ts +34 -0
  716. package/runtime/src/worklet-runtime/api/lynxApi.ts +42 -0
  717. package/runtime/src/worklet-runtime/bindings/bindings.ts +91 -0
  718. package/runtime/src/worklet-runtime/bindings/events.ts +29 -0
  719. package/runtime/src/worklet-runtime/bindings/index.ts +12 -0
  720. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
  721. package/runtime/src/worklet-runtime/bindings/observers.ts +61 -0
  722. package/runtime/src/worklet-runtime/bindings/types.ts +84 -0
  723. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +51 -0
  724. package/runtime/src/worklet-runtime/delayWorkletEvent.ts +70 -0
  725. package/runtime/src/worklet-runtime/eomImpl.ts +14 -0
  726. package/runtime/src/worklet-runtime/eventPropagation.ts +56 -0
  727. package/runtime/src/worklet-runtime/global.ts +28 -0
  728. package/runtime/src/worklet-runtime/hydrate.ts +113 -0
  729. package/runtime/src/worklet-runtime/index.ts +12 -0
  730. package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +69 -0
  731. package/runtime/src/worklet-runtime/listeners.ts +28 -0
  732. package/runtime/src/worklet-runtime/runOnMainThread.ts +21 -0
  733. package/runtime/src/worklet-runtime/types/dev.d.ts +4 -0
  734. package/runtime/src/worklet-runtime/types/elementApi.d.ts +97 -0
  735. package/runtime/src/worklet-runtime/types/runtimeProxy.d.ts +32 -0
  736. package/runtime/src/worklet-runtime/types/systeminfo.d.ts +19 -0
  737. package/runtime/src/worklet-runtime/utils/mainThreadFlushLoopGuard.ts +87 -0
  738. package/runtime/src/worklet-runtime/utils/profile.ts +20 -0
  739. package/runtime/src/worklet-runtime/utils/version.ts +11 -0
  740. package/runtime/src/worklet-runtime/workletRef.ts +119 -0
  741. package/runtime/src/worklet-runtime/workletRuntime.ts +215 -0
  742. package/runtime/tsconfig.json +30 -0
  743. package/runtime/turbo.json +21 -0
  744. package/runtime/types/internal-preact.d.ts +67 -0
  745. package/runtime/types/types.d.ts +339 -0
  746. package/runtime/vitest.config.ts +181 -0
  747. package/testing-library/.npmignore +6 -0
  748. package/testing-library/.turbo/turbo-build.log +28 -0
  749. package/testing-library/README.md +109 -0
  750. package/testing-library/dist/index.d.ts +1 -1
  751. package/testing-library/dist/rstest-config.d.ts +15 -1
  752. package/testing-library/dist/rstest-config.js +38 -5
  753. package/testing-library/etc/react-lynx-testing-library.api.md +71 -0
  754. package/testing-library/loaders/jsx-loader.js +49 -0
  755. package/testing-library/node_modules/.bin/rsbuild +55 -0
  756. package/testing-library/node_modules/.bin/rspeedy +55 -0
  757. package/testing-library/node_modules/.bin/rstest +55 -0
  758. package/testing-library/package.json +28 -0
  759. package/testing-library/rslib.config.ts +97 -0
  760. package/testing-library/rstest.config.ts +44 -0
  761. package/testing-library/src/__tests__/3.1/text.test.jsx +109 -0
  762. package/testing-library/src/__tests__/act.test.jsx +348 -0
  763. package/testing-library/src/__tests__/alog.test.jsx +813 -0
  764. package/testing-library/src/__tests__/auto-cleanup-skip.test.jsx +25 -0
  765. package/testing-library/src/__tests__/auto-cleanup.test.jsx +12 -0
  766. package/testing-library/src/__tests__/background-only.test.jsx +45 -0
  767. package/testing-library/src/__tests__/button.test.jsx +25 -0
  768. package/testing-library/src/__tests__/cleanup.test.jsx +29 -0
  769. package/testing-library/src/__tests__/css/index.test.jsx +47 -0
  770. package/testing-library/src/__tests__/css/style1.css +3 -0
  771. package/testing-library/src/__tests__/css/style2.css +3 -0
  772. package/testing-library/src/__tests__/css/style3.module.css +3 -0
  773. package/testing-library/src/__tests__/dom-reuse.test.jsx +1515 -0
  774. package/testing-library/src/__tests__/end-to-end.test.jsx +212 -0
  775. package/testing-library/src/__tests__/events.test.jsx +368 -0
  776. package/testing-library/src/__tests__/lazy-bundle/LazyComponent.jsx +4 -0
  777. package/testing-library/src/__tests__/lazy-bundle/index.test.jsx +598 -0
  778. package/testing-library/src/__tests__/list.test.jsx +1015 -0
  779. package/testing-library/src/__tests__/lynx.test.jsx +85 -0
  780. package/testing-library/src/__tests__/portals.test.jsx +1303 -0
  781. package/testing-library/src/__tests__/preact-signals.test.jsx +190 -0
  782. package/testing-library/src/__tests__/raw-text.test.jsx +59 -0
  783. package/testing-library/src/__tests__/ref.test.jsx +573 -0
  784. package/testing-library/src/__tests__/remove-element.test.jsx +68 -0
  785. package/testing-library/src/__tests__/render.test.jsx +296 -0
  786. package/testing-library/src/__tests__/renderComponent.test.jsx +344 -0
  787. package/testing-library/src/__tests__/renderHook.test.jsx +61 -0
  788. package/testing-library/src/__tests__/rerender.test.jsx +62 -0
  789. package/testing-library/src/__tests__/rstest-config.test.js +31 -0
  790. package/testing-library/src/__tests__/slot-jsx.test.jsx +965 -0
  791. package/testing-library/src/__tests__/spread.test.jsx +212 -0
  792. package/testing-library/src/__tests__/stopwatch.test.jsx +80 -0
  793. package/testing-library/src/__tests__/text.test.jsx +130 -0
  794. package/testing-library/src/__tests__/worklet.test.jsx +618 -0
  795. package/testing-library/src/entry.ts +2 -0
  796. package/testing-library/src/env/index.ts +2 -0
  797. package/testing-library/src/env/rstest.ts +7 -0
  798. package/testing-library/src/env/vitest.ts +27 -0
  799. package/testing-library/src/fire-event.ts +199 -0
  800. package/testing-library/src/index.jsx +25 -0
  801. package/testing-library/src/plugins/index.ts +2 -0
  802. package/testing-library/src/plugins/vitest.ts +387 -0
  803. package/testing-library/src/pure.jsx +159 -0
  804. package/testing-library/src/rstest-config.ts +173 -0
  805. package/testing-library/src/setupFiles/common/bootstrap.js +6 -0
  806. package/testing-library/src/setupFiles/common/runtime-setup.js +142 -0
  807. package/testing-library/src/setupFiles/inner/rstest.js +13 -0
  808. package/testing-library/src/setupFiles/inner/vitest.js +17 -0
  809. package/testing-library/src/setupFiles/rstest.js +30 -0
  810. package/testing-library/src/setupFiles/vitest.js +29 -0
  811. package/testing-library/src/vitest.config.ts +14 -0
  812. package/testing-library/tsconfig.json +16 -0
  813. package/testing-library/turbo.json +21 -0
  814. package/testing-library/types/entry.d.ts +1 -1
  815. package/testing-library/vitest-polyfill.cjs +6 -0
  816. package/testing-library/vitest.3.1.config.ts +17 -0
  817. package/testing-library/vitest.config.ts +14 -0
  818. package/transform/.cargo/config.toml +2 -0
  819. package/transform/.gitignore +6 -0
  820. package/transform/.npmignore +8 -0
  821. package/transform/.turbo/turbo-build$colon$wasm.log +252 -0
  822. package/transform/Cargo.toml +45 -0
  823. package/transform/__test__/background-only.spec.js +222 -0
  824. package/transform/__test__/basic.bench.js +80 -0
  825. package/transform/__test__/css/__snapshots__/transform-all-css-scoped-all.js +18 -0
  826. package/transform/__test__/css/__snapshots__/transform-all-css-scoped-modules.js +18 -0
  827. package/transform/__test__/css/__snapshots__/transform-all-css-scoped-none.js +18 -0
  828. package/transform/__test__/css/__snapshots__/transform-imports-css-scoped-all.js +24 -0
  829. package/transform/__test__/css/__snapshots__/transform-imports-css-scoped-modules.js +24 -0
  830. package/transform/__test__/css/__snapshots__/transform-imports-css-scoped-none.js +24 -0
  831. package/transform/__test__/css/__snapshots__/transform-imports-defaults.js +5 -0
  832. package/transform/__test__/css/__snapshots__/transform-imports-without-jsx-css-scoped-all.js +5 -0
  833. package/transform/__test__/css/__snapshots__/transform-imports-without-jsx-css-scoped-modules.js +5 -0
  834. package/transform/__test__/css/__snapshots__/transform-imports-without-jsx-css-scoped-none.js +5 -0
  835. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-all-lazy-bundle.js +50 -0
  836. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-all.js +50 -0
  837. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-modules-lazy-bundle.js +50 -0
  838. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-modules.js +50 -0
  839. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-none-lazy-bundle.js +50 -0
  840. package/transform/__test__/css/__snapshots__/transform-jsx-css-scoped-none.js +50 -0
  841. package/transform/__test__/css/__snapshots__/transform-jsx-defaults.js +50 -0
  842. package/transform/__test__/css/css-scope.spec.js +209 -0
  843. package/transform/__test__/css/inline-style.spec.js +53 -0
  844. package/transform/__test__/css/object-lit-style.spec.js +293 -0
  845. package/transform/__test__/defines.spec.js +321 -0
  846. package/transform/__test__/fixture.spec.js +2496 -0
  847. package/transform/__test__/typescript.spec.js +97 -0
  848. package/transform/build.rs +11 -0
  849. package/transform/crates/swc_plugin_background_only/Cargo.toml +13 -0
  850. package/transform/crates/swc_plugin_background_only/lib.rs +326 -0
  851. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/defaults_to_null_without_fallback.js +5 -0
  852. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/desugars_nested_background_only.js +5 -0
  853. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/desugars_to_thread_conditional_in_child_position.js +8 -0
  854. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/desugars_to_thread_conditional_in_expression_position.js +3 -0
  855. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/keeps_the_fragment_for_a_lone_text_child.js +3 -0
  856. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/renders_nothing_for_empty_children.js +5 -0
  857. package/transform/crates/swc_plugin_background_only/tests/__swc_snapshots__/lib.rs/unwraps_a_lone_child_past_layout_and_comments.js +3 -0
  858. package/transform/crates/swc_plugin_compat/Cargo.toml +24 -0
  859. package/transform/crates/swc_plugin_compat/is_component_class.rs +51 -0
  860. package/transform/crates/swc_plugin_compat/lib.rs +1885 -0
  861. package/transform/crates/swc_plugin_compat/napi.rs +526 -0
  862. package/transform/crates/swc_plugin_compat/simplify_ctor_like_react_lynx_2.rs +172 -0
  863. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_add_component_element.js +17 -0
  864. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_add_component_element_compiler_only.js +16 -0
  865. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_add_component_element_embedded.js +2 -0
  866. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_add_component_element_embedded_compiler_only.js +1 -0
  867. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_add_component_is_import.js +3 -0
  868. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_change_runtime_pkg.js +1 -0
  869. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_handle_recursive.js +4 -0
  870. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_left_no_remove_component_element_attr.js +1 -0
  871. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_not_handle_jsx_member_expression.js +1 -0
  872. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_not_rename_view_in_scope.js +6 -0
  873. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_not_rename_view_redeclaration.js +4 -0
  874. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_not_transform_event_props_when_disabled.js +1 -0
  875. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_remove_component_attr_regex.js +8 -0
  876. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_rename_view.js +1 -0
  877. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_simplify_ctor.js +9 -0
  878. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_simplify_ctor_correct_order.js +10 -0
  879. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_simplify_ctor_not_remain_local_decls.js +9 -0
  880. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_simplify_ctor_not_remain_local_decls_with_macro.js +19 -0
  881. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_simplify_ctor_not_remain_local_decls_with_spread.js +12 -0
  882. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_transform_event_props_1.js +1 -0
  883. package/transform/crates/swc_plugin_compat/tests/__swc_snapshots__/lib.rs/should_transform_event_props_2.js +1 -0
  884. package/transform/crates/swc_plugin_css_scope/Cargo.toml +18 -0
  885. package/transform/crates/swc_plugin_css_scope/lib.rs +327 -0
  886. package/transform/crates/swc_plugin_css_scope/napi.rs +144 -0
  887. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_all_transform_imports.js +5 -0
  888. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_all_transform_imports_without_jsx.js +4 -0
  889. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_modules_transform_imports.js +5 -0
  890. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_modules_transform_imports_without_jsx.js +4 -0
  891. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_none_transform_imports.js +5 -0
  892. package/transform/crates/swc_plugin_css_scope/tests/__swc_snapshots__/lib.rs/scoped_none_transform_imports_without_jsx.js +4 -0
  893. package/transform/crates/swc_plugin_define_dce/Cargo.toml +15 -0
  894. package/transform/crates/swc_plugin_define_dce/lib.rs +21 -0
  895. package/transform/crates/swc_plugin_define_dce/napi.rs +79 -0
  896. package/transform/crates/swc_plugin_directive_dce/Cargo.toml +18 -0
  897. package/transform/crates/swc_plugin_directive_dce/lib.rs +489 -0
  898. package/transform/crates/swc_plugin_directive_dce/napi.rs +65 -0
  899. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_do_nothing_in_mixed_target.js +6 -0
  900. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_do_nothing_when_arrow_function_return_directive.js +1 -0
  901. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_async_arrow_with_background_only_directive.js +1 -0
  902. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_background_only_generator_forms.js +7 -0
  903. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_fn_body_in_component_props.js +1 -0
  904. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_fn_decl.js +1 -0
  905. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_js_only_but_keep_constructor.js +6 -0
  906. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_js_only_class_method.js +4 -0
  907. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_js_only_class_property.js +4 -0
  908. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_js_only_embedded.js +5 -0
  909. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_native_modules_in_default_params.js +1 -0
  910. package/transform/crates/swc_plugin_directive_dce/tests/__swc_snapshots__/lib.rs/should_eliminate_transpiled_async_arrow_with_background_only_generator.js +1 -0
  911. package/transform/crates/swc_plugin_dynamic_import/Cargo.toml +18 -0
  912. package/transform/crates/swc_plugin_dynamic_import/lib.rs +408 -0
  913. package/transform/crates/swc_plugin_dynamic_import/napi.rs +89 -0
  914. package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_import_lazy_bundle.js +4 -0
  915. package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_import_lazy_import.js +9 -0
  916. package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_not_import_lazy.js +3 -0
  917. package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_transform_import_call.js +61 -0
  918. package/transform/crates/swc_plugin_element_template/Cargo.toml +29 -0
  919. package/transform/crates/swc_plugin_element_template/asset.rs +64 -0
  920. package/transform/crates/swc_plugin_element_template/attr_name.rs +77 -0
  921. package/transform/crates/swc_plugin_element_template/extractor.rs +484 -0
  922. package/transform/crates/swc_plugin_element_template/lib.rs +734 -0
  923. package/transform/crates/swc_plugin_element_template/lowering.rs +125 -0
  924. package/transform/crates/swc_plugin_element_template/napi.rs +168 -0
  925. package/transform/crates/swc_plugin_element_template/template_attribute.rs +31 -0
  926. package/transform/crates/swc_plugin_element_template/template_definition.rs +375 -0
  927. package/transform/crates/swc_plugin_element_template/template_identity.rs +160 -0
  928. package/transform/crates/swc_plugin_element_template/template_slot.rs +81 -0
  929. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_generate_attribute_slots_for_dynamic_attributes.snap +81 -0
  930. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_background_conditional_attributes.snap +44 -0
  931. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_boolean_and_number_attributes.snap +62 -0
  932. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_complex_text_structure.snap +120 -0
  933. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dataset_attributes.snap +62 -0
  934. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_deeply_nested_user_components.snap +54 -0
  935. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dynamic_class_attributes.snap +57 -0
  936. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_events_js.snap +57 -0
  937. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_events_lepus.snap +57 -0
  938. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_id_attributes.snap +57 -0
  939. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_inline_styles.snap +82 -0
  940. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_interpolated_text_with_siblings_js.snap +85 -0
  941. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_interpolated_text_with_siblings_lepus.snap +85 -0
  942. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_mixed_content.snap +82 -0
  943. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_nested_structure_and_dynamic_content.snap +143 -0
  944. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_refs_js.snap +52 -0
  945. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_refs_lepus.snap +52 -0
  946. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_sibling_user_components.snap +69 -0
  947. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_spread_attributes.snap +56 -0
  948. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_user_component.snap +54 -0
  949. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_isolate_arrays_with_child_slot_placeholder.snap +56 -0
  950. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_keep_code_and_template_attribute_slots_in_sync_for_spread.snap +66 -0
  951. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_element_template_simple_lepus.snap +52 -0
  952. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_template_with_static_attributes.snap +62 -0
  953. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_template_structure_complex.snap +69 -0
  954. package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_text_attribute_and_child_text_slots.snap +70 -0
  955. package/transform/crates/swc_plugin_element_template/tests/element_template.rs +1207 -0
  956. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +930 -0
  957. package/transform/crates/swc_plugin_inject/Cargo.toml +18 -0
  958. package/transform/crates/swc_plugin_inject/lib.rs +344 -0
  959. package/transform/crates/swc_plugin_inject/napi.rs +150 -0
  960. package/transform/crates/swc_plugin_inject/tests/__swc_snapshots__/lib.rs/should_inject.js +8 -0
  961. package/transform/crates/swc_plugin_inject/tests/__swc_snapshots__/lib.rs/should_inject_callee.js +1 -0
  962. package/transform/crates/swc_plugin_list/Cargo.toml +15 -0
  963. package/transform/crates/swc_plugin_list/legacy_slot.rs +410 -0
  964. package/transform/crates/swc_plugin_list/lib.rs +631 -0
  965. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/basic_list_legacy_slot.js +61 -0
  966. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/basic_list_toplevel_legacy_slot.js +40 -0
  967. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/basic_list_with_fragment_legacy_slot.js +65 -0
  968. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/should_transform_list_in_view_legacy_slot.js +6 -0
  969. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/should_transform_list_in_view_with_snapshot_legacy_slot.js +49 -0
  970. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/should_transform_list_item_deferred_in_list_legacy_slot.js +5 -0
  971. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/legacy_slot.rs/should_transform_list_item_deferred_with_children_with_snapshot_legacy_slot.js +95 -0
  972. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/basic_list.js +53 -0
  973. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/basic_list_toplevel.js +40 -0
  974. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/basic_list_with_fragment.js +57 -0
  975. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_not_transform_list_item_with_defer_false.js +1 -0
  976. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view.js +6 -0
  977. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view_with_snapshot.js +54 -0
  978. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view_with_static_sibling.js +7 -0
  979. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view_with_static_sibling_nested.js +16 -0
  980. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view_with_static_sibling_with_snapshot.js +65 -0
  981. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_in_view_with_static_sibling_with_snapshot_nested.js +138 -0
  982. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_deferred_basic.js +2 -0
  983. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_deferred_in_list.js +5 -0
  984. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_deferred_with_children.js +6 -0
  985. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_deferred_with_children_with_snapshot.js +95 -0
  986. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_not_deferred.js +1 -0
  987. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_when_defer_is_expr.js +4 -0
  988. package/transform/crates/swc_plugin_list/tests/__swc_snapshots__/lib.rs/should_transform_list_item_with_spread_deferred.js +2 -0
  989. package/transform/crates/swc_plugin_shake/Cargo.toml +20 -0
  990. package/transform/crates/swc_plugin_shake/is_component_class.rs +66 -0
  991. package/transform/crates/swc_plugin_shake/lib.rs +908 -0
  992. package/transform/crates/swc_plugin_shake/napi.rs +220 -0
  993. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/only_shake_class_like_react_component_class.js +10 -0
  994. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_access_inside_class_property_iife.js +11 -0
  995. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_constructor_and_used.js +12 -0
  996. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_indirect.js +12 -0
  997. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_render_and_used.js +11 -0
  998. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_state_and_remove_other.js +8 -0
  999. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_use_effect_call_from_custom_runtime.js +6 -0
  1000. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_with_nested_class.js +11 -0
  1001. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_not_remove_call_in_scope_id.js +5 -0
  1002. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_not_remove_in_scope_id.js +5 -0
  1003. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_not_remove_test_with_other_runtime.js +3 -0
  1004. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_call.js +4 -0
  1005. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_call_by_local_name.js +4 -0
  1006. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_param.js +4 -0
  1007. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_param_by_local_name.js +4 -0
  1008. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_calls.js +6 -0
  1009. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_params.js +6 -0
  1010. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_test.js +5 -0
  1011. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_unused_indirect.js +5 -0
  1012. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_use_effect_call.js +8 -0
  1013. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_use_effect_param.js +8 -0
  1014. package/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_replace_use_effect_call_with_undefined.js +2 -0
  1015. package/transform/crates/swc_plugin_snapshot/Cargo.toml +25 -0
  1016. package/transform/crates/swc_plugin_snapshot/attr_name.rs +84 -0
  1017. package/transform/crates/swc_plugin_snapshot/legacy_slot.rs +2201 -0
  1018. package/transform/crates/swc_plugin_snapshot/lib.rs +3495 -0
  1019. package/transform/crates/swc_plugin_snapshot/napi.rs +184 -0
  1020. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_component_legacy_slot.js +10 -0
  1021. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_component_with_static_sibling_jsx_dev_legacy_slot.js +35 -0
  1022. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_component_with_static_sibling_jsx_legacy_slot.js +27 -0
  1023. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_component_with_static_sibling_legacy_slot.js +24 -0
  1024. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_expr_container_legacy_slot.js +10 -0
  1025. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_expr_container_with_static_sibling_legacy_slot.js +24 -0
  1026. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/basic_spread_list_item_legacy_slot.js +42 -0
  1027. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/full_static_children_map_jsx_legacy_slot.js +44 -0
  1028. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/page_component_legacy_slot.js +15 -0
  1029. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/page_element_dev_legacy_slot.js +16 -0
  1030. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/page_element_legacy_slot.js +16 -0
  1031. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_create_raw_text_node_for_text_node_legacy_slot.js +55 -0
  1032. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_emit_list_item_platform_info_marker_for_spread_props_legacy_slot.js +32 -0
  1033. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_inject_implicit_flatten_legacy_slot.js +67 -0
  1034. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_not_wrap_dynamic_part.js +29 -0
  1035. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_wrap_dynamic_key_legacy_slot.js +54 -0
  1036. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/legacy_slot.rs/should_wrap_dynamic_part.js +34 -0
  1037. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_component.js +10 -0
  1038. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_component_with_static_sibling.js +24 -0
  1039. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_component_with_static_sibling_jsx.js +27 -0
  1040. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_component_with_static_sibling_jsx_dev.js +35 -0
  1041. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_event.js +26 -0
  1042. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_expr_container.js +10 -0
  1043. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_expr_container_with_static_sibling.js +24 -0
  1044. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_full_static.js +25 -0
  1045. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_full_static_snapshot_extract.js +16 -0
  1046. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_full_static_snapshot_extract_it.js +21 -0
  1047. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_ref.js +45 -0
  1048. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_spread.js +30 -0
  1049. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_spread_list_item.js +30 -0
  1050. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/basic_timing_flag.js +31 -0
  1051. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/empty_module.js +1 -0
  1052. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/external_bundle_uses_card_entry_name.js +16 -0
  1053. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/full_static_children_comments.js +19 -0
  1054. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/full_static_children_map_jsx.js +28 -0
  1055. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/full_static_children_new_line.js +25 -0
  1056. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/full_static_children_self_close.js +25 -0
  1057. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/gesture.js +26 -0
  1058. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/inline_style_literal.js +11 -0
  1059. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/inline_style_literal_unknown_property.js +11 -0
  1060. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/mode_development_spread.js +24 -0
  1061. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/page_component.js +15 -0
  1062. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/page_element.js +16 -0
  1063. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/page_element_dev.js +16 -0
  1064. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_create_raw_text_node_for_text_node.js +47 -0
  1065. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_emit_list_item_platform_info_marker_for_non_zero_value_index.js +25 -0
  1066. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_emit_list_item_platform_info_marker_for_spread_props.js +22 -0
  1067. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_escape_newline_character.js +55 -0
  1068. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_extract_css_id.js +71 -0
  1069. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_extract_css_id_dynamic_component.js +71 -0
  1070. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_extract_css_id_dynamic_component_without_css_id.js +69 -0
  1071. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_extract_css_id_without_css_id.js +69 -0
  1072. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_inject_implicit_flatten.js +59 -0
  1073. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_set_attribute_for_text_node.js +44 -0
  1074. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_static_extract_dynamic_inline_style.js +69 -0
  1075. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_static_extract_inline_style.js +21 -0
  1076. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_wrap_dynamic_key.js +46 -0
  1077. package/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/worklet.js +35 -0
  1078. package/transform/crates/swc_plugin_text/Cargo.toml +14 -0
  1079. package/transform/crates/swc_plugin_text/lib.rs +93 -0
  1080. package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_keep_children_for_dynamic_or_multiple_text.js +9 -0
  1081. package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_transform_single_static_text_to_text_attr.js +8 -0
  1082. package/transform/crates/swc_plugin_worklet/Cargo.toml +24 -0
  1083. package/transform/crates/swc_plugin_worklet/decl_collect.rs +226 -0
  1084. package/transform/crates/swc_plugin_worklet/extract_ident.rs +460 -0
  1085. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +326 -0
  1086. package/transform/crates/swc_plugin_worklet/globals.rs +104 -0
  1087. package/transform/crates/swc_plugin_worklet/hash.rs +29 -0
  1088. package/transform/crates/swc_plugin_worklet/lib.rs +2869 -0
  1089. package/transform/crates/swc_plugin_worklet/napi.rs +116 -0
  1090. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/class_in_worklet_1.js +3 -0
  1091. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_inner_ident.js +13 -0
  1092. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_outer_ident.js +13 -0
  1093. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +12 -0
  1094. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +35 -0
  1095. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_js.js +6 -0
  1096. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_lepus.js +15 -0
  1097. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_idents_outside_of_ctx.js +9 -0
  1098. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +29 -0
  1099. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +54 -0
  1100. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_js.js +12 -0
  1101. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_lepus.js +89 -0
  1102. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_js.js +3 -0
  1103. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_lepus.js +13 -0
  1104. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +23 -0
  1105. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +46 -0
  1106. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_handle_renamed_import_shadowing_js.js +16 -0
  1107. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_globals.js +15 -0
  1108. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_type_annotations.js +22 -0
  1109. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_destructure_from_closure.js +12 -0
  1110. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_catch_clause_params.js +17 -0
  1111. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_ident_from_this.js +9 -0
  1112. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_idents_inside_of_ctx.js +24 -0
  1113. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_constructor.js +7 -0
  1114. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_getter_and_setter.js +13 -0
  1115. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_recursively.js +23 -0
  1116. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_when_wrong_directives.js +14 -0
  1117. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_default_import_js.js +12 -0
  1118. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js +12 -0
  1119. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js +23 -0
  1120. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_namespace_import_js.js +12 -0
  1121. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_string_key_js.js +12 -0
  1122. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_arrow_function.js +15 -0
  1123. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_js.js +6 -0
  1124. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_lepus.js +16 -0
  1125. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_function_expr.js +15 -0
  1126. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_js.js +11 -0
  1127. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_js_capture_values.js +11 -0
  1128. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_lepus.js +17 -0
  1129. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_js.js +14 -0
  1130. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_js_capture_values.js +11 -0
  1131. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_lepus.js +21 -0
  1132. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_js.js +9 -0
  1133. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_lepus.js +18 -0
  1134. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_js.js +9 -0
  1135. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_lepus.js +17 -0
  1136. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +15 -0
  1137. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_js.js +10 -0
  1138. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_lepus.js +25 -0
  1139. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_general.js +9 -0
  1140. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +34 -0
  1141. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_alias.js +20 -0
  1142. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general.js +20 -0
  1143. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general_mixed.js +20 -0
  1144. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets.js +29 -0
  1145. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets_in_func.js +31 -0
  1146. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_js.js +6 -0
  1147. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_lepus.js +15 -0
  1148. package/transform/crates/swc_plugin_worklet/worklet_type.rs +24 -0
  1149. package/transform/crates/swc_plugins_shared/Cargo.toml +27 -0
  1150. package/transform/crates/swc_plugins_shared/css.rs +64 -0
  1151. package/transform/crates/swc_plugins_shared/defines.rs +51 -0
  1152. package/transform/crates/swc_plugins_shared/engine_version.rs +50 -0
  1153. package/transform/crates/swc_plugins_shared/jsx_helpers.rs +451 -0
  1154. package/transform/crates/swc_plugins_shared/lib.rs +12 -0
  1155. package/transform/crates/swc_plugins_shared/lynx_event.rs +159 -0
  1156. package/transform/crates/swc_plugins_shared/target.rs +66 -0
  1157. package/transform/crates/swc_plugins_shared/target_napi.rs +69 -0
  1158. package/transform/crates/swc_plugins_shared/transform_mode.rs +61 -0
  1159. package/transform/crates/swc_plugins_shared/transform_mode_napi.rs +72 -0
  1160. package/transform/crates/swc_plugins_shared/utils.rs +149 -0
  1161. package/transform/dist/wasm.cjs +1 -1
  1162. package/transform/node_modules/.bin/esbuild +46 -0
  1163. package/transform/node_modules/.bin/napi +55 -0
  1164. package/transform/package.json +42 -0
  1165. package/transform/rspack-napi/lib/index.d.ts +32 -0
  1166. package/transform/rspack-napi/lib/index.js +96 -0
  1167. package/transform/rspack-napi/lib/index.js.map +1 -0
  1168. package/transform/rspack-napi/package.json +25 -0
  1169. package/transform/rspack-napi/src/index.ts +161 -0
  1170. package/transform/rspack-napi/tsconfig.json +17 -0
  1171. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -0
  1172. package/transform/scripts/build_wasm.js +55 -0
  1173. package/transform/src/bundle.rs +249 -0
  1174. package/transform/src/esbuild.rs +201 -0
  1175. package/transform/src/lib.rs +1197 -0
  1176. package/transform/src/swc_plugin_compat_post/mod.rs +143 -0
  1177. package/transform/src/swc_plugin_extract_str/mod.rs +382 -0
  1178. package/transform/src/swc_plugin_refresh/mod.rs +546 -0
  1179. package/transform/src/swc_plugin_transform_builtin_attribute_names/mod.rs +286 -0
  1180. package/transform/src/swc_plugin_worklet_post_process/mod.rs +100 -0
  1181. package/transform/src/wasm.js +39 -0
  1182. package/transform/swc-plugin-reactlynx/.cargo/config.toml +9 -0
  1183. package/transform/swc-plugin-reactlynx/.gitignore +2 -0
  1184. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +346 -0
  1185. package/transform/swc-plugin-reactlynx/Cargo.toml +30 -0
  1186. package/transform/swc-plugin-reactlynx/build.js +27 -0
  1187. package/transform/swc-plugin-reactlynx/index.d.ts +273 -0
  1188. package/transform/swc-plugin-reactlynx/package.json +22 -0
  1189. package/transform/swc-plugin-reactlynx/src/lib.rs +606 -0
  1190. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  1191. package/transform/swc-plugin-reactlynx/turbo.json +18 -0
  1192. package/transform/swc-plugin-reactlynx-compat/.cargo/config.toml +9 -0
  1193. package/transform/swc-plugin-reactlynx-compat/.gitignore +2 -0
  1194. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +256 -0
  1195. package/transform/swc-plugin-reactlynx-compat/Cargo.toml +17 -0
  1196. package/transform/swc-plugin-reactlynx-compat/build.js +27 -0
  1197. package/transform/swc-plugin-reactlynx-compat/index.d.ts +326 -0
  1198. package/transform/swc-plugin-reactlynx-compat/package.json +22 -0
  1199. package/transform/swc-plugin-reactlynx-compat/src/lib.rs +15 -0
  1200. package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
  1201. package/transform/swc-plugin-reactlynx-compat/turbo.json +18 -0
  1202. package/transform/tests/__swc_snapshots__/src/swc_plugin_compat_post/mod.rs/should_compat_dark_mode.js +3 -0
  1203. package/transform/tests/__swc_snapshots__/src/swc_plugin_compat_post/mod.rs/should_compat_dark_mode_custom_theme_expr.js +3 -0
  1204. package/transform/tests/__swc_snapshots__/src/swc_plugin_extract_str/mod.rs/should_extract_str.js +21 -0
  1205. package/transform/tests/__swc_snapshots__/src/swc_plugin_extract_str/mod.rs/should_extract_str_with_arr.js +20 -0
  1206. package/transform/tests/__swc_snapshots__/src/swc_plugin_extract_str/mod.rs/should_extract_tpl_str.js +9 -0
  1207. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_basic.js +4 -0
  1208. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_custom_library.js +4 -0
  1209. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_function_parameter.js +4 -0
  1210. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_import_computed.js +4 -0
  1211. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_import_default.js +4 -0
  1212. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_import_named_computed.js +4 -0
  1213. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_import_namespace_computed.js +4 -0
  1214. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_init_value.js +10 -0
  1215. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_local_ident.js +8 -0
  1216. package/transform/tests/__swc_snapshots__/src/swc_plugin_refresh/mod.rs/should_handle_multiple_index.js +21 -0
  1217. package/transform/tests/__swc_snapshots__/src/swc_plugin_worklet_post_process/mod.rs/should_transform_worklet.js +12 -0
  1218. package/transform/tests/__swc_snapshots__/src/swc_plugin_worklet_post_process/mod.rs/should_transform_worklet_2.js +14 -0
  1219. package/transform/turbo.json +38 -0
  1220. package/transform/vitest.config.ts +19 -0
@@ -0,0 +1,3704 @@
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
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6
+
7
+ import { getReloadVersion, increaseReloadVersion } from '../../../../src/core/reload-version.js';
8
+ import type { BackgroundElementTemplateInstance } from '../../../../src/element-template/background/instance.js';
9
+ import { root } from '../../../../src/element-template/index.js';
10
+ import {
11
+ installElementTemplatePatchListener,
12
+ resetElementTemplatePatchListener,
13
+ } from '../../../../src/element-template/native/patch-listener.js';
14
+ import { ElementTemplateLifecycleConstant } from '../../../../src/element-template/protocol/lifecycle-constant.js';
15
+ import { ElementTemplateUpdateOps } from '../../../../src/element-template/protocol/opcodes.js';
16
+ import type {
17
+ ElementTemplateHydrateCommitContext,
18
+ ElementTemplateHandleSlotsCommand,
19
+ ElementTemplateUpdateCommandStream,
20
+ ElementTemplateUpdateCommitContext,
21
+ SerializedEtNode,
22
+ } from '../../../../src/element-template/protocol/types.js';
23
+ import {
24
+ createElementTemplateUpdateEvent,
25
+ parseElementTemplateUpdateEventPayload,
26
+ } from '../../../../src/element-template/protocol/update-event.js';
27
+ import { __page, setupPage } from '../../../../src/element-template/runtime/page/page.js';
28
+ import { __root } from '../../../../src/element-template/runtime/page/root-instance.js';
29
+ import { applyElementTemplateUpdateCommands } from '../../../../src/element-template/runtime/patch.js';
30
+ import {
31
+ composeElementTemplateListAttributes,
32
+ createElementTemplateListState,
33
+ markElementTemplateListDestroyed,
34
+ registerElementTemplateListItem,
35
+ registerElementTemplateListState,
36
+ removeElementTemplateListItem,
37
+ } from '../../../../src/element-template/runtime/list/list.js';
38
+ import {
39
+ attachMainThreadDynamicAttrRefsForSubtree,
40
+ clearMainThreadDynamicAttrState,
41
+ detachMainThreadDynamicAttrRefsForSubtree,
42
+ getMainThreadDynamicAttrState,
43
+ initializeMainThreadDynamicAttrSlots,
44
+ } from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
45
+ import {
46
+ __etAttrPlanMap,
47
+ adaptMTEventAttrSlot,
48
+ adaptMTRefAttrSlot,
49
+ clearEtAttrPlanMap,
50
+ } from '../../../../src/element-template/runtime/template/attr-slot-plan.js';
51
+ import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
52
+ import { ElementTemplateEnvManager } from '../../test-utils/debug/envManager.js';
53
+ import { registerBuiltinRawTextTemplate, registerTemplates } from '../../test-utils/debug/registry.js';
54
+ import { lastMock } from '../../test-utils/mock/mockNativePapi.js';
55
+ import { serializeToJSX } from '../../test-utils/debug/serializer.js';
56
+
57
+ declare const renderPage: () => void;
58
+
59
+ interface RootWithFirstChild {
60
+ firstChild: BackgroundElementTemplateInstance | null;
61
+ }
62
+ interface ReportErrorMock {
63
+ mock: { calls: unknown[][] };
64
+ mockClear: () => void;
65
+ }
66
+ interface LynxWithReportErrorMock {
67
+ reportError: ReportErrorMock;
68
+ }
69
+ interface PageWithChildren {
70
+ children?: Array<{ templateId?: string }>;
71
+ }
72
+
73
+ type HydrateEvent = { data: ElementTemplateHydrateCommitContext };
74
+ type HydrateInstances = SerializedEtNode[];
75
+
76
+ function createMockElementTemplateHandle(id: string, nativeId?: number): ElementTemplateHandle {
77
+ const handle = { __isNativeRef: true, id, __mockNativeId: nativeId };
78
+ return handle as unknown as ElementTemplateHandle;
79
+ }
80
+
81
+ function createRawTextOps(id: number, text: string) {
82
+ return [
83
+ ElementTemplateUpdateOps.createTemplate,
84
+ id,
85
+ '_et_builtin_raw_text',
86
+ null,
87
+ [text],
88
+ [],
89
+ ] as const;
90
+ }
91
+
92
+ function dispatchElementTemplateUpdate(payload: ElementTemplateUpdateCommitContext): void {
93
+ lynx.getCoreContext().dispatchEvent(createElementTemplateUpdateEvent(payload));
94
+ }
95
+
96
+ function resetReportedErrors(): void {
97
+ const lynxObj = globalThis.lynx as unknown as LynxWithReportErrorMock;
98
+ lynxObj.reportError.mockClear();
99
+ (globalThis as unknown as { __LYNX_REPORT_ERROR_CALLS: Error[] }).__LYNX_REPORT_ERROR_CALLS = [];
100
+ }
101
+
102
+ function createMaterializedListForFrontendTest(nativeId: number): FiberElement {
103
+ return {
104
+ __isNativeRef: true,
105
+ id: 'materialized-list',
106
+ __mockNativeId: nativeId,
107
+ } as unknown as FiberElement;
108
+ }
109
+
110
+ const MT_EVENT_TEMPLATE = '_et_mt_event';
111
+ const MT_REF_TEMPLATE = '_et_mt_ref';
112
+
113
+ function registerMTEventSlotsForTemplate(templateType: string, ...slotIndexes: number[]): void {
114
+ __etAttrPlanMap[templateType] = slotIndexes.flatMap(slotIndex => [
115
+ slotIndex,
116
+ adaptMTEventAttrSlot,
117
+ ]);
118
+ }
119
+
120
+ function registerMTEventSlots(...slotIndexes: number[]): void {
121
+ registerMTEventSlotsForTemplate(MT_EVENT_TEMPLATE, ...slotIndexes);
122
+ }
123
+
124
+ function registerMTRefSlotsForTemplate(templateType: string, ...slotIndexes: number[]): void {
125
+ __etAttrPlanMap[templateType] = slotIndexes.flatMap(slotIndex => [
126
+ slotIndex,
127
+ adaptMTRefAttrSlot,
128
+ ]);
129
+ }
130
+
131
+ function registerMTRefSlots(...slotIndexes: number[]): void {
132
+ registerMTRefSlotsForTemplate(MT_REF_TEMPLATE, ...slotIndexes);
133
+ }
134
+
135
+ function seedMTEventState(
136
+ handleId: number,
137
+ attrSlotIndex: number,
138
+ value: Record<string, unknown>,
139
+ ): void {
140
+ registerMTEventSlots(attrSlotIndex);
141
+ const attributeSlots: unknown[] = [];
142
+ attributeSlots[attrSlotIndex] = { type: 'worklet', value };
143
+ initializeMainThreadDynamicAttrSlots(handleId, MT_EVENT_TEMPLATE, attributeSlots);
144
+ }
145
+
146
+ function seedMTRefState(
147
+ handleId: number,
148
+ attrSlotIndex: number,
149
+ value: Record<string, unknown>,
150
+ nativeRef: ElementTemplateHandle,
151
+ ): void {
152
+ registerMTRefSlots(attrSlotIndex);
153
+ const attributeSlots: unknown[] = [];
154
+ attributeSlots[attrSlotIndex] = { type: 'main-thread-ref', value };
155
+ initializeMainThreadDynamicAttrSlots(handleId, MT_REF_TEMPLATE, attributeSlots);
156
+ attachMainThreadDynamicAttrRefsForSubtree([{ uid: handleId, ref: nativeRef }]);
157
+ }
158
+
159
+ function installWorkletRefRuntime(): {
160
+ updateWorkletRef: ReturnType<typeof vi.fn>;
161
+ restore: () => void;
162
+ } {
163
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
164
+ const updateWorkletRef = vi.fn();
165
+ globalThis.lynxWorkletImpl = {
166
+ ...previousWorkletImpl,
167
+ _refImpl: {
168
+ updateWorkletRef,
169
+ },
170
+ };
171
+ return {
172
+ updateWorkletRef,
173
+ restore: () => {
174
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
175
+ },
176
+ };
177
+ }
178
+
179
+ function createMainThreadRefImplMock(clearFirstScreenWorkletRefMap = vi.fn()) {
180
+ return { clearFirstScreenWorkletRefMap };
181
+ }
182
+
183
+ describe('ElementTemplate patch stream (apply)', () => {
184
+ const envManager = new ElementTemplateEnvManager();
185
+ let hydrationData: HydrateInstances = [];
186
+
187
+ let onHydrate: (event: HydrateEvent) => void;
188
+ let mockCreateElementTemplate: ReportErrorMock;
189
+ let mockCreateTypedElementTemplate: ReportErrorMock;
190
+ let mockSetAttribute: ReportErrorMock;
191
+ let mockSetElementTemplateAttributeSlot: ReportErrorMock;
192
+ let mockInsertElementTemplateNodeIntoSlot: ReportErrorMock;
193
+ let mockRemoveElementTemplateNodeFromSlot: ReportErrorMock;
194
+ let mockFlushElementTree: ReportErrorMock;
195
+
196
+ beforeEach(() => {
197
+ vi.clearAllMocks();
198
+ // mocks are already installed by setup.js beforeEach
199
+ mockCreateElementTemplate = lastMock!.mockCreateCompiledElementTemplate as unknown as ReportErrorMock;
200
+ mockCreateTypedElementTemplate = lastMock!.mockCreateTypedElementTemplate as unknown as ReportErrorMock;
201
+ mockSetAttribute = lastMock!.mockSetAttribute as unknown as ReportErrorMock;
202
+ mockSetElementTemplateAttributeSlot = lastMock!.mockSetElementTemplateAttributeSlot as unknown as ReportErrorMock;
203
+ mockInsertElementTemplateNodeIntoSlot = lastMock!
204
+ .mockInsertElementTemplateNodeIntoSlot as unknown as ReportErrorMock;
205
+ mockRemoveElementTemplateNodeFromSlot = lastMock!
206
+ .mockRemoveElementTemplateNodeFromSlot as unknown as ReportErrorMock;
207
+ mockFlushElementTree = lastMock!.mockFlushElementTree as unknown as ReportErrorMock;
208
+ registerBuiltinRawTextTemplate();
209
+ clearMainThreadDynamicAttrState();
210
+ clearEtAttrPlanMap();
211
+
212
+ hydrationData = [];
213
+ envManager.resetEnv('background');
214
+ envManager.setUseElementTemplate(true);
215
+
216
+ onHydrate = vi.fn().mockImplementation((event: HydrateEvent) => {
217
+ hydrationData.push(...(event.data.page.childSlots?.[0] ?? []));
218
+ });
219
+ lynx.getCoreContext().addEventListener(ElementTemplateLifecycleConstant.hydrate, onHydrate);
220
+ });
221
+
222
+ afterEach(() => {
223
+ envManager.switchToBackground();
224
+ lynx.getCoreContext().removeEventListener(ElementTemplateLifecycleConstant.hydrate, onHydrate);
225
+
226
+ envManager.switchToMainThread();
227
+ resetElementTemplatePatchListener();
228
+
229
+ envManager.setUseElementTemplate(false);
230
+ });
231
+
232
+ function renderAndCollect(App: () => JSX.Element) {
233
+ const jsx = <App />;
234
+ root.render(jsx);
235
+ envManager.switchToMainThread();
236
+ root.render(jsx);
237
+ renderPage();
238
+ envManager.switchToBackground();
239
+
240
+ const before = hydrationData[0]!;
241
+ const backgroundRoot = __root as unknown as RootWithFirstChild;
242
+ const after = backgroundRoot.firstChild;
243
+ if (!after) {
244
+ throw new Error('Missing background root child');
245
+ }
246
+
247
+ return { before, after };
248
+ }
249
+
250
+ it('reports missing reference handle without mutating the page', () => {
251
+ function App() {
252
+ return (
253
+ <view>
254
+ <view key='a' id='a' />
255
+ <view key='b' id='b' />
256
+ </view>
257
+ );
258
+ }
259
+
260
+ const { before } = renderAndCollect(App);
261
+ envManager.switchToMainThread();
262
+
263
+ const beforeJSX = serializeToJSX(__page);
264
+ applyElementTemplateUpdateCommands([
265
+ ElementTemplateUpdateOps.insertNode,
266
+ before.uid,
267
+ 9999,
268
+ before.uid,
269
+ 9999,
270
+ [],
271
+ ]);
272
+
273
+ expect(serializeToJSX(__page)).toBe(beforeJSX);
274
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
275
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
276
+ 'reference handle 9999 not found',
277
+ );
278
+ resetReportedErrors();
279
+ });
280
+
281
+ it('resolves page target id 0 and uses the generic attr and root patch paths', () => {
282
+ envManager.switchToMainThread();
283
+ const pageRef = createMockElementTemplateHandle('page');
284
+ const childRef = createMockElementTemplateHandle('root');
285
+ setupPage(pageRef);
286
+ elementTemplateRegistry.set(10, childRef);
287
+
288
+ applyElementTemplateUpdateCommands([
289
+ ElementTemplateUpdateOps.setAttribute,
290
+ 0,
291
+ 0,
292
+ { id: 'background' },
293
+ ElementTemplateUpdateOps.insertNode,
294
+ 0,
295
+ 0,
296
+ 10,
297
+ 0,
298
+ [10],
299
+ ElementTemplateUpdateOps.removeNode,
300
+ 0,
301
+ 0,
302
+ 10,
303
+ [10],
304
+ ]);
305
+
306
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toEqual([[pageRef, 0, { id: 'background' }]]);
307
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toEqual([[pageRef, 0, childRef, null]]);
308
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[pageRef, 0, childRef]]);
309
+ expect(elementTemplateRegistry.has(10)).toBe(false);
310
+ });
311
+
312
+ it('accepts commit context payload on update event', () => {
313
+ function App() {
314
+ const id = __BACKGROUND__ ? 'bg' : 'main';
315
+ return <view id={id} />;
316
+ }
317
+
318
+ const { before } = renderAndCollect(App);
319
+ const targetId = before.uid;
320
+ if (typeof targetId !== 'number') {
321
+ throw new Error('Missing uid on hydration payload');
322
+ }
323
+ const stream = [ElementTemplateUpdateOps.setAttribute, targetId, 0, 'bg'] as const;
324
+
325
+ envManager.switchToMainThread();
326
+ installElementTemplatePatchListener();
327
+ mockSetElementTemplateAttributeSlot.mockClear();
328
+ mockFlushElementTree.mockClear();
329
+
330
+ envManager.switchToBackground();
331
+ dispatchElementTemplateUpdate({ ops: stream, flushOptions: {} });
332
+ envManager.switchToMainThread();
333
+
334
+ expect(mockSetElementTemplateAttributeSlot.mock.calls.length).toBeGreaterThan(0);
335
+ expect(mockFlushElementTree.mock.calls.length).toBeGreaterThan(0);
336
+ });
337
+
338
+ it('records MTEvent state after setMainThreadEvent PAPI succeeds', () => {
339
+ const targetId = 101;
340
+ const nativeRef = {};
341
+ const ctx = { _wkltId: 'tap' };
342
+ elementTemplateRegistry.set(targetId, nativeRef as ElementTemplateHandle);
343
+
344
+ envManager.switchToMainThread();
345
+ installElementTemplatePatchListener();
346
+ mockSetElementTemplateAttributeSlot.mockClear();
347
+ mockFlushElementTree.mockClear();
348
+
349
+ envManager.switchToBackground();
350
+ dispatchElementTemplateUpdate({
351
+ ops: [ElementTemplateUpdateOps.setMainThreadEvent, targetId, 0, { type: 'worklet', value: ctx }],
352
+ flushOptions: {},
353
+ });
354
+ envManager.switchToMainThread();
355
+
356
+ expect(mockSetElementTemplateAttributeSlot).toHaveBeenCalledTimes(1);
357
+ expect(mockFlushElementTree).toHaveBeenCalledTimes(1);
358
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toEqual({
359
+ kind: 'mt-event',
360
+ nativeHeldValue: ctx,
361
+ });
362
+ });
363
+
364
+ it('does not record wrapper-shaped values without direct MTEvent attr-plan eligibility', () => {
365
+ const targetId = 120;
366
+ const ctx = { _wkltId: 'ordinary-wrapper' };
367
+ const hydrateCtx = vi.fn();
368
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
369
+ globalThis.lynxWorkletImpl = {
370
+ ...previousWorkletImpl,
371
+ _hydrateCtx: hydrateCtx,
372
+ _refImpl: createMainThreadRefImplMock(),
373
+ };
374
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
375
+
376
+ try {
377
+ envManager.switchToMainThread();
378
+ installElementTemplatePatchListener();
379
+ mockSetElementTemplateAttributeSlot.mockClear();
380
+
381
+ envManager.switchToBackground();
382
+ dispatchElementTemplateUpdate({
383
+ ops: [ElementTemplateUpdateOps.setAttribute, targetId, 0, { type: 'worklet', value: ctx }],
384
+ flushOptions: {},
385
+ isHydration: true,
386
+ });
387
+ envManager.switchToMainThread();
388
+
389
+ expect(mockSetElementTemplateAttributeSlot).toHaveBeenCalledTimes(1);
390
+ expect(hydrateCtx).not.toHaveBeenCalled();
391
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toBeUndefined();
392
+ } finally {
393
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
394
+ }
395
+ });
396
+
397
+ it('passes wrapper-shaped ordinary attribute values through without MTRef attr-plan eligibility', () => {
398
+ const targetId = 125;
399
+ const nativeRef = {};
400
+ const ordinaryValue = { type: 'main-thread-ref', value: { _wvid: 12 } };
401
+ elementTemplateRegistry.set(targetId, nativeRef as ElementTemplateHandle);
402
+
403
+ envManager.switchToMainThread();
404
+ installElementTemplatePatchListener();
405
+ mockSetElementTemplateAttributeSlot.mockClear();
406
+
407
+ envManager.switchToBackground();
408
+ dispatchElementTemplateUpdate({
409
+ ops: [ElementTemplateUpdateOps.setAttribute, targetId, 0, ordinaryValue],
410
+ flushOptions: {},
411
+ });
412
+ envManager.switchToMainThread();
413
+
414
+ expect(mockSetElementTemplateAttributeSlot).toHaveBeenCalledWith(nativeRef, 0, ordinaryValue);
415
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toBeUndefined();
416
+ });
417
+
418
+ it('records main-thread dynamic attr state after createTemplate PAPI succeeds', () => {
419
+ const handleId = 107;
420
+ const ctx = { _wkltId: 'created' };
421
+ // The transform keys the attr plan by the full `${entry}:${key}` tag; the
422
+ // main card uses the `__Card__` sentinel (normalized from a null bundleUrl).
423
+ __etAttrPlanMap['__Card__:view'] = [0, adaptMTEventAttrSlot];
424
+ registerTemplates([{
425
+ templateId: 'view',
426
+ compiledTemplate: {
427
+ kind: 'element',
428
+ type: 'view',
429
+ attributesArray: [{
430
+ kind: 'slot',
431
+ key: 'main-thread:bindtap',
432
+ attrSlotIndex: 0,
433
+ }],
434
+ children: [],
435
+ },
436
+ }]);
437
+
438
+ envManager.switchToMainThread();
439
+ installElementTemplatePatchListener();
440
+
441
+ envManager.switchToBackground();
442
+ dispatchElementTemplateUpdate({
443
+ ops: [
444
+ ElementTemplateUpdateOps.createTemplate,
445
+ handleId,
446
+ 'view',
447
+ null,
448
+ [{ type: 'worklet', value: ctx }],
449
+ [],
450
+ ],
451
+ flushOptions: {},
452
+ });
453
+ envManager.switchToMainThread();
454
+
455
+ expect(getMainThreadDynamicAttrState(handleId, 0)).toEqual({
456
+ kind: 'mt-event',
457
+ nativeHeldValue: ctx,
458
+ });
459
+ });
460
+
461
+ it('records dynamic-entry main-thread dynamic attr state after createTemplate PAPI succeeds', () => {
462
+ const handleId = 108;
463
+ const ctx = { _wkltId: 'dynamic-created' };
464
+ registerMTEventSlotsForTemplate('lazy-entry:view', 0);
465
+ registerTemplates([{
466
+ templateId: 'view',
467
+ compiledTemplate: {
468
+ kind: 'element',
469
+ type: 'view',
470
+ attributesArray: [{
471
+ kind: 'slot',
472
+ key: 'main-thread:bindtap',
473
+ attrSlotIndex: 0,
474
+ }],
475
+ children: [],
476
+ },
477
+ }]);
478
+
479
+ envManager.switchToMainThread();
480
+ installElementTemplatePatchListener();
481
+
482
+ envManager.switchToBackground();
483
+ dispatchElementTemplateUpdate({
484
+ ops: [
485
+ ElementTemplateUpdateOps.createTemplate,
486
+ handleId,
487
+ 'view',
488
+ 'lazy-entry',
489
+ [{ type: 'worklet', value: ctx }],
490
+ [],
491
+ ],
492
+ flushOptions: {},
493
+ });
494
+ envManager.switchToMainThread();
495
+
496
+ expect(getMainThreadDynamicAttrState(handleId, 0)).toEqual({
497
+ kind: 'mt-event',
498
+ nativeHeldValue: ctx,
499
+ });
500
+ });
501
+
502
+ it('initializes object MTRef detached after createTemplate and strips the native slot payload', () => {
503
+ const handleId = 121;
504
+ const ref = { _wvid: 7 };
505
+ const { updateWorkletRef, restore } = installWorkletRefRuntime();
506
+ __etAttrPlanMap['__Card__:view'] = [0, adaptMTRefAttrSlot];
507
+ registerTemplates([{
508
+ templateId: 'view',
509
+ compiledTemplate: {
510
+ kind: 'element',
511
+ type: 'view',
512
+ attributesArray: [{
513
+ kind: 'slot',
514
+ key: 'main-thread:ref',
515
+ attrSlotIndex: 0,
516
+ }],
517
+ children: [],
518
+ },
519
+ }]);
520
+
521
+ try {
522
+ envManager.switchToMainThread();
523
+ installElementTemplatePatchListener();
524
+
525
+ envManager.switchToBackground();
526
+ dispatchElementTemplateUpdate({
527
+ ops: [
528
+ ElementTemplateUpdateOps.createTemplate,
529
+ handleId,
530
+ 'view',
531
+ null,
532
+ [{ type: 'main-thread-ref', value: ref }],
533
+ [],
534
+ ],
535
+ flushOptions: {},
536
+ });
537
+ envManager.switchToMainThread();
538
+
539
+ const nativeRef = elementTemplateRegistry.get(handleId);
540
+ expect(nativeRef).toBeDefined();
541
+ expect(mockCreateElementTemplate.mock.calls.at(-1)?.[2]).toEqual([null]);
542
+ expect(updateWorkletRef).not.toHaveBeenCalled();
543
+ expect(getMainThreadDynamicAttrState(handleId, 0)).toEqual({
544
+ kind: 'mt-ref',
545
+ value: ref,
546
+ });
547
+ } finally {
548
+ restore();
549
+ }
550
+ });
551
+
552
+ it('attaches an object MTRef only after insertNode PAPI succeeds', () => {
553
+ const handleId = 125;
554
+ const parentId = 126;
555
+ const ref = { _wvid: 70 };
556
+ const { updateWorkletRef, restore } = installWorkletRefRuntime();
557
+ const parentRef = {} as ElementTemplateHandle;
558
+ elementTemplateRegistry.set(parentId, parentRef);
559
+ __etAttrPlanMap['__Card__:view'] = [0, adaptMTRefAttrSlot];
560
+ registerTemplates([{
561
+ templateId: 'view',
562
+ compiledTemplate: {
563
+ kind: 'element',
564
+ type: 'view',
565
+ attributesArray: [{
566
+ kind: 'slot',
567
+ key: 'main-thread:ref',
568
+ attrSlotIndex: 0,
569
+ }],
570
+ children: [],
571
+ },
572
+ }]);
573
+
574
+ try {
575
+ envManager.switchToMainThread();
576
+
577
+ applyElementTemplateUpdateCommands([
578
+ ElementTemplateUpdateOps.createTemplate,
579
+ handleId,
580
+ 'view',
581
+ null,
582
+ [{ type: 'main-thread-ref', value: ref }],
583
+ [],
584
+ ]);
585
+
586
+ const nativeRef = elementTemplateRegistry.get(handleId);
587
+ expect(nativeRef).toBeDefined();
588
+ expect(mockCreateElementTemplate.mock.calls.at(-1)?.[2]).toEqual([null]);
589
+ expect(updateWorkletRef).not.toHaveBeenCalled();
590
+ expect(getMainThreadDynamicAttrState(handleId, 0)).toEqual({
591
+ kind: 'mt-ref',
592
+ value: ref,
593
+ });
594
+
595
+ applyElementTemplateUpdateCommands([
596
+ ElementTemplateUpdateOps.insertNode,
597
+ parentId,
598
+ 0,
599
+ handleId,
600
+ 0,
601
+ [handleId],
602
+ ]);
603
+
604
+ expect(mockInsertElementTemplateNodeIntoSlot).toHaveBeenCalledWith(parentRef, 0, nativeRef, null);
605
+ expect(updateWorkletRef).toHaveBeenCalledWith(ref, nativeRef);
606
+ expect(getMainThreadDynamicAttrState(handleId, 0)).toEqual({
607
+ kind: 'mt-ref',
608
+ value: ref,
609
+ });
610
+ } finally {
611
+ restore();
612
+ }
613
+ });
614
+
615
+ it('keeps an object MTRef blocked when insertNode PAPI throws', () => {
616
+ const handleId = 127;
617
+ const parentId = 128;
618
+ const ref = { _wvid: 71 };
619
+ const { updateWorkletRef, restore } = installWorkletRefRuntime();
620
+ elementTemplateRegistry.set(parentId, {} as ElementTemplateHandle);
621
+ __etAttrPlanMap['__Card__:view'] = [0, adaptMTRefAttrSlot];
622
+ registerTemplates([{
623
+ templateId: 'view',
624
+ compiledTemplate: {
625
+ kind: 'element',
626
+ type: 'view',
627
+ attributesArray: [{ kind: 'slot', key: 'main-thread:ref', attrSlotIndex: 0 }],
628
+ children: [],
629
+ },
630
+ }]);
631
+
632
+ try {
633
+ envManager.switchToMainThread();
634
+ applyElementTemplateUpdateCommands([
635
+ ElementTemplateUpdateOps.createTemplate,
636
+ handleId,
637
+ 'view',
638
+ null,
639
+ [{ type: 'main-thread-ref', value: ref }],
640
+ [],
641
+ ]);
642
+ mockInsertElementTemplateNodeIntoSlot.mockImplementationOnce(() => {
643
+ throw new Error('insert failed');
644
+ });
645
+
646
+ expect(() =>
647
+ applyElementTemplateUpdateCommands([
648
+ ElementTemplateUpdateOps.insertNode,
649
+ parentId,
650
+ 0,
651
+ handleId,
652
+ 0,
653
+ [handleId],
654
+ ])
655
+ ).toThrow('insert failed');
656
+
657
+ expect(updateWorkletRef).not.toHaveBeenCalled();
658
+ expect(getMainThreadDynamicAttrState(handleId, 0)).toEqual({
659
+ kind: 'mt-ref',
660
+ value: ref,
661
+ });
662
+ } finally {
663
+ restore();
664
+ }
665
+ });
666
+
667
+ it('deletes MTEvent state after a slot clear patch succeeds', () => {
668
+ const targetId = 103;
669
+ const nativeRef = {};
670
+ elementTemplateRegistry.set(targetId, nativeRef as ElementTemplateHandle);
671
+ seedMTEventState(targetId, 0, { _wkltId: 'old' });
672
+
673
+ envManager.switchToMainThread();
674
+ installElementTemplatePatchListener();
675
+
676
+ envManager.switchToBackground();
677
+ dispatchElementTemplateUpdate({
678
+ ops: [ElementTemplateUpdateOps.setMainThreadEvent, targetId, 0, null],
679
+ flushOptions: {},
680
+ });
681
+ envManager.switchToMainThread();
682
+
683
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toBeUndefined();
684
+ });
685
+
686
+ it('cleans object MTRef without forwarding the value to native', () => {
687
+ const targetId = 122;
688
+ const nativeRef = {};
689
+ const ref = { _wvid: 8 };
690
+ const { updateWorkletRef, restore } = installWorkletRefRuntime();
691
+ elementTemplateRegistry.set(targetId, nativeRef as ElementTemplateHandle);
692
+ seedMTRefState(targetId, 0, ref, nativeRef as ElementTemplateHandle);
693
+
694
+ try {
695
+ envManager.switchToMainThread();
696
+ installElementTemplatePatchListener();
697
+
698
+ envManager.switchToBackground();
699
+ dispatchElementTemplateUpdate({
700
+ ops: [ElementTemplateUpdateOps.setMainThreadRef, targetId, 0, null],
701
+ flushOptions: {},
702
+ });
703
+ envManager.switchToMainThread();
704
+
705
+ expect(mockSetElementTemplateAttributeSlot).not.toHaveBeenCalled();
706
+ expect(updateWorkletRef).toHaveBeenCalledWith(ref, null);
707
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toBeUndefined();
708
+ } finally {
709
+ restore();
710
+ }
711
+ });
712
+
713
+ it('applies an empty MTRef hydration clear without forwarding it to native', () => {
714
+ const targetId = 131;
715
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
716
+
717
+ applyElementTemplateUpdateCommands([
718
+ ElementTemplateUpdateOps.setMainThreadRef,
719
+ targetId,
720
+ 0,
721
+ null,
722
+ ], true);
723
+
724
+ expect(mockSetElementTemplateAttributeSlot).not.toHaveBeenCalled();
725
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toBeUndefined();
726
+ });
727
+
728
+ it('cleans and remounts callback MTRef without forwarding the value to native', () => {
729
+ const targetId = 123;
730
+ const nativeRef = {};
731
+ const oldCleanup = vi.fn();
732
+ const nextCleanup = vi.fn();
733
+ const oldCallback = { _wkltId: 'old-ref-callback' };
734
+ const nextCallback = { _wkltId: 'next-ref-callback' };
735
+ const previousRunWorklet = globalThis.runWorklet;
736
+ elementTemplateRegistry.set(targetId, nativeRef as ElementTemplateHandle);
737
+ globalThis.runWorklet = vi.fn(() => oldCleanup);
738
+ seedMTRefState(targetId, 0, oldCallback, nativeRef as ElementTemplateHandle);
739
+ globalThis.runWorklet = vi.fn(() => nextCleanup);
740
+ const runWorklet = globalThis.runWorklet as ReturnType<typeof vi.fn>;
741
+
742
+ try {
743
+ envManager.switchToMainThread();
744
+ installElementTemplatePatchListener();
745
+
746
+ envManager.switchToBackground();
747
+ dispatchElementTemplateUpdate({
748
+ ops: [
749
+ ElementTemplateUpdateOps.setMainThreadRef,
750
+ targetId,
751
+ 0,
752
+ { type: 'main-thread-ref', value: nextCallback },
753
+ ],
754
+ flushOptions: {},
755
+ });
756
+ envManager.switchToMainThread();
757
+
758
+ expect(mockSetElementTemplateAttributeSlot).not.toHaveBeenCalled();
759
+ expect(oldCleanup).toHaveBeenCalledTimes(1);
760
+ const mountedCallback = runWorklet.mock.calls[0]?.[0] as typeof nextCallback & {
761
+ _unmount?: () => void;
762
+ };
763
+ expect(mountedCallback).toEqual(expect.objectContaining({
764
+ _wkltId: 'next-ref-callback',
765
+ }));
766
+ expect(runWorklet.mock.calls[0]?.[1]).toEqual([{ elementRefptr: nativeRef }]);
767
+ expect(mountedCallback._unmount).toBe(nextCleanup);
768
+ expect(nextCallback).not.toHaveProperty('_unmount');
769
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toEqual({
770
+ kind: 'mt-ref',
771
+ value: mountedCallback,
772
+ });
773
+ } finally {
774
+ globalThis.runWorklet = previousRunWorklet;
775
+ }
776
+ });
777
+
778
+ it('hydrates callback MTRef ctx without legacy delayed event replay', () => {
779
+ const targetId = 129;
780
+ const nativeRef = {} as ElementTemplateHandle;
781
+ const oldCleanup = vi.fn();
782
+ const nextCleanup = vi.fn();
783
+ const oldCallback = { _wkltId: 'ref-callback', version: 1 };
784
+ const nextCallback = { _wkltId: 'ref-callback', version: 2 };
785
+ const hydrateCtx = vi.fn();
786
+ const runDelayedWorklet = vi.fn();
787
+ const previousRunWorklet = globalThis.runWorklet;
788
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
789
+ elementTemplateRegistry.set(targetId, nativeRef);
790
+ globalThis.runWorklet = vi.fn(() => oldCleanup);
791
+ seedMTRefState(targetId, 0, oldCallback, nativeRef);
792
+ globalThis.runWorklet = vi.fn(() => nextCleanup);
793
+ globalThis.lynxWorkletImpl = {
794
+ ...previousWorkletImpl,
795
+ _hydrateCtx: hydrateCtx,
796
+ _eventDelayImpl: { runDelayedWorklet },
797
+ };
798
+
799
+ try {
800
+ applyElementTemplateUpdateCommands([
801
+ ElementTemplateUpdateOps.setMainThreadRef,
802
+ targetId,
803
+ 0,
804
+ { type: 'main-thread-ref', value: nextCallback },
805
+ ], true);
806
+
807
+ expect(hydrateCtx).toHaveBeenCalledWith(nextCallback, oldCallback);
808
+ expect(runDelayedWorklet).not.toHaveBeenCalled();
809
+ expect(oldCleanup).toHaveBeenCalledTimes(1);
810
+ expect(globalThis.runWorklet).toHaveBeenCalledWith(nextCallback, [{ elementRefptr: nativeRef }]);
811
+ } finally {
812
+ globalThis.runWorklet = previousRunWorklet;
813
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
814
+ }
815
+ });
816
+
817
+ it('hydrates callback MTRef ctx while a list item is detached without remounting it', () => {
818
+ const targetId = 130;
819
+ const nativeRef = {} as ElementTemplateHandle;
820
+ const oldCallback = { _wkltId: 'ref-callback', version: 1 };
821
+ const nextCallback = { _wkltId: 'ref-callback', version: 2 };
822
+ const hydrateCtx = vi.fn();
823
+ const oldCleanup = vi.fn();
824
+ const previousRunWorklet = globalThis.runWorklet;
825
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
826
+ elementTemplateRegistry.set(targetId, nativeRef);
827
+ globalThis.runWorklet = vi.fn(() => oldCleanup);
828
+ seedMTRefState(targetId, 0, oldCallback, nativeRef);
829
+ detachMainThreadDynamicAttrRefsForSubtree([{ uid: targetId, ref: nativeRef }]);
830
+ globalThis.runWorklet = vi.fn();
831
+ globalThis.lynxWorkletImpl = {
832
+ ...previousWorkletImpl,
833
+ _hydrateCtx: hydrateCtx,
834
+ };
835
+
836
+ try {
837
+ applyElementTemplateUpdateCommands([
838
+ ElementTemplateUpdateOps.setMainThreadRef,
839
+ targetId,
840
+ 0,
841
+ { type: 'main-thread-ref', value: nextCallback },
842
+ ], true);
843
+
844
+ expect(hydrateCtx).toHaveBeenCalledWith(nextCallback, oldCallback);
845
+ expect(globalThis.runWorklet).not.toHaveBeenCalled();
846
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toEqual({
847
+ kind: 'mt-ref',
848
+ value: nextCallback,
849
+ });
850
+ } finally {
851
+ globalThis.runWorklet = previousRunWorklet;
852
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
853
+ }
854
+ });
855
+
856
+ it('does not update MTRef state when the target is missing', () => {
857
+ const targetId = 124;
858
+ const ref = { _wvid: 9 };
859
+ const { updateWorkletRef, restore } = installWorkletRefRuntime();
860
+
861
+ try {
862
+ envManager.switchToMainThread();
863
+ installElementTemplatePatchListener();
864
+
865
+ envManager.switchToBackground();
866
+ dispatchElementTemplateUpdate({
867
+ ops: [
868
+ ElementTemplateUpdateOps.setMainThreadRef,
869
+ targetId,
870
+ 0,
871
+ { type: 'main-thread-ref', value: ref },
872
+ ],
873
+ flushOptions: {},
874
+ });
875
+ envManager.switchToMainThread();
876
+
877
+ expect(mockSetElementTemplateAttributeSlot).not.toHaveBeenCalled();
878
+ expect(updateWorkletRef).not.toHaveBeenCalled();
879
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toBeUndefined();
880
+ resetReportedErrors();
881
+ } finally {
882
+ restore();
883
+ }
884
+ });
885
+
886
+ it('deletes main-thread dynamic attr state for a removed subtree after patch succeeds', () => {
887
+ const targetId = 104;
888
+ const childId = 105;
889
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
890
+ elementTemplateRegistry.set(childId, {} as ElementTemplateHandle);
891
+ seedMTEventState(childId, 0, { _wkltId: 'child' });
892
+
893
+ envManager.switchToMainThread();
894
+ installElementTemplatePatchListener();
895
+
896
+ envManager.switchToBackground();
897
+ dispatchElementTemplateUpdate({
898
+ ops: [ElementTemplateUpdateOps.removeNode, targetId, 0, childId, [childId]],
899
+ flushOptions: {},
900
+ });
901
+ envManager.switchToMainThread();
902
+
903
+ expect(getMainThreadDynamicAttrState(childId, 0)).toBeUndefined();
904
+ });
905
+
906
+ it('cleans object MTRef for a removed subtree after patch succeeds', () => {
907
+ const targetId = 126;
908
+ const childId = 127;
909
+ const targetRef = {};
910
+ const childRef = {};
911
+ const ref = { _wvid: 10 };
912
+ const { updateWorkletRef, restore } = installWorkletRefRuntime();
913
+ elementTemplateRegistry.set(targetId, targetRef as ElementTemplateHandle);
914
+ elementTemplateRegistry.set(childId, childRef as ElementTemplateHandle);
915
+ seedMTRefState(childId, 0, ref, childRef as ElementTemplateHandle);
916
+
917
+ try {
918
+ envManager.switchToMainThread();
919
+ installElementTemplatePatchListener();
920
+
921
+ envManager.switchToBackground();
922
+ dispatchElementTemplateUpdate({
923
+ ops: [ElementTemplateUpdateOps.removeNode, targetId, 0, childId, [childId]],
924
+ flushOptions: {},
925
+ });
926
+ envManager.switchToMainThread();
927
+
928
+ expect(mockRemoveElementTemplateNodeFromSlot).toHaveBeenCalledWith(targetRef, 0, childRef);
929
+ expect(updateWorkletRef).toHaveBeenCalledWith(ref, null);
930
+ expect(getMainThreadDynamicAttrState(childId, 0)).toBeUndefined();
931
+ } finally {
932
+ restore();
933
+ }
934
+ });
935
+
936
+ it('hydrates MTEvent ctx after setMainThreadEvent PAPI succeeds', () => {
937
+ const targetId = 109;
938
+ const oldCtx = { _wkltId: 'tap', count: 1 };
939
+ const nextCtx = { _wkltId: 'tap', count: 2 };
940
+ const hydrateCtx = vi.fn();
941
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
942
+ globalThis.lynxWorkletImpl = {
943
+ ...previousWorkletImpl,
944
+ _hydrateCtx: hydrateCtx,
945
+ _refImpl: createMainThreadRefImplMock(),
946
+ };
947
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
948
+ seedMTEventState(targetId, 0, oldCtx);
949
+
950
+ try {
951
+ envManager.switchToMainThread();
952
+ installElementTemplatePatchListener();
953
+
954
+ envManager.switchToBackground();
955
+ dispatchElementTemplateUpdate({
956
+ ops: [ElementTemplateUpdateOps.setMainThreadEvent, targetId, 0, { type: 'worklet', value: nextCtx }],
957
+ flushOptions: {},
958
+ isHydration: true,
959
+ });
960
+ envManager.switchToMainThread();
961
+
962
+ expect(hydrateCtx).toHaveBeenCalledWith(nextCtx, oldCtx);
963
+ expect(getMainThreadDynamicAttrState(targetId, 0)?.nativeHeldValue).toEqual(nextCtx);
964
+ expect(getMainThreadDynamicAttrState(targetId, 0)?.nativeHeldValue).not.toBe(nextCtx);
965
+ } finally {
966
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
967
+ }
968
+ });
969
+
970
+ it('flushes delayed runOnBackground calls after hydration apply and before native flush', () => {
971
+ const targetId = 118;
972
+ const oldCtx = { _wkltId: 'tap', count: 1 };
973
+ const nextCtx = { _wkltId: 'tap', count: 2 };
974
+ const callOrder: string[] = [];
975
+ const hydrateCtx = vi.fn(() => {
976
+ callOrder.push('hydrate');
977
+ });
978
+ const runDelayedBackgroundFunctions = vi.fn(() => {
979
+ callOrder.push('runOnBackground');
980
+ });
981
+ const clearFirstScreenWorkletRefMap = vi.fn(() => {
982
+ callOrder.push('clearFirstScreenRefs');
983
+ });
984
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
985
+ globalThis.lynxWorkletImpl = {
986
+ ...previousWorkletImpl,
987
+ _hydrateCtx: hydrateCtx,
988
+ _refImpl: createMainThreadRefImplMock(clearFirstScreenWorkletRefMap),
989
+ _runOnBackgroundDelayImpl: {
990
+ runDelayedBackgroundFunctions,
991
+ },
992
+ };
993
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
994
+ seedMTEventState(targetId, 0, oldCtx);
995
+
996
+ try {
997
+ envManager.switchToMainThread();
998
+ installElementTemplatePatchListener();
999
+ mockFlushElementTree.mockImplementationOnce(() => {
1000
+ callOrder.push('flushElementTree');
1001
+ });
1002
+
1003
+ envManager.switchToBackground();
1004
+ dispatchElementTemplateUpdate({
1005
+ ops: [ElementTemplateUpdateOps.setMainThreadEvent, targetId, 0, { type: 'worklet', value: nextCtx }],
1006
+ flushOptions: {},
1007
+ isHydration: true,
1008
+ });
1009
+ envManager.switchToMainThread();
1010
+
1011
+ expect(hydrateCtx).toHaveBeenCalledWith(nextCtx, oldCtx);
1012
+ expect(runDelayedBackgroundFunctions).toHaveBeenCalledTimes(1);
1013
+ expect(callOrder).toEqual([
1014
+ 'hydrate',
1015
+ 'runOnBackground',
1016
+ 'clearFirstScreenRefs',
1017
+ 'flushElementTree',
1018
+ ]);
1019
+ } finally {
1020
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1021
+ }
1022
+ });
1023
+
1024
+ it('runs delayed runOnMainThread after hydration apply and delayed runOnBackground before native flush', () => {
1025
+ const targetId = 119;
1026
+ const oldCtx = { _wkltId: 'tap', count: 1 };
1027
+ const nextCtx = { _wkltId: 'tap', count: 2 };
1028
+ const mainThreadWorklet = { _wkltId: 'delayed-main-thread-function' };
1029
+ const callOrder: string[] = [];
1030
+ const hydrateCtx = vi.fn(() => {
1031
+ callOrder.push('hydrate');
1032
+ });
1033
+ const runDelayedBackgroundFunctions = vi.fn(() => {
1034
+ callOrder.push('runOnBackground');
1035
+ });
1036
+ const clearFirstScreenWorkletRefMap = vi.fn(() => {
1037
+ callOrder.push('clearFirstScreenRefs');
1038
+ });
1039
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1040
+ globalThis.lynxWorkletImpl = {
1041
+ ...previousWorkletImpl,
1042
+ _hydrateCtx: hydrateCtx,
1043
+ _refImpl: createMainThreadRefImplMock(clearFirstScreenWorkletRefMap),
1044
+ _runOnBackgroundDelayImpl: {
1045
+ runDelayedBackgroundFunctions,
1046
+ },
1047
+ _eomImpl: {
1048
+ setShouldFlush: vi.fn((value: boolean) => {
1049
+ callOrder.push(`eom:${String(value)}`);
1050
+ }),
1051
+ },
1052
+ _runRunOnMainThreadTask: vi.fn(() => {
1053
+ callOrder.push('runOnMainThread');
1054
+ }),
1055
+ };
1056
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
1057
+ seedMTEventState(targetId, 0, oldCtx);
1058
+
1059
+ try {
1060
+ envManager.switchToMainThread();
1061
+ installElementTemplatePatchListener();
1062
+ mockFlushElementTree.mockImplementationOnce(() => {
1063
+ callOrder.push('flushElementTree');
1064
+ });
1065
+
1066
+ envManager.switchToBackground();
1067
+ dispatchElementTemplateUpdate({
1068
+ ops: [ElementTemplateUpdateOps.setMainThreadEvent, targetId, 0, { type: 'worklet', value: nextCtx }],
1069
+ flushOptions: {},
1070
+ isHydration: true,
1071
+ delayedRunOnMainThreadData: [
1072
+ {
1073
+ worklet: mainThreadWorklet,
1074
+ params: ['from-hydrate'],
1075
+ resolveId: 7,
1076
+ },
1077
+ ],
1078
+ });
1079
+ envManager.switchToMainThread();
1080
+
1081
+ expect(hydrateCtx).toHaveBeenCalledWith(nextCtx, oldCtx);
1082
+ expect(runDelayedBackgroundFunctions).toHaveBeenCalledTimes(1);
1083
+ expect(globalThis.lynxWorkletImpl._runRunOnMainThreadTask).toHaveBeenCalledWith(
1084
+ mainThreadWorklet,
1085
+ ['from-hydrate'],
1086
+ 7,
1087
+ );
1088
+ expect(callOrder).toEqual([
1089
+ 'hydrate',
1090
+ 'runOnBackground',
1091
+ 'clearFirstScreenRefs',
1092
+ 'eom:false',
1093
+ 'runOnMainThread',
1094
+ 'eom:true',
1095
+ 'flushElementTree',
1096
+ ]);
1097
+ } finally {
1098
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1099
+ }
1100
+ });
1101
+
1102
+ it('reports delayed runOnMainThread errors and restores EOM before native flush', () => {
1103
+ const taskError = new Error('main thread task failed');
1104
+ const callOrder: string[] = [];
1105
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1106
+ globalThis.lynxWorkletImpl = {
1107
+ ...previousWorkletImpl,
1108
+ _eomImpl: {
1109
+ setShouldFlush: vi.fn((value: boolean) => {
1110
+ callOrder.push(`eom:${String(value)}`);
1111
+ }),
1112
+ },
1113
+ _runRunOnMainThreadTask: vi.fn(() => {
1114
+ callOrder.push('runOnMainThread');
1115
+ throw taskError;
1116
+ }),
1117
+ };
1118
+
1119
+ try {
1120
+ resetReportedErrors();
1121
+ envManager.switchToMainThread();
1122
+ installElementTemplatePatchListener();
1123
+ mockFlushElementTree.mockImplementationOnce(() => {
1124
+ callOrder.push('flushElementTree');
1125
+ });
1126
+
1127
+ envManager.switchToBackground();
1128
+ dispatchElementTemplateUpdate({
1129
+ ops: [],
1130
+ flushOptions: {},
1131
+ delayedRunOnMainThreadData: [
1132
+ {
1133
+ worklet: { _wkltId: 'throwing-main-thread-function' },
1134
+ params: [],
1135
+ resolveId: 8,
1136
+ },
1137
+ ],
1138
+ });
1139
+ envManager.switchToMainThread();
1140
+
1141
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
1142
+ expect(reportError.mock.calls[0]?.[0]).toBe(taskError);
1143
+ expect(callOrder).toEqual([
1144
+ 'eom:false',
1145
+ 'runOnMainThread',
1146
+ 'eom:true',
1147
+ 'flushElementTree',
1148
+ ]);
1149
+ } finally {
1150
+ resetReportedErrors();
1151
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1152
+ }
1153
+ });
1154
+
1155
+ it('flushes delayed runOnBackground on empty hydration boundaries', () => {
1156
+ const callOrder: string[] = [];
1157
+ const runDelayedBackgroundFunctions = vi.fn(() => {
1158
+ callOrder.push('runOnBackground');
1159
+ });
1160
+ const clearFirstScreenWorkletRefMap = vi.fn(() => {
1161
+ callOrder.push('clearFirstScreenRefs');
1162
+ });
1163
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1164
+ globalThis.lynxWorkletImpl = {
1165
+ ...previousWorkletImpl,
1166
+ _refImpl: createMainThreadRefImplMock(clearFirstScreenWorkletRefMap),
1167
+ _runOnBackgroundDelayImpl: {
1168
+ runDelayedBackgroundFunctions,
1169
+ },
1170
+ };
1171
+
1172
+ try {
1173
+ envManager.switchToMainThread();
1174
+ installElementTemplatePatchListener();
1175
+ mockFlushElementTree.mockImplementationOnce(() => {
1176
+ callOrder.push('flushElementTree');
1177
+ });
1178
+
1179
+ envManager.switchToBackground();
1180
+ dispatchElementTemplateUpdate({
1181
+ ops: [],
1182
+ flushOptions: {},
1183
+ isHydration: true,
1184
+ });
1185
+ envManager.switchToMainThread();
1186
+
1187
+ expect(runDelayedBackgroundFunctions).toHaveBeenCalledTimes(1);
1188
+ expect(callOrder).toEqual([
1189
+ 'runOnBackground',
1190
+ 'clearFirstScreenRefs',
1191
+ 'flushElementTree',
1192
+ ]);
1193
+ } finally {
1194
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1195
+ }
1196
+ });
1197
+
1198
+ it('does not hydrate MTEvent ctx for ordinary update patches', () => {
1199
+ const targetId = 110;
1200
+ const oldCtx = { _wkltId: 'tap', count: 1 };
1201
+ const nextCtx = { _wkltId: 'tap', count: 2 };
1202
+ const hydrateCtx = vi.fn();
1203
+ const runDelayedBackgroundFunctions = vi.fn();
1204
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1205
+ globalThis.lynxWorkletImpl = {
1206
+ ...previousWorkletImpl,
1207
+ _hydrateCtx: hydrateCtx,
1208
+ _runOnBackgroundDelayImpl: {
1209
+ runDelayedBackgroundFunctions,
1210
+ },
1211
+ };
1212
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
1213
+ seedMTEventState(targetId, 0, oldCtx);
1214
+
1215
+ try {
1216
+ envManager.switchToMainThread();
1217
+ installElementTemplatePatchListener();
1218
+
1219
+ envManager.switchToBackground();
1220
+ dispatchElementTemplateUpdate({
1221
+ ops: [ElementTemplateUpdateOps.setMainThreadEvent, targetId, 0, { type: 'worklet', value: nextCtx }],
1222
+ flushOptions: {},
1223
+ });
1224
+ envManager.switchToMainThread();
1225
+
1226
+ expect(hydrateCtx).not.toHaveBeenCalled();
1227
+ expect(runDelayedBackgroundFunctions).not.toHaveBeenCalled();
1228
+ expect(getMainThreadDynamicAttrState(targetId, 0)?.nativeHeldValue).toEqual(nextCtx);
1229
+ expect(getMainThreadDynamicAttrState(targetId, 0)?.nativeHeldValue).not.toBe(nextCtx);
1230
+ } finally {
1231
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1232
+ }
1233
+ });
1234
+
1235
+ it('keeps MTEvent state when update flush throws after its PAPI succeeds', () => {
1236
+ const targetId = 102;
1237
+ const nativeRef = {};
1238
+ const ctx = { _wkltId: 'tap' };
1239
+ elementTemplateRegistry.set(targetId, nativeRef as ElementTemplateHandle);
1240
+
1241
+ envManager.switchToMainThread();
1242
+ installElementTemplatePatchListener();
1243
+ mockFlushElementTree.mockImplementationOnce(() => {
1244
+ throw new Error('flush failed');
1245
+ });
1246
+
1247
+ expect(() => {
1248
+ envManager.switchToBackground();
1249
+ dispatchElementTemplateUpdate({
1250
+ ops: [ElementTemplateUpdateOps.setMainThreadEvent, targetId, 0, { type: 'worklet', value: ctx }],
1251
+ flushOptions: {},
1252
+ });
1253
+ envManager.switchToMainThread();
1254
+ }).toThrow('flush failed');
1255
+
1256
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toEqual({
1257
+ kind: 'mt-event',
1258
+ nativeHeldValue: ctx,
1259
+ });
1260
+ });
1261
+
1262
+ it('hydrates MTEvent ctx when its PAPI succeeds even if flush throws', () => {
1263
+ const targetId = 111;
1264
+ const oldCtx = { _wkltId: 'tap', count: 1 };
1265
+ const nextCtx = { _wkltId: 'tap', count: 2 };
1266
+ const hydrateCtx = vi.fn();
1267
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1268
+ globalThis.lynxWorkletImpl = {
1269
+ ...previousWorkletImpl,
1270
+ _hydrateCtx: hydrateCtx,
1271
+ _refImpl: createMainThreadRefImplMock(),
1272
+ };
1273
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
1274
+ seedMTEventState(targetId, 0, oldCtx);
1275
+
1276
+ try {
1277
+ envManager.switchToMainThread();
1278
+ installElementTemplatePatchListener();
1279
+ mockFlushElementTree.mockImplementationOnce(() => {
1280
+ throw new Error('flush failed');
1281
+ });
1282
+
1283
+ expect(() => {
1284
+ envManager.switchToBackground();
1285
+ dispatchElementTemplateUpdate({
1286
+ ops: [ElementTemplateUpdateOps.setMainThreadEvent, targetId, 0, { type: 'worklet', value: nextCtx }],
1287
+ flushOptions: {},
1288
+ isHydration: true,
1289
+ });
1290
+ envManager.switchToMainThread();
1291
+ }).toThrow('flush failed');
1292
+
1293
+ expect(hydrateCtx).toHaveBeenCalledWith(nextCtx, oldCtx);
1294
+ expect(getMainThreadDynamicAttrState(targetId, 0)?.nativeHeldValue).toEqual(nextCtx);
1295
+ expect(getMainThreadDynamicAttrState(targetId, 0)?.nativeHeldValue).not.toBe(nextCtx);
1296
+ } finally {
1297
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1298
+ }
1299
+ });
1300
+
1301
+ it('does not hydrate MTEvent ctx for stale hydrate update payloads', () => {
1302
+ const targetId = 112;
1303
+ const oldCtx = { _wkltId: 'tap', count: 1 };
1304
+ const nextCtx = { _wkltId: 'tap', count: 2 };
1305
+ const staleReloadVersion = getReloadVersion();
1306
+ const hydrateCtx = vi.fn();
1307
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1308
+ globalThis.lynxWorkletImpl = {
1309
+ ...previousWorkletImpl,
1310
+ _hydrateCtx: hydrateCtx,
1311
+ };
1312
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
1313
+ seedMTEventState(targetId, 0, oldCtx);
1314
+
1315
+ try {
1316
+ increaseReloadVersion();
1317
+ envManager.switchToMainThread();
1318
+ installElementTemplatePatchListener();
1319
+
1320
+ envManager.switchToBackground();
1321
+ dispatchElementTemplateUpdate({
1322
+ ops: [ElementTemplateUpdateOps.setMainThreadEvent, targetId, 0, { type: 'worklet', value: nextCtx }],
1323
+ flushOptions: {},
1324
+ isHydration: true,
1325
+ reloadVersion: staleReloadVersion,
1326
+ });
1327
+ envManager.switchToMainThread();
1328
+
1329
+ expect(hydrateCtx).not.toHaveBeenCalled();
1330
+ expect(getMainThreadDynamicAttrState(targetId, 0)?.nativeHeldValue).toBe(oldCtx);
1331
+ } finally {
1332
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1333
+ }
1334
+ });
1335
+
1336
+ it('flushes hydration runOnBackground replay but aborts delayed main-thread tasks when a native patch op throws', () => {
1337
+ const targetId = 108;
1338
+ const nativeRef = {};
1339
+ const ctx = { _wkltId: 'tap' };
1340
+ const runDelayedBackgroundFunctions = vi.fn();
1341
+ const runRunOnMainThreadTask = vi.fn();
1342
+ const setShouldFlush = vi.fn();
1343
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1344
+ globalThis.lynxWorkletImpl = {
1345
+ ...previousWorkletImpl,
1346
+ _refImpl: createMainThreadRefImplMock(),
1347
+ _runOnBackgroundDelayImpl: {
1348
+ runDelayedBackgroundFunctions,
1349
+ },
1350
+ _eomImpl: {
1351
+ setShouldFlush,
1352
+ },
1353
+ _runRunOnMainThreadTask: runRunOnMainThreadTask,
1354
+ };
1355
+ elementTemplateRegistry.set(targetId, nativeRef as ElementTemplateHandle);
1356
+
1357
+ try {
1358
+ envManager.switchToMainThread();
1359
+ installElementTemplatePatchListener();
1360
+ mockSetElementTemplateAttributeSlot.mockImplementationOnce(() => {
1361
+ throw new Error('setAttribute failed');
1362
+ });
1363
+
1364
+ expect(() => {
1365
+ envManager.switchToBackground();
1366
+ dispatchElementTemplateUpdate({
1367
+ ops: [ElementTemplateUpdateOps.setMainThreadEvent, targetId, 0, { type: 'worklet', value: ctx }],
1368
+ flushOptions: {},
1369
+ isHydration: true,
1370
+ delayedRunOnMainThreadData: [
1371
+ {
1372
+ worklet: { _wkltId: 'should-not-run' },
1373
+ params: [],
1374
+ resolveId: 11,
1375
+ },
1376
+ ],
1377
+ });
1378
+ envManager.switchToMainThread();
1379
+ }).toThrow('setAttribute failed');
1380
+
1381
+ expect(runDelayedBackgroundFunctions).toHaveBeenCalledTimes(1);
1382
+ expect(globalThis.lynxWorkletImpl._refImpl.clearFirstScreenWorkletRefMap).toHaveBeenCalledTimes(1);
1383
+ expect(setShouldFlush).not.toHaveBeenCalled();
1384
+ expect(runRunOnMainThreadTask).not.toHaveBeenCalled();
1385
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toBeUndefined();
1386
+ } finally {
1387
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1388
+ }
1389
+ });
1390
+
1391
+ it('continues delayed lifecycle when patch apply reports a missing target', () => {
1392
+ const runDelayedBackgroundFunctions = vi.fn();
1393
+ const runRunOnMainThreadTask = vi.fn();
1394
+ const setShouldFlush = vi.fn();
1395
+ const worklet = { _wkltId: 'missing-target-main-thread-function' };
1396
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1397
+ globalThis.lynxWorkletImpl = {
1398
+ ...previousWorkletImpl,
1399
+ _refImpl: createMainThreadRefImplMock(),
1400
+ _runOnBackgroundDelayImpl: {
1401
+ runDelayedBackgroundFunctions,
1402
+ },
1403
+ _eomImpl: {
1404
+ setShouldFlush,
1405
+ },
1406
+ _runRunOnMainThreadTask: runRunOnMainThreadTask,
1407
+ };
1408
+
1409
+ try {
1410
+ resetReportedErrors();
1411
+ envManager.switchToMainThread();
1412
+ installElementTemplatePatchListener();
1413
+ mockFlushElementTree.mockClear();
1414
+
1415
+ envManager.switchToBackground();
1416
+ dispatchElementTemplateUpdate({
1417
+ ops: [ElementTemplateUpdateOps.setAttribute, 404, 0, 'missing'],
1418
+ flushOptions: {},
1419
+ isHydration: true,
1420
+ delayedRunOnMainThreadData: [
1421
+ {
1422
+ worklet,
1423
+ params: [],
1424
+ resolveId: 9,
1425
+ },
1426
+ ],
1427
+ });
1428
+ envManager.switchToMainThread();
1429
+
1430
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
1431
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('target handle 404 not found');
1432
+ expect(runDelayedBackgroundFunctions).toHaveBeenCalledTimes(1);
1433
+ expect(runRunOnMainThreadTask).toHaveBeenCalledWith(worklet, [], 9);
1434
+ expect(setShouldFlush.mock.calls).toEqual([[false], [true]]);
1435
+ expect(mockFlushElementTree).toHaveBeenCalledTimes(1);
1436
+ } finally {
1437
+ resetReportedErrors();
1438
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1439
+ }
1440
+ });
1441
+
1442
+ it('applies MainThreadRef init patches before same-payload delayed main-thread tasks', () => {
1443
+ const callOrder: string[] = [];
1444
+ const updateWorkletRefInitValueChanges = vi.fn(() => {
1445
+ callOrder.push('init-patch');
1446
+ });
1447
+ const runRunOnMainThreadTask = vi.fn(() => {
1448
+ callOrder.push('runOnMainThread');
1449
+ });
1450
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1451
+ globalThis.lynxWorkletImpl = {
1452
+ ...previousWorkletImpl,
1453
+ _refImpl: {
1454
+ updateWorkletRefInitValueChanges,
1455
+ },
1456
+ _eomImpl: {
1457
+ setShouldFlush: vi.fn(),
1458
+ },
1459
+ _runRunOnMainThreadTask: runRunOnMainThreadTask,
1460
+ };
1461
+
1462
+ try {
1463
+ envManager.switchToMainThread();
1464
+ installElementTemplatePatchListener();
1465
+ mockFlushElementTree.mockImplementationOnce(() => {
1466
+ callOrder.push('flushElementTree');
1467
+ });
1468
+
1469
+ envManager.switchToBackground();
1470
+ dispatchElementTemplateUpdate({
1471
+ ops: [],
1472
+ flushOptions: {},
1473
+ delayedRunOnMainThreadData: [
1474
+ {
1475
+ worklet: { _wkltId: 'same-payload-main-thread-function' },
1476
+ params: [],
1477
+ resolveId: 10,
1478
+ },
1479
+ ],
1480
+ mainThreadRefInitValuePatch: [[1, 'same-payload-init']],
1481
+ });
1482
+ envManager.switchToMainThread();
1483
+
1484
+ expect(updateWorkletRefInitValueChanges).toHaveBeenCalledWith([[1, 'same-payload-init']]);
1485
+ expect(runRunOnMainThreadTask).toHaveBeenCalledTimes(1);
1486
+ expect(callOrder).toEqual([
1487
+ 'init-patch',
1488
+ 'runOnMainThread',
1489
+ 'flushElementTree',
1490
+ ]);
1491
+ } finally {
1492
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1493
+ }
1494
+ });
1495
+
1496
+ it('does not run delayed main-thread tasks for stale reload payloads', () => {
1497
+ const staleReloadVersion = getReloadVersion();
1498
+ const runRunOnMainThreadTask = vi.fn();
1499
+ const updateWorkletRefInitValueChanges = vi.fn();
1500
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1501
+ globalThis.lynxWorkletImpl = {
1502
+ ...previousWorkletImpl,
1503
+ _refImpl: {
1504
+ updateWorkletRefInitValueChanges,
1505
+ },
1506
+ _eomImpl: {
1507
+ setShouldFlush: vi.fn(),
1508
+ },
1509
+ _runRunOnMainThreadTask: runRunOnMainThreadTask,
1510
+ };
1511
+
1512
+ try {
1513
+ increaseReloadVersion();
1514
+ envManager.switchToMainThread();
1515
+ installElementTemplatePatchListener();
1516
+ mockFlushElementTree.mockClear();
1517
+
1518
+ envManager.switchToBackground();
1519
+ dispatchElementTemplateUpdate({
1520
+ ops: [],
1521
+ flushOptions: {},
1522
+ reloadVersion: staleReloadVersion,
1523
+ delayedRunOnMainThreadData: [
1524
+ {
1525
+ worklet: { _wkltId: 'stale-main-thread-function' },
1526
+ params: [],
1527
+ resolveId: 10,
1528
+ },
1529
+ ],
1530
+ mainThreadRefInitValuePatch: [[1, 'stale-init']],
1531
+ });
1532
+ envManager.switchToMainThread();
1533
+
1534
+ expect(updateWorkletRefInitValueChanges).toHaveBeenCalledWith([[1, 'stale-init']]);
1535
+ expect(runRunOnMainThreadTask).not.toHaveBeenCalled();
1536
+ expect(mockFlushElementTree).not.toHaveBeenCalled();
1537
+ } finally {
1538
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1539
+ }
1540
+ });
1541
+
1542
+ it('does not record main-thread dynamic attr state when the patch target is missing', () => {
1543
+ const targetId = 106;
1544
+ const ctx = { _wkltId: 'tap' };
1545
+
1546
+ envManager.switchToMainThread();
1547
+ installElementTemplatePatchListener();
1548
+
1549
+ envManager.switchToBackground();
1550
+ dispatchElementTemplateUpdate({
1551
+ ops: [ElementTemplateUpdateOps.setMainThreadEvent, targetId, 0, { type: 'worklet', value: ctx }],
1552
+ flushOptions: {},
1553
+ });
1554
+ envManager.switchToMainThread();
1555
+
1556
+ expect(getMainThreadDynamicAttrState(targetId, 0)).toBeUndefined();
1557
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
1558
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(`target handle ${targetId} not found`);
1559
+ resetReportedErrors();
1560
+ });
1561
+
1562
+ it('hydrates successfully applied MTEvent slot when the same payload has a missing target op', () => {
1563
+ const targetId = 113;
1564
+ const missingTargetId = 114;
1565
+ const oldCtx = { _wkltId: 'tap', count: 1 };
1566
+ const nextCtx = { _wkltId: 'tap', count: 2 };
1567
+ const hydrateCtx = vi.fn();
1568
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1569
+ globalThis.lynxWorkletImpl = {
1570
+ ...previousWorkletImpl,
1571
+ _hydrateCtx: hydrateCtx,
1572
+ _refImpl: createMainThreadRefImplMock(),
1573
+ };
1574
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
1575
+ seedMTEventState(targetId, 0, oldCtx);
1576
+
1577
+ try {
1578
+ envManager.switchToMainThread();
1579
+ installElementTemplatePatchListener();
1580
+ mockSetElementTemplateAttributeSlot.mockClear();
1581
+ mockFlushElementTree.mockClear();
1582
+
1583
+ envManager.switchToBackground();
1584
+ dispatchElementTemplateUpdate({
1585
+ ops: [
1586
+ ElementTemplateUpdateOps.setMainThreadEvent,
1587
+ targetId,
1588
+ 0,
1589
+ { type: 'worklet', value: nextCtx },
1590
+ ElementTemplateUpdateOps.setAttribute,
1591
+ missingTargetId,
1592
+ 0,
1593
+ 'missing',
1594
+ ],
1595
+ flushOptions: {},
1596
+ isHydration: true,
1597
+ });
1598
+ envManager.switchToMainThread();
1599
+
1600
+ expect(mockSetElementTemplateAttributeSlot).toHaveBeenCalledTimes(1);
1601
+ expect(mockFlushElementTree).toHaveBeenCalledTimes(1);
1602
+ expect(hydrateCtx).toHaveBeenCalledWith(nextCtx, oldCtx);
1603
+ expect(getMainThreadDynamicAttrState(targetId, 0)?.nativeHeldValue).toEqual(nextCtx);
1604
+ expect(getMainThreadDynamicAttrState(targetId, 0)?.nativeHeldValue).not.toBe(nextCtx);
1605
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
1606
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
1607
+ `target handle ${missingTargetId} not found`,
1608
+ );
1609
+ resetReportedErrors();
1610
+ } finally {
1611
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1612
+ }
1613
+ });
1614
+
1615
+ it('cleans removed MTEvent state when the same payload later has a missing target op', () => {
1616
+ const targetId = 115;
1617
+ const childId = 116;
1618
+ const missingTargetId = 117;
1619
+ const hydrateCtx = vi.fn();
1620
+ const previousWorkletImpl = globalThis.lynxWorkletImpl;
1621
+ globalThis.lynxWorkletImpl = {
1622
+ ...previousWorkletImpl,
1623
+ _hydrateCtx: hydrateCtx,
1624
+ _refImpl: createMainThreadRefImplMock(),
1625
+ };
1626
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
1627
+ elementTemplateRegistry.set(childId, {} as ElementTemplateHandle);
1628
+ seedMTEventState(childId, 0, { _wkltId: 'removed' });
1629
+
1630
+ try {
1631
+ envManager.switchToMainThread();
1632
+ installElementTemplatePatchListener();
1633
+ mockRemoveElementTemplateNodeFromSlot.mockClear();
1634
+ mockFlushElementTree.mockClear();
1635
+
1636
+ envManager.switchToBackground();
1637
+ dispatchElementTemplateUpdate({
1638
+ ops: [
1639
+ ElementTemplateUpdateOps.removeNode,
1640
+ targetId,
1641
+ 0,
1642
+ childId,
1643
+ [childId],
1644
+ ElementTemplateUpdateOps.setAttribute,
1645
+ missingTargetId,
1646
+ 0,
1647
+ 'missing',
1648
+ ],
1649
+ flushOptions: {},
1650
+ isHydration: true,
1651
+ });
1652
+ envManager.switchToMainThread();
1653
+
1654
+ expect(mockRemoveElementTemplateNodeFromSlot).toHaveBeenCalledTimes(1);
1655
+ expect(mockFlushElementTree).toHaveBeenCalledTimes(1);
1656
+ expect(hydrateCtx).not.toHaveBeenCalled();
1657
+ expect(elementTemplateRegistry.get(childId)).toBeUndefined();
1658
+ expect(getMainThreadDynamicAttrState(childId, 0)).toBeUndefined();
1659
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
1660
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
1661
+ `target handle ${missingTargetId} not found`,
1662
+ );
1663
+ resetReportedErrors();
1664
+ } finally {
1665
+ globalThis.lynxWorkletImpl = previousWorkletImpl;
1666
+ }
1667
+ });
1668
+
1669
+ it('cleans removed MTEvent state when flush throws after remove succeeds', () => {
1670
+ const targetId = 118;
1671
+ const childId = 119;
1672
+ elementTemplateRegistry.set(targetId, {} as ElementTemplateHandle);
1673
+ elementTemplateRegistry.set(childId, {} as ElementTemplateHandle);
1674
+ seedMTEventState(childId, 0, { _wkltId: 'removed' });
1675
+
1676
+ envManager.switchToMainThread();
1677
+ installElementTemplatePatchListener();
1678
+ mockRemoveElementTemplateNodeFromSlot.mockClear();
1679
+ mockFlushElementTree.mockImplementationOnce(() => {
1680
+ throw new Error('flush failed');
1681
+ });
1682
+
1683
+ expect(() => {
1684
+ envManager.switchToBackground();
1685
+ dispatchElementTemplateUpdate({
1686
+ ops: [ElementTemplateUpdateOps.removeNode, targetId, 0, childId, [childId]],
1687
+ flushOptions: {},
1688
+ isHydration: true,
1689
+ });
1690
+ envManager.switchToMainThread();
1691
+ }).toThrow('flush failed');
1692
+
1693
+ expect(mockRemoveElementTemplateNodeFromSlot).toHaveBeenCalledTimes(1);
1694
+ expect(elementTemplateRegistry.get(childId)).toBeUndefined();
1695
+ expect(getMainThreadDynamicAttrState(childId, 0)).toBeUndefined();
1696
+ });
1697
+
1698
+ it('profiles patch update flowIds on main thread without passing them to __FlushElementTree', () => {
1699
+ function App() {
1700
+ const id = __BACKGROUND__ ? 'bg' : 'main';
1701
+ return <view id={id} />;
1702
+ }
1703
+
1704
+ const { before } = renderAndCollect(App);
1705
+ const targetId = before.uid;
1706
+ if (typeof targetId !== 'number') {
1707
+ throw new Error('Missing uid on hydration payload');
1708
+ }
1709
+ const stream = [ElementTemplateUpdateOps.setAttribute, targetId, 0, 'bg'] as const;
1710
+
1711
+ envManager.switchToMainThread();
1712
+ installElementTemplatePatchListener();
1713
+ const performance = lynx.performance;
1714
+ performance.profileStart.mockClear();
1715
+ performance.profileEnd.mockClear();
1716
+ mockFlushElementTree.mockClear();
1717
+
1718
+ envManager.switchToBackground();
1719
+ dispatchElementTemplateUpdate({ ops: stream, flushOptions: {}, flowIds: [101, 202] });
1720
+ envManager.switchToMainThread();
1721
+
1722
+ expect(performance.profileStart).toHaveBeenCalledWith('ReactLynx::patch', {
1723
+ flowId: 101,
1724
+ flowIds: [101, 202],
1725
+ });
1726
+ expect(performance.profileEnd).toHaveBeenCalledTimes(1);
1727
+ const lastFlushOptions = mockFlushElementTree.mock.calls.at(-1)?.[1] as { flowIds?: unknown };
1728
+ expect(lastFlushOptions.flowIds).toBeUndefined();
1729
+ });
1730
+
1731
+ it('does not profile empty update payloads that only flush native options', () => {
1732
+ envManager.switchToMainThread();
1733
+ installElementTemplatePatchListener();
1734
+ const performance = lynx.performance;
1735
+ performance.profileStart.mockClear();
1736
+ performance.profileEnd.mockClear();
1737
+ mockFlushElementTree.mockClear();
1738
+
1739
+ envManager.switchToBackground();
1740
+ dispatchElementTemplateUpdate({ ops: [], flushOptions: { triggerDataUpdated: true }, flowIds: [101, 202] });
1741
+ envManager.switchToMainThread();
1742
+
1743
+ expect(performance.profileStart).not.toHaveBeenCalled();
1744
+ expect(performance.profileEnd).not.toHaveBeenCalled();
1745
+ expect(mockFlushElementTree.mock.calls).toHaveLength(1);
1746
+ expect(mockFlushElementTree.mock.calls[0]?.[1]).toEqual({ triggerDataUpdated: true });
1747
+ });
1748
+
1749
+ it('flushes option-only update payloads with empty ops', () => {
1750
+ envManager.switchToMainThread();
1751
+ installElementTemplatePatchListener();
1752
+ const performance = lynx.performance;
1753
+ performance.profileStart.mockClear();
1754
+ performance.profileEnd.mockClear();
1755
+ mockFlushElementTree.mockClear();
1756
+
1757
+ envManager.switchToBackground();
1758
+ dispatchElementTemplateUpdate({
1759
+ ops: [],
1760
+ flushOptions: { triggerDataUpdated: true },
1761
+ flowIds: [101, 202],
1762
+ });
1763
+ envManager.switchToMainThread();
1764
+
1765
+ expect(performance.profileStart).not.toHaveBeenCalled();
1766
+ expect(performance.profileEnd).not.toHaveBeenCalled();
1767
+ expect(mockFlushElementTree.mock.calls).toHaveLength(1);
1768
+ expect(mockFlushElementTree.mock.calls[0]?.[1]).toEqual({ triggerDataUpdated: true });
1769
+ });
1770
+
1771
+ it('reports illegal handleId 0 on create', () => {
1772
+ const jsx = <view />;
1773
+ root.render(jsx);
1774
+ envManager.switchToMainThread();
1775
+ root.render(jsx);
1776
+ renderPage();
1777
+
1778
+ applyElementTemplateUpdateCommands(createRawTextOps(0, 'x'));
1779
+
1780
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
1781
+ expect(reportError.mock.calls).toHaveLength(1);
1782
+ resetReportedErrors();
1783
+ });
1784
+
1785
+ it('reports invalid non-integer handleId on create', () => {
1786
+ envManager.switchToMainThread();
1787
+
1788
+ applyElementTemplateUpdateCommands([
1789
+ ElementTemplateUpdateOps.createTemplate,
1790
+ 1.5,
1791
+ '_et_builtin_raw_text',
1792
+ null,
1793
+ ['x'],
1794
+ [],
1795
+ ]);
1796
+
1797
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
1798
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('invalid handleId 1.5');
1799
+ resetReportedErrors();
1800
+ });
1801
+
1802
+ it('reports duplicate handleId on create', () => {
1803
+ envManager.switchToMainThread();
1804
+ const existingRef = createMockElementTemplateHandle('existing');
1805
+ elementTemplateRegistry.set(7, existingRef);
1806
+
1807
+ applyElementTemplateUpdateCommands([
1808
+ ElementTemplateUpdateOps.createTemplate,
1809
+ 7,
1810
+ '_et_builtin_raw_text',
1811
+ null,
1812
+ ['x'],
1813
+ [],
1814
+ ]);
1815
+
1816
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
1817
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('duplicate handleId 7');
1818
+ resetReportedErrors();
1819
+ });
1820
+
1821
+ it('reports invalid non-array attributeSlots on create', () => {
1822
+ envManager.switchToMainThread();
1823
+
1824
+ applyElementTemplateUpdateCommands([
1825
+ ElementTemplateUpdateOps.createTemplate,
1826
+ 7,
1827
+ '_et_builtin_raw_text',
1828
+ null,
1829
+ 'bad-attrs' as unknown as ElementTemplateUpdateCommandStream[number],
1830
+ [],
1831
+ ]);
1832
+
1833
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
1834
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
1835
+ 'attributeSlots must be an array, null, or undefined',
1836
+ );
1837
+ resetReportedErrors();
1838
+ });
1839
+
1840
+ it('reports invalid non-array childSlots on create', () => {
1841
+ envManager.switchToMainThread();
1842
+
1843
+ applyElementTemplateUpdateCommands([
1844
+ ElementTemplateUpdateOps.createTemplate,
1845
+ 8,
1846
+ '_et_builtin_raw_text',
1847
+ null,
1848
+ [],
1849
+ 'bad-slots' as unknown as ElementTemplateUpdateCommandStream[number],
1850
+ ]);
1851
+
1852
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
1853
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
1854
+ 'childSlots must be an array, null, or undefined',
1855
+ );
1856
+ resetReportedErrors();
1857
+ });
1858
+
1859
+ it('creates templates with nullable and sparse child slots', () => {
1860
+ envManager.switchToMainThread();
1861
+ elementTemplateRegistry.clear();
1862
+ registerTemplates([
1863
+ {
1864
+ templateId: '_et_sparse_slot_parent',
1865
+ compiledTemplate: {
1866
+ kind: 'element',
1867
+ type: 'view',
1868
+ attributesArray: [],
1869
+ children: [
1870
+ { kind: 'childSlot', type: 'slot', elementSlotIndex: 0 },
1871
+ { kind: 'childSlot', type: 'slot', elementSlotIndex: 1 },
1872
+ { kind: 'childSlot', type: 'slot', elementSlotIndex: 2 },
1873
+ ],
1874
+ },
1875
+ },
1876
+ ]);
1877
+
1878
+ const childSlots: ElementTemplateHandleSlotsCommand = [];
1879
+ childSlots[1] = [31];
1880
+ childSlots[2] = null;
1881
+
1882
+ const createTemplateMock = globalThis.__CreateElementTemplate as unknown as {
1883
+ mockClear: () => void;
1884
+ mock: { calls: unknown[][] };
1885
+ };
1886
+ createTemplateMock.mockClear();
1887
+
1888
+ applyElementTemplateUpdateCommands([
1889
+ ...createRawTextOps(31, 'child'),
1890
+ ElementTemplateUpdateOps.createTemplate,
1891
+ 32,
1892
+ '_et_sparse_slot_parent',
1893
+ null,
1894
+ [],
1895
+ childSlots,
1896
+ ]);
1897
+
1898
+ const parentCall = createTemplateMock.mock.calls.find((call) => call[0] === '_et_sparse_slot_parent');
1899
+ expect(parentCall).toBeDefined();
1900
+ const childRef = elementTemplateRegistry.get(31);
1901
+ const resolvedSlots = parentCall![3] as Array<ElementTemplateHandle[] | null | undefined>;
1902
+ expect(0 in resolvedSlots).toBe(false);
1903
+ expect(resolvedSlots[1]).toEqual([childRef]);
1904
+ expect(2 in resolvedSlots).toBe(false);
1905
+ expect(elementTemplateRegistry.has(32)).toBe(true);
1906
+ expect((globalThis.lynx as unknown as LynxWithReportErrorMock).reportError.mock.calls).toHaveLength(0);
1907
+ });
1908
+
1909
+ it('reports missing patch target', () => {
1910
+ const jsx = <view />;
1911
+ root.render(jsx);
1912
+ envManager.switchToMainThread();
1913
+ root.render(jsx);
1914
+ renderPage();
1915
+
1916
+ applyElementTemplateUpdateCommands([ElementTemplateUpdateOps.setAttribute, 999, 0, 'a']);
1917
+
1918
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
1919
+ expect(reportError.mock.calls).toHaveLength(1);
1920
+ resetReportedErrors();
1921
+ });
1922
+
1923
+ it('creates typed elements with resolved slots and serializable command options', () => {
1924
+ envManager.switchToMainThread();
1925
+ elementTemplateRegistry.clear();
1926
+
1927
+ const slotChildRef = createMockElementTemplateHandle('slot-child');
1928
+ elementTemplateRegistry.set(11, slotChildRef);
1929
+ mockCreateTypedElementTemplate.mockClear();
1930
+
1931
+ applyElementTemplateUpdateCommands([
1932
+ ElementTemplateUpdateOps.createTypedElement,
1933
+ 21,
1934
+ 'typed-host',
1935
+ { id: 'typed-list' },
1936
+ [[11], null],
1937
+ {
1938
+ metadata: { itemCount: 1 },
1939
+ estimatedHeight: 80,
1940
+ },
1941
+ ]);
1942
+
1943
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(1);
1944
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[0]).toBe('typed-host');
1945
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[1]).toEqual({ id: 'typed-list' });
1946
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[2]).toEqual([[slotChildRef]]);
1947
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[3]).toBe(21);
1948
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[4]).toEqual({
1949
+ metadata: { itemCount: 1 },
1950
+ estimatedHeight: 80,
1951
+ });
1952
+ expect(elementTemplateRegistry.has(21)).toBe(true);
1953
+ });
1954
+
1955
+ it('creates a typed list with callbacks and logical children', () => {
1956
+ envManager.switchToMainThread();
1957
+ elementTemplateRegistry.clear();
1958
+
1959
+ const itemRef = createMockElementTemplateHandle('option-child', 101);
1960
+ elementTemplateRegistry.set(12, itemRef);
1961
+ mockCreateTypedElementTemplate.mockClear();
1962
+
1963
+ applyElementTemplateUpdateCommands([
1964
+ ElementTemplateUpdateOps.createTypedElement,
1965
+ 28,
1966
+ 'list',
1967
+ { id: 'typed-list' },
1968
+ [],
1969
+ {
1970
+ listChildren: [{ __etHandleRef: 12, type: '_et_item', platformInfo: { 'item-key': 'a' } }],
1971
+ estimatedHeight: 80,
1972
+ },
1973
+ ]);
1974
+
1975
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(1);
1976
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[0]).toBe('list');
1977
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[1]).toEqual({
1978
+ id: 'typed-list',
1979
+ 'component-at-index': expect.any(Function),
1980
+ 'component-at-indexes': expect.any(Function),
1981
+ 'enqueue-component': expect.any(Function),
1982
+ });
1983
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[2]).toBe(null);
1984
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[3]).toBe(28);
1985
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[4]).toEqual({
1986
+ listChildren: [itemRef],
1987
+ estimatedHeight: 80,
1988
+ });
1989
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toEqual([[
1990
+ expect.anything(),
1991
+ 0,
1992
+ {
1993
+ id: 'typed-list',
1994
+ 'component-at-index': expect.any(Function),
1995
+ 'component-at-indexes': expect.any(Function),
1996
+ 'enqueue-component': expect.any(Function),
1997
+ 'update-list-info': {
1998
+ insertAction: [{ position: 0, type: '_et_item', 'item-key': 'a' }],
1999
+ removeAction: [],
2000
+ updateAction: [],
2001
+ },
2002
+ },
2003
+ ]]);
2004
+ expect(elementTemplateRegistry.has(28)).toBe(true);
2005
+ const listRef = elementTemplateRegistry.get(28)!;
2006
+ const materializedListRef = createMaterializedListForFrontendTest(1001);
2007
+ const componentAtIndex = (mockCreateTypedElementTemplate.mock.calls[0]![1] as Record<string, unknown>)[
2008
+ 'component-at-index'
2009
+ ] as ComponentAtIndexCallback;
2010
+
2011
+ mockInsertElementTemplateNodeIntoSlot.mockClear();
2012
+ expect(componentAtIndex(materializedListRef, 7, 0, 88, false)).toBe(101);
2013
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toEqual([[listRef, 0, itemRef, null]]);
2014
+ });
2015
+
2016
+ it('creates a typed list outside development', () => {
2017
+ const originalDev = globalThis.__DEV__;
2018
+ globalThis.__DEV__ = false;
2019
+ try {
2020
+ envManager.switchToMainThread();
2021
+ elementTemplateRegistry.clear();
2022
+ const itemRef = createMockElementTemplateHandle('option-child');
2023
+ elementTemplateRegistry.set(12, itemRef);
2024
+ mockCreateTypedElementTemplate.mockClear();
2025
+
2026
+ applyElementTemplateUpdateCommands([
2027
+ ElementTemplateUpdateOps.createTypedElement,
2028
+ 33,
2029
+ 'list',
2030
+ null,
2031
+ [],
2032
+ {
2033
+ listChildren: [{ __etHandleRef: 12, type: '_et_item', platformInfo: {} }],
2034
+ estimatedHeight: 80,
2035
+ },
2036
+ ]);
2037
+
2038
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(1);
2039
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[4]).toEqual({
2040
+ listChildren: [itemRef],
2041
+ estimatedHeight: 80,
2042
+ });
2043
+ expect(elementTemplateRegistry.has(33)).toBe(true);
2044
+ } finally {
2045
+ globalThis.__DEV__ = originalDev;
2046
+ }
2047
+ });
2048
+
2049
+ it('creates a typed list with null child slots', () => {
2050
+ envManager.switchToMainThread();
2051
+ elementTemplateRegistry.clear();
2052
+ mockCreateTypedElementTemplate.mockClear();
2053
+
2054
+ applyElementTemplateUpdateCommands([
2055
+ ElementTemplateUpdateOps.createTypedElement,
2056
+ 29,
2057
+ 'list',
2058
+ null,
2059
+ null,
2060
+ { listChildren: [] },
2061
+ ]);
2062
+
2063
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(1);
2064
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[2]).toBe(null);
2065
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[4]).toEqual({
2066
+ listChildren: [],
2067
+ });
2068
+ expect(elementTemplateRegistry.has(29)).toBe(true);
2069
+ });
2070
+
2071
+ it('rejects exact typed list create without logical children options', () => {
2072
+ envManager.switchToMainThread();
2073
+ elementTemplateRegistry.clear();
2074
+ mockCreateTypedElementTemplate.mockClear();
2075
+
2076
+ applyElementTemplateUpdateCommands([
2077
+ ElementTemplateUpdateOps.createTypedElement,
2078
+ 32,
2079
+ 'list',
2080
+ null,
2081
+ [],
2082
+ null,
2083
+ ]);
2084
+
2085
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2086
+ expect(elementTemplateRegistry.has(32)).toBe(false);
2087
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2088
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2089
+ 'logical children in options.listChildren',
2090
+ );
2091
+ resetReportedErrors();
2092
+ });
2093
+
2094
+ it('rejects exact typed list create with visible child slots', () => {
2095
+ envManager.switchToMainThread();
2096
+ elementTemplateRegistry.clear();
2097
+ const slotChildRef = createMockElementTemplateHandle('slot-child');
2098
+ const itemRef = createMockElementTemplateHandle('item');
2099
+ elementTemplateRegistry.set(11, slotChildRef);
2100
+ elementTemplateRegistry.set(12, itemRef);
2101
+ mockCreateTypedElementTemplate.mockClear();
2102
+
2103
+ applyElementTemplateUpdateCommands([
2104
+ ElementTemplateUpdateOps.createTypedElement,
2105
+ 30,
2106
+ 'list',
2107
+ null,
2108
+ [[11]],
2109
+ { listChildren: [{ __etHandleRef: 12, type: '_et_item', platformInfo: {} }] },
2110
+ ]);
2111
+
2112
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2113
+ expect(elementTemplateRegistry.has(30)).toBe(false);
2114
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2115
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2116
+ 'logical children in options.listChildren',
2117
+ );
2118
+ resetReportedErrors();
2119
+ });
2120
+
2121
+ it('creates typed elements with no command options', () => {
2122
+ envManager.switchToMainThread();
2123
+ elementTemplateRegistry.clear();
2124
+ mockCreateTypedElementTemplate.mockClear();
2125
+
2126
+ applyElementTemplateUpdateCommands([
2127
+ ElementTemplateUpdateOps.createTypedElement,
2128
+ 23,
2129
+ 'typed-host',
2130
+ null,
2131
+ [],
2132
+ null,
2133
+ ]);
2134
+
2135
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[1]).toBe(null);
2136
+ expect(mockCreateTypedElementTemplate.mock.calls[0]?.[4]).toBe(null);
2137
+ expect(elementTemplateRegistry.has(23)).toBe(true);
2138
+ });
2139
+
2140
+ it('reports invalid typed create handleId', () => {
2141
+ envManager.switchToMainThread();
2142
+ elementTemplateRegistry.clear();
2143
+ mockCreateTypedElementTemplate.mockClear();
2144
+
2145
+ applyElementTemplateUpdateCommands([
2146
+ ElementTemplateUpdateOps.createTypedElement,
2147
+ 0,
2148
+ 'typed-host',
2149
+ null,
2150
+ [],
2151
+ null,
2152
+ ]);
2153
+
2154
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2155
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2156
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('invalid handleId 0');
2157
+ resetReportedErrors();
2158
+ });
2159
+
2160
+ it('reports invalid typed create childSlots', () => {
2161
+ envManager.switchToMainThread();
2162
+ elementTemplateRegistry.clear();
2163
+ mockCreateTypedElementTemplate.mockClear();
2164
+
2165
+ applyElementTemplateUpdateCommands([
2166
+ ElementTemplateUpdateOps.createTypedElement,
2167
+ 28,
2168
+ 'typed-host',
2169
+ null,
2170
+ 'bad-slots' as unknown as ElementTemplateUpdateCommandStream[number],
2171
+ null,
2172
+ ]);
2173
+
2174
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2175
+ expect(elementTemplateRegistry.has(28)).toBe(false);
2176
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2177
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2178
+ 'childSlots must be an array, null, or undefined',
2179
+ );
2180
+ resetReportedErrors();
2181
+ });
2182
+
2183
+ it('reports duplicate typed create handleId', () => {
2184
+ envManager.switchToMainThread();
2185
+ const existingRef = createMockElementTemplateHandle('existing');
2186
+ elementTemplateRegistry.set(26, existingRef);
2187
+ mockCreateTypedElementTemplate.mockClear();
2188
+
2189
+ applyElementTemplateUpdateCommands([
2190
+ ElementTemplateUpdateOps.createTypedElement,
2191
+ 26,
2192
+ 'typed-host',
2193
+ null,
2194
+ [],
2195
+ null,
2196
+ ]);
2197
+
2198
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2199
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2200
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('duplicate handleId 26');
2201
+ resetReportedErrors();
2202
+ });
2203
+
2204
+ it('reports invalid non-array childSlots on typed create', () => {
2205
+ envManager.switchToMainThread();
2206
+ elementTemplateRegistry.clear();
2207
+ mockCreateTypedElementTemplate.mockClear();
2208
+
2209
+ applyElementTemplateUpdateCommands([
2210
+ ElementTemplateUpdateOps.createTypedElement,
2211
+ 27,
2212
+ 'typed-host',
2213
+ null,
2214
+ 'bad-slots' as unknown as ElementTemplateUpdateCommandStream[number],
2215
+ null,
2216
+ ]);
2217
+
2218
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2219
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2220
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2221
+ 'childSlots must be an array, null, or undefined',
2222
+ );
2223
+ resetReportedErrors();
2224
+ });
2225
+
2226
+ it('skips typed create when child slot handles are unresolved', () => {
2227
+ envManager.switchToMainThread();
2228
+ elementTemplateRegistry.clear();
2229
+ mockCreateTypedElementTemplate.mockClear();
2230
+
2231
+ applyElementTemplateUpdateCommands([
2232
+ ElementTemplateUpdateOps.createTypedElement,
2233
+ 25,
2234
+ 'typed-host',
2235
+ null,
2236
+ [[404]],
2237
+ null,
2238
+ ]);
2239
+
2240
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2241
+ expect(elementTemplateRegistry.has(25)).toBe(false);
2242
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2243
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('child handle 404 not found');
2244
+ resetReportedErrors();
2245
+ });
2246
+
2247
+ it('skips typed list create when a logical child handle is unresolved', () => {
2248
+ envManager.switchToMainThread();
2249
+ elementTemplateRegistry.clear();
2250
+ mockCreateTypedElementTemplate.mockClear();
2251
+
2252
+ applyElementTemplateUpdateCommands([
2253
+ ElementTemplateUpdateOps.createTypedElement,
2254
+ 42,
2255
+ 'list',
2256
+ null,
2257
+ [],
2258
+ { listChildren: [{ __etHandleRef: 404, type: '_et_item', platformInfo: {} }] },
2259
+ ]);
2260
+
2261
+ expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2262
+ expect(elementTemplateRegistry.has(42)).toBe(false);
2263
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2264
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2265
+ 'typed list item 0 handle 404 not found',
2266
+ );
2267
+ resetReportedErrors();
2268
+ });
2269
+
2270
+ it('skips typed list item patches when the item handle is unresolved', () => {
2271
+ envManager.switchToMainThread();
2272
+ elementTemplateRegistry.clear();
2273
+ const listRef = createMockElementTemplateHandle('typed-list', 41);
2274
+ elementTemplateRegistry.set(41, listRef);
2275
+ registerElementTemplateListState(41, createElementTemplateListState([]), false, listRef);
2276
+ mockSetElementTemplateAttributeSlot.mockClear();
2277
+
2278
+ applyElementTemplateUpdateCommands([
2279
+ ElementTemplateUpdateOps.insertTypedListItem,
2280
+ 41,
2281
+ { __etHandleRef: 404, type: '_et_item', platformInfo: {} },
2282
+ 0,
2283
+ ElementTemplateUpdateOps.updateTypedListItem,
2284
+ 41,
2285
+ { __etHandleRef: 405, type: '_et_item', platformInfo: {} },
2286
+ ]);
2287
+
2288
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
2289
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2290
+ expect(reportError.mock.calls).toHaveLength(2);
2291
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2292
+ 'typed list insert item handle 404 not found',
2293
+ );
2294
+ expect(String(reportError.mock.calls[1]?.[0]?.message ?? '')).toContain(
2295
+ 'typed list update item handle 405 not found',
2296
+ );
2297
+ resetReportedErrors();
2298
+ });
2299
+
2300
+ it('skips pending typed list flushes when the list handle is unresolved', () => {
2301
+ envManager.switchToMainThread();
2302
+ elementTemplateRegistry.clear();
2303
+ const listRef = createMockElementTemplateHandle('typed-list');
2304
+ registerElementTemplateListState(91, createElementTemplateListState([]), true, listRef);
2305
+ mockSetElementTemplateAttributeSlot.mockClear();
2306
+
2307
+ applyElementTemplateUpdateCommands([]);
2308
+
2309
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
2310
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2311
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('typed list handle 91 not found');
2312
+ resetReportedErrors();
2313
+ });
2314
+
2315
+ it('reports missing list item records when constructing typed list state', () => {
2316
+ expect(() => createElementTemplateListState([404])).toThrow(
2317
+ 'Element Template typed list received a non-list-item root in logical slot $0.',
2318
+ );
2319
+ });
2320
+
2321
+ it('sets typed slot 0 attributes through the standard attr-slot PAPI', () => {
2322
+ envManager.switchToMainThread();
2323
+ const targetRef = createMockElementTemplateHandle('typed-target');
2324
+ elementTemplateRegistry.set(31, targetRef);
2325
+ mockSetAttribute.mockClear();
2326
+ mockSetElementTemplateAttributeSlot.mockClear();
2327
+
2328
+ const updateListInfo = {
2329
+ insertAction: [],
2330
+ removeAction: [],
2331
+ updateAction: [],
2332
+ };
2333
+ applyElementTemplateUpdateCommands([
2334
+ ElementTemplateUpdateOps.setAttribute,
2335
+ 31,
2336
+ 0,
2337
+ { 'update-list-info': updateListInfo },
2338
+ ]);
2339
+
2340
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toEqual([[
2341
+ targetRef,
2342
+ 0,
2343
+ { 'update-list-info': updateListInfo },
2344
+ ]]);
2345
+ expect(mockSetAttribute.mock.calls).toHaveLength(0);
2346
+ });
2347
+
2348
+ it('keeps list callbacks when hydrated list attributes update through slot 0', () => {
2349
+ envManager.switchToMainThread();
2350
+ const listRef = createMockElementTemplateHandle('typed-list', 95);
2351
+ elementTemplateRegistry.set(29, listRef);
2352
+ registerElementTemplateListState(29, createElementTemplateListState([], { id: 'old' }), false, listRef);
2353
+
2354
+ applyElementTemplateUpdateCommands([
2355
+ ElementTemplateUpdateOps.setAttribute,
2356
+ 29,
2357
+ 0,
2358
+ { id: 'next' },
2359
+ ]);
2360
+
2361
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[0]).toEqual([
2362
+ listRef,
2363
+ 0,
2364
+ {
2365
+ id: 'next',
2366
+ 'component-at-index': expect.any(Function),
2367
+ 'component-at-indexes': expect.any(Function),
2368
+ 'enqueue-component': expect.any(Function),
2369
+ },
2370
+ ]);
2371
+ });
2372
+
2373
+ it('clears typed slot 0 attributes through the standard attr-slot PAPI', () => {
2374
+ envManager.switchToMainThread();
2375
+ const targetRef = createMockElementTemplateHandle('typed-target');
2376
+ elementTemplateRegistry.set(32, targetRef);
2377
+ mockSetAttribute.mockClear();
2378
+ mockSetElementTemplateAttributeSlot.mockClear();
2379
+
2380
+ applyElementTemplateUpdateCommands([
2381
+ ElementTemplateUpdateOps.setAttribute,
2382
+ 32,
2383
+ 0,
2384
+ null,
2385
+ ]);
2386
+
2387
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toEqual([[
2388
+ targetRef,
2389
+ 0,
2390
+ null,
2391
+ ]]);
2392
+ expect(mockSetAttribute.mock.calls).toHaveLength(0);
2393
+ });
2394
+
2395
+ it('inserts before writing update-list-info', () => {
2396
+ envManager.switchToMainThread();
2397
+ const listRef = createMockElementTemplateHandle('typed-list', 100);
2398
+ const materializedList = createMaterializedListForFrontendTest(100);
2399
+ const firstRef = createMockElementTemplateHandle('first', 101);
2400
+ const secondRef = createMockElementTemplateHandle('second', 102);
2401
+ elementTemplateRegistry.set(31, listRef);
2402
+ elementTemplateRegistry.set(32, firstRef);
2403
+ elementTemplateRegistry.set(33, secondRef);
2404
+ registerElementTemplateListItem(32, firstRef, {
2405
+ templateKey: '_et_item_a',
2406
+ platformInfo: { 'item-key': 'a' },
2407
+ });
2408
+ const state = createElementTemplateListState([32]);
2409
+ registerElementTemplateListState(31, state, false, listRef);
2410
+ const attrs = composeElementTemplateListAttributes({ id: 'feed' }, state);
2411
+ const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
2412
+ mockSetElementTemplateAttributeSlot.mockImplementationOnce((...args: unknown[]) => {
2413
+ expect(componentAtIndex(materializedList, 7, 1, 99, false)).toBe(102);
2414
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls[0]).toEqual([listRef, 0, secondRef, null]);
2415
+ lastMock!.mockSetElementTemplateAttributeSlot(...args);
2416
+ });
2417
+
2418
+ applyElementTemplateUpdateCommands([
2419
+ ElementTemplateUpdateOps.insertTypedListItem,
2420
+ 31,
2421
+ {
2422
+ __etHandleRef: 33,
2423
+ type: '_et_item_b',
2424
+ platformInfo: { 'item-key': 'b' },
2425
+ },
2426
+ 0,
2427
+ ]);
2428
+
2429
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[0]).toEqual([
2430
+ listRef,
2431
+ 0,
2432
+ {
2433
+ id: 'feed',
2434
+ 'component-at-index': attrs['component-at-index'],
2435
+ 'component-at-indexes': attrs['component-at-indexes'],
2436
+ 'enqueue-component': attrs['enqueue-component'],
2437
+ 'update-list-info': {
2438
+ insertAction: [{ position: 1, type: '_et_item_b', 'item-key': 'b' }],
2439
+ removeAction: [],
2440
+ updateAction: [],
2441
+ },
2442
+ },
2443
+ ]);
2444
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
2445
+ expect(elementTemplateRegistry.get(32)).toBe(firstRef);
2446
+ });
2447
+
2448
+ it('preserves update-list-info when list attributes update after list mutation in the same stream', () => {
2449
+ envManager.switchToMainThread();
2450
+ const listRef = createMockElementTemplateHandle('typed-list', 105);
2451
+ const firstRef = createMockElementTemplateHandle('first', 106);
2452
+ const secondRef = createMockElementTemplateHandle('second', 107);
2453
+ elementTemplateRegistry.set(35, listRef);
2454
+ elementTemplateRegistry.set(36, firstRef);
2455
+ elementTemplateRegistry.set(37, secondRef);
2456
+ registerElementTemplateListItem(36, firstRef, {
2457
+ templateKey: '_et_item_a',
2458
+ platformInfo: { 'item-key': 'a' },
2459
+ });
2460
+ registerElementTemplateListState(
2461
+ 35,
2462
+ createElementTemplateListState([36], { id: 'feed' }),
2463
+ false,
2464
+ listRef,
2465
+ );
2466
+
2467
+ applyElementTemplateUpdateCommands([
2468
+ ElementTemplateUpdateOps.insertTypedListItem,
2469
+ 35,
2470
+ {
2471
+ __etHandleRef: 37,
2472
+ type: '_et_item_b',
2473
+ platformInfo: { 'item-key': 'b' },
2474
+ },
2475
+ 0,
2476
+ ElementTemplateUpdateOps.setAttribute,
2477
+ 35,
2478
+ 0,
2479
+ { id: 'next' },
2480
+ ]);
2481
+
2482
+ const attrWrite = mockSetElementTemplateAttributeSlot.mock.calls[0]![2] as Record<string, unknown>;
2483
+ const finalWrite = mockSetElementTemplateAttributeSlot.mock.calls[1]![2] as Record<string, unknown>;
2484
+ const updateListInfo = {
2485
+ insertAction: [{ position: 1, type: '_et_item_b', 'item-key': 'b' }],
2486
+ removeAction: [],
2487
+ updateAction: [],
2488
+ };
2489
+ expect(attrWrite).toEqual(expect.objectContaining({
2490
+ id: 'next',
2491
+ 'component-at-index': expect.any(Function),
2492
+ 'component-at-indexes': expect.any(Function),
2493
+ 'enqueue-component': expect.any(Function),
2494
+ }));
2495
+ expect(attrWrite).not.toHaveProperty('update-list-info');
2496
+ expect(finalWrite).toEqual(expect.objectContaining({
2497
+ id: 'next',
2498
+ 'update-list-info': updateListInfo,
2499
+ 'component-at-index': attrWrite['component-at-index'],
2500
+ 'component-at-indexes': attrWrite['component-at-indexes'],
2501
+ 'enqueue-component': attrWrite['enqueue-component'],
2502
+ }));
2503
+ });
2504
+
2505
+ it('coalesces multiple incremental list mutations into one Snapshot-shaped update-list-info write', () => {
2506
+ envManager.switchToMainThread();
2507
+ const listRef = createMockElementTemplateHandle('typed-list', 200);
2508
+ const refs = [201, 202, 203, 204, 205].map(id =>
2509
+ ({ __isNativeRef: true, id: `item-${id}`, __mockNativeId: id }) as unknown as ElementTemplateHandle
2510
+ );
2511
+ elementTemplateRegistry.set(200, listRef);
2512
+ for (let index = 0; index < refs.length; index += 1) {
2513
+ const handleId = 201 + index;
2514
+ elementTemplateRegistry.set(handleId, refs[index]!);
2515
+ if (handleId <= 203) {
2516
+ registerElementTemplateListItem(handleId, refs[index]!, {
2517
+ templateKey: `_et_item_${handleId}`,
2518
+ platformInfo: { 'item-key': String(handleId) },
2519
+ });
2520
+ }
2521
+ }
2522
+ registerElementTemplateListState(200, createElementTemplateListState([201, 202, 203]), false, listRef);
2523
+
2524
+ applyElementTemplateUpdateCommands([
2525
+ ElementTemplateUpdateOps.insertTypedListItem,
2526
+ 200,
2527
+ { __etHandleRef: 204, type: '_et_item_204', platformInfo: { 'item-key': '204' } },
2528
+ 202,
2529
+ ElementTemplateUpdateOps.insertTypedListItem,
2530
+ 200,
2531
+ { __etHandleRef: 205, type: '_et_item_205', platformInfo: { 'item-key': '205' } },
2532
+ 204,
2533
+ ElementTemplateUpdateOps.removeTypedListItem,
2534
+ 200,
2535
+ 202,
2536
+ [202],
2537
+ ElementTemplateUpdateOps.removeTypedListItem,
2538
+ 200,
2539
+ 203,
2540
+ [],
2541
+ ElementTemplateUpdateOps.insertTypedListItem,
2542
+ 200,
2543
+ { __etHandleRef: 203, type: '_et_item_203', platformInfo: { 'item-key': '203' } },
2544
+ 0,
2545
+ ]);
2546
+
2547
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(1);
2548
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[0]).toEqual([
2549
+ listRef,
2550
+ 0,
2551
+ {
2552
+ 'component-at-index': expect.any(Function),
2553
+ 'component-at-indexes': expect.any(Function),
2554
+ 'enqueue-component': expect.any(Function),
2555
+ 'update-list-info': {
2556
+ insertAction: [
2557
+ { position: 1, type: '_et_item_205', 'item-key': '205' },
2558
+ { position: 2, type: '_et_item_204', 'item-key': '204' },
2559
+ { position: 3, type: '_et_item_203', 'item-key': '203' },
2560
+ ],
2561
+ removeAction: [1, 2],
2562
+ updateAction: [],
2563
+ },
2564
+ },
2565
+ ]);
2566
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
2567
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
2568
+ });
2569
+
2570
+ it('coalesces platform info updates and indexes them after same-batch insertions', () => {
2571
+ envManager.switchToMainThread();
2572
+ const listRef = createMockElementTemplateHandle('typed-list', 210);
2573
+ const aRef = createMockElementTemplateHandle('a', 211);
2574
+ const bRef = createMockElementTemplateHandle('b', 212);
2575
+ const dRef = createMockElementTemplateHandle('d', 213);
2576
+ elementTemplateRegistry.set(210, listRef);
2577
+ elementTemplateRegistry.set(211, aRef);
2578
+ elementTemplateRegistry.set(212, bRef);
2579
+ elementTemplateRegistry.set(213, dRef);
2580
+ registerElementTemplateListItem(211, aRef, {
2581
+ templateKey: '_et_item_a',
2582
+ platformInfo: { 'item-key': 'a' },
2583
+ });
2584
+ registerElementTemplateListItem(212, bRef, {
2585
+ templateKey: '_et_item_b',
2586
+ platformInfo: { 'item-key': 'b' },
2587
+ });
2588
+ registerElementTemplateListState(210, createElementTemplateListState([211, 212]), false, listRef);
2589
+
2590
+ applyElementTemplateUpdateCommands([
2591
+ ElementTemplateUpdateOps.insertTypedListItem,
2592
+ 210,
2593
+ { __etHandleRef: 213, type: '_et_item_d', platformInfo: { 'item-key': 'd' } },
2594
+ 212,
2595
+ ElementTemplateUpdateOps.updateTypedListItem,
2596
+ 210,
2597
+ { __etHandleRef: 211, type: '_et_item_a', platformInfo: { 'item-key': 'a', 'full-span': true } },
2598
+ ElementTemplateUpdateOps.updateTypedListItem,
2599
+ 210,
2600
+ { __etHandleRef: 212, type: '_et_item_b', platformInfo: { 'item-key': 'b', 'estimated-height': 42 } },
2601
+ ]);
2602
+
2603
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(1);
2604
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![2]).toEqual(expect.objectContaining({
2605
+ 'update-list-info': {
2606
+ insertAction: [{ position: 1, type: '_et_item_d', 'item-key': 'd' }],
2607
+ removeAction: [],
2608
+ updateAction: [
2609
+ { from: 0, to: 0, type: '_et_item_a', flush: false, 'item-key': 'a', 'full-span': true },
2610
+ { from: 2, to: 2, type: '_et_item_b', flush: false, 'item-key': 'b', 'estimated-height': 42 },
2611
+ ],
2612
+ },
2613
+ }));
2614
+ });
2615
+
2616
+ it('skips no-op list item platform info updates', () => {
2617
+ envManager.switchToMainThread();
2618
+ const listRef = createMockElementTemplateHandle('typed-list', 214);
2619
+ const itemRef = createMockElementTemplateHandle('a', 2141);
2620
+ elementTemplateRegistry.set(214, listRef);
2621
+ elementTemplateRegistry.set(2141, itemRef);
2622
+ registerElementTemplateListItem(2141, itemRef, {
2623
+ templateKey: '_et_item_a',
2624
+ platformInfo: { 'item-key': 'a' },
2625
+ });
2626
+ registerElementTemplateListState(214, createElementTemplateListState([2141]), false, listRef);
2627
+
2628
+ applyElementTemplateUpdateCommands([
2629
+ ElementTemplateUpdateOps.updateTypedListItem,
2630
+ 214,
2631
+ { __etHandleRef: 2141, type: '_et_item_a', platformInfo: { 'item-key': 'a' } },
2632
+ ]);
2633
+
2634
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
2635
+ });
2636
+
2637
+ it('folds moved item platform info into the incremental insert action', () => {
2638
+ envManager.switchToMainThread();
2639
+ const listRef = createMockElementTemplateHandle('typed-list', 215);
2640
+ const aRef = createMockElementTemplateHandle('a', 216);
2641
+ const bRef = createMockElementTemplateHandle('b', 217);
2642
+ elementTemplateRegistry.set(215, listRef);
2643
+ elementTemplateRegistry.set(216, aRef);
2644
+ elementTemplateRegistry.set(217, bRef);
2645
+ registerElementTemplateListItem(216, aRef, {
2646
+ templateKey: '_et_item_a',
2647
+ platformInfo: { 'item-key': 'a' },
2648
+ });
2649
+ registerElementTemplateListItem(217, bRef, {
2650
+ templateKey: '_et_item_b',
2651
+ platformInfo: { 'item-key': 'b' },
2652
+ });
2653
+ registerElementTemplateListState(215, createElementTemplateListState([216, 217]), false, listRef);
2654
+
2655
+ applyElementTemplateUpdateCommands([
2656
+ ElementTemplateUpdateOps.removeTypedListItem,
2657
+ 215,
2658
+ 217,
2659
+ [],
2660
+ ElementTemplateUpdateOps.insertTypedListItem,
2661
+ 215,
2662
+ { __etHandleRef: 217, type: '_et_item_b', platformInfo: { 'item-key': 'b' } },
2663
+ 216,
2664
+ ElementTemplateUpdateOps.updateTypedListItem,
2665
+ 215,
2666
+ { __etHandleRef: 217, type: '_et_item_b', platformInfo: { 'item-key': 'b', 'full-span': true } },
2667
+ ]);
2668
+
2669
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(1);
2670
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![2]).toEqual(expect.objectContaining({
2671
+ 'update-list-info': {
2672
+ insertAction: [{ position: 0, type: '_et_item_b', 'item-key': 'b', 'full-span': true }],
2673
+ removeAction: [1],
2674
+ updateAction: [],
2675
+ },
2676
+ }));
2677
+ });
2678
+
2679
+ it('places an insertion before a moved item at the moved item final position', () => {
2680
+ envManager.switchToMainThread();
2681
+ const listRef = createMockElementTemplateHandle('typed-list', 218);
2682
+ const aRef = createMockElementTemplateHandle('a', 2181);
2683
+ const bRef = createMockElementTemplateHandle('b', 2182);
2684
+ const cRef = createMockElementTemplateHandle('c', 2183);
2685
+ const xRef = createMockElementTemplateHandle('x', 2184);
2686
+ elementTemplateRegistry.set(218, listRef);
2687
+ elementTemplateRegistry.set(2181, aRef);
2688
+ elementTemplateRegistry.set(2182, bRef);
2689
+ elementTemplateRegistry.set(2183, cRef);
2690
+ elementTemplateRegistry.set(2184, xRef);
2691
+ registerElementTemplateListItem(2181, aRef, {
2692
+ templateKey: '_et_item_a',
2693
+ platformInfo: { 'item-key': 'a' },
2694
+ });
2695
+ registerElementTemplateListItem(2182, bRef, {
2696
+ templateKey: '_et_item_b',
2697
+ platformInfo: { 'item-key': 'b' },
2698
+ });
2699
+ registerElementTemplateListItem(2183, cRef, {
2700
+ templateKey: '_et_item_c',
2701
+ platformInfo: { 'item-key': 'c' },
2702
+ });
2703
+ registerElementTemplateListState(218, createElementTemplateListState([2181, 2182, 2183]), false, listRef);
2704
+
2705
+ applyElementTemplateUpdateCommands([
2706
+ ElementTemplateUpdateOps.removeTypedListItem,
2707
+ 218,
2708
+ 2181,
2709
+ [],
2710
+ ElementTemplateUpdateOps.removeTypedListItem,
2711
+ 218,
2712
+ 2183,
2713
+ [2183],
2714
+ ElementTemplateUpdateOps.insertTypedListItem,
2715
+ 218,
2716
+ { __etHandleRef: 2181, type: '_et_item_a', platformInfo: { 'item-key': 'a', 'reuse-identifier': 'next' } },
2717
+ 0,
2718
+ ElementTemplateUpdateOps.insertTypedListItem,
2719
+ 218,
2720
+ { __etHandleRef: 2184, type: '_et_item_x', platformInfo: { 'item-key': 'x' } },
2721
+ 2181,
2722
+ ]);
2723
+
2724
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(1);
2725
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![2]).toEqual(expect.objectContaining({
2726
+ 'update-list-info': {
2727
+ insertAction: [
2728
+ { position: 1, type: '_et_item_x', 'item-key': 'x' },
2729
+ { position: 2, type: '_et_item_a', 'item-key': 'a', 'reuse-identifier': 'next' },
2730
+ ],
2731
+ removeAction: [0, 2],
2732
+ updateAction: [],
2733
+ },
2734
+ }));
2735
+ });
2736
+
2737
+ it('flushes incremental list updates with the latest slot 0 attributes regardless of stream order', () => {
2738
+ envManager.switchToMainThread();
2739
+ const listRef = createMockElementTemplateHandle('typed-list', 220);
2740
+ const firstRef = createMockElementTemplateHandle('first', 221);
2741
+ const secondRef = createMockElementTemplateHandle('second', 222);
2742
+ elementTemplateRegistry.set(220, listRef);
2743
+ elementTemplateRegistry.set(221, firstRef);
2744
+ elementTemplateRegistry.set(222, secondRef);
2745
+ registerElementTemplateListItem(221, firstRef, {
2746
+ templateKey: '_et_item_a',
2747
+ platformInfo: { 'item-key': 'a' },
2748
+ });
2749
+ registerElementTemplateListState(220, createElementTemplateListState([221], { id: 'old' }), false, listRef);
2750
+
2751
+ applyElementTemplateUpdateCommands([
2752
+ ElementTemplateUpdateOps.setAttribute,
2753
+ 220,
2754
+ 0,
2755
+ { id: 'intermediate' },
2756
+ ElementTemplateUpdateOps.insertTypedListItem,
2757
+ 220,
2758
+ { __etHandleRef: 222, type: '_et_item_b', platformInfo: { 'item-key': 'b' } },
2759
+ 0,
2760
+ ElementTemplateUpdateOps.setAttribute,
2761
+ 220,
2762
+ 0,
2763
+ { id: 'final' },
2764
+ ]);
2765
+
2766
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(3);
2767
+ const latestAttrWrite = mockSetElementTemplateAttributeSlot.mock.calls[1]![2] as Record<string, unknown>;
2768
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[2]![2]).toEqual(expect.objectContaining({
2769
+ id: 'final',
2770
+ 'update-list-info': {
2771
+ insertAction: [{ position: 1, type: '_et_item_b', 'item-key': 'b' }],
2772
+ removeAction: [],
2773
+ updateAction: [],
2774
+ },
2775
+ 'component-at-index': latestAttrWrite['component-at-index'],
2776
+ 'component-at-indexes': latestAttrWrite['component-at-indexes'],
2777
+ 'enqueue-component': latestAttrWrite['enqueue-component'],
2778
+ }));
2779
+ });
2780
+
2781
+ it('moves an attached item on native request', () => {
2782
+ envManager.switchToMainThread();
2783
+ const listRef = createMockElementTemplateHandle('typed-list', 225);
2784
+ const materializedList = createMaterializedListForFrontendTest(225);
2785
+ const aRef = createMockElementTemplateHandle('a', 226);
2786
+ const bRef = createMockElementTemplateHandle('b', 227);
2787
+ elementTemplateRegistry.set(225, listRef);
2788
+ elementTemplateRegistry.set(226, aRef);
2789
+ elementTemplateRegistry.set(227, bRef);
2790
+ registerElementTemplateListItem(226, aRef, {
2791
+ templateKey: '_et_item_a',
2792
+ platformInfo: { 'item-key': 'a' },
2793
+ });
2794
+ registerElementTemplateListItem(227, bRef, {
2795
+ templateKey: '_et_item_b',
2796
+ platformInfo: { 'item-key': 'b' },
2797
+ });
2798
+ const state = createElementTemplateListState([226, 227]);
2799
+ registerElementTemplateListState(225, state, false, listRef);
2800
+ const attrs = composeElementTemplateListAttributes(null, state);
2801
+ const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
2802
+ const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
2803
+ expect(componentAtIndex(materializedList, 7, 0, 88, false)).toBe(226);
2804
+ expect(componentAtIndex(materializedList, 7, 1, 89, false)).toBe(227);
2805
+ mockInsertElementTemplateNodeIntoSlot.mockClear();
2806
+ mockRemoveElementTemplateNodeFromSlot.mockClear();
2807
+
2808
+ applyElementTemplateUpdateCommands([
2809
+ ElementTemplateUpdateOps.removeTypedListItem,
2810
+ 225,
2811
+ 227,
2812
+ [],
2813
+ ElementTemplateUpdateOps.insertTypedListItem,
2814
+ 225,
2815
+ { __etHandleRef: 227, type: '_et_item_b', platformInfo: { 'item-key': 'b' } },
2816
+ 226,
2817
+ ]);
2818
+ mockInsertElementTemplateNodeIntoSlot.mockClear();
2819
+ mockRemoveElementTemplateNodeFromSlot.mockClear();
2820
+
2821
+ expect(componentAtIndex(materializedList, 7, 0, 90, false)).toBe(227);
2822
+
2823
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toEqual([[listRef, 0, bRef, aRef]]);
2824
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
2825
+ enqueueComponent(materializedList, 7, 227);
2826
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
2827
+ enqueueComponent(materializedList, 7, 227);
2828
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[listRef, 0, bRef]]);
2829
+ });
2830
+
2831
+ it('places multiple attached moves', () => {
2832
+ envManager.switchToMainThread();
2833
+ const listRef = createMockElementTemplateHandle('typed-list', 240);
2834
+ const materializedList = createMaterializedListForFrontendTest(240);
2835
+ const aRef = createMockElementTemplateHandle('a', 241);
2836
+ const bRef = createMockElementTemplateHandle('b', 242);
2837
+ const cRef = createMockElementTemplateHandle('c', 243);
2838
+ elementTemplateRegistry.set(240, listRef);
2839
+ elementTemplateRegistry.set(241, aRef);
2840
+ elementTemplateRegistry.set(242, bRef);
2841
+ elementTemplateRegistry.set(243, cRef);
2842
+ registerElementTemplateListItem(241, aRef, {
2843
+ templateKey: '_et_item_a',
2844
+ platformInfo: { 'item-key': 'a' },
2845
+ });
2846
+ registerElementTemplateListItem(242, bRef, {
2847
+ templateKey: '_et_item_b',
2848
+ platformInfo: { 'item-key': 'b' },
2849
+ });
2850
+ registerElementTemplateListItem(243, cRef, {
2851
+ templateKey: '_et_item_c',
2852
+ platformInfo: { 'item-key': 'c' },
2853
+ });
2854
+ const state = createElementTemplateListState([241, 242, 243]);
2855
+ registerElementTemplateListState(240, state, false, listRef);
2856
+ const attrs = composeElementTemplateListAttributes(null, state);
2857
+ const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
2858
+ const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
2859
+ expect(componentAtIndex(materializedList, 7, 0, 80, false)).toBe(241);
2860
+ expect(componentAtIndex(materializedList, 7, 1, 81, false)).toBe(242);
2861
+ expect(componentAtIndex(materializedList, 7, 2, 82, false)).toBe(243);
2862
+ mockInsertElementTemplateNodeIntoSlot.mockClear();
2863
+ mockRemoveElementTemplateNodeFromSlot.mockClear();
2864
+
2865
+ applyElementTemplateUpdateCommands([
2866
+ ElementTemplateUpdateOps.removeTypedListItem,
2867
+ 240,
2868
+ 243,
2869
+ [],
2870
+ ElementTemplateUpdateOps.insertTypedListItem,
2871
+ 240,
2872
+ { __etHandleRef: 243, type: '_et_item_c', platformInfo: { 'item-key': 'c' } },
2873
+ 241,
2874
+ ElementTemplateUpdateOps.removeTypedListItem,
2875
+ 240,
2876
+ 241,
2877
+ [],
2878
+ ElementTemplateUpdateOps.insertTypedListItem,
2879
+ 240,
2880
+ { __etHandleRef: 241, type: '_et_item_a', platformInfo: { 'item-key': 'a' } },
2881
+ 0,
2882
+ ]);
2883
+ mockInsertElementTemplateNodeIntoSlot.mockClear();
2884
+ mockRemoveElementTemplateNodeFromSlot.mockClear();
2885
+
2886
+ expect(componentAtIndex(materializedList, 7, 0, 90, false)).toBe(243);
2887
+
2888
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toEqual([
2889
+ [listRef, 0, aRef, null],
2890
+ [listRef, 0, cRef, bRef],
2891
+ ]);
2892
+ enqueueComponent(materializedList, 7, 243);
2893
+ enqueueComponent(materializedList, 7, 241);
2894
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
2895
+ expect(componentAtIndex(materializedList, 7, 1, 91, false)).toBe(242);
2896
+ });
2897
+
2898
+ it('preserves moved item registry during removal', () => {
2899
+ envManager.switchToMainThread();
2900
+ const listRef = createMockElementTemplateHandle('typed-list', 230);
2901
+ const materializedList = createMaterializedListForFrontendTest(230);
2902
+ const firstRef = createMockElementTemplateHandle('first', 231);
2903
+ const secondRef = createMockElementTemplateHandle('second', 232);
2904
+ elementTemplateRegistry.set(230, listRef);
2905
+ elementTemplateRegistry.set(231, firstRef);
2906
+ elementTemplateRegistry.set(232, secondRef);
2907
+ registerElementTemplateListItem(231, firstRef, {
2908
+ templateKey: '_et_item_a',
2909
+ platformInfo: { 'item-key': 'a' },
2910
+ });
2911
+ registerElementTemplateListItem(232, secondRef, {
2912
+ templateKey: '_et_item_b',
2913
+ platformInfo: { 'item-key': 'b' },
2914
+ });
2915
+ const state = createElementTemplateListState([231, 232]);
2916
+ registerElementTemplateListState(230, state, false, listRef);
2917
+ const attrs = composeElementTemplateListAttributes(null, state);
2918
+ const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
2919
+ const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
2920
+ expect(componentAtIndex(materializedList, 7, 1, 88, false)).toBe(232);
2921
+ mockInsertElementTemplateNodeIntoSlot.mockClear();
2922
+ mockRemoveElementTemplateNodeFromSlot.mockClear();
2923
+
2924
+ applyElementTemplateUpdateCommands([
2925
+ ElementTemplateUpdateOps.removeTypedListItem,
2926
+ 230,
2927
+ 232,
2928
+ [],
2929
+ ElementTemplateUpdateOps.insertTypedListItem,
2930
+ 230,
2931
+ { __etHandleRef: 232, type: '_et_item_b', platformInfo: { 'item-key': 'b' } },
2932
+ 231,
2933
+ ElementTemplateUpdateOps.removeTypedListItem,
2934
+ 230,
2935
+ 231,
2936
+ [231],
2937
+ ]);
2938
+ enqueueComponent(materializedList, 7, 232);
2939
+ enqueueComponent(materializedList, 7, 231);
2940
+
2941
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![2]).toEqual(expect.objectContaining({
2942
+ 'update-list-info': {
2943
+ insertAction: [{ position: 0, type: '_et_item_b', 'item-key': 'b' }],
2944
+ removeAction: [0, 1],
2945
+ updateAction: [],
2946
+ },
2947
+ }));
2948
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[listRef, 0, secondRef]]);
2949
+ expect(elementTemplateRegistry.get(231)).toBeUndefined();
2950
+ expect(elementTemplateRegistry.get(232)).toBe(secondRef);
2951
+ });
2952
+
2953
+ it('retains callback lookup until native enqueue', () => {
2954
+ envManager.switchToMainThread();
2955
+ const listRef = createMockElementTemplateHandle('typed-list', 110);
2956
+ const materializedList = createMaterializedListForFrontendTest(110);
2957
+ const firstRef = createMockElementTemplateHandle('first', 111);
2958
+ elementTemplateRegistry.set(41, listRef);
2959
+ elementTemplateRegistry.set(42, firstRef);
2960
+ registerElementTemplateListItem(42, firstRef, {
2961
+ templateKey: '_et_item_a',
2962
+ platformInfo: { 'item-key': 'a' },
2963
+ });
2964
+ const state = createElementTemplateListState([42]);
2965
+ registerElementTemplateListState(41, state, false, listRef);
2966
+ const attrs = composeElementTemplateListAttributes(null, state);
2967
+ const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
2968
+
2969
+ expect(componentAtIndex(materializedList, 7, 0, 88, false)).toBe(111);
2970
+ mockRemoveElementTemplateNodeFromSlot.mockClear();
2971
+ let enqueueComponent: EnqueueComponentCallback | undefined;
2972
+ mockSetElementTemplateAttributeSlot.mockImplementationOnce((...args: unknown[]) => {
2973
+ const attrs = args[2] as Record<string, unknown>;
2974
+ enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
2975
+ enqueueComponent(materializedList, 7, 111);
2976
+ lastMock!.mockSetElementTemplateAttributeSlot(...args);
2977
+ });
2978
+
2979
+ applyElementTemplateUpdateCommands([
2980
+ ElementTemplateUpdateOps.removeTypedListItem,
2981
+ 41,
2982
+ 42,
2983
+ [42],
2984
+ ]);
2985
+
2986
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[listRef, 0, firstRef]]);
2987
+ expect(elementTemplateRegistry.get(42)).toBeUndefined();
2988
+ enqueueComponent!(materializedList, 7, 111);
2989
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(1);
2990
+ });
2991
+
2992
+ it('detaches by attached state', () => {
2993
+ envManager.switchToMainThread();
2994
+ const listRef = createMockElementTemplateHandle('typed-list', 140);
2995
+ const materializedList = createMaterializedListForFrontendTest(140);
2996
+ const itemRef = createMockElementTemplateHandle('item', 141);
2997
+ elementTemplateRegistry.set(140, listRef);
2998
+ elementTemplateRegistry.set(141, itemRef);
2999
+ registerElementTemplateListItem(141, itemRef, {
3000
+ templateKey: '_et_item_a',
3001
+ platformInfo: { 'item-key': 'a' },
3002
+ });
3003
+ const state = createElementTemplateListState([141]);
3004
+ registerElementTemplateListState(140, state, false, listRef);
3005
+ const attrs = composeElementTemplateListAttributes(null, state);
3006
+ const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
3007
+ const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
3008
+
3009
+ expect(componentAtIndex(materializedList, 7, 0, 88, false)).toBe(141);
3010
+ state.items[0]!.attached = false;
3011
+ mockRemoveElementTemplateNodeFromSlot.mockClear();
3012
+
3013
+ enqueueComponent(materializedList, 7, 141);
3014
+ enqueueComponent(materializedList, 7, 141);
3015
+
3016
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
3017
+ });
3018
+
3019
+ it('releases removed list item subtrees after the final update-list-info write', () => {
3020
+ envManager.switchToMainThread();
3021
+ const outerListRef = {
3022
+ __isNativeRef: true,
3023
+ id: 'outer-list',
3024
+ __mockNativeId: 300,
3025
+ } as unknown as ElementTemplateHandle;
3026
+ const itemRef = createMockElementTemplateHandle('item', 301);
3027
+ const nestedListRef = {
3028
+ __isNativeRef: true,
3029
+ id: 'nested-list',
3030
+ __mockNativeId: 302,
3031
+ } as unknown as ElementTemplateHandle;
3032
+ const nestedItemRef = {
3033
+ __isNativeRef: true,
3034
+ id: 'nested-item',
3035
+ __mockNativeId: 303,
3036
+ } as unknown as ElementTemplateHandle;
3037
+ elementTemplateRegistry.set(300, outerListRef);
3038
+ elementTemplateRegistry.set(301, itemRef);
3039
+ elementTemplateRegistry.set(302, nestedListRef);
3040
+ elementTemplateRegistry.set(303, nestedItemRef);
3041
+ registerElementTemplateListItem(301, itemRef, {
3042
+ templateKey: '_et_item',
3043
+ platformInfo: { 'item-key': 'outer' },
3044
+ });
3045
+ registerElementTemplateListState(300, createElementTemplateListState([301]), false, outerListRef);
3046
+ registerElementTemplateListItem(303, nestedItemRef, {
3047
+ templateKey: '_et_nested_item',
3048
+ platformInfo: { 'item-key': 'nested' },
3049
+ });
3050
+ const nestedState = createElementTemplateListState([303]);
3051
+ registerElementTemplateListState(302, nestedState, false, nestedListRef);
3052
+ const nestedAttrs = composeElementTemplateListAttributes(null, nestedState);
3053
+ const nestedComponentAtIndex = nestedAttrs['component-at-index'] as ComponentAtIndexCallback;
3054
+
3055
+ applyElementTemplateUpdateCommands([
3056
+ ElementTemplateUpdateOps.removeTypedListItem,
3057
+ 300,
3058
+ 301,
3059
+ [301, 302, 303],
3060
+ ]);
3061
+
3062
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![0]).toBe(outerListRef);
3063
+ expect(elementTemplateRegistry.get(301)).toBeUndefined();
3064
+ expect(elementTemplateRegistry.get(302)).toBeUndefined();
3065
+ expect(elementTemplateRegistry.get(303)).toBeUndefined();
3066
+ expect(nestedComponentAtIndex(createMaterializedListForFrontendTest(302), 8, 0, 91, false)).toBe(-1);
3067
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
3068
+ });
3069
+
3070
+ it('drains pending item cleanup when the list holder is removed in the same patch', () => {
3071
+ envManager.switchToMainThread();
3072
+ const parentRef = createMockElementTemplateHandle('parent', 299);
3073
+ const listRef = createMockElementTemplateHandle('list', 300);
3074
+ const itemRef = createMockElementTemplateHandle('item', 301);
3075
+ const nestedListRef = {
3076
+ __isNativeRef: true,
3077
+ id: 'nested-list',
3078
+ __mockNativeId: 302,
3079
+ } as unknown as ElementTemplateHandle;
3080
+ const nestedItemRef = {
3081
+ __isNativeRef: true,
3082
+ id: 'nested-item',
3083
+ __mockNativeId: 303,
3084
+ } as unknown as ElementTemplateHandle;
3085
+ elementTemplateRegistry.set(299, parentRef);
3086
+ elementTemplateRegistry.set(300, listRef);
3087
+ elementTemplateRegistry.set(301, itemRef);
3088
+ elementTemplateRegistry.set(302, nestedListRef);
3089
+ elementTemplateRegistry.set(303, nestedItemRef);
3090
+ registerElementTemplateListItem(301, itemRef, {
3091
+ templateKey: '_et_item',
3092
+ platformInfo: { 'item-key': 'outer' },
3093
+ });
3094
+ registerElementTemplateListState(300, createElementTemplateListState([301]), false, listRef);
3095
+ registerElementTemplateListItem(303, nestedItemRef, {
3096
+ templateKey: '_et_nested_item',
3097
+ platformInfo: { 'item-key': 'nested' },
3098
+ });
3099
+ const nestedState = createElementTemplateListState([303]);
3100
+ registerElementTemplateListState(302, nestedState, false, nestedListRef);
3101
+ const nestedAttrs = composeElementTemplateListAttributes(null, nestedState);
3102
+ const nestedComponentAtIndex = nestedAttrs['component-at-index'] as ComponentAtIndexCallback;
3103
+
3104
+ applyElementTemplateUpdateCommands([
3105
+ ElementTemplateUpdateOps.removeTypedListItem,
3106
+ 300,
3107
+ 301,
3108
+ [301, 302, 303],
3109
+ ElementTemplateUpdateOps.removeNode,
3110
+ 299,
3111
+ 0,
3112
+ 300,
3113
+ [300],
3114
+ ]);
3115
+
3116
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[parentRef, 0, listRef]]);
3117
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
3118
+ expect(elementTemplateRegistry.get(300)).toBeUndefined();
3119
+ expect(elementTemplateRegistry.get(301)).toBeUndefined();
3120
+ expect(elementTemplateRegistry.get(302)).toBeUndefined();
3121
+ expect(elementTemplateRegistry.get(303)).toBeUndefined();
3122
+ expect(nestedComponentAtIndex(createMaterializedListForFrontendTest(302), 8, 0, 91, false)).toBe(-1);
3123
+ });
3124
+
3125
+ it('emits Snapshot-shaped update-list-info for incremental reorder with platform info changes', () => {
3126
+ envManager.switchToMainThread();
3127
+ const listRef = createMockElementTemplateHandle('typed-list', 115);
3128
+ const firstRef = createMockElementTemplateHandle('first', 116);
3129
+ const secondRef = createMockElementTemplateHandle('second', 117);
3130
+ elementTemplateRegistry.set(51, listRef);
3131
+ elementTemplateRegistry.set(52, firstRef);
3132
+ elementTemplateRegistry.set(53, secondRef);
3133
+ registerElementTemplateListItem(52, firstRef, {
3134
+ templateKey: '_et_item_a',
3135
+ platformInfo: { 'item-key': 'a', 'reuse-identifier': 'old' },
3136
+ });
3137
+ registerElementTemplateListItem(53, secondRef, {
3138
+ templateKey: '_et_item_b',
3139
+ platformInfo: { 'item-key': 'b' },
3140
+ });
3141
+ const state = createElementTemplateListState([52, 53]);
3142
+ registerElementTemplateListState(51, state, false, listRef);
3143
+
3144
+ applyElementTemplateUpdateCommands([
3145
+ ElementTemplateUpdateOps.removeTypedListItem,
3146
+ 51,
3147
+ 52,
3148
+ [],
3149
+ ElementTemplateUpdateOps.insertTypedListItem,
3150
+ 51,
3151
+ {
3152
+ __etHandleRef: 52,
3153
+ type: '_et_item_a',
3154
+ platformInfo: { 'item-key': 'a', 'reuse-identifier': 'old' },
3155
+ },
3156
+ 0,
3157
+ ElementTemplateUpdateOps.updateTypedListItem,
3158
+ 51,
3159
+ {
3160
+ __etHandleRef: 52,
3161
+ type: '_et_item_a',
3162
+ platformInfo: { 'item-key': 'a', 'reuse-identifier': 'new' },
3163
+ },
3164
+ ]);
3165
+
3166
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[0]).toEqual([
3167
+ listRef,
3168
+ 0,
3169
+ {
3170
+ 'component-at-index': expect.any(Function),
3171
+ 'component-at-indexes': expect.any(Function),
3172
+ 'enqueue-component': expect.any(Function),
3173
+ 'update-list-info': {
3174
+ insertAction: [{ position: 1, type: '_et_item_a', 'item-key': 'a', 'reuse-identifier': 'new' }],
3175
+ removeAction: [0],
3176
+ updateAction: [],
3177
+ },
3178
+ },
3179
+ ]);
3180
+ });
3181
+
3182
+ it('emits Snapshot-shaped update-list-info for standalone platform info updates', () => {
3183
+ envManager.switchToMainThread();
3184
+ const listRef = createMockElementTemplateHandle('typed-list', 145);
3185
+ const itemRef = createMockElementTemplateHandle('item', 146);
3186
+ elementTemplateRegistry.set(81, listRef);
3187
+ elementTemplateRegistry.set(82, itemRef);
3188
+ registerElementTemplateListItem(82, itemRef, {
3189
+ templateKey: '_et_item',
3190
+ platformInfo: { 'item-key': 'a' },
3191
+ });
3192
+ const state = createElementTemplateListState([82]);
3193
+ registerElementTemplateListState(81, state, false, listRef);
3194
+
3195
+ applyElementTemplateUpdateCommands([
3196
+ ElementTemplateUpdateOps.updateTypedListItem,
3197
+ 81,
3198
+ {
3199
+ __etHandleRef: 82,
3200
+ type: '_et_item',
3201
+ platformInfo: { 'item-key': 'a', 'reuse-identifier': 'next' },
3202
+ },
3203
+ ]);
3204
+
3205
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[0]).toEqual([
3206
+ listRef,
3207
+ 0,
3208
+ {
3209
+ 'component-at-index': expect.any(Function),
3210
+ 'component-at-indexes': expect.any(Function),
3211
+ 'enqueue-component': expect.any(Function),
3212
+ 'update-list-info': {
3213
+ insertAction: [],
3214
+ removeAction: [],
3215
+ updateAction: [{
3216
+ from: 0,
3217
+ to: 0,
3218
+ type: '_et_item',
3219
+ flush: false,
3220
+ 'item-key': 'a',
3221
+ 'reuse-identifier': 'next',
3222
+ }],
3223
+ },
3224
+ },
3225
+ ]);
3226
+ });
3227
+
3228
+ it('moves attached items without detached siblings', () => {
3229
+ envManager.switchToMainThread();
3230
+ const listRef = createMockElementTemplateHandle('typed-list', 135);
3231
+ const materializedList = createMaterializedListForFrontendTest(135);
3232
+ const firstRef = createMockElementTemplateHandle('first', 136);
3233
+ const secondRef = createMockElementTemplateHandle('second', 137);
3234
+ elementTemplateRegistry.set(71, listRef);
3235
+ elementTemplateRegistry.set(72, firstRef);
3236
+ elementTemplateRegistry.set(73, secondRef);
3237
+ registerElementTemplateListItem(72, firstRef, {
3238
+ templateKey: '_et_item_a',
3239
+ platformInfo: { 'item-key': 'a' },
3240
+ });
3241
+ registerElementTemplateListItem(73, secondRef, {
3242
+ templateKey: '_et_item_b',
3243
+ platformInfo: { 'item-key': 'b' },
3244
+ });
3245
+ const state = createElementTemplateListState([72, 73]);
3246
+ registerElementTemplateListState(71, state, false, listRef);
3247
+ const attrs = composeElementTemplateListAttributes(null, state);
3248
+ const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
3249
+
3250
+ expect(componentAtIndex(materializedList, 7, 0, 91, false)).toBe(136);
3251
+ mockInsertElementTemplateNodeIntoSlot.mockClear();
3252
+ mockFlushElementTree.mockClear();
3253
+
3254
+ applyElementTemplateUpdateCommands([
3255
+ ElementTemplateUpdateOps.removeTypedListItem,
3256
+ 71,
3257
+ 72,
3258
+ [],
3259
+ ElementTemplateUpdateOps.insertTypedListItem,
3260
+ 71,
3261
+ {
3262
+ __etHandleRef: 72,
3263
+ type: '_et_item_a',
3264
+ platformInfo: { 'item-key': 'a' },
3265
+ },
3266
+ 0,
3267
+ ]);
3268
+ mockInsertElementTemplateNodeIntoSlot.mockClear();
3269
+
3270
+ expect(componentAtIndex(materializedList, 7, 1, 92, false)).toBe(136);
3271
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toEqual([[listRef, 0, firstRef, null]]);
3272
+ });
3273
+
3274
+ it('treats same-key list item replacement with a new ref as remove and insert', () => {
3275
+ envManager.switchToMainThread();
3276
+ const listRef = createMockElementTemplateHandle('typed-list', 125);
3277
+ const oldRef = createMockElementTemplateHandle('old', 126);
3278
+ const nextRef = createMockElementTemplateHandle('next', 127);
3279
+ elementTemplateRegistry.set(61, listRef);
3280
+ elementTemplateRegistry.set(62, oldRef);
3281
+ elementTemplateRegistry.set(63, nextRef);
3282
+ registerElementTemplateListItem(62, oldRef, {
3283
+ templateKey: '_et_item',
3284
+ platformInfo: { 'item-key': 'same' },
3285
+ });
3286
+ const state = createElementTemplateListState([62]);
3287
+ registerElementTemplateListState(61, state, false, listRef);
3288
+
3289
+ applyElementTemplateUpdateCommands([
3290
+ ElementTemplateUpdateOps.removeTypedListItem,
3291
+ 61,
3292
+ 62,
3293
+ [62],
3294
+ ElementTemplateUpdateOps.insertTypedListItem,
3295
+ 61,
3296
+ {
3297
+ __etHandleRef: 63,
3298
+ type: '_et_item',
3299
+ platformInfo: { 'item-key': 'same' },
3300
+ },
3301
+ 0,
3302
+ ]);
3303
+
3304
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![2]).toEqual(expect.objectContaining({
3305
+ 'update-list-info': {
3306
+ insertAction: [{ position: 0, type: '_et_item', 'item-key': 'same' }],
3307
+ removeAction: [0],
3308
+ updateAction: [],
3309
+ },
3310
+ }));
3311
+ expect(elementTemplateRegistry.get(62)).toBeUndefined();
3312
+ });
3313
+
3314
+ it('keeps destroyed typed list callbacks Snapshot-safe', () => {
3315
+ envManager.switchToMainThread();
3316
+ const listRef = 120 as unknown as ElementTemplateHandle;
3317
+ const itemRef = 121 as unknown as ElementTemplateHandle;
3318
+ registerElementTemplateListItem(121, itemRef, {
3319
+ templateKey: '_et_item',
3320
+ platformInfo: { 'item-key': 'a' },
3321
+ });
3322
+ const state = createElementTemplateListState([121]);
3323
+ registerElementTemplateListState(120, state, false, listRef);
3324
+ const attrs = composeElementTemplateListAttributes(null, state);
3325
+ const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
3326
+ const componentAtIndexes = attrs['component-at-indexes'] as ComponentAtIndexesCallback;
3327
+ const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
3328
+ const materializedList = { id: 'materialized-list' } as unknown as FiberElement;
3329
+
3330
+ markElementTemplateListDestroyed(120);
3331
+
3332
+ expect(componentAtIndex(materializedList, 7, 0, 99, false)).toBe(-1);
3333
+ componentAtIndexes(materializedList, 7, [0], [99], false, true);
3334
+ enqueueComponent(materializedList, 7, 121);
3335
+
3336
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
3337
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
3338
+ expect(mockFlushElementTree.mock.calls).toHaveLength(0);
3339
+ });
3340
+
3341
+ it('skips typed slot 0 attributes when the target handle is unresolved', () => {
3342
+ envManager.switchToMainThread();
3343
+ elementTemplateRegistry.clear();
3344
+ mockSetAttribute.mockClear();
3345
+ mockSetElementTemplateAttributeSlot.mockClear();
3346
+
3347
+ applyElementTemplateUpdateCommands([
3348
+ ElementTemplateUpdateOps.setAttribute,
3349
+ 404,
3350
+ 0,
3351
+ null,
3352
+ ]);
3353
+
3354
+ expect(mockSetAttribute.mock.calls).toHaveLength(0);
3355
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
3356
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
3357
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('target handle 404 not found');
3358
+ resetReportedErrors();
3359
+ });
3360
+
3361
+ it('reports missing handle when resolving references', () => {
3362
+ const jsx = <view />;
3363
+ root.render(jsx);
3364
+ envManager.switchToMainThread();
3365
+ root.render(jsx);
3366
+ renderPage();
3367
+
3368
+ applyElementTemplateUpdateCommands([ElementTemplateUpdateOps.insertNode, -1, 0, 999, 0, []]);
3369
+
3370
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
3371
+ expect(reportError.mock.calls).toHaveLength(1);
3372
+ resetReportedErrors();
3373
+ });
3374
+
3375
+ it('reports a missing insert reference before calling the native PAPI', () => {
3376
+ envManager.switchToMainThread();
3377
+ const targetRef = { __isNativeRef: true, id: 'target' } as unknown as ElementTemplateHandle;
3378
+ const childRef = { __isNativeRef: true, id: 'child' } as unknown as ElementTemplateHandle;
3379
+ elementTemplateRegistry.set(600, targetRef);
3380
+ elementTemplateRegistry.set(601, childRef);
3381
+ mockInsertElementTemplateNodeIntoSlot.mockClear();
3382
+
3383
+ applyElementTemplateUpdateCommands([
3384
+ ElementTemplateUpdateOps.insertNode,
3385
+ 600,
3386
+ 0,
3387
+ 601,
3388
+ 999,
3389
+ [601],
3390
+ ]);
3391
+
3392
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
3393
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
3394
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('reference handle 999 not found');
3395
+ resetReportedErrors();
3396
+ });
3397
+
3398
+ it('reports a missing insert subtree handle before calling the native PAPI', () => {
3399
+ envManager.switchToMainThread();
3400
+ const targetRef = { __isNativeRef: true, id: 'target' } as unknown as ElementTemplateHandle;
3401
+ const childRef = { __isNativeRef: true, id: 'child' } as unknown as ElementTemplateHandle;
3402
+ elementTemplateRegistry.set(600, targetRef);
3403
+ elementTemplateRegistry.set(601, childRef);
3404
+ mockInsertElementTemplateNodeIntoSlot.mockClear();
3405
+
3406
+ applyElementTemplateUpdateCommands([
3407
+ ElementTemplateUpdateOps.insertNode,
3408
+ 600,
3409
+ 0,
3410
+ 601,
3411
+ 0,
3412
+ [999],
3413
+ ]);
3414
+
3415
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
3416
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
3417
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('insert subtree handle 999 not found');
3418
+ resetReportedErrors();
3419
+ });
3420
+
3421
+ it('reports missing child handle on removeNode', () => {
3422
+ envManager.switchToMainThread();
3423
+ const targetRef = createMockElementTemplateHandle('target');
3424
+ const descendantRef = createMockElementTemplateHandle('descendant');
3425
+ elementTemplateRegistry.set(1, targetRef);
3426
+ elementTemplateRegistry.set(12, descendantRef);
3427
+
3428
+ applyElementTemplateUpdateCommands([ElementTemplateUpdateOps.removeNode, 1, 0, 999, [12]]);
3429
+
3430
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
3431
+ expect(elementTemplateRegistry.has(12)).toBe(true);
3432
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
3433
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('child handle 999 not found');
3434
+ resetReportedErrors();
3435
+ });
3436
+
3437
+ it('reports missing target handle on removeNode without deleting subtree registry entries', () => {
3438
+ envManager.switchToMainThread();
3439
+ const childRef = createMockElementTemplateHandle('child');
3440
+ const descendantRef = createMockElementTemplateHandle('descendant');
3441
+ elementTemplateRegistry.set(11, childRef);
3442
+ elementTemplateRegistry.set(12, descendantRef);
3443
+
3444
+ applyElementTemplateUpdateCommands([ElementTemplateUpdateOps.removeNode, 999, 0, 11, [11, 12]]);
3445
+
3446
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
3447
+ expect(elementTemplateRegistry.has(11)).toBe(true);
3448
+ expect(elementTemplateRegistry.has(12)).toBe(true);
3449
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
3450
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('target handle 999 not found');
3451
+ resetReportedErrors();
3452
+ });
3453
+
3454
+ it('removes registry entries for the detached subtree after native remove succeeds', () => {
3455
+ envManager.switchToMainThread();
3456
+ elementTemplateRegistry.clear();
3457
+
3458
+ const targetRef = createMockElementTemplateHandle('target');
3459
+ const beforeRef = createMockElementTemplateHandle('before');
3460
+ const childRef = createMockElementTemplateHandle('child');
3461
+ const descendantRef = createMockElementTemplateHandle('descendant');
3462
+ elementTemplateRegistry.set(1, targetRef);
3463
+ elementTemplateRegistry.set(10, beforeRef);
3464
+ elementTemplateRegistry.set(11, childRef);
3465
+ elementTemplateRegistry.set(12, descendantRef);
3466
+
3467
+ const stream: ElementTemplateUpdateCommandStream = [
3468
+ ElementTemplateUpdateOps.insertNode,
3469
+ 1,
3470
+ 0,
3471
+ 11,
3472
+ 10,
3473
+ [11, 12],
3474
+ ElementTemplateUpdateOps.removeNode,
3475
+ 1,
3476
+ 0,
3477
+ 11,
3478
+ [11, 12],
3479
+ ];
3480
+
3481
+ applyElementTemplateUpdateCommands(stream);
3482
+
3483
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls[0]?.[0]).toBe(targetRef);
3484
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls[0]?.[2]).toBe(childRef);
3485
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls[0]?.[3]).toBe(beforeRef);
3486
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls[0]?.[0]).toBe(targetRef);
3487
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls[0]?.[2]).toBe(childRef);
3488
+ expect(elementTemplateRegistry.has(1)).toBe(true);
3489
+ expect(elementTemplateRegistry.has(10)).toBe(true);
3490
+ expect(elementTemplateRegistry.has(11)).toBe(false);
3491
+ expect(elementTemplateRegistry.has(12)).toBe(false);
3492
+ });
3493
+
3494
+ it('marks nested typed list state destroyed when removing a holder subtree', () => {
3495
+ envManager.switchToMainThread();
3496
+ elementTemplateRegistry.clear();
3497
+
3498
+ const targetRef = createMockElementTemplateHandle('target');
3499
+ const childRef = createMockElementTemplateHandle('child');
3500
+ const listRef = createMockElementTemplateHandle('typed-list', 132);
3501
+ const itemRef = createMockElementTemplateHandle('item', 131);
3502
+ elementTemplateRegistry.set(70, targetRef);
3503
+ elementTemplateRegistry.set(71, childRef);
3504
+ elementTemplateRegistry.set(72, listRef);
3505
+ elementTemplateRegistry.set(73, itemRef);
3506
+ registerElementTemplateListItem(73, itemRef, {
3507
+ templateKey: '_et_item',
3508
+ platformInfo: { 'item-key': 'a' },
3509
+ });
3510
+ const state = createElementTemplateListState([73]);
3511
+ registerElementTemplateListState(72, state, false, listRef);
3512
+ const attrs = composeElementTemplateListAttributes(null, state);
3513
+ const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
3514
+ const componentAtIndexes = attrs['component-at-indexes'] as ComponentAtIndexesCallback;
3515
+ const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
3516
+ const materializedList = { id: 'materialized-list' } as unknown as FiberElement;
3517
+
3518
+ removeElementTemplateListItem(72, 73, [73]);
3519
+
3520
+ applyElementTemplateUpdateCommands([
3521
+ ElementTemplateUpdateOps.removeNode,
3522
+ 70,
3523
+ 0,
3524
+ 71,
3525
+ [71, 72],
3526
+ ]);
3527
+
3528
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[targetRef, 0, childRef]]);
3529
+ expect(elementTemplateRegistry.has(71)).toBe(false);
3530
+ expect(elementTemplateRegistry.has(72)).toBe(false);
3531
+ expect(elementTemplateRegistry.has(73)).toBe(false);
3532
+ mockRemoveElementTemplateNodeFromSlot.mockClear();
3533
+
3534
+ expect(componentAtIndex(materializedList, 7, 0, 99, false)).toBe(-1);
3535
+ componentAtIndexes(materializedList, 7, [0], [99], false, true);
3536
+ enqueueComponent(materializedList, 7, 131);
3537
+
3538
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
3539
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
3540
+ expect(mockFlushElementTree.mock.calls).toHaveLength(0);
3541
+ });
3542
+
3543
+ it('creates builtin raw-text template from attributeSlots', () => {
3544
+ const jsx = <view />;
3545
+ root.render(jsx);
3546
+ envManager.switchToMainThread();
3547
+ root.render(jsx);
3548
+ renderPage();
3549
+
3550
+ applyElementTemplateUpdateCommands(createRawTextOps(1, 'x'));
3551
+
3552
+ expect(serializeToJSX(__page)).toMatchInlineSnapshot(`
3553
+ "<page>
3554
+ <view />
3555
+ </page>"
3556
+ `);
3557
+ });
3558
+
3559
+ it('creates template with empty slots when payload is null', () => {
3560
+ const jsx = <view />;
3561
+ root.render(jsx);
3562
+ envManager.switchToMainThread();
3563
+ root.render(jsx);
3564
+ renderPage();
3565
+
3566
+ const templateKey = (__page as unknown as PageWithChildren).children?.[0]?.templateId;
3567
+ if (!templateKey) {
3568
+ throw new Error('Missing templateId on first page child');
3569
+ }
3570
+ applyElementTemplateUpdateCommands([
3571
+ ElementTemplateUpdateOps.createTemplate,
3572
+ 7,
3573
+ templateKey,
3574
+ null,
3575
+ null,
3576
+ null,
3577
+ ]);
3578
+
3579
+ expect(serializeToJSX(__page)).toMatchInlineSnapshot(`
3580
+ "<page>
3581
+ <view />
3582
+ </page>"
3583
+ `);
3584
+ });
3585
+
3586
+ it('reuses create attribute slots normalized by the update transport', () => {
3587
+ envManager.switchToMainThread();
3588
+ const createTemplateMock = globalThis.__CreateElementTemplate as unknown as {
3589
+ mockClear: () => void;
3590
+ mock: { calls: unknown[][] };
3591
+ };
3592
+ createTemplateMock.mockClear();
3593
+
3594
+ const rawSlots = [undefined, 'x'];
3595
+ rawSlots.length = 3;
3596
+ const event = createElementTemplateUpdateEvent({
3597
+ ops: [
3598
+ ElementTemplateUpdateOps.createTemplate,
3599
+ 8,
3600
+ '_et_builtin_raw_text',
3601
+ null,
3602
+ rawSlots as unknown as ElementTemplateUpdateCommandStream[number],
3603
+ [],
3604
+ ],
3605
+ flushOptions: {},
3606
+ });
3607
+ const payload = parseElementTemplateUpdateEventPayload(event.data);
3608
+ const attributeSlots = payload.ops[4];
3609
+ expect(attributeSlots).toEqual([null, 'x', null]);
3610
+
3611
+ applyElementTemplateUpdateCommands(payload.ops);
3612
+
3613
+ expect(createTemplateMock.mock.calls[0]?.[2]).toBe(attributeSlots);
3614
+ });
3615
+
3616
+ it('passes bundleUrl from createTemplate patch to native create', () => {
3617
+ envManager.switchToMainThread();
3618
+ const createTemplateMock = globalThis.__CreateElementTemplate as unknown as {
3619
+ mockClear: () => void;
3620
+ mock: { calls: unknown[][] };
3621
+ };
3622
+ createTemplateMock.mockClear();
3623
+
3624
+ applyElementTemplateUpdateCommands([
3625
+ ElementTemplateUpdateOps.createTemplate,
3626
+ 9,
3627
+ '_et_builtin_raw_text',
3628
+ 'dynamic-entry',
3629
+ ['x'],
3630
+ [],
3631
+ ]);
3632
+
3633
+ expect(createTemplateMock.mock.calls[0]?.[1]).toBe('dynamic-entry');
3634
+ });
3635
+
3636
+ it('reports unsupported opcodes', () => {
3637
+ applyElementTemplateUpdateCommands([999 as unknown as ElementTemplateUpdateCommandStream[number]]);
3638
+
3639
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
3640
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('opcode 999 is not supported');
3641
+ resetReportedErrors();
3642
+ });
3643
+
3644
+ it('resolves childSlots defensively for invalid payload members', () => {
3645
+ envManager.switchToMainThread();
3646
+ registerTemplates([
3647
+ {
3648
+ templateId: '_et_patch_parent',
3649
+ compiledTemplate: {
3650
+ kind: 'element',
3651
+ type: 'view',
3652
+ attributesArray: [],
3653
+ children: [{ kind: 'childSlot', type: 'slot', elementSlotIndex: 0 }],
3654
+ },
3655
+ },
3656
+ ]);
3657
+
3658
+ const childRef = createMockElementTemplateHandle('child');
3659
+ elementTemplateRegistry.set(11, childRef);
3660
+ const createTemplateMock = globalThis.__CreateElementTemplate as unknown as {
3661
+ mockClear: () => void;
3662
+ mock: { calls: unknown[][] };
3663
+ };
3664
+ createTemplateMock.mockClear();
3665
+
3666
+ applyElementTemplateUpdateCommands([
3667
+ ElementTemplateUpdateOps.createTemplate,
3668
+ 21,
3669
+ '_et_patch_parent',
3670
+ null,
3671
+ [],
3672
+ [[11, 404], 'bad-slot' as unknown as number[]],
3673
+ ]);
3674
+
3675
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
3676
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('child handle 404 not found');
3677
+ expect(createTemplateMock.mock.calls).toHaveLength(0);
3678
+ resetReportedErrors();
3679
+ });
3680
+
3681
+ it('still flushes update payloads with empty ops so flushOptions can reach native', () => {
3682
+ envManager.switchToMainThread();
3683
+ installElementTemplatePatchListener();
3684
+ mockSetElementTemplateAttributeSlot.mockClear();
3685
+ mockInsertElementTemplateNodeIntoSlot.mockClear();
3686
+ mockRemoveElementTemplateNodeFromSlot.mockClear();
3687
+ mockFlushElementTree.mockClear();
3688
+ lynx.performance._markTiming.mockClear();
3689
+
3690
+ envManager.switchToBackground();
3691
+ dispatchElementTemplateUpdate({
3692
+ ops: [],
3693
+ flushOptions: { triggerDataUpdated: true },
3694
+ });
3695
+ envManager.switchToMainThread();
3696
+
3697
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
3698
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
3699
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
3700
+ expect(mockFlushElementTree.mock.calls).toHaveLength(1);
3701
+ expect(mockFlushElementTree.mock.calls[0]?.[1]).toEqual({ triggerDataUpdated: true });
3702
+ expect(lynx.performance._markTiming.mock.calls).toEqual([]);
3703
+ });
3704
+ });