@lynx-js/react 0.129.3 → 0.129.5

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 (494) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +10 -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/lynx/env.test.ts +146 -0
  13. package/runtime/__test__/core/ref.test.ts +218 -1
  14. package/runtime/__test__/core/sync-effect-flush.test.ts +58 -0
  15. package/runtime/__test__/element-template/debug/alog.test.ts +20 -12
  16. package/runtime/__test__/element-template/fixtures/background/hydrate/_shared.tsx +15 -34
  17. package/runtime/__test__/element-template/fixtures/background/hydrate/children.creates-missing-nodes-recursively/output.txt +2 -0
  18. package/runtime/__test__/element-template/fixtures/background/hydrate/children.iterates-existing-slots/output.txt +1 -0
  19. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-attrs-element/output.txt +6 -1
  20. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-main/output.txt +1 -0
  21. package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.move-before-child → children.reconciles-raw-text-slots}/case.tsx +1 -1
  22. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text/output.txt +1 -0
  23. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text-non-text/output.txt +1 -0
  24. package/runtime/__test__/element-template/fixtures/background/hydrate/root-key-mismatch-reconciles/output.txt +1 -0
  25. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.creates-and-inserts-new/output.txt +1 -0
  26. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.inserts-before-existing-sibling/output.txt +1 -0
  27. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.mixed-operations/output.txt +1 -0
  28. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -0
  29. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/complex-trees.deeply-nested-dynamic-content/output.txt +1 -0
  30. package/runtime/__test__/element-template/fixtures/background/instance/ops/emits-bundle-url-in-create-template/output.txt +1 -0
  31. package/runtime/__test__/element-template/fixtures/list/mts/index.tsx +185 -0
  32. package/runtime/__test__/element-template/fixtures/page/render-page/native-log.txt +1 -0
  33. package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/case.tsx +2 -0
  34. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/ops.txt +1 -0
  35. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/ops.txt +1 -0
  36. package/runtime/__test__/element-template/fixtures/render/child-siblings/papi.txt +10 -5
  37. package/runtime/__test__/element-template/fixtures/render/component/papi.txt +6 -3
  38. package/runtime/__test__/element-template/fixtures/render/component-slot-content/papi.txt +6 -3
  39. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/papi.txt +2 -1
  40. package/runtime/__test__/element-template/fixtures/render/direct-native/appends-root-text-via-append-element/native-log.txt +1 -0
  41. package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/native-log.txt +2 -0
  42. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-template-children-in-the-same-slot/native-log.txt +3 -0
  43. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +3 -0
  44. package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/native-log.txt +3 -0
  45. package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/native-log.txt +3 -0
  46. package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/native-log.txt +1 -0
  47. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/papi.txt +14 -7
  48. package/runtime/__test__/element-template/fixtures/render/mixed-children/papi.txt +8 -4
  49. package/runtime/__test__/element-template/fixtures/render/multiple-text/papi.txt +38 -19
  50. package/runtime/__test__/element-template/fixtures/render/nested-templates/papi.txt +6 -3
  51. package/runtime/__test__/element-template/fixtures/render/react-example/papi.txt +6 -3
  52. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/papi.txt +6 -3
  53. package/runtime/__test__/element-template/fixtures/render/template-dedupe/papi.txt +10 -5
  54. package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +47 -4
  55. package/runtime/__test__/element-template/lynx/performance.test.ts +1 -0
  56. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +1 -0
  57. package/runtime/__test__/element-template/native/index.test.ts +9 -9
  58. package/runtime/__test__/element-template/native/mts-destroy.test.ts +65 -17
  59. package/runtime/__test__/element-template/native/reload.test.ts +19 -12
  60. package/runtime/__test__/element-template/runtime/background/adapter/background-adapter.et.test.tsx +0 -32
  61. package/runtime/__test__/element-template/runtime/background/commit-context.test.ts +0 -14
  62. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +10 -0
  63. package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +22 -0
  64. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +197 -252
  65. package/runtime/__test__/element-template/runtime/background/instance.test.ts +277 -126
  66. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +1 -1
  67. package/runtime/__test__/element-template/runtime/background/passive-update-depth.test.tsx +496 -0
  68. package/runtime/__test__/element-template/runtime/background/render/preact.test.tsx +16 -22
  69. package/runtime/__test__/element-template/runtime/background/root-render.test.tsx +5 -3
  70. package/runtime/__test__/element-template/runtime/background/suspense.test.tsx +2 -0
  71. package/runtime/__test__/element-template/runtime/background/update/compiled-fixtures.test.tsx +1 -0
  72. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +1 -0
  73. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +4 -5
  74. package/runtime/__test__/element-template/runtime/list/list-mts-compiled.test.ts +525 -0
  75. package/runtime/__test__/element-template/runtime/page/compiled-fixtures.test.tsx +2 -0
  76. package/runtime/__test__/element-template/runtime/page/root-instance.test.ts +2 -14
  77. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +425 -1032
  78. package/runtime/__test__/element-template/runtime/patch/patch-listener-alog.test.ts +1 -0
  79. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +1 -0
  80. package/runtime/__test__/element-template/runtime/prop-adapters/event.test.ts +0 -20
  81. package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +2 -1
  82. package/runtime/__test__/element-template/runtime/prop-adapters/hydrate.test.ts +1 -0
  83. package/runtime/__test__/element-template/runtime/prop-adapters/ref.test.ts +65 -0
  84. package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +12 -4
  85. package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +2 -5
  86. package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +56 -121
  87. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +18 -17
  88. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +5 -4
  89. package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -0
  90. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +1 -60
  91. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +65 -89
  92. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +8 -6
  93. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +34 -6
  94. package/runtime/__test__/element-template/test-utils/debug/updateRunner.test.tsx +20 -12
  95. package/runtime/__test__/element-template/test-utils/debug/updateRunner.ts +2 -28
  96. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.test.ts +14 -5
  97. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.ts +1 -57
  98. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +29 -13
  99. package/runtime/__test__/element-template/vitest.config.ts +2 -1
  100. package/runtime/__test__/guardrails/snapshot-containment.test.ts +98 -77
  101. package/runtime/__test__/snapshot/debug/passive-update-depth.test.jsx +549 -0
  102. package/runtime/__test__/snapshot/debug/profile.test.jsx +147 -26
  103. package/runtime/__test__/snapshot/debug/react-hooks-profile.test.jsx +3 -3
  104. package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +138 -1
  105. package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +55 -1
  106. package/runtime/__test__/snapshot/lifecycle/transfer.mts.test.jsx +286 -0
  107. package/runtime/__test__/snapshot/lifecycle/transfer.test.jsx +415 -0
  108. package/runtime/__test__/snapshot/list.test.jsx +109 -0
  109. package/runtime/__test__/snapshot/lynx/suspense.test.jsx +48 -0
  110. package/runtime/__test__/snapshot/lynxQueueMicrotask.test.jsx +2 -2
  111. package/runtime/__test__/snapshot/ref.test.jsx +124 -1
  112. package/runtime/__test__/snapshot/utils/envManager.ts +7 -0
  113. package/runtime/__test__/snapshot/utils/globals.js +1 -0
  114. package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +43 -11
  115. package/runtime/__test__/worklet-runtime/hydrate.test.js +1 -0
  116. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +24 -16
  117. package/runtime/__test__/worklet-runtime/lifecycle.test.js +297 -0
  118. package/runtime/__test__/worklet-runtime/profile.test.js +12 -6
  119. package/runtime/__test__/worklet-runtime/runOnBackground.test.js +188 -0
  120. package/runtime/__test__/worklet-runtime/workletRef.test.js +16 -0
  121. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +53 -1
  122. package/runtime/lazy/element-template-internal.js +1 -0
  123. package/runtime/lazy/internal.js +1 -0
  124. package/runtime/lib/core/attribute-name.js.map +1 -0
  125. package/runtime/lib/core/background-function/run-on-background.js +7 -7
  126. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  127. package/runtime/lib/core/compat/componentIs.d.ts +1 -0
  128. package/runtime/lib/core/compat/componentIs.js +20 -0
  129. package/runtime/lib/core/compat/componentIs.js.map +1 -0
  130. package/runtime/lib/{shared → core}/component-stack.js +1 -1
  131. package/runtime/lib/core/component-stack.js.map +1 -0
  132. package/runtime/lib/core/deep-equal.d.ts +1 -0
  133. package/runtime/lib/core/deep-equal.js +31 -0
  134. package/runtime/lib/core/deep-equal.js.map +1 -0
  135. package/runtime/lib/core/hooks/mainThreadImpl.js +1 -1
  136. package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
  137. package/runtime/lib/core/lynx/env.d.ts +1 -0
  138. package/runtime/lib/{element-template → core}/lynx/env.js +3 -2
  139. package/runtime/lib/core/lynx/env.js.map +1 -0
  140. package/runtime/lib/core/lynx-page-data.js +1 -1
  141. package/runtime/lib/core/lynx-page-data.js.map +1 -1
  142. package/runtime/lib/core/mts-capability.js +1 -1
  143. package/runtime/lib/core/mts-capability.js.map +1 -1
  144. package/runtime/lib/core/performance.js +2 -1
  145. package/runtime/lib/core/performance.js.map +1 -1
  146. package/runtime/lib/core/ref.d.ts +1 -2
  147. package/runtime/lib/core/ref.js +60 -9
  148. package/runtime/lib/core/ref.js.map +1 -1
  149. package/runtime/lib/core/sync-effect-flush.d.ts +9 -0
  150. package/runtime/lib/core/sync-effect-flush.js +31 -0
  151. package/runtime/lib/core/sync-effect-flush.js.map +1 -0
  152. package/runtime/lib/core/thread-function-call/main-thread.d.ts +1 -0
  153. package/runtime/lib/core/thread-function-call/main-thread.js +5 -2
  154. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  155. package/runtime/lib/element-template/background/attr-slots.d.ts +1 -0
  156. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  157. package/runtime/lib/element-template/background/commit-event.d.ts +6 -0
  158. package/runtime/lib/element-template/background/commit-event.js +36 -0
  159. package/runtime/lib/element-template/background/commit-event.js.map +1 -0
  160. package/runtime/lib/element-template/background/commit-hook.js +4 -24
  161. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  162. package/runtime/lib/element-template/background/destroy.js +2 -2
  163. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  164. package/runtime/lib/element-template/background/hydrate.js +174 -87
  165. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  166. package/runtime/lib/element-template/background/hydration-listener.js +5 -25
  167. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  168. package/runtime/lib/element-template/background/instance.d.ts +7 -10
  169. package/runtime/lib/element-template/background/instance.js +65 -58
  170. package/runtime/lib/element-template/background/instance.js.map +1 -1
  171. package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.js +4 -4
  172. package/runtime/lib/element-template/background/main-thread-function.js.map +1 -0
  173. package/runtime/lib/element-template/background/render-scope.js +2 -1
  174. package/runtime/lib/element-template/background/render-scope.js.map +1 -1
  175. package/runtime/lib/element-template/debug/alog.d.ts +1 -10
  176. package/runtime/lib/element-template/debug/alog.js +1 -16
  177. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  178. package/runtime/lib/element-template/debug/profile.js +1 -1
  179. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  180. package/runtime/lib/element-template/index.d.ts +1 -1
  181. package/runtime/lib/element-template/index.js +1 -1
  182. package/runtime/lib/element-template/index.js.map +1 -1
  183. package/runtime/lib/element-template/internal.js +3 -0
  184. package/runtime/lib/element-template/internal.js.map +1 -1
  185. package/runtime/lib/element-template/native/index.js +4 -4
  186. package/runtime/lib/element-template/native/index.js.map +1 -1
  187. package/runtime/lib/element-template/native/mts-destroy.d.ts +2 -1
  188. package/runtime/lib/element-template/native/mts-destroy.js +15 -4
  189. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  190. package/runtime/lib/element-template/native/patch-listener.js +4 -8
  191. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  192. package/runtime/lib/element-template/native/reload-main-thread.js +2 -6
  193. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  194. package/runtime/lib/element-template/prop-adapters/ref.d.ts +2 -1
  195. package/runtime/lib/element-template/prop-adapters/ref.js +4 -4
  196. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
  197. package/runtime/lib/element-template/prop-adapters/spread.js +1 -1
  198. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  199. package/runtime/lib/element-template/protocol/opcodes.d.ts +0 -2
  200. package/runtime/lib/element-template/protocol/opcodes.js +0 -2
  201. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  202. package/runtime/lib/element-template/protocol/types.d.ts +8 -30
  203. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  204. package/runtime/lib/element-template/runtime/list/list.d.ts +14 -54
  205. package/runtime/lib/element-template/runtime/list/list.js +82 -546
  206. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  207. package/runtime/lib/element-template/runtime/list/platform-info.d.ts +2 -0
  208. package/runtime/lib/element-template/runtime/list/platform-info.js +26 -0
  209. package/runtime/lib/element-template/runtime/list/platform-info.js.map +1 -0
  210. package/runtime/lib/element-template/runtime/patch.js +44 -128
  211. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  212. package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +1 -1
  213. package/runtime/lib/element-template/runtime/render/create-rendered-host.js +24 -21
  214. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
  215. package/runtime/lib/element-template/runtime/render/render-components.d.ts +1 -1
  216. package/runtime/lib/element-template/runtime/render/render-components.js +3 -6
  217. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  218. package/runtime/lib/element-template/runtime/render/render-direct.js +21 -20
  219. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
  220. package/runtime/lib/element-template/runtime/render/render-main-thread.js +0 -13
  221. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  222. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +8 -0
  223. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  224. package/runtime/lib/element-template/runtime/template/handle.d.ts +3 -3
  225. package/runtime/lib/element-template/runtime/template/handle.js +3 -3
  226. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  227. package/runtime/lib/element-template/runtime/template/main-thread-background-function.d.ts +1 -0
  228. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -8
  229. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  230. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +2 -1
  231. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +44 -28
  232. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  233. package/runtime/lib/element-template/runtime/template/typed-attributes.d.ts +2 -0
  234. package/runtime/lib/element-template/runtime/template/typed-attributes.js +8 -1
  235. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  236. package/runtime/lib/internal.d.ts +1 -0
  237. package/runtime/lib/internal.js +5 -10
  238. package/runtime/lib/internal.js.map +1 -1
  239. package/runtime/lib/lynx-api.js +6 -1
  240. package/runtime/lib/lynx-api.js.map +1 -1
  241. package/runtime/lib/lynx.js +4 -4
  242. package/runtime/lib/lynx.js.map +1 -1
  243. package/runtime/lib/root.d.ts +5 -1
  244. package/runtime/lib/root.js +12 -1
  245. package/runtime/lib/root.js.map +1 -1
  246. package/runtime/lib/shared/microtask.d.ts +1 -0
  247. package/runtime/lib/shared/microtask.js +28 -0
  248. package/runtime/lib/shared/microtask.js.map +1 -0
  249. package/runtime/lib/shared/utils.d.ts +8 -0
  250. package/runtime/lib/shared/utils.js +27 -0
  251. package/runtime/lib/shared/utils.js.map +1 -0
  252. package/runtime/lib/{worklet-runtime/utils → shared}/version.d.ts +1 -0
  253. package/runtime/lib/{worklet-runtime/utils → shared}/version.js +4 -2
  254. package/runtime/lib/shared/version.js.map +1 -0
  255. package/runtime/lib/snapshot/alog/render.js +1 -1
  256. package/runtime/lib/snapshot/alog/render.js.map +1 -1
  257. package/runtime/lib/snapshot/debug/profileHooks.js +28 -63
  258. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  259. package/runtime/lib/snapshot/lifecycle/destroy.js +2 -2
  260. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  261. package/runtime/lib/snapshot/lifecycle/isRendering.js +2 -1
  262. package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
  263. package/runtime/lib/snapshot/lifecycle/patch/commit.d.ts +7 -2
  264. package/runtime/lib/snapshot/lifecycle/patch/commit.js +11 -6
  265. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  266. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.d.ts +5 -0
  267. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +1 -1
  268. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  269. package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +1 -1
  270. package/runtime/lib/snapshot/lifecycle/ref/delay.js +2 -2
  271. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  272. package/runtime/lib/snapshot/lifecycle/reload.js +3 -3
  273. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  274. package/runtime/lib/snapshot/list/list.js +12 -3
  275. package/runtime/lib/snapshot/list/list.js.map +1 -1
  276. package/runtime/lib/snapshot/lynx/env.js +2 -32
  277. package/runtime/lib/snapshot/lynx/env.js.map +1 -1
  278. package/runtime/lib/snapshot/lynx/tt.d.ts +3 -1
  279. package/runtime/lib/snapshot/lynx/tt.js +7 -3
  280. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  281. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +1 -1
  282. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  283. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  284. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  285. package/runtime/lib/snapshot/snapshot/platformInfo.js +1 -1
  286. package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
  287. package/runtime/lib/snapshot/snapshot/ref.d.ts +1 -0
  288. package/runtime/lib/snapshot/snapshot/ref.js +2 -2
  289. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  290. package/runtime/lib/snapshot/snapshot/snapshot.js +1 -1
  291. package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
  292. package/runtime/lib/snapshot/snapshot/spread.js +3 -2
  293. package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
  294. package/runtime/lib/snapshot/transfer.d.ts +21 -0
  295. package/runtime/lib/snapshot/transfer.js +486 -0
  296. package/runtime/lib/snapshot/transfer.js.map +1 -0
  297. package/runtime/lib/snapshot/worklet/functionality.js +1 -1
  298. package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
  299. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  300. package/runtime/lib/worklet-runtime/api/element.js +1 -1
  301. package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
  302. package/runtime/lib/worklet-runtime/api/lynxApi.js +1 -1
  303. package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
  304. package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -2
  305. package/runtime/lib/worklet-runtime/bindings/bindings.js +11 -1
  306. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  307. package/runtime/lib/worklet-runtime/bindings/lifecycle.d.ts +19 -0
  308. package/runtime/lib/worklet-runtime/bindings/lifecycle.js +49 -0
  309. package/runtime/lib/worklet-runtime/bindings/lifecycle.js.map +1 -0
  310. package/runtime/lib/worklet-runtime/bindings/observers.js +9 -1
  311. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  312. package/runtime/lib/worklet-runtime/bindings/types.d.ts +1 -0
  313. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
  314. package/runtime/lib/worklet-runtime/delayWorkletEvent.d.ts +3 -5
  315. package/runtime/lib/worklet-runtime/delayWorkletEvent.js +49 -43
  316. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
  317. package/runtime/lib/worklet-runtime/global.d.ts +1 -2
  318. package/runtime/lib/worklet-runtime/global.js.map +1 -1
  319. package/runtime/lib/worklet-runtime/hydrate.js +2 -32
  320. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  321. package/runtime/lib/worklet-runtime/run-on-background/index.d.ts +28 -0
  322. package/runtime/lib/worklet-runtime/run-on-background/index.js +103 -0
  323. package/runtime/lib/worklet-runtime/run-on-background/index.js.map +1 -0
  324. package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.d.ts → run-on-background/lifecycle.d.ts} +2 -2
  325. package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.js → run-on-background/lifecycle.js} +12 -9
  326. package/runtime/lib/worklet-runtime/run-on-background/lifecycle.js.map +1 -0
  327. package/runtime/lib/worklet-runtime/utils/profile.js +1 -3
  328. package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
  329. package/runtime/lib/worklet-runtime/workletRef.js +51 -54
  330. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
  331. package/runtime/lib/worklet-runtime/workletRuntime.js +5 -6
  332. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  333. package/runtime/src/core/background-function/run-on-background.ts +7 -7
  334. package/runtime/src/core/compat/componentIs.ts +32 -0
  335. package/runtime/src/{shared → core}/component-stack.ts +1 -1
  336. package/runtime/src/core/deep-equal.ts +33 -0
  337. package/runtime/src/core/hooks/mainThreadImpl.ts +1 -1
  338. package/runtime/src/{element-template → core}/lynx/env.ts +6 -4
  339. package/runtime/src/core/lynx-page-data.ts +1 -1
  340. package/runtime/src/core/mts-capability.ts +1 -1
  341. package/runtime/src/core/performance.ts +2 -1
  342. package/runtime/src/core/ref.ts +92 -15
  343. package/runtime/src/core/sync-effect-flush.ts +30 -0
  344. package/runtime/src/core/thread-function-call/main-thread.ts +6 -2
  345. package/runtime/src/element-template/background/attr-slots.ts +2 -2
  346. package/runtime/src/element-template/background/commit-event.ts +52 -0
  347. package/runtime/src/element-template/background/commit-hook.ts +5 -32
  348. package/runtime/src/element-template/background/destroy.ts +2 -2
  349. package/runtime/src/element-template/background/hydrate.ts +234 -122
  350. package/runtime/src/element-template/background/hydration-listener.ts +7 -32
  351. package/runtime/src/element-template/background/instance.ts +82 -82
  352. package/runtime/src/element-template/{runtime/template → background}/main-thread-function.ts +4 -7
  353. package/runtime/src/element-template/background/render-scope.ts +2 -1
  354. package/runtime/src/element-template/debug/alog.ts +2 -30
  355. package/runtime/src/element-template/debug/profile.ts +1 -1
  356. package/runtime/src/element-template/index.ts +1 -1
  357. package/runtime/src/element-template/internal.ts +4 -0
  358. package/runtime/src/element-template/native/index.ts +4 -4
  359. package/runtime/src/element-template/native/mts-destroy.ts +21 -4
  360. package/runtime/src/element-template/native/patch-listener.ts +6 -7
  361. package/runtime/src/element-template/native/reload-main-thread.ts +2 -6
  362. package/runtime/src/element-template/prop-adapters/ref.ts +12 -5
  363. package/runtime/src/element-template/prop-adapters/spread.ts +1 -1
  364. package/runtime/src/element-template/protocol/opcodes.ts +0 -2
  365. package/runtime/src/element-template/protocol/types.ts +10 -38
  366. package/runtime/src/element-template/runtime/list/list.ts +115 -744
  367. package/runtime/src/element-template/runtime/list/platform-info.ts +31 -0
  368. package/runtime/src/element-template/runtime/patch.ts +78 -197
  369. package/runtime/src/element-template/runtime/render/create-rendered-host.ts +27 -31
  370. package/runtime/src/element-template/runtime/render/render-components.ts +2 -5
  371. package/runtime/src/element-template/runtime/render/render-direct.ts +19 -18
  372. package/runtime/src/element-template/runtime/render/render-main-thread.ts +0 -14
  373. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +9 -0
  374. package/runtime/src/element-template/runtime/template/handle.ts +5 -2
  375. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +9 -8
  376. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +44 -30
  377. package/runtime/src/element-template/runtime/template/typed-attributes.ts +17 -1
  378. package/runtime/src/element-template/types.d.ts +6 -22
  379. package/runtime/src/internal.ts +6 -13
  380. package/runtime/src/lynx-api.ts +6 -1
  381. package/runtime/src/lynx.ts +4 -4
  382. package/runtime/src/root.ts +17 -1
  383. package/runtime/src/shared/microtask.ts +26 -0
  384. package/runtime/src/shared/utils.ts +37 -0
  385. package/runtime/src/{worklet-runtime/utils → shared}/version.ts +6 -4
  386. package/runtime/src/snapshot/alog/render.ts +1 -1
  387. package/runtime/src/snapshot/debug/profileHooks.ts +31 -92
  388. package/runtime/src/snapshot/lifecycle/destroy.ts +2 -2
  389. package/runtime/src/snapshot/lifecycle/isRendering.ts +2 -1
  390. package/runtime/src/snapshot/lifecycle/patch/commit.ts +28 -7
  391. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +1 -1
  392. package/runtime/src/snapshot/lifecycle/ref/delay.ts +5 -2
  393. package/runtime/src/snapshot/lifecycle/reload.ts +3 -4
  394. package/runtime/src/snapshot/list/list.ts +12 -3
  395. package/runtime/src/snapshot/lynx/env.ts +3 -43
  396. package/runtime/src/snapshot/lynx/tt.ts +8 -3
  397. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +1 -1
  398. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
  399. package/runtime/src/snapshot/snapshot/platformInfo.ts +1 -1
  400. package/runtime/src/snapshot/snapshot/ref.ts +7 -4
  401. package/runtime/src/snapshot/snapshot/snapshot.ts +1 -1
  402. package/runtime/src/snapshot/snapshot/spread.ts +3 -2
  403. package/runtime/src/snapshot/transfer.ts +535 -0
  404. package/runtime/src/snapshot/worklet/functionality.ts +1 -1
  405. package/runtime/src/worklet-runtime/api/element.ts +1 -1
  406. package/runtime/src/worklet-runtime/api/lynxApi.ts +1 -1
  407. package/runtime/src/worklet-runtime/bindings/bindings.ts +12 -0
  408. package/runtime/src/worklet-runtime/bindings/lifecycle.ts +51 -0
  409. package/runtime/src/worklet-runtime/bindings/observers.ts +9 -1
  410. package/runtime/src/worklet-runtime/bindings/types.ts +1 -0
  411. package/runtime/src/worklet-runtime/delayWorkletEvent.ts +57 -54
  412. package/runtime/src/worklet-runtime/global.ts +1 -2
  413. package/runtime/src/worklet-runtime/hydrate.ts +2 -35
  414. package/runtime/src/worklet-runtime/run-on-background/index.ts +145 -0
  415. package/runtime/src/worklet-runtime/{jsFunctionLifecycle.ts → run-on-background/lifecycle.ts} +11 -9
  416. package/runtime/src/worklet-runtime/utils/profile.ts +1 -3
  417. package/runtime/src/worklet-runtime/workletRef.ts +63 -62
  418. package/runtime/src/worklet-runtime/workletRuntime.ts +10 -10
  419. package/runtime/types/internal-preact.d.ts +2 -0
  420. package/runtime/vitest.config.ts +0 -1
  421. package/testing-library/.turbo/turbo-build.log +11 -11
  422. package/testing-library/dist/pure.js +7 -4
  423. package/testing-library/dist/setupFiles/common/runtime-setup.js +3 -1
  424. package/testing-library/dist/setupFiles/inner/rstest.js +1 -1
  425. package/testing-library/dist/setupFiles/inner/vitest.js +1 -1
  426. package/testing-library/src/__tests__/events.test.jsx +1 -1
  427. package/testing-library/src/__tests__/list.test.jsx +52 -0
  428. package/testing-library/src/__tests__/worklet.test.jsx +81 -0
  429. package/testing-library/src/fire-event.ts +1 -1
  430. package/testing-library/src/pure.jsx +5 -2
  431. package/testing-library/src/setupFiles/common/runtime-setup.js +2 -0
  432. package/transform/.turbo/turbo-build$colon$wasm.log +45 -44
  433. package/transform/__test__/fixture.spec.js +1 -1
  434. package/transform/cjs/browser.cjs +11 -0
  435. package/transform/crates/swc_plugin_compat/lib.rs +20 -2
  436. package/transform/crates/swc_plugin_compat/napi.rs +7 -0
  437. package/transform/crates/swc_plugin_dynamic_import/lib.rs +15 -4
  438. package/transform/crates/swc_plugin_element_template/attr_name.rs +0 -3
  439. package/transform/crates/swc_plugin_element_template/extractor.rs +0 -8
  440. package/transform/crates/swc_plugin_element_template/lib.rs +12 -1
  441. package/transform/crates/swc_plugin_element_template/tests/element_template.rs +19 -45
  442. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +35 -19
  443. package/transform/crates/swc_plugin_worklet/lib.rs +11 -7
  444. package/transform/dist/wasm.cjs +1 -1
  445. package/transform/rspack-napi/lib/index.js +1 -4
  446. package/transform/rspack-napi/lib/index.js.map +1 -1
  447. package/transform/rspack-napi/src/index.ts +1 -4
  448. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
  449. package/transform/src/lib.rs +394 -27
  450. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +415 -107
  451. package/transform/swc-plugin-reactlynx/src/lib.rs +99 -22
  452. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  453. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +29 -339
  454. package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
  455. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.move-before-child/output.txt +0 -10
  456. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.raw-text-key-branches/case.tsx +0 -5
  457. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/case.ts +0 -11
  458. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/output.txt +0 -1
  459. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/case.ts +0 -23
  460. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/output.txt +0 -6
  461. package/runtime/__test__/element-template/lynx/env.test.ts +0 -242
  462. package/runtime/__test__/element-template/runtime/page/authored-page.test.ts +0 -35
  463. package/runtime/__test__/element-template/runtime/patch/update-fixture-helper.test.tsx +0 -40
  464. package/runtime/__test__/snapshot/lynx-data-processors.test.ts +0 -3
  465. package/runtime/lib/element-template/lynx/env.d.ts +0 -1
  466. package/runtime/lib/element-template/lynx/env.js.map +0 -1
  467. package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +0 -1
  468. package/runtime/lib/shared/attribute-name.js.map +0 -1
  469. package/runtime/lib/shared/component-stack.js.map +0 -1
  470. package/runtime/lib/snapshot/alog/index.d.ts +0 -1
  471. package/runtime/lib/snapshot/alog/index.js +0 -8
  472. package/runtime/lib/snapshot/alog/index.js.map +0 -1
  473. package/runtime/lib/snapshot/compat/componentIs.d.ts +0 -4
  474. package/runtime/lib/snapshot/compat/componentIs.js +0 -20
  475. package/runtime/lib/snapshot/compat/componentIs.js.map +0 -1
  476. package/runtime/lib/utils.d.ts +0 -19
  477. package/runtime/lib/utils.js +0 -119
  478. package/runtime/lib/utils.js.map +0 -1
  479. package/runtime/lib/worklet-runtime/delayRunOnBackground.d.ts +0 -13
  480. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +0 -29
  481. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +0 -1
  482. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +0 -1
  483. package/runtime/lib/worklet-runtime/utils/version.js.map +0 -1
  484. package/runtime/src/snapshot/alog/index.ts +0 -8
  485. package/runtime/src/snapshot/compat/componentIs.ts +0 -30
  486. package/runtime/src/utils.ts +0 -134
  487. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +0 -53
  488. /package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.raw-text-key-branches → children.reconciles-raw-text-slots}/output.txt +0 -0
  489. /package/runtime/__test__/element-template/runtime/{template → background}/main-thread-function.test.ts +0 -0
  490. /package/runtime/lib/{shared → core}/attribute-name.d.ts +0 -0
  491. /package/runtime/lib/{shared → core}/attribute-name.js +0 -0
  492. /package/runtime/lib/{shared → core}/component-stack.d.ts +0 -0
  493. /package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.d.ts +0 -0
  494. /package/runtime/src/{shared → core}/attribute-name.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"hydrate.js","sourceRoot":"","sources":["../../../src/element-template/background/hydrate.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,yCAAyC,EAAE,MAAM,qBAAqB,CAAC;AACrG,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,EACrC,oCAAoC,EACpC,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,wCAAwC,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,+BAA+B,EAAE,qCAAqC,EAAE,MAAM,qBAAqB,CAAC;AAC7G,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAOpG,OAAO,EAAE,iCAAiC,EAAE,MAAM,uCAAuC,CAAC;AAE1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AAGtF,MAAM,wBAAwB,GAAG,UAAU,CAAC;AAC5C,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AACrD,MAAM,yBAAyB,GAAG,sB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,CAAC,GAAG,CAAC,IAAI,CAC1B,wBAAwB,CAAC,YAAY,EAAE,SAAS,CAAC,EACjD,QAAQ,EACR,SAAS,EACT,UAAU,CACX,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,gCAAgC,CACvC,QAA+C,EAC/C,KAAoC;IAEpC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,KAAK,IAAI,IAAI,CAAC;IACvB,CAAC;IACD,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC5B,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IACD,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1B,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACf,CAAC;QACD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,IAAI,GAAG,KAAK,iBAAiB,EAAE,CAAC;gBAC9B,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YACzB,IAAI,GAAG,KAAK,qBAAqB,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC/D,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IAAI,wBAAwB,CAAC,GAAG,CAAC,IAAI,sBAAsB,CAAC,KAAK,CAAC,EAAE,CAAC;gBACnE,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,QAAQ,KAAK,QAAQ;WACvB,CAAC,KAAK,IAAI,IAAI,IAAI,oBAAoB,CAAE,KAAuC,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/F,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { getAttributeSlotUpdateOp } from './attr-slots.js';\nimport { globalCommitContext, markRemovedSubtreeForPostDispatchTeardown } from './commit-context.js';\nimport {\n BUILTIN_RAW_TEXT_TEMPLATE_KEY,\n BackgroundListElementTemplateInstance,\n collectMainThreadRefSubtreeHandleIds,\n getContainingListItem,\n toUpdateTypedListItemCommand,\n} from './instance.js';\nimport type { BackgroundElementTemplateInstance } from './instance.js';\nimport { backgroundElementTemplateInstanceManager } from './manager.js';\nimport { isMainThreadFunction } from '../../core/main-thread-function.js';\nimport { isDirectOrDeepEqual } from '../../utils.js';\nimport { hydrationMap } from '../hydration-map.js';\nimport { isGestureSlotValue } from '../prop-adapters/gesture.js';\nimport { isMainThreadEventPropKey, isSpreadRecord } from '../prop-adapters/spread.js';\nimport { ElementTemplateUpdateOps } from '../protocol/opcodes.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../protocol/page.js';\nimport { elementTemplateIdentityKey, parseElementTemplateType } from '../protocol/template-type.js';\nimport type {\n SerializableValue,\n SerializedCompiledNode,\n SerializedEtNode,\n SerializedTypedListNode,\n} from '../protocol/types.js';\nimport { getMainThreadDynamicAttrSlotKinds } from '../runtime/template/attr-slot-plan.js';\nimport type { MainThreadDynamicAttrKind } from '../runtime/template/attr-slot-plan.js';\nimport { isMTEventNativeWrapper } from '../runtime/template/main-thread-event-ctx.js';\nimport type { MTRefNativeWrapper } from '../runtime/template/main-thread-ref-ctx.js';\n\nconst MAIN_BUNDLE_URL_SENTINEL = '__Card__';\nconst COMPONENT_AT_INDEX_ATTR = 'component-at-index';\nconst COMPONENT_AT_INDEXES_ATTR = 'component-at-indexes';\nconst ENQUEUE_COMPONENT_ATTR = 'enqueue-component';\nconst UPDATE_LIST_INFO_ATTR = 'update-list-info';\n\nexport function hydrateRootChildrenIntoContext(\n serializedChildren: SerializedEtNode[],\n root: BackgroundElementTemplateInstance,\n): boolean {\n try {\n return hydrateChildListIntoContext(\n ELEMENT_TEMPLATE_PAGE_HANDLE_ID,\n ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX,\n serializedChildren,\n root.childNodes,\n );\n } finally {\n // Template identities only need caching for this synchronous hydration pass.\n backgroundHydrateKeys.clear();\n }\n}\n\nfunction isSerializedCompiledNode(serialized: SerializedEtNode): serialized is SerializedCompiledNode {\n return typeof (serialized as { templateKey?: unknown }).templateKey === 'string';\n}\n\nfunction isSerializedTypedListNode(serialized: SerializedEtNode): serialized is SerializedTypedListNode {\n return !isSerializedCompiledNode(serialized) && serialized.tag === 'list';\n}\n\ninterface HydrateChildListDiff {\n // Background child at a new slot index that has no matching serialized child.\n insertions: Record<number, BackgroundElementTemplateInstance>;\n insertionCount: number;\n // Serialized child indexes that no longer exist in the background slot.\n removals: number[];\n // Serialized child old index -> same-slot reorder target.\n moves: Record<number, { toIndex: number; instance: BackgroundElementTemplateInstance }>;\n}\n\nfunction hydrateMatchingChildrenAndDiffSlot(\n serializedChildren: SerializedEtNode[],\n backgroundChildren: BackgroundElementTemplateInstance[],\n): HydrateChildListDiff | null {\n let lastPlacedIndex = 0;\n const result: HydrateChildListDiff = {\n insertions: {},\n insertionCount: 0,\n removals: [],\n moves: {},\n };\n const serializedByNodeKey: Record<string, [SerializedEtNode, number][]> = {};\n const serializedCursorByNodeKey: Record<string, number> = {};\n\n for (let i = 0; i < serializedChildren.length; i += 1) {\n const node = serializedChildren[i]!;\n const key = getSerializedNodeHydrateKey(node);\n (serializedByNodeKey[key] ??= []).push([node, i]);\n }\n\n for (let i = 0; i < backgroundChildren.length; i += 1) {\n const backgroundChild = backgroundChildren[i]!;\n // Normalize the background instance's full `${entry}:${key}` type tag to the\n // same native identity the serialized side uses (sentinel folded to the main\n // card), so main-card nodes match regardless of the `__Card__` prefix.\n const backgroundKey = getBackgroundNodeHydrateKey(backgroundChild.type);\n const serializedCandidates = serializedByNodeKey[backgroundKey];\n const candidateCursor = serializedCursorByNodeKey[backgroundKey] ?? 0;\n const matchedSerialized = serializedCandidates?.[candidateCursor];\n\n if (matchedSerialized) {\n serializedCursorByNodeKey[backgroundKey] = candidateCursor + 1;\n const oldIndex = matchedSerialized[1];\n if (!hydrateInstance(matchedSerialized[0], backgroundChild)) {\n return null;\n }\n if (oldIndex < lastPlacedIndex) {\n result.moves[oldIndex] = { toIndex: i, instance: backgroundChild };\n } else {\n lastPlacedIndex = oldIndex;\n }\n } else {\n result.insertions[i] = backgroundChild;\n result.insertionCount += 1;\n }\n }\n\n for (const key in serializedByNodeKey) {\n const candidates = serializedByNodeKey[key]!;\n const candidateCursor = serializedCursorByNodeKey[key] ?? 0;\n for (let i = candidateCursor; i < candidates.length; i += 1) {\n result.removals.push(candidates[i]![1]);\n }\n }\n\n return result;\n}\n\nfunction hydrateInstance(\n serialized: SerializedEtNode,\n instance: BackgroundElementTemplateInstance,\n): boolean {\n if (isSerializedCompiledNode(serialized)) {\n return hydrateCompiledInstance(serialized, instance);\n }\n if (__DEV__ && !isSerializedTypedListNode(serialized)) {\n lynx.reportError(\n new Error(`ElementTemplate hydrate does not support serialized typed node '${serialized.tag}'.`),\n );\n return false;\n }\n return hydrateListInstance(\n serialized as SerializedTypedListNode,\n instance as BackgroundListElementTemplateInstance,\n );\n}\n\nfunction hydrateCompiledInstance(\n serialized: SerializedCompiledNode,\n instance: BackgroundElementTemplateInstance,\n): boolean {\n const handleId = serialized.uid;\n if (!bindHydrationHandleId(instance, handleId, serialized.templateKey)) {\n return false;\n }\n if (serialized.attributeSlots?.length || instance.attributeSlots.length) {\n instance.prepareAttributeSlotsForHydration();\n hydrateAttributeSlots(instance.type, handleId, serialized.attributeSlots ?? [], instance.attributeSlots);\n }\n\n if (serialized.templateKey === BUILTIN_RAW_TEXT_TEMPLATE_KEY) {\n return true;\n }\n\n if (!serialized.childSlots?.length && !instance.firstChild) {\n return true;\n }\n\n const serializedChildSlots = serialized.childSlots ?? [];\n const backgroundChildSlots = instance.childSlots;\n // Snapshot hydrates dynamic children through slot-filtered lists. Keeping ET\n // scoped the same way means a cross-slot candidate is a source remove plus a\n // target create/insert, while same-slot reorder can still stay move-like.\n const slotCount = Math.max(serializedChildSlots.length, backgroundChildSlots.length);\n for (let slotId = 0; slotId < slotCount; slotId += 1) {\n const serializedSlot = serializedChildSlots[slotId];\n const backgroundSlot = backgroundChildSlots[slotId];\n if (!serializedSlot && !backgroundSlot) {\n continue;\n }\n if (\n !hydrateChildListIntoContext(\n instance.instanceId,\n slotId,\n serializedSlot ?? [],\n backgroundSlot ?? [],\n )\n ) {\n return false;\n }\n }\n return true;\n}\n\nconst backgroundHydrateKeys = new Map<string, string>();\n\nfunction getBackgroundNodeHydrateKey(type: string): string {\n const cached = backgroundHydrateKeys.get(type);\n if (cached !== undefined) {\n return cached;\n }\n const parsed = parseElementTemplateType(type);\n const key = elementTemplateIdentityKey(parsed.templateKey, parsed.bundleUrl);\n backgroundHydrateKeys.set(type, key);\n return key;\n}\n\nfunction getSerializedNodeHydrateKey(serialized: SerializedEtNode): string {\n if (!isSerializedCompiledNode(serialized)) {\n return serialized.tag;\n }\n return elementTemplateIdentityKey(\n serialized.templateKey,\n normalizeSerializedBundleUrl(serialized.bundleUrl),\n );\n}\n\nfunction normalizeSerializedBundleUrl(bundleUrl: string | undefined): string | null {\n return bundleUrl === undefined || bundleUrl === MAIN_BUNDLE_URL_SENTINEL ? null : bundleUrl;\n}\n\nfunction getSerializedTypedListChildren(serialized: SerializedTypedListNode): SerializedEtNode[] {\n return (__DEV__ ? serialized.options?.listChildren : serialized.options!.listChildren)!;\n}\n\nfunction hydrateListInstance(\n serialized: SerializedTypedListNode,\n instance: BackgroundListElementTemplateInstance,\n): boolean {\n if (__DEV__ && (serialized.childSlots?.length ?? 0) > 0) {\n lynx.reportError(new Error('ElementTemplate hydrate typed list does not support childSlots.'));\n return false;\n }\n\n const listChildren = getSerializedTypedListChildren(serialized);\n if (__DEV__ && !Array.isArray(listChildren)) {\n lynx.reportError(new Error('ElementTemplate hydrate typed list requires options.listChildren.'));\n return false;\n }\n\n const backgroundChildren = instance.childNodes;\n const handleId = serialized.uid;\n if (!bindHydrationHandleId(instance, handleId, serialized.tag)) {\n return false;\n }\n instance.prepareAttributeSlotsForHydration();\n hydrateAttributeSlots(\n serialized.tag,\n handleId,\n [getStableSerializedListAttributes(serialized.attributes)],\n instance.attributeSlots,\n );\n\n const listDiff = hydrateMatchingChildrenAndDiffSlot(listChildren, backgroundChildren);\n if (listDiff === null) {\n return false;\n }\n\n return emitHydrateTypedListReconciliation(\n instance,\n listChildren,\n backgroundChildren,\n listDiff,\n );\n}\n\nfunction getStableSerializedListAttributes(\n attributes: SerializedTypedListNode['attributes'],\n): SerializableValue {\n if (attributes == null) {\n return null;\n }\n if (\n !(COMPONENT_AT_INDEX_ATTR in attributes)\n && !(COMPONENT_AT_INDEXES_ATTR in attributes)\n && !(ENQUEUE_COMPONENT_ATTR in attributes)\n && !(UPDATE_LIST_INFO_ATTR in attributes)\n ) {\n return attributes;\n }\n const stableAttributes: Record<string, SerializableValue> = {};\n let hasStableAttribute = false;\n for (const key in attributes) {\n if (\n key === COMPONENT_AT_INDEX_ATTR\n || key === COMPONENT_AT_INDEXES_ATTR\n || key === ENQUEUE_COMPONENT_ATTR\n || key === UPDATE_LIST_INFO_ATTR\n ) {\n continue;\n }\n stableAttributes[key] = attributes[key]!;\n hasStableAttribute = true;\n }\n return hasStableAttribute ? stableAttributes : null;\n}\n\nfunction hydrateChildListIntoContext(\n targetHandleId: number,\n slotId: number,\n serializedChildren: SerializedEtNode[],\n backgroundChildren: BackgroundElementTemplateInstance[],\n): boolean {\n if (backgroundChildren.length === 0) {\n for (const serialized of serializedChildren) {\n if (!emitSerializedSubtreeRemove(targetHandleId, slotId, serialized)) {\n return false;\n }\n }\n return true;\n }\n\n // Preserve the full matcher’s FIFO pairing while avoiding its temporary\n // structures when every child already occupies the matching slot position.\n const length = serializedChildren.length;\n if (length === backgroundChildren.length) {\n let samePairwise = true;\n for (let i = 0; i < length; i += 1) {\n if (\n getSerializedNodeHydrateKey(serializedChildren[i]!)\n !== getBackgroundNodeHydrateKey(backgroundChildren[i]!.type)\n ) {\n samePairwise = false;\n break;\n }\n }\n if (samePairwise) {\n for (let i = 0; i < length; i += 1) {\n if (!hydrateInstance(serializedChildren[i]!, backgroundChildren[i]!)) {\n return false;\n }\n }\n return true;\n }\n }\n\n const listDiff = hydrateMatchingChildrenAndDiffSlot(serializedChildren, backgroundChildren);\n if (listDiff === null) {\n return false;\n }\n\n // Hydrate emits patches directly here. Replaying against serialized order\n // keeps insert targets in the main-thread slot without reshaping background.\n const removalIndexes = new Set(listDiff.removals);\n const { insertions, moves } = listDiff;\n const movesWaitingForInsertionPoint = new Map<number, BackgroundElementTemplateInstance>();\n let serializedCursor = 0;\n let currentSerializedChild = serializedChildren[serializedCursor];\n let newIndex = 0;\n let oldIndex = 0;\n // Insertions are known before replay starts. Moves are counted only when their\n // old serialized position is reached, so the cursor can keep emitting patches\n // even after all serialized children have been consumed.\n let insertOrMovePatchesWaitingForInsertionPoint = listDiff.insertionCount;\n while (currentSerializedChild || insertOrMovePatchesWaitingForInsertionPoint > 0) {\n let keepCurrentSerializedChild = false;\n if (currentSerializedChild && removalIndexes.has(oldIndex)) {\n if (!emitSerializedSubtreeRemove(targetHandleId, slotId, currentSerializedChild)) {\n return false;\n }\n } else if (currentSerializedChild && moves[oldIndex] !== undefined) {\n const move = moves[oldIndex]!;\n movesWaitingForInsertionPoint.set(move.toIndex, move.instance);\n insertOrMovePatchesWaitingForInsertionPoint += 1;\n } else {\n const beforeChildId = currentSerializedChild ? currentSerializedChild.uid : 0;\n const movedChild = movesWaitingForInsertionPoint.get(newIndex);\n if (movedChild) {\n keepCurrentSerializedChild = true;\n globalCommitContext.ops.push(\n ElementTemplateUpdateOps.insertNode,\n targetHandleId,\n slotId,\n movedChild.instanceId,\n beforeChildId,\n getContainingListItem(movedChild) ? null : collectMainThreadRefSubtreeHandleIds(movedChild),\n );\n insertOrMovePatchesWaitingForInsertionPoint -= 1;\n } else if (insertions[newIndex] !== undefined) {\n const insertedChild = insertions[newIndex]!;\n keepCurrentSerializedChild = true;\n emitCreateSubtree(insertedChild);\n globalCommitContext.ops.push(\n ElementTemplateUpdateOps.insertNode,\n targetHandleId,\n slotId,\n insertedChild.instanceId,\n beforeChildId,\n getContainingListItem(insertedChild) ? null : collectMainThreadRefSubtreeHandleIds(insertedChild),\n );\n insertOrMovePatchesWaitingForInsertionPoint -= 1;\n }\n\n newIndex += 1;\n }\n if (currentSerializedChild && !keepCurrentSerializedChild) {\n currentSerializedChild = serializedChildren[++serializedCursor];\n oldIndex += 1;\n }\n }\n return true;\n}\n\nfunction emitSerializedSubtreeRemove(\n targetHandleId: number,\n slotId: number,\n serialized: SerializedEtNode,\n): boolean {\n // The removed child may no longer have a live background instance in this\n // slot, so serialized data is the source of truth for registry cleanup.\n const removedSubtreeHandleIds: number[] = [];\n if (!collectRemovableSerializedSubtreeHandleIdsInto(serialized, removedSubtreeHandleIds)) {\n return false;\n }\n const childId = removedSubtreeHandleIds[0]!;\n const existing = backgroundElementTemplateInstanceManager.get(childId);\n globalCommitContext.ops.push(\n ElementTemplateUpdateOps.removeNode,\n targetHandleId,\n slotId,\n childId,\n removedSubtreeHandleIds,\n );\n if (existing && !existing.parent) {\n markRemovedSubtreeForPostDispatchTeardown(existing);\n }\n return true;\n}\n\nfunction collectRemovableSerializedSubtreeHandleIdsInto(\n serialized: SerializedEtNode,\n handles: number[],\n): boolean {\n const handleId = getRemovableSerializedHandleId(serialized);\n if (handleId === null) {\n return false;\n }\n handles.push(handleId);\n\n if (isSerializedCompiledNode(serialized)) {\n for (const slotChildren of serialized.childSlots ?? []) {\n if (!slotChildren) {\n continue;\n }\n for (const child of slotChildren) {\n if (!collectRemovableSerializedSubtreeHandleIdsInto(child, handles)) {\n return false;\n }\n }\n }\n return true;\n }\n\n if (__DEV__ && !isSerializedTypedListNode(serialized)) {\n lynx.reportError(\n new Error(`ElementTemplate hydrate does not support serialized typed node '${serialized.tag}'.`),\n );\n return false;\n }\n const serializedList = serialized as SerializedTypedListNode;\n if (__DEV__ && (serializedList.childSlots?.length ?? 0) > 0) {\n lynx.reportError(new Error('ElementTemplate hydrate typed list does not support childSlots.'));\n return false;\n }\n const listChildren = getSerializedTypedListChildren(serializedList);\n if (__DEV__ && !Array.isArray(listChildren)) {\n lynx.reportError(new Error('ElementTemplate hydrate typed list requires options.listChildren.'));\n return false;\n }\n for (const child of listChildren) {\n if (!collectRemovableSerializedSubtreeHandleIdsInto(child, handles)) {\n return false;\n }\n }\n return true;\n}\n\nfunction getRemovableSerializedHandleId(serialized: SerializedEtNode): number | null {\n const handleId = serialized.uid;\n if (\n __DEV__\n && (typeof handleId !== 'number'\n || !Number.isInteger(handleId)\n || handleId === ELEMENT_TEMPLATE_PAGE_HANDLE_ID)\n ) {\n lynx.reportError(\n new Error(`ElementTemplate hydrate remove received invalid uid ${String(handleId)}.`),\n );\n return null;\n }\n return handleId;\n}\n\nfunction emitHydrateTypedListReconciliation(\n instance: BackgroundListElementTemplateInstance,\n serializedChildren: SerializedEtNode[],\n backgroundChildren: BackgroundElementTemplateInstance[],\n listDiff: HydrateChildListDiff,\n): boolean {\n const movedOldIndexes = Object.keys(listDiff.moves).map(Number);\n const removalIndexes = listDiff.removals.concat(movedOldIndexes).sort((a, b) => a - b);\n for (let index = 0; index < removalIndexes.length; index += 1) {\n const oldIndex = removalIndexes[index]!;\n const serialized = serializedChildren[oldIndex]!;\n let itemId: number;\n const removedSubtreeHandleIds: number[] = [];\n if (listDiff.moves[oldIndex] === undefined) {\n if (!collectRemovableSerializedSubtreeHandleIdsInto(serialized, removedSubtreeHandleIds)) {\n return false;\n }\n itemId = removedSubtreeHandleIds[0]!;\n } else {\n itemId = serialized.uid;\n }\n globalCommitContext.ops.push(\n ElementTemplateUpdateOps.removeTypedListItem,\n instance.instanceId,\n itemId,\n removedSubtreeHandleIds,\n );\n }\n\n const insertedIndexes = Object.keys(listDiff.insertions).map(Number);\n let movedToIndexes: Set<number> | null = null;\n for (let index = 0; index < movedOldIndexes.length; index += 1) {\n const toIndex = listDiff.moves[movedOldIndexes[index]!]!.toIndex;\n insertedIndexes.push(toIndex);\n (movedToIndexes ??= new Set()).add(toIndex);\n }\n insertedIndexes.sort((a, b) => b - a);\n for (let index = 0; index < insertedIndexes.length; index += 1) {\n const insertedIndex = insertedIndexes[index]!;\n const child = backgroundChildren[insertedIndex]!;\n emitCreateSubtree(child);\n globalCommitContext.ops.push(\n ElementTemplateUpdateOps.insertTypedListItem,\n instance.instanceId,\n toUpdateTypedListItemCommand(child),\n backgroundChildren[insertedIndex + 1]?.instanceId ?? 0,\n );\n }\n\n for (let index = 0; index < backgroundChildren.length; index += 1) {\n if (listDiff.insertions[index] || movedToIndexes?.has(index)) {\n continue;\n }\n globalCommitContext.ops.push(\n ElementTemplateUpdateOps.updateTypedListItem,\n instance.instanceId,\n toUpdateTypedListItemCommand(backgroundChildren[index]!),\n );\n }\n return true;\n}\n\nfunction emitCreateSubtree(node: BackgroundElementTemplateInstance): void {\n // Linked-list walk: slot grouping would be discarded since we recurse into\n // every child regardless of slot. `emitCreate` does its own single-walk\n // serialization of `instanceId`s grouped by slot.\n let child = node.firstChild;\n while (child) {\n emitCreateSubtree(child);\n child = child.nextSibling;\n }\n node.prepareAttributeSlotsForHydration();\n node.emitCreate();\n}\n\nfunction bindHydrationHandleId(\n instance: BackgroundElementTemplateInstance,\n handleId: number,\n templateKey: string,\n): boolean {\n const oldHandleId = instance.instanceId;\n if (__DEV__) {\n try {\n backgroundElementTemplateInstanceManager.updateId(instance.instanceId, handleId);\n // Ref proxies created before hydrate keep the old background id; resolve it\n // lazily so user-held proxies continue selecting the hydrated native node.\n hydrationMap.set(oldHandleId, handleId);\n instance.markMaterializedByHydration();\n return true;\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n lynx.reportError(\n new Error(`ElementTemplate hydrate received invalid uid ${handleId} for '${templateKey}': ${reason}`),\n );\n return false;\n }\n }\n\n backgroundElementTemplateInstanceManager.updateId(instance.instanceId, handleId);\n hydrationMap.set(oldHandleId, handleId);\n instance.markMaterializedByHydration();\n return true;\n}\n\nfunction hydrateAttributeSlots(\n templateType: string,\n handleId: number,\n beforeSlots: SerializableValue[],\n afterSlots: SerializableValue[],\n): void {\n const slotCount = Math.max(beforeSlots.length, afterSlots.length);\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n for (let slotIndex = 0; slotIndex < slotCount; slotIndex += 1) {\n // Native serialization and background preparation may represent an absent slot differently.\n const beforeValue = beforeSlots[slotIndex] ?? null;\n const afterValue = afterSlots[slotIndex] ?? null;\n if (\n !shouldForceMainThreadHydrateSlot(slotKinds?.get(slotIndex), afterValue)\n && isDirectOrDeepEqual(beforeValue, afterValue)\n ) {\n continue;\n }\n globalCommitContext.ops.push(\n getAttributeSlotUpdateOp(templateType, slotIndex),\n handleId,\n slotIndex,\n afterValue,\n );\n }\n}\n\nfunction shouldForceMainThreadHydrateSlot(\n slotKind: MainThreadDynamicAttrKind | undefined,\n value: SerializableValue | undefined,\n): boolean {\n if (slotKind === 'gesture') {\n return value != null;\n }\n if (slotKind === 'mt-event') {\n return isMTEventNativeWrapper(value);\n }\n if (slotKind === 'spread') {\n if (!isSpreadRecord(value)) {\n return false;\n }\n for (const key of Object.keys(value)) {\n if (key === 'main-thread:ref') {\n return true;\n }\n const entry = value[key];\n if (key === 'main-thread:gesture' && isGestureSlotValue(entry)) {\n return true;\n }\n if (isMainThreadEventPropKey(key) && isMTEventNativeWrapper(entry)) {\n return true;\n }\n }\n return false;\n }\n return slotKind === 'mt-ref'\n && (value == null || isMainThreadFunction((value as unknown as MTRefNativeWrapper).value));\n}\n"]}
