@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
@@ -0,0 +1,486 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { createElement, options, render } from 'preact';
5
+ import { addReloadScopedEventListener } from '../core/reload-scoped-event.js';
6
+ import { getReloadVersion } from '../core/reload-version.js';
7
+ import { prepareMainThreadFunctionCtx } from '../core/thread-function-call/main-thread.js';
8
+ import { __root, enableTransferMode, warnRootRenderOnTransferPage } from '../root.js';
9
+ import { CHILDREN, COMMIT, COMPONENT, DIFFED, HOOKS, PARENT, PENDING_EFFECTS, RENDER_COMPONENT, VALUE, } from '../shared/render-constants.js';
10
+ import { isRendering } from './lifecycle/isRendering.js';
11
+ import { WorkletEvents } from '../worklet-runtime/bindings/events.js';
12
+ import { genCommitTaskId, replaceCommitHook } from './lifecycle/patch/commit.js';
13
+ import { updateMainThread } from './lifecycle/patch/updateMainThread.js';
14
+ import { __pendingListUpdates } from './list/pendingListUpdates.js';
15
+ import { enablePublishEvent } from './lynx/tt.js';
16
+ import { hydrate as hydrateMainThread } from './renderToOpcodes/hydrate.js';
17
+ import { render as renderFirstFrame } from './renderToOpcodes/index.js';
18
+ import { BackgroundSnapshotInstance, hydrate } from './snapshot/backgroundSnapshot.js';
19
+ import { __page, __pageId, setupPage } from './snapshot/definition.js';
20
+ import { SnapshotInstance } from './snapshot/snapshot.js';
21
+ import { snapshotInstanceManager } from './snapshot/snapshotInstanceManager.js';
22
+ function forgetIds(node) {
23
+ snapshotInstanceManager.values.delete(node.__id);
24
+ node.childNodes.forEach(child => forgetIds(child));
25
+ }
26
+ const providers = new Map();
27
+ let initialized = false;
28
+ function initialize() {
29
+ const mts = typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__;
30
+ const instances = new Map();
31
+ const frames = new Map();
32
+ const disposed = new Set();
33
+ const owners = new WeakMap();
34
+ const workletReturns = new Map();
35
+ let nextWorkletReturnId = 0;
36
+ const removers = [];
37
+ const patchedDelays = new WeakSet();
38
+ const pendingCreates = [];
39
+ let pageReady = !mts;
40
+ let active;
41
+ let activeVersion;
42
+ function send(type, data) {
43
+ const target = mts ? lynx.getJSContext() : lynx.getCoreContext();
44
+ target.dispatchEvent({ type, data: JSON.stringify(data) });
45
+ }
46
+ function listen(target, type, listener) {
47
+ const callback = (event) => {
48
+ try {
49
+ listener((typeof event.data === 'string' ? JSON.parse(event.data) : event.data));
50
+ }
51
+ catch (error) {
52
+ lynx.reportError(error);
53
+ }
54
+ };
55
+ target.addEventListener(type, callback);
56
+ removers.push(() => target.removeEventListener(type, callback));
57
+ }
58
+ function withInstance(instance, fn, version = instance?.version) {
59
+ const previous = active;
60
+ const previousVersion = activeVersion;
61
+ active = instance;
62
+ activeVersion = version;
63
+ try {
64
+ return fn();
65
+ }
66
+ finally {
67
+ active = previous;
68
+ activeVersion = previousVersion;
69
+ }
70
+ }
71
+ function findOwner(vnode) {
72
+ if (active)
73
+ return active;
74
+ for (let node = vnode; node; node = node[PARENT]) {
75
+ const owner = owners.get(node);
76
+ if (owner)
77
+ return owner;
78
+ }
79
+ return undefined;
80
+ }
81
+ function renderBackground(instance) {
82
+ const container = instance.background;
83
+ withInstance(instance, () => render(createElement(instance.Component, instance.props), container));
84
+ // Each `render` call creates a new root vnode.
85
+ const vnode = container[CHILDREN];
86
+ if (vnode)
87
+ owners.set(vnode, instance);
88
+ }
89
+ /** Renders the first frame; later frames take over the elements of the previous one, like a template reload. */
90
+ function renderMain(instance) {
91
+ const previous = instance.main;
92
+ const root = new SnapshotInstance('root');
93
+ if (!previous) {
94
+ root.__elements = [instance.element];
95
+ root.__element_root = instance.element;
96
+ instance.main = root;
97
+ }
98
+ try {
99
+ withInstance(instance, () => {
100
+ renderFirstFrame(createElement(instance.Component, instance.props), undefined, root);
101
+ });
102
+ }
103
+ catch (error) {
104
+ if (previous)
105
+ forgetIds(root);
106
+ dispose(instance.init);
107
+ throw error;
108
+ }
109
+ if (previous) {
110
+ hydrateMainThread(previous, root, { skipUnRef: true });
111
+ forgetIds(previous);
112
+ instance.main = root;
113
+ }
114
+ __pendingListUpdates.flush();
115
+ __FlushElementTree(__page, {});
116
+ send('__TransferFirstFrame', { transferId: instance.init.transferId, snapshot: JSON.stringify(root) });
117
+ }
118
+ /** Releases the commits of an instance that will never be applied. */
119
+ function release(instance) {
120
+ instance.firstFrameWorklets = undefined;
121
+ for (const [id, call] of workletReturns) {
122
+ if (call.instance === instance)
123
+ workletReturns.delete(id);
124
+ }
125
+ instance.inFlight?.finish();
126
+ instance.inFlight = undefined;
127
+ instance.queue.forEach(item => item.finish());
128
+ instance.queue.length = 0;
129
+ }
130
+ function pump(instance) {
131
+ if (instance.inFlight || instance.phase === 'disposed')
132
+ return;
133
+ instance.inFlight = instance.queue.shift();
134
+ if (instance.inFlight)
135
+ send('__TransferCommit', instance.inFlight.packet);
136
+ }
137
+ function enqueue(instance, kind, patchList, patchOptions, finish) {
138
+ const packet = {
139
+ transferId: instance.init.transferId,
140
+ version: instance.version,
141
+ seq: ++instance.seq,
142
+ kind,
143
+ patchList,
144
+ patchOptions,
145
+ };
146
+ instance.queue.push({ packet, finish });
147
+ pump(instance);
148
+ }
149
+ function acceptFrame(frame) {
150
+ if (disposed.has(frame.transferId))
151
+ return;
152
+ const instance = instances.get(frame.transferId);
153
+ if (!instance) {
154
+ frames.set(frame.transferId, frame);
155
+ return;
156
+ }
157
+ if (instance.phase !== 'waiting')
158
+ return;
159
+ instance.phase = 'hydrating';
160
+ const serialized = JSON.parse(frame.snapshot);
161
+ const snapshotPatch = withInstance(instance, () => hydrate(serialized, instance.background));
162
+ const patchList = { patchList: [{ id: genCommitTaskId(), snapshotPatch }] };
163
+ if (instance.firstFrameWorklets?.length) {
164
+ patchList.delayedRunOnMainThreadData = instance.firstFrameWorklets.map(({ worklet, params, resolve }) => {
165
+ const callWorklet = { ...worklet };
166
+ prepareMainThreadFunctionCtx(callWorklet);
167
+ const resolveId = --nextWorkletReturnId;
168
+ workletReturns.set(resolveId, { instance, resolve });
169
+ return { worklet: callWorklet, params, resolveId };
170
+ });
171
+ }
172
+ instance.firstFrameWorklets = undefined;
173
+ enqueue(instance, 'hydrate', patchList, { reloadVersion: getReloadVersion(), isHydration: true }, () => {
174
+ if (instance.phase === 'hydrating')
175
+ instance.phase = 'live';
176
+ });
177
+ }
178
+ function create(init) {
179
+ if (disposed.has(init.transferId) || instances.has(init.transferId))
180
+ return;
181
+ if (!pageReady) {
182
+ pendingCreates.push(init);
183
+ return;
184
+ }
185
+ const provider = providers.get(init.componentName);
186
+ if (!provider)
187
+ throw new Error(`Unknown transfer component: ${init.componentName}`);
188
+ const instance = {
189
+ init,
190
+ Component: provider({ transferId: init.transferId }),
191
+ props: init.initialProps,
192
+ phase: 'waiting',
193
+ version: 0,
194
+ seq: 0,
195
+ queue: [],
196
+ };
197
+ instances.set(init.transferId, instance);
198
+ if (mts) {
199
+ const element = instance.element = __CreateElement('transfer-view', __pageId);
200
+ __SetAttribute(element, 'transfer-id', init.transferId);
201
+ __AppendElement(__page, element);
202
+ send('__CreateTransfer', init);
203
+ renderMain(instance);
204
+ }
205
+ else {
206
+ instance.background = new BackgroundSnapshotInstance('root');
207
+ instance.firstFrameWorklets = [];
208
+ renderBackground(instance);
209
+ const frame = frames.get(init.transferId);
210
+ if (frame) {
211
+ frames.delete(init.transferId);
212
+ acceptFrame(frame);
213
+ }
214
+ }
215
+ }
216
+ /** Replaces the props of an instance; returns the instance to re-render, if it has been created. */
217
+ function replaceProps(update) {
218
+ const pending = pendingCreates.find(init => init.transferId === update.transferId);
219
+ if (pending) {
220
+ pending.initialProps = update.props;
221
+ return undefined;
222
+ }
223
+ const instance = instances.get(update.transferId);
224
+ if (instance)
225
+ instance.props = update.props;
226
+ return instance;
227
+ }
228
+ /** Re-renders the background with the new props and keeps component state, like `updateGlobalProps`. */
229
+ function updateProps(update) {
230
+ const instance = replaceProps(update);
231
+ if (!instance)
232
+ return;
233
+ // The main thread keeps its elements; background commits bring them up to date.
234
+ if (mts) {
235
+ send('__UpdateTransfer', update);
236
+ return;
237
+ }
238
+ renderBackground(instance);
239
+ }
240
+ /** Re-renders both threads with the new props and re-syncs the first frame, like a template reload. */
241
+ function reloadProps(update) {
242
+ const instance = replaceProps(update);
243
+ if (!instance)
244
+ return;
245
+ instance.version++;
246
+ instance.seq = 0;
247
+ if (mts) {
248
+ send('__ReloadTransfer', update);
249
+ renderMain(instance);
250
+ return;
251
+ }
252
+ // Remount like a template reload: state resets and commits wait for the new first frame.
253
+ instance.phase = 'waiting';
254
+ release(instance);
255
+ withInstance(instance, () => render(null, instance.background));
256
+ instance.firstFrameWorklets = [];
257
+ renderBackground(instance);
258
+ }
259
+ function dispose(scope, notify = true) {
260
+ if (disposed.has(scope.transferId))
261
+ return;
262
+ disposed.add(scope.transferId);
263
+ frames.delete(scope.transferId);
264
+ const instance = instances.get(scope.transferId);
265
+ if (instance) {
266
+ instance.phase = 'disposed';
267
+ release(instance);
268
+ if (instance.main) {
269
+ forgetIds(instance.main);
270
+ instance.main.removeChildren();
271
+ __RemoveElement(__page, instance.element);
272
+ __FlushElementTree(__page, {});
273
+ }
274
+ else if (instance.background) {
275
+ withInstance(instance, () => render(null, instance.background));
276
+ instance.background.tearDown();
277
+ }
278
+ instances.delete(scope.transferId);
279
+ }
280
+ if (notify)
281
+ send(mts ? '__DestroyTransfer' : '__TransferDisposed', { transferId: scope.transferId });
282
+ }
283
+ // Business code may call `root.render` before registering; the page root never renders on transfer pages.
284
+ if (__root.__jsx !== undefined) {
285
+ warnRootRenderOnTransferPage();
286
+ __root.__jsx = undefined;
287
+ if (!mts)
288
+ render(null, __root);
289
+ }
290
+ enableTransferMode();
291
+ /**
292
+ * The worklet runtime flushes its pre-hydration `runOnBackground` queue once per page, dropping calls whose
293
+ * first-screen handles are not bound yet. Each transfer instance hydrates separately, so a hydration only runs
294
+ * the calls already bound to the background and keeps the rest in place for the instances still waiting.
295
+ */
296
+ function keepDelayedBackgroundCalls() {
297
+ const delay = globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl;
298
+ if (!delay || patchedDelays.has(delay))
299
+ return;
300
+ patchedDelays.add(delay);
301
+ /* eslint-disable-next-line @typescript-eslint/unbound-method */
302
+ const run = delay.runDelayedBackgroundFunctions;
303
+ delay.runDelayedBackgroundFunctions = () => {
304
+ const queue = delay.delayedBackgroundFunctionArray;
305
+ if (queue.every(details => !details || details.jsFnHandle)) {
306
+ run();
307
+ // Later instances still queue their first-screen calls.
308
+ delay.hasHydrated = false;
309
+ return;
310
+ }
311
+ // Pending handles keep indices into the queue, so bound calls are cleared in place.
312
+ queue.forEach((details, index) => {
313
+ if (!details?.jsFnHandle)
314
+ return;
315
+ queue[index] = undefined;
316
+ details.task(details.jsFnHandle._jsFnId, details.jsFnHandle._execId);
317
+ });
318
+ };
319
+ removers.push(() => {
320
+ delay.runDelayedBackgroundFunctions = run;
321
+ patchedDelays.delete(delay);
322
+ });
323
+ }
324
+ if (mts) {
325
+ listen(lynx.getEngine(), '__RenderPage', ([initData]) => {
326
+ lynx.__initData = initData ?? {};
327
+ setupPage(__CreatePage('0', 0));
328
+ __root.ensureElements();
329
+ __FlushElementTree(__page, {});
330
+ pageReady = true;
331
+ pendingCreates.splice(0).forEach(init => {
332
+ try {
333
+ create(init);
334
+ }
335
+ catch (error) {
336
+ lynx.reportError(error);
337
+ }
338
+ });
339
+ });
340
+ const native = lynx.getNative();
341
+ listen(native, '__CreateTransfer', create);
342
+ listen(native, '__UpdateTransfer', updateProps);
343
+ listen(native, '__ReloadTransfer', reloadProps);
344
+ listen(native, '__DestroyTransfer', scope => dispose(scope));
345
+ listen(lynx.getJSContext(), '__TransferCommit', packet => {
346
+ const instance = instances.get(packet.transferId);
347
+ // Commits rendered before a props update belong to a replaced first frame.
348
+ if (instance && packet.version !== instance.version)
349
+ return;
350
+ let status = 'disposed';
351
+ if (instance && instance.phase !== 'disposed') {
352
+ try {
353
+ if (packet.seq !== instance.seq + 1)
354
+ throw new Error('Transfer commit sequence mismatch');
355
+ if (packet.patchOptions.isHydration)
356
+ keepDelayedBackgroundCalls();
357
+ updateMainThread({ data: JSON.stringify(packet.patchList), patchOptions: packet.patchOptions });
358
+ instance.seq = packet.seq;
359
+ status = 'applied';
360
+ }
361
+ catch (error) {
362
+ status = 'failed';
363
+ lynx.reportError(error);
364
+ }
365
+ }
366
+ const { transferId, version, seq } = packet;
367
+ send('__TransferCommitResult', { transferId, version, seq, status });
368
+ });
369
+ listen(lynx.getJSContext(), '__TransferDisposed', scope => dispose(scope, false));
370
+ }
371
+ else {
372
+ // Background commits belong to transfer instances and travel through scoped events.
373
+ replaceCommitHook((vnode, patchList, patchOptions, finish) => {
374
+ const instance = findOwner(vnode);
375
+ if (!instance) {
376
+ finish();
377
+ lynx.reportError(new Error('Commit rendered outside a transfer instance'));
378
+ return;
379
+ }
380
+ if (instance.phase === 'waiting' || instance.phase === 'disposed') {
381
+ finish();
382
+ return;
383
+ }
384
+ enqueue(instance, 'update', patchList, { ...patchOptions, reloadVersion: getReloadVersion() }, finish);
385
+ });
386
+ let rendering;
387
+ /* eslint-disable @typescript-eslint/unbound-method */
388
+ const renderComponent = options[RENDER_COMPONENT];
389
+ const commit = options[COMMIT];
390
+ const diffed = options[DIFFED];
391
+ /* eslint-enable @typescript-eslint/unbound-method */
392
+ options[RENDER_COMPONENT] = (vnode, component) => {
393
+ rendering = findOwner(vnode);
394
+ renderComponent?.(vnode, component);
395
+ };
396
+ options[DIFFED] = vnode => {
397
+ const effects = vnode[COMPONENT]?.[HOOKS]?.[PENDING_EFFECTS];
398
+ if (effects?.length) {
399
+ const instance = findOwner(vnode);
400
+ if (instance?.phase === 'waiting') {
401
+ const version = instance.version;
402
+ for (const effect of effects) {
403
+ const callback = effect[VALUE];
404
+ effect[VALUE] = () => {
405
+ const cleanup = withInstance(instance, () => callback.call(effect), version);
406
+ return typeof cleanup === 'function' ? () => withInstance(instance, cleanup, version) : cleanup;
407
+ };
408
+ }
409
+ }
410
+ }
411
+ diffed?.(vnode);
412
+ };
413
+ options[COMMIT] = (vnode, queue) => {
414
+ rendering = undefined;
415
+ withInstance(findOwner(vnode), () => commit?.(vnode, queue));
416
+ };
417
+ const scheduleWorklet = options.scheduleMainThreadWorklet;
418
+ function scheduleTransferWorklet(call) {
419
+ if (active && active.version !== activeVersion)
420
+ return true;
421
+ const instance = active ?? (isRendering.value ? rendering : undefined);
422
+ if (!instance || (instance.phase !== 'waiting' && instance.phase !== 'disposed')) {
423
+ return false;
424
+ }
425
+ instance.firstFrameWorklets?.push(call);
426
+ return true;
427
+ }
428
+ options.scheduleMainThreadWorklet = scheduleTransferWorklet;
429
+ removers.push(() => {
430
+ Object.assign(options, {
431
+ [RENDER_COMPONENT]: renderComponent,
432
+ [COMMIT]: commit,
433
+ [DIFFED]: diffed,
434
+ scheduleMainThreadWorklet: scheduleWorklet,
435
+ });
436
+ });
437
+ // Events of hydrated instances dispatch directly; earlier events have no handler and are dropped.
438
+ enablePublishEvent();
439
+ const core = lynx.getCoreContext();
440
+ removers.push(addReloadScopedEventListener(core, WorkletEvents.FunctionCallRet, data => {
441
+ const call = workletReturns.get(data.resolveId);
442
+ if (!call)
443
+ return;
444
+ workletReturns.delete(data.resolveId);
445
+ call.resolve(data.returnValue);
446
+ }));
447
+ listen(core, '__CreateTransfer', create);
448
+ listen(core, '__TransferFirstFrame', acceptFrame);
449
+ listen(core, '__UpdateTransfer', updateProps);
450
+ listen(core, '__ReloadTransfer', reloadProps);
451
+ listen(core, '__DestroyTransfer', scope => dispose(scope, false));
452
+ listen(core, '__TransferCommitResult', result => {
453
+ const instance = instances.get(result.transferId);
454
+ const item = instance?.inFlight;
455
+ if (!instance || !item || item.packet.version !== result.version || item.packet.seq !== result.seq)
456
+ return;
457
+ instance.inFlight = undefined;
458
+ item.finish();
459
+ if (result.status === 'applied')
460
+ pump(instance);
461
+ else
462
+ dispose(instance.init);
463
+ });
464
+ }
465
+ listen(lynx.getNative(), '__DestroyLifetime', () => {
466
+ instances.forEach(instance => dispose(instance.init, false));
467
+ removers.splice(0).forEach(remove => remove());
468
+ if (!mts)
469
+ replaceCommitHook();
470
+ });
471
+ }
472
+ /**
473
+ * Registers components that native hosts render as independent transfer instances.
474
+ * Registering the first component turns the page into a transfer page, where `root.render` is ignored.
475
+ * @experimental
476
+ */
477
+ export const TransferRegistry = {
478
+ registerComponent(componentName, provider) {
479
+ providers.set(componentName, provider);
480
+ if (!initialized) {
481
+ initialized = true;
482
+ initialize();
483
+ }
484
+ },
485
+ };
486
+ //# sourceMappingURL=transfer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../src/snapshot/transfer.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAC3F,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EACL,QAAQ,EACR,MAAM,EACN,SAAS,EACT,MAAM,EACN,KAAK,EACL,MAAM,EACN,eAAe,EACf,gBAAgB,EAChB,KAAK,GACN,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAGtE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEjF,OAAO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SAAS;gBAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;;gBAC3C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,mBAAmB,EAAE,GAAG,EAAE;QACjD,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAC7D,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,GAAG;YAAE,iBAAiB,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,iBAAiB,CAAC,aAAqB,EAAE,QAA2B;QAClE,SAAS,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QACvC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,WAAW,GAAG,IAAI,CAAC;YACnB,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;CACF,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 { createElement, options, render } from 'preact';\nimport type { ComponentType, ContainerNode, VNode } from 'preact';\n\nimport { addReloadScopedEventListener } from '../core/reload-scoped-event.js';\nimport { getReloadVersion } from '../core/reload-version.js';\nimport { prepareMainThreadFunctionCtx } from '../core/thread-function-call/main-thread.js';\nimport { __root, enableTransferMode, warnRootRenderOnTransferPage } from '../root.js';\nimport {\n CHILDREN,\n COMMIT,\n COMPONENT,\n DIFFED,\n HOOKS,\n PARENT,\n PENDING_EFFECTS,\n RENDER_COMPONENT,\n VALUE,\n} from '../shared/render-constants.js';\nimport { isRendering } from './lifecycle/isRendering.js';\nimport { WorkletEvents } from '../worklet-runtime/bindings/events.js';\nimport type { RunWorkletCtxRetData } from '../worklet-runtime/bindings/events.js';\nimport type { Worklet } from '../worklet-runtime/bindings/types.js';\nimport { genCommitTaskId, replaceCommitHook } from './lifecycle/patch/commit.js';\nimport type { PatchList, PatchOptions } from './lifecycle/patch/commit.js';\nimport { updateMainThread } from './lifecycle/patch/updateMainThread.js';\nimport { __pendingListUpdates } from './list/pendingListUpdates.js';\nimport { enablePublishEvent } from './lynx/tt.js';\nimport { hydrate as hydrateMainThread } from './renderToOpcodes/hydrate.js';\nimport { render as renderFirstFrame } from './renderToOpcodes/index.js';\nimport { BackgroundSnapshotInstance, hydrate } from './snapshot/backgroundSnapshot.js';\nimport { __page, __pageId, setupPage } from './snapshot/definition.js';\nimport { SnapshotInstance } from './snapshot/snapshot.js';\nimport { snapshotInstanceManager } from './snapshot/snapshotInstanceManager.js';\nimport type { SerializedSnapshotInstance } from './snapshot/types.js';\n\ntype TransferProps = Record<string, unknown>;\ninterface Scope {\n transferId: string;\n}\ntype CreateTransferEvent = Scope & { componentName: string; initialProps: TransferProps };\ntype TransferPropsEvent = Scope & { props: TransferProps };\ntype TransferFirstFrame = Scope & { snapshot: string };\ntype TransferCommit = Scope & {\n version: number;\n seq: number;\n kind: 'hydrate' | 'update';\n patchList: PatchList;\n patchOptions: PatchOptions;\n};\ntype TransferCommitResult = Scope & { version: number; seq: number; status: 'applied' | 'disposed' | 'failed' };\ntype ComponentProvider = (scope: Scope) => ComponentType<TransferProps>;\n\ninterface Pending {\n packet: TransferCommit;\n finish: () => void;\n}\nexport interface PendingMainThreadCall {\n worklet: Worklet;\n params: unknown[];\n resolve: (value: any) => void;\n}\ninterface Instance {\n init: CreateTransferEvent;\n Component: ComponentType<TransferProps>;\n props: TransferProps;\n phase: 'waiting' | 'hydrating' | 'live' | 'disposed';\n /** Counts reloads; each one re-syncs the first frame and restarts `seq`. */\n version: number;\n seq: number;\n main?: SnapshotInstance;\n element?: FiberElement;\n background?: BackgroundSnapshotInstance;\n firstFrameWorklets?: PendingMainThreadCall[] | undefined;\n queue: Pending[];\n inFlight?: Pending | undefined;\n}\ninterface EventTarget {\n addEventListener(type: string, listener: (event: { data: unknown }) => void): void;\n removeEventListener(type: string, listener: (event: { data: unknown }) => void): void;\n}\n\nfunction forgetIds(node: SnapshotInstance): void {\n snapshotInstanceManager.values.delete(node.__id);\n node.childNodes.forEach(child => forgetIds(child));\n}\n\nconst providers = new Map<string, ComponentProvider>();\nlet initialized = false;\n\nfunction initialize(): void {\n const mts = typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__;\n const instances = new Map<string, Instance>();\n const frames = new Map<string, TransferFirstFrame>();\n const disposed = new Set<string>();\n const owners = new WeakMap<object, Instance>();\n const workletReturns = new Map<number, { instance: Instance; resolve: (value: unknown) => void }>();\n let nextWorkletReturnId = 0;\n const removers: (() => void)[] = [];\n const patchedDelays = new WeakSet<object>();\n const pendingCreates: CreateTransferEvent[] = [];\n let pageReady = !mts;\n let active: Instance | undefined;\n let activeVersion: number | undefined;\n\n function send(type: string, data: unknown) {\n const target = mts ? lynx.getJSContext() : lynx.getCoreContext();\n target.dispatchEvent({ type, data: JSON.stringify(data) });\n }\n function listen<T>(target: EventTarget, type: string, listener: (data: T) => void) {\n const callback = (event: { data: unknown }) => {\n try {\n listener((typeof event.data === 'string' ? JSON.parse(event.data) : event.data) as T);\n } catch (error) {\n lynx.reportError(error as Error);\n }\n };\n target.addEventListener(type, callback);\n removers.push(() => target.removeEventListener(type, callback));\n }\n function withInstance<T>(instance: Instance | undefined, fn: () => T, version = instance?.version): T {\n const previous = active;\n const previousVersion = activeVersion;\n active = instance;\n activeVersion = version;\n try {\n return fn();\n } finally {\n active = previous;\n activeVersion = previousVersion;\n }\n }\n function findOwner(vnode: VNode): Instance | undefined {\n if (active) return active;\n for (let node: VNode | undefined = vnode; node; node = (node as unknown as Record<string, VNode>)[PARENT]) {\n const owner = owners.get(node);\n if (owner) return owner;\n }\n return undefined;\n }\n\n function renderBackground(instance: Instance) {\n const container = instance.background as unknown as ContainerNode;\n withInstance(instance, () => render(createElement(instance.Component, instance.props), container));\n // Each `render` call creates a new root vnode.\n const vnode = (container as unknown as Record<string, object | undefined>)[CHILDREN];\n if (vnode) owners.set(vnode, instance);\n }\n /** Renders the first frame; later frames take over the elements of the previous one, like a template reload. */\n function renderMain(instance: Instance) {\n const previous = instance.main;\n const root = new SnapshotInstance('root');\n if (!previous) {\n root.__elements = [instance.element!];\n root.__element_root = instance.element;\n instance.main = root;\n }\n try {\n withInstance(instance, () => {\n renderFirstFrame(createElement(instance.Component, instance.props), undefined, root);\n });\n } catch (error) {\n if (previous) forgetIds(root);\n dispose(instance.init);\n throw error;\n }\n if (previous) {\n hydrateMainThread(previous, root, { skipUnRef: true });\n forgetIds(previous);\n instance.main = root;\n }\n __pendingListUpdates.flush();\n __FlushElementTree(__page, {});\n send('__TransferFirstFrame', { transferId: instance.init.transferId, snapshot: JSON.stringify(root) });\n }\n /** Releases the commits of an instance that will never be applied. */\n function release(instance: Instance) {\n instance.firstFrameWorklets = undefined;\n for (const [id, call] of workletReturns) {\n if (call.instance === instance) workletReturns.delete(id);\n }\n instance.inFlight?.finish();\n instance.inFlight = undefined;\n instance.queue.forEach(item => item.finish());\n instance.queue.length = 0;\n }\n function pump(instance: Instance) {\n if (instance.inFlight || instance.phase === 'disposed') return;\n instance.inFlight = instance.queue.shift();\n if (instance.inFlight) send('__TransferCommit', instance.inFlight.packet);\n }\n function enqueue(\n instance: Instance,\n kind: TransferCommit['kind'],\n patchList: PatchList,\n patchOptions: PatchOptions,\n finish: () => void,\n ) {\n const packet = {\n transferId: instance.init.transferId,\n version: instance.version,\n seq: ++instance.seq,\n kind,\n patchList,\n patchOptions,\n };\n instance.queue.push({ packet, finish });\n pump(instance);\n }\n function acceptFrame(frame: TransferFirstFrame) {\n if (disposed.has(frame.transferId)) return;\n const instance = instances.get(frame.transferId);\n if (!instance) {\n frames.set(frame.transferId, frame);\n return;\n }\n if (instance.phase !== 'waiting') return;\n instance.phase = 'hydrating';\n const serialized = JSON.parse(frame.snapshot) as SerializedSnapshotInstance;\n const snapshotPatch = withInstance(instance, () => hydrate(serialized, instance.background!));\n const patchList: PatchList = { patchList: [{ id: genCommitTaskId(), snapshotPatch }] };\n if (instance.firstFrameWorklets?.length) {\n patchList.delayedRunOnMainThreadData = instance.firstFrameWorklets.map(({ worklet, params, resolve }) => {\n const callWorklet = { ...worklet };\n prepareMainThreadFunctionCtx(callWorklet);\n const resolveId = --nextWorkletReturnId;\n workletReturns.set(resolveId, { instance, resolve });\n return { worklet: callWorklet, params, resolveId };\n });\n }\n instance.firstFrameWorklets = undefined;\n enqueue(\n instance,\n 'hydrate',\n patchList,\n { reloadVersion: getReloadVersion(), isHydration: true },\n () => {\n if (instance.phase === 'hydrating') instance.phase = 'live';\n },\n );\n }\n\n function create(init: CreateTransferEvent) {\n if (disposed.has(init.transferId) || instances.has(init.transferId)) return;\n if (!pageReady) {\n pendingCreates.push(init);\n return;\n }\n const provider = providers.get(init.componentName);\n if (!provider) throw new Error(`Unknown transfer component: ${init.componentName}`);\n const instance: Instance = {\n init,\n Component: provider({ transferId: init.transferId }),\n props: init.initialProps,\n phase: 'waiting',\n version: 0,\n seq: 0,\n queue: [],\n };\n instances.set(init.transferId, instance);\n if (mts) {\n const element = instance.element = __CreateElement('transfer-view', __pageId);\n __SetAttribute(element, 'transfer-id', init.transferId);\n __AppendElement(__page, element);\n send('__CreateTransfer', init);\n renderMain(instance);\n } else {\n instance.background = new BackgroundSnapshotInstance('root');\n instance.firstFrameWorklets = [];\n renderBackground(instance);\n const frame = frames.get(init.transferId);\n if (frame) {\n frames.delete(init.transferId);\n acceptFrame(frame);\n }\n }\n }\n /** Replaces the props of an instance; returns the instance to re-render, if it has been created. */\n function replaceProps(update: TransferPropsEvent): Instance | undefined {\n const pending = pendingCreates.find(init => init.transferId === update.transferId);\n if (pending) {\n pending.initialProps = update.props;\n return undefined;\n }\n const instance = instances.get(update.transferId);\n if (instance) instance.props = update.props;\n return instance;\n }\n /** Re-renders the background with the new props and keeps component state, like `updateGlobalProps`. */\n function updateProps(update: TransferPropsEvent) {\n const instance = replaceProps(update);\n if (!instance) return;\n // The main thread keeps its elements; background commits bring them up to date.\n if (mts) {\n send('__UpdateTransfer', update);\n return;\n }\n renderBackground(instance);\n }\n /** Re-renders both threads with the new props and re-syncs the first frame, like a template reload. */\n function reloadProps(update: TransferPropsEvent) {\n const instance = replaceProps(update);\n if (!instance) return;\n instance.version++;\n instance.seq = 0;\n if (mts) {\n send('__ReloadTransfer', update);\n renderMain(instance);\n return;\n }\n // Remount like a template reload: state resets and commits wait for the new first frame.\n instance.phase = 'waiting';\n release(instance);\n withInstance(instance, () => render(null, instance.background as unknown as ContainerNode));\n instance.firstFrameWorklets = [];\n renderBackground(instance);\n }\n function dispose(scope: Scope, notify = true) {\n if (disposed.has(scope.transferId)) return;\n disposed.add(scope.transferId);\n frames.delete(scope.transferId);\n const instance = instances.get(scope.transferId);\n if (instance) {\n instance.phase = 'disposed';\n release(instance);\n if (instance.main) {\n forgetIds(instance.main);\n instance.main.removeChildren();\n __RemoveElement(__page, instance.element!);\n __FlushElementTree(__page, {});\n } else if (instance.background) {\n withInstance(instance, () => render(null, instance.background as unknown as ContainerNode));\n instance.background.tearDown();\n }\n instances.delete(scope.transferId);\n }\n if (notify) send(mts ? '__DestroyTransfer' : '__TransferDisposed', { transferId: scope.transferId });\n }\n\n // Business code may call `root.render` before registering; the page root never renders on transfer pages.\n if (__root.__jsx !== undefined) {\n warnRootRenderOnTransferPage();\n __root.__jsx = undefined;\n if (!mts) render(null, __root as unknown as ContainerNode);\n }\n enableTransferMode();\n\n /**\n * The worklet runtime flushes its pre-hydration `runOnBackground` queue once per page, dropping calls whose\n * first-screen handles are not bound yet. Each transfer instance hydrates separately, so a hydration only runs\n * the calls already bound to the background and keeps the rest in place for the instances still waiting.\n */\n function keepDelayedBackgroundCalls() {\n const delay = globalThis.lynxWorkletImpl?._runOnBackgroundDelayImpl;\n if (!delay || patchedDelays.has(delay)) return;\n patchedDelays.add(delay);\n /* eslint-disable-next-line @typescript-eslint/unbound-method */\n const run = delay.runDelayedBackgroundFunctions;\n delay.runDelayedBackgroundFunctions = () => {\n const queue = delay.delayedBackgroundFunctionArray;\n if (queue.every(details => !details || details.jsFnHandle)) {\n run();\n // Later instances still queue their first-screen calls.\n delay.hasHydrated = false;\n return;\n }\n // Pending handles keep indices into the queue, so bound calls are cleared in place.\n queue.forEach((details, index) => {\n if (!details?.jsFnHandle) return;\n queue[index] = undefined;\n details.task(details.jsFnHandle._jsFnId!, details.jsFnHandle._execId!);\n });\n };\n removers.push(() => {\n delay.runDelayedBackgroundFunctions = run;\n patchedDelays.delete(delay);\n });\n }\n\n if (mts) {\n listen<[Record<string, unknown>?]>(lynx.getEngine(), '__RenderPage', ([initData]) => {\n lynx.__initData = initData ?? {};\n setupPage(__CreatePage('0', 0));\n (__root as SnapshotInstance).ensureElements();\n __FlushElementTree(__page, {});\n pageReady = true;\n pendingCreates.splice(0).forEach(init => {\n try {\n create(init);\n } catch (error) {\n lynx.reportError(error as Error);\n }\n });\n });\n const native = lynx.getNative();\n listen(native, '__CreateTransfer', create);\n listen(native, '__UpdateTransfer', updateProps);\n listen(native, '__ReloadTransfer', reloadProps);\n listen<Scope>(native, '__DestroyTransfer', scope => dispose(scope));\n listen<TransferCommit>(lynx.getJSContext(), '__TransferCommit', packet => {\n const instance = instances.get(packet.transferId);\n // Commits rendered before a props update belong to a replaced first frame.\n if (instance && packet.version !== instance.version) return;\n let status: TransferCommitResult['status'] = 'disposed';\n if (instance && instance.phase !== 'disposed') {\n try {\n if (packet.seq !== instance.seq + 1) throw new Error('Transfer commit sequence mismatch');\n if (packet.patchOptions.isHydration) keepDelayedBackgroundCalls();\n updateMainThread({ data: JSON.stringify(packet.patchList), patchOptions: packet.patchOptions });\n instance.seq = packet.seq;\n status = 'applied';\n } catch (error) {\n status = 'failed';\n lynx.reportError(error as Error);\n }\n }\n const { transferId, version, seq } = packet;\n send('__TransferCommitResult', { transferId, version, seq, status });\n });\n listen<Scope>(lynx.getJSContext(), '__TransferDisposed', scope => dispose(scope, false));\n } else {\n // Background commits belong to transfer instances and travel through scoped events.\n replaceCommitHook((vnode, patchList, patchOptions, finish) => {\n const instance = findOwner(vnode);\n if (!instance) {\n finish();\n lynx.reportError(new Error('Commit rendered outside a transfer instance'));\n return;\n }\n if (instance.phase === 'waiting' || instance.phase === 'disposed') {\n finish();\n return;\n }\n enqueue(instance, 'update', patchList, { ...patchOptions, reloadVersion: getReloadVersion() }, finish);\n });\n let rendering: Instance | undefined;\n /* eslint-disable @typescript-eslint/unbound-method */\n const renderComponent = options[RENDER_COMPONENT];\n const commit = options[COMMIT];\n const diffed = options[DIFFED];\n /* eslint-enable @typescript-eslint/unbound-method */\n options[RENDER_COMPONENT] = (vnode, component) => {\n rendering = findOwner(vnode);\n renderComponent?.(vnode, component);\n };\n options[DIFFED] = vnode => {\n const effects = vnode[COMPONENT]?.[HOOKS]?.[PENDING_EFFECTS] as\n | { [VALUE]: () => void | (() => void) }[]\n | undefined;\n if (effects?.length) {\n const instance = findOwner(vnode);\n if (instance?.phase === 'waiting') {\n const version = instance.version;\n for (const effect of effects) {\n const callback = effect[VALUE];\n effect[VALUE] = () => {\n const cleanup = withInstance(instance, () => callback.call(effect), version);\n return typeof cleanup === 'function' ? () => withInstance(instance, cleanup, version) : cleanup;\n };\n }\n }\n }\n diffed?.(vnode);\n };\n options[COMMIT] = (vnode, queue) => {\n rendering = undefined;\n withInstance(findOwner(vnode), () => commit?.(vnode, queue));\n };\n const scheduleWorklet = options.scheduleMainThreadWorklet;\n function scheduleTransferWorklet(call: PendingMainThreadCall): boolean {\n if (active && active.version !== activeVersion) return true;\n const instance = active ?? (isRendering.value ? rendering : undefined);\n if (!instance || (instance.phase !== 'waiting' && instance.phase !== 'disposed')) {\n return false;\n }\n instance.firstFrameWorklets?.push(call);\n return true;\n }\n options.scheduleMainThreadWorklet = scheduleTransferWorklet;\n removers.push(() => {\n Object.assign(options, {\n [RENDER_COMPONENT]: renderComponent,\n [COMMIT]: commit,\n [DIFFED]: diffed,\n scheduleMainThreadWorklet: scheduleWorklet,\n });\n });\n // Events of hydrated instances dispatch directly; earlier events have no handler and are dropped.\n enablePublishEvent();\n const core = lynx.getCoreContext();\n removers.push(addReloadScopedEventListener<RunWorkletCtxRetData>(core, WorkletEvents.FunctionCallRet, data => {\n const call = workletReturns.get(data.resolveId);\n if (!call) return;\n workletReturns.delete(data.resolveId);\n call.resolve(data.returnValue);\n }));\n listen(core, '__CreateTransfer', create);\n listen(core, '__TransferFirstFrame', acceptFrame);\n listen(core, '__UpdateTransfer', updateProps);\n listen(core, '__ReloadTransfer', reloadProps);\n listen<Scope>(core, '__DestroyTransfer', scope => dispose(scope, false));\n listen<TransferCommitResult>(core, '__TransferCommitResult', result => {\n const instance = instances.get(result.transferId);\n const item = instance?.inFlight;\n if (!instance || !item || item.packet.version !== result.version || item.packet.seq !== result.seq) return;\n instance.inFlight = undefined;\n item.finish();\n if (result.status === 'applied') pump(instance);\n else dispose(instance.init);\n });\n }\n\n listen(lynx.getNative(), '__DestroyLifetime', () => {\n instances.forEach(instance => dispose(instance.init, false));\n removers.splice(0).forEach(remove => remove());\n if (!mts) replaceCommitHook();\n });\n}\n\n/**\n * Registers components that native hosts render as independent transfer instances.\n * Registering the first component turns the page into a transfer page, where `root.render` is ignored.\n * @experimental\n */\nexport const TransferRegistry = {\n registerComponent(componentName: string, provider: ComponentProvider): void {\n providers.set(componentName, provider);\n if (!initialized) {\n initialized = true;\n initialize();\n }\n },\n};\n"]}
@@ -2,7 +2,7 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { clearMtsConfigCacheForTesting, isMtsEnabled } from '../../core/mts-capability.js';
5
- import { isSdkVersionGt } from '../../utils.js';
5
+ import { isSdkVersionGt } from '../../shared/version.js';
6
6
  let runOnBackgroundEnabled;
