@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":"lynx-api.js","sourceRoot":"","sources":["../src/lynx-api.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AACxF,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AA+DpE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,IAAI,GAAS;IACxB,MAAM,EAAE,CAAC,GAAc,EAAQ,EAAE;QAC/B,sBAAsB;QACtB,IAAI,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EAAE,CAAC;YAC9D,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC;YACnB,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;gBACtD,YAAY,CAAC,6B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2BAA2B,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,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 { render } from 'preact';\nimport { createContext, createElement } from 'preact/compat';\nimport { useState } from 'preact/hooks';\nimport type { Consumer, FC, ReactNode } from 'react';\n\nimport { createGlobalProps } from './core/globalProps.js';\nimport type { GlobalProps } from './core/globalProps.js';\nimport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nimport { factory, withInitDataInState } from './core/initData.js';\nimport type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw } from './core/lynx-data-processors.js';\nimport { __root } from './root.js';\nimport { profileEnd, profileStart } from './shared/profile.js';\nimport { LifecycleConstant } from './snapshot/lifecycle/constant.js';\nimport { onFirstScreenSyncReady } from './snapshot/lifecycle/event/firstScreenSync.js';\nimport { flushDelayedLifecycleEvents } from './snapshot/lynx/tt.js';\n\n/**\n * The default root exported by `@lynx-js/react` for you to render a JSX\n * @public\n *\n * @group Types\n */\nexport interface Root {\n /**\n * Use this API to pass in your JSX to render\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * ```tsx\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * if (__MAIN_THREAD__) {\n * root.render(\n * <DataProvider data={DEFAULT_DATA}>\n * <App/>\n * </DataProvider>\n * );\n * } else if (__BACKGROUND__) {\n * fetchData().then((data) => {\n * root.render(\n * <DataProvider data={data}>\n * <App/>\n * </DataProvider>\n * ); // You can render later after your data is ready\n * })\n * }\n * ```\n *\n * @public\n */\n render: (jsx: ReactNode) => void;\n /**\n * {@inheritDoc Lynx.registerDataProcessors}\n * @deprecated use {@link Lynx.registerDataProcessors | lynx.registerDataProcessors} instead\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition) => void;\n}\n\n/**\n * The default and only root of ReactLynx for you to render JSX\n * @example\n * ```ts\n * import { root } from \"@lynx-js/react\"\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport const root: Root = {\n render: (jsx: ReactNode): void => {\n /* v8 ignore next 2 */\n if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n __root.__jsx = jsx;\n } else {\n __root.__jsx = jsx;\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::renderBackground');\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(jsx, __root as any);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'jsReady') {\n // `jsReady` is a special case of the `manual` first-screen sync: the\n // framework marks ready automatically once the background is ready.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n } else {\n // `immediately` or `manual`: the first screen is synced without waiting\n // for the background, so the `firstScreen` message might have been\n // reached when `root.render()` is called asynchronously.\n flushDelayedLifecycleEvents();\n }\n }\n },\n /* v8 ignore next 3 */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition): void => {\n lynx.registerDataProcessors(dataProcessorDefinition);\n },\n};\n\n/**\n * Mark the first screen as ready to sync when `firstScreenSyncTiming` is `'manual'`.\n *\n * The main thread holds the UI control until this is called, so the handover timing to\n * the background thread (for hydration) is fully controlled by the user. It can be called\n * from both threads (a background-thread call is forwarded to the main thread), is a no-op\n * unless `firstScreenSyncTiming` is `'manual'`, and has no further effect once called.\n *\n * @example\n *\n * ```ts\n * import { markFirstScreenSyncReady } from \"@lynx-js/react\"\n *\n * markFirstScreenSyncReady();\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport function markFirstScreenSyncReady(): void {\n if (__FIRST_SCREEN_SYNC_TIMING__ !== 'manual') {\n return;\n }\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // The sync happens on the main thread, forward the mark to it.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n return;\n }\n onFirstScreenSyncReady();\n}\n\nconst _InitData = /* @__PURE__ */ factory<InitData>(\n {\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n },\n '__initData',\n 'onDataChanged',\n);\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `initData`,\n * you must wrap your JSX inside it\n * @group Components\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <InitDataConsumer children={(initData) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <InitDataProvider>\n * <App/>\n * </InitDataProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _InitData.Provider();\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `initData`.\n * This should be used with {@link InitDataProvider}\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataConsumer: Consumer<InitData> = /* @__PURE__ */ _InitData.Consumer();\n/**\n * A React Hooks for you to get `initData`.\n * If `initData` is changed, a re-render will be triggered automatically.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const initData = useInitData();\n *\n * initData.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitData: () => InitData = /* @__PURE__ */ _InitData.use();\n/**\n * A React Hooks for you to get notified when `initData` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useInitDataChanged((data) => {\n * data.someProperty // can use it\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitDataChanged: (callback: (data: InitData) => void) => void = /* @__PURE__ */ _InitData.useChanged();\n\nexport type { GlobalProps } from './core/globalProps.js';\n\nconst _GlobalProps = /* @__PURE__ */ createGlobalProps<GlobalProps>({\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n});\n\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`; in the default `'reactive'` mode it renders its children directly\n * and updates come from a full re-render.\n * @group Components\n *\n * @example\n *\n * With `globalPropsMode: 'event'`:\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <GlobalPropsConsumer children={(globalProps) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <GlobalPropsProvider>\n * <App/>\n * </GlobalPropsProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _GlobalProps.Provider();\n\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`, together with {@link GlobalPropsProvider}; in the default `'reactive'` mode\n * it calls `children` with `lynx.__globalProps` directly and updates come from a full re-render.\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsConsumer: Consumer<GlobalProps> = /* @__PURE__ */ _GlobalProps.Consumer();\n\n/**\n * A React Hooks for you to get `lynx.__globalProps`.\n * With `globalPropsMode: 'event'`, the component re-renders when `lynx.__globalProps` changes;\n * in the default `'reactive'` mode, updates arrive through a full re-render.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const globalProps = useGlobalProps();\n *\n * globalProps.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalProps: () => GlobalProps = /* @__PURE__ */ _GlobalProps.use();\n\n/**\n * A React Hooks for you to get notified when `__globalProps` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useGlobalPropsChanged((data) => {\n * lynx.__globalProps.someProperty // can use lynx.__globalProps\n * data.someProperty // can use data\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalPropsChanged: (callback: (data: GlobalProps) => void) => void = /* @__PURE__ */ _GlobalProps\n .useChanged();\n\nexport type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw };\nexport { withInitDataInState };\n\n/**\n * APIs under `lynx` global variable that added by ReactLynx.\n *\n * @example\n *\n * ```ts\n * lynx.registerDataProcessors(...);\n * lynx.querySelector(...);\n * lynx.querySelectorAll(...);\n * ```\n *\n * @public\n *\n * @group Types\n */\nexport interface Lynx {\n /**\n * An alias of `lynx.getJSModule(\"GlobalEventEmitter\").trigger(eventName, params)` only in Lepus\n *\n * @public\n */\n triggerGlobalEventFromLepus: (eventName: string, params: any) => void;\n\n /**\n * Register DataProcessors. You MUST call this before `root.render()`.\n *\n * @example\n *\n * You MUST call `lynx.registerDataProcessors` before calling `root.render()`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * // You MUST call this before `root.render()`\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {...} // default DataProcessor\n * dataProcessors: {\n * getScreenMetricsOverride: () => {...} // named DataProcessor\n * }\n * })\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * If you have a class component with `static defaultDataProcessor`\n * or `static dataProcessors`, you can use it to register DataProcessors.\n *\n * ```ts\n * import { root, Component } from \"@lynx-js/react\"\n *\n * class App extends Component {\n * static defaultDataProcessor() {\n * ...\n * }\n *\n * static dataProcessors = {\n * getScreenMetricsOverride() {\n * ...\n * }\n * }\n * }\n *\n * lynx.registerDataProcessors(App); // You can pass `App` because it has the required shape\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * interface ExistingInterface {\n * somePropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitDataRaw extends ExistingInterface {\n * someAnotherCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: (initDataRaw) => {\n * initDataRaw.somePropertyFromExistingInterface // will be typed\n * }\n * })\n *\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { useInitData } from \"@lynx-js/react\"\n *\n * interface AnotherExistingInterface {\n * someAnotherPropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitData extends AnotherExistingInterface {\n * someCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {\n * return {\n * someCustomProperty: 'value', // will be typed\n * someAnotherPropertyFromExistingInterface: 1, // will be typed\n * }\n * }\n * })\n *\n * function App() {\n * const initData = useInitData();\n *\n * initData.someCustomProperty // will be typed\n * initData.someAnotherPropertyFromExistingInterface // will be typed\n * }\n *\n * ```\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void;\n}\n\nexport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nexport { runOnBackground } from './core/background-function/run-on-background.js';\nexport { runOnMainThread } from './snapshot/worklet/call/runOnMainThread.js';\nexport { MainThreadRef, useMainThreadRef } from './core/main-thread-ref.js';\nexport { defineMainThreadObjectType, useMainThreadObject } from './core/main-thread-object.js';\nexport type {\n MainThreadObjectHandle,\n MainThreadObjectType,\n MainThreadObjectTypeDefinition,\n} from './core/main-thread-object.js';\n"]}
1
+ {"version":3,"file":"lynx-api.js","sourceRoot":"","sources":["../src/lynx-api.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa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M,WAAW,GAAmB,eAAe,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;AAC3E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAiD,eAAe,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;AAIvH,MAAM,YAAY,GAAG,eAAe,CAAC,iBAAiB,CAAc;IAClE,aAAa;IACb,QAAQ;IACR,aAAa;IACb,0BAA0B;CAC3B,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,oDAAoD;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAA6C,eAAe,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;AAErH;;;;;;;;GAQG;AACH,oDAAoD;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAA0B,eAAe,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;AAElG;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB,eAAe,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;AAEpF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAoD,eAAe,CAAC,YAAY;KAC/G,UAAU,EAAE,CAAC;AAGhB,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAwI/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,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 { render } from 'preact';\nimport { createContext, createElement } from 'preact/compat';\nimport { useState } from 'preact/hooks';\nimport type { Consumer, FC, ReactNode } from 'react';\n\nimport { createGlobalProps } from './core/globalProps.js';\nimport type { GlobalProps } from './core/globalProps.js';\nimport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nimport { factory, withInitDataInState } from './core/initData.js';\nimport type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw } from './core/lynx-data-processors.js';\nimport { __root, transferMode, warnRootRenderOnTransferPage } from './root.js';\nimport { profileEnd, profileStart } from './shared/profile.js';\nimport { LifecycleConstant } from './snapshot/lifecycle/constant.js';\nimport { onFirstScreenSyncReady } from './snapshot/lifecycle/event/firstScreenSync.js';\nimport { flushDelayedLifecycleEvents } from './snapshot/lynx/tt.js';\n\n/**\n * The default root exported by `@lynx-js/react` for you to render a JSX\n * @public\n *\n * @group Types\n */\nexport interface Root {\n /**\n * Use this API to pass in your JSX to render\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * ```tsx\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * if (__MAIN_THREAD__) {\n * root.render(\n * <DataProvider data={DEFAULT_DATA}>\n * <App/>\n * </DataProvider>\n * );\n * } else if (__BACKGROUND__) {\n * fetchData().then((data) => {\n * root.render(\n * <DataProvider data={data}>\n * <App/>\n * </DataProvider>\n * ); // You can render later after your data is ready\n * })\n * }\n * ```\n *\n * @public\n */\n render: (jsx: ReactNode) => void;\n /**\n * {@inheritDoc Lynx.registerDataProcessors}\n * @deprecated use {@link Lynx.registerDataProcessors | lynx.registerDataProcessors} instead\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition) => void;\n}\n\n/**\n * The default and only root of ReactLynx for you to render JSX\n * @example\n * ```ts\n * import { root } from \"@lynx-js/react\"\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport const root: Root = {\n render: (jsx: ReactNode): void => {\n // Transfer pages render only registered components; the page root stays empty.\n if (transferMode) {\n warnRootRenderOnTransferPage();\n return;\n }\n /* v8 ignore next 2 */\n if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n __root.__jsx = jsx;\n } else {\n __root.__jsx = jsx;\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::renderBackground');\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(jsx, __root as any);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'jsReady') {\n // `jsReady` is a special case of the `manual` first-screen sync: the\n // framework marks ready automatically once the background is ready.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n } else {\n // `immediately` or `manual`: the first screen is synced without waiting\n // for the background, so the `firstScreen` message might have been\n // reached when `root.render()` is called asynchronously.\n flushDelayedLifecycleEvents();\n }\n }\n },\n /* v8 ignore next 3 */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition): void => {\n lynx.registerDataProcessors(dataProcessorDefinition);\n },\n};\n\n/**\n * Mark the first screen as ready to sync when `firstScreenSyncTiming` is `'manual'`.\n *\n * The main thread holds the UI control until this is called, so the handover timing to\n * the background thread (for hydration) is fully controlled by the user. It can be called\n * from both threads (a background-thread call is forwarded to the main thread), is a no-op\n * unless `firstScreenSyncTiming` is `'manual'`, and has no further effect once called.\n *\n * @example\n *\n * ```ts\n * import { markFirstScreenSyncReady } from \"@lynx-js/react\"\n *\n * markFirstScreenSyncReady();\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport function markFirstScreenSyncReady(): void {\n if (__FIRST_SCREEN_SYNC_TIMING__ !== 'manual') {\n return;\n }\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // The sync happens on the main thread, forward the mark to it.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n return;\n }\n onFirstScreenSyncReady();\n}\n\nconst _InitData = /* @__PURE__ */ factory<InitData>(\n {\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n },\n '__initData',\n 'onDataChanged',\n);\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `initData`,\n * you must wrap your JSX inside it\n * @group Components\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <InitDataConsumer children={(initData) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <InitDataProvider>\n * <App/>\n * </InitDataProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _InitData.Provider();\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `initData`.\n * This should be used with {@link InitDataProvider}\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataConsumer: Consumer<InitData> = /* @__PURE__ */ _InitData.Consumer();\n/**\n * A React Hooks for you to get `initData`.\n * If `initData` is changed, a re-render will be triggered automatically.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const initData = useInitData();\n *\n * initData.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitData: () => InitData = /* @__PURE__ */ _InitData.use();\n/**\n * A React Hooks for you to get notified when `initData` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useInitDataChanged((data) => {\n * data.someProperty // can use it\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitDataChanged: (callback: (data: InitData) => void) => void = /* @__PURE__ */ _InitData.useChanged();\n\nexport type { GlobalProps } from './core/globalProps.js';\n\nconst _GlobalProps = /* @__PURE__ */ createGlobalProps<GlobalProps>({\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n});\n\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`; in the default `'reactive'` mode it renders its children directly\n * and updates come from a full re-render.\n * @group Components\n *\n * @example\n *\n * With `globalPropsMode: 'event'`:\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <GlobalPropsConsumer children={(globalProps) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <GlobalPropsProvider>\n * <App/>\n * </GlobalPropsProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _GlobalProps.Provider();\n\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`, together with {@link GlobalPropsProvider}; in the default `'reactive'` mode\n * it calls `children` with `lynx.__globalProps` directly and updates come from a full re-render.\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsConsumer: Consumer<GlobalProps> = /* @__PURE__ */ _GlobalProps.Consumer();\n\n/**\n * A React Hooks for you to get `lynx.__globalProps`.\n * With `globalPropsMode: 'event'`, the component re-renders when `lynx.__globalProps` changes;\n * in the default `'reactive'` mode, updates arrive through a full re-render.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const globalProps = useGlobalProps();\n *\n * globalProps.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalProps: () => GlobalProps = /* @__PURE__ */ _GlobalProps.use();\n\n/**\n * A React Hooks for you to get notified when `__globalProps` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useGlobalPropsChanged((data) => {\n * lynx.__globalProps.someProperty // can use lynx.__globalProps\n * data.someProperty // can use data\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalPropsChanged: (callback: (data: GlobalProps) => void) => void = /* @__PURE__ */ _GlobalProps\n .useChanged();\n\nexport type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw };\nexport { withInitDataInState };\n\n/**\n * APIs under `lynx` global variable that added by ReactLynx.\n *\n * @example\n *\n * ```ts\n * lynx.registerDataProcessors(...);\n * lynx.querySelector(...);\n * lynx.querySelectorAll(...);\n * ```\n *\n * @public\n *\n * @group Types\n */\nexport interface Lynx {\n /**\n * An alias of `lynx.getJSModule(\"GlobalEventEmitter\").trigger(eventName, params)` only in Lepus\n *\n * @public\n */\n triggerGlobalEventFromLepus: (eventName: string, params: any) => void;\n\n /**\n * Register DataProcessors. You MUST call this before `root.render()`.\n *\n * @example\n *\n * You MUST call `lynx.registerDataProcessors` before calling `root.render()`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * // You MUST call this before `root.render()`\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {...} // default DataProcessor\n * dataProcessors: {\n * getScreenMetricsOverride: () => {...} // named DataProcessor\n * }\n * })\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * If you have a class component with `static defaultDataProcessor`\n * or `static dataProcessors`, you can use it to register DataProcessors.\n *\n * ```ts\n * import { root, Component } from \"@lynx-js/react\"\n *\n * class App extends Component {\n * static defaultDataProcessor() {\n * ...\n * }\n *\n * static dataProcessors = {\n * getScreenMetricsOverride() {\n * ...\n * }\n * }\n * }\n *\n * lynx.registerDataProcessors(App); // You can pass `App` because it has the required shape\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * interface ExistingInterface {\n * somePropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitDataRaw extends ExistingInterface {\n * someAnotherCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: (initDataRaw) => {\n * initDataRaw.somePropertyFromExistingInterface // will be typed\n * }\n * })\n *\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { useInitData } from \"@lynx-js/react\"\n *\n * interface AnotherExistingInterface {\n * someAnotherPropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitData extends AnotherExistingInterface {\n * someCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {\n * return {\n * someCustomProperty: 'value', // will be typed\n * someAnotherPropertyFromExistingInterface: 1, // will be typed\n * }\n * }\n * })\n *\n * function App() {\n * const initData = useInitData();\n *\n * initData.someCustomProperty // will be typed\n * initData.someAnotherPropertyFromExistingInterface // will be typed\n * }\n *\n * ```\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void;\n}\n\nexport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nexport { runOnBackground } from './core/background-function/run-on-background.js';\nexport { runOnMainThread } from './snapshot/worklet/call/runOnMainThread.js';\nexport { MainThreadRef, useMainThreadRef } from './core/main-thread-ref.js';\nexport { defineMainThreadObjectType, useMainThreadObject } from './core/main-thread-object.js';\nexport type {\n MainThreadObjectHandle,\n MainThreadObjectType,\n MainThreadObjectTypeDefinition,\n} from './core/main-thread-object.js';\n"]}
@@ -4,11 +4,12 @@
4
4
  import { options } from 'preact';
5
5
  // to make sure preact's hooks to register earlier than ours
6
6
  import './core/hooks/react.js';
7
+ import { setupComponentStack } from './core/component-stack.js';
7
8
  import { document, setupBackgroundDocument } from './document.js';
8
- import { setupComponentStack } from './shared/component-stack.js';
9
+ import { lynxQueueMicrotask } from './shared/microtask.js';
9
10
  import { isProfiling } from './shared/profile.js';
10
11
  import { initElementPAPICallAlog } from './snapshot/alog/elementPAPICall.js';
11
- import { initAlog } from './snapshot/alog/index.js';
12
+ import { initRenderAlog } from './snapshot/alog/render.js';
12
13
  import { initProfileHook } from './snapshot/debug/profileHooks.js';
13
14
  import { setupVNodeSourceHook } from './snapshot/debug/vnodeSource.js';
14
15
  import { replaceCommitHook } from './snapshot/lifecycle/patch/commit.js';
@@ -21,7 +22,6 @@ import { initTimingAPI } from './snapshot/lynx/performance.js';
21
22
  import { injectPrepareLazyBundleMTS } from './snapshot/lynx/prepareLazyBundleMTS.js';
22
23
  import { injectTt } from './snapshot/lynx/tt.js';
23
24
  import { injectUpdateMTRefInitValue } from './snapshot/worklet/ref/updateInitValue.js';
24
- import { lynxQueueMicrotask } from './utils.js';
25
25
  export { runWithForce } from './snapshot/lynx/runWithForce.js';
26
26
  // @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature
27
27
  if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__ && typeof globalThis.processEvalResult === 'undefined') {
@@ -54,7 +54,7 @@ if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__ && typeof __PROFIL
54
54
  }