1
+ {"version":3,"file":"hydrate.js","sourceRoot":"","sources":["../../../src/element-template/background/hydrate.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB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G,CAAC,CAAC;YACzB,IAAI,GAAG,KAAK,qBAAqB,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC/D,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IAAI,wBAAwB,CAAC,GAAG,CAAC,IAAI,sBAAsB,CAAC,KAAK,CAAC,EAAE,CAAC;gBACnE,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,QAAQ,KAAK,QAAQ;WACvB,CAAC,KAAK,IAAI,IAAI,IAAI,oBAAoB,CAAE,KAAuC,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/F,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { getAttributeSlotUpdateOp } from './attr-slots.js';\nimport { globalCommitContext, markRemovedSubtreeForPostDispatchTeardown } from './commit-context.js';\nimport {\n BUILTIN_RAW_TEXT_TEMPLATE_KEY,\n BackgroundListElementTemplateInstance,\n collectMainThreadRefSubtreeHandleIds,\n getContainingListItem,\n toUpdateTypedListItemCommand,\n} from './instance.js';\nimport type { BackgroundElementTemplateInstance } from './instance.js';\nimport { backgroundElementTemplateInstanceManager } from './manager.js';\nimport { isDirectOrDeepEqual } from '../../core/deep-equal.js';\nimport { isMainThreadFunction } from '../../core/main-thread-function.js';\nimport { hydrationMap } from '../hydration-map.js';\nimport { isGestureSlotValue } from '../prop-adapters/gesture.js';\nimport { isMainThreadEventPropKey, isSpreadRecord } from '../prop-adapters/spread.js';\nimport { ElementTemplateUpdateOps } from '../protocol/opcodes.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../protocol/page.js';\nimport {\n MAIN_BUNDLE_URL_SENTINEL,\n elementTemplateIdentityKey,\n parseElementTemplateType,\n} from '../protocol/template-type.js';\nimport type {\n SerializableValue,\n SerializedCompiledNode,\n SerializedEtNode,\n SerializedTypedListNode,\n} from '../protocol/types.js';\nimport type { ETListItemPlatformInfo } from '../runtime/list/list.js';\nimport { getMainThreadDynamicAttrSlotKinds } from '../runtime/template/attr-slot-plan.js';\nimport type { MainThreadDynamicAttrKind } from '../runtime/template/attr-slot-plan.js';\nimport { isMTEventNativeWrapper } from '../runtime/template/main-thread-event-ctx.js';\nimport type { MTRefNativeWrapper } from '../runtime/template/main-thread-ref-ctx.js';\n\nexport function hydrateRootChildrenIntoContext(\n serializedChildren: SerializedEtNode[],\n root: BackgroundElementTemplateInstance,\n): boolean {\n try {\n return hydrateChildListIntoContext(\n ELEMENT_TEMPLATE_PAGE_HANDLE_ID,\n ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX,\n serializedChildren,\n root.childNodes,\n );\n } finally {\n // Template identities only need caching for this synchronous hydration pass.\n backgroundHydrateKeys.clear();\n hydratedListItemsNeedingSubtreeSync.clear();\n }\n}\n\nconst hydratedListItemsNeedingSubtreeSync = new Set<BackgroundElementTemplateInstance>();\n\nfunction isSerializedCompiledNode(serialized: SerializedEtNode): serialized is SerializedCompiledNode {\n return typeof (serialized as { templateKey?: unknown }).templateKey === 'string';\n}\n\nfunction isSerializedTypedListNode(serialized: SerializedEtNode): serialized is SerializedTypedListNode {\n return !isSerializedCompiledNode(serialized) && serialized.tag === 'list';\n}\n\ninterface HydrateChildListDiff {\n // Background child at a new slot index that has no matching serialized child.\n insertions: Record<number, BackgroundElementTemplateInstance>;\n insertionCount: number;\n // Serialized child indexes that no longer exist in the background slot.\n removals: number[];\n // Serialized child old index -> same-slot reorder target.\n moves: Record<number, { toIndex: number; instance: BackgroundElementTemplateInstance }>;\n}\n\nfunction hydrateMatchingChildrenAndDiffSlot(\n serializedChildren: SerializedEtNode[],\n backgroundChildren: BackgroundElementTemplateInstance[],\n): HydrateChildListDiff | null {\n let lastPlacedIndex = 0;\n const result: HydrateChildListDiff = {\n insertions: {},\n insertionCount: 0,\n removals: [],\n moves: {},\n };\n const serializedByNodeKey: Record<string, [SerializedEtNode, number][]> = {};\n const serializedCursorByNodeKey: Record<string, number> = {};\n\n for (let i = 0; i < serializedChildren.length; i += 1) {\n const node = serializedChildren[i]!;\n const key = getSerializedNodeHydrateKey(node);\n (serializedByNodeKey[key] ??= []).push([node, i]);\n }\n\n for (let i = 0; i < backgroundChildren.length; i += 1) {\n const backgroundChild = backgroundChildren[i]!;\n // Normalize the background instance's full `${entry}:${key}` type tag to the\n // same native identity the serialized side uses (sentinel folded to the main\n // card), so main-card nodes match regardless of the `__Card__` prefix.\n const backgroundKey = getBackgroundNodeHydrateKey(backgroundChild.type);\n const serializedCandidates = serializedByNodeKey[backgroundKey];\n const candidateCursor = serializedCursorByNodeKey[backgroundKey] ?? 0;\n const matchedSerialized = serializedCandidates?.[candidateCursor];\n\n if (matchedSerialized) {\n serializedCursorByNodeKey[backgroundKey] = candidateCursor + 1;\n const oldIndex = matchedSerialized[1];\n if (!hydrateInstance(matchedSerialized[0], backgroundChild)) {\n return null;\n }\n if (oldIndex < lastPlacedIndex) {\n result.moves[oldIndex] = { toIndex: i, instance: backgroundChild };\n } else {\n lastPlacedIndex = oldIndex;\n }\n } else {\n result.insertions[i] = backgroundChild;\n result.insertionCount += 1;\n }\n }\n\n for (const key in serializedByNodeKey) {\n const candidates = serializedByNodeKey[key]!;\n const candidateCursor = serializedCursorByNodeKey[key] ?? 0;\n for (let i = candidateCursor; i < candidates.length; i += 1) {\n result.removals.push(candidates[i]![1]);\n }\n }\n\n return result;\n}\n\nfunction hydrateInstance(\n serialized: SerializedEtNode,\n instance: BackgroundElementTemplateInstance,\n): boolean {\n if (isSerializedCompiledNode(serialized)) {\n return hydrateCompiledInstance(serialized, instance);\n }\n if (__DEV__ && !isSerializedTypedListNode(serialized)) {\n lynx.reportError(\n new Error(`ElementTemplate hydrate does not support serialized typed node '${serialized.tag}'.`),\n );\n return false;\n }\n // Match List items separately, then reuse the shared structural patch\n // emitter.\n return hydrateListInstance(\n serialized as SerializedTypedListNode,\n instance as BackgroundListElementTemplateInstance,\n );\n}\n\nfunction hydrateCompiledInstance(\n serialized: SerializedCompiledNode,\n instance: BackgroundElementTemplateInstance,\n): boolean {\n const handleId = serialized.uid;\n if (!bindHydrationHandleId(instance, handleId, serialized.templateKey)) {\n return false;\n }\n if (serialized.attributeSlots?.length || instance.attributeSlots.length) {\n instance.prepareAttributeSlotsForHydration();\n hydrateAttributeSlots(instance.type, handleId, serialized.attributeSlots ?? [], instance.attributeSlots);\n }\n\n if (serialized.templateKey === BUILTIN_RAW_TEXT_TEMPLATE_KEY) {\n return true;\n }\n\n if (!serialized.childSlots?.length && !instance.firstChild) {\n return true;\n }\n\n const serializedChildSlots = serialized.childSlots ?? [];\n const backgroundChildSlots = instance.childSlots;\n // Snapshot hydrates dynamic children through slot-filtered lists. Keeping ET\n // scoped the same way means a cross-slot candidate is a source remove plus a\n // target create/insert, while same-slot reorder can still stay move-like.\n const slotCount = Math.max(serializedChildSlots.length, backgroundChildSlots.length);\n for (let slotId = 0; slotId < slotCount; slotId += 1) {\n const serializedSlot = serializedChildSlots[slotId];\n const backgroundSlot = backgroundChildSlots[slotId];\n if (!serializedSlot && !backgroundSlot) {\n continue;\n }\n if (\n !hydrateChildListIntoContext(\n instance.instanceId,\n slotId,\n serializedSlot ?? [],\n backgroundSlot ?? [],\n )\n ) {\n return false;\n }\n }\n return true;\n}\n\nconst backgroundHydrateKeys = new Map<string, string>();\n\nfunction getBackgroundNodeHydrateKey(type: string): string {\n const cached = backgroundHydrateKeys.get(type);\n if (cached !== undefined) {\n return cached;\n }\n const parsed = parseElementTemplateType(type);\n const key = elementTemplateIdentityKey(parsed.templateKey, parsed.bundleUrl);\n backgroundHydrateKeys.set(type, key);\n return key;\n}\n\nfunction getSerializedNodeHydrateKey(serialized: SerializedEtNode): string {\n if (!isSerializedCompiledNode(serialized)) {\n return serialized.tag;\n }\n return elementTemplateIdentityKey(\n serialized.templateKey,\n normalizeSerializedBundleUrl(serialized.bundleUrl),\n );\n}\n\nfunction normalizeSerializedBundleUrl(bundleUrl: string | undefined): string | null {\n return bundleUrl === undefined || bundleUrl === MAIN_BUNDLE_URL_SENTINEL ? null : bundleUrl;\n}\n\nfunction getSerializedTypedListChildren(\n serialized: SerializedTypedListNode,\n): SerializedEtNode[] {\n // Native List stores logical items in childSlots[0].\n // A missing or empty slot 0 represents an empty List.\n return serialized.childSlots?.[0] ?? [];\n}\n\nfunction getSerializedListItemPlatformInfo(\n serialized: SerializedEtNode,\n): ETListItemPlatformInfo | undefined {\n const options = serialized.options;\n if (!options || !('__listItemPlatformInfo' in options)) {\n return undefined;\n }\n const platformInfo = options['__listItemPlatformInfo'];\n // Require an attribute object for platform info.\n if (\n platformInfo == null\n || typeof platformInfo !== 'object'\n || Array.isArray(platformInfo)\n ) {\n return undefined;\n }\n // Reuse the ET serializable attribute type and preserve the original object.\n return platformInfo as ETListItemPlatformInfo;\n}\n\nfunction getListItemHydrateKey(\n platformInfo: ETListItemPlatformInfo | undefined,\n): string | undefined {\n const itemKey = platformInfo?.['item-key'];\n // Nullish item keys use the unkeyed group. Empty strings are valid keys.\n // Normalize provided keys to strings to preserve RL3's object-key grouping.\n return itemKey == null ? undefined : String(itemKey as string | number);\n}\n\nfunction hydrateListInstance(\n serialized: SerializedTypedListNode,\n instance: BackgroundListElementTemplateInstance,\n): boolean {\n const serializedChildren = getSerializedTypedListChildren(serialized);\n const backgroundChildren = instance.childNodes;\n if (__DEV__) {\n // Both sides store logical List items in slot 0.\n const hasUnsupportedSerializedSlot = serialized.childSlots?.some(\n (children, slotIndex) => slotIndex !== 0 && (children?.length ?? 0) > 0,\n );\n // A child's __slotIndex identifies its logical slot.\n const hasUnsupportedBackgroundSlot = backgroundChildren.some(child => child.__slotIndex !== 0);\n if (hasUnsupportedSerializedSlot || hasUnsupportedBackgroundSlot) {\n lynx.reportError(new Error('ElementTemplate hydrate typed list only supports logical slot 0.'));\n return false;\n }\n }\n\n const handleId = serialized.uid;\n if (!bindHydrationHandleId(instance, handleId, serialized.tag)) {\n return false;\n }\n\n instance.prepareAttributeSlotsForHydration();\n\n hydrateAttributeSlots(\n serialized.tag,\n handleId,\n [serialized.attributes ?? null],\n instance.attributeSlots,\n );\n\n // The List UID and attributes are hydrated before this empty-children fast\n // path.\n if (serializedChildren.length === 0 && backgroundChildren.length === 0) {\n return true;\n }\n\n // Hydrate matched items recursively and preserve insertion, removal, and move\n // distinctions.\n const listDiff = hydrateMatchingListChildrenAndDiff(handleId, serializedChildren, backgroundChildren);\n if (listDiff === null) {\n return false;\n }\n\n // Reuse child-slot structural commands so native records List changes in slot\n // 0.\n if (!emitHydrateChildrenDiff(handleId, 0, serializedChildren, listDiff)) {\n return false;\n }\n for (let index = 0; index < backgroundChildren.length; index += 1) {\n const child = backgroundChildren[index]!;\n if (!hydratedListItemsNeedingSubtreeSync.delete(child)) {\n continue;\n }\n globalCommitContext.ops.push(\n ElementTemplateUpdateOps.updateTypedListItem,\n handleId,\n toUpdateTypedListItemCommand(child, false),\n );\n }\n return true;\n}\n\nfunction hydrateMatchingListChildrenAndDiff(\n listHandleId: number,\n serializedChildren: SerializedEtNode[],\n backgroundChildren: BackgroundElementTemplateInstance[],\n): HydrateChildListDiff | null {\n const result: HydrateChildListDiff = {\n insertions: {},\n insertionCount: 0,\n removals: [],\n moves: {},\n };\n // Explicit item-key values are unique on each side, so each key maps to one\n // old node.\n const serializedByItemKey = new Map<string, SerializedEtNode>();\n // Group unkeyed nodes by template identity.\n // Preserve their old order and consume candidates with a per-template cursor.\n const serializedByTemplateKey = new Map<string, {\n nodes: SerializedEtNode[];\n cursor: number; // Index of the next candidate to consume, initially zero.\n }>();\n // Track old positions to detect moves.\n // Remove matched records so the remaining entries identify deleted nodes.\n const remainingOldIndices = new Map<SerializedEtNode, number>();\n\n for (let oldIndex = 0; oldIndex < serializedChildren.length; oldIndex++) {\n const serialized = serializedChildren[oldIndex]!;\n const itemKey = getListItemHydrateKey(\n getSerializedListItemPlatformInfo(serialized),\n );\n remainingOldIndices.set(serialized, oldIndex);\n if (itemKey !== undefined) {\n // Index keyed nodes for matching by item-key.\n serializedByItemKey.set(itemKey, serialized);\n continue;\n }\n // Queue unkeyed nodes by normalized template identity.\n const templateKey = getSerializedNodeHydrateKey(serialized);\n let group = serializedByTemplateKey.get(templateKey);\n if (group === undefined) {\n group = { nodes: [], cursor: 0 };\n serializedByTemplateKey.set(templateKey, group);\n }\n group.nodes.push(serialized);\n }\n\n let lastPlacedIndex = 0;\n for (let newIndex = 0; newIndex < backgroundChildren.length; newIndex++) {\n const instance = backgroundChildren[newIndex]!;\n const itemKey = getListItemHydrateKey(\n instance.getListItemPlatformInfo(),\n );\n const templateKey = getBackgroundNodeHydrateKey(instance.type);\n\n let serialized: SerializedEtNode | undefined;\n if (itemKey === undefined) {\n const group = serializedByTemplateKey.get(templateKey);\n serialized = group?.nodes[group.cursor];\n } else {\n serialized = serializedByItemKey.get(itemKey);\n }\n\n if (serialized === undefined || getSerializedNodeHydrateKey(serialized) !== templateKey) {\n // Record an insertion when no compatible candidate exists.\n result.insertions[newIndex] = instance;\n result.insertionCount += 1;\n // Keep the old candidate pending removal.\n continue;\n }\n\n if (!hydrateInstance(serialized, instance)) {\n return null;\n }\n\n // The item now uses its native UID.\n // Emit updateTypedListItem when platform info changes.\n hydrateListItemPlatformInfo(listHandleId, serialized, instance);\n\n // Remove the matched node from the pending-removal map.\n const oldIndex = remainingOldIndices.get(serialized)!;\n remainingOldIndices.delete(serialized);\n if (itemKey === undefined) {\n serializedByTemplateKey.get(templateKey)!.cursor += 1;\n } else {\n serializedByItemKey.delete(itemKey);\n }\n if (oldIndex < lastPlacedIndex) {\n // Record a move for the retained item.\n result.moves[oldIndex] = {\n toIndex: newIndex,\n instance,\n };\n } else {\n lastPlacedIndex = oldIndex;\n }\n }\n // Remove the old nodes left unmatched.\n // The Map preserves old order, so remaining indexes are already sorted.\n for (const oldIndex of remainingOldIndices.values()) {\n result.removals.push(oldIndex);\n }\n return result;\n}\n\nfunction hydrateListItemPlatformInfo(\n listHandleId: number,\n serialized: SerializedEtNode,\n instance: BackgroundElementTemplateInstance,\n): void {\n const before = getSerializedListItemPlatformInfo(serialized) ?? {};\n const after = instance.getListItemPlatformInfo();\n if (isDirectOrDeepEqual(before, after)) {\n return;\n }\n globalCommitContext.ops.push(\n ElementTemplateUpdateOps.updateTypedListItem,\n listHandleId,\n {\n __etHandleRef: serialized.uid,\n type: instance.type,\n platformInfo: after,\n subtreeHandleIds: null,\n },\n );\n}\n\nfunction hydrateChildListIntoContext(\n targetHandleId: number,\n slotId: number,\n serializedChildren: SerializedEtNode[],\n backgroundChildren: BackgroundElementTemplateInstance[],\n): boolean {\n if (backgroundChildren.length === 0) {\n for (const serialized of serializedChildren) {\n if (!emitSerializedSubtreeRemove(targetHandleId, slotId, serialized)) {\n return false;\n }\n }\n return true;\n }\n\n // Preserve the full matcher’s FIFO pairing while avoiding its temporary\n // structures when every child already occupies the matching slot position.\n const length = serializedChildren.length;\n if (length === backgroundChildren.length) {\n let samePairwise = true;\n for (let i = 0; i < length; i += 1) {\n if (\n getSerializedNodeHydrateKey(serializedChildren[i]!)\n !== getBackgroundNodeHydrateKey(backgroundChildren[i]!.type)\n ) {\n samePairwise = false;\n break;\n }\n }\n if (samePairwise) {\n for (let i = 0; i < length; i += 1) {\n if (!hydrateInstance(serializedChildren[i]!, backgroundChildren[i]!)) {\n return false;\n }\n }\n return true;\n }\n }\n\n const listDiff = hydrateMatchingChildrenAndDiffSlot(serializedChildren, backgroundChildren);\n if (listDiff === null) {\n return false;\n }\n\n // Hydrate emits patches directly here. Replaying against serialized order\n // keeps insert targets in the main-thread slot without reshaping background.\n return emitHydrateChildrenDiff(targetHandleId, slotId, serializedChildren, listDiff);\n}\n\nfunction emitHydrateChildrenDiff(\n targetHandleId: number,\n slotId: number,\n serializedChildren: SerializedEtNode[],\n listDiff: HydrateChildListDiff,\n): boolean {\n // serializedChildren supplies the old order and insertion anchors.\n // listDiff describes the target changes.\n const removalIndexes = new Set(listDiff.removals);\n const { insertions, moves } = listDiff;\n const movesWaitingForInsertionPoint = new Map<number, BackgroundElementTemplateInstance>();\n let serializedCursor = 0;\n let currentSerializedChild = serializedChildren[serializedCursor];\n let newIndex = 0;\n let oldIndex = 0;\n // Insertions are known before replay starts. Moves are counted only when their\n // old serialized position is reached, so the cursor can keep emitting patches\n // even after all serialized children have been consumed.\n let insertOrMovePatchesWaitingForInsertionPoint = listDiff.insertionCount;\n while (currentSerializedChild || insertOrMovePatchesWaitingForInsertionPoint > 0) {\n let keepCurrentSerializedChild = false;\n if (currentSerializedChild && removalIndexes.has(oldIndex)) {\n if (!emitSerializedSubtreeRemove(targetHandleId, slotId, currentSerializedChild)) {\n return false;\n }\n } else if (currentSerializedChild && moves[oldIndex] !== undefined) {\n const move = moves[oldIndex]!;\n movesWaitingForInsertionPoint.set(move.toIndex, move.instance);\n insertOrMovePatchesWaitingForInsertionPoint += 1;\n } else {\n const beforeChildId = currentSerializedChild ? currentSerializedChild.uid : 0;\n const movedChild = movesWaitingForInsertionPoint.get(newIndex);\n if (movedChild) {\n keepCurrentSerializedChild = true;\n globalCommitContext.ops.push(\n ElementTemplateUpdateOps.insertNode,\n targetHandleId,\n slotId,\n movedChild.instanceId,\n beforeChildId,\n getContainingListItem(movedChild) ? null : collectMainThreadRefSubtreeHandleIds(movedChild),\n );\n insertOrMovePatchesWaitingForInsertionPoint -= 1;\n } else if (insertions[newIndex] !== undefined) {\n const insertedChild = insertions[newIndex]!;\n const containingListItem = getContainingListItem(insertedChild);\n const subtreeHandleIds = collectMainThreadRefSubtreeHandleIds(insertedChild);\n keepCurrentSerializedChild = true;\n emitCreateSubtree(insertedChild);\n globalCommitContext.ops.push(\n ElementTemplateUpdateOps.insertNode,\n targetHandleId,\n slotId,\n insertedChild.instanceId,\n beforeChildId,\n containingListItem ? null : subtreeHandleIds,\n );\n if (containingListItem && subtreeHandleIds !== null) {\n hydratedListItemsNeedingSubtreeSync.add(containingListItem);\n }\n insertOrMovePatchesWaitingForInsertionPoint -= 1;\n }\n\n newIndex += 1;\n }\n if (currentSerializedChild && !keepCurrentSerializedChild) {\n currentSerializedChild = serializedChildren[++serializedCursor];\n oldIndex += 1;\n }\n }\n return true;\n}\n\nfunction emitSerializedSubtreeRemove(\n targetHandleId: number,\n slotId: number,\n serialized: SerializedEtNode,\n): boolean {\n // The removed child may no longer have a live background instance in this\n // slot, so serialized data is the source of truth for registry cleanup.\n const removedSubtreeHandleIds: number[] = [];\n if (!collectRemovableSerializedSubtreeHandleIdsInto(serialized, removedSubtreeHandleIds)) {\n return false;\n }\n const childId = removedSubtreeHandleIds[0]!;\n const existing = backgroundElementTemplateInstanceManager.get(childId);\n globalCommitContext.ops.push(\n ElementTemplateUpdateOps.removeNode,\n targetHandleId,\n slotId,\n childId,\n removedSubtreeHandleIds,\n );\n if (existing && !existing.parent) {\n markRemovedSubtreeForPostDispatchTeardown(existing);\n }\n return true;\n}\n\nfunction collectRemovableSerializedSubtreeHandleIdsInto(\n serialized: SerializedEtNode,\n handles: number[],\n): boolean {\n const handleId = getRemovableSerializedHandleId(serialized);\n if (handleId === null) {\n return false;\n }\n handles.push(handleId);\n\n if (isSerializedCompiledNode(serialized)) {\n for (const slotChildren of serialized.childSlots ?? []) {\n if (!slotChildren) {\n continue;\n }\n for (const child of slotChildren) {\n if (!collectRemovableSerializedSubtreeHandleIdsInto(child, handles)) {\n return false;\n }\n }\n }\n return true;\n }\n\n if (__DEV__ && !isSerializedTypedListNode(serialized)) {\n lynx.reportError(\n new Error(`ElementTemplate hydrate does not support serialized typed node '${serialized.tag}'.`),\n );\n return false;\n }\n const serializedList = serialized as SerializedTypedListNode;\n // Collect all logical item UIDs from slot 0 when removing a List or its\n // ancestor.\n if (\n __DEV__\n && serializedList.childSlots?.some(\n (children, slotIndex) => slotIndex !== 0 && (children?.length ?? 0) > 0,\n )\n ) {\n lynx.reportError(new Error('ElementTemplate hydrate typed list only supports logical slot 0.'));\n return false;\n }\n const listChildren = getSerializedTypedListChildren(serializedList);\n for (const child of listChildren) {\n if (!collectRemovableSerializedSubtreeHandleIdsInto(child, handles)) {\n return false;\n }\n }\n return true;\n}\n\nfunction getRemovableSerializedHandleId(serialized: SerializedEtNode): number | null {\n const handleId = serialized.uid;\n if (\n __DEV__\n && (typeof handleId !== 'number'\n || !Number.isInteger(handleId)\n || handleId === ELEMENT_TEMPLATE_PAGE_HANDLE_ID)\n ) {\n lynx.reportError(\n new Error(`ElementTemplate hydrate remove received invalid uid ${String(handleId)}.`),\n );\n return null;\n }\n return handleId;\n}\n\nfunction emitCreateSubtree(node: BackgroundElementTemplateInstance): void {\n // Linked-list walk: slot grouping would be discarded since we recurse into\n // every child regardless of slot. `emitCreate` does its own single-walk\n // serialization of `instanceId`s grouped by slot.\n let child = node.firstChild;\n while (child) {\n emitCreateSubtree(child);\n child = child.nextSibling;\n }\n node.prepareAttributeSlotsForHydration();\n node.emitCreate();\n}\n\nfunction bindHydrationHandleId(\n instance: BackgroundElementTemplateInstance,\n handleId: number,\n templateKey: string,\n): boolean {\n const oldHandleId = instance.instanceId;\n if (__DEV__) {\n try {\n backgroundElementTemplateInstanceManager.updateId(instance.instanceId, handleId);\n // Ref proxies created before hydrate keep the old background id; resolve it\n // lazily so user-held proxies continue selecting the hydrated native node.\n hydrationMap.set(oldHandleId, handleId);\n instance.markMaterializedByHydration();\n return true;\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n lynx.reportError(\n new Error(`ElementTemplate hydrate received invalid uid ${handleId} for '${templateKey}': ${reason}`),\n );\n return false;\n }\n }\n\n backgroundElementTemplateInstanceManager.updateId(instance.instanceId, handleId);\n hydrationMap.set(oldHandleId, handleId);\n instance.markMaterializedByHydration();\n return true;\n}\n\nfunction hydrateAttributeSlots(\n templateType: string,\n handleId: number,\n beforeSlots: SerializableValue[],\n afterSlots: SerializableValue[],\n): void {\n const slotCount = Math.max(beforeSlots.length, afterSlots.length);\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n for (let slotIndex = 0; slotIndex < slotCount; slotIndex += 1) {\n // Native serialization and background preparation may represent an absent slot differently.\n const beforeValue = beforeSlots[slotIndex] ?? null;\n const afterValue = afterSlots[slotIndex] ?? null;\n if (\n !shouldForceMainThreadHydrateSlot(slotKinds?.get(slotIndex), afterValue)\n && isDirectOrDeepEqual(beforeValue, afterValue)\n ) {\n continue;\n }\n globalCommitContext.ops.push(\n getAttributeSlotUpdateOp(templateType, slotIndex),\n handleId,\n slotIndex,\n afterValue,\n );\n }\n}\n\nfunction shouldForceMainThreadHydrateSlot(\n slotKind: MainThreadDynamicAttrKind | undefined,\n value: SerializableValue | undefined,\n): boolean {\n if (slotKind === 'gesture') {\n return value != null;\n }\n if (slotKind === 'mt-event') {\n return isMTEventNativeWrapper(value);\n }\n if (slotKind === 'spread') {\n if (!isSpreadRecord(value)) {\n return false;\n }\n for (const key of Object.keys(value)) {\n if (key === 'main-thread:ref') {\n return true;\n }\n const entry = value[key];\n if (key === 'main-thread:gesture' && isGestureSlotValue(entry)) {\n return true;\n }\n if (isMainThreadEventPropKey(key) && isMTEventNativeWrapper(entry)) {\n return true;\n }\n }\n return false;\n }\n return slotKind === 'mt-ref'\n && (value == null || isMainThreadFunction((value as unknown as MTRefNativeWrapper).value));\n}\n"]}
@@ -2,22 +2,21 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { globalCommitContext, resetGlobalCommitContext, takeRemovedSubtreesForPostDispatchTeardown, } from './commit-context.js';
5
+ import { dropDelayedRunOnMainThreadReturnIds, packElementTemplateCommitUpdateEvent } from './commit-event.js';
5
6
  import { markElementTemplateHydrated, resetElementTemplateCommitState, scheduleElementTemplateRemovedSubtreeCleanup, } from './commit-hook.js';
