@lynx-js/react 0.129.3 → 0.129.4

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 (413) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +2 -2
  4. package/refresh/.turbo/turbo-build.log +3 -3
  5. package/refresh/dist/index.js +113 -20
  6. package/refresh/rslib.config.ts +13 -3
  7. package/refresh/src/index.ts +100 -0
  8. package/refresh/src/self.ts +38 -0
  9. package/runtime/__test__/{snapshot → core}/attribute-name.test.ts +1 -1
  10. package/runtime/__test__/core/background-function.test.ts +37 -0
  11. package/runtime/__test__/{shared → core}/component-stack.test.ts +4 -4
  12. package/runtime/__test__/core/ref.test.ts +218 -1
  13. package/runtime/__test__/core/sync-effect-flush.test.ts +58 -0
  14. package/runtime/__test__/element-template/debug/alog.test.ts +20 -12
  15. package/runtime/__test__/element-template/fixtures/background/hydrate/_shared.tsx +15 -34
  16. package/runtime/__test__/element-template/fixtures/background/hydrate/children.creates-missing-nodes-recursively/output.txt +2 -0
  17. package/runtime/__test__/element-template/fixtures/background/hydrate/children.iterates-existing-slots/output.txt +1 -0
  18. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-attrs-element/output.txt +6 -1
  19. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-main/output.txt +1 -0
  20. package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.move-before-child → children.reconciles-raw-text-slots}/case.tsx +1 -1
  21. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text/output.txt +1 -0
  22. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text-non-text/output.txt +1 -0
  23. package/runtime/__test__/element-template/fixtures/background/hydrate/root-key-mismatch-reconciles/output.txt +1 -0
  24. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.creates-and-inserts-new/output.txt +1 -0
  25. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.inserts-before-existing-sibling/output.txt +1 -0
  26. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.mixed-operations/output.txt +1 -0
  27. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -0
  28. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/complex-trees.deeply-nested-dynamic-content/output.txt +1 -0
  29. package/runtime/__test__/element-template/fixtures/background/instance/ops/emits-bundle-url-in-create-template/output.txt +1 -0
  30. package/runtime/__test__/element-template/fixtures/list/mts/index.tsx +185 -0
  31. package/runtime/__test__/element-template/fixtures/page/render-page/native-log.txt +1 -0
  32. package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/case.tsx +2 -0
  33. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/ops.txt +1 -0
  34. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/ops.txt +1 -0
  35. package/runtime/__test__/element-template/fixtures/render/child-siblings/papi.txt +10 -5
  36. package/runtime/__test__/element-template/fixtures/render/component/papi.txt +6 -3
  37. package/runtime/__test__/element-template/fixtures/render/component-slot-content/papi.txt +6 -3
  38. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/papi.txt +2 -1
  39. package/runtime/__test__/element-template/fixtures/render/direct-native/appends-root-text-via-append-element/native-log.txt +1 -0
  40. package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/native-log.txt +2 -0
  41. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-template-children-in-the-same-slot/native-log.txt +3 -0
  42. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +3 -0
  43. package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/native-log.txt +3 -0
  44. package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/native-log.txt +3 -0
  45. package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/native-log.txt +1 -0
  46. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/papi.txt +14 -7
  47. package/runtime/__test__/element-template/fixtures/render/mixed-children/papi.txt +8 -4
  48. package/runtime/__test__/element-template/fixtures/render/multiple-text/papi.txt +38 -19
  49. package/runtime/__test__/element-template/fixtures/render/nested-templates/papi.txt +6 -3
  50. package/runtime/__test__/element-template/fixtures/render/react-example/papi.txt +6 -3
  51. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/papi.txt +6 -3
  52. package/runtime/__test__/element-template/fixtures/render/template-dedupe/papi.txt +10 -5
  53. package/runtime/__test__/element-template/lynx/performance.test.ts +1 -0
  54. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +1 -0
  55. package/runtime/__test__/element-template/native/mts-destroy.test.ts +10 -15
  56. package/runtime/__test__/element-template/native/reload.test.ts +4 -7
  57. package/runtime/__test__/element-template/runtime/background/adapter/background-adapter.et.test.tsx +0 -32
  58. package/runtime/__test__/element-template/runtime/background/commit-context.test.ts +0 -14
  59. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +10 -0
  60. package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +22 -0
  61. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +197 -252
  62. package/runtime/__test__/element-template/runtime/background/instance.test.ts +277 -126
  63. package/runtime/__test__/element-template/runtime/background/passive-update-depth.test.tsx +496 -0
  64. package/runtime/__test__/element-template/runtime/background/render/preact.test.tsx +16 -22
  65. package/runtime/__test__/element-template/runtime/background/root-render.test.tsx +5 -3
  66. package/runtime/__test__/element-template/runtime/background/suspense.test.tsx +2 -0
  67. package/runtime/__test__/element-template/runtime/background/update/compiled-fixtures.test.tsx +1 -0
  68. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +1 -0
  69. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +3 -4
  70. package/runtime/__test__/element-template/runtime/list/list-mts-compiled.test.ts +525 -0
  71. package/runtime/__test__/element-template/runtime/page/compiled-fixtures.test.tsx +2 -0
  72. package/runtime/__test__/element-template/runtime/page/root-instance.test.ts +2 -14
  73. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +425 -1032
  74. package/runtime/__test__/element-template/runtime/patch/patch-listener-alog.test.ts +1 -0
  75. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +1 -0
  76. package/runtime/__test__/element-template/runtime/prop-adapters/event.test.ts +0 -20
  77. package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +2 -1
  78. package/runtime/__test__/element-template/runtime/prop-adapters/hydrate.test.ts +1 -0
  79. package/runtime/__test__/element-template/runtime/prop-adapters/ref.test.ts +65 -0
  80. package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +12 -4
  81. package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +2 -5
  82. package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +56 -121
  83. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +18 -17
  84. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +5 -4
  85. package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -0
  86. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +1 -60
  87. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +32 -89
  88. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +8 -6
  89. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +34 -6
  90. package/runtime/__test__/element-template/test-utils/debug/updateRunner.test.tsx +20 -12
  91. package/runtime/__test__/element-template/test-utils/debug/updateRunner.ts +2 -28
  92. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.test.ts +14 -5
  93. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.ts +1 -57
  94. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +29 -13
  95. package/runtime/__test__/element-template/vitest.config.ts +1 -0
  96. package/runtime/__test__/guardrails/snapshot-containment.test.ts +98 -77
  97. package/runtime/__test__/snapshot/debug/passive-update-depth.test.jsx +549 -0
  98. package/runtime/__test__/snapshot/debug/react-hooks-profile.test.jsx +3 -3
  99. package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +138 -1
  100. package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +1 -1
  101. package/runtime/__test__/snapshot/lifecycle/transfer.mts.test.jsx +194 -0
  102. package/runtime/__test__/snapshot/lifecycle/transfer.test.jsx +210 -0
  103. package/runtime/__test__/snapshot/list.test.jsx +109 -0
  104. package/runtime/__test__/snapshot/lynxQueueMicrotask.test.jsx +2 -2
  105. package/runtime/__test__/snapshot/ref.test.jsx +124 -1
  106. package/runtime/__test__/snapshot/utils/envManager.ts +5 -0
  107. package/runtime/__test__/snapshot/utils/globals.js +1 -0
  108. package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +22 -11
  109. package/runtime/__test__/worklet-runtime/hydrate.test.js +1 -0
  110. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +24 -16
  111. package/runtime/__test__/worklet-runtime/runOnBackground.test.js +188 -0
  112. package/runtime/__test__/worklet-runtime/workletRef.test.js +16 -0
  113. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +53 -1
  114. package/runtime/lazy/internal.js +1 -0
  115. package/runtime/lib/core/attribute-name.js.map +1 -0
  116. package/runtime/lib/core/background-function/run-on-background.js +7 -7
  117. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  118. package/runtime/lib/{shared → core}/component-stack.js +1 -1
  119. package/runtime/lib/core/component-stack.js.map +1 -0
  120. package/runtime/lib/core/deep-equal.d.ts +1 -0
  121. package/runtime/lib/core/deep-equal.js +31 -0
  122. package/runtime/lib/core/deep-equal.js.map +1 -0
  123. package/runtime/lib/core/hooks/mainThreadImpl.js +1 -1
  124. package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
  125. package/runtime/lib/core/lynx-page-data.js +1 -1
  126. package/runtime/lib/core/lynx-page-data.js.map +1 -1
  127. package/runtime/lib/core/mts-capability.js +1 -1
  128. package/runtime/lib/core/mts-capability.js.map +1 -1
  129. package/runtime/lib/core/performance.js +2 -1
  130. package/runtime/lib/core/performance.js.map +1 -1
  131. package/runtime/lib/core/ref.d.ts +1 -2
  132. package/runtime/lib/core/ref.js +60 -9
  133. package/runtime/lib/core/ref.js.map +1 -1
  134. package/runtime/lib/core/sync-effect-flush.d.ts +9 -0
  135. package/runtime/lib/core/sync-effect-flush.js +31 -0
  136. package/runtime/lib/core/sync-effect-flush.js.map +1 -0
  137. package/runtime/lib/core/thread-function-call/main-thread.js +1 -1
  138. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  139. package/runtime/lib/element-template/background/attr-slots.d.ts +1 -0
  140. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  141. package/runtime/lib/element-template/background/commit-hook.js +1 -1
  142. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  143. package/runtime/lib/element-template/background/destroy.js +1 -1
  144. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  145. package/runtime/lib/element-template/background/hydrate.js +173 -85
  146. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  147. package/runtime/lib/element-template/background/instance.d.ts +7 -10
  148. package/runtime/lib/element-template/background/instance.js +65 -58
  149. package/runtime/lib/element-template/background/instance.js.map +1 -1
  150. package/runtime/lib/element-template/background/render-scope.js +2 -1
  151. package/runtime/lib/element-template/background/render-scope.js.map +1 -1
  152. package/runtime/lib/element-template/debug/alog.d.ts +1 -10
  153. package/runtime/lib/element-template/debug/alog.js +1 -16
  154. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  155. package/runtime/lib/element-template/debug/profile.js +1 -1
  156. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  157. package/runtime/lib/element-template/native/index.js +2 -2
  158. package/runtime/lib/element-template/native/index.js.map +1 -1
  159. package/runtime/lib/element-template/native/patch-listener.js +4 -8
  160. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  161. package/runtime/lib/element-template/native/reload-main-thread.js +0 -4
  162. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  163. package/runtime/lib/element-template/prop-adapters/ref.d.ts +2 -1
  164. package/runtime/lib/element-template/prop-adapters/ref.js +4 -4
  165. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
  166. package/runtime/lib/element-template/prop-adapters/spread.js +1 -1
  167. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  168. package/runtime/lib/element-template/protocol/opcodes.d.ts +0 -2
  169. package/runtime/lib/element-template/protocol/opcodes.js +0 -2
  170. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  171. package/runtime/lib/element-template/protocol/types.d.ts +8 -30
  172. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  173. package/runtime/lib/element-template/runtime/list/list.d.ts +14 -54
  174. package/runtime/lib/element-template/runtime/list/list.js +82 -546
  175. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  176. package/runtime/lib/element-template/runtime/list/platform-info.d.ts +2 -0
  177. package/runtime/lib/element-template/runtime/list/platform-info.js +26 -0
  178. package/runtime/lib/element-template/runtime/list/platform-info.js.map +1 -0
  179. package/runtime/lib/element-template/runtime/patch.js +42 -119
  180. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  181. package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +1 -1
  182. package/runtime/lib/element-template/runtime/render/create-rendered-host.js +24 -21
  183. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
  184. package/runtime/lib/element-template/runtime/render/render-components.d.ts +1 -1
  185. package/runtime/lib/element-template/runtime/render/render-components.js +3 -6
  186. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  187. package/runtime/lib/element-template/runtime/render/render-direct.js +21 -20
  188. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
  189. package/runtime/lib/element-template/runtime/render/render-main-thread.js +0 -13
  190. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  191. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +8 -0
  192. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  193. package/runtime/lib/element-template/runtime/template/handle.d.ts +3 -3
  194. package/runtime/lib/element-template/runtime/template/handle.js +2 -2
  195. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  196. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +1 -6
  197. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  198. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +2 -1
  199. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +44 -28
  200. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  201. package/runtime/lib/element-template/runtime/template/typed-attributes.d.ts +2 -0
  202. package/runtime/lib/element-template/runtime/template/typed-attributes.js +8 -1
  203. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  204. package/runtime/lib/internal.d.ts +1 -0
  205. package/runtime/lib/internal.js +1 -0
  206. package/runtime/lib/internal.js.map +1 -1
  207. package/runtime/lib/lynx-api.js +6 -1
  208. package/runtime/lib/lynx-api.js.map +1 -1
  209. package/runtime/lib/lynx.js +4 -4
  210. package/runtime/lib/lynx.js.map +1 -1
  211. package/runtime/lib/root.d.ts +5 -1
  212. package/runtime/lib/root.js +12 -1
  213. package/runtime/lib/root.js.map +1 -1
  214. package/runtime/lib/shared/microtask.d.ts +1 -0
  215. package/runtime/lib/shared/microtask.js +28 -0
  216. package/runtime/lib/shared/microtask.js.map +1 -0
  217. package/runtime/lib/shared/utils.d.ts +8 -0
  218. package/runtime/lib/shared/utils.js +27 -0
  219. package/runtime/lib/shared/utils.js.map +1 -0
  220. package/runtime/lib/{worklet-runtime/utils → shared}/version.d.ts +1 -0
  221. package/runtime/lib/{worklet-runtime/utils → shared}/version.js +4 -2
  222. package/runtime/lib/shared/version.js.map +1 -0
  223. package/runtime/lib/snapshot/alog/render.js +1 -1
  224. package/runtime/lib/snapshot/alog/render.js.map +1 -1
  225. package/runtime/lib/snapshot/debug/profileHooks.js +1 -1
  226. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  227. package/runtime/lib/snapshot/lifecycle/destroy.js +2 -2
  228. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  229. package/runtime/lib/snapshot/lifecycle/isRendering.js +2 -1
  230. package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
  231. package/runtime/lib/snapshot/lifecycle/patch/commit.d.ts +7 -2
  232. package/runtime/lib/snapshot/lifecycle/patch/commit.js +11 -6
  233. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  234. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.d.ts +5 -0
  235. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +1 -1
  236. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  237. package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +1 -1
  238. package/runtime/lib/snapshot/lifecycle/ref/delay.js +2 -2
  239. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  240. package/runtime/lib/snapshot/lifecycle/reload.js +1 -1
  241. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  242. package/runtime/lib/snapshot/list/list.js +12 -3
  243. package/runtime/lib/snapshot/list/list.js.map +1 -1
  244. package/runtime/lib/snapshot/lynx/tt.d.ts +3 -1
  245. package/runtime/lib/snapshot/lynx/tt.js +7 -3
  246. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  247. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +1 -1
  248. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  249. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  250. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  251. package/runtime/lib/snapshot/snapshot/platformInfo.js +1 -1
  252. package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
  253. package/runtime/lib/snapshot/snapshot/ref.d.ts +1 -0
  254. package/runtime/lib/snapshot/snapshot/ref.js +2 -2
  255. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  256. package/runtime/lib/snapshot/snapshot/snapshot.js +1 -1
  257. package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
  258. package/runtime/lib/snapshot/snapshot/spread.js +3 -2
  259. package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
  260. package/runtime/lib/snapshot/transfer.d.ts +15 -0
  261. package/runtime/lib/snapshot/transfer.js +343 -0
  262. package/runtime/lib/snapshot/transfer.js.map +1 -0
  263. package/runtime/lib/snapshot/worklet/functionality.js +1 -1
  264. package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
  265. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  266. package/runtime/lib/worklet-runtime/api/element.js +1 -1
  267. package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
  268. package/runtime/lib/worklet-runtime/api/lynxApi.js +1 -1
  269. package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
  270. package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -2
  271. package/runtime/lib/worklet-runtime/bindings/bindings.js +11 -1
  272. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  273. package/runtime/lib/worklet-runtime/bindings/observers.js +9 -1
  274. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  275. package/runtime/lib/worklet-runtime/bindings/types.d.ts +1 -0
  276. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
  277. package/runtime/lib/worklet-runtime/delayWorkletEvent.d.ts +2 -4
  278. package/runtime/lib/worklet-runtime/delayWorkletEvent.js +42 -44
  279. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
  280. package/runtime/lib/worklet-runtime/global.d.ts +1 -2
  281. package/runtime/lib/worklet-runtime/global.js.map +1 -1
  282. package/runtime/lib/worklet-runtime/hydrate.js +2 -32
  283. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  284. package/runtime/lib/worklet-runtime/run-on-background/index.d.ts +28 -0
  285. package/runtime/lib/worklet-runtime/run-on-background/index.js +103 -0
  286. package/runtime/lib/worklet-runtime/run-on-background/index.js.map +1 -0
  287. package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.d.ts → run-on-background/lifecycle.d.ts} +2 -2
  288. package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.js → run-on-background/lifecycle.js} +12 -9
  289. package/runtime/lib/worklet-runtime/run-on-background/lifecycle.js.map +1 -0
  290. package/runtime/lib/worklet-runtime/workletRef.js +51 -54
  291. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
  292. package/runtime/lib/worklet-runtime/workletRuntime.js +5 -6
  293. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  294. package/runtime/src/core/background-function/run-on-background.ts +7 -7
  295. package/runtime/src/{shared → core}/component-stack.ts +1 -1
  296. package/runtime/src/core/deep-equal.ts +33 -0
  297. package/runtime/src/core/hooks/mainThreadImpl.ts +1 -1
  298. package/runtime/src/core/lynx-page-data.ts +1 -1
  299. package/runtime/src/core/mts-capability.ts +1 -1
  300. package/runtime/src/core/performance.ts +2 -1
  301. package/runtime/src/core/ref.ts +92 -15
  302. package/runtime/src/core/sync-effect-flush.ts +30 -0
  303. package/runtime/src/core/thread-function-call/main-thread.ts +1 -1
  304. package/runtime/src/element-template/background/attr-slots.ts +2 -2
  305. package/runtime/src/element-template/background/commit-hook.ts +1 -1
  306. package/runtime/src/element-template/background/destroy.ts +1 -1
  307. package/runtime/src/element-template/background/hydrate.ts +229 -119
  308. package/runtime/src/element-template/background/instance.ts +82 -82
  309. package/runtime/src/element-template/background/render-scope.ts +2 -1
  310. package/runtime/src/element-template/debug/alog.ts +2 -30
  311. package/runtime/src/element-template/debug/profile.ts +1 -1
  312. package/runtime/src/element-template/native/index.ts +2 -2
  313. package/runtime/src/element-template/native/patch-listener.ts +6 -7
  314. package/runtime/src/element-template/native/reload-main-thread.ts +0 -4
  315. package/runtime/src/element-template/prop-adapters/ref.ts +12 -5
  316. package/runtime/src/element-template/prop-adapters/spread.ts +1 -1
  317. package/runtime/src/element-template/protocol/opcodes.ts +0 -2
  318. package/runtime/src/element-template/protocol/types.ts +10 -38
  319. package/runtime/src/element-template/runtime/list/list.ts +115 -744
  320. package/runtime/src/element-template/runtime/list/platform-info.ts +31 -0
  321. package/runtime/src/element-template/runtime/patch.ts +59 -163
  322. package/runtime/src/element-template/runtime/render/create-rendered-host.ts +27 -31
  323. package/runtime/src/element-template/runtime/render/render-components.ts +2 -5
  324. package/runtime/src/element-template/runtime/render/render-direct.ts +19 -18
  325. package/runtime/src/element-template/runtime/render/render-main-thread.ts +0 -14
  326. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +9 -0
  327. package/runtime/src/element-template/runtime/template/handle.ts +3 -2
  328. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +1 -6
  329. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +44 -30
  330. package/runtime/src/element-template/runtime/template/typed-attributes.ts +17 -1
  331. package/runtime/src/element-template/types.d.ts +6 -22
  332. package/runtime/src/internal.ts +2 -0
  333. package/runtime/src/lynx-api.ts +6 -1
  334. package/runtime/src/lynx.ts +4 -4
  335. package/runtime/src/root.ts +17 -1
  336. package/runtime/src/shared/microtask.ts +26 -0
  337. package/runtime/src/shared/utils.ts +37 -0
  338. package/runtime/src/{worklet-runtime/utils → shared}/version.ts +6 -4
  339. package/runtime/src/snapshot/alog/render.ts +1 -1
  340. package/runtime/src/snapshot/debug/profileHooks.ts +1 -1
  341. package/runtime/src/snapshot/lifecycle/destroy.ts +2 -2
  342. package/runtime/src/snapshot/lifecycle/isRendering.ts +2 -1
  343. package/runtime/src/snapshot/lifecycle/patch/commit.ts +28 -7
  344. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +1 -1
  345. package/runtime/src/snapshot/lifecycle/ref/delay.ts +5 -2
  346. package/runtime/src/snapshot/lifecycle/reload.ts +1 -1
  347. package/runtime/src/snapshot/list/list.ts +12 -3
  348. package/runtime/src/snapshot/lynx/tt.ts +8 -3
  349. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +1 -1
  350. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
  351. package/runtime/src/snapshot/snapshot/platformInfo.ts +1 -1
  352. package/runtime/src/snapshot/snapshot/ref.ts +7 -4
  353. package/runtime/src/snapshot/snapshot/snapshot.ts +1 -1
  354. package/runtime/src/snapshot/snapshot/spread.ts +3 -2
  355. package/runtime/src/snapshot/transfer.ts +379 -0
  356. package/runtime/src/snapshot/worklet/functionality.ts +1 -1
  357. package/runtime/src/worklet-runtime/api/element.ts +1 -1
  358. package/runtime/src/worklet-runtime/api/lynxApi.ts +1 -1
  359. package/runtime/src/worklet-runtime/bindings/bindings.ts +12 -0
  360. package/runtime/src/worklet-runtime/bindings/observers.ts +9 -1
  361. package/runtime/src/worklet-runtime/bindings/types.ts +1 -0
  362. package/runtime/src/worklet-runtime/delayWorkletEvent.ts +49 -54
  363. package/runtime/src/worklet-runtime/global.ts +1 -2
  364. package/runtime/src/worklet-runtime/hydrate.ts +2 -35
  365. package/runtime/src/worklet-runtime/run-on-background/index.ts +145 -0
  366. package/runtime/src/worklet-runtime/{jsFunctionLifecycle.ts → run-on-background/lifecycle.ts} +11 -9
  367. package/runtime/src/worklet-runtime/workletRef.ts +63 -62
  368. package/runtime/src/worklet-runtime/workletRuntime.ts +10 -10
  369. package/testing-library/.turbo/turbo-build.log +10 -10
  370. package/testing-library/dist/pure.js +7 -4
  371. package/testing-library/dist/setupFiles/common/runtime-setup.js +3 -1
  372. package/testing-library/dist/setupFiles/inner/rstest.js +1 -1
  373. package/testing-library/dist/setupFiles/inner/vitest.js +1 -1
  374. package/testing-library/src/__tests__/list.test.jsx +52 -0
  375. package/testing-library/src/__tests__/worklet.test.jsx +81 -0
  376. package/testing-library/src/pure.jsx +5 -2
  377. package/testing-library/src/setupFiles/common/runtime-setup.js +2 -0
  378. package/transform/.turbo/turbo-build$colon$wasm.log +64 -64
  379. package/transform/crates/swc_plugin_element_template/tests/element_template.rs +19 -45
  380. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +0 -19
  381. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
  382. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +85 -85
  383. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +213 -192
  384. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.move-before-child/output.txt +0 -10
  385. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.raw-text-key-branches/case.tsx +0 -5
  386. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/case.ts +0 -11
  387. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/output.txt +0 -1
  388. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/case.ts +0 -23
  389. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/output.txt +0 -6
  390. package/runtime/__test__/element-template/runtime/page/authored-page.test.ts +0 -35
  391. package/runtime/__test__/element-template/runtime/patch/update-fixture-helper.test.tsx +0 -40
  392. package/runtime/__test__/snapshot/lynx-data-processors.test.ts +0 -3
  393. package/runtime/lib/shared/attribute-name.js.map +0 -1
  394. package/runtime/lib/shared/component-stack.js.map +0 -1
  395. package/runtime/lib/snapshot/alog/index.d.ts +0 -1
  396. package/runtime/lib/snapshot/alog/index.js +0 -8
  397. package/runtime/lib/snapshot/alog/index.js.map +0 -1
  398. package/runtime/lib/utils.d.ts +0 -19
  399. package/runtime/lib/utils.js +0 -119
  400. package/runtime/lib/utils.js.map +0 -1
  401. package/runtime/lib/worklet-runtime/delayRunOnBackground.d.ts +0 -13
  402. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +0 -29
  403. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +0 -1
  404. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +0 -1
  405. package/runtime/lib/worklet-runtime/utils/version.js.map +0 -1
  406. package/runtime/src/snapshot/alog/index.ts +0 -8
  407. package/runtime/src/utils.ts +0 -134
  408. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +0 -53
  409. /package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.raw-text-key-branches → children.reconciles-raw-text-slots}/output.txt +0 -0
  410. /package/runtime/lib/{shared → core}/attribute-name.d.ts +0 -0
  411. /package/runtime/lib/{shared → core}/attribute-name.js +0 -0
  412. /package/runtime/lib/{shared → core}/component-stack.d.ts +0 -0
  413. /package/runtime/src/{shared → core}/attribute-name.ts +0 -0