55
55
  if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
56
56
  // We are logging both main-thread and background.
57
- initAlog();
57
+ initRenderAlog();
58
58
  }
59
59
  if (typeof __ALOG_ELEMENT_API__ !== 'undefined' && __ALOG_ELEMENT_API__) {
60
60
  initElementPAPICallAlog();
@@ -1 +1 @@
1
- {"version":3,"file":"lynx.js","sourceRoot":"","sources":["../src/lynx.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,4DAA4D;AAC5D,OAAO,uBAAuB,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,WAAW,EAA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WAAW,EAAE,CAAC;YAChB,eAAe,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC;AAED,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,cAAc,EAAE,CAAC;IAC5D,qBAAqB,EAAE,CAAC;AAC1B,CAAC;AAED,YAAY,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.\nimport { options } from 'preact';\n// to make sure preact's hooks to register earlier than ours\nimport './core/hooks/react.js';\n\nimport { document, setupBackgroundDocument } from './document.js';\nimport { setupComponentStack } from './shared/component-stack.js';\nimport { isProfiling } from './shared/profile.js';\nimport { initElementPAPICallAlog } from './snapshot/alog/elementPAPICall.js';\nimport { initAlog } from './snapshot/alog/index.js';\nimport { initProfileHook } from './snapshot/debug/profileHooks.js';\nimport { setupVNodeSourceHook } from './snapshot/debug/vnodeSource.js';\nimport { replaceCommitHook } from './snapshot/lifecycle/patch/commit.js';\nimport { addCtxNotFoundEventListener } from './snapshot/lifecycle/patch/error.js';\nimport { injectUpdateMainThread } from './snapshot/lifecycle/patch/updateMainThread.js';\nimport { injectCalledByNative } from './snapshot/lynx/calledByNative.js';\nimport { setupLynxEnv } from './snapshot/lynx/env.js';\nimport { injectLepusMethods } from './snapshot/lynx/injectLepusMethods.js';\nimport { initTimingAPI } from './snapshot/lynx/performance.js';\nimport { injectPrepareLazyBundleMTS } from './snapshot/lynx/prepareLazyBundleMTS.js';\nimport { injectTt } from './snapshot/lynx/tt.js';\nimport { injectUpdateMTRefInitValue } from './snapshot/worklet/ref/updateInitValue.js';\nimport { lynxQueueMicrotask } from './utils.js';\n\nexport { runWithForce } from './snapshot/lynx/runWithForce.js';\n\n// @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__ && typeof globalThis.processEvalResult === 'undefined') {\n // @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature\n globalThis.processEvalResult = <T>(result: ((schema: string) => T) | undefined, schema: string) => {\n return result?.(schema);\n };\n}\n\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n injectCalledByNative();\n injectUpdateMainThread();\n injectUpdateMTRefInitValue();\n if (\n typeof __LAZY_BUNDLE_FETCHER__ !== 'undefined'\n && __LAZY_BUNDLE_FETCHER__ === 'FetchBundle'\n ) {\n injectPrepareLazyBundleMTS();\n }\n // `injectLepusMethods` exposes the snapshot <-> element mapping that preact\n // devtools relies on, so it must also run when devtools is enabled in\n // production via `REACT_DEVTOOL=true`.\n if (__DEV__ || (typeof __REACT_DEVTOOL__ !== 'undefined' && __REACT_DEVTOOL__)) {\n injectLepusMethods();\n }\n}\n\nif (__DEV__) {\n setupComponentStack();\n}\n\n// We are profiling both main-thread and background.\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__ && typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n initProfileHook();\n}\n\nif (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n // We are logging both main-thread and background.\n initAlog();\n}\nif (typeof __ALOG_ELEMENT_API__ !== 'undefined' && __ALOG_ELEMENT_API__) {\n initElementPAPICallAlog();\n}\n\nfunction initBackgroundRuntime(): void {\n // Trick Preact and TypeScript to accept our custom document adapter.\n options.document = document as unknown as Document;\n options.requestAnimationFrame = lynxQueueMicrotask;\n setupBackgroundDocument();\n injectTt();\n addCtxNotFoundEventListener();\n\n if (process.env['NODE_ENV'] === 'test') {}\n else {\n replaceCommitHook();\n initTimingAPI();\n if (__DEV__ && isProfiling) {\n setupVNodeSourceHook();\n }\n if (isProfiling) {\n initProfileHook();\n }\n }\n}\n\nif (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n initBackgroundRuntime();\n}\n\nsetupLynxEnv();\n"]}
1
+ {"version":3,"file":"lynx.js","sourceRoot":"","sources":["../src/lynx.ts"],"names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AC;IAC1B,QAAQ,EAAE,CAAC;IACX,2BAA2B,EAAE,CAAC;IAE9B,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,MAAM,EAAE,CAAC,CAAA,CAAC;SACrC,CAAC;QACJ,iBAAiB,EAAE,CAAC;QACpB,aAAa,EAAE,CAAC;QAChB,IAAI,OAAO,IAAI,WAAW,EAAE,CAAC;YAC3B,oBAAoB,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,WAAW,EAAE,CAAC;YAChB,eAAe,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC;AAED,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,cAAc,EAAE,CAAC;IAC5D,qBAAqB,EAAE,CAAC;AAC1B,CAAC;AAED,YAAY,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.\nimport { options } from 'preact';\n// to make sure preact's hooks to register earlier than ours\nimport './core/hooks/react.js';\n\nimport { setupComponentStack } from './core/component-stack.js';\nimport { document, setupBackgroundDocument } from './document.js';\nimport { lynxQueueMicrotask } from './shared/microtask.js';\nimport { isProfiling } from './shared/profile.js';\nimport { initElementPAPICallAlog } from './snapshot/alog/elementPAPICall.js';\nimport { initRenderAlog } from './snapshot/alog/render.js';\nimport { initProfileHook } from './snapshot/debug/profileHooks.js';\nimport { setupVNodeSourceHook } from './snapshot/debug/vnodeSource.js';\nimport { replaceCommitHook } from './snapshot/lifecycle/patch/commit.js';\nimport { addCtxNotFoundEventListener } from './snapshot/lifecycle/patch/error.js';\nimport { injectUpdateMainThread } from './snapshot/lifecycle/patch/updateMainThread.js';\nimport { injectCalledByNative } from './snapshot/lynx/calledByNative.js';\nimport { setupLynxEnv } from './snapshot/lynx/env.js';\nimport { injectLepusMethods } from './snapshot/lynx/injectLepusMethods.js';\nimport { initTimingAPI } from './snapshot/lynx/performance.js';\nimport { injectPrepareLazyBundleMTS } from './snapshot/lynx/prepareLazyBundleMTS.js';\nimport { injectTt } from './snapshot/lynx/tt.js';\nimport { injectUpdateMTRefInitValue } from './snapshot/worklet/ref/updateInitValue.js';\n\nexport { runWithForce } from './snapshot/lynx/runWithForce.js';\n\n// @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__ && typeof globalThis.processEvalResult === 'undefined') {\n // @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature\n globalThis.processEvalResult = <T>(result: ((schema: string) => T) | undefined, schema: string) => {\n return result?.(schema);\n };\n}\n\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n injectCalledByNative();\n injectUpdateMainThread();\n injectUpdateMTRefInitValue();\n if (\n typeof __LAZY_BUNDLE_FETCHER__ !== 'undefined'\n && __LAZY_BUNDLE_FETCHER__ === 'FetchBundle'\n ) {\n injectPrepareLazyBundleMTS();\n }\n // `injectLepusMethods` exposes the snapshot <-> element mapping that preact\n // devtools relies on, so it must also run when devtools is enabled in\n // production via `REACT_DEVTOOL=true`.\n if (__DEV__ || (typeof __REACT_DEVTOOL__ !== 'undefined' && __REACT_DEVTOOL__)) {\n injectLepusMethods();\n }\n}\n\nif (__DEV__) {\n setupComponentStack();\n}\n\n// We are profiling both main-thread and background.\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__ && typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n initProfileHook();\n}\n\nif (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n // We are logging both main-thread and background.\n initRenderAlog();\n}\nif (typeof __ALOG_ELEMENT_API__ !== 'undefined' && __ALOG_ELEMENT_API__) {\n initElementPAPICallAlog();\n}\n\nfunction initBackgroundRuntime(): void {\n // Trick Preact and TypeScript to accept our custom document adapter.\n options.document = document as unknown as Document;\n options.requestAnimationFrame = lynxQueueMicrotask;\n setupBackgroundDocument();\n injectTt();\n addCtxNotFoundEventListener();\n\n if (process.env['NODE_ENV'] === 'test') {}\n else {\n replaceCommitHook();\n initTimingAPI();\n if (__DEV__ && isProfiling) {\n setupVNodeSourceHook();\n }\n if (isProfiling) {\n initProfileHook();\n }\n }\n}\n\nif (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n initBackgroundRuntime();\n}\n\nsetupLynxEnv();\n"]}
@@ -15,4 +15,8 @@ declare let __root: (SnapshotInstance | BackgroundSnapshotInstance) & {
15
15
  nodeType?: Element['nodeType'];
16
16
  };