7
+ import { resetElementTemplateMainThreadFunctionRuntime } from './main-thread-function.js';
6
8
  import { hydratePageRootIntoContext } from './page-root-hydrate.js';
7
9
  import { takeMainThreadRefInitValuePatch } from '../../core/main-thread-ref-init-value.js';
8
10
  import { PerformanceTimingFlags, PipelineOrigins, beginPipeline, globalPipelineOptions, markTiming, setPipeline, } from '../../core/performance.js';
9
11
  import { getReloadVersion } from '../../core/reload-version.js';
10
12
  import { delayedRunOnMainThreadData, takeDelayedRunOnMainThreadData, } from '../../core/thread-function-call/main-thread.js';
11
- import { dropFunctionCallReturnIds } from '../../core/thread-function-call/return-value.js';
12
- import { formatElementTemplateUpdateCommands, printElementTemplateTreeToString } from '../debug/alog.js';
13
+ import { printElementTemplateTreeToString } from '../debug/alog.js';
13
14
  import { profileEnd, profileStart } from '../debug/profile.js';
14
15
  import { sendMTRefInitValueToMainThread } from '../main-thread-ref-init-value.js';
15
16
  import { clearPendingEvents, flushPendingEvents } from '../prop-adapters/event.js';
16
17
  import { clearDelayedRefUiOps, clearPendingRefs, flushDelayedRefUiOps } from '../prop-adapters/ref.js';