@@ -8,7 +8,7 @@ import {
8
8
  } from '../../../../src/element-template/main-thread-ref-init-value.js';
9
9
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
10
10
 
11
- import { JsFunctionLifecycleManager } from '../../../../src/worklet-runtime/jsFunctionLifecycle.js';
11
+ import { JsFunctionLifecycleManager } from '../../../../src/worklet-runtime/run-on-background/lifecycle.js';
12
12
  import { getReloadVersion, increaseReloadVersion } from '../../../../src/core/reload-version.js';
13
13
  import type { BackgroundElementTemplateInstance } from '../../../../src/element-template/background/instance.js';
14
14
  import { root } from '../../../../src/element-template/index.js';
@@ -36,15 +36,16 @@ import {
36
36
  composeElementTemplateListAttributes,
37
37
  createElementTemplateListState,
38
38
  markElementTemplateListDestroyed,
39
- registerElementTemplateListItem,
40
39
  registerElementTemplateListState,
41
40
  removeElementTemplateListItem,
41
+ updateElementTemplateListAttributes,
42
+ updateElementTemplateListItemSubtreeHandles,
42
43
  } from '../../../../src/element-template/runtime/list/list.js';
43
44
  import {
44
45
  attachMainThreadDynamicAttrRefsForSubtree,
45
46
  applyPendingMainThreadRefAttachments,
46
47
  clearMainThreadDynamicAttrState,
47
- detachMainThreadDynamicAttrRefsForSubtree,
48
+ detachMainThreadDynamicAttrRefsForHandleIds,
48
49
  getMainThreadDynamicAttrState,
49
50
  initializeMainThreadDynamicAttrSlots,
50
51
  } from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
@@ -92,6 +93,7 @@ function createRawTextOps(id: number, text: string) {
92
93
  null,
93
94
  [text],
94
95
  [],
96
+ null,
95
97
  ] as const;
96
98
  }
97
99
 
@@ -105,14 +107,6 @@ function resetReportedErrors(): void {
105
107
  (globalThis as unknown as { __LYNX_REPORT_ERROR_CALLS: Error[] }).__LYNX_REPORT_ERROR_CALLS = [];
106
108
  }
107
109
 
108
- function createMaterializedListForFrontendTest(nativeId: number): FiberElement {
109
- return {
110
- __isNativeRef: true,
111
- id: 'materialized-list',
112
- __mockNativeId: nativeId,
113
- } as unknown as FiberElement;
114
- }
115
-
116
110
  const MT_EVENT_TEMPLATE = '_et_mt_event';
117
111
  const MT_REF_TEMPLATE = '_et_mt_ref';
118
112
  const REF_TARGET = { id: 'materialized-ref-node' } as unknown as ElementRef;
@@ -173,6 +167,9 @@ function installWorkletRefRuntime(): {
173
167
  const updateWorkletRef = vi.fn();
174
168
  globalThis.lynxWorkletImpl = {
175
169
  ...previousWorkletImpl,
170
+ _eomImpl: {
171
+ setShouldFlush: vi.fn(),
172
+ },
176
173
  _refImpl: {
177
174
  updateWorkletRef,
178
175
  },
@@ -493,6 +490,7 @@ describe('ElementTemplate patch stream (apply)', () => {
493
490
  null,
494
491
  [{ type: 'worklet', value: ctx }],
495
492
  [],
493
+ null,
496
494
  ],
497
495
  flushOptions: {},
498
496
  });
@@ -534,6 +532,7 @@ describe('ElementTemplate patch stream (apply)', () => {
534
532
  'lazy-entry',
535
533
  [{ type: 'worklet', value: ctx }],
536
534
  [],
535
+ null,
537
536
  ],
538
537
  flushOptions: {},
539
538
  });
@@ -577,6 +576,7 @@ describe('ElementTemplate patch stream (apply)', () => {
577
576
  null,
578
577
  [{ type: 'main-thread-ref', value: ref }],
579
578
  [],
579
+ null,
580
580
  ],
581
581
  flushOptions: {},
582
582
  });
@@ -627,6 +627,7 @@ describe('ElementTemplate patch stream (apply)', () => {
627
627
  null,
628
628
  [{ type: 'main-thread-ref', value: ref }],
629
629
  [],
630
+ null,
630
631
  ]);
