@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":"isRendering.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/isRendering.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAE5D,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,WAAW,CAAC,KAAK,GAAG,IAAI,CAAC;IACzB,sFAAsF;IACtF,kBAAkB,CAAC,GAAG,EAAE;QACtB,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAsB,GAAuC,EAAE,GAAG,IAAO,EAAE,EAAE;IAChG,oBAAoB;IACpB,IAAI,GAAG;QAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IACtB,cAAc,EAAE,CAAC;AACnB,CAAC,CAAC;AAEF,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC;AAC9C,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,CAAC,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 { options } from 'preact';\n\nimport { RENDER_COMPONENT, ROOT } from '../../shared/render-constants.js';\nimport { hook, lynxQueueMicrotask } from '../../utils.js';\n\nexport const isRendering = /* @__PURE__ */ { value: false };\n\nconst setIsRendering = () => {\n isRendering.value = true;\n // Make sure `isRendering` is set to false even if an error is thrown during rendering\n lynxQueueMicrotask(() => {\n isRendering.value = false;\n });\n};\n\nconst onRenderHook = <T extends unknown[]>(old: ((...args: T) => void) | undefined, ...args: T) => {\n /* v8 ignore next */\n if (old) old(...args);\n setIsRendering();\n};\n\nhook(options, RENDER_COMPONENT, onRenderHook);\nhook(options, ROOT, onRenderHook);\n"]}
1
+ {"version":3,"file":"isRendering.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/isRendering.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAE5D,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,WAAW,CAAC,KAAK,GAAG,IAAI,CAAC;IACzB,sFAAsF;IACtF,kBAAkB,CAAC,GAAG,EAAE;QACtB,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAsB,GAAuC,EAAE,GAAG,IAAO,EAAE,EAAE;IAChG,oBAAoB;IACpB,IAAI,GAAG;QAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IACtB,cAAc,EAAE,CAAC;AACnB,CAAC,CAAC;AAEF,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC;AAC9C,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,CAAC,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 { options } from 'preact';\n\nimport { lynxQueueMicrotask } from '../../shared/microtask.js';\nimport { RENDER_COMPONENT, ROOT } from '../../shared/render-constants.js';\nimport { hook } from '../../shared/utils.js';\n\nexport const isRendering = /* @__PURE__ */ { value: false };\n\nconst setIsRendering = () => {\n isRendering.value = true;\n // Make sure `isRendering` is set to false even if an error is thrown during rendering\n lynxQueueMicrotask(() => {\n isRendering.value = false;\n });\n};\n\nconst onRenderHook = <T extends unknown[]>(old: ((...args: T) => void) | undefined, ...args: T) => {\n /* v8 ignore next */\n if (old) old(...args);\n setIsRendering();\n};\n\nhook(options, RENDER_COMPONENT, onRenderHook);\nhook(options, ROOT, onRenderHook);\n"]}
@@ -1,3 +1,4 @@
1
+ import type { VNode } from 'preact';
1
2
  import type { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';
2
3
  import { globalBackgroundSnapshotInstancesToRemove } from './globalState.js';
3
4
  import type { SnapshotPatch } from './snapshotPatch.js';
@@ -31,11 +32,15 @@ interface PatchOptions {
31
32
  */
32
33
  export type GlobalPatchOptions = Omit<PatchOptions, 'reloadVersion'>;
33
34
  export declare let globalPatchOptions: GlobalPatchOptions;
35
+ /**
36
+ * Delivers a collected commit and calls `finish` once it has been applied.
37
+ */
38
+ type CommitTransport = (vnode: VNode, patchList: PatchList, patchOptions: GlobalPatchOptions, finish: () => void) => void;
34
39
  /**
35
40
  * Replaces Preact's default commit hook with our custom implementation.
36
- * Calling it again is a no-op until {@link removeCommitHookForTesting} is called.
41
+ * Calling it again only replaces the transport until {@link removeCommitHookForTesting} is called.
37
42
  */
38
- declare function replaceCommitHook(): void;
43
+ declare function replaceCommitHook(transport?: CommitTransport): void;
39
44
  /**
40
45
  * Restores the commit option replaced by {@link replaceCommitHook} so tests
41
46
  * can clean up the global Preact `options` object. Assumes the matching
@@ -25,7 +25,7 @@ import { getReloadVersion } from '../../../core/reload-version.js';
25
25
  import { delayedRunOnMainThreadData, takeDelayedRunOnMainThreadData, } from '../../../core/thread-function-call/main-thread.js';
26
26
  import { profileEnd, profileStart } from '../../../shared/profile.js';
27
27
  import { COMMIT } from '../../../shared/render-constants.js';
28
- import { hook, isEmptyObject } from '../../../utils.js';
28
+ import { hook, isEmptyObject } from '../../../shared/utils.js';
29
29
  import { LifecycleConstant } from '../../lifecycle/constant.js';
30
30
  import { backgroundSnapshotInstanceManager } from '../../snapshot/backgroundSnapshot.js';
31
31
  import { applyQueuedRefs } from '../../snapshot/ref.js';
@@ -39,13 +39,19 @@ function takeGlobalPatchOptions() {
39
39
  globalPatchOptions = {};
40
40
  return res;
41
41
  }
42
+ const nativeTransport = (_vnode, patchList, patchOptions, finish) => {
43
+ // Send the update to the native layer
44
+ lynx.getNativeApp().callLepusMethod(LifecycleConstant.patchUpdate, commitPatchUpdate(patchList, patchOptions), finish);
45
+ };
42
46
  let commitHookInstalled = false;
43
47
  let previousCommit;
48
+ let commitTransport = nativeTransport;
44
49
  /**
45
50
  * Replaces Preact's default commit hook with our custom implementation.
46
- * Calling it again is a no-op until {@link removeCommitHookForTesting} is called.
51
+ * Calling it again only replaces the transport until {@link removeCommitHookForTesting} is called.
47
52
  */
48
- function replaceCommitHook() {
53
+ function replaceCommitHook(transport = nativeTransport) {
54
+ commitTransport = transport;
49
55
  if (commitHookInstalled) {
50
56
  return;
51
57
  }
@@ -107,9 +113,7 @@ function replaceCommitHook() {
107
113
  if (delayedRunOnMainThreadData.length) {
108
114
  patchList.delayedRunOnMainThreadData = takeDelayedRunOnMainThreadData();
109
115
  }
110
- const obj = commitPatchUpdate(patchList, patchOptions);
111
- // Send the update to the native layer
112
- lynx.getNativeApp().callLepusMethod(LifecycleConstant.patchUpdate, obj, () => {
116
+ commitTransport(vnode, patchList, patchOptions, () => {
113
117
  const commitTask = globalCommitTaskMap.get(commitTaskId);
114
118
  if (commitTask) {
115
119
  commitTask();
@@ -132,6 +136,7 @@ function removeCommitHookForTesting() {
132
136
  return;
133
137
  }
134
138
  commitHookInstalled = false;
139
+ commitTransport = nativeTransport;
135
140
  if (previousCommit) {
136
141
  options[COMMIT] = previousCommit;
137
142
  previousCommit = undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"commit.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/commit.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;;;;;;GAUG;AAEH;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAIjC,OAAO,EACL,yCAAyC,EACzC,4CAA4C,GAC7C,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EACL,0BAA0B,EAC1B,8BAA8B,GAC/B,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,iCAAiC,EAAE,MAAM,sCAAsC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AACtF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AC,gBAAgB,CAAC,CAAC;IAC7B,IAAI,qBAAqB,EAAE,CAAC;QAC1B,GAAG,CAAC,YAAY,CAAC,eAAe,GAAG,qBAAqB,CAAC;QACzD,WAAW,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,SAAS,eAAe;IACtB,OAAO,gBAAgB,EAAE,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,SAAS,iBAAiB;IACxB,gBAAgB,GAAG,CAAC,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,yCAAyC,EACzC,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,GAGlB,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\n/**\n * Implements the commit phase of the rendering lifecycle.\n * This module patches Preact's commit phase to integrate with the snapshot system,\n * handling the collection and transmission of patches between threads.\n *\n * The commit phase is responsible for:\n * - Collecting patches from the snapshot system\n * - Managing commit tasks and their execution\n * - Coordinating with the native layer for updates\n * - Handling performance timing and pipeline options\n */\n\n/**\n * This module patches Preact's commit phase by hacking into the internal of\n * its [options](https://preactjs.com/guide/v10/options/) API\n */\n\nimport { options } from 'preact';\n\nimport type { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport {\n globalBackgroundSnapshotInstancesToRemove,\n setGlobalBackgroundSnapshotInstancesToRemove,\n} from './globalState.js';\nimport { takeGlobalSnapshotPatch } from './snapshotPatch.js';\nimport type { SnapshotPatch } from './snapshotPatch.js';\nimport { takeGlobalFlushOptions } from '../../../core/commit-context.js';\nimport { globalPipelineOptions, markTiming, markTimingLegacy, setPipeline } 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 { profileEnd, profileStart } from '../../../shared/profile.js';\nimport { COMMIT } from '../../../shared/render-constants.js';\nimport { hook, isEmptyObject } from '../../../utils.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\nimport { backgroundSnapshotInstanceManager } from '../../snapshot/backgroundSnapshot.js';\nimport { applyQueuedRefs } from '../../snapshot/ref.js';\nimport { sendMTRefInitValueToMainThread } from '../../worklet/ref/updateInitValue.js';\nimport { isRendering } from '../isRendering.js';\n\nconst globalCommitTaskMap: Map<number, () => void> = /*@__PURE__*/ new Map<number, () => void>();\nlet nextCommitTaskId = 1;\n\n/**\n * A single patch operation.\n */\ninterface Patch {\n // TODO: ref: do we need `id`?\n id: number;\n snapshotPatch?: SnapshotPatch;\n}\n\n/**\n * List of patches to be applied in a single update cycle with flush options.\n */\ninterface PatchList {\n patchList: Patch[];\n delayedRunOnMainThreadData?: RunWorkletCtxData[];\n flushOptions?: FlushOptions;\n}\n\n/**\n * Configuration options for patch operations\n */\ninterface PatchOptions {\n pipelineOptions?: PipelineOptions;\n reloadVersion: number;\n isHydration?: boolean;\n flowIds?: number[];\n}\n\n/**\n * Allow to pass options to the patch operation\n */\nexport type GlobalPatchOptions = Omit<PatchOptions, 'reloadVersion'>;\nexport let globalPatchOptions: GlobalPatchOptions = {};\n\nfunction takeGlobalPatchOptions(): GlobalPatchOptions {\n const res = globalPatchOptions;\n globalPatchOptions = {};\n return res;\n}\n\nlet commitHookInstalled = false;\nlet previousCommit: typeof options[typeof COMMIT];\n\n/**\n * Replaces Preact's default commit hook with our custom implementation.\n * Calling it again is a no-op until {@link removeCommitHookForTesting} is called.\n */\nfunction replaceCommitHook(): void {\n if (commitHookInstalled) {\n return;\n }\n commitHookInstalled = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n previousCommit = options[COMMIT];\n\n hook(\n options,\n COMMIT,\n (\n originalPreactCommit, // This is actually not used since Preact use `hooks._commit` for callbacks of `useLayoutEffect`.\n vnode,\n commitQueue,\n ) => {\n // Skip commit phase for MT runtime\n if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n // for testing only\n commitQueue.length = 0;\n return;\n }\n\n isRendering.value = false;\n\n // Mark the end of virtual DOM diffing phase for performance tracking\n markTimingLegacy('updateDiffVdomEnd');\n markTiming('diffVdomEnd');\n\n const backgroundSnapshotInstancesToRemove = globalBackgroundSnapshotInstancesToRemove;\n setGlobalBackgroundSnapshotInstancesToRemove([]);\n\n const commitTaskId = genCommitTaskId();\n\n // Register the commit task\n globalCommitTaskMap.set(commitTaskId, () => {\n if (backgroundSnapshotInstancesToRemove.length) {\n setTimeout(() => {\n backgroundSnapshotInstancesToRemove.forEach(id => {\n backgroundSnapshotInstanceManager.values.get(id)?.tearDown();\n });\n }, 10000);\n }\n });\n\n sendMTRefInitValueToMainThread();\n\n // Collect patches for this update\n const snapshotPatch = takeGlobalSnapshotPatch();\n const flushOptions = takeGlobalFlushOptions();\n const patchOptions = takeGlobalPatchOptions();\n if (!snapshotPatch) {\n // before hydration, skip patch\n applyQueuedRefs();\n originalPreactCommit?.(vnode, commitQueue);\n return;\n }\n\n const patch: Patch = {\n id: commitTaskId,\n };\n // TODO: check all fields in `flushOptions` from runtime3\n if (snapshotPatch.length) {\n patch.snapshotPatch = snapshotPatch;\n }\n const patchList: PatchList = {\n patchList: [patch],\n };\n if (!snapshotPatch.length && !delayedRunOnMainThreadData.length) {\n flushOptions.emptyPatch = true;\n }\n if (!isEmptyObject(flushOptions)) {\n patchList.flushOptions = flushOptions;\n }\n if (delayedRunOnMainThreadData.length) {\n patchList.delayedRunOnMainThreadData = takeDelayedRunOnMainThreadData();\n }\n const obj = commitPatchUpdate(patchList, patchOptions);\n\n // Send the update to the native layer\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.patchUpdate, obj, () => {\n const commitTask = globalCommitTaskMap.get(commitTaskId);\n if (commitTask) {\n commitTask();\n globalCommitTaskMap.delete(commitTaskId);\n }\n });\n\n applyQueuedRefs();\n originalPreactCommit?.(vnode, commitQueue);\n },\n );\n}\n\n/**\n * Restores the commit option replaced by {@link replaceCommitHook} so tests\n * can clean up the global Preact `options` object. Assumes the matching\n * install was the most recent commit-option replacement; the snapshot and\n * ElementTemplate runtimes are separate entrypoints and never install their\n * commit hooks in the same context.\n */\nfunction removeCommitHookForTesting(): void {\n if (!commitHookInstalled) {\n return;\n }\n commitHookInstalled = false;\n if (previousCommit) {\n options[COMMIT] = previousCommit;\n previousCommit = undefined;\n } else {\n delete options[COMMIT];\n }\n}\n\n/**\n * Prepares the patch update for transmission to the native layer\n */\nfunction commitPatchUpdate(patchList: PatchList, patchOptions: GlobalPatchOptions): {\n data: string;\n patchOptions: PatchOptions;\n} {\n // console.debug('********** JS update:');\n // printSnapshotInstance(\n // (backgroundSnapshotInstanceManager.values.get(1) ?? backgroundSnapshotInstanceManager.values.get(-1))!,\n // );\n // console.debug('commitPatchUpdate:', prettyFormatSnapshotPatch(patchList.patchList[0]?.snapshotPatch));\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::commitChanges');\n }\n markTiming('packChangesStart');\n const obj: {\n data: string;\n patchOptions: PatchOptions;\n } = {\n data: JSON.stringify(patchList),\n patchOptions: {\n ...patchOptions,\n reloadVersion: getReloadVersion(),\n },\n };\n markTiming('packChangesEnd');\n if (globalPipelineOptions) {\n obj.patchOptions.pipelineOptions = globalPipelineOptions;\n setPipeline(undefined);\n }\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n\n return obj;\n}\n\n/**\n * Generates a unique ID for commit tasks\n */\nfunction genCommitTaskId(): number {\n return nextCommitTaskId++;\n}\n\n/**\n * Resets the commit task ID counter\n */\nfunction clearCommitTaskId(): void {\n nextCommitTaskId = 1;\n}\n\n/**\n * @internal\n */\nexport {\n clearCommitTaskId,\n commitPatchUpdate,\n genCommitTaskId,\n globalBackgroundSnapshotInstancesToRemove,\n globalCommitTaskMap,\n removeCommitHookForTesting,\n replaceCommitHook,\n type PatchList,\n type PatchOptions,\n};\n"]}
1
+ {"version":3,"file":"commit.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/commit.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;;;;;;GAUG;AAEH;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAKjC,OAAO,EACL,yCAAyC,EACzC,4CAA4C,GAC7C,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EACL,0BAA0B,EAC1B,8BAA8B,GAC/B,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,iCAAiC,EAAE,MAAM,sCAAsC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,mBAAmB,G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,CAAC,CAAC;IAC/B,MAAM,GAAG,GAGL;QACF,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;QAC/B,YAAY,EAAE;YACZ,GAAG,YAAY;YACf,aAAa,EAAE,gBAAgB,EAAE;SAClC;KACF,CAAC;IACF,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC7B,IAAI,qBAAqB,EAAE,CAAC;QAC1B,GAAG,CAAC,YAAY,CAAC,eAAe,GAAG,qBAAqB,CAAC;QACzD,WAAW,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,SAAS,eAAe;IACtB,OAAO,gBAAgB,EAAE,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,SAAS,iBAAiB;IACxB,gBAAgB,GAAG,CAAC,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,yCAAyC,EACzC,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,GAIlB,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\n/**\n * Implements the commit phase of the rendering lifecycle.\n * This module patches Preact's commit phase to integrate with the snapshot system,\n * handling the collection and transmission of patches between threads.\n *\n * The commit phase is responsible for:\n * - Collecting patches from the snapshot system\n * - Managing commit tasks and their execution\n * - Coordinating with the native layer for updates\n * - Handling performance timing and pipeline options\n */\n\n/**\n * This module patches Preact's commit phase by hacking into the internal of\n * its [options](https://preactjs.com/guide/v10/options/) API\n */\n\nimport { options } from 'preact';\nimport type { VNode } from 'preact';\n\nimport type { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport {\n globalBackgroundSnapshotInstancesToRemove,\n setGlobalBackgroundSnapshotInstancesToRemove,\n} from './globalState.js';\nimport { takeGlobalSnapshotPatch } from './snapshotPatch.js';\nimport type { SnapshotPatch } from './snapshotPatch.js';\nimport { takeGlobalFlushOptions } from '../../../core/commit-context.js';\nimport { globalPipelineOptions, markTiming, markTimingLegacy, setPipeline } 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 { profileEnd, profileStart } from '../../../shared/profile.js';\nimport { COMMIT } from '../../../shared/render-constants.js';\nimport { hook, isEmptyObject } from '../../../shared/utils.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\nimport { backgroundSnapshotInstanceManager } from '../../snapshot/backgroundSnapshot.js';\nimport { applyQueuedRefs } from '../../snapshot/ref.js';\nimport { sendMTRefInitValueToMainThread } from '../../worklet/ref/updateInitValue.js';\nimport { isRendering } from '../isRendering.js';\n\nconst globalCommitTaskMap: Map<number, () => void> = /*@__PURE__*/ new Map<number, () => void>();\nlet nextCommitTaskId = 1;\n\n/**\n * A single patch operation.\n */\ninterface Patch {\n // TODO: ref: do we need `id`?\n id: number;\n snapshotPatch?: SnapshotPatch;\n}\n\n/**\n * List of patches to be applied in a single update cycle with flush options.\n */\ninterface PatchList {\n patchList: Patch[];\n delayedRunOnMainThreadData?: RunWorkletCtxData[];\n flushOptions?: FlushOptions;\n}\n\n/**\n * Configuration options for patch operations\n */\ninterface PatchOptions {\n pipelineOptions?: PipelineOptions;\n reloadVersion: number;\n isHydration?: boolean;\n flowIds?: number[];\n}\n\n/**\n * Allow to pass options to the patch operation\n */\nexport type GlobalPatchOptions = Omit<PatchOptions, 'reloadVersion'>;\nexport let globalPatchOptions: GlobalPatchOptions = {};\n\nfunction takeGlobalPatchOptions(): GlobalPatchOptions {\n const res = globalPatchOptions;\n globalPatchOptions = {};\n return res;\n}\n\n/**\n * Delivers a collected commit and calls `finish` once it has been applied.\n */\ntype CommitTransport = (\n vnode: VNode,\n patchList: PatchList,\n patchOptions: GlobalPatchOptions,\n finish: () => void,\n) => void;\n\nconst nativeTransport: CommitTransport = (_vnode, patchList, patchOptions, finish) => {\n // Send the update to the native layer\n lynx.getNativeApp().callLepusMethod(\n LifecycleConstant.patchUpdate,\n commitPatchUpdate(patchList, patchOptions),\n finish,\n );\n};\n\nlet commitHookInstalled = false;\nlet previousCommit: typeof options[typeof COMMIT];\nlet commitTransport: CommitTransport = nativeTransport;\n\n/**\n * Replaces Preact's default commit hook with our custom implementation.\n * Calling it again only replaces the transport until {@link removeCommitHookForTesting} is called.\n */\nfunction replaceCommitHook(transport: CommitTransport = nativeTransport): void {\n commitTransport = transport;\n if (commitHookInstalled) {\n return;\n }\n commitHookInstalled = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n previousCommit = options[COMMIT];\n\n hook(\n options,\n COMMIT,\n (\n originalPreactCommit, // This is actually not used since Preact use `hooks._commit` for callbacks of `useLayoutEffect`.\n vnode,\n commitQueue,\n ) => {\n // Skip commit phase for MT runtime\n if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n // for testing only\n commitQueue.length = 0;\n return;\n }\n\n isRendering.value = false;\n\n // Mark the end of virtual DOM diffing phase for performance tracking\n markTimingLegacy('updateDiffVdomEnd');\n markTiming('diffVdomEnd');\n\n const backgroundSnapshotInstancesToRemove = globalBackgroundSnapshotInstancesToRemove;\n setGlobalBackgroundSnapshotInstancesToRemove([]);\n\n const commitTaskId = genCommitTaskId();\n\n // Register the commit task\n globalCommitTaskMap.set(commitTaskId, () => {\n if (backgroundSnapshotInstancesToRemove.length) {\n setTimeout(() => {\n backgroundSnapshotInstancesToRemove.forEach(id => {\n backgroundSnapshotInstanceManager.values.get(id)?.tearDown();\n });\n }, 10000);\n }\n });\n\n sendMTRefInitValueToMainThread();\n\n // Collect patches for this update\n const snapshotPatch = takeGlobalSnapshotPatch();\n const flushOptions = takeGlobalFlushOptions();\n const patchOptions = takeGlobalPatchOptions();\n if (!snapshotPatch) {\n // before hydration, skip patch\n applyQueuedRefs();\n originalPreactCommit?.(vnode, commitQueue);\n return;\n }\n\n const patch: Patch = {\n id: commitTaskId,\n };\n // TODO: check all fields in `flushOptions` from runtime3\n if (snapshotPatch.length) {\n patch.snapshotPatch = snapshotPatch;\n }\n const patchList: PatchList = {\n patchList: [patch],\n };\n if (!snapshotPatch.length && !delayedRunOnMainThreadData.length) {\n flushOptions.emptyPatch = true;\n }\n if (!isEmptyObject(flushOptions)) {\n patchList.flushOptions = flushOptions;\n }\n if (delayedRunOnMainThreadData.length) {\n patchList.delayedRunOnMainThreadData = takeDelayedRunOnMainThreadData();\n }\n commitTransport(vnode, patchList, patchOptions, () => {\n const commitTask = globalCommitTaskMap.get(commitTaskId);\n if (commitTask) {\n commitTask();\n globalCommitTaskMap.delete(commitTaskId);\n }\n });\n\n applyQueuedRefs();\n originalPreactCommit?.(vnode, commitQueue);\n },\n );\n}\n\n/**\n * Restores the commit option replaced by {@link replaceCommitHook} so tests\n * can clean up the global Preact `options` object. Assumes the matching\n * install was the most recent commit-option replacement; the snapshot and\n * ElementTemplate runtimes are separate entrypoints and never install their\n * commit hooks in the same context.\n */\nfunction removeCommitHookForTesting(): void {\n if (!commitHookInstalled) {\n return;\n }\n commitHookInstalled = false;\n commitTransport = nativeTransport;\n if (previousCommit) {\n options[COMMIT] = previousCommit;\n previousCommit = undefined;\n } else {\n delete options[COMMIT];\n }\n}\n\n/**\n * Prepares the patch update for transmission to the native layer\n */\nfunction commitPatchUpdate(patchList: PatchList, patchOptions: GlobalPatchOptions): {\n data: string;\n patchOptions: PatchOptions;\n} {\n // console.debug('********** JS update:');\n // printSnapshotInstance(\n // (backgroundSnapshotInstanceManager.values.get(1) ?? backgroundSnapshotInstanceManager.values.get(-1))!,\n // );\n // console.debug('commitPatchUpdate:', prettyFormatSnapshotPatch(patchList.patchList[0]?.snapshotPatch));\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::commitChanges');\n }\n markTiming('packChangesStart');\n const obj: {\n data: string;\n patchOptions: PatchOptions;\n } = {\n data: JSON.stringify(patchList),\n patchOptions: {\n ...patchOptions,\n reloadVersion: getReloadVersion(),\n },\n };\n markTiming('packChangesEnd');\n if (globalPipelineOptions) {\n obj.patchOptions.pipelineOptions = globalPipelineOptions;\n setPipeline(undefined);\n }\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n\n return obj;\n}\n\n/**\n * Generates a unique ID for commit tasks\n */\nfunction genCommitTaskId(): number {\n return nextCommitTaskId++;\n}\n\n/**\n * Resets the commit task ID counter\n */\nfunction clearCommitTaskId(): void {\n nextCommitTaskId = 1;\n}\n\n/**\n * @internal\n */\nexport {\n clearCommitTaskId,\n commitPatchUpdate,\n genCommitTaskId,\n globalBackgroundSnapshotInstancesToRemove,\n globalCommitTaskMap,\n removeCommitHookForTesting,\n replaceCommitHook,\n type CommitTransport,\n type PatchList,\n type PatchOptions,\n};\n"]}
@@ -1,2 +1,7 @@
1
+ import type { PatchOptions } from './commit.js';
2
+ declare function updateMainThread({ data, patchOptions }: {
3
+ data: string;
4
+ patchOptions: PatchOptions;
5
+ }): void;
1
6
  declare function injectUpdateMainThread(): void;
2
7
  export {};
@@ -96,5 +96,5 @@ function injectUpdateMainThread() {
96
96
  /**
97
97
  * @internal
98
98
  */
99
- export { injectUpdateMainThread };
99
+ export { injectUpdateMainThread, updateMainThread };
100
100
  //# sourceMappingURL=updateMainThread.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateMainThread.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/updateMainThread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAG/G,OAAO,EAAE,sBAAsB,EA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I,IAAI,0BAA0B,EAAE,CAAC;gBAC9C,IAAI,CAAC;oBACH,sBAAsB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAA4B,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;oBACxF,sBAAsB;gBACxB,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,IAAI,CAAC,WAAW,CAAC,CAAU,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC;YACD,4BAA4B,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,YAAY,CAAC,eAAe,EAAE,CAAC;YACjC,YAAY,CAAC,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC;QAC9D,CAAC;QACD,kBAAkB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAEzC,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;YAAS,CAAC;QACT,WAAW,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC;AACH,CAAC;AAED,SAAS,sBAAsB;IAC7B,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC;AACnF,CAAC;AAED;;GAEG;AACH,OAAO,EAAE,sBAAsB,EAAE,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 type { ClosureValueType } from '@lynx-js/react/worklet-runtime/bindings';\nimport { runRunOnMainThreadTask, setEomShouldFlushElementTree } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport type { PatchList, PatchOptions } from './commit.js';\nimport { setMainThreadHydrating } from './isMainThreadHydrating.js';\nimport { snapshotPatchApply } from './snapshotPatchApply.js';\nimport { markTiming, setPipeline } from '../../../core/performance.js';\nimport { getReloadVersion } from '../../../core/reload-version.js';\nimport { prettyFormatSnapshotPatch } from '../../debug/formatPatch.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\nimport { __pendingListUpdates } from '../../list/pendingListUpdates.js';\nimport { __page } from '../../snapshot/definition.js';\nimport { applyRefQueue } from '../../snapshot/workletRef.js';\nimport { isMtsEnabled } from '../../worklet/functionality.js';\n\nfunction updateMainThread(\n { data, patchOptions }: {\n data: string;\n patchOptions: PatchOptions;\n },\n): void {\n if ((patchOptions.reloadVersion) < getReloadVersion()) {\n return;\n }\n\n const flowIds = patchOptions.flowIds;\n if (flowIds) {\n lynx.performance.profileStart('ReactLynx::patch', {\n flowId: flowIds[0],\n flowIds,\n });\n }\n\n setPipeline(patchOptions.pipelineOptions);\n try {\n markTiming('mtsRenderStart');\n markTiming('parseChangesStart');\n const parsedData = JSON.parse(data) as PatchList;\n const { patchList, flushOptions = {}, delayedRunOnMainThreadData } = parsedData;\n\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] BTS -> MTS updateMainThread:\\n' + JSON.stringify(\n {\n data: {\n ...parsedData,\n patchList: parsedData.patchList.map(patch => ({\n ...patch,\n snapshotPatch: prettyFormatSnapshotPatch(patch.snapshotPatch),\n })),\n },\n patchOptions,\n },\n null,\n 2,\n ),\n );\n }\n\n markTiming('parseChangesEnd');\n markTiming('patchChangesStart');\n if (patchOptions.isHydration) {\n setMainThreadHydrating(true);\n }\n try {\n for (const { snapshotPatch, id } of patchList) {\n __pendingListUpdates.clearAttachedLists();\n if (snapshotPatch) {\n snapshotPatchApply(snapshotPatch, id, patchOptions.isHydration === true);\n }\n __pendingListUpdates.flush();\n // console.debug('********** Lepus updatePatch:');\n // printSnapshotInstance(snapshotInstanceManager.values.get(-1)!);\n }\n } finally {\n markTiming('patchChangesEnd');\n markTiming('mtsRenderEnd');\n if (patchOptions.isHydration) {\n setMainThreadHydrating(false);\n }\n }\n applyRefQueue();\n if (delayedRunOnMainThreadData && isMtsEnabled()) {\n setEomShouldFlushElementTree(false);\n for (const data of delayedRunOnMainThreadData) {\n try {\n runRunOnMainThreadTask(data.worklet, data.params as ClosureValueType[], data.resolveId);\n /* v8 ignore next 3 */\n } catch (e) {\n lynx.reportError(e as Error);\n }\n }\n setEomShouldFlushElementTree(true);\n }\n if (patchOptions.pipelineOptions) {\n flushOptions.pipelineOptions = patchOptions.pipelineOptions;\n }\n __FlushElementTree(__page, flushOptions);\n\n if (flowIds) {\n lynx.performance.profileEnd();\n }\n } finally {\n setPipeline(undefined);\n }\n}\n\nfunction injectUpdateMainThread(): void {\n Object.assign(globalThis, { [LifecycleConstant.patchUpdate]: updateMainThread });\n}\n\n/**\n * @internal\n */\nexport { injectUpdateMainThread };\n"]}
1
+ {"version":3,"file":"updateMainThread.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/updateMainThread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAG/G,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE9D,SAAS,gBAAgB,CACvB,EAAE,I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AAW,CAAC,UAAU,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;YAAS,CAAC;QACT,WAAW,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC;AACH,CAAC;AAED,SAAS,sBAAsB;IAC7B,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC;AACnF,CAAC;AAED;;GAEG;AACH,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,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 type { ClosureValueType } from '@lynx-js/react/worklet-runtime/bindings';\nimport { runRunOnMainThreadTask, setEomShouldFlushElementTree } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport type { PatchList, PatchOptions } from './commit.js';\nimport { setMainThreadHydrating } from './isMainThreadHydrating.js';\nimport { snapshotPatchApply } from './snapshotPatchApply.js';\nimport { markTiming, setPipeline } from '../../../core/performance.js';\nimport { getReloadVersion } from '../../../core/reload-version.js';\nimport { prettyFormatSnapshotPatch } from '../../debug/formatPatch.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\nimport { __pendingListUpdates } from '../../list/pendingListUpdates.js';\nimport { __page } from '../../snapshot/definition.js';\nimport { applyRefQueue } from '../../snapshot/workletRef.js';\nimport { isMtsEnabled } from '../../worklet/functionality.js';\n\nfunction updateMainThread(\n { data, patchOptions }: {\n data: string;\n patchOptions: PatchOptions;\n },\n): void {\n if ((patchOptions.reloadVersion) < getReloadVersion()) {\n return;\n }\n\n const flowIds = patchOptions.flowIds;\n if (flowIds) {\n lynx.performance.profileStart('ReactLynx::patch', {\n flowId: flowIds[0],\n flowIds,\n });\n }\n\n setPipeline(patchOptions.pipelineOptions);\n try {\n markTiming('mtsRenderStart');\n markTiming('parseChangesStart');\n const parsedData = JSON.parse(data) as PatchList;\n const { patchList, flushOptions = {}, delayedRunOnMainThreadData } = parsedData;\n\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] BTS -> MTS updateMainThread:\\n' + JSON.stringify(\n {\n data: {\n ...parsedData,\n patchList: parsedData.patchList.map(patch => ({\n ...patch,\n snapshotPatch: prettyFormatSnapshotPatch(patch.snapshotPatch),\n })),\n },\n patchOptions,\n },\n null,\n 2,\n ),\n );\n }\n\n markTiming('parseChangesEnd');\n markTiming('patchChangesStart');\n if (patchOptions.isHydration) {\n setMainThreadHydrating(true);\n }\n try {\n for (const { snapshotPatch, id } of patchList) {\n __pendingListUpdates.clearAttachedLists();\n if (snapshotPatch) {\n snapshotPatchApply(snapshotPatch, id, patchOptions.isHydration === true);\n }\n __pendingListUpdates.flush();\n // console.debug('********** Lepus updatePatch:');\n // printSnapshotInstance(snapshotInstanceManager.values.get(-1)!);\n }\n } finally {\n markTiming('patchChangesEnd');\n markTiming('mtsRenderEnd');\n if (patchOptions.isHydration) {\n setMainThreadHydrating(false);\n }\n }\n applyRefQueue();\n if (delayedRunOnMainThreadData && isMtsEnabled()) {\n setEomShouldFlushElementTree(false);\n for (const data of delayedRunOnMainThreadData) {\n try {\n runRunOnMainThreadTask(data.worklet, data.params as ClosureValueType[], data.resolveId);\n /* v8 ignore next 3 */\n } catch (e) {\n lynx.reportError(e as Error);\n }\n }\n setEomShouldFlushElementTree(true);\n }\n if (patchOptions.pipelineOptions) {\n flushOptions.pipelineOptions = patchOptions.pipelineOptions;\n }\n __FlushElementTree(__page, flushOptions);\n\n if (flowIds) {\n lynx.performance.profileEnd();\n }\n } finally {\n setPipeline(undefined);\n }\n}\n\nfunction injectUpdateMainThread(): void {\n Object.assign(globalThis, { [LifecycleConstant.patchUpdate]: updateMainThread });\n}\n\n/**\n * @internal\n */\nexport { injectUpdateMainThread, updateMainThread };\n"]}
@@ -25,7 +25,7 @@ declare function runDelayedUiOps(): void;
25
25
  */
26
26
  declare class RefProxy extends SelectorRefProxy<RefProxy> {
27
27
  private readonly refAttr;
28
- constructor(refAttr: [snapshotInstanceId: number, expIndex: number]);
28
+ constructor(refAttr: [snapshotInstanceId: number, expIndex: number], snapshotType?: string);
29
29
  protected createProxyTarget(): RefProxy;
30
30
  protected runOrDelay(task: () => void): void;
31
31
  get selector(): string;
@@ -45,10 +45,10 @@ function runDelayedUiOps() {
45
45
  */
46
46
  class RefProxy extends SelectorRefProxy {
47
47
  refAttr;
48
- constructor(refAttr) {
48
+ constructor(refAttr, snapshotType) {
49
49
  super();
50
50
  this.refAttr = refAttr;
51
- return this.createProxy();
51
+ return this.createProxy(snapshotType);
52
52
  }
53
53
  createProxyTarget() {
54
54
  return new RefProxy(this.refAttr);
@@ -1 +1 @@
1
- {"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/ref/delay.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAEzC;;;GAGG;AACH,MAAM,YAAY,GAAmB,EAAE,CAAC;AAExC;;;GAGG;AACH,SAAS,UAAU,CAAC,IAAgB;IAClC,IAAI,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC3B,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,IAAI,EAAE,CAAC;IACT,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,eAAe;IACtB,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC;IACnC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;IACxB,gBAAgB,CAAC,KAAK,GAAG,KAAK,CAAC;IAE/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,EAAE,CAAC;IACT,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,QAAS,SAAQ,gBAA0B;IAC9B,OAAO,CAAiD;IAEzE,YAAY,OAAuD;QACjE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAES,iBAAiB;QACzB,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAES,UAAU,CAAC,IAAgB;QACnC,UAAU,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IAED,IAAI,QAAQ;QACV,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACvE,OAAO,cAAc,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IACvD,CAAC;CACF;AAID;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,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 { SelectorRefProxy } from '../../../core/ref.js';\nimport type { RefProxyForwardedMethods } from '../../../core/ref.js';\nimport { hydrationMap } from '../../snapshot/snapshotInstanceHydrationMap.js';\n\n/**\n * A flag to indicate whether UI operations should be delayed.\n * When set to true, UI operations will be queued in the `delayedUiOps` array\n * and executed later when `runDelayedUiOps` is called.\n * This is used before hydration to ensure UI operations are batched\n * and executed at the appropriate time.\n */\nconst shouldDelayUiOps = { value: true };\n\n/**\n * An array of functions that will be executed later when `runDelayedUiOps` is called.\n * These functions contain UI operations that need to be delayed.\n */\nconst delayedUiOps: (() => void)[] = [];\n\n/**\n * Runs a task either immediately or delays it based on the `shouldDelayUiOps` flag.\n * @param task - The function to execute.\n */\nfunction runOrDelay(task: () => void): void {\n if (shouldDelayUiOps.value) {\n delayedUiOps.push(task);\n } else {\n task();\n }\n}\n\n/**\n * Executes all delayed UI operations.\n */\nfunction runDelayedUiOps(): void {\n const tasks = delayedUiOps.slice();\n delayedUiOps.length = 0;\n shouldDelayUiOps.value = false;\n\n for (const task of tasks) {\n task();\n }\n}\n\n/**\n * A proxy class designed for managing and executing reference-based tasks.\n * It delays the execution of tasks until hydration is complete.\n */\nclass RefProxy extends SelectorRefProxy<RefProxy> {\n private readonly refAttr: [snapshotInstanceId: number, expIndex: number];\n\n constructor(refAttr: [snapshotInstanceId: number, expIndex: number]) {\n super();\n this.refAttr = refAttr;\n\n return this.createProxy();\n }\n\n protected createProxyTarget(): RefProxy {\n return new RefProxy(this.refAttr);\n }\n\n protected runOrDelay(task: () => void): void {\n runOrDelay(task);\n }\n\n get selector(): string {\n const realRefId = hydrationMap.get(this.refAttr[0]) ?? this.refAttr[0];\n return `[react-ref-${realRefId}-${this.refAttr[1]}]`;\n }\n}\n\ninterface RefProxy extends RefProxyForwardedMethods<RefProxy> {}\n\n/**\n * @internal\n */\nexport { delayedUiOps, RefProxy, runDelayedUiOps, shouldDelayUiOps };\n"]}
1
+ {"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/ref/delay.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAEzC;;;GAGG;AACH,MAAM,YAAY,GAAmB,EAAE,CAAC;AAExC;;;GAGG;AACH,SAAS,UAAU,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that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { SelectorRefProxy } from '../../../core/ref.js';\nimport type { RefProxyForwardedMethods } from '../../../core/ref.js';\nimport { hydrationMap } from '../../snapshot/snapshotInstanceHydrationMap.js';\n\n/**\n * A flag to indicate whether UI operations should be delayed.\n * When set to true, UI operations will be queued in the `delayedUiOps` array\n * and executed later when `runDelayedUiOps` is called.\n * This is used before hydration to ensure UI operations are batched\n * and executed at the appropriate time.\n */\nconst shouldDelayUiOps = { value: true };\n\n/**\n * An array of functions that will be executed later when `runDelayedUiOps` is called.\n * These functions contain UI operations that need to be delayed.\n */\nconst delayedUiOps: (() => void)[] = [];\n\n/**\n * Runs a task either immediately or delays it based on the `shouldDelayUiOps` flag.\n * @param task - The function to execute.\n */\nfunction runOrDelay(task: () => void): void {\n if (shouldDelayUiOps.value) {\n delayedUiOps.push(task);\n } else {\n task();\n }\n}\n\n/**\n * Executes all delayed UI operations.\n */\nfunction runDelayedUiOps(): void {\n const tasks = delayedUiOps.slice();\n delayedUiOps.length = 0;\n shouldDelayUiOps.value = false;\n\n for (const task of tasks) {\n task();\n }\n}\n\n/**\n * A proxy class designed for managing and executing reference-based tasks.\n * It delays the execution of tasks until hydration is complete.\n */\nclass RefProxy extends SelectorRefProxy<RefProxy> {\n private readonly refAttr: [snapshotInstanceId: number, expIndex: number];\n\n constructor(\n refAttr: [snapshotInstanceId: number, expIndex: number],\n snapshotType?: string,\n ) {\n super();\n this.refAttr = refAttr;\n\n return this.createProxy(snapshotType);\n }\n\n protected createProxyTarget(): RefProxy {\n return new RefProxy(this.refAttr);\n }\n\n protected runOrDelay(task: () => void): void {\n runOrDelay(task);\n }\n\n get selector(): string {\n const realRefId = hydrationMap.get(this.refAttr[0]) ?? this.refAttr[0];\n return `[react-ref-${realRefId}-${this.refAttr[1]}]`;\n }\n}\n\ninterface RefProxy extends RefProxyForwardedMethods<RefProxy> {}\n\n/**\n * @internal\n */\nexport { delayedUiOps, RefProxy, runDelayedUiOps, shouldDelayUiOps };\n"]}
@@ -6,7 +6,6 @@
6
6
  * and background thread.
7
7
  */
8
8
  import { render } from 'preact';
9
- import { clearDelayedRunOnBackgroundFunctions } from '@lynx-js/react/worklet-runtime/bindings';
10
9
  import { destroyBackground } from './destroy.js';
11
10
  import { renderMainThread } from './render.js';
12
11
  import { canReEvalBackgroundEntry, canReEvalMainThreadEntry, installMainThreadReloadCompleter, reEvalBackgroundEntry, reEvalMainThreadEntry, } from '../../core/entry-reload.js';
@@ -14,7 +13,8 @@ import { increaseReloadVersion } from '../../core/reload-version.js';
14
13
  import { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';
15
14
  import { __root, setRoot } from '../../root.js';
16
15
  import { profileEnd, profileStart } from '../../shared/profile.js';
17
- import { isEmptyObject } from '../../utils.js';
16
+ import { isEmptyObject } from '../../shared/utils.js';
17
+ import { resetWorkletRuntimeForReload } from '../../worklet-runtime/bindings/lifecycle.js';
18
18
  import { LifecycleConstant } from '../lifecycle/constant.js';
19
19
  import { __pendingListUpdates } from '../list/pendingListUpdates.js';
20
20
  import { hydrate } from '../renderToOpcodes/hydrate.js';
@@ -27,7 +27,7 @@ function reloadMainThread(data, options) {
27
27
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
28
28
  profileStart('ReactLynx::reloadMainThread');
29
29
  }
30
- clearDelayedRunOnBackgroundFunctions();
30
+ resetWorkletRuntimeForReload();
31
31
  resetFunctionCallReturnListener();
32
32
  increaseReloadVersion();
33
33
  if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {
@@ -1 +1 @@
1
- {"version":3,"file":"reload.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/reload.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,oCAAoC,EAAE,MAAM,yCAAyC,CAAC;AAE/F,OAAO,E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AiB,CAAC,WAAW,EAAE,kBAAkB;YACjD;gBACE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;aAC7B;SACF,CAAC,CAAC;IACL,CAAC;IAED,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEpC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,UAA+B,EAAE,OAAiC;IAC1F,IAAI,wBAAwB,EAAE,EAAE,CAAC;QAC/B,qBAAqB,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE;YAC9C,kEAAkE;YAClE,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC;QAC3B,CAAC,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,6BAA6B,CAAC,CAAC;IAC9C,CAAC;IAED,iBAAiB,EAAE,CAAC;IACpB,qBAAqB,EAAE,CAAC;IAExB,2EAA2E;IAC3E,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEjE,gBAAgB,CAAC,KAAK,GAAG,IAAI,CAAC;IAC9B,iEAAiE;IACjE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAa,CAAC,CAAC;IAEpC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,gBAAgB,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\n/**\n * Implements the reload (thinking of \"refresh\" in browser) for both main thread\n * and background thread.\n */\n\nimport { render } from 'preact';\n\nimport { clearDelayedRunOnBackgroundFunctions } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { destroyBackground } from './destroy.js';\nimport { renderMainThread } from './render.js';\nimport {\n canReEvalBackgroundEntry,\n canReEvalMainThreadEntry,\n installMainThreadReloadCompleter,\n reEvalBackgroundEntry,\n reEvalMainThreadEntry,\n} from '../../core/entry-reload.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';\nimport { __root, setRoot } from '../../root.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { isEmptyObject } from '../../utils.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport { __pendingListUpdates } from '../list/pendingListUpdates.js';\nimport { hydrate } from '../renderToOpcodes/hydrate.js';\nimport { __page, setupPage } from '../snapshot/definition.js';\nimport { SnapshotInstance, snapshotInstanceManager } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\nimport { clearFirstScreenEventIdSwap, firstScreenSync } from './event/firstScreenSync.js';\nimport { shouldDelayUiOps } from './ref/delay.js';\n\nfunction reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n clearDelayedRunOnBackgroundFunctions();\n resetFunctionCallReturnListener();\n increaseReloadVersion();\n\n if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {\n Object.assign(lynx.__initData, data);\n }\n\n snapshotInstanceManager.clear();\n __pendingListUpdates.clearAttachedLists();\n clearFirstScreenEventIdSwap();\n\n const oldRoot = __root;\n if (canReEvalMainThreadEntry()) {\n reEvalMainThreadEntry<MainThreadReloadHandoff>({ oldRoot: oldRoot as SnapshotInstance, page: __page, options });\n return;\n }\n setRoot(new SnapshotInstance('root'));\n __root.__jsx = oldRoot.__jsx;\n finishMainThreadReload(oldRoot as SnapshotInstance, options);\n}\n\ninterface MainThreadReloadHandoff {\n oldRoot: SnapshotInstance;\n page: FiberElement;\n options: UpdatePageOption;\n}\n\nfunction completeMainThreadReload({ oldRoot, page, options }: MainThreadReloadHandoff): void {\n setupPage(page);\n finishMainThreadReload(oldRoot, options);\n}\n\ninstallMainThreadReloadCompleter(completeMainThreadReload);\n\nfunction finishMainThreadReload(oldRoot: SnapshotInstance, options: UpdatePageOption): void {\n renderMainThread();\n hydrate(oldRoot, __root as SnapshotInstance, {\n skipUnRef: true,\n });\n\n // always call this before `__FlushElementTree`\n __pendingListUpdates.flush();\n applyRefQueue();\n\n if (typeof lepusng_gc === 'function') {\n lepusng_gc();\n }\n\n if (firstScreenSync.isSynced) {\n __OnLifecycleEvent([\n LifecycleConstant.firstScreen, /* FIRST_SCREEN */\n {\n root: JSON.stringify(__root),\n },\n ]);\n }\n\n __FlushElementTree(__page, options);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nfunction reloadBackground(updateData: Record<string, any>, options?: Record<string, unknown>): void {\n if (canReEvalBackgroundEntry()) {\n reEvalBackgroundEntry(updateData, options, () => {\n // A queued `updateGlobalProps` callback must not render it again.\n __root.__jsx = undefined;\n });\n return;\n }\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadBackground');\n }\n\n destroyBackground();\n increaseReloadVersion();\n\n // COW when modify `lynx.__initData` to make sure Provider & Consumer works\n lynx.__initData = Object.assign({}, lynx.__initData, updateData);\n\n shouldDelayUiOps.value = true;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(__root.__jsx, __root as any);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nexport { completeMainThreadReload, reloadBackground, reloadMainThread };\n"]}
1
+ {"version":3,"file":"reload.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/reload.ts"],"names":[],"mappings":"AA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AAE,wBAAwB,EAAE,gBAAgB,EAAE,gBAAgB,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\n/**\n * Implements the reload (thinking of \"refresh\" in browser) for both main thread\n * and background thread.\n */\n\nimport { render } from 'preact';\n\nimport { destroyBackground } from './destroy.js';\nimport { renderMainThread } from './render.js';\nimport {\n canReEvalBackgroundEntry,\n canReEvalMainThreadEntry,\n installMainThreadReloadCompleter,\n reEvalBackgroundEntry,\n reEvalMainThreadEntry,\n} from '../../core/entry-reload.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';\nimport { __root, setRoot } from '../../root.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { isEmptyObject } from '../../shared/utils.js';\nimport { resetWorkletRuntimeForReload } from '../../worklet-runtime/bindings/lifecycle.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport { __pendingListUpdates } from '../list/pendingListUpdates.js';\nimport { hydrate } from '../renderToOpcodes/hydrate.js';\nimport { __page, setupPage } from '../snapshot/definition.js';\nimport { SnapshotInstance, snapshotInstanceManager } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\nimport { clearFirstScreenEventIdSwap, firstScreenSync } from './event/firstScreenSync.js';\nimport { shouldDelayUiOps } from './ref/delay.js';\n\nfunction reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n resetWorkletRuntimeForReload();\n resetFunctionCallReturnListener();\n increaseReloadVersion();\n\n if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {\n Object.assign(lynx.__initData, data);\n }\n\n snapshotInstanceManager.clear();\n __pendingListUpdates.clearAttachedLists();\n clearFirstScreenEventIdSwap();\n\n const oldRoot = __root;\n if (canReEvalMainThreadEntry()) {\n reEvalMainThreadEntry<MainThreadReloadHandoff>({ oldRoot: oldRoot as SnapshotInstance, page: __page, options });\n return;\n }\n setRoot(new SnapshotInstance('root'));\n __root.__jsx = oldRoot.__jsx;\n finishMainThreadReload(oldRoot as SnapshotInstance, options);\n}\n\ninterface MainThreadReloadHandoff {\n oldRoot: SnapshotInstance;\n page: FiberElement;\n options: UpdatePageOption;\n}\n\nfunction completeMainThreadReload({ oldRoot, page, options }: MainThreadReloadHandoff): void {\n setupPage(page);\n finishMainThreadReload(oldRoot, options);\n}\n\ninstallMainThreadReloadCompleter(completeMainThreadReload);\n\nfunction finishMainThreadReload(oldRoot: SnapshotInstance, options: UpdatePageOption): void {\n renderMainThread();\n hydrate(oldRoot, __root as SnapshotInstance, {\n skipUnRef: true,\n });\n\n // always call this before `__FlushElementTree`\n __pendingListUpdates.flush();\n applyRefQueue();\n\n if (typeof lepusng_gc === 'function') {\n lepusng_gc();\n }\n\n if (firstScreenSync.isSynced) {\n __OnLifecycleEvent([\n LifecycleConstant.firstScreen, /* FIRST_SCREEN */\n {\n root: JSON.stringify(__root),\n },\n ]);\n }\n\n __FlushElementTree(__page, options);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nfunction reloadBackground(updateData: Record<string, any>, options?: Record<string, unknown>): void {\n if (canReEvalBackgroundEntry()) {\n reEvalBackgroundEntry(updateData, options, () => {\n // A queued `updateGlobalProps` callback must not render it again.\n __root.__jsx = undefined;\n });\n return;\n }\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadBackground');\n }\n\n destroyBackground();\n increaseReloadVersion();\n\n // COW when modify `lynx.__initData` to make sure Provider & Consumer works\n lynx.__initData = Object.assign({}, lynx.__initData, updateData);\n\n shouldDelayUiOps.value = true;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(__root.__jsx, __root as any);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nexport { completeMainThreadReload, reloadBackground, reloadMainThread };\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 { cardLifetime } from '../../core/card-lifetime.js';
5
- import { maybePromise } from '../../utils.js';
5
+ import { maybePromise } from '../../shared/utils.js';
6
6
  import { LifecycleConstant } from '../lifecycle/constant.js';
7
7
  import { applyRefQueue } from '../snapshot/workletRef.js';
8
8
  export const gSignMap = /*#__PURE__*/ cardLifetime('listSignMap', () => ({}));
@@ -44,7 +44,7 @@ export function componentAtIndexFactory(ctx, hydrateFunction) {
44
44
  // Kept as a safeguard in case the callback is somehow invoked after list removal.
45
45
  throw new Error('componentAtIndex called on removed list');
46
46
  }
47
- /* v8 ignore end */
47
+ /* v8 ignore stop */
48
48
  const platformInfo = childCtx.__listItemPlatformInfo ?? {};
49
49
  // The lifecycle of this `__extraProps.isReady`:
50
50
  // 0 -> Promise<number> -> 1
@@ -119,7 +119,16 @@ export function componentAtIndexFactory(ctx, hydrateFunction) {
119
119
  }
120
120
  else {
121
121
  const newCtx = childCtx.takeElements();
122
- signMap.set(sign, newCtx);
122
+ for (const id in gSignMap) {
123
+ if (gSignMap[id].get(sign) === childCtx) {
124
+ gSignMap[id].set(sign, newCtx);
125
+ }
126
+ gRecycleMap[id]?.forEach((pool) => {
127
+ if (pool.get(sign) === childCtx) {
128
+ pool.set(sign, newCtx);
129
+ }
130
+ });
131
+ }
123
132
  }
124
133
  }
125
134
  if (recycleSignMap && recycleSignMap.size > 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/snapshot/list/list.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,gB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,CAAC,CAAC,CAAC,CAAC;YACvF,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IACD,OAAO,CAAC,gBAAgB,EAAE,kBAAkB,CAAU,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,+DAA+D;IAC/D,MAAM,gBAAgB,GAAG,CAAC,CAAe,EAAE,MAAc,EAAE,IAAY,EAAE,EAAE;QACzE,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC7D,CAAC;QAED,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;QACpC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO;QACT,CAAC;QAED,MAAM,YAAY,GAAG,QAAQ,CAAC,sBAAsB,IAAI,EAAE,CAAC;QAE3D,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5B,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACpC,CAAC;QACD,UAAU,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC,CAAC;IACF,OAAO,gBAAgB,CAAC;AAC1B,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.\nimport { cardLifetime } from '../../core/card-lifetime.js';\nimport { maybePromise } from '../../utils.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport type { SnapshotInstance } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\n\nexport const gSignMap: Record<number, Map<number, SnapshotInstance>> = /*#__PURE__*/ cardLifetime(\n 'listSignMap',\n () => ({}),\n);\nexport const gRecycleMap: Record<number, Map<string, Map<number, SnapshotInstance>>> = /*#__PURE__*/ cardLifetime(\n 'listRecycleMap',\n () => ({}),\n);\nconst gParentWeakMap: WeakMap<SnapshotInstance, unknown> = /*#__PURE__*/ new WeakMap();\nconst resolvedPromise = /* @__PURE__ */ Promise.resolve();\n\nexport function clearListGlobal(): void {\n for (const key in gSignMap) {\n delete gSignMap[key];\n }\n for (const key in gRecycleMap) {\n delete gRecycleMap[key];\n }\n}\n\nexport function componentAtIndexFactory(\n ctx: SnapshotInstance[],\n hydrateFunction: (before: SnapshotInstance, after: SnapshotInstance) => void,\n): [ComponentAtIndexCallback, ComponentAtIndexesCallback] {\n // A hack workaround to ensure childCtx has no direct reference through `__parent` to list,\n // to avoid memory leak.\n // TODO(hzy): make `__parent` a WeakRef or `#__parent` in the future.\n ctx.forEach((childCtx) => {\n if (gParentWeakMap.has(childCtx)) {\n // do it only once\n } else {\n gParentWeakMap.set(childCtx, childCtx.parentNode!);\n Object.defineProperty(childCtx, '__parent', {\n get: () => gParentWeakMap.get(childCtx)!,\n set: (value: unknown) => {\n gParentWeakMap.set(childCtx, value);\n },\n });\n }\n });\n\n const componentAtChildCtx = (\n list: FiberElement,\n listID: number,\n childCtx: SnapshotInstance,\n operationID: number,\n enableReuseNotification: boolean,\n enableBatchRender: boolean = false,\n asyncFlush: boolean = false,\n ) => {\n const signMap = gSignMap[listID];\n const recycleMap = gRecycleMap[listID];\n\n /* v8 ignore start */\n if (!signMap || !recycleMap) {\n // Theoretically unreachable since snapshotDestroyList clears componentAtIndex with a noop function.\n // Kept as a safeguard in case the callback is somehow invoked after list removal.\n throw new Error('componentAtIndex called on removed list');\n }\n /* v8 ignore end */\n\n const platformInfo = childCtx.__listItemPlatformInfo ?? {};\n\n // The lifecycle of this `__extraProps.isReady`:\n // 0 -> Promise<number> -> 1\n // 0: The initial state, the list-item is not ready yet, we will send a event to background\n // when `componentAtIndex` is called on it\n // Promise<number>: A promise that will be resolved when the list-item is ready\n // 1: The list-item is ready, we can use it to render the list\n if (childCtx.__extraProps?.['isReady'] === 0) {\n if (\n typeof __GetAttributeByName === 'function'\n && __GetAttributeByName(list, 'custom-list-name') === 'list-container'\n ) {\n // we are in supported env\n // do not throw\n } else {\n throw new Error(\n 'Unsupported: `<list-item/>` with `defer={true}` must be used with `<list custom-list-name=\"list-container\"/>`',\n );\n }\n\n // send a event to background to render the list-item\n __OnLifecycleEvent([LifecycleConstant.publishEvent, {\n handlerName: `${childCtx.__id}:__extraProps:onComponentAtIndex`,\n data: {},\n }]);\n\n // use a promise to track the list-item's readiness\n let p: Promise<number>;\n return (p = new Promise<number>((resolve) => {\n Object.defineProperty(childCtx.__extraProps, 'isReady', {\n set(isReady) {\n if (isReady === 1) {\n delete childCtx.__extraProps!['isReady'];\n childCtx.__extraProps!['isReady'] = 1;\n\n void resolvedPromise.then(() => {\n // the cellIndex may be changed already, but the `childCtx` is the same\n resolve(componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification));\n });\n }\n },\n get() {\n return p;\n },\n });\n }));\n } else if (maybePromise<number>(childCtx.__extraProps?.['isReady'])) {\n throw new Error('componentAtIndex was called on a pending deferred list item');\n }\n\n const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');\n const recycleSignMap = recycleMap.get(uniqID);\n\n if (childCtx.__elements) {\n /**\n * If this situation is encountered, there might be two cases:\n * 1. Reusing with itself\n * In this case, enqueueComponent will be triggered first, followed by componentAtIndex.\n * 2. Moving\n * In this case, the trigger order is uncertain; componentAtIndex might be triggered first, or enqueueComponent might be triggered first.\n *\n * When enqueueComponent is triggered first, there must be an item in the reuse pool with the same sign as here, which can be returned directly.\n * When componentAtIndex is triggered first, a clone needs to be made first, then follow the logic for adding or reusing. The cloned item will enter the reuse pool in the subsequent enqueueComponent.\n */\n const root = childCtx.__elements[0]!;\n const sign = __GetElementUniqueID(root);\n\n if (recycleSignMap?.has(sign)) {\n signMap.set(sign, childCtx);\n recycleSignMap.delete(sign);\n if (!enableBatchRender) {\n __FlushElementTree(root, { triggerLayout: true, operationID, elementID: sign, listID });\n } else if (enableBatchRender && asyncFlush) {\n __FlushElementTree(root, { asyncFlush: true });\n }\n // enableBatchRender == true && asyncFlush == false\n // in this case, no need to invoke __FlushElementTree because in the end of componentAtIndexes(), the list will invoke __FlushElementTree.\n return sign;\n } else {\n const newCtx = childCtx.takeElements();\n signMap.set(sign, newCtx);\n }\n }\n\n if (recycleSignMap && recycleSignMap.size > 0) {\n const [first] = recycleSignMap;\n const [sign, oldCtx] = first!;\n recycleSignMap.delete(sign);\n hydrateFunction(oldCtx, childCtx);\n oldCtx.unRenderElements();\n if (!oldCtx.__id) {\n oldCtx.tearDown();\n } else if (oldCtx.__extraProps?.['isReady'] === 1) {\n // send a event to background to recycle the list-item\n __OnLifecycleEvent([LifecycleConstant.publishEvent, {\n handlerName: `${oldCtx.__id}:__extraProps:onRecycleComponent`,\n data: {},\n }]);\n }\n const root = childCtx.__element_root!;\n applyRefQueue();\n // In the defer `list-item` scenario, `componentAtIndex` occurs with delay.\n // Within `componentAtIndex`, nodes that quickly appear and disappear due to re-layout will be enqueued again,\n // causing the mapping relationship between sign and SnapshotInstance to become corrupted.\n // This results in a SnapshotInstance without `__elements` being enqueued.\n signMap.set(sign, childCtx);\n if (!enableBatchRender) {\n const flushOptions: FlushOptions = {\n triggerLayout: true,\n operationID,\n elementID: sign,\n listID,\n };\n if (enableReuseNotification) {\n flushOptions.listReuseNotification = {\n listElement: list,\n itemKey: platformInfo['item-key']!,\n };\n }\n __FlushElementTree(root, flushOptions);\n } else if (enableBatchRender && asyncFlush) {\n const flushOptions: FlushOptions = {\n asyncFlush: true,\n };\n if (enableReuseNotification) {\n flushOptions.listReuseNotification = {\n listElement: list,\n itemKey: platformInfo['item-key']!,\n };\n }\n __FlushElementTree(root, flushOptions);\n }\n return sign;\n }\n\n childCtx.ensureElements();\n const root = childCtx.__element_root!;\n __AppendElement(list, root);\n const sign = __GetElementUniqueID(root);\n applyRefQueue();\n signMap.set(sign, childCtx);\n if (!enableBatchRender) {\n __FlushElementTree(root, {\n triggerLayout: true,\n operationID,\n elementID: sign,\n listID,\n });\n } else if (enableBatchRender && asyncFlush) {\n __FlushElementTree(root, {\n asyncFlush: true,\n });\n }\n return sign;\n };\n\n function componentAtIndex(\n list: FiberElement,\n listID: number,\n cellIndex: number,\n operationID: number,\n enableReuseNotification: boolean,\n ) {\n const childCtx = ctx[cellIndex];\n if (!childCtx) {\n throw new Error('childCtx not found');\n }\n const r = componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification);\n\n /* v8 ignore start */\n if (process.env['NODE_ENV'] === 'test') {\n return r;\n } else {\n return typeof r === 'number' ? r : undefined;\n }\n /* v8 ignore end */\n }\n\n function componentAtIndexes(\n list: FiberElement,\n listID: number,\n cellIndexes: number[],\n operationIDs: number[],\n enableReuseNotification: boolean,\n asyncFlush: boolean,\n ) {\n let hasUnready = false;\n const p: Array<Promise<number> | number> = [];\n\n cellIndexes.forEach((cellIndex, index) => {\n const operationID = operationIDs[index]!;\n const childCtx = ctx[cellIndex];\n if (!childCtx) {\n throw new Error('childCtx not found');\n }\n\n const u = componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification, true, asyncFlush);\n if (typeof u === 'number') {\n // ready\n } else {\n hasUnready = true;\n }\n p.push(u);\n });\n\n // We need __FlushElementTree twice:\n // 1. The first time is sync, we flush the items that are ready, with unready items' uiSign as -1.\n // 2. The second time is async, with all the uiSigns.\n // NOTE: The `operationIDs` passed to __FlushElementTree must be the one passed in,\n // not the one generated by any code here, to workaround a bug of Lynx Engine.\n // So we CANNOT split the `operationIDs` into two parts: one for ready items, one for unready items.\n if (hasUnready) {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n void Promise.all(p).then((uiSigns) => {\n __FlushElementTree(list, {\n triggerLayout: true,\n operationIDs,\n elementIDs: uiSigns,\n listID,\n });\n });\n }\n __FlushElementTree(list, {\n triggerLayout: true,\n operationIDs,\n elementIDs: cellIndexes.map((_, index) => typeof p[index] === 'number' ? p[index] : -1),\n listID,\n });\n }\n return [componentAtIndex, componentAtIndexes] as const;\n}\n\nexport function enqueueComponentFactory(): EnqueueComponentCallback {\n // eslint-disable-next-line unicorn/consistent-function-scoping\n const enqueueComponent = (_: FiberElement, listID: number, sign: number) => {\n const signMap = gSignMap[listID];\n const recycleMap = gRecycleMap[listID];\n if (!signMap || !recycleMap) {\n throw new Error('enqueueComponent called on removed list');\n }\n\n const childCtx = signMap.get(sign)!;\n if (!childCtx) {\n return;\n }\n\n const platformInfo = childCtx.__listItemPlatformInfo ?? {};\n\n const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');\n if (!recycleMap.has(uniqID)) {\n recycleMap.set(uniqID, new Map());\n }\n recycleMap.get(uniqID)!.set(sign, childCtx);\n };\n return enqueueComponent;\n}\n"]}
1
+ {"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/snapshot/list/list.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,MAAM,CAAC,MAAM,QAAQ,GAAkD,aAAa,CAAC,YAAY,CAC/F,aAAa,EACb,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CACX,CAAC;AACF,MAAM,CAAC,MAAM,WAAW,GAA+D,aAAa,CAAC,YAAY,CAC/G,gBAAgB,EAChB,GAAG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ache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { cardLifetime } from '../../core/card-lifetime.js';\nimport { maybePromise } from '../../shared/utils.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport type { SnapshotInstance } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\n\nexport const gSignMap: Record<number, Map<number, SnapshotInstance>> = /*#__PURE__*/ cardLifetime(\n 'listSignMap',\n () => ({}),\n);\nexport const gRecycleMap: Record<number, Map<string, Map<number, SnapshotInstance>>> = /*#__PURE__*/ cardLifetime(\n 'listRecycleMap',\n () => ({}),\n);\nconst gParentWeakMap: WeakMap<SnapshotInstance, unknown> = /*#__PURE__*/ new WeakMap();\nconst resolvedPromise = /* @__PURE__ */ Promise.resolve();\n\nexport function clearListGlobal(): void {\n for (const key in gSignMap) {\n delete gSignMap[key];\n }\n for (const key in gRecycleMap) {\n delete gRecycleMap[key];\n }\n}\n\nexport function componentAtIndexFactory(\n ctx: SnapshotInstance[],\n hydrateFunction: (before: SnapshotInstance, after: SnapshotInstance) => void,\n): [ComponentAtIndexCallback, ComponentAtIndexesCallback] {\n // A hack workaround to ensure childCtx has no direct reference through `__parent` to list,\n // to avoid memory leak.\n // TODO(hzy): make `__parent` a WeakRef or `#__parent` in the future.\n ctx.forEach((childCtx) => {\n if (gParentWeakMap.has(childCtx)) {\n // do it only once\n } else {\n gParentWeakMap.set(childCtx, childCtx.parentNode!);\n Object.defineProperty(childCtx, '__parent', {\n get: () => gParentWeakMap.get(childCtx)!,\n set: (value: unknown) => {\n gParentWeakMap.set(childCtx, value);\n },\n });\n }\n });\n\n const componentAtChildCtx = (\n list: FiberElement,\n listID: number,\n childCtx: SnapshotInstance,\n operationID: number,\n enableReuseNotification: boolean,\n enableBatchRender: boolean = false,\n asyncFlush: boolean = false,\n ) => {\n const signMap = gSignMap[listID];\n const recycleMap = gRecycleMap[listID];\n\n /* v8 ignore start */\n if (!signMap || !recycleMap) {\n // Theoretically unreachable since snapshotDestroyList clears componentAtIndex with a noop function.\n // Kept as a safeguard in case the callback is somehow invoked after list removal.\n throw new Error('componentAtIndex called on removed list');\n }\n /* v8 ignore stop */\n\n const platformInfo = childCtx.__listItemPlatformInfo ?? {};\n\n // The lifecycle of this `__extraProps.isReady`:\n // 0 -> Promise<number> -> 1\n // 0: The initial state, the list-item is not ready yet, we will send a event to background\n // when `componentAtIndex` is called on it\n // Promise<number>: A promise that will be resolved when the list-item is ready\n // 1: The list-item is ready, we can use it to render the list\n if (childCtx.__extraProps?.['isReady'] === 0) {\n if (\n typeof __GetAttributeByName === 'function'\n && __GetAttributeByName(list, 'custom-list-name') === 'list-container'\n ) {\n // we are in supported env\n // do not throw\n } else {\n throw new Error(\n 'Unsupported: `<list-item/>` with `defer={true}` must be used with `<list custom-list-name=\"list-container\"/>`',\n );\n }\n\n // send a event to background to render the list-item\n __OnLifecycleEvent([LifecycleConstant.publishEvent, {\n handlerName: `${childCtx.__id}:__extraProps:onComponentAtIndex`,\n data: {},\n }]);\n\n // use a promise to track the list-item's readiness\n let p: Promise<number>;\n return (p = new Promise<number>((resolve) => {\n Object.defineProperty(childCtx.__extraProps, 'isReady', {\n set(isReady) {\n if (isReady === 1) {\n delete childCtx.__extraProps!['isReady'];\n childCtx.__extraProps!['isReady'] = 1;\n\n void resolvedPromise.then(() => {\n // the cellIndex may be changed already, but the `childCtx` is the same\n resolve(componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification));\n });\n }\n },\n get() {\n return p;\n },\n });\n }));\n } else if (maybePromise<number>(childCtx.__extraProps?.['isReady'])) {\n throw new Error('componentAtIndex was called on a pending deferred list item');\n }\n\n const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');\n const recycleSignMap = recycleMap.get(uniqID);\n\n if (childCtx.__elements) {\n /**\n * If this situation is encountered, there might be two cases:\n * 1. Reusing with itself\n * In this case, enqueueComponent will be triggered first, followed by componentAtIndex.\n * 2. Moving\n * In this case, the trigger order is uncertain; componentAtIndex might be triggered first, or enqueueComponent might be triggered first.\n *\n * When enqueueComponent is triggered first, there must be an item in the reuse pool with the same sign as here, which can be returned directly.\n * When componentAtIndex is triggered first, a clone needs to be made first, then follow the logic for adding or reusing. The cloned item will enter the reuse pool in the subsequent enqueueComponent.\n */\n const root = childCtx.__elements[0]!;\n const sign = __GetElementUniqueID(root);\n\n if (recycleSignMap?.has(sign)) {\n signMap.set(sign, childCtx);\n recycleSignMap.delete(sign);\n if (!enableBatchRender) {\n __FlushElementTree(root, { triggerLayout: true, operationID, elementID: sign, listID });\n } else if (enableBatchRender && asyncFlush) {\n __FlushElementTree(root, { asyncFlush: true });\n }\n // enableBatchRender == true && asyncFlush == false\n // in this case, no need to invoke __FlushElementTree because in the end of componentAtIndexes(), the list will invoke __FlushElementTree.\n return sign;\n } else {\n const newCtx = childCtx.takeElements();\n for (const id in gSignMap) {\n if (gSignMap[id]!.get(sign) === childCtx) {\n gSignMap[id]!.set(sign, newCtx);\n }\n gRecycleMap[id]?.forEach((pool) => {\n if (pool.get(sign) === childCtx) {\n pool.set(sign, newCtx);\n }\n });\n }\n }\n }\n\n if (recycleSignMap && recycleSignMap.size > 0) {\n const [first] = recycleSignMap;\n const [sign, oldCtx] = first!;\n recycleSignMap.delete(sign);\n hydrateFunction(oldCtx, childCtx);\n oldCtx.unRenderElements();\n if (!oldCtx.__id) {\n oldCtx.tearDown();\n } else if (oldCtx.__extraProps?.['isReady'] === 1) {\n // send a event to background to recycle the list-item\n __OnLifecycleEvent([LifecycleConstant.publishEvent, {\n handlerName: `${oldCtx.__id}:__extraProps:onRecycleComponent`,\n data: {},\n }]);\n }\n const root = childCtx.__element_root!;\n applyRefQueue();\n // In the defer `list-item` scenario, `componentAtIndex` occurs with delay.\n // Within `componentAtIndex`, nodes that quickly appear and disappear due to re-layout will be enqueued again,\n // causing the mapping relationship between sign and SnapshotInstance to become corrupted.\n // This results in a SnapshotInstance without `__elements` being enqueued.\n signMap.set(sign, childCtx);\n if (!enableBatchRender) {\n const flushOptions: FlushOptions = {\n triggerLayout: true,\n operationID,\n elementID: sign,\n listID,\n };\n if (enableReuseNotification) {\n flushOptions.listReuseNotification = {\n listElement: list,\n itemKey: platformInfo['item-key']!,\n };\n }\n __FlushElementTree(root, flushOptions);\n } else if (enableBatchRender && asyncFlush) {\n const flushOptions: FlushOptions = {\n asyncFlush: true,\n };\n if (enableReuseNotification) {\n flushOptions.listReuseNotification = {\n listElement: list,\n itemKey: platformInfo['item-key']!,\n };\n }\n __FlushElementTree(root, flushOptions);\n }\n return sign;\n }\n\n childCtx.ensureElements();\n const root = childCtx.__element_root!;\n __AppendElement(list, root);\n const sign = __GetElementUniqueID(root);\n applyRefQueue();\n signMap.set(sign, childCtx);\n if (!enableBatchRender) {\n __FlushElementTree(root, {\n triggerLayout: true,\n operationID,\n elementID: sign,\n listID,\n });\n } else if (enableBatchRender && asyncFlush) {\n __FlushElementTree(root, {\n asyncFlush: true,\n });\n }\n return sign;\n };\n\n function componentAtIndex(\n list: FiberElement,\n listID: number,\n cellIndex: number,\n operationID: number,\n enableReuseNotification: boolean,\n ) {\n const childCtx = ctx[cellIndex];\n if (!childCtx) {\n throw new Error('childCtx not found');\n }\n const r = componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification);\n\n /* v8 ignore start */\n if (process.env['NODE_ENV'] === 'test') {\n return r;\n } else {\n return typeof r === 'number' ? r : undefined;\n }\n /* v8 ignore end */\n }\n\n function componentAtIndexes(\n list: FiberElement,\n listID: number,\n cellIndexes: number[],\n operationIDs: number[],\n enableReuseNotification: boolean,\n asyncFlush: boolean,\n ) {\n let hasUnready = false;\n const p: Array<Promise<number> | number> = [];\n\n cellIndexes.forEach((cellIndex, index) => {\n const operationID = operationIDs[index]!;\n const childCtx = ctx[cellIndex];\n if (!childCtx) {\n throw new Error('childCtx not found');\n }\n\n const u = componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification, true, asyncFlush);\n if (typeof u === 'number') {\n // ready\n } else {\n hasUnready = true;\n }\n p.push(u);\n });\n\n // We need __FlushElementTree twice:\n // 1. The first time is sync, we flush the items that are ready, with unready items' uiSign as -1.\n // 2. The second time is async, with all the uiSigns.\n // NOTE: The `operationIDs` passed to __FlushElementTree must be the one passed in,\n // not the one generated by any code here, to workaround a bug of Lynx Engine.\n // So we CANNOT split the `operationIDs` into two parts: one for ready items, one for unready items.\n if (hasUnready) {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n void Promise.all(p).then((uiSigns) => {\n __FlushElementTree(list, {\n triggerLayout: true,\n operationIDs,\n elementIDs: uiSigns,\n listID,\n });\n });\n }\n __FlushElementTree(list, {\n triggerLayout: true,\n operationIDs,\n elementIDs: cellIndexes.map((_, index) => typeof p[index] === 'number' ? p[index] : -1),\n listID,\n });\n }\n return [componentAtIndex, componentAtIndexes] as const;\n}\n\nexport function enqueueComponentFactory(): EnqueueComponentCallback {\n // eslint-disable-next-line unicorn/consistent-function-scoping\n const enqueueComponent = (_: FiberElement, listID: number, sign: number) => {\n const signMap = gSignMap[listID];\n const recycleMap = gRecycleMap[listID];\n if (!signMap || !recycleMap) {\n throw new Error('enqueueComponent called on removed list');\n }\n\n const childCtx = signMap.get(sign)!;\n if (!childCtx) {\n return;\n }\n\n const platformInfo = childCtx.__listItemPlatformInfo ?? {};\n\n const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');\n if (!recycleMap.has(uniqID)) {\n recycleMap.set(uniqID, new Map());\n }\n recycleMap.get(uniqID)!.set(sign, childCtx);\n };\n return enqueueComponent;\n}\n"]}
@@ -1,46 +1,16 @@
1
1
  // Copyright 2024 The Lynx Authors. All rights reserved.
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
- import { createProcessData } from '../../core/lynx-data-processors.js';
4
+ import { setupSharedLynxEnv } from '../../core/lynx/env.js';
5
5
  export function setupLynxEnv() {
6
- if (!__LEPUS__) {
7
- const { initData, updateData } = lynx.getApp()._params;
8
- lynx.__initData = { ...initData, ...updateData };
9
- lynx.registerDataProcessors = function () { };
10
- }
6
+ setupSharedLynxEnv();
11
7
  if (__LEPUS__) {
12
- lynx.__initData = {
13
- /* available only in renderPage */
14
- };
15
- // @ts-expect-error no type for lynx.SystemInfo
16
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
17
- globalThis.SystemInfo = lynx.SystemInfo ?? {};
18
8
  lynx.reportError = function (e) {
19
9
  const error = e instanceof Error ? e : new Error(JSON.stringify(e));
20
10
  _ReportError(error, {
21
11
  errorCode: 1101, // ErrCode::LYNX_ERROR_CODE_LEPUS in Lynx/base/debug/error_code.h
22
12
  });
23
13
  };
24
- lynx.triggerGlobalEventFromLepus = function (eventName, params) {
25
- __OnLifecycleEvent(['globalEventFromLepus', [eventName, params]]);
26
- };
27
- {
28
- // eslint-disable-next-line unicorn/consistent-function-scoping
29
- function __name(empty) {
30
- return `Native${empty}Modules`;
31
- }
32
- // TODO(hongzhiyuan.hzy): make sure this is run before any other code (especially code access `NativeModules`)
33
- // @ts-expect-error hack
34
- if (typeof globalThis[__name('')] === 'undefined') {
35
- // @ts-expect-error hack
36
- globalThis[__name('')] = undefined;
37
- }
38
- }
39
- lynx.registerDataProcessors = function (dataProcessorDefinition) {
40
- globalThis.processData = createProcessData(dataProcessorDefinition);
41
- };
42
- // register empty DataProcessors to make sure `globalThis.processData` is set
43
- lynx.registerDataProcessors();
44
14
  }
45
15
  }
46
16
  //# sourceMappingURL=env.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/snapshot/lynx/env.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAGvE,MAAM,UAAU,YAAY;IAC1B,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,MAAM,EA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AuB,CAAC,CAAC;QACtE,CAAC,CAAC;QAEF,6EAA6E;QAC7E,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAChC,CAAC;AACH,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.\nimport { createProcessData } from '../../core/lynx-data-processors.js';\nimport type { DataProcessorDefinition } from '../../lynx-api.js';\n\nexport function setupLynxEnv(): void {\n if (!__LEPUS__) {\n const { initData, updateData } = lynx.getApp()._params;\n lynx.__initData = { ...initData, ...updateData };\n lynx.registerDataProcessors = function() {};\n }\n\n if (__LEPUS__) {\n lynx.__initData = {\n /* available only in renderPage */\n };\n // @ts-expect-error no type for lynx.SystemInfo\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n globalThis.SystemInfo = lynx.SystemInfo ?? {};\n\n lynx.reportError = function(e: Error | string) {\n const error = e instanceof Error ? e : new Error(JSON.stringify(e));\n _ReportError(error, {\n errorCode: 1101, // ErrCode::LYNX_ERROR_CODE_LEPUS in Lynx/base/debug/error_code.h\n });\n };\n\n lynx.triggerGlobalEventFromLepus = function(\n eventName: string,\n params: any,\n ) {\n __OnLifecycleEvent(['globalEventFromLepus', [eventName, params]]);\n };\n\n {\n // eslint-disable-next-line unicorn/consistent-function-scoping\n function __name(empty: string) {\n return `Native${empty}Modules`;\n }\n // TODO(hongzhiyuan.hzy): make sure this is run before any other code (especially code access `NativeModules`)\n // @ts-expect-error hack\n if (typeof globalThis[__name('')] === 'undefined') {\n // @ts-expect-error hack\n globalThis[__name('')] = undefined;\n }\n }\n\n lynx.registerDataProcessors = function(\n dataProcessorDefinition?: DataProcessorDefinition,\n ) {\n globalThis.processData = createProcessData(dataProcessorDefinition);\n };\n\n // register empty DataProcessors to make sure `globalThis.processData` is set\n lynx.registerDataProcessors();\n }\n}\n"]}
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/snapshot/lynx/env.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,UAAU,YAAY;IAC1B,kBAAkB,EAAE,CAAC;IAErB,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,UAAS,CAAiB;YAC3C,MAAM,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;YACpE,YAAY,CAAC,KAAK,EAAE;gBAClB,SAAS,EAAE,IAAI,EAAE,iEAAiE;aACnF,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;AACH,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 { setupSharedLynxEnv } from '../../core/lynx/env.js';\n\nexport function setupLynxEnv(): void {\n setupSharedLynxEnv();\n\n if (__LEPUS__) {\n lynx.reportError = function(e: Error | string) {\n const error = e instanceof Error ? e : new Error(JSON.stringify(e));\n _ReportError(error, {\n errorCode: 1101, // ErrCode::LYNX_ERROR_CODE_LEPUS in Lynx/base/debug/error_code.h\n });\n };\n }\n}\n"]}
@@ -2,4 +2,6 @@ import { runWithForce } from './runWithForce.js';
2
2
  export { runWithForce };
3
3
  declare function injectTt(): void;
4
4
  declare function flushDelayedLifecycleEvents(): void;
5
- export { injectTt, flushDelayedLifecycleEvents };
5
+ /** Dispatches native events to their background handlers instead of delaying them. */
6
+ declare function enablePublishEvent(): void;
7
+ export { enablePublishEvent, injectTt, flushDelayedLifecycleEvents };
@@ -119,8 +119,7 @@ function onLifecycleEventImpl(type, data) {
119
119
  });
120
120
  delayedEvents.length = 0;
121
121
  }
122
- lynx.getApp().publishEvent = publishEvent;
123
- lynx.getApp().publicComponentEvent = publicComponentEvent;
122
+ enablePublishEvent();
124
123
  // console.debug("********** After hydration:");
125
124
  // printSnapshotInstance(__root as BackgroundSnapshotInstance);
126
125
  const commitTaskId = genCommitTaskId();
@@ -214,6 +213,11 @@ function publishEvent(handlerName, data) {
214
213
  function publicComponentEvent(_componentId, handlerName, data) {
215
214
  publishEvent(handlerName, data);
216
215
  }
216
+ /** Dispatches native events to their background handlers instead of delaying them. */
217
+ function enablePublishEvent() {
218
+ lynx.getApp().publishEvent = publishEvent;
219
+ lynx.getApp().publicComponentEvent = publicComponentEvent;
220
+ }
217
221
  function delayedPublicComponentEvent(_componentId, handlerName, data) {
218
222
  delayedPublishEvent(handlerName, data);
219
223
  }
@@ -227,5 +231,5 @@ function updateGlobalProps(newData) {
227
231
  },
228
232
  });
229
233
  }
230
- export { injectTt, flushDelayedLifecycleEvents };
234
+ export { enablePublishEvent, injectTt, flushDelayedLifecycleEvents };
231
235
  //# sourceMappingURL=tt.js.map