7
7
  /**
8
8
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"functionality.js","sourceRoot":"","sources":["../../../src/snapshot/worklet/functionality.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,6BAA6B,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,IAAI,sBAA2C,CAAC;AAEhD;;GAEG;AACH,SAAS,wBAAwB;IAC/B,OAAO,sBAAsB,KAAK,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,0BAA0B;IACjC,6BAA6B,EAAE,CAAC;IAChC,sBAAsB,GAAG,SAAS,CAAC;AACrC,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,CAAC","sourcesContent":["// Copyright 2024 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 { clearMtsConfigCacheForTesting, isMtsEnabled } from '../../core/mts-capability.js';\nimport { isSdkVersionGt } from '../../utils.js';\n\nlet runOnBackgroundEnabled: boolean | undefined;\n\n/**\n * @internal\n */\nfunction isRunOnBackgroundEnabled(): boolean {\n return runOnBackgroundEnabled ??= isSdkVersionGt(2, 15);\n}\n\nfunction clearConfigCacheForTesting(): void {\n clearMtsConfigCacheForTesting();\n runOnBackgroundEnabled = undefined;\n}\n\nexport { isMtsEnabled, isRunOnBackgroundEnabled, clearConfigCacheForTesting };\n"]}
1
+ {"version":3,"file":"functionality.js","sourceRoot":"","sources":["../../../src/snapshot/worklet/functionality.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,6BAA6B,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,IAAI,sBAA2C,CAAC;AAEhD;;GAEG;AACH,SAAS,wBAAwB;IAC/B,OAAO,sBAAsB,KAAK,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,0BAA0B;IACjC,6BAA6B,EAAE,CAAC;IAChC,sBAAsB,GAAG,SAAS,CAAC;AACrC,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,CAAC","sourcesContent":["// Copyright 2024 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 { clearMtsConfigCacheForTesting, isMtsEnabled } from '../../core/mts-capability.js';\nimport { isSdkVersionGt } from '../../shared/version.js';\n\nlet runOnBackgroundEnabled: boolean | undefined;\n\n/**\n * @internal\n */\nfunction isRunOnBackgroundEnabled(): boolean {\n return runOnBackgroundEnabled ??= isSdkVersionGt(2, 15);\n}\n\nfunction clearConfigCacheForTesting(): void {\n clearMtsConfigCacheForTesting();\n runOnBackgroundEnabled = undefined;\n}\n\nexport { isMtsEnabled, isRunOnBackgroundEnabled, clearConfigCacheForTesting };\n"]}