17
17
  declare function setRoot(root: typeof __root): void;
18
- export { __root, setRoot };
18
+ /** Set once a page renders transfer components; `root.render` is then ignored. */
19
+ declare let transferMode: boolean;
20
+ declare function enableTransferMode(): void;
21
+ declare function warnRootRenderOnTransferPage(): void;
22
+ export { __root, enableTransferMode, setRoot, transferMode, warnRootRenderOnTransferPage };
@@ -21,5 +21,16 @@ if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {
21
21
  else if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
22
22
  setRoot(new BackgroundSnapshotInstance('root'));
23
23
  }
24
- export { __root, setRoot };
24
+ /** Set once a page renders transfer components; `root.render` is then ignored. */
25
+ let transferMode = false;
26
+ function enableTransferMode() {
27
+ transferMode = true;
28
+ }
29
+ function warnRootRenderOnTransferPage() {
30
+ if (__DEV__) {
31
+ console.warn('[ReactLynx] `root.render` is ignored on transfer pages. '
32
+ + 'Render components through `TransferRegistry.registerComponent` instead of mixing both.');
33
+ }
34
+ }
35
+ export { __root, enableTransferMode, setRoot, transferMode, warnRootRenderOnTransferPage };
25
36
  //# sourceMappingURL=root.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"root.js","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE;;;GAGG;AACH,IAAI,MAUH,CAAC;AAEF,SAAS,OAAO,CAAC,IAAmB;IAClC,MAAM,GAAG,IAAI,CAAC;IAEd,kDAAkD;IAClD,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACtB,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,IAAI,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EAAE,CAAC;IAC9D,OAAO,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;AACxC,CAAC;KAAM,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,cAAc,EAAE,CAAC;IACnE,OAAO,CAAC,IAAI,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,OAAO,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.\nimport { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js';\nimport { SnapshotInstance } from './snapshot/snapshot/snapshot.js';\n\n/**\n * The internal ReactLynx's root.\n * {@link @lynx-js/react!Root | root}.\n */\nlet __root: (SnapshotInstance | BackgroundSnapshotInstance) & {\n __jsx?: React.ReactNode;\n __opcodes?: any[];\n\n /**\n * Returns the type of node.\n *\n * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/nodeType)\n */\n nodeType?: Element['nodeType'];\n};\n\nfunction setRoot(root: typeof __root): void {\n __root = root;\n\n // A fake ELEMENT_NODE to make preact/debug happy.\n if (__DEV__ && __root) {\n __root.nodeType = 1;\n }\n}\n\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n setRoot(new SnapshotInstance('root'));\n} else if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n setRoot(new BackgroundSnapshotInstance('root'));\n}\n\nexport { __root, setRoot };\n"]}