17
18
  import { ElementTemplateLifecycleConstant } from '../protocol/lifecycle-constant.js';
18
- import { createElementTemplateUpdateEvent } from '../protocol/update-event.js';
19
19
  import { __root } from '../runtime/page/root-instance.js';
20
- import { resetElementTemplateMainThreadFunctionRuntime } from '../runtime/template/main-thread-function.js';
21
20
  let listener;
22
21
  export function installElementTemplateHydrationListener() {
23
22
  resetElementTemplateHydrationListener();
@@ -85,29 +84,10 @@ export function installElementTemplateHydrationListener() {
85
84
  markTiming('packChangesStart');
86
85
  try {
87
86
  sendMTRefInitValueToMainThread();
88
- if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
89
- console.alog?.('[ReactLynxDebug] ElementTemplate hydrate update commands:\n'
90
- + JSON.stringify({
91
- ops: formatElementTemplateUpdateCommands(globalCommitContext.ops),
92
- flushOptions: globalCommitContext.flushOptions,
93
- flowIds: globalCommitContext.flowIds,
94
- isHydration: true,
95
- delayedRunOnMainThreadDataCount: delayedRunOnMainThreadPayload?.length,
96
- }, null, 2));
97
- }
98
- hydrateUpdateEvent = createElementTemplateUpdateEvent({
99
- ops: globalCommitContext.ops,
100
- flushOptions: globalCommitContext.flushOptions,
101
- isHydration: true,
102
- reloadVersion: getReloadVersion(),
103
- flowIds: globalCommitContext.flowIds,
104
- delayedRunOnMainThreadData: delayedRunOnMainThreadPayload,
105
- });
87
+ hydrateUpdateEvent = packElementTemplateCommitUpdateEvent(delayedRunOnMainThreadPayload, true);
106
88
  }
107
89
  catch (error) {
108
- if (delayedRunOnMainThreadPayload) {
109
- dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));
110
- }
90
+ dropDelayedRunOnMainThreadReturnIds(delayedRunOnMainThreadPayload);
111
91
  // Do not expose refs or replay delayed selector ops if the hydrate