631
632
 
632
633
  const nativeRef = elementTemplateRegistry.get(handleId);
@@ -688,6 +689,7 @@ describe('ElementTemplate patch stream (apply)', () => {
688
689
  null,
689
690
  [{ type: 'main-thread-ref', value: ref }],
690
691
  [],
692
+ null,
691
693
  ]);
692
694
  mockInsertElementTemplateNodeIntoSlot.mockImplementationOnce(() => {
693
695
  throw new Error('insert failed');
@@ -877,7 +879,7 @@ describe('ElementTemplate patch stream (apply)', () => {
877
879
  elementTemplateRegistry.set(targetId, nativeRef);
878
880
  globalThis.runWorklet = vi.fn(() => oldCleanup);
879
881
  seedMTRefState(targetId, 0, oldCallback, nativeRef);
880
- detachMainThreadDynamicAttrRefsForSubtree([{ uid: targetId, ref: nativeRef }]);
882
+ detachMainThreadDynamicAttrRefsForHandleIds([targetId]);
881
883
  globalThis.runWorklet = vi.fn();
882
884
  globalThis.lynxWorkletImpl = {
883
885
  ...previousWorkletImpl,
@@ -1965,28 +1967,6 @@ describe('ElementTemplate patch stream (apply)', () => {
1965
1967
  expect(mockFlushElementTree.mock.calls[0]?.[1]).toEqual({ triggerDataUpdated: true });
1966
1968
  });
1967
1969
 
1968
- it('flushes option-only update payloads with empty ops', () => {
1969
- envManager.switchToMainThread();
1970
- installElementTemplatePatchListener();
1971
- const performance = lynx.performance;
1972
- performance.profileStart.mockClear();
1973
- performance.profileEnd.mockClear();
1974
- mockFlushElementTree.mockClear();
1975
-
1976
- envManager.switchToBackground();
1977
- dispatchElementTemplateUpdate({
1978
- ops: [],
1979
- flushOptions: { triggerDataUpdated: true },
1980
- flowIds: [101, 202],
1981
- });
1982
- envManager.switchToMainThread();
1983
-
1984
- expect(performance.profileStart).not.toHaveBeenCalled();
1985
- expect(performance.profileEnd).not.toHaveBeenCalled();
1986
- expect(mockFlushElementTree.mock.calls).toHaveLength(1);
1987
- expect(mockFlushElementTree.mock.calls[0]?.[1]).toEqual({ triggerDataUpdated: true });
1988
- });
1989
-
1990
1970
  it('reports illegal handleId 0 on create', () => {
1991
1971
  const jsx = <view />;
1992
1972
  root.render(jsx);
@@ -2011,6 +1991,7 @@ describe('ElementTemplate patch stream (apply)', () => {
2011
1991
  null,
2012
1992
  ['x'],
2013
1993
  [],
1994
+ null,
2014
1995
  ]);
2015
1996
 
2016
1997
  const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
@@ -2030,6 +2011,7 @@ describe('ElementTemplate patch stream (apply)', () => {
2030
2011
  null,
2031
2012
  ['x'],
2032
2013
  [],
2014
+ null,
2033
2015
  ]);
2034
2016
 
2035
2017
  const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
@@ -2047,6 +2029,7 @@ describe('ElementTemplate patch stream (apply)', () => {
2047
2029
  null,
2048
2030
  'bad-attrs' as unknown as ElementTemplateUpdateCommandStream[number],
2049
2031
  [],
2032
+ null,
2050
2033
  ]);
2051
2034
 
2052
2035
  const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
@@ -2066,6 +2049,7 @@ describe('ElementTemplate patch stream (apply)', () => {
2066
2049
  null,
2067
2050
  [],
2068
2051
  'bad-slots' as unknown as ElementTemplateUpdateCommandStream[number],
2052
+ null,
2069
2053
  ]);
2070
2054
 
2071
2055
  const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
@@ -2112,6 +2096,7 @@ describe('ElementTemplate patch stream (apply)', () => {
2112
2096
  null,
2113
2097
  [],
2114
2098
  childSlots,
2099
+ null,
2115
2100
  ]);
2116
2101
 
2117
2102
  const parentCall = createTemplateMock.mock.calls.find((call) => call[0] === '_et_sparse_slot_parent');
@@ -2171,11 +2156,11 @@ describe('ElementTemplate patch stream (apply)', () => {
2171
2156
  expect(elementTemplateRegistry.has(21)).toBe(true);
2172
2157
  });
2173
2158
 
2174
- it('creates a typed list with callbacks and logical children', () => {
2159
+ it('creates a typed list with logical children in slot 0', () => {
2175
2160
  envManager.switchToMainThread();
2176
2161
  elementTemplateRegistry.clear();
2177
2162
 
2178
- const itemRef = createMockElementTemplateHandle('option-child', 101);
2163
+ const itemRef = createMockElementTemplateHandle('logical-child', 101);
2179
2164
  elementTemplateRegistry.set(12, itemRef);
2180
2165
  mockCreateTypedElementTemplate.mockClear();
2181
2166
 
@@ -2184,52 +2169,43 @@ describe('ElementTemplate patch stream (apply)', () => {
2184
2169
  28,
2185
2170
  'list',
2186
2171
  { id: 'typed-list' },
2187
- [],
2188
- {
2189
- listChildren: [{ __etHandleRef: 12, type: '_et_item', platformInfo: { 'item-key': 'a' } }],
2190
- estimatedHeight: 80,
2191
- },
2172
+ [[12], null],
2173
+ { estimatedHeight: 80 },
2192
2174
  ]);
2193
2175
 
2194
- expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(1);
2195
- expect(mockCreateTypedElementTemplate.mock.calls[0]?.[0]).toBe('list');
2196
- expect(mockCreateTypedElementTemplate.mock.calls[0]?.[1]).toEqual({
2197
- id: 'typed-list',
2198
- 'component-at-index': expect.any(Function),
2199
- 'component-at-indexes': expect.any(Function),
2200
- 'enqueue-component': expect.any(Function),
2201
- });
2202
- expect(mockCreateTypedElementTemplate.mock.calls[0]?.[2]).toBe(null);
2203
- expect(mockCreateTypedElementTemplate.mock.calls[0]?.[3]).toBe(28);
2204
- expect(mockCreateTypedElementTemplate.mock.calls[0]?.[4]).toEqual({
2205
- listChildren: [itemRef],
2206
- estimatedHeight: 80,
2207
- });
2208
- expect(mockSetElementTemplateAttributeSlot.mock.calls).toEqual([[
2209
- expect.anything(),
2210
- 0,
2176
+ expect(mockCreateTypedElementTemplate.mock.calls).toEqual([[
2177
+ 'list',
2211
2178
  {
2212
2179
  id: 'typed-list',
2213
2180
  'component-at-index': expect.any(Function),
2214
- 'component-at-indexes': expect.any(Function),
2215
2181
  'enqueue-component': expect.any(Function),
2216
- 'update-list-info': {
2217
- insertAction: [{ position: 0, type: '_et_item', 'item-key': 'a' }],
2218
- removeAction: [],
2219
- updateAction: [],
2220
- },
2221
2182
  },
2183
+ [[itemRef]],
2184
+ 28,
2185
+ { estimatedHeight: 80 },
2222
2186
  ]]);
2187
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
2223
2188
  expect(elementTemplateRegistry.has(28)).toBe(true);
2224
- const listRef = elementTemplateRegistry.get(28)!;
2225
- const materializedListRef = createMaterializedListForFrontendTest(1001);
2226
- const componentAtIndex = (mockCreateTypedElementTemplate.mock.calls[0]![1] as Record<string, unknown>)[
2227
- 'component-at-index'
2228
- ] as ComponentAtIndexCallback;
2229
2189
 
2230
- mockInsertElementTemplateNodeIntoSlot.mockClear();
2231
- expect(componentAtIndex(materializedListRef, 7, 0, 88, false)).toBe(101);
2232
- expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toEqual([[listRef, 0, itemRef, null]]);
2190
+ const listRef = elementTemplateRegistry.get(28);
2191
+ const createdAttributes = mockCreateTypedElementTemplate.mock.calls[0]?.[1] as Record<string, unknown>;
2192
+ expect(createdAttributes).not.toHaveProperty('component-at-indexes');
2193
+ applyElementTemplateUpdateCommands([
2194
+ ElementTemplateUpdateOps.setAttribute,
2195
+ 28,
2196
+ 0,
2197
+ { id: 'updated-list' },
2198
+ ]);
2199
+
2200
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toEqual([[
2201
+ listRef,
2202
+ 0,
2203
+ {
2204
+ id: 'updated-list',
2205
+ 'component-at-index': createdAttributes['component-at-index'],
2206
+ 'enqueue-component': createdAttributes['enqueue-component'],
2207
+ },
2208
+ ]]);
2233
2209
  });
2234
2210
 
2235
2211
  it('creates a typed list outside development', () => {
@@ -2238,7 +2214,7 @@ describe('ElementTemplate patch stream (apply)', () => {
2238
2214
  try {
2239
2215
  envManager.switchToMainThread();
2240
2216
  elementTemplateRegistry.clear();
2241
- const itemRef = createMockElementTemplateHandle('option-child');
2217
+ const itemRef = createMockElementTemplateHandle('logical-child');
2242
2218
  elementTemplateRegistry.set(12, itemRef);
2243
2219
  mockCreateTypedElementTemplate.mockClear();
2244
2220
 
@@ -2247,18 +2223,20 @@ describe('ElementTemplate patch stream (apply)', () => {
2247
2223
  33,
2248
2224
  'list',
2249
2225
  null,
2250
- [],
2251
- {
2252
- listChildren: [{ __etHandleRef: 12, type: '_et_item', platformInfo: {} }],
2253
- estimatedHeight: 80,
2254
- },
2226
+ [[12]],
2227
+ { estimatedHeight: 80 },
2255
2228
  ]);
2256
2229
 
2257
- expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(1);
2258
- expect(mockCreateTypedElementTemplate.mock.calls[0]?.[4]).toEqual({
2259
- listChildren: [itemRef],
2260
- estimatedHeight: 80,
2261
- });
2230
+ expect(mockCreateTypedElementTemplate.mock.calls).toEqual([[
2231
+ 'list',
2232
+ {
2233
+ 'component-at-index': expect.any(Function),
2234
+ 'enqueue-component': expect.any(Function),
2235
+ },
2236
+ [[itemRef]],
2237
+ 33,
2238
+ { estimatedHeight: 80 },
2239
+ ]]);
2262
2240
  expect(elementTemplateRegistry.has(33)).toBe(true);
2263
2241
  } finally {
2264
2242
  globalThis.__DEV__ = originalDev;
@@ -2270,24 +2248,37 @@ describe('ElementTemplate patch stream (apply)', () => {
2270
2248
  elementTemplateRegistry.clear();
2271
2249
  mockCreateTypedElementTemplate.mockClear();
2272
2250
 
2273
- applyElementTemplateUpdateCommands([
2251
+ const stream: ElementTemplateUpdateCommandStream = [
2274
2252
  ElementTemplateUpdateOps.createTypedElement,
2275
2253
  29,
2276
2254
  'list',
2277
2255
  null,
2278
2256
  null,
2279
- { listChildren: [] },
2280
- ]);
2257
+ {},
2258
+ ];
2259
+ vi.mocked(__CreateTypedElementTemplate).mockReturnValueOnce(null as unknown as ElementTemplateHandle);
2260
+ applyElementTemplateUpdateCommands(stream);
2281
2261
 
2282
- expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(1);
2283
- expect(mockCreateTypedElementTemplate.mock.calls[0]?.[2]).toBe(null);
2284
- expect(mockCreateTypedElementTemplate.mock.calls[0]?.[4]).toEqual({
2285
- listChildren: [],
2286
- });
2262
+ expect(elementTemplateRegistry.has(29)).toBe(false);
2263
+ expect(updateElementTemplateListAttributes(29, null)).toBeNull();
2264
+ mockCreateTypedElementTemplate.mockClear();
2265
+
2266
+ applyElementTemplateUpdateCommands(stream);
2267
+
2268
+ expect(mockCreateTypedElementTemplate.mock.calls).toEqual([[
2269
+ 'list',
2270
+ {
2271
+ 'component-at-index': expect.any(Function),
2272
+ 'enqueue-component': expect.any(Function),
2273
+ },
2274
+ null,
2275
+ 29,
2276
+ {},
2277
+ ]]);
2287
2278
  expect(elementTemplateRegistry.has(29)).toBe(true);
2288
2279
  });
2289
2280
 
2290
- it('rejects exact typed list create without logical children options', () => {
2281
+ it('creates an empty typed list without command options', () => {
2291
2282
  envManager.switchToMainThread();
2292
2283
  elementTemplateRegistry.clear();
2293
2284
  mockCreateTypedElementTemplate.mockClear();
@@ -2301,22 +2292,28 @@ describe('ElementTemplate patch stream (apply)', () => {
2301
2292
  null,
2302
2293
  ]);
2303
2294
 
2304
- expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2305
- expect(elementTemplateRegistry.has(32)).toBe(false);
2295
+ expect(mockCreateTypedElementTemplate.mock.calls).toEqual([[
2296
+ 'list',
2297
+ {
2298
+ 'component-at-index': expect.any(Function),
2299
+ 'enqueue-component': expect.any(Function),
2300
+ },
2301
+ [],
2302
+ 32,
2303
+ null,
2304
+ ]]);
2305
+ expect(elementTemplateRegistry.has(32)).toBe(true);
2306
2306
  const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2307
- expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2308
- 'logical children in options.listChildren',
2309
- );
2310
- resetReportedErrors();
2307
+ expect(reportError.mock.calls).toHaveLength(0);
2311
2308
  });
2312
2309
 
2313
- it('rejects exact typed list create with visible child slots', () => {
2310
+ it('rejects typed list create with logical children outside slot 0', () => {
2314
2311
  envManager.switchToMainThread();
2315
2312
  elementTemplateRegistry.clear();
2316
- const slotChildRef = createMockElementTemplateHandle('slot-child');
2317
- const itemRef = createMockElementTemplateHandle('item');
2318
- elementTemplateRegistry.set(11, slotChildRef);
2319
- elementTemplateRegistry.set(12, itemRef);
2313
+ const firstItemRef = createMockElementTemplateHandle('first-item');
2314
+ const secondItemRef = createMockElementTemplateHandle('second-item');
2315
+ elementTemplateRegistry.set(11, firstItemRef);
2316
+ elementTemplateRegistry.set(12, secondItemRef);
2320
2317
  mockCreateTypedElementTemplate.mockClear();
2321
2318
 
2322
2319
  applyElementTemplateUpdateCommands([
@@ -2324,15 +2321,15 @@ describe('ElementTemplate patch stream (apply)', () => {
2324
2321
  30,
2325
2322
  'list',
2326
2323
  null,
2327
- [[11]],
2328
- { listChildren: [{ __etHandleRef: 12, type: '_et_item', platformInfo: {} }] },
2324
+ [[11], [12]],
2325
+ {},
2329
2326
  ]);
2330
2327
 
2331
2328
  expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2332
2329
  expect(elementTemplateRegistry.has(30)).toBe(false);
2333
2330
  const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2334
2331
  expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2335
- 'logical children in options.listChildren',
2332
+ 'only supports logical slot 0',
2336
2333
  );
2337
2334
  resetReportedErrors();
2338
2335
  });
@@ -2420,28 +2417,6 @@ describe('ElementTemplate patch stream (apply)', () => {
2420
2417
  resetReportedErrors();
2421
2418
  });
2422
2419
 
2423
- it('reports invalid non-array childSlots on typed create', () => {
2424
- envManager.switchToMainThread();
2425
- elementTemplateRegistry.clear();
2426
- mockCreateTypedElementTemplate.mockClear();
2427
-
2428
- applyElementTemplateUpdateCommands([
2429
- ElementTemplateUpdateOps.createTypedElement,
2430
- 27,
2431
- 'typed-host',
2432
- null,
2433
- 'bad-slots' as unknown as ElementTemplateUpdateCommandStream[number],
2434
- null,
2435
- ]);
2436
-
2437
- expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2438
- const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2439
- expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2440
- 'childSlots must be an array, null, or undefined',
2441
- );
2442
- resetReportedErrors();
2443
- });
2444
-
2445
2420
  it('skips typed create when child slot handles are unresolved', () => {
2446
2421
  envManager.switchToMainThread();
2447
2422
  elementTemplateRegistry.clear();
@@ -2473,70 +2448,39 @@ describe('ElementTemplate patch stream (apply)', () => {
2473
2448
  42,
2474
2449
  'list',
2475
2450
  null,
2476
- [],
2477
- { listChildren: [{ __etHandleRef: 404, type: '_et_item', platformInfo: {} }] },
2451
+ [[404]],
2452
+ {},
2478
2453
  ]);
2479
2454
 
2480
2455
  expect(mockCreateTypedElementTemplate.mock.calls).toHaveLength(0);
2481
2456
  expect(elementTemplateRegistry.has(42)).toBe(false);
2482
2457
  const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2483
- expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2484
- 'typed list item 0 handle 404 not found',
2485
- );
2458
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('child handle 404 not found');
2486
2459
  resetReportedErrors();
2487
2460
  });
2488
2461
 
2489
- it('skips typed list item patches when the item handle is unresolved', () => {
2462
+ it('skips typed list item updates when the item handle is unresolved', () => {
2490
2463
  envManager.switchToMainThread();
2491
2464
  elementTemplateRegistry.clear();
2492
2465
  const listRef = createMockElementTemplateHandle('typed-list', 41);
2493
2466
  elementTemplateRegistry.set(41, listRef);
2494
- registerElementTemplateListState(41, createElementTemplateListState([]), false, listRef);
2495
- mockSetElementTemplateAttributeSlot.mockClear();
2496
2467
 
2497
2468
  applyElementTemplateUpdateCommands([
2498
- ElementTemplateUpdateOps.insertTypedListItem,
2499
- 41,
2500
- { __etHandleRef: 404, type: '_et_item', platformInfo: {} },
2501
- 0,
2502
2469
  ElementTemplateUpdateOps.updateTypedListItem,
2503
2470
  41,
2504
- { __etHandleRef: 405, type: '_et_item', platformInfo: {} },
2471
+ { __etHandleRef: 405, type: '_et_item', platformInfo: {}, subtreeHandleIds: null },
2505
2472
  ]);
2506
2473
 
2474
+ expect(__SetListItemInfoOfTemplate).not.toHaveBeenCalled();
2507
2475
  expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
2508
2476
  const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2509
- expect(reportError.mock.calls).toHaveLength(2);
2477
+ expect(reportError.mock.calls).toHaveLength(1);
2510
2478
  expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2511
- 'typed list insert item handle 404 not found',
2512
- );
2513
- expect(String(reportError.mock.calls[1]?.[0]?.message ?? '')).toContain(
2514
2479
  'typed list update item handle 405 not found',
2515
2480
  );
2516
2481
  resetReportedErrors();
2517
2482
  });
2518
2483
 
2519
- it('skips pending typed list flushes when the list handle is unresolved', () => {
2520
- envManager.switchToMainThread();
2521
- elementTemplateRegistry.clear();
2522
- const listRef = createMockElementTemplateHandle('typed-list');
2523
- registerElementTemplateListState(91, createElementTemplateListState([]), true, listRef);
2524
- mockSetElementTemplateAttributeSlot.mockClear();
2525
-
2526
- applyElementTemplateUpdateCommands([]);
2527
-
2528
- expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
2529
- const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2530
- expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain('typed list handle 91 not found');
2531
- resetReportedErrors();
2532
- });
2533
-
2534
- it('reports missing list item records when constructing typed list state', () => {
2535
- expect(() => createElementTemplateListState([404])).toThrow(
2536
- 'Element Template typed list received a non-list-item root in logical slot $0.',
2537
- );
2538
- });
2539
-
2540
2484
  it('sets typed slot 0 attributes through the standard attr-slot PAPI', () => {
2541
2485
  envManager.switchToMainThread();
2542
2486
  const targetRef = createMockElementTemplateHandle('typed-target');
@@ -2544,22 +2488,18 @@ describe('ElementTemplate patch stream (apply)', () => {
2544
2488
  mockSetAttribute.mockClear();
2545
2489
  mockSetElementTemplateAttributeSlot.mockClear();
2546
2490
 
2547
- const updateListInfo = {
2548
- insertAction: [],
2549
- removeAction: [],
2550
- updateAction: [],
2551
- };
2491
+ const attributes = { id: 'updated-list' };
2552
2492
  applyElementTemplateUpdateCommands([
2553
2493
  ElementTemplateUpdateOps.setAttribute,
2554
2494
  31,
2555
2495
  0,
2556
- { 'update-list-info': updateListInfo },
2496
+ attributes,
2557
2497
  ]);
2558
2498
 
2559
2499
  expect(mockSetElementTemplateAttributeSlot.mock.calls).toEqual([[
2560
2500
  targetRef,
2561
2501
  0,
2562
- { 'update-list-info': updateListInfo },
2502
+ attributes,
2563
2503
  ]]);
2564
2504
  expect(mockSetAttribute.mock.calls).toHaveLength(0);
2565
2505
  });
@@ -2568,7 +2508,11 @@ describe('ElementTemplate patch stream (apply)', () => {
2568
2508
  envManager.switchToMainThread();
2569
2509
  const listRef = createMockElementTemplateHandle('typed-list', 95);
2570
2510
  elementTemplateRegistry.set(29, listRef);
2571
- registerElementTemplateListState(29, createElementTemplateListState([], { id: 'old' }), false, listRef);
2511
+ const state = createElementTemplateListState();
2512
+ registerElementTemplateListState(29, state, listRef);
2513
+ const initialAttributes = composeElementTemplateListAttributes({ id: 'old', class: 'initial' }, state);
2514
+ expect(initialAttributes).not.toHaveProperty('component-at-indexes');
2515
+ expect(state.callbacks).not.toHaveProperty('componentAtIndexes');
2572
2516
 
2573
2517
  applyElementTemplateUpdateCommands([
2574
2518
  ElementTemplateUpdateOps.setAttribute,
@@ -2582,9 +2526,24 @@ describe('ElementTemplate patch stream (apply)', () => {
2582
2526
  0,
2583
2527
  {
2584
2528
  id: 'next',
2585
- 'component-at-index': expect.any(Function),
2586
- 'component-at-indexes': expect.any(Function),
2587
- 'enqueue-component': expect.any(Function),
2529
+ 'component-at-index': initialAttributes['component-at-index'],
2530
+ 'enqueue-component': initialAttributes['enqueue-component'],
2531
+ },
2532
+ ]);
2533
+
2534
+ applyElementTemplateUpdateCommands([
2535
+ ElementTemplateUpdateOps.setAttribute,
2536
+ 29,
2537
+ 0,
2538
+ null,
2539
+ ]);
2540
+
2541
+ expect(mockSetElementTemplateAttributeSlot.mock.calls[1]).toEqual([
2542
+ listRef,
2543
+ 0,
2544
+ {
2545
+ 'component-at-index': initialAttributes['component-at-index'],
2546
+ 'enqueue-component': initialAttributes['enqueue-component'],
2588
2547
  },
2589
2548
  ]);
2590
2549
  });
@@ -2611,805 +2570,295 @@ describe('ElementTemplate patch stream (apply)', () => {
2611
2570
  expect(mockSetAttribute.mock.calls).toHaveLength(0);
2612
2571
  });
2613
2572
 
2614
- it('inserts before writing update-list-info', () => {
2573
+ it('inserts logical List items through the standard child-slot PAPI', () => {
2615
2574
  envManager.switchToMainThread();
2616
2575
  const listRef = createMockElementTemplateHandle('typed-list', 100);
2617
- const materializedList = createMaterializedListForFrontendTest(100);
2618
2576
  const firstRef = createMockElementTemplateHandle('first', 101);
2619
2577
  const secondRef = createMockElementTemplateHandle('second', 102);
2620
2578
  elementTemplateRegistry.set(31, listRef);
2621
2579
  elementTemplateRegistry.set(32, firstRef);
2622
2580
  elementTemplateRegistry.set(33, secondRef);
2623
- registerElementTemplateListItem(32, firstRef, {
2624
- templateKey: '_et_item_a',
2625
- platformInfo: { 'item-key': 'a' },
2626
- });
2627
- const state = createElementTemplateListState([32]);
2628
- registerElementTemplateListState(31, state, false, listRef);
2629
- const attrs = composeElementTemplateListAttributes({ id: 'feed' }, state);
2630
- const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
2631
- mockSetElementTemplateAttributeSlot.mockImplementationOnce((...args: unknown[]) => {
2632
- expect(componentAtIndex(materializedList, 7, 1, 99, false)).toBe(102);
2633
- expect(mockInsertElementTemplateNodeIntoSlot.mock.calls[0]).toEqual([listRef, 0, secondRef, null]);
2634
- lastMock!.mockSetElementTemplateAttributeSlot(...args);
2635
- });
2636
2581
 
2637
2582
  applyElementTemplateUpdateCommands([
2638
- ElementTemplateUpdateOps.insertTypedListItem,
2583
+ ElementTemplateUpdateOps.insertNode,
2639
2584
  31,
2640
- {
2641
- __etHandleRef: 33,
2642
- type: '_et_item_b',
2643
- platformInfo: { 'item-key': 'b' },
2644
- },
2645
2585
  0,
2586
+ 33,
2587
+ 32,
2588
+ null,
2646
2589
  ]);
2647
2590
 
2648
- expect(mockSetElementTemplateAttributeSlot.mock.calls[0]).toEqual([
2591
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toEqual([[
2649
2592
  listRef,
2650
2593
  0,
2651
- {
2652
- id: 'feed',
2653
- 'component-at-index': attrs['component-at-index'],
2654
- 'component-at-indexes': attrs['component-at-indexes'],
2655
- 'enqueue-component': attrs['enqueue-component'],
2656
- 'update-list-info': {
2657
- insertAction: [{ position: 1, type: '_et_item_b', 'item-key': 'b' }],
2658
- removeAction: [],
2659
- updateAction: [],
2660
- },
2661
- },
2662
- ]);
2594
+ secondRef,
2595
+ firstRef,
2596
+ ]]);
2597
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
2663
2598
  expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
2664
2599
  expect(elementTemplateRegistry.get(32)).toBe(firstRef);
2665
2600
  });
2666
2601
 
2667
- it('preserves update-list-info when list attributes update after list mutation in the same stream', () => {
2668
- envManager.switchToMainThread();
2669
- const listRef = createMockElementTemplateHandle('typed-list', 105);
2670
- const firstRef = createMockElementTemplateHandle('first', 106);
2671
- const secondRef = createMockElementTemplateHandle('second', 107);
2672
- elementTemplateRegistry.set(35, listRef);
2673
- elementTemplateRegistry.set(36, firstRef);
2674
- elementTemplateRegistry.set(37, secondRef);
2675
- registerElementTemplateListItem(36, firstRef, {
2676
- templateKey: '_et_item_a',
2677
- platformInfo: { 'item-key': 'a' },
2678
- });
2679
- registerElementTemplateListState(
2680
- 35,
2681
- createElementTemplateListState([36], { id: 'feed' }),
2682
- false,
2683
- listRef,
2684
- );
2685
-
2686
- applyElementTemplateUpdateCommands([
2687
- ElementTemplateUpdateOps.insertTypedListItem,
2688
- 35,
2689
- {
2690
- __etHandleRef: 37,
2691
- type: '_et_item_b',
2692
- platformInfo: { 'item-key': 'b' },
2693
- },
2694
- 0,
2695
- ElementTemplateUpdateOps.setAttribute,
2696
- 35,
2697
- 0,
2698
- { id: 'next' },
2699
- ]);
2700
-
2701
- const attrWrite = mockSetElementTemplateAttributeSlot.mock.calls[0]![2] as Record<string, unknown>;
2702
- const finalWrite = mockSetElementTemplateAttributeSlot.mock.calls[1]![2] as Record<string, unknown>;
2703
- const updateListInfo = {
2704
- insertAction: [{ position: 1, type: '_et_item_b', 'item-key': 'b' }],
2705
- removeAction: [],
2706
- updateAction: [],
2707
- };
2708
- expect(attrWrite).toEqual(expect.objectContaining({
2709
- id: 'next',
2710
- 'component-at-index': expect.any(Function),
2711
- 'component-at-indexes': expect.any(Function),
2712
- 'enqueue-component': expect.any(Function),
2713
- }));
2714
- expect(attrWrite).not.toHaveProperty('update-list-info');
2715
- expect(finalWrite).toEqual(expect.objectContaining({
2716
- id: 'next',
2717
- 'update-list-info': updateListInfo,
2718
- 'component-at-index': attrWrite['component-at-index'],
2719
- 'component-at-indexes': attrWrite['component-at-indexes'],
2720
- 'enqueue-component': attrWrite['enqueue-component'],
2721
- }));
2722
- });
2723
-
2724
- it('coalesces multiple incremental list mutations into one Snapshot-shaped update-list-info write', () => {
2725
- envManager.switchToMainThread();
2726
- const listRef = createMockElementTemplateHandle('typed-list', 200);
2727
- const refs = [201, 202, 203, 204, 205].map(id =>
2728
- ({ __isNativeRef: true, id: `item-${id}`, __mockNativeId: id }) as unknown as ElementTemplateHandle
2729
- );
2730
- elementTemplateRegistry.set(200, listRef);
2731
- for (let index = 0; index < refs.length; index += 1) {
2732
- const handleId = 201 + index;
2733
- elementTemplateRegistry.set(handleId, refs[index]!);
2734
- if (handleId <= 203) {
2735
- registerElementTemplateListItem(handleId, refs[index]!, {
2736
- templateKey: `_et_item_${handleId}`,
2737
- platformInfo: { 'item-key': String(handleId) },
2738
- });
2739
- }
2740
- }
2741
- registerElementTemplateListState(200, createElementTemplateListState([201, 202, 203]), false, listRef);
2742
-
2743
- applyElementTemplateUpdateCommands([
2744
- ElementTemplateUpdateOps.insertTypedListItem,
2745
- 200,
2746
- { __etHandleRef: 204, type: '_et_item_204', platformInfo: { 'item-key': '204' } },
2747
- 202,
2748
- ElementTemplateUpdateOps.insertTypedListItem,
2749
- 200,
2750
- { __etHandleRef: 205, type: '_et_item_205', platformInfo: { 'item-key': '205' } },
2751
- 204,
2752
- ElementTemplateUpdateOps.removeTypedListItem,
2753
- 200,
2754
- 202,
2755
- [202],
2756
- ElementTemplateUpdateOps.removeTypedListItem,
2757
- 200,
2758
- 203,
2759
- [],
2760
- ElementTemplateUpdateOps.insertTypedListItem,
2761
- 200,
2762
- { __etHandleRef: 203, type: '_et_item_203', platformInfo: { 'item-key': '203' } },
2763
- 0,
2764
- ]);
2765
-
2766
- expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(1);
2767
- expect(mockSetElementTemplateAttributeSlot.mock.calls[0]).toEqual([
2768
- listRef,
2769
- 0,
2770
- {
2771
- 'component-at-index': expect.any(Function),
2772
- 'component-at-indexes': expect.any(Function),
2773
- 'enqueue-component': expect.any(Function),
2774
- 'update-list-info': {
2775
- insertAction: [
2776
- { position: 1, type: '_et_item_205', 'item-key': '205' },
2777
- { position: 2, type: '_et_item_204', 'item-key': '204' },
2778
- { position: 3, type: '_et_item_203', 'item-key': '203' },
2779
- ],
2780
- removeAction: [1, 2],
2781
- updateAction: [],
2782
- },
2783
- },
2784
- ]);
2785
- expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
2786
- expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
2787
- });
2788
-
2789
- it('coalesces platform info updates and indexes them after same-batch insertions', () => {
2790
- envManager.switchToMainThread();
2791
- const listRef = createMockElementTemplateHandle('typed-list', 210);
2792
- const aRef = createMockElementTemplateHandle('a', 211);
2793
- const bRef = createMockElementTemplateHandle('b', 212);
2794
- const dRef = createMockElementTemplateHandle('d', 213);
2795
- elementTemplateRegistry.set(210, listRef);
2796
- elementTemplateRegistry.set(211, aRef);
2797
- elementTemplateRegistry.set(212, bRef);
2798
- elementTemplateRegistry.set(213, dRef);
2799
- registerElementTemplateListItem(211, aRef, {
2800
- templateKey: '_et_item_a',
2801
- platformInfo: { 'item-key': 'a' },
2802
- });
2803
- registerElementTemplateListItem(212, bRef, {
2804
- templateKey: '_et_item_b',
2805
- platformInfo: { 'item-key': 'b' },
2806
- });
2807
- registerElementTemplateListState(210, createElementTemplateListState([211, 212]), false, listRef);
2808
-
2809
- applyElementTemplateUpdateCommands([
2810
- ElementTemplateUpdateOps.insertTypedListItem,
2811
- 210,
2812
- { __etHandleRef: 213, type: '_et_item_d', platformInfo: { 'item-key': 'd' } },
2813
- 212,
2814
- ElementTemplateUpdateOps.updateTypedListItem,
2815
- 210,
2816
- { __etHandleRef: 211, type: '_et_item_a', platformInfo: { 'item-key': 'a', 'full-span': true } },
2817
- ElementTemplateUpdateOps.updateTypedListItem,
2818
- 210,
2819
- { __etHandleRef: 212, type: '_et_item_b', platformInfo: { 'item-key': 'b', 'estimated-height': 42 } },
2820
- ]);
2821
-
2822
- expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(1);
2823
- expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![2]).toEqual(expect.objectContaining({
2824
- 'update-list-info': {
2825
- insertAction: [{ position: 1, type: '_et_item_d', 'item-key': 'd' }],
2826
- removeAction: [],
2827
- updateAction: [
2828
- { from: 0, to: 0, type: '_et_item_a', flush: false, 'item-key': 'a', 'full-span': true },
2829
- { from: 2, to: 2, type: '_et_item_b', flush: false, 'item-key': 'b', 'estimated-height': 42 },
2830
- ],
2831
- },
2832
- }));
2833
- });
2834
-
2835
- it('skips no-op list item platform info updates', () => {
2602
+ it('skips native platform info updates when the payload omits platform info', () => {
2836
2603
  envManager.switchToMainThread();
2837
2604
  const listRef = createMockElementTemplateHandle('typed-list', 214);
2838
2605
  const itemRef = createMockElementTemplateHandle('a', 2141);
2839
2606
  elementTemplateRegistry.set(214, listRef);
2840
2607
  elementTemplateRegistry.set(2141, itemRef);
2841
- registerElementTemplateListItem(2141, itemRef, {
2842
- templateKey: '_et_item_a',
2843
- platformInfo: { 'item-key': 'a' },
2844
- });
2845
- registerElementTemplateListState(214, createElementTemplateListState([2141]), false, listRef);
2846
2608
 
2847
2609
  applyElementTemplateUpdateCommands([
2848
2610
  ElementTemplateUpdateOps.updateTypedListItem,
2849
2611
  214,
2850
- { __etHandleRef: 2141, type: '_et_item_a', platformInfo: { 'item-key': 'a' } },
2612
+ { __etHandleRef: 2141, type: '_et_item_a', platformInfo: null, subtreeHandleIds: null },
2851
2613
  ]);
2852
2614
 
2615
+ expect(__SetListItemInfoOfTemplate).not.toHaveBeenCalled();
2853
2616
  expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
2854
2617
  });
2855
2618
 
2856
- it('folds moved item platform info into the incremental insert action', () => {
2857
- envManager.switchToMainThread();
2858
- const listRef = createMockElementTemplateHandle('typed-list', 215);
2859
- const aRef = createMockElementTemplateHandle('a', 216);
2860
- const bRef = createMockElementTemplateHandle('b', 217);
2861
- elementTemplateRegistry.set(215, listRef);
2862
- elementTemplateRegistry.set(216, aRef);
2863
- elementTemplateRegistry.set(217, bRef);
2864
- registerElementTemplateListItem(216, aRef, {
2865
- templateKey: '_et_item_a',
2866
- platformInfo: { 'item-key': 'a' },
2867
- });
2868
- registerElementTemplateListItem(217, bRef, {
2869
- templateKey: '_et_item_b',
2870
- platformInfo: { 'item-key': 'b' },
2871
- });
2872
- registerElementTemplateListState(215, createElementTemplateListState([216, 217]), false, listRef);
2873
-
2874
- applyElementTemplateUpdateCommands([
2875
- ElementTemplateUpdateOps.removeTypedListItem,
2876
- 215,
2877
- 217,
2878
- [],
2879
- ElementTemplateUpdateOps.insertTypedListItem,
2880
- 215,
2881
- { __etHandleRef: 217, type: '_et_item_b', platformInfo: { 'item-key': 'b' } },
2882
- 216,
2883
- ElementTemplateUpdateOps.updateTypedListItem,
2884
- 215,
2885
- { __etHandleRef: 217, type: '_et_item_b', platformInfo: { 'item-key': 'b', 'full-span': true } },
2886
- ]);
2887
-
2888
- expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(1);
2889
- expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![2]).toEqual(expect.objectContaining({
2890
- 'update-list-info': {
2891
- insertAction: [{ position: 0, type: '_et_item_b', 'item-key': 'b', 'full-span': true }],
2892
- removeAction: [1],
2893
- updateAction: [],
2894
- },
2895
- }));
2896
- });
2897
-
2898
- it('places an insertion before a moved item at the moved item final position', () => {
2899
- envManager.switchToMainThread();
2900
- const listRef = createMockElementTemplateHandle('typed-list', 218);
2901
- const aRef = createMockElementTemplateHandle('a', 2181);
2902
- const bRef = createMockElementTemplateHandle('b', 2182);
2903
- const cRef = createMockElementTemplateHandle('c', 2183);
2904
- const xRef = createMockElementTemplateHandle('x', 2184);
2905
- elementTemplateRegistry.set(218, listRef);
2906
- elementTemplateRegistry.set(2181, aRef);
2907
- elementTemplateRegistry.set(2182, bRef);
2908
- elementTemplateRegistry.set(2183, cRef);
2909
- elementTemplateRegistry.set(2184, xRef);
2910
- registerElementTemplateListItem(2181, aRef, {
2911
- templateKey: '_et_item_a',
2912
- platformInfo: { 'item-key': 'a' },
2913
- });
2914
- registerElementTemplateListItem(2182, bRef, {
2915
- templateKey: '_et_item_b',
2916
- platformInfo: { 'item-key': 'b' },
2917
- });
2918
- registerElementTemplateListItem(2183, cRef, {
2919
- templateKey: '_et_item_c',
2920
- platformInfo: { 'item-key': 'c' },
2921
- });
2922
- registerElementTemplateListState(218, createElementTemplateListState([2181, 2182, 2183]), false, listRef);
2923
-
2924
- applyElementTemplateUpdateCommands([
2925
- ElementTemplateUpdateOps.removeTypedListItem,
2926
- 218,
2927
- 2181,
2928
- [],
2929
- ElementTemplateUpdateOps.removeTypedListItem,
2930
- 218,
2931
- 2183,
2932
- [2183],
2933
- ElementTemplateUpdateOps.insertTypedListItem,
2934
- 218,
2935
- { __etHandleRef: 2181, type: '_et_item_a', platformInfo: { 'item-key': 'a', 'reuse-identifier': 'next' } },
2936
- 0,
2937
- ElementTemplateUpdateOps.insertTypedListItem,
2938
- 218,
2939
- { __etHandleRef: 2184, type: '_et_item_x', platformInfo: { 'item-key': 'x' } },
2940
- 2181,
2941
- ]);
2942
-
2943
- expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(1);
2944
- expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![2]).toEqual(expect.objectContaining({
2945
- 'update-list-info': {
2946
- insertAction: [
2947
- { position: 1, type: '_et_item_x', 'item-key': 'x' },
2948
- { position: 2, type: '_et_item_a', 'item-key': 'a', 'reuse-identifier': 'next' },
2949
- ],
2950
- removeAction: [0, 2],
2951
- updateAction: [],
2952
- },
2953
- }));
2954
- });
2955
-
2956
- it('flushes incremental list updates with the latest slot 0 attributes regardless of stream order', () => {
2619
+ it('keeps list callbacks stable after removing a logical item', () => {
2957
2620
  envManager.switchToMainThread();
2958
- const listRef = createMockElementTemplateHandle('typed-list', 220);
2959
- const firstRef = createMockElementTemplateHandle('first', 221);
2960
- const secondRef = createMockElementTemplateHandle('second', 222);
2961
- elementTemplateRegistry.set(220, listRef);
2962
- elementTemplateRegistry.set(221, firstRef);
2963
- elementTemplateRegistry.set(222, secondRef);
2964
- registerElementTemplateListItem(221, firstRef, {
2965
- templateKey: '_et_item_a',
2966
- platformInfo: { 'item-key': 'a' },
2967
- });
2968
- registerElementTemplateListState(220, createElementTemplateListState([221], { id: 'old' }), false, listRef);
2969
-
2970
- applyElementTemplateUpdateCommands([
2971
- ElementTemplateUpdateOps.setAttribute,
2972
- 220,
2973
- 0,
2974
- { id: 'intermediate' },
2975
- ElementTemplateUpdateOps.insertTypedListItem,
2976
- 220,
2977
- { __etHandleRef: 222, type: '_et_item_b', platformInfo: { 'item-key': 'b' } },
2978
- 0,
2979
- ElementTemplateUpdateOps.setAttribute,
2980
- 220,
2981
- 0,
2982
- { id: 'final' },
2983
- ]);
2984
-
2985
- expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(3);
2986
- const latestAttrWrite = mockSetElementTemplateAttributeSlot.mock.calls[1]![2] as Record<string, unknown>;
2987
- expect(mockSetElementTemplateAttributeSlot.mock.calls[2]![2]).toEqual(expect.objectContaining({
2988
- id: 'final',
2989
- 'update-list-info': {
2990
- insertAction: [{ position: 1, type: '_et_item_b', 'item-key': 'b' }],
2991
- removeAction: [],
2992
- updateAction: [],
2993
- },
2994
- 'component-at-index': latestAttrWrite['component-at-index'],
2995
- 'component-at-indexes': latestAttrWrite['component-at-indexes'],
2996
- 'enqueue-component': latestAttrWrite['enqueue-component'],
2997
- }));
2998
- });
2999
-
3000
- it('moves an attached item on native request', () => {
3001
- envManager.switchToMainThread();
3002
- const listRef = createMockElementTemplateHandle('typed-list', 225);
3003
- const materializedList = createMaterializedListForFrontendTest(225);
3004
- const aRef = createMockElementTemplateHandle('a', 226);
3005
- const bRef = createMockElementTemplateHandle('b', 227);
3006
- elementTemplateRegistry.set(225, listRef);
3007
- elementTemplateRegistry.set(226, aRef);
3008
- elementTemplateRegistry.set(227, bRef);
3009
- registerElementTemplateListItem(226, aRef, {
3010
- templateKey: '_et_item_a',
3011
- platformInfo: { 'item-key': 'a' },
3012
- });
3013
- registerElementTemplateListItem(227, bRef, {
3014
- templateKey: '_et_item_b',
3015
- platformInfo: { 'item-key': 'b' },
3016
- });
3017
- const state = createElementTemplateListState([226, 227]);
3018
- registerElementTemplateListState(225, state, false, listRef);
2621
+ const listRef = createMockElementTemplateHandle('typed-list', 110);
2622
+ const itemRef = createMockElementTemplateHandle('item', 111);
2623
+ elementTemplateRegistry.set(41, listRef);
2624
+ elementTemplateRegistry.set(42, itemRef);
2625
+ const state = createElementTemplateListState();
2626
+ registerElementTemplateListState(41, state, listRef);
3019
2627
  const attrs = composeElementTemplateListAttributes(null, state);
3020
- const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
3021
- const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
3022
- expect(componentAtIndex(materializedList, 7, 0, 88, false)).toBe(226);
3023
- expect(componentAtIndex(materializedList, 7, 1, 89, false)).toBe(227);
3024
- mockInsertElementTemplateNodeIntoSlot.mockClear();
3025
- mockRemoveElementTemplateNodeFromSlot.mockClear();
3026
-
3027
- applyElementTemplateUpdateCommands([
3028
- ElementTemplateUpdateOps.removeTypedListItem,
3029
- 225,
3030
- 227,
3031
- [],
3032
- ElementTemplateUpdateOps.insertTypedListItem,
3033
- 225,
3034
- { __etHandleRef: 227, type: '_et_item_b', platformInfo: { 'item-key': 'b' } },
3035
- 226,
3036
- ]);
3037
- mockInsertElementTemplateNodeIntoSlot.mockClear();
3038
- mockRemoveElementTemplateNodeFromSlot.mockClear();
2628
+ const componentAtIndex = attrs['component-at-index'] as (listUid: number, itemUid: number) => void;
2629
+ const enqueueComponent = attrs['enqueue-component'] as (listUid: number, itemUid: number) => void;
3039
2630
 
3040
- expect(componentAtIndex(materializedList, 7, 0, 90, false)).toBe(227);
3041
-
3042
- expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toEqual([[listRef, 0, bRef, aRef]]);
3043
- expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
3044
- enqueueComponent(materializedList, 7, 227);
3045
- expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
3046
- enqueueComponent(materializedList, 7, 227);
3047
- expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[listRef, 0, bRef]]);
3048
- });
3049
-
3050
- it('places multiple attached moves', () => {
3051
- envManager.switchToMainThread();
3052
- const listRef = createMockElementTemplateHandle('typed-list', 240);
3053
- const materializedList = createMaterializedListForFrontendTest(240);
3054
- const aRef = createMockElementTemplateHandle('a', 241);
3055
- const bRef = createMockElementTemplateHandle('b', 242);
3056
- const cRef = createMockElementTemplateHandle('c', 243);
3057
- elementTemplateRegistry.set(240, listRef);
3058
- elementTemplateRegistry.set(241, aRef);
3059
- elementTemplateRegistry.set(242, bRef);
3060
- elementTemplateRegistry.set(243, cRef);
3061
- registerElementTemplateListItem(241, aRef, {
3062
- templateKey: '_et_item_a',
3063
- platformInfo: { 'item-key': 'a' },
3064
- });
3065
- registerElementTemplateListItem(242, bRef, {
3066
- templateKey: '_et_item_b',
3067
- platformInfo: { 'item-key': 'b' },
3068
- });
3069
- registerElementTemplateListItem(243, cRef, {
3070
- templateKey: '_et_item_c',
3071
- platformInfo: { 'item-key': 'c' },
3072
- });
3073
- const state = createElementTemplateListState([241, 242, 243]);
3074
- registerElementTemplateListState(240, state, false, listRef);
3075
- const attrs = composeElementTemplateListAttributes(null, state);
3076
- const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
3077
- const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
3078
- expect(componentAtIndex(materializedList, 7, 0, 80, false)).toBe(241);
3079
- expect(componentAtIndex(materializedList, 7, 1, 81, false)).toBe(242);
3080
- expect(componentAtIndex(materializedList, 7, 2, 82, false)).toBe(243);
3081
- mockInsertElementTemplateNodeIntoSlot.mockClear();
3082
- mockRemoveElementTemplateNodeFromSlot.mockClear();
2631
+ expect(componentAtIndex(41, 42)).toBeUndefined();
3083
2632
 
3084
2633
  applyElementTemplateUpdateCommands([
3085
- ElementTemplateUpdateOps.removeTypedListItem,
3086
- 240,
3087
- 243,
3088
- [],
3089
- ElementTemplateUpdateOps.insertTypedListItem,
3090
- 240,
3091
- { __etHandleRef: 243, type: '_et_item_c', platformInfo: { 'item-key': 'c' } },
3092
- 241,
3093
- ElementTemplateUpdateOps.removeTypedListItem,
3094
- 240,
3095
- 241,
3096
- [],
3097
- ElementTemplateUpdateOps.insertTypedListItem,
3098
- 240,
3099
- { __etHandleRef: 241, type: '_et_item_a', platformInfo: { 'item-key': 'a' } },
2634
+ ElementTemplateUpdateOps.removeNode,
2635
+ 41,
3100
2636
  0,
2637
+ 42,
2638
+ [42],
3101
2639
  ]);
3102
- mockInsertElementTemplateNodeIntoSlot.mockClear();
2640
+
2641
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[listRef, 0, itemRef]]);
2642
+ expect(elementTemplateRegistry.get(42)).toBeUndefined();
2643
+ expect(state.destroyed).toBe(false);
2644
+ expect(state.holderRef).toBe(listRef);
2645
+ expect(state.mountedItemUids.has(42)).toBe(false);
2646
+ expect(state.callbacks.componentAtIndex).toBe(componentAtIndex);
2647
+ expect(state.callbacks.enqueueComponent).toBe(enqueueComponent);
3103
2648
  mockRemoveElementTemplateNodeFromSlot.mockClear();
3104
2649
 
3105
- expect(componentAtIndex(materializedList, 7, 0, 90, false)).toBe(243);
2650
+ enqueueComponent(41, 42);
2651
+ enqueueComponent(41, 42);
3106
2652
 
3107
- expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toEqual([
3108
- [listRef, 0, aRef, null],
3109
- [listRef, 0, cRef, bRef],
3110
- ]);
3111
- enqueueComponent(materializedList, 7, 243);
3112
- enqueueComponent(materializedList, 7, 241);
2653
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
3113
2654
  expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
3114
- expect(componentAtIndex(materializedList, 7, 1, 91, false)).toBe(242);
2655
+ expect(mockFlushElementTree.mock.calls).toHaveLength(0);
2656
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
3115
2657
  });
3116
2658
 
3117
- it('preserves moved item registry during removal', () => {
2659
+ it('keeps typed list callbacks free of JS mounting and recycling', () => {
3118
2660
  envManager.switchToMainThread();
3119
- const listRef = createMockElementTemplateHandle('typed-list', 230);
3120
- const materializedList = createMaterializedListForFrontendTest(230);
3121
- const firstRef = createMockElementTemplateHandle('first', 231);
3122
- const secondRef = createMockElementTemplateHandle('second', 232);
3123
- elementTemplateRegistry.set(230, listRef);
3124
- elementTemplateRegistry.set(231, firstRef);
3125
- elementTemplateRegistry.set(232, secondRef);
3126
- registerElementTemplateListItem(231, firstRef, {
3127
- templateKey: '_et_item_a',
3128
- platformInfo: { 'item-key': 'a' },
3129
- });
3130
- registerElementTemplateListItem(232, secondRef, {
3131
- templateKey: '_et_item_b',
3132
- platformInfo: { 'item-key': 'b' },
3133
- });
3134
- const state = createElementTemplateListState([231, 232]);
3135
- registerElementTemplateListState(230, state, false, listRef);
2661
+ const listRef = createMockElementTemplateHandle('typed-list', 140);
2662
+ const state = createElementTemplateListState();
2663
+ registerElementTemplateListState(140, state, listRef);
3136
2664
  const attrs = composeElementTemplateListAttributes(null, state);
3137
- const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
3138
- const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
3139
- expect(componentAtIndex(materializedList, 7, 1, 88, false)).toBe(232);
3140
- mockInsertElementTemplateNodeIntoSlot.mockClear();
3141
- mockRemoveElementTemplateNodeFromSlot.mockClear();
3142
-
3143
- applyElementTemplateUpdateCommands([
3144
- ElementTemplateUpdateOps.removeTypedListItem,
3145
- 230,
3146
- 232,
3147
- [],
3148
- ElementTemplateUpdateOps.insertTypedListItem,
3149
- 230,
3150
- { __etHandleRef: 232, type: '_et_item_b', platformInfo: { 'item-key': 'b' } },
3151
- 231,
3152
- ElementTemplateUpdateOps.removeTypedListItem,
3153
- 230,
3154
- 231,
3155
- [231],
3156
- ]);
3157
- enqueueComponent(materializedList, 7, 232);
3158
- enqueueComponent(materializedList, 7, 231);
3159
-
3160
- expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![2]).toEqual(expect.objectContaining({
3161
- 'update-list-info': {
3162
- insertAction: [{ position: 0, type: '_et_item_b', 'item-key': 'b' }],
3163
- removeAction: [0, 1],
3164
- updateAction: [],
2665
+ const componentAtIndex = attrs['component-at-index'] as (listUid: number, itemUid: number) => void;
2666
+ const enqueueComponent = attrs['enqueue-component'] as (listUid: number, itemUid: number) => void;
2667
+
2668
+ expect(attrs).not.toHaveProperty('component-at-indexes');
2669
+ expect(state.callbacks).not.toHaveProperty('componentAtIndexes');
2670
+ expect(state).toEqual({
2671
+ listHandleId: 140,
2672
+ holderRef: listRef,
2673
+ destroyed: false,
2674
+ mountedItemUids: new Set(),
2675
+ itemSubtreeHandleIds: new Map(),
2676
+ callbacks: {
2677
+ componentAtIndex,
2678
+ enqueueComponent,
3165
2679
  },
3166
- }));
3167
- expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[listRef, 0, secondRef]]);
3168
- expect(elementTemplateRegistry.get(231)).toBeUndefined();
3169
- expect(elementTemplateRegistry.get(232)).toBe(secondRef);
2680
+ });
2681
+ expect(componentAtIndex(140, 141)).toBeUndefined();
2682
+ expect(state.mountedItemUids).toEqual(new Set([141]));
2683
+ enqueueComponent(140, 141);
2684
+ expect(state.mountedItemUids).toEqual(new Set());
2685
+ enqueueComponent(140, 141);
2686
+ enqueueComponent(140, 999);
2687
+
2688
+ expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
2689
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
2690
+ expect(mockFlushElementTree.mock.calls).toHaveLength(0);
3170
2691
  });
3171
2692
 
3172
- it('retains callback lookup until native enqueue', () => {
3173
- envManager.switchToMainThread();
3174
- const listRef = createMockElementTemplateHandle('typed-list', 110);
3175
- const materializedList = createMaterializedListForFrontendTest(110);
3176
- const firstRef = createMockElementTemplateHandle('first', 111);
3177
- elementTemplateRegistry.set(41, listRef);
3178
- elementTemplateRegistry.set(42, firstRef);
3179
- registerElementTemplateListItem(42, firstRef, {
3180
- templateKey: '_et_item_a',
3181
- platformInfo: { 'item-key': 'a' },
3182
- });
3183
- const state = createElementTemplateListState([42]);
3184
- registerElementTemplateListState(41, state, false, listRef);
3185
- const attrs = composeElementTemplateListAttributes(null, state);
3186
- const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
2693
+ it('defers unmounted list-item subtree MTRef updates until mount and skips stale removed handles', () => {
2694
+ const { updateWorkletRef, restore } = installWorkletRefRuntime();
2695
+ const previousRunWorklet = globalThis.runWorklet;
2696
+ const callbackCleanup = vi.fn();
2697
+ const callbackRef = { _wkltId: 'item-cb', _execId: 701 };
2698
+ const objectRef = { _wvid: 901 };
2699
+ globalThis.runWorklet = vi.fn(() => callbackCleanup);
2700
+ __etAttrPlanMap['__Card__:_et_item_ref'] = [0, adaptMTRefAttrSlot];
3187
2701
 
3188
- expect(componentAtIndex(materializedList, 7, 0, 88, false)).toBe(111);
3189
- mockRemoveElementTemplateNodeFromSlot.mockClear();
3190
- let enqueueComponent: EnqueueComponentCallback | undefined;
3191
- mockSetElementTemplateAttributeSlot.mockImplementationOnce((...args: unknown[]) => {
3192
- const attrs = args[2] as Record<string, unknown>;
3193
- enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
3194
- enqueueComponent(materializedList, 7, 111);
3195
- lastMock!.mockSetElementTemplateAttributeSlot(...args);
3196
- });
2702
+ try {
2703
+ envManager.switchToMainThread();
2704
+ registerTemplates([
2705
+ {
2706
+ templateId: '_et_item',
2707
+ compiledTemplate: {
2708
+ kind: 'element',
2709
+ type: 'list-item',
2710
+ children: [{ kind: 'childSlot', type: 'slot', elementSlotIndex: 0 }],
2711
+ },
2712
+ },
2713
+ {
2714
+ templateId: '_et_item_ref',
2715
+ compiledTemplate: {
2716
+ kind: 'element',
2717
+ type: 'view',
2718
+ attributesArray: [{ kind: 'slot', key: 'main-thread:ref', attrSlotIndex: 0 }],
2719
+ children: [],
2720
+ },
2721
+ },
2722
+ ]);
3197
2723
 
3198
- applyElementTemplateUpdateCommands([
3199
- ElementTemplateUpdateOps.removeTypedListItem,
3200
- 41,
3201
- 42,
3202
- [42],
3203
- ]);
2724
+ const itemARef = __CreateElementTemplate('_et_item', null, null, [[]], 710, null)!;
2725
+ const itemBRef = __CreateElementTemplate('_et_item', null, null, [[]], 711, null)!;
2726
+ const childCbRef = __CreateElementTemplate('_et_item_ref', null, [null], [], 712, null)!;
2727
+ const childObjRef = __CreateElementTemplate('_et_item_ref', null, [null], [], 713, null)!;
2728
+ const listRef = __CreateTypedElementTemplate('list', null, [[itemARef, itemBRef]], 700, {})!;
2729
+ elementTemplateRegistry.set(700, listRef);
2730
+ elementTemplateRegistry.set(710, itemARef);
2731
+ elementTemplateRegistry.set(711, itemBRef);
2732
+ elementTemplateRegistry.set(712, childCbRef);
2733
+ elementTemplateRegistry.set(713, childObjRef);
2734
+
2735
+ initializeMainThreadDynamicAttrSlots(712, '__Card__:_et_item_ref', [
2736
+ { type: 'main-thread-ref', value: callbackRef },
2737
+ ]);
2738
+ initializeMainThreadDynamicAttrSlots(713, '__Card__:_et_item_ref', [
2739
+ { type: 'main-thread-ref', value: objectRef },
2740
+ ]);
3204
2741
 
3205
- expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[listRef, 0, firstRef]]);
3206
- expect(elementTemplateRegistry.get(42)).toBeUndefined();
3207
- enqueueComponent!(materializedList, 7, 111);
3208
- expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(1);
3209
- });
2742
+ const state = createElementTemplateListState();
2743
+ registerElementTemplateListState(700, state, listRef);
2744
+ const { componentAtIndex } = state.callbacks;
3210
2745
 
3211
- it('detaches by attached state', () => {
3212
- envManager.switchToMainThread();
3213
- const listRef = createMockElementTemplateHandle('typed-list', 140);
3214
- const materializedList = createMaterializedListForFrontendTest(140);
3215
- const itemRef = createMockElementTemplateHandle('item', 141);
3216
- elementTemplateRegistry.set(140, listRef);
3217
- elementTemplateRegistry.set(141, itemRef);
3218
- registerElementTemplateListItem(141, itemRef, {
3219
- templateKey: '_et_item_a',
3220
- platformInfo: { 'item-key': 'a' },
3221
- });
3222
- const state = createElementTemplateListState([141]);
3223
- registerElementTemplateListState(140, state, false, listRef);
3224
- const attrs = composeElementTemplateListAttributes(null, state);
3225
- const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
3226
- const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
2746
+ // Unknown listUid helpers are no-ops; missing subtreeHandleIds target reports an error and skips mutation.
2747
+ updateElementTemplateListItemSubtreeHandles(999, 710, [{ uid: 712, ref: childCbRef }]);
2748
+ removeElementTemplateListItem(999, 710);
2749
+ vi.mocked(__SetListItemInfoOfTemplate).mockClear();
2750
+ applyElementTemplateUpdateCommands([
2751
+ ElementTemplateUpdateOps.updateTypedListItem,
2752
+ 700,
2753
+ {
2754
+ __etHandleRef: 710,
2755
+ type: '__Card__:_et_item',
2756
+ platformInfo: { 'item-key': 'should-skip' },
2757
+ subtreeHandleIds: [712, 404],
2758
+ },
2759
+ ]);
2760
+ expect(__SetListItemInfoOfTemplate).not.toHaveBeenCalled();
2761
+ const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;
2762
+ expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
2763
+ 'typed list item subtree handle 404 not found',
2764
+ );
2765
+ resetReportedErrors();
3227
2766
 
3228
- expect(componentAtIndex(materializedList, 7, 0, 88, false)).toBe(141);
3229
- state.items[0]!.attached = false;
3230
- mockRemoveElementTemplateNodeFromSlot.mockClear();
2767
+ // Updating an unmounted item records candidate subtree handle IDs without attaching yet, and empty clears them.
2768
+ applyElementTemplateUpdateCommands([
2769
+ ElementTemplateUpdateOps.updateTypedListItem,
2770
+ 700,
2771
+ {
2772
+ __etHandleRef: 710,
2773
+ type: '__Card__:_et_item',
2774
+ platformInfo: null,
2775
+ subtreeHandleIds: [712, 713],
2776
+ },
2777
+ ElementTemplateUpdateOps.updateTypedListItem,
2778
+ 700,
2779
+ {
2780
+ __etHandleRef: 711,
2781
+ type: '__Card__:_et_item',
2782
+ platformInfo: null,
2783
+ subtreeHandleIds: [713],
2784
+ },
2785
+ ElementTemplateUpdateOps.updateTypedListItem,
2786
+ 700,
2787
+ {
2788
+ __etHandleRef: 711,
2789
+ type: '__Card__:_et_item',
2790
+ platformInfo: null,
2791
+ subtreeHandleIds: [],
2792
+ },
2793
+ ]);
2794
+ expect(globalThis.runWorklet).not.toHaveBeenCalled();
2795
+ expect(updateWorkletRef).not.toHaveBeenCalled();
2796
+ expect(state.itemSubtreeHandleIds.has(711)).toBe(false);
3231
2797
 
3232
- enqueueComponent(materializedList, 7, 141);
3233
- enqueueComponent(materializedList, 7, 141);
2798
+ // Hydration-style removeNode of childObj (without updateTypedListItem) leaves stale UID 713 recorded;
2799
+ // componentAtIndex attaches only live handle 712, and if all recorded handles are gone it skips cleanly.
2800
+ state.itemSubtreeHandleIds.set(711, [713]);
2801
+ applyElementTemplateUpdateCommands([
2802
+ ElementTemplateUpdateOps.removeNode,
2803
+ 710,
2804
+ 0,
2805
+ 713,
2806
+ [713],
2807
+ ]);
2808
+ const expectedCbElement = __GetElementByAttrSlot(childCbRef, 0);
2809
+ componentAtIndex(700, 710);
2810
+ expect(updateWorkletRef).not.toHaveBeenCalled();
2811
+ expect(globalThis.runWorklet).toHaveBeenCalledExactlyOnceWith(callbackRef, [
2812
+ { elementRefptr: expectedCbElement },
2813
+ ]);
3234
2814
 
3235
- expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
2815
+ vi.mocked(globalThis.runWorklet).mockClear();
2816
+ componentAtIndex(700, 711);
2817
+ expect(globalThis.runWorklet).not.toHaveBeenCalled();
2818
+ expect(updateWorkletRef).not.toHaveBeenCalled();
2819
+ } finally {
2820
+ globalThis.runWorklet = previousRunWorklet;
2821
+ restore();
2822
+ }
3236
2823
  });
3237
2824
 
3238
- it('releases removed list item subtrees after the final update-list-info write', () => {
2825
+ it('releases removed List item subtrees after the native child-slot remove succeeds', () => {
3239
2826
  envManager.switchToMainThread();
3240
- const outerListRef = {
3241
- __isNativeRef: true,
3242
- id: 'outer-list',
3243
- __mockNativeId: 300,
3244
- } as unknown as ElementTemplateHandle;
2827
+ const outerListRef = createMockElementTemplateHandle('outer-list', 300);
3245
2828
  const itemRef = createMockElementTemplateHandle('item', 301);
3246
- const nestedListRef = {
3247
- __isNativeRef: true,
3248
- id: 'nested-list',
3249
- __mockNativeId: 302,
3250
- } as unknown as ElementTemplateHandle;
3251
- const nestedItemRef = {
3252
- __isNativeRef: true,
3253
- id: 'nested-item',
3254
- __mockNativeId: 303,
3255
- } as unknown as ElementTemplateHandle;
2829
+ const nestedListRef = createMockElementTemplateHandle('nested-list', 302);
2830
+ const nestedItemRef = createMockElementTemplateHandle('nested-item', 303);
3256
2831
  elementTemplateRegistry.set(300, outerListRef);
3257
2832
  elementTemplateRegistry.set(301, itemRef);
3258
2833
  elementTemplateRegistry.set(302, nestedListRef);
3259
2834
  elementTemplateRegistry.set(303, nestedItemRef);
3260
- registerElementTemplateListItem(301, itemRef, {
3261
- templateKey: '_et_item',
3262
- platformInfo: { 'item-key': 'outer' },
3263
- });
3264
- registerElementTemplateListState(300, createElementTemplateListState([301]), false, outerListRef);
3265
- registerElementTemplateListItem(303, nestedItemRef, {
3266
- templateKey: '_et_nested_item',
3267
- platformInfo: { 'item-key': 'nested' },
3268
- });
3269
- const nestedState = createElementTemplateListState([303]);
3270
- registerElementTemplateListState(302, nestedState, false, nestedListRef);
3271
- const nestedAttrs = composeElementTemplateListAttributes(null, nestedState);
3272
- const nestedComponentAtIndex = nestedAttrs['component-at-index'] as ComponentAtIndexCallback;
2835
+ const nestedState = createElementTemplateListState();
2836
+ registerElementTemplateListState(302, nestedState, nestedListRef);
3273
2837
 
3274
2838
  applyElementTemplateUpdateCommands([
3275
- ElementTemplateUpdateOps.removeTypedListItem,
2839
+ ElementTemplateUpdateOps.removeNode,
3276
2840
  300,
2841
+ 0,
3277
2842
  301,
3278
2843
  [301, 302, 303],
3279
2844
  ]);
3280
2845
 
3281
- expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![0]).toBe(outerListRef);
2846
+ expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[outerListRef, 0, itemRef]]);
3282
2847
  expect(elementTemplateRegistry.get(301)).toBeUndefined();
3283
2848
  expect(elementTemplateRegistry.get(302)).toBeUndefined();
3284
2849
  expect(elementTemplateRegistry.get(303)).toBeUndefined();
3285
- expect(nestedComponentAtIndex(createMaterializedListForFrontendTest(302), 8, 0, 91, false)).toBe(-1);
3286
- expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
3287
- });
3288
-
3289
- it('drains pending item cleanup when the list holder is removed in the same patch', () => {
3290
- envManager.switchToMainThread();
3291
- const parentRef = createMockElementTemplateHandle('parent', 299);
3292
- const listRef = createMockElementTemplateHandle('list', 300);
3293
- const itemRef = createMockElementTemplateHandle('item', 301);
3294
- const nestedListRef = {
3295
- __isNativeRef: true,
3296
- id: 'nested-list',
3297
- __mockNativeId: 302,
3298
- } as unknown as ElementTemplateHandle;
3299
- const nestedItemRef = {
3300
- __isNativeRef: true,
3301
- id: 'nested-item',
3302
- __mockNativeId: 303,
3303
- } as unknown as ElementTemplateHandle;
3304
- elementTemplateRegistry.set(299, parentRef);
3305
- elementTemplateRegistry.set(300, listRef);
3306
- elementTemplateRegistry.set(301, itemRef);
3307
- elementTemplateRegistry.set(302, nestedListRef);
3308
- elementTemplateRegistry.set(303, nestedItemRef);
3309
- registerElementTemplateListItem(301, itemRef, {
3310
- templateKey: '_et_item',
3311
- platformInfo: { 'item-key': 'outer' },
3312
- });
3313
- registerElementTemplateListState(300, createElementTemplateListState([301]), false, listRef);
3314
- registerElementTemplateListItem(303, nestedItemRef, {
3315
- templateKey: '_et_nested_item',
3316
- platformInfo: { 'item-key': 'nested' },
3317
- });
3318
- const nestedState = createElementTemplateListState([303]);
3319
- registerElementTemplateListState(302, nestedState, false, nestedListRef);
3320
- const nestedAttrs = composeElementTemplateListAttributes(null, nestedState);
3321
- const nestedComponentAtIndex = nestedAttrs['component-at-index'] as ComponentAtIndexCallback;
3322
-
3323
- applyElementTemplateUpdateCommands([
3324
- ElementTemplateUpdateOps.removeTypedListItem,
3325
- 300,
3326
- 301,
3327
- [301, 302, 303],
3328
- ElementTemplateUpdateOps.removeNode,
3329
- 299,
3330
- 0,
3331
- 300,
3332
- [300],
3333
- ]);
3334
-
3335
- expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[parentRef, 0, listRef]]);
2850
+ expect(nestedState.destroyed).toBe(true);
2851
+ expect(nestedState.holderRef).toBeNull();
3336
2852
  expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
3337
- expect(elementTemplateRegistry.get(300)).toBeUndefined();
3338
- expect(elementTemplateRegistry.get(301)).toBeUndefined();
3339
- expect(elementTemplateRegistry.get(302)).toBeUndefined();
3340
- expect(elementTemplateRegistry.get(303)).toBeUndefined();
3341
- expect(nestedComponentAtIndex(createMaterializedListForFrontendTest(302), 8, 0, 91, false)).toBe(-1);
3342
- });
3343
-
3344
- it('emits Snapshot-shaped update-list-info for incremental reorder with platform info changes', () => {
3345
- envManager.switchToMainThread();
3346
- const listRef = createMockElementTemplateHandle('typed-list', 115);
3347
- const firstRef = createMockElementTemplateHandle('first', 116);
3348
- const secondRef = createMockElementTemplateHandle('second', 117);
3349
- elementTemplateRegistry.set(51, listRef);
3350
- elementTemplateRegistry.set(52, firstRef);
3351
- elementTemplateRegistry.set(53, secondRef);
3352
- registerElementTemplateListItem(52, firstRef, {
3353
- templateKey: '_et_item_a',
3354
- platformInfo: { 'item-key': 'a', 'reuse-identifier': 'old' },
3355
- });
3356
- registerElementTemplateListItem(53, secondRef, {
3357
- templateKey: '_et_item_b',
3358
- platformInfo: { 'item-key': 'b' },
3359
- });
3360
- const state = createElementTemplateListState([52, 53]);
3361
- registerElementTemplateListState(51, state, false, listRef);
3362
-
3363
- applyElementTemplateUpdateCommands([
3364
- ElementTemplateUpdateOps.removeTypedListItem,
3365
- 51,
3366
- 52,
3367
- [],
3368
- ElementTemplateUpdateOps.insertTypedListItem,
3369
- 51,
3370
- {
3371
- __etHandleRef: 52,
3372
- type: '_et_item_a',
3373
- platformInfo: { 'item-key': 'a', 'reuse-identifier': 'old' },
3374
- },
3375
- 0,
3376
- ElementTemplateUpdateOps.updateTypedListItem,
3377
- 51,
3378
- {
3379
- __etHandleRef: 52,
3380
- type: '_et_item_a',
3381
- platformInfo: { 'item-key': 'a', 'reuse-identifier': 'new' },
3382
- },
3383
- ]);
3384
-
3385
- expect(mockSetElementTemplateAttributeSlot.mock.calls[0]).toEqual([
3386
- listRef,
3387
- 0,
3388
- {
3389
- 'component-at-index': expect.any(Function),
3390
- 'component-at-indexes': expect.any(Function),
3391
- 'enqueue-component': expect.any(Function),
3392
- 'update-list-info': {
3393
- insertAction: [{ position: 1, type: '_et_item_a', 'item-key': 'a', 'reuse-identifier': 'new' }],
3394
- removeAction: [0],
3395
- updateAction: [],
3396
- },
3397
- },
3398
- ]);
3399
2853
  });
3400
2854
 
3401
- it('emits Snapshot-shaped update-list-info for standalone platform info updates', () => {
2855
+ it('forwards List item platform info updates to native', () => {
3402
2856
  envManager.switchToMainThread();
3403
2857
  const listRef = createMockElementTemplateHandle('typed-list', 145);
3404
2858
  const itemRef = createMockElementTemplateHandle('item', 146);
3405
2859
  elementTemplateRegistry.set(81, listRef);
3406
2860
  elementTemplateRegistry.set(82, itemRef);
3407
- registerElementTemplateListItem(82, itemRef, {
3408
- templateKey: '_et_item',
3409
- platformInfo: { 'item-key': 'a' },
3410
- });
3411
- const state = createElementTemplateListState([82]);
3412
- registerElementTemplateListState(81, state, false, listRef);
2861
+ const platformInfo = { 'item-key': 'a', 'reuse-identifier': 'next' };
3413
2862
 
3414
2863
  applyElementTemplateUpdateCommands([
3415
2864
  ElementTemplateUpdateOps.updateTypedListItem,
@@ -3417,140 +2866,30 @@ describe('ElementTemplate patch stream (apply)', () => {
3417
2866
  {
3418
2867
  __etHandleRef: 82,
3419
2868
  type: '_et_item',
3420
- platformInfo: { 'item-key': 'a', 'reuse-identifier': 'next' },
3421
- },
3422
- ]);
3423
-
3424
- expect(mockSetElementTemplateAttributeSlot.mock.calls[0]).toEqual([
3425
- listRef,
3426
- 0,
3427
- {
3428
- 'component-at-index': expect.any(Function),
3429
- 'component-at-indexes': expect.any(Function),
3430
- 'enqueue-component': expect.any(Function),
3431
- 'update-list-info': {
3432
- insertAction: [],
3433
- removeAction: [],
3434
- updateAction: [{
3435
- from: 0,
3436
- to: 0,
3437
- type: '_et_item',
3438
- flush: false,
3439
- 'item-key': 'a',
3440
- 'reuse-identifier': 'next',
3441
- }],
3442
- },
2869
+ platformInfo,
2870
+ subtreeHandleIds: null,
3443
2871
  },
3444
2872
  ]);
3445
- });
3446
2873
 
3447
- it('moves attached items without detached siblings', () => {
3448
- envManager.switchToMainThread();
3449
- const listRef = createMockElementTemplateHandle('typed-list', 135);
3450
- const materializedList = createMaterializedListForFrontendTest(135);
3451
- const firstRef = createMockElementTemplateHandle('first', 136);
3452
- const secondRef = createMockElementTemplateHandle('second', 137);
3453
- elementTemplateRegistry.set(71, listRef);
3454
- elementTemplateRegistry.set(72, firstRef);
3455
- elementTemplateRegistry.set(73, secondRef);
3456
- registerElementTemplateListItem(72, firstRef, {
3457
- templateKey: '_et_item_a',
3458
- platformInfo: { 'item-key': 'a' },
3459
- });
3460
- registerElementTemplateListItem(73, secondRef, {
3461
- templateKey: '_et_item_b',
3462
- platformInfo: { 'item-key': 'b' },
3463
- });
3464
- const state = createElementTemplateListState([72, 73]);
3465
- registerElementTemplateListState(71, state, false, listRef);
3466
- const attrs = composeElementTemplateListAttributes(null, state);
3467
- const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
3468
-
3469
- expect(componentAtIndex(materializedList, 7, 0, 91, false)).toBe(136);
3470
- mockInsertElementTemplateNodeIntoSlot.mockClear();
3471
- mockFlushElementTree.mockClear();
3472
-
3473
- applyElementTemplateUpdateCommands([
3474
- ElementTemplateUpdateOps.removeTypedListItem,
3475
- 71,
3476
- 72,
3477
- [],
3478
- ElementTemplateUpdateOps.insertTypedListItem,
3479
- 71,
3480
- {
3481
- __etHandleRef: 72,
3482
- type: '_et_item_a',
3483
- platformInfo: { 'item-key': 'a' },
3484
- },
3485
- 0,
3486
- ]);
3487
- mockInsertElementTemplateNodeIntoSlot.mockClear();
3488
-
3489
- expect(componentAtIndex(materializedList, 7, 1, 92, false)).toBe(136);
3490
- expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toEqual([[listRef, 0, firstRef, null]]);
3491
- });
3492
-
3493
- it('treats same-key list item replacement with a new ref as remove and insert', () => {
3494
- envManager.switchToMainThread();
3495
- const listRef = createMockElementTemplateHandle('typed-list', 125);
3496
- const oldRef = createMockElementTemplateHandle('old', 126);
3497
- const nextRef = createMockElementTemplateHandle('next', 127);
3498
- elementTemplateRegistry.set(61, listRef);
3499
- elementTemplateRegistry.set(62, oldRef);
3500
- elementTemplateRegistry.set(63, nextRef);
3501
- registerElementTemplateListItem(62, oldRef, {
3502
- templateKey: '_et_item',
3503
- platformInfo: { 'item-key': 'same' },
3504
- });
3505
- const state = createElementTemplateListState([62]);
3506
- registerElementTemplateListState(61, state, false, listRef);
3507
-
3508
- applyElementTemplateUpdateCommands([
3509
- ElementTemplateUpdateOps.removeTypedListItem,
3510
- 61,
3511
- 62,
3512
- [62],
3513
- ElementTemplateUpdateOps.insertTypedListItem,
3514
- 61,
3515
- {
3516
- __etHandleRef: 63,
3517
- type: '_et_item',
3518
- platformInfo: { 'item-key': 'same' },
3519
- },
3520
- 0,
3521
- ]);
3522
-
3523
- expect(mockSetElementTemplateAttributeSlot.mock.calls[0]![2]).toEqual(expect.objectContaining({
3524
- 'update-list-info': {
3525
- insertAction: [{ position: 0, type: '_et_item', 'item-key': 'same' }],
3526
- removeAction: [0],
3527
- updateAction: [],
3528
- },
3529
- }));
3530
- expect(elementTemplateRegistry.get(62)).toBeUndefined();
2874
+ expect(vi.mocked(__SetListItemInfoOfTemplate).mock.calls).toEqual([[itemRef, platformInfo]]);
2875
+ expect(mockSetElementTemplateAttributeSlot.mock.calls).toHaveLength(0);
3531
2876
  });
3532
2877
 
3533
2878
  it('keeps destroyed typed list callbacks Snapshot-safe', () => {
3534
2879
  envManager.switchToMainThread();
3535
2880
  const listRef = 120 as unknown as ElementTemplateHandle;
3536
- const itemRef = 121 as unknown as ElementTemplateHandle;
3537
- registerElementTemplateListItem(121, itemRef, {
3538
- templateKey: '_et_item',
3539
- platformInfo: { 'item-key': 'a' },
3540
- });
3541
- const state = createElementTemplateListState([121]);
3542
- registerElementTemplateListState(120, state, false, listRef);
2881
+ const state = createElementTemplateListState();
2882
+ registerElementTemplateListState(120, state, listRef);
3543
2883
  const attrs = composeElementTemplateListAttributes(null, state);
3544
- const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
3545
- const componentAtIndexes = attrs['component-at-indexes'] as ComponentAtIndexesCallback;
3546
- const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
3547
- const materializedList = { id: 'materialized-list' } as unknown as FiberElement;
2884
+ const componentAtIndex = attrs['component-at-index'] as (listUid: number, itemUid: number) => void;
2885
+ const enqueueComponent = attrs['enqueue-component'] as (listUid: number, itemUid: number) => void;
3548
2886
 
3549
2887
  markElementTemplateListDestroyed(120);
3550
2888
 
3551
- expect(componentAtIndex(materializedList, 7, 0, 99, false)).toBe(-1);
3552
- componentAtIndexes(materializedList, 7, [0], [99], false, true);
3553
- enqueueComponent(materializedList, 7, 121);
2889
+ expect(state.destroyed).toBe(true);
2890
+ expect(state.holderRef).toBeNull();
2891
+ expect(componentAtIndex(120, 121)).toBeUndefined();
2892
+ enqueueComponent(120, 121);
3554
2893
 
3555
2894
  expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
3556
2895
  expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
@@ -3710,6 +3049,55 @@ describe('ElementTemplate patch stream (apply)', () => {
3710
3049
  expect(elementTemplateRegistry.has(12)).toBe(false);
3711
3050
  });
3712
3051
 
3052
+ it('cleans all mounted list-item refs and releases the subtree when a callback cleanup throws', () => {
3053
+ envManager.switchToMainThread();
3054
+ const listRef = createMockElementTemplateHandle('list');
3055
+ const subtree = [72, 73, 74];
3056
+ elementTemplateRegistry.set(70, createMockElementTemplateHandle('parent'));
3057
+ elementTemplateRegistry.set(71, listRef);
3058
+ const state = createElementTemplateListState(new Map([[72, subtree]]));
3059
+ registerElementTemplateListState(71, state, listRef);
3060
+ const cleanupError = new Error('item cleanup failed');
3061
+ const descendantCleanup = vi.fn();
3062
+ const previousRunWorklet = globalThis.runWorklet;
3063
+ globalThis.runWorklet = vi.fn()
3064
+ .mockReturnValueOnce(() => {
3065
+ throw cleanupError;
3066
+ })
3067
+ .mockReturnValueOnce(() => {
3068
+ throw new Error('another cleanup failed');
3069
+ })
3070
+ .mockReturnValueOnce(descendantCleanup);
3071
+
3072
+ try {
3073
+ registerMTRefSlots(0);
3074
+ for (const uid of subtree) {
3075
+ elementTemplateRegistry.set(uid, createMockElementTemplateHandle(`item-${uid}`));
3076
+ initializeMainThreadDynamicAttrSlots(uid, MT_REF_TEMPLATE, [
3077
+ { type: 'main-thread-ref', value: { _wkltId: `ref-${uid}` } },
3078
+ ]);
3079
+ }
3080
+ vi.mocked(__GetElementByAttrSlot).mockReturnValue(REF_TARGET);
3081
+ state.callbacks.componentAtIndex(71, 72);
3082
+
3083
+ expect(() =>
3084
+ applyElementTemplateUpdateCommands([
3085
+ ElementTemplateUpdateOps.removeNode,
3086
+ 70,
3087
+ 0,
3088
+ 71,
3089
+ [71, ...subtree],
3090
+ ])
3091
+ ).toThrow(cleanupError);
3092
+
3093
+ expect(descendantCleanup).toHaveBeenCalledOnce();
3094
+ expect(elementTemplateRegistry.has(74)).toBe(false);
3095
+ expect(getMainThreadDynamicAttrState(74, 0)).toBeUndefined();
3096
+ } finally {
3097
+ globalThis.runWorklet = previousRunWorklet;
3098
+ }
3099
+ });
3100
+
3713
3101
  it('marks nested typed list state destroyed when removing a holder subtree', () => {
3714
3102
  envManager.switchToMainThread();
3715
3103
  elementTemplateRegistry.clear();
@@ -3722,37 +3110,30 @@ describe('ElementTemplate patch stream (apply)', () => {
3722
3110
  elementTemplateRegistry.set(71, childRef);
3723
3111
  elementTemplateRegistry.set(72, listRef);
3724
3112
  elementTemplateRegistry.set(73, itemRef);
3725
- registerElementTemplateListItem(73, itemRef, {
3726
- templateKey: '_et_item',
3727
- platformInfo: { 'item-key': 'a' },
3728
- });
3729
- const state = createElementTemplateListState([73]);
3730
- registerElementTemplateListState(72, state, false, listRef);
3113
+ const state = createElementTemplateListState();
3114
+ registerElementTemplateListState(72, state, listRef);
3731
3115
  const attrs = composeElementTemplateListAttributes(null, state);
3732
- const componentAtIndex = attrs['component-at-index'] as ComponentAtIndexCallback;
3733
- const componentAtIndexes = attrs['component-at-indexes'] as ComponentAtIndexesCallback;
3734
- const enqueueComponent = attrs['enqueue-component'] as EnqueueComponentCallback;
3735
- const materializedList = { id: 'materialized-list' } as unknown as FiberElement;
3736
-
3737
- removeElementTemplateListItem(72, 73, [73]);
3116
+ const componentAtIndex = attrs['component-at-index'] as (listUid: number, itemUid: number) => void;
3117
+ const enqueueComponent = attrs['enqueue-component'] as (listUid: number, itemUid: number) => void;
3738
3118
 
3739
3119
  applyElementTemplateUpdateCommands([
3740
3120
  ElementTemplateUpdateOps.removeNode,
3741
3121
  70,
3742
3122
  0,
3743
3123
  71,
3744
- [71, 72],
3124
+ [71, 72, 73],
3745
3125
  ]);
3746
3126
 
3747
3127
  expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toEqual([[targetRef, 0, childRef]]);
3748
3128
  expect(elementTemplateRegistry.has(71)).toBe(false);
3749
3129
  expect(elementTemplateRegistry.has(72)).toBe(false);
3750
3130
  expect(elementTemplateRegistry.has(73)).toBe(false);
3131
+ expect(state.destroyed).toBe(true);
3132
+ expect(state.holderRef).toBeNull();
3751
3133
  mockRemoveElementTemplateNodeFromSlot.mockClear();
3752
3134
 
3753
- expect(componentAtIndex(materializedList, 7, 0, 99, false)).toBe(-1);
3754
- componentAtIndexes(materializedList, 7, [0], [99], false, true);
3755
- enqueueComponent(materializedList, 7, 131);
3135
+ expect(componentAtIndex(72, 73)).toBeUndefined();
3136
+ enqueueComponent(72, 73);
3756
3137
 
3757
3138
  expect(mockInsertElementTemplateNodeIntoSlot.mock.calls).toHaveLength(0);
3758
3139
  expect(mockRemoveElementTemplateNodeFromSlot.mock.calls).toHaveLength(0);
@@ -3793,6 +3174,7 @@ describe('ElementTemplate patch stream (apply)', () => {
3793
3174
  null,
3794
3175
  null,
3795
3176
  null,
3177
+ null,
3796
3178
  ]);
3797
3179
 
3798
3180
  expect(serializeToJSX(__page)).toMatchInlineSnapshot(`
@@ -3820,6 +3202,7 @@ describe('ElementTemplate patch stream (apply)', () => {
3820
3202
  null,
3821
3203
  rawSlots as unknown as ElementTemplateUpdateCommandStream[number],
3822
3204
  [],
3205
+ null,
3823
3206
  ],
3824
3207
  flushOptions: {},
3825
3208
  });
@@ -3832,13 +3215,14 @@ describe('ElementTemplate patch stream (apply)', () => {
3832
3215
  expect(createTemplateMock.mock.calls[0]?.[2]).toBe(attributeSlots);
3833
3216
  });
3834
3217
 
3835
- it('passes bundleUrl from createTemplate patch to native create', () => {
3218
+ it('passes bundleUrl and List item platform info from createTemplate to native create', () => {
3836
3219
  envManager.switchToMainThread();
3837
3220
  const createTemplateMock = globalThis.__CreateElementTemplate as unknown as {
3838
3221
  mockClear: () => void;
3839
3222
  mock: { calls: unknown[][] };
3840
3223
  };
3841
3224
  createTemplateMock.mockClear();
3225
+ const options = { __listItemPlatformInfo: { 'item-key': 'a', 'reuse-identifier': 'item' } };
3842
3226
 
3843
3227
  applyElementTemplateUpdateCommands([
3844
3228
  ElementTemplateUpdateOps.createTemplate,
@@ -3847,9 +3231,17 @@ describe('ElementTemplate patch stream (apply)', () => {
3847
3231
  'dynamic-entry',
3848
3232
  ['x'],
3849
3233
  [],
3234
+ options,
3850
3235
  ]);
3851
3236
 
3852
- expect(createTemplateMock.mock.calls[0]?.[1]).toBe('dynamic-entry');
3237
+ expect(createTemplateMock.mock.calls).toEqual([[
3238
+ '_et_builtin_raw_text',
3239
+ 'dynamic-entry',
3240
+ ['x'],
3241
+ [],
3242
+ 9,
3243
+ options,
3244
+ ]]);
3853
3245
  });
3854
3246
 
3855
3247
  it('reports unsupported opcodes', () => {
@@ -3889,6 +3281,7 @@ describe('ElementTemplate patch stream (apply)', () => {
3889
3281
  null,
3890
3282
  [],
3891
3283
  [[11, 404], 'bad-slot' as unknown as number[]],
3284
+ null,
3892
3285
  ]);
3893
3286
 
3894
3287
  const reportError = (globalThis.lynx as unknown as LynxWithReportErrorMock).reportError;