1
+ {"version":3,"file":"root.js","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE;;;GAGG;AACH,IAAI,MAUH,CAAC;AAEF,SAAS,OAAO,CAAC,IAAmB;IAClC,MAAM,GAAG,IAAI,CAAC;IAEd,kDAAkD;IAClD,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACtB,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,IAAI,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EAAE,CAAC;IAC9D,OAAO,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;AACxC,CAAC;KAAM,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,cAAc,EAAE,CAAC;IACnE,OAAO,CAAC,IAAI,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,kFAAkF;AAClF,IAAI,YAAY,GAAG,KAAK,CAAC;AAEzB,SAAS,kBAAkB;IACzB,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC;AAED,SAAS,4BAA4B;IACnC,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CACV,0DAA0D;cACtD,wFAAwF,CAC7F,CAAC;IACJ,CAAC;AACH,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,4BAA4B,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.\nimport { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js';\nimport { SnapshotInstance } from './snapshot/snapshot/snapshot.js';\n\n/**\n * The internal ReactLynx's root.\n * {@link @lynx-js/react!Root | root}.\n */\nlet __root: (SnapshotInstance | BackgroundSnapshotInstance) & {\n __jsx?: React.ReactNode;\n __opcodes?: any[];\n\n /**\n * Returns the type of node.\n *\n * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/nodeType)\n */\n nodeType?: Element['nodeType'];\n};\n\nfunction setRoot(root: typeof __root): void {\n __root = root;\n\n // A fake ELEMENT_NODE to make preact/debug happy.\n if (__DEV__ && __root) {\n __root.nodeType = 1;\n }\n}\n\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n setRoot(new SnapshotInstance('root'));\n} else if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n setRoot(new BackgroundSnapshotInstance('root'));\n}\n\n/** Set once a page renders transfer components; `root.render` is then ignored. */\nlet transferMode = false;\n\nfunction enableTransferMode(): void {\n transferMode = true;\n}\n\nfunction warnRootRenderOnTransferPage(): void {\n if (__DEV__) {\n console.warn(\n '[ReactLynx] `root.render` is ignored on transfer pages. '\n + 'Render components through `TransferRegistry.registerComponent` instead of mixing both.',\n );\n }\n}\n\nexport { __root, enableTransferMode, setRoot, transferMode, warnRootRenderOnTransferPage };\n"]}
@@ -0,0 +1 @@
1
+ export declare const lynxQueueMicrotask: typeof lynx.queueMicrotask;
@@ -0,0 +1,28 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ export const lynxQueueMicrotask = /* @__PURE__ */ (() => {
5
+ if (lynx.queueMicrotask) {
6
+ return (fn) => lynx.queueMicrotask(fn);
7
+ }
8
+ else if (typeof globalThis.Promise === 'function') {
9
+ const resolved = globalThis.Promise.resolve();
10
+ /* v8 ignore start */
11
+ return (fn) => {
12
+ // Schedule as a microtask, and surface exceptions like queueMicrotask would.
13
+ resolved.then(fn).catch((err) => {
14
+ setTimeout(() => {
15
+ throw err;
16
+ }, 0);
17
+ });
18
+ };
19
+ }
20
+ else {
21
+ // Fallback to macrotask when microtasks aren't available.
22
+ return (fn) => {
23
+ setTimeout(fn, 0);
24
+ };
25
+ }
26
+ /* v8 ignore stop */
27
+ })();
28
+ //# sourceMappingURL=microtask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"microtask.js","sourceRoot":"","sources":["../../src/shared/microtask.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAC,MAAM,kBAAkB,GAA+B,eAAe,CAAC,CAAC,GAAG,EAAE;IAClF,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;QACxB,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;SAAM,IAAI,OAAO,UAAU,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QACpD,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC9C,qBAAqB;QACrB,OAAO,CAAC,EAAE,EAAE,EAAE;YACZ,6EAA6E;YAC7E,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC9B,UAAU,CAAC,GAAG,EAAE;oBACd,MAAM,GAAG,CAAC;gBACZ,CAAC,EAAE,CAAC,CAAC,CAAC;YACR,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,0DAA0D;QAC1D,OAAO,CAAC,EAAE,EAAE,EAAE;YACZ,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QACpB,CAAC,CAAC;IACJ,CAAC;IACD,oBAAoB;AACtB,CAAC,CAAC,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\nexport const lynxQueueMicrotask: typeof lynx.queueMicrotask = /* @__PURE__ */ (() => {\n if (lynx.queueMicrotask) {\n return (fn) => lynx.queueMicrotask(fn);\n } else if (typeof globalThis.Promise === 'function') {\n const resolved = globalThis.Promise.resolve();\n /* v8 ignore start */\n return (fn) => {\n // Schedule as a microtask, and surface exceptions like queueMicrotask would.\n resolved.then(fn).catch((err) => {\n setTimeout(() => {\n throw err;\n }, 0);\n });\n };\n } else {\n // Fallback to macrotask when microtasks aren't available.\n return (fn) => {\n setTimeout(fn, 0);\n };\n }\n /* v8 ignore stop */\n})();\n"]}
@@ -0,0 +1,8 @@
1
+ export declare const noop: (...args: unknown[]) => unknown;
2
+ export declare function isEmptyObject(obj?: object): obj is Record<string, never>;
3
+ export declare function maybePromise<T>(value: unknown): value is Promise<T>;
4
+ export declare function getDisplayName(type: {
5
+ displayName?: string | undefined;
6
+ name: string;
7
+ }): string;
8
+ export declare function hook<T, K extends keyof T>(object: T, key: K, fn: Required<T>[K] extends (...args: infer P) => infer Q ? ((old?: T[K], ...args: P) => Q) : never): void;
@@ -0,0 +1,27 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ /* v8 ignore start */
5
+ export const noop = () => { };
6
+ /* v8 ignore stop */
7
+ export function isEmptyObject(obj) {
8
+ for (const _ in obj)
9
+ return false;
10
+ return true;
11
+ }
12
+ export function maybePromise(value) {
13
+ return (typeof value === 'object'
14
+ && value !== null
15
+ // @ts-expect-error the check is safe
16
+ && typeof value.then === 'function');
17
+ }
18
+ export function getDisplayName(type) {
19
+ return type.displayName ?? type.name;
20
+ }
21
+ export function hook(object, key, fn) {
22
+ const oldFn = object[key];
23
+ object[key] = function (...args) {
24
+ return fn.call(this, oldFn, ...args);
25
+ };
26
+ }
27
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/shared/utils.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,qBAAqB;AACrB,MAAM,CAAC,MAAM,IAAI,GAAoC,GAAG,EAAE,GAAE,CAAC,CAAC;AAC9D,oBAAoB;AAEpB,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,KAAK,MAAM,CAAC,IAAI,GAAG;QAAE,OAAO,KAAK,CAAC;IAClC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,YAAY,CAAI,KAAc;IAC5C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;WACtB,KAAK,KAAK,IAAI;QACjB,qCAAqC;WAClC,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CACpC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAwD;IACrF,OAAO,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,IAAI,CAClB,MAAS,EACT,GAAM,EACN,EACS;IAET,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,CAAC,GAAG,UAAkB,GAAG,IAAe;QAChD,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;IACvC,CAAS,CAAC;AACZ,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/* v8 ignore start */\nexport const noop: (...args: unknown[]) => unknown = () => {};\n/* v8 ignore stop */\n\nexport function isEmptyObject(obj?: object): obj is Record<string, never> {\n for (const _ in obj) return false;\n return true;\n}\n\nexport function maybePromise<T>(value: unknown): value is Promise<T> {\n return (\n typeof value === 'object'\n && value !== null\n // @ts-expect-error the check is safe\n && typeof value.then === 'function'\n );\n}\n\nexport function getDisplayName(type: { displayName?: string | undefined; name: string }): string {\n return type.displayName ?? type.name;\n}\n\nexport function hook<T, K extends keyof T>(\n object: T,\n key: K,\n fn: Required<T>[K] extends (...args: infer P) => infer Q ? ((old?: T[K], ...args: P) => Q)\n : never,\n): void {\n const oldFn = object[key];\n object[key] = function(this: T, ...args: unknown[]) {\n return fn.call(this, oldFn, ...args);\n } as T[K];\n}\n"]}
@@ -1 +1,2 @@
1
1
  export declare function isSdkVersionGt(major: number, minor: number): boolean;
2
+ export declare function isRunOnBackgroundEnabled(): boolean;
@@ -7,7 +7,9 @@ export function isSdkVersionGt(major, minor) {
7
7
  ?? lynx.SystemInfo?.lynxSdkVersion
8
8
  ?? '1.0';
9
9
  const version = lynxSdkVersion.split('.');
10
- return (Number(version[0]) > major
11
- || (Number(version[0]) == major && Number(version[1]) > minor));
10
+ return Number(version[0]) > major || (Number(version[0]) == major && Number(version[1]) > minor);
11
+ }
12
+ export function isRunOnBackgroundEnabled() {
13
+ return isSdkVersionGt(2, 15);
12
14
  }
13
15
  //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,KAAa;IACzD,6EAA6E;IAC7E,MAAM,cAAc,GAAI,UAA+D,CAAC,UAAU,EAAE,cAAc;WAC5G,IAAmD,CAAC,UAAU,EAAE,cAAc;WAC/E,KAAK,CAAC;IACX,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;AACnG,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/B,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\nexport function isSdkVersionGt(major: number, minor: number): boolean {\n // Worklet initialization can run before ReactLynx installs the global alias.\n const lynxSdkVersion = (globalThis as typeof globalThis & { SystemInfo?: ISystemInfo }).SystemInfo?.lynxSdkVersion\n ?? (lynx as typeof lynx & { SystemInfo?: ISystemInfo }).SystemInfo?.lynxSdkVersion\n ?? '1.0';\n const version = lynxSdkVersion.split('.');\n return Number(version[0]) > major || (Number(version[0]) == major && Number(version[1]) > minor);\n}\n\nexport function isRunOnBackgroundEnabled(): boolean {\n return isSdkVersionGt(2, 15);\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { options } from 'preact';
5
5
  import { DIFFED, DOM } from '../../shared/render-constants.js';
6
- import { getDisplayName } from '../../utils.js';
6
+ import { getDisplayName } from '../../shared/utils.js';
7
7
  export function initRenderAlog() {
8
8
  // eslint-disable-next-line @typescript-eslint/unbound-method
9
9
  const oldAfterDiff = options[DIFFED];
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/snapshot/alog/render.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD,MAAM,UAAU,cAAc;IAC5B,6DAA6D;IAC7D,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,OAAO,CAAC,MAAM,CAAC,GAAG,UAAS,KAA0C;QACnE,8BAA8B;QAC9B,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACrC,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,kBAAkB,CAAC;YACvE,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,IAAsB,CAAC,CAAC;YACjE,qCAAqC;YACrC,IAAI,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EAAE,CAAC;gBAC9D,OAAO,CAAC,IAAI,EAAE,CACZ,IAAI,UAAU,4BAA4B,WAAW,EAAE,CACxD,CAAC;YACJ,CAAC;iBAAM,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,cAAc,EAAE,CAAC;gBACnE,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;gBACvB,OAAO,CAAC,IAAI,EAAE,CACZ,IAAI,UAAU,4BAA4B,WAAW,aAAa,GAAG,EAAE,IAAI,WAAW,GAAG,EAAE,IAAI,EAAE,CAClG,CAAC;YACJ,CAAC;QACH,CAAC;QACD,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC,CAAC;AACJ,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 { options } from 'preact';\nimport type { ComponentClass, VNode } from 'preact';\n\nimport { DIFFED, DOM } from '../../shared/render-constants.js';\nimport { getDisplayName } from '../../utils.js';\nimport type { SnapshotInstance } from '../snapshot/snapshot.js';\n\nexport function initRenderAlog(): void {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldAfterDiff = options[DIFFED];\n options[DIFFED] = function(vnode: VNode & { [DOM]: SnapshotInstance }) {\n // Only log on component vnode\n if (typeof vnode.type === 'function') {\n const threadName = __MAIN_THREAD__ ? 'MainThread' : 'BackgroundThread';\n const displayName = getDisplayName(vnode.type as ComponentClass);\n // log the component render into Alog\n if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n console.alog?.(\n `[${threadName} Component Render] name: ${displayName}`,\n );\n } else if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const dom = vnode[DOM];\n console.alog?.(\n `[${threadName} Component Render] name: ${displayName}, uniqID: ${dom?.type}, __id: ${dom?.__id}`,\n );\n }\n }\n oldAfterDiff?.(vnode);\n };\n}\n"]}
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/snapshot/alog/render.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD,MAAM,UAAU,cAAc;IAC5B,6DAA6D;IAC7D,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,OAAO,CAAC,MAAM,CAAC,GAAG,UAAS,KAA0C;QACnE,8BAA8B;QAC9B,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACrC,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,kBAAkB,CAAC;YACvE,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,IAAsB,CAAC,CAAC;YACjE,qCAAqC;YACrC,IAAI,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EAAE,CAAC;gBAC9D,OAAO,CAAC,IAAI,EAAE,CACZ,IAAI,UAAU,4BAA4B,WAAW,EAAE,CACxD,CAAC;YACJ,CAAC;iBAAM,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,cAAc,EAAE,CAAC;gBACnE,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;gBACvB,OAAO,CAAC,IAAI,EAAE,CACZ,IAAI,UAAU,4BAA4B,WAAW,aAAa,GAAG,EAAE,IAAI,WAAW,GAAG,EAAE,IAAI,EAAE,CAClG,CAAC;YACJ,CAAC;QACH,CAAC;QACD,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC,CAAC;AACJ,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 { options } from 'preact';\nimport type { ComponentClass, VNode } from 'preact';\n\nimport { DIFFED, DOM } from '../../shared/render-constants.js';\nimport { getDisplayName } from '../../shared/utils.js';\nimport type { SnapshotInstance } from '../snapshot/snapshot.js';\n\nexport function initRenderAlog(): void {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldAfterDiff = options[DIFFED];\n options[DIFFED] = function(vnode: VNode & { [DOM]: SnapshotInstance }) {\n // Only log on component vnode\n if (typeof vnode.type === 'function') {\n const threadName = __MAIN_THREAD__ ? 'MainThread' : 'BackgroundThread';\n const displayName = getDisplayName(vnode.type as ComponentClass);\n // log the component render into Alog\n if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n console.alog?.(\n `[${threadName} Component Render] name: ${displayName}`,\n );\n } else if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const dom = vnode[DOM];\n console.alog?.(\n `[${threadName} Component Render] name: ${displayName}, uniqID: ${dom?.type}, __id: ${dom?.__id}`,\n );\n }\n }\n oldAfterDiff?.(vnode);\n };\n}\n"]}
@@ -2,45 +2,10 @@
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 { Component, options } from 'preact';
5
- import { BITS, COMMIT, COMPONENT, COMPONENT_DIRTY, DIFF, DIFF2, DIFFED, HOOKS, LIST, NEXT_STATE, NEXT_VALUE, RENDER, VALUE, VNODE, } from '../../shared/render-constants.js';
6
- import { getDisplayName } from '../../utils.js';
5
+ import { BITS, COMMIT, COMPONENT, COMPONENT_DIRTY, DIFF, DIFF2, DIFFED, HOOKS, LIST, NEXT_VALUE, RENDER, VNODE, } from '../../shared/render-constants.js';
6
+ import { getDisplayName } from '../../shared/utils.js';
7
7
  import { globalPatchOptions } from '../lifecycle/patch/commit.js';
8
8
  import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';
9
- const format = (val) => {
10
- if (typeof val === 'function') {
11
- return val.toString();
12
- }
13
- return val;
14
- };
15
- function safeJsonStringify(val) {
16
- const seen = new WeakSet();
17
- return JSON.stringify(val, function (_key, value) {
18
- if (typeof value === 'object' && value !== null) {
19
- if (seen.has(value)) {
20
- return '[Unserializable: Circular]';
21
- }
22
- seen.add(value);
23
- }
24
- return value;
25
- });
26
- }
27
- function buildSetStateProfileMarkArgs(type, currentState, nextState) {
28
- const EMPTY_OBJ = {};
29
- const currentStateObj = (currentState ?? EMPTY_OBJ);
30
- const nextStateObj = (nextState ?? EMPTY_OBJ);
31
- return {
32
- componentName: (type && typeof type === 'function')
33
- ? getDisplayName(type)
34
- : 'Unknown',
35
- 'current state keys': JSON.stringify(Object.keys(currentStateObj)),
36
- 'next state keys': JSON.stringify(Object.keys(nextStateObj)),
37
- 'changed (shallow diff) state keys': JSON.stringify(
38
- // the setState is in assign manner, we assume nextState is a superset of currentState
39
- Object.keys(nextStateObj).filter(key => currentStateObj[key] !== nextStateObj[key])),
40
- currentValue: safeJsonStringify(format(currentState)),
41
- nextValue: safeJsonStringify(format(nextState)),
42
- };
43
- }
44
9
  export function initProfileHook() {
45
10
  // early-exit if required profiling APIs are unavailable
46
11
  let p;
@@ -62,21 +27,35 @@ export function initProfileHook() {
62
27
  // This allows us to trace the flow of its diffing, committing and patching.
63
28
  {
64
29
  const sFlowID = Symbol('FLOW_ID');
30
+ function markSetState(component, hookIdx) {
31
+ try {
32
+ const type = component[VNODE].type;
33
+ if (hookIdx === undefined
34
+ && !(typeof type === 'function' && ('prototype' in type) && ('render' in type.prototype))) {
35
+ return;
36
+ }
37
+ // Update traces describe the framework's work without inspecting application state.
38
+ const args = {
39
+ componentName: typeof type === 'function' ? getDisplayName(type) : 'Unknown',
40
+ };
41
+ if (hookIdx !== undefined) {
42
+ args['hookIdx'] = String(hookIdx);
43
+ }
44
+ const flowId = component[sFlowID] ?? profileFlowId();
45
+ profileMark(hookIdx === undefined ? 'ReactLynx::setState' : 'ReactLynx::hooks::setState', { flowId, args });
46
+ component[sFlowID] = flowId;
47
+ }
48
+ catch {
49
+ // A profiling failure must not interrupt Preact's update or scheduling.
50
+ }
51
+ }
65
52
  if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
66
53
  // eslint-disable-next-line @typescript-eslint/unbound-method
67
54
  const oldSetState = Component.prototype.setState;
68
55
  Component.prototype.setState = function (state, callback) {
69
56
  oldSetState?.call(this, state, callback);
70
57
  if (this[BITS] & COMPONENT_DIRTY) {
71
- const type = this[VNODE].type;
72
- const isClassComponent = typeof type === 'function' && ('prototype' in type)
73
- && ('render' in type.prototype);
74
- if (isClassComponent) {
75
- profileMark('ReactLynx::setState', {
76
- flowId: this[sFlowID] ??= profileFlowId(),
77
- args: buildSetStateProfileMarkArgs(type, this.state, this[NEXT_STATE]),
78
- });
79
- }
58
+ markSetState(this);
80
59
  }
81
60
  };
82
61
  }
@@ -117,27 +96,13 @@ export function initProfileHook() {
117
96
  Object.defineProperty(hookState, NEXT_VALUE, {
118
97
  get: () => hookState['internalNextValue'],
119
98
  set: (value) => {
99
+ hookState['internalNextValue'] = value;
120
100
  if (Array.isArray(value)) {
121
- // hookState[VALUE] is [state, dispatch]
122
- const currentValueTuple = hookState[VALUE];
123
- const currentValue = currentValueTuple[0];
124
- const [nextValue] = value;
125
101
  const component = hookState[COMPONENT];
126
- if (!component) {
127
- hookState['internalNextValue'] = value;
128
- return;
102
+ if (component) {
103
+ markSetState(component, hookIdx);
129
104
  }
130
- const type = component[VNODE].type;
131
- const flowId = component[sFlowID] ??= profileFlowId();
132
- profileMark('ReactLynx::hooks::setState', {
133
- flowId,
134
- args: {
135
- hookIdx: String(hookIdx),
136
- ...buildSetStateProfileMarkArgs(type, currentValue, nextValue),
137
- },
138
- });
139
105
  }
140
- hookState['internalNextValue'] = value;
141
106
  },
142
107
  configurable: true,
143
108
  });
@@ -1 +1 @@
1
- {"version":3,"file":"profileHooks.js","sourceRoot":"","sources":["../../../src/snapshot/debug/profileHooks.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAK5C,OAAO,EACL,IAAI,EACJ,MAAM,EACN,SAAS,EACT,eAAe,EACf,IAAI,EACJ,KAAK,EACL,MAAM,EACN,KAAK,EACL,IAAI,EACJ,UAAU,EACV,UAAU,EACV,MAAM,EACN,KAAK,EACL,KAAK,GACN,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,MAAM,MAAM,GAAG,CAAC,GAAY,EAAE,EAAE;IAC9B,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,SAAS,iBAAiB,CAAC,GAAY;IACrC,MAAM,IAAI,GAAG,IAAI,OAAO,EAAU,CAAC;IAEnC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,UAAS,IAAI,EAAE,KAAc;QACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAChD,IA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,KAAK,UAAU,EAAE,CAAC;gBACrC,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;gBACxC,OAAO,KAAK,CAAC,YAAY,CAAC,CAAC;gBAC3B,IAAI,qBAAqB,IAAI,WAAW,KAAK,qBAAqB,CAAC,MAAM,EAAE,CAAC;oBAC1E,2CAA2C;oBAC3C,WAAW,CAAC,8BAA8B,EAAE;wBAC1C,IAAI,EAAE;4BACJ,aAAa,EAAE,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,IAAsB,CAAC;yBAC9E;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC;QAC1B,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.\nimport { Component, options } from 'preact';\nimport type { ComponentClass, ComponentType, VNode } from 'preact';\n\nimport type { TraceOption } from '@lynx-js/types';\n\nimport {\n BITS,\n COMMIT,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DIFF2,\n DIFFED,\n HOOKS,\n LIST,\n NEXT_STATE,\n NEXT_VALUE,\n RENDER,\n VALUE,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { getDisplayName } from '../../utils.js';\nimport { globalPatchOptions } from '../lifecycle/patch/commit.js';\nimport { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';\n\nconst format = (val: unknown) => {\n if (typeof val === 'function') {\n return val.toString();\n }\n return val;\n};\n\nfunction safeJsonStringify(val: unknown) {\n const seen = new WeakSet<object>();\n\n return JSON.stringify(val, function(_key, value: unknown) {\n if (typeof value === 'object' && value !== null) {\n if (seen.has(value)) {\n return '[Unserializable: Circular]';\n }\n seen.add(value);\n }\n\n return value;\n });\n}\n\nfunction buildSetStateProfileMarkArgs(\n type: string | ComponentType | undefined,\n currentState: unknown,\n nextState: unknown,\n): Record<string, string> {\n const EMPTY_OBJ = {};\n\n const currentStateObj = (currentState ?? EMPTY_OBJ) as Record<string, unknown>;\n const nextStateObj = (nextState ?? EMPTY_OBJ) as Record<string, unknown>;\n\n return {\n componentName: (type && typeof type === 'function')\n ? getDisplayName(type as ComponentClass)\n : 'Unknown',\n 'current state keys': JSON.stringify(Object.keys(currentStateObj)),\n 'next state keys': JSON.stringify(Object.keys(nextStateObj)),\n 'changed (shallow diff) state keys': JSON.stringify(\n // the setState is in assign manner, we assume nextState is a superset of currentState\n Object.keys(nextStateObj).filter(\n key => currentStateObj[key] !== nextStateObj[key],\n ),\n ),\n currentValue: safeJsonStringify(format(currentState)),\n nextValue: safeJsonStringify(format(nextState)),\n };\n}\n\nexport function initProfileHook(): void {\n // early-exit if required profiling APIs are unavailable\n let p;\n /* v8 ignore start */\n if (\n !(p = lynx.performance)\n || typeof p.profileStart !== 'function'\n || typeof p.profileEnd !== 'function'\n || typeof p.profileMark !== 'function'\n || typeof p.profileFlowId !== 'function'\n ) {\n return;\n }\n /* v8 ignore stop */\n\n const profileStart = p.profileStart.bind(p);\n const profileEnd = p.profileEnd.bind(p);\n const profileMark = p.profileMark.bind(p);\n const profileFlowId = p.profileFlowId.bind(p);\n\n // for each setState call, we will add a profiling trace and\n // attach a flowId to the component instance.\n // This allows us to trace the flow of its diffing, committing and patching.\n {\n const sFlowID = Symbol('FLOW_ID');\n type PatchedComponent = Component & { [sFlowID]?: number };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldSetState = Component.prototype.setState;\n Component.prototype.setState = function(this: PatchedComponent & { [NEXT_STATE]: unknown }, state, callback) {\n oldSetState?.call(this, state, callback);\n\n if (this[BITS] & COMPONENT_DIRTY) {\n const type = this[VNODE]!.type;\n const isClassComponent = typeof type === 'function' && ('prototype' in type)\n && ('render' in type.prototype);\n\n if (isClassComponent) {\n profileMark('ReactLynx::setState', {\n flowId: this[sFlowID] ??= profileFlowId(),\n args: buildSetStateProfileMarkArgs(\n type,\n this.state,\n this[NEXT_STATE],\n ),\n });\n }\n }\n };\n }\n\n // These hot callbacks have fixed signatures; avoid collecting and spreading\n // an argument array for every host and component visited.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff2 = options[DIFF2];\n options[DIFF2] = (vnode, oldVNode) => {\n // We only add profiling trace for Component\n if (typeof vnode.type === 'function') {\n const profileOptions: TraceOption = {};\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const c: PatchedComponent = oldVNode[COMPONENT]!;\n if (c) {\n const flowId = c[sFlowID];\n delete c[sFlowID];\n if (flowId) {\n globalPatchOptions.flowIds ??= [];\n globalPatchOptions.flowIds.push(flowId);\n profileOptions.flowId = flowId;\n }\n }\n }\n\n profileStart(\n `ReactLynx::diff::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`,\n profileOptions,\n );\n }\n oldDiff2?.(vnode, oldVNode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiffed = options[DIFFED];\n options[DIFFED] = vnode => {\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const hooks = vnode[COMPONENT]?.[HOOKS];\n const hookList = hooks?.[LIST];\n\n if (Array.isArray(hookList)) {\n hookList.forEach((hookState, hookIdx: number) => {\n hookState['internalNextValue'] = hookState[NEXT_VALUE];\n // define a setter for __N to track the next value of the hook\n Object.defineProperty(hookState, NEXT_VALUE, {\n get: () => hookState['internalNextValue'],\n set: (value) => {\n if (Array.isArray(value)) {\n // hookState[VALUE] is [state, dispatch]\n const currentValueTuple = hookState[VALUE] as unknown[];\n const currentValue = currentValueTuple[0];\n const [nextValue] = value as unknown[];\n\n const component = hookState[COMPONENT] as PatchedComponent | undefined;\n if (!component) {\n hookState['internalNextValue'] = value;\n return;\n }\n\n const type = component[VNODE]!.type;\n const flowId = component[sFlowID] ??= profileFlowId();\n\n profileMark('ReactLynx::hooks::setState', {\n flowId,\n args: {\n hookIdx: String(hookIdx),\n ...buildSetStateProfileMarkArgs(\n type,\n currentValue,\n nextValue,\n ),\n },\n });\n }\n hookState['internalNextValue'] = value;\n },\n configurable: true,\n });\n });\n }\n }\n\n if (typeof vnode.type === 'function') {\n profileEnd(); // for options[DIFF2]\n }\n oldDiffed?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldCommit = options[COMMIT];\n options[COMMIT] = (vnode, commitQueue) => {\n profileStart('ReactLynx::commit', {\n ...globalPatchOptions.flowIds\n ? {\n flowId: globalPatchOptions.flowIds[0],\n flowIds: globalPatchOptions.flowIds,\n }\n : {},\n });\n oldCommit?.(vnode, commitQueue);\n profileEnd();\n };\n }\n }\n\n // Profile the user-provided `render`.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldRender = options[RENDER];\n options[RENDER] = (vnode: VNode) => {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalRender = vnode[COMPONENT]!.render;\n vnode[COMPONENT]!.render = function render(this, props, state, context) {\n profileStart(`ReactLynx::render::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`);\n try {\n return originalRender.call(this, props, state, context);\n } finally {\n profileEnd();\n vnode[COMPONENT]!.render = originalRender;\n }\n };\n oldRender?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const sPatchLength = Symbol('PATCH_LENGTH');\n\n type PatchedVNode = VNode & { [sPatchLength]?: number };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff = options[DIFF];\n options[DIFF] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function' && __globalSnapshotPatch) {\n vnode[sPatchLength] = __globalSnapshotPatch.length;\n }\n oldDiff?.(vnode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldPatchDiffed = options[DIFFED];\n options[DIFFED] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function') {\n const patchLength = vnode[sPatchLength];\n delete vnode[sPatchLength];\n if (__globalSnapshotPatch && patchLength === __globalSnapshotPatch.length) {\n // \"NoPatch\" is a conventional name in Lynx\n profileMark('ReactLynx::diffFinishNoPatch', {\n args: {\n componentName: /* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass),\n },\n });\n }\n }\n oldPatchDiffed?.(vnode);\n };\n }\n}\n"]}
1
+ {"version":3,"file":"profileHooks.js","sourceRoot":"","sources":["../../../src/snapshot/debug/profileHooks.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAK5C,OAAO,EACL,IAAI,EACJ,MAAM,EACN,SAAS,EACT,eAAe,EACf,IAAI,EACJ,KAAK,EACL,MAAM,EACN,KAAK,EACL,IAAI,EACJ,UAAU,EACV,MAAM,EACN,KAAK,GACN,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,MAAM,UAAU,eAAe;IAC7B,wDAAwD;IACxD,IAAI,CAAC,CAAC;IACN,qBAAqB;IACrB,IACE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC;WACpB,OAAO,CAAC,CAAC,YAAY,KAAK,UAAU;WACpC,OAAO,CAAC,CAAC,UAAU,KAAK,UAAU;WAClC,OAAO,CAAC,CAAC,WAAW,KAAK,UAAU;WACnC,OAAO,CAAC,CAAC,aAAa,KAAK,UAAU,EACxC,CAAC;QACD,OAAO;IACT,CAAC;IACD,oBAAoB;IAEpB,MAAM,YAAY,GAAG,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC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CAAC,KAAK,CAAC,IAAsB,CAAC;yBAC9E;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC;QAC1B,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.\nimport { Component, options } from 'preact';\nimport type { ComponentClass, VNode } from 'preact';\n\nimport type { TraceOption } from '@lynx-js/types';\n\nimport {\n BITS,\n COMMIT,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DIFF2,\n DIFFED,\n HOOKS,\n LIST,\n NEXT_VALUE,\n RENDER,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { getDisplayName } from '../../shared/utils.js';\nimport { globalPatchOptions } from '../lifecycle/patch/commit.js';\nimport { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';\n\nexport function initProfileHook(): void {\n // early-exit if required profiling APIs are unavailable\n let p;\n /* v8 ignore start */\n if (\n !(p = lynx.performance)\n || typeof p.profileStart !== 'function'\n || typeof p.profileEnd !== 'function'\n || typeof p.profileMark !== 'function'\n || typeof p.profileFlowId !== 'function'\n ) {\n return;\n }\n /* v8 ignore stop */\n\n const profileStart = p.profileStart.bind(p);\n const profileEnd = p.profileEnd.bind(p);\n const profileMark = p.profileMark.bind(p);\n const profileFlowId = p.profileFlowId.bind(p);\n\n // for each setState call, we will add a profiling trace and\n // attach a flowId to the component instance.\n // This allows us to trace the flow of its diffing, committing and patching.\n {\n const sFlowID = Symbol('FLOW_ID');\n type PatchedComponent = Component & { [sFlowID]?: number };\n\n function markSetState(component: PatchedComponent, hookIdx?: number): void {\n try {\n const type = component[VNODE]!.type;\n if (\n hookIdx === undefined\n && !(typeof type === 'function' && ('prototype' in type) && ('render' in type.prototype))\n ) {\n return;\n }\n // Update traces describe the framework's work without inspecting application state.\n const args: Record<string, string> = {\n componentName: typeof type === 'function' ? getDisplayName(type as ComponentClass) : 'Unknown',\n };\n if (hookIdx !== undefined) {\n args['hookIdx'] = String(hookIdx);\n }\n const flowId = component[sFlowID] ?? profileFlowId();\n profileMark(hookIdx === undefined ? 'ReactLynx::setState' : 'ReactLynx::hooks::setState', { flowId, args });\n component[sFlowID] = flowId;\n } catch {\n // A profiling failure must not interrupt Preact's update or scheduling.\n }\n }\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldSetState = Component.prototype.setState;\n Component.prototype.setState = function(this: PatchedComponent, state, callback) {\n oldSetState?.call(this, state, callback);\n\n if (this[BITS] & COMPONENT_DIRTY) {\n markSetState(this);\n }\n };\n }\n\n // These hot callbacks have fixed signatures; avoid collecting and spreading\n // an argument array for every host and component visited.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff2 = options[DIFF2];\n options[DIFF2] = (vnode, oldVNode) => {\n // We only add profiling trace for Component\n if (typeof vnode.type === 'function') {\n const profileOptions: TraceOption = {};\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const c: PatchedComponent = oldVNode[COMPONENT]!;\n if (c) {\n const flowId = c[sFlowID];\n delete c[sFlowID];\n if (flowId) {\n globalPatchOptions.flowIds ??= [];\n globalPatchOptions.flowIds.push(flowId);\n profileOptions.flowId = flowId;\n }\n }\n }\n\n profileStart(\n `ReactLynx::diff::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`,\n profileOptions,\n );\n }\n oldDiff2?.(vnode, oldVNode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiffed = options[DIFFED];\n options[DIFFED] = vnode => {\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const hooks = vnode[COMPONENT]?.[HOOKS];\n const hookList = hooks?.[LIST];\n\n if (Array.isArray(hookList)) {\n hookList.forEach((hookState, hookIdx: number) => {\n hookState['internalNextValue'] = hookState[NEXT_VALUE];\n // define a setter for __N to track the next value of the hook\n Object.defineProperty(hookState, NEXT_VALUE, {\n get: () => hookState['internalNextValue'],\n set: (value) => {\n hookState['internalNextValue'] = value;\n if (Array.isArray(value)) {\n const component = hookState[COMPONENT] as PatchedComponent | undefined;\n if (component) {\n markSetState(component, hookIdx);\n }\n }\n },\n configurable: true,\n });\n });\n }\n }\n\n if (typeof vnode.type === 'function') {\n profileEnd(); // for options[DIFF2]\n }\n oldDiffed?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldCommit = options[COMMIT];\n options[COMMIT] = (vnode, commitQueue) => {\n profileStart('ReactLynx::commit', {\n ...globalPatchOptions.flowIds\n ? {\n flowId: globalPatchOptions.flowIds[0],\n flowIds: globalPatchOptions.flowIds,\n }\n : {},\n });\n oldCommit?.(vnode, commitQueue);\n profileEnd();\n };\n }\n }\n\n // Profile the user-provided `render`.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldRender = options[RENDER];\n options[RENDER] = (vnode: VNode) => {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalRender = vnode[COMPONENT]!.render;\n vnode[COMPONENT]!.render = function render(this, props, state, context) {\n profileStart(`ReactLynx::render::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`);\n try {\n return originalRender.call(this, props, state, context);\n } finally {\n profileEnd();\n vnode[COMPONENT]!.render = originalRender;\n }\n };\n oldRender?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const sPatchLength = Symbol('PATCH_LENGTH');\n\n type PatchedVNode = VNode & { [sPatchLength]?: number };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff = options[DIFF];\n options[DIFF] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function' && __globalSnapshotPatch) {\n vnode[sPatchLength] = __globalSnapshotPatch.length;\n }\n oldDiff?.(vnode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldPatchDiffed = options[DIFFED];\n options[DIFFED] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function') {\n const patchLength = vnode[sPatchLength];\n delete vnode[sPatchLength];\n if (__globalSnapshotPatch && patchLength === __globalSnapshotPatch.length) {\n // \"NoPatch\" is a conventional name in Lynx\n profileMark('ReactLynx::diffFinishNoPatch', {\n args: {\n componentName: /* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass),\n },\n });\n }\n }\n oldPatchDiffed?.(vnode);\n };\n }\n}\n"]}
@@ -2,14 +2,14 @@
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 { render } from 'preact';
5
- import { __root } from '../../root.js';
6
5
  import { delayedEvents } from './event/delayEvents.js';
7
6
  import { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';
8
7
  import { globalCommitTaskMap } from './patch/commit.js';
9
8
  import { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';
10
9
  import { delayedUiOps } from './ref/delay.js';
10
+ import { withSyncEffectFlush } from '../../core/sync-effect-flush.js';
11
+ import { __root } from '../../root.js';
11
12
  import { profileEnd, profileStart } from '../../shared/profile.js';
12
- import { withSyncEffectFlush } from '../../utils.js';
13
13
  import { resetSnapshotMainThreadFunctionRuntime } from '../worklet/call/runOnMainThread.js';
14
14
  import { resetSnapshotBackgroundFunctionRuntime } from '../worklet/ctx.js';
15
15
  function destroyBackground() {
@@ -1 +1 @@
1
- {"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,C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QACf,CAAC;IACH,CAAC;AACH,CAAC;AAED,OAAO,EAAE,iBAAiB,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.\nimport { render } from 'preact';\n\nimport { __root } from '../../root.js';\nimport { delayedEvents } from './event/delayEvents.js';\nimport { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';\nimport { globalCommitTaskMap } from './patch/commit.js';\nimport { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';\nimport { delayedUiOps } from './ref/delay.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { withSyncEffectFlush } from '../../utils.js';\nimport { resetSnapshotMainThreadFunctionRuntime } from '../worklet/call/runOnMainThread.js';\nimport { resetSnapshotBackgroundFunctionRuntime } from '../worklet/ctx.js';\n\nfunction destroyBackground(): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::destroyBackground');\n }\n\n deinitGlobalSnapshotPatch();\n\n try {\n withSyncEffectFlush(() => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(null, __root as any);\n });\n\n globalCommitTaskMap.forEach(task => {\n task();\n });\n } finally {\n globalCommitTaskMap.clear();\n // Clear delayed events which should not be executed after destroyed.\n // This is important when the page is performing a reload.\n delayedLifecycleEvents.length = 0;\n if (delayedEvents) {\n delayedEvents.length = 0;\n }\n delayedUiOps.length = 0;\n resetSnapshotBackgroundFunctionRuntime();\n resetSnapshotMainThreadFunctionRuntime();\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n\nexport { destroyBackground };\n"]}
1
+ {"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;A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AE,CAAC;QACzC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;AACH,CAAC;AAED,OAAO,EAAE,iBAAiB,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.\nimport { render } from 'preact';\n\nimport { delayedEvents } from './event/delayEvents.js';\nimport { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';\nimport { globalCommitTaskMap } from './patch/commit.js';\nimport { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';\nimport { delayedUiOps } from './ref/delay.js';\nimport { withSyncEffectFlush } from '../../core/sync-effect-flush.js';\nimport { __root } from '../../root.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { resetSnapshotMainThreadFunctionRuntime } from '../worklet/call/runOnMainThread.js';\nimport { resetSnapshotBackgroundFunctionRuntime } from '../worklet/ctx.js';\n\nfunction destroyBackground(): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::destroyBackground');\n }\n\n deinitGlobalSnapshotPatch();\n\n try {\n withSyncEffectFlush(() => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(null, __root as any);\n });\n\n globalCommitTaskMap.forEach(task => {\n task();\n });\n } finally {\n globalCommitTaskMap.clear();\n // Clear delayed events which should not be executed after destroyed.\n // This is important when the page is performing a reload.\n delayedLifecycleEvents.length = 0;\n if (delayedEvents) {\n delayedEvents.length = 0;\n }\n delayedUiOps.length = 0;\n resetSnapshotBackgroundFunctionRuntime();\n resetSnapshotMainThreadFunctionRuntime();\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n\nexport { destroyBackground };\n"]}
@@ -2,8 +2,9 @@
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 { options } from 'preact';
5
+ import { lynxQueueMicrotask } from '../../shared/microtask.js';
5
6
  import { RENDER_COMPONENT, ROOT } from '../../shared/render-constants.js';
6
- import { hook, lynxQueueMicrotask } from '../../utils.js';
7
+ import { hook } from '../../shared/utils.js';
7
8
  export const isRendering = /* @__PURE__ */ { value: false };
8
9
  const setIsRendering = () => {
9
10
  isRendering.value = true;