112
92
  // patch failed to serialize; selectors may still point at stale
113
93
  // pre-hydration ids in that case.
@@ -1 +1 @@
1
- {"version":3,"file":"hydration-listener.js","sourceRoot":"","sources":["../../../src/element-template/background/hydration-listener.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,0CAA0C,GAC3C,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,4CAA4C,GAC7C,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAC;AAC3F,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,qBAAqB,EACrB,UAAU,EACV,WAAW,GACZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EACL,0BAA0B,EAC1B,8BAA8B,GAC/B,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,mCAAmC,EAAE,gCAAgC,EAAE,MAA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AgE;oBAChE,kCAAkC;oBAClC,kBAAkB,EAAE,CAAC;oBACrB,gBAAgB,EAAE,CAAC;oBACnB,oBAAoB,EAAE,CAAC;oBACvB,IAAI,CAAC,WAAW,CAAC,KAAc,CAAC,CAAC;gBACnC,CAAC;gBACD,UAAU,CAAC,gBAAgB,CAAC,CAAC;gBAC7B,IAAI,eAAe,EAAE,CAAC;oBACpB,WAAW,CAAC,SAAS,CAAC,CAAC;gBACzB,CAAC;gBACD,IAAI,WAAW,EAAE,CAAC;oBAChB,UAAU,EAAE,CAAC;gBACf,CAAC;gBACD,wBAAwB,EAAE,CAAC;gBAC3B,4CAA4C,CAAC,+BAA+B,CAAC,CAAC;gBAE9E,IAAI,CAAC,kBAAkB,EAAE,CAAC;oBACxB,OAAO;gBACT,CAAC;gBAED,IAAI,CAAC,cAAc,EAAE,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;gBACxD,kBAAkB,EAAE,CAAC;gBACrB,4EAA4E;gBAC5E,6EAA6E;gBAC7E,oBAAoB,EAAE,CAAC;YACzB,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,WAAW,CAAC,SAAS,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,CAAC;IAEF,IAAI,CAAC,cAAc,EAAE,CAAC,gBAAgB,CAAC,gCAAgC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,qCAAqC;IACnD,IAAI,QAAQ,EAAE,CAAC;QACb,IAAI,CAAC,cAAc,EAAE,CAAC,mBAAmB,CAAC,gCAAgC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAChG,CAAC;IACD,QAAQ,GAAG,SAAS,CAAC;AACvB,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport {\n globalCommitContext,\n resetGlobalCommitContext,\n takeRemovedSubtreesForPostDispatchTeardown,\n} from './commit-context.js';\nimport {\n markElementTemplateHydrated,\n resetElementTemplateCommitState,\n scheduleElementTemplateRemovedSubtreeCleanup,\n} from './commit-hook.js';\nimport type { BackgroundPageRootInstance } from './instance.js';\nimport { hydratePageRootIntoContext } from './page-root-hydrate.js';\nimport { takeMainThreadRefInitValuePatch } from '../../core/main-thread-ref-init-value.js';\nimport {\n PerformanceTimingFlags,\n PipelineOrigins,\n beginPipeline,\n globalPipelineOptions,\n markTiming,\n setPipeline,\n} from '../../core/performance.js';\nimport { getReloadVersion } from '../../core/reload-version.js';\nimport {\n delayedRunOnMainThreadData,\n takeDelayedRunOnMainThreadData,\n} from '../../core/thread-function-call/main-thread.js';\nimport { dropFunctionCallReturnIds } from '../../core/thread-function-call/return-value.js';\nimport { formatElementTemplateUpdateCommands, printElementTemplateTreeToString } from '../debug/alog.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { sendMTRefInitValueToMainThread } from '../main-thread-ref-init-value.js';\nimport { clearPendingEvents, flushPendingEvents } from '../prop-adapters/event.js';\nimport { clearDelayedRefUiOps, clearPendingRefs, flushDelayedRefUiOps } from '../prop-adapters/ref.js';\nimport { ElementTemplateLifecycleConstant } from '../protocol/lifecycle-constant.js';\nimport type { ElementTemplateHydrateCommitContext } from '../protocol/types.js';\nimport { createElementTemplateUpdateEvent } from '../protocol/update-event.js';\nimport { __root } from '../runtime/page/root-instance.js';\nimport { resetElementTemplateMainThreadFunctionRuntime } from '../runtime/template/main-thread-function.js';\n\nlet listener:\n | ((event: { data: ElementTemplateHydrateCommitContext }) => void)\n | undefined;\n\nexport function installElementTemplateHydrationListener(): void {\n resetElementTemplateHydrationListener();\n resetElementTemplateCommitState();\n\n listener = (event: { data: ElementTemplateHydrateCommitContext }) => {\n const { page, reloadVersion } = event.data;\n if (reloadVersion < getReloadVersion()) {\n return;\n }\n\n const root = __root as BackgroundPageRootInstance;\n\n if (__PROFILE__) {\n profileStart('ReactLynx::hydrate');\n }\n beginPipeline(true, PipelineOrigins.reactLynxHydrate, PerformanceTimingFlags.reactLynxHydrate);\n try {\n markTiming('hydrateParseSnapshotStart');\n markTiming('hydrateParseSnapshotEnd');\n markTiming('diffVdomStart');\n\n resetGlobalCommitContext();\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] ElementTemplate MTS -> BTS hydrate:\\n'\n + JSON.stringify({ data: page }, null, 2),\n );\n console.alog?.(\n '[ReactLynxDebug] BackgroundElementTemplate tree before hydration:\\n'\n + printElementTemplateTreeToString(root),\n );\n }\n\n const didHydrateMatchedInstances = hydratePageRootIntoContext(page, root);\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] BackgroundElementTemplate tree after hydration:\\n'\n + printElementTemplateTreeToString(root),\n );\n }\n\n if (__PROFILE__) {\n profileEnd();\n }\n markTiming('diffVdomEnd');\n\n if (didHydrateMatchedInstances) {\n markElementTemplateHydrated();\n } else {\n // Hydrate is not transactional; a later failure can happen after earlier\n // nodes were rebound. Treat the pass as failed for externally observable\n // work, so delayed refs/events are not released from an incomplete tree.\n clearPendingEvents();\n clearPendingRefs();\n clearDelayedRefUiOps();\n resetElementTemplateMainThreadFunctionRuntime();\n takeMainThreadRefInitValuePatch();\n resetGlobalCommitContext();\n }\n\n if (didHydrateMatchedInstances) {\n const hasDelayedRunOnMainThread = delayedRunOnMainThreadData.length > 0;\n const delayedRunOnMainThreadPayload = hasDelayedRunOnMainThread\n ? takeDelayedRunOnMainThreadData()\n : undefined;\n const pipelineOptions = globalPipelineOptions;\n if (pipelineOptions) {\n globalCommitContext.flushOptions.pipelineOptions = pipelineOptions;\n }\n const removedSubtreesAwaitingTeardown = globalCommitContext.ops.length > 0\n ? takeRemovedSubtreesForPostDispatchTeardown()\n : [];\n let hydrateUpdateEvent: ReturnType<typeof createElementTemplateUpdateEvent> | undefined;\n if (__PROFILE__) {\n profileStart('ReactLynx::commitChanges');\n }\n markTiming('packChangesStart');\n try {\n sendMTRefInitValueToMainThread();\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] ElementTemplate hydrate update commands:\\n'\n + JSON.stringify(\n {\n ops: formatElementTemplateUpdateCommands(globalCommitContext.ops),\n flushOptions: globalCommitContext.flushOptions,\n flowIds: globalCommitContext.flowIds,\n isHydration: true,\n delayedRunOnMainThreadDataCount: delayedRunOnMainThreadPayload?.length,\n },\n null,\n 2,\n ),\n );\n }\n hydrateUpdateEvent = createElementTemplateUpdateEvent({\n ops: globalCommitContext.ops,\n flushOptions: globalCommitContext.flushOptions,\n isHydration: true,\n reloadVersion: getReloadVersion(),\n flowIds: globalCommitContext.flowIds,\n delayedRunOnMainThreadData: delayedRunOnMainThreadPayload,\n });\n } catch (error) {\n if (delayedRunOnMainThreadPayload) {\n dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));\n }\n // Do not expose refs or replay delayed selector ops if the hydrate\n // patch failed to serialize; selectors may still point at stale\n // pre-hydration ids in that case.\n clearPendingEvents();\n clearPendingRefs();\n clearDelayedRefUiOps();\n lynx.reportError(error as Error);\n }\n markTiming('packChangesEnd');\n if (pipelineOptions) {\n setPipeline(undefined);\n }\n if (__PROFILE__) {\n profileEnd();\n }\n resetGlobalCommitContext();\n scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);\n\n if (!hydrateUpdateEvent) {\n return;\n }\n\n lynx.getCoreContext().dispatchEvent(hydrateUpdateEvent);\n flushPendingEvents();\n // Ordinary refs attach on Preact commit boundaries; hydration only releases\n // delayed selector ops after ids have been rebound to stable native handles.\n flushDelayedRefUiOps();\n }\n } finally {\n setPipeline(undefined);\n }\n };\n\n lynx.getCoreContext().addEventListener(ElementTemplateLifecycleConstant.hydrate, listener);\n}\n\nexport function resetElementTemplateHydrationListener(): void {\n if (listener) {\n lynx.getCoreContext().removeEventListener(ElementTemplateLifecycleConstant.hydrate, listener);\n }\n listener = undefined;\n}\n"]}
1
+ {"version":3,"file":"hydration-listener.js","sourceRoot":"","sources":["../../../src/element-template/background/hydration-listener.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,0CAA0C,GAC3C,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mCAAmC,EAAE,oCAAoC,EAAE,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,4CAA4C,GAC7C,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,6CAA6C,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAC;AAC3F,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,qBAAqB,EACrB,UAAU,EACV,WAAW,GACZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EACL,0BAA0B,EAC1B,8BAA8B,GAC/B,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACvG,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AAGrF,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAE1D,IAAI,QAES,CAAC;AAEd,MAAM,UAAU,uCAAu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ClC,kBAAkB,EAAE,CAAC;oBACrB,gBAAgB,EAAE,CAAC;oBACnB,oBAAoB,EAAE,CAAC;oBACvB,IAAI,CAAC,WAAW,CAAC,KAAc,CAAC,CAAC;gBACnC,CAAC;gBACD,UAAU,CAAC,gBAAgB,CAAC,CAAC;gBAC7B,IAAI,eAAe,EAAE,CAAC;oBACpB,WAAW,CAAC,SAAS,CAAC,CAAC;gBACzB,CAAC;gBACD,IAAI,WAAW,EAAE,CAAC;oBAChB,UAAU,EAAE,CAAC;gBACf,CAAC;gBACD,wBAAwB,EAAE,CAAC;gBAC3B,4CAA4C,CAAC,+BAA+B,CAAC,CAAC;gBAE9E,IAAI,CAAC,kBAAkB,EAAE,CAAC;oBACxB,OAAO;gBACT,CAAC;gBAED,IAAI,CAAC,cAAc,EAAE,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;gBACxD,kBAAkB,EAAE,CAAC;gBACrB,4EAA4E;gBAC5E,6EAA6E;gBAC7E,oBAAoB,EAAE,CAAC;YACzB,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,WAAW,CAAC,SAAS,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,CAAC;IAEF,IAAI,CAAC,cAAc,EAAE,CAAC,gBAAgB,CAAC,gCAAgC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,qCAAqC;IACnD,IAAI,QAAQ,EAAE,CAAC;QACb,IAAI,CAAC,cAAc,EAAE,CAAC,mBAAmB,CAAC,gCAAgC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAChG,CAAC;IACD,QAAQ,GAAG,SAAS,CAAC;AACvB,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport {\n globalCommitContext,\n resetGlobalCommitContext,\n takeRemovedSubtreesForPostDispatchTeardown,\n} from './commit-context.js';\nimport { dropDelayedRunOnMainThreadReturnIds, packElementTemplateCommitUpdateEvent } from './commit-event.js';\nimport {\n markElementTemplateHydrated,\n resetElementTemplateCommitState,\n scheduleElementTemplateRemovedSubtreeCleanup,\n} from './commit-hook.js';\nimport type { BackgroundPageRootInstance } from './instance.js';\nimport { resetElementTemplateMainThreadFunctionRuntime } from './main-thread-function.js';\nimport { hydratePageRootIntoContext } from './page-root-hydrate.js';\nimport { takeMainThreadRefInitValuePatch } from '../../core/main-thread-ref-init-value.js';\nimport {\n PerformanceTimingFlags,\n PipelineOrigins,\n beginPipeline,\n globalPipelineOptions,\n markTiming,\n setPipeline,\n} from '../../core/performance.js';\nimport { getReloadVersion } from '../../core/reload-version.js';\nimport {\n delayedRunOnMainThreadData,\n takeDelayedRunOnMainThreadData,\n} from '../../core/thread-function-call/main-thread.js';\nimport { printElementTemplateTreeToString } from '../debug/alog.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { sendMTRefInitValueToMainThread } from '../main-thread-ref-init-value.js';\nimport { clearPendingEvents, flushPendingEvents } from '../prop-adapters/event.js';\nimport { clearDelayedRefUiOps, clearPendingRefs, flushDelayedRefUiOps } from '../prop-adapters/ref.js';\nimport { ElementTemplateLifecycleConstant } from '../protocol/lifecycle-constant.js';\nimport type { ElementTemplateHydrateCommitContext } from '../protocol/types.js';\nimport type { ElementTemplateUpdateEvent } from '../protocol/update-event.js';\nimport { __root } from '../runtime/page/root-instance.js';\n\nlet listener:\n | ((event: { data: ElementTemplateHydrateCommitContext }) => void)\n | undefined;\n\nexport function installElementTemplateHydrationListener(): void {\n resetElementTemplateHydrationListener();\n resetElementTemplateCommitState();\n\n listener = (event: { data: ElementTemplateHydrateCommitContext }) => {\n const { page, reloadVersion } = event.data;\n if (reloadVersion < getReloadVersion()) {\n return;\n }\n\n const root = __root as BackgroundPageRootInstance;\n\n if (__PROFILE__) {\n profileStart('ReactLynx::hydrate');\n }\n beginPipeline(true, PipelineOrigins.reactLynxHydrate, PerformanceTimingFlags.reactLynxHydrate);\n try {\n markTiming('hydrateParseSnapshotStart');\n markTiming('hydrateParseSnapshotEnd');\n markTiming('diffVdomStart');\n\n resetGlobalCommitContext();\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] ElementTemplate MTS -> BTS hydrate:\\n'\n + JSON.stringify({ data: page }, null, 2),\n );\n console.alog?.(\n '[ReactLynxDebug] BackgroundElementTemplate tree before hydration:\\n'\n + printElementTemplateTreeToString(root),\n );\n }\n\n const didHydrateMatchedInstances = hydratePageRootIntoContext(page, root);\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] BackgroundElementTemplate tree after hydration:\\n'\n + printElementTemplateTreeToString(root),\n );\n }\n\n if (__PROFILE__) {\n profileEnd();\n }\n markTiming('diffVdomEnd');\n\n if (didHydrateMatchedInstances) {\n markElementTemplateHydrated();\n } else {\n // Hydrate is not transactional; a later failure can happen after earlier\n // nodes were rebound. Treat the pass as failed for externally observable\n // work, so delayed refs/events are not released from an incomplete tree.\n clearPendingEvents();\n clearPendingRefs();\n clearDelayedRefUiOps();\n resetElementTemplateMainThreadFunctionRuntime();\n takeMainThreadRefInitValuePatch();\n resetGlobalCommitContext();\n }\n\n if (didHydrateMatchedInstances) {\n const hasDelayedRunOnMainThread = delayedRunOnMainThreadData.length > 0;\n const delayedRunOnMainThreadPayload = hasDelayedRunOnMainThread\n ? takeDelayedRunOnMainThreadData()\n : undefined;\n const pipelineOptions = globalPipelineOptions;\n if (pipelineOptions) {\n globalCommitContext.flushOptions.pipelineOptions = pipelineOptions;\n }\n const removedSubtreesAwaitingTeardown = globalCommitContext.ops.length > 0\n ? takeRemovedSubtreesForPostDispatchTeardown()\n : [];\n let hydrateUpdateEvent: ElementTemplateUpdateEvent | undefined;\n if (__PROFILE__) {\n profileStart('ReactLynx::commitChanges');\n }\n markTiming('packChangesStart');\n try {\n sendMTRefInitValueToMainThread();\n hydrateUpdateEvent = packElementTemplateCommitUpdateEvent(delayedRunOnMainThreadPayload, true);\n } catch (error) {\n dropDelayedRunOnMainThreadReturnIds(delayedRunOnMainThreadPayload);\n // Do not expose refs or replay delayed selector ops if the hydrate\n // patch failed to serialize; selectors may still point at stale\n // pre-hydration ids in that case.\n clearPendingEvents();\n clearPendingRefs();\n clearDelayedRefUiOps();\n lynx.reportError(error as Error);\n }\n markTiming('packChangesEnd');\n if (pipelineOptions) {\n setPipeline(undefined);\n }\n if (__PROFILE__) {\n profileEnd();\n }\n resetGlobalCommitContext();\n scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);\n\n if (!hydrateUpdateEvent) {\n return;\n }\n\n lynx.getCoreContext().dispatchEvent(hydrateUpdateEvent);\n flushPendingEvents();\n // Ordinary refs attach on Preact commit boundaries; hydration only releases\n // delayed selector ops after ids have been rebound to stable native handles.\n flushDelayedRefUiOps();\n }\n } finally {\n setPipeline(undefined);\n }\n };\n\n lynx.getCoreContext().addEventListener(ElementTemplateLifecycleConstant.hydrate, listener);\n}\n\nexport function resetElementTemplateHydrationListener(): void {\n if (listener) {\n lynx.getCoreContext().removeEventListener(ElementTemplateLifecycleConstant.hydrate, listener);\n }\n listener = undefined;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { ElementTemplateHandleSlotsCommand, RuntimeOptionsCommand, SerializableValue, TypedElementAttributesCommand, TypedListOptionsCommand, UpdateTypedListItemCommand } from '../protocol/types.js';
1
+ import type { ElementTemplateHandleSlotsCommand, RuntimeOptionsCommand, SerializableValue, TypedElementAttributesCommand, UpdateTypedListItemCommand } from '../protocol/types.js';
2
2
  import type { AuthoredPageAttributes } from '../runtime/page/authored-page.js';
3
3
  import type { EtAttrPlan } from '../runtime/template/attr-slot-plan.js';
4
4
  export declare const BUILTIN_RAW_TEXT_TEMPLATE_KEY = "_et_builtin_raw_text";
@@ -32,7 +32,7 @@ export declare class BackgroundElementTemplateInstance {
32
32
  protected canEmitUpdatePatch(): boolean;
33
33
  protected cleanupDetachedChildForLifetimeRemoval(child: BackgroundElementTemplateInstance, canEmitUpdatePatch: boolean): void;
34
34
  appendChild(child: BackgroundElementTemplateInstance): void;
35
- insertBefore(child: BackgroundElementTemplateInstance, beforeChild: BackgroundElementTemplateInstance | null, silent?: boolean): void;
35
+ insertBefore(child: BackgroundElementTemplateInstance, beforeChild: BackgroundElementTemplateInstance | null): void;
36
36
  removeChild(child: BackgroundElementTemplateInstance, silent?: boolean): void;
37
37
  tearDown(): void;
38
38
  queueRefCleanupForSubtree(): void;
@@ -68,14 +68,11 @@ export declare class BackgroundPageRootInstance extends BackgroundTypedElementTe
68
68
  }
69
69
  export declare class BackgroundListElementTemplateInstance extends BackgroundTypedElementTemplateInstance {
70
70
  constructor();
71
- protected getRuntimeOptionsForCreate(): TypedListOptionsCommand;
72
- insertBefore(child: BackgroundElementTemplateInstance, beforeChild: BackgroundElementTemplateInstance | null, silent?: boolean): void;
73
- removeChild(child: BackgroundElementTemplateInstance, silent?: boolean): void;
74
- notifyLogicalChildUpdated(child: BackgroundElementTemplateInstance): void;
75
- private emitTypedListItemInsert;
76
- private emitTypedListItemRemove;
77
- private emitTypedListItemUpdate;
71
+ emitCreate(): void;
72
+ protected getAttributeSlotPlan(): EtAttrPlan;
73
+ protected getChildSlotsForCreate(): ElementTemplateHandleSlotsCommand;
74
+ emitTypedListItemUpdate(child: BackgroundElementTemplateInstance, isUpdatePlatformInfo: boolean): void;
78
75
  }
79
- export declare function toUpdateTypedListItemCommand(child: BackgroundElementTemplateInstance): UpdateTypedListItemCommand;
76
+ export declare function toUpdateTypedListItemCommand(child: BackgroundElementTemplateInstance, isUpdatePlatformInfo: boolean): UpdateTypedListItemCommand;
80
77
  export declare function collectElementTemplateSubtreeHandleIds(root: BackgroundElementTemplateInstance): number[];
81
78
  export declare function collectMainThreadRefSubtreeHandleIds(root: BackgroundElementTemplateInstance): number[] | null;
@@ -5,12 +5,13 @@ import { getAttributeSlotUpdateOp, prepareAttributeSlots as prepareRawAttributeS
5
5
  import { globalCommitContext, markRemovedSubtreeForPostDispatchTeardown } from './commit-context.js';
6
6
  import { isElementTemplateHydrated } from './commit-hook.js';
7
7
  import { backgroundElementTemplateInstanceManager } from './manager.js';
8
- import { isDirectOrDeepEqual } from '../../utils.js';
8
+ import { isDirectOrDeepEqual } from '../../core/deep-equal.js';
9
9
  import { ElementTemplateUpdateOps } from '../protocol/opcodes.js';
10
10
  import { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_TYPE } from '../protocol/page.js';
11
11
  import { parseElementTemplateType } from '../protocol/template-type.js';
12
+ import { filterListItemPlatformInfoFromSpread } from '../runtime/list/platform-info.js';
12
13
  import { hasMainThreadRefAttrSlot } from '../runtime/template/attr-slot-plan.js';
13
- import { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, TYPED_ELEMENT_ATTR_PLAN } from '../runtime/template/typed-attributes.js';
14
+ import { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, TYPED_ELEMENT_ATTR_PLAN, TYPED_LIST_ATTR_PLAN, } from '../runtime/template/typed-attributes.js';
14
15
  function pushOp(...items) {
15
16
  globalCommitContext.ops.push(...items);
16
17
  }
@@ -104,7 +105,11 @@ export class BackgroundElementTemplateInstance {
104
105
  child = child.nextSibling;
105
106
  }
106
107
  const nativeTemplate = parseElementTemplateType(this.type);
107
- pushOp(ElementTemplateUpdateOps.createTemplate, this.instanceId, nativeTemplate.templateKey, nativeTemplate.bundleUrl, this.attributeSlots, serializedSlots);
108
+ // Pass List item platform info to native with the create command for
109
+ // serialization and List diffing.
110
+ pushOp(ElementTemplateUpdateOps.createTemplate, this.instanceId, nativeTemplate.templateKey, nativeTemplate.bundleUrl, this.attributeSlots, serializedSlots, this.listItemPlatformInfo === undefined
111
+ ? null
112
+ : { __listItemPlatformInfo: this.listItemPlatformInfo });
108
113
  this.isMaterializedOnMainThread = true;
109
114
  }
110
115
  needsMainThreadCreate() {
@@ -201,7 +206,7 @@ export class BackgroundElementTemplateInstance {
201
206
  appendChild(child) {
202
207
  this.insertBefore(child, null);
203
208
  }
204
- insertBefore(child, beforeChild, silent) {
209
+ insertBefore(child, beforeChild) {
205
210
  if (beforeChild === child) {
206
211
  throw new Error('Cannot insert a node before itself');
207
212
  }
@@ -210,7 +215,13 @@ export class BackgroundElementTemplateInstance {
210
215
  }
211
216
  const previousParent = child.parent;
212
217
  if (previousParent) {
218
+ const shouldRecordOldListRemove = previousParent !== this
219
+ && previousParent instanceof BackgroundListElementTemplateInstance
220
+ && previousParent.canEmitUpdatePatch();
213
221
  previousParent.removeChild(child, true);
222
+ if (shouldRecordOldListRemove) {
223
+ pushOp(ElementTemplateUpdateOps.removeNode, previousParent.instanceId, 0, child.instanceId, EMPTY_REMOVED_SUBTREE_HANDLE_IDS);
224
+ }
214
225
  }
215
226
  child.parent = this;
216
227
  if (beforeChild) {
@@ -235,7 +246,7 @@ export class BackgroundElementTemplateInstance {
235
246
  this.lastChild = child;
236
247
  child.nextSibling = null;
237
248
  }
238
- if (silent || !this.canEmitUpdatePatch()) {
249
+ if (!this.canEmitUpdatePatch()) {
239
250
  return;
240
251
  }
241
252
  const beforeId = (beforeChild && beforeChild.__slotIndex === child.__slotIndex) ? beforeChild.instanceId : 0;
@@ -246,7 +257,7 @@ export class BackgroundElementTemplateInstance {
246
257
  if (movedMainThreadRefHandleIds !== null
247
258
  && containingListItem
248
259
  && previousParent !== this) {
249
- notifyListItemSubtreeUpdated(containingListItem);
260
+ notifyListItemSubtreeUpdated(containingListItem, false);
250
261
  }
251
262
  }
252
263
  removeChild(child, silent) {
@@ -281,7 +292,7 @@ export class BackgroundElementTemplateInstance {
281
292
  if (canEmitUpdatePatch
282
293
  && containingListItem
283
294
  && collectMainThreadRefSubtreeHandleIds(child) !== null) {
284
- notifyListItemSubtreeUpdated(containingListItem);
295
+ notifyListItemSubtreeUpdated(containingListItem, false);
285
296
  }
286
297
  }
287
298
  tearDown() {
@@ -352,10 +363,12 @@ export class BackgroundElementTemplateInstance {
352
363
  }
353
364
  else if (key === '__listItemPlatformInfo') {
354
365
  const previous = this.getListItemPlatformInfo();
355
- const next = value;
356
- this.listItemPlatformInfo = next;
366
+ this.listItemPlatformInfo = value == null
367
+ ? undefined
368
+ : filterListItemPlatformInfoFromSpread(value);
369
+ const next = this.getListItemPlatformInfo();
357
370
  if (!isDirectOrDeepEqual(previous, next)) {
358
- notifyListItemSubtreeUpdated(this);
371
+ notifyListItemSubtreeUpdated(this, true);
359
372
  }
360
373
  }
361
374
  else if (key === 'attributeSlots' && Array.isArray(value)) {
@@ -430,9 +443,9 @@ export function getContainingListItem(instance) {
430
443
  }
431
444
  return undefined;
432
445
  }
433
- function notifyListItemSubtreeUpdated(listItem) {
446
+ function notifyListItemSubtreeUpdated(listItem, isUpdatePlatformInfo) {
434
447
  if (listItem.parent instanceof BackgroundListElementTemplateInstance) {
435
- listItem.parent.notifyLogicalChildUpdated(listItem);
448
+ listItem.parent.emitTypedListItemUpdate(listItem, isUpdatePlatformInfo);
436
449
  }
437
450
  }
438
451
  export class BackgroundTypedElementTemplateInstance extends BackgroundElementTemplateInstance {
@@ -503,67 +516,56 @@ export class BackgroundListElementTemplateInstance extends BackgroundTypedElemen
503
516
  constructor() {
504
517
  super('list');
505
518
  }
506
- getRuntimeOptionsForCreate() {
507
- const listChildren = [];
508
- let child = this.firstChild;
509
- while (child) {
510
- listChildren.push(toUpdateTypedListItemCommand(child));
511
- child = child.nextSibling;
519
+ emitCreate() {
520
+ // Skip creation and candidate initialization for an existing List.
521
+ if (this.isMaterializedOnMainThread) {
522
+ return;
512
523
  }
513
- return {
514
- listChildren,
515
- };
516
- }
517
- insertBefore(child, beforeChild, silent) {
518
- const previousParent = child.parent;
519
- super.insertBefore(child, beforeChild, true);
520
- if (!silent) {
521
- if (previousParent instanceof BackgroundListElementTemplateInstance) {
522
- previousParent.emitTypedListItemRemove(child, EMPTY_REMOVED_SUBTREE_HANDLE_IDS);
523
- }
524
- this.emitTypedListItemInsert(child, beforeChild);
524
+ // The base class emits the List create command with the initial item UIDs
525
+ // in childSlots.
526
+ super.emitCreate();
527
+ // Queue initial ref candidates after the List create command has been
528
+ // emitted.
529
+ if (!this.isMaterializedOnMainThread) {
530
+ return;
525
531
  }
526
- }
527
- removeChild(child, silent) {
528
- super.removeChild(child, true);
529
- if (!silent) {
530
- const canEmitUpdatePatch = this.canEmitUpdatePatch();
531
- const removedSubtreeHandleIds = canEmitUpdatePatch
532
- ? collectElementTemplateSubtreeHandleIds(child)
533
- : EMPTY_REMOVED_SUBTREE_HANDLE_IDS;
534
- this.cleanupDetachedChildForLifetimeRemoval(child, canEmitUpdatePatch);
535
- this.emitTypedListItemRemove(child, removedSubtreeHandleIds);
532
+ let item = this.firstChild;
533
+ while (item) {
534
+ // Collect main-thread ref candidates separately for each direct item.
535
+ // Passing false sends only ref candidates and leaves platformInfo null.
536
+ pushOp(ElementTemplateUpdateOps.updateTypedListItem, this.instanceId, toUpdateTypedListItemCommand(item, false));
537
+ item = item.nextSibling;
536
538
  }
537
539
  }
538
- notifyLogicalChildUpdated(child) {
539
- this.emitTypedListItemUpdate(child);
540
- }
541
- emitTypedListItemInsert(child, beforeChild) {
542
- if (!isElementTemplateHydrated() || !this.isMaterializedOnMainThread) {
543
- return;
544
- }
545
- child.emitMainThreadCreateIfNeeded();
546
- pushOp(ElementTemplateUpdateOps.insertTypedListItem, this.instanceId, toUpdateTypedListItemCommand(child), beforeChild?.instanceId ?? 0);
540
+ getAttributeSlotPlan() {
541
+ return TYPED_LIST_ATTR_PLAN;
547
542
  }
548
- emitTypedListItemRemove(child, removedSubtreeHandleIds) {
549
- if (!isElementTemplateHydrated() || !this.isMaterializedOnMainThread) {
550
- return;
543
+ getChildSlotsForCreate() {
544
+ const childSlots = [];
545
+ let child = this.firstChild;
546
+ while (child) {
547
+ // Group child UIDs by their logical slot.
548
+ // Direct List children belong to slot 0, which MTS validates.
549
+ (childSlots[child.__slotIndex] ??= []).push(child.instanceId);
550
+ child = child.nextSibling;
551
551
  }
552
- pushOp(ElementTemplateUpdateOps.removeTypedListItem, this.instanceId, child.instanceId, removedSubtreeHandleIds);
552
+ return childSlots;
553
553
  }
554
- emitTypedListItemUpdate(child) {
554
+ emitTypedListItemUpdate(child, isUpdatePlatformInfo) {
555
555
  if (!isElementTemplateHydrated() || !this.isMaterializedOnMainThread) {
556
556
  return;
557
557
  }
558
- pushOp(ElementTemplateUpdateOps.updateTypedListItem, this.instanceId, toUpdateTypedListItemCommand(child));
558
+ pushOp(ElementTemplateUpdateOps.updateTypedListItem, this.instanceId, toUpdateTypedListItemCommand(child, isUpdatePlatformInfo));
559
559
  }
560
560
  }
561
- export function toUpdateTypedListItemCommand(child) {
561
+ export function toUpdateTypedListItemCommand(child, isUpdatePlatformInfo) {
562
562
  return {
563
563
  __etHandleRef: child.instanceId,
564
564
  type: child.type,
565
- platformInfo: child.getListItemPlatformInfo(),
566
- subtreeHandleIds: collectMainThreadRefSubtreeHandleIds(child) ?? [],
565
+ platformInfo: isUpdatePlatformInfo ? child.getListItemPlatformInfo() : null,
566
+ subtreeHandleIds: isUpdatePlatformInfo
567
+ ? null
568
+ : collectMainThreadRefSubtreeHandleIds(child) ?? [],
567
569
  };
568
570
  }
569
571
  export function collectElementTemplateSubtreeHandleIds(root) {
@@ -579,6 +581,11 @@ function collectMainThreadRefSubtreeHandleIdsImpl(instance, handles) {
579
581
  handles ??= [];
580
582
  handles.push(instance.instanceId);
581
583
  }
584
+ // The List's own ref is collected above. Item refs follow their own
585
+ // materialization and binding lifecycle.
586
+ if (instance instanceof BackgroundListElementTemplateInstance) {
587
+ return handles;
588
+ }
582
589
  let child = instance.firstChild;
583
590
  while (child) {
584
591
  handles = collectMainThreadRefSubtreeHandleIdsImpl(child, handles);