@lynx-js/react 0.129.3 → 0.129.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (413) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +2 -2
  4. package/refresh/.turbo/turbo-build.log +3 -3
  5. package/refresh/dist/index.js +113 -20
  6. package/refresh/rslib.config.ts +13 -3
  7. package/refresh/src/index.ts +100 -0
  8. package/refresh/src/self.ts +38 -0
  9. package/runtime/__test__/{snapshot → core}/attribute-name.test.ts +1 -1
  10. package/runtime/__test__/core/background-function.test.ts +37 -0
  11. package/runtime/__test__/{shared → core}/component-stack.test.ts +4 -4
  12. package/runtime/__test__/core/ref.test.ts +218 -1
  13. package/runtime/__test__/core/sync-effect-flush.test.ts +58 -0
  14. package/runtime/__test__/element-template/debug/alog.test.ts +20 -12
  15. package/runtime/__test__/element-template/fixtures/background/hydrate/_shared.tsx +15 -34
  16. package/runtime/__test__/element-template/fixtures/background/hydrate/children.creates-missing-nodes-recursively/output.txt +2 -0
  17. package/runtime/__test__/element-template/fixtures/background/hydrate/children.iterates-existing-slots/output.txt +1 -0
  18. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-attrs-element/output.txt +6 -1
  19. package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-main/output.txt +1 -0
  20. package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.move-before-child → children.reconciles-raw-text-slots}/case.tsx +1 -1
  21. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text/output.txt +1 -0
  22. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text-non-text/output.txt +1 -0
  23. package/runtime/__test__/element-template/fixtures/background/hydrate/root-key-mismatch-reconciles/output.txt +1 -0
  24. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.creates-and-inserts-new/output.txt +1 -0
  25. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.inserts-before-existing-sibling/output.txt +1 -0
  26. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.mixed-operations/output.txt +1 -0
  27. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -0
  28. package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/complex-trees.deeply-nested-dynamic-content/output.txt +1 -0
  29. package/runtime/__test__/element-template/fixtures/background/instance/ops/emits-bundle-url-in-create-template/output.txt +1 -0
  30. package/runtime/__test__/element-template/fixtures/list/mts/index.tsx +185 -0
  31. package/runtime/__test__/element-template/fixtures/page/render-page/native-log.txt +1 -0
  32. package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/case.tsx +2 -0
  33. package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/ops.txt +1 -0
  34. package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/ops.txt +1 -0
  35. package/runtime/__test__/element-template/fixtures/render/child-siblings/papi.txt +10 -5
  36. package/runtime/__test__/element-template/fixtures/render/component/papi.txt +6 -3
  37. package/runtime/__test__/element-template/fixtures/render/component-slot-content/papi.txt +6 -3
  38. package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/papi.txt +2 -1
  39. package/runtime/__test__/element-template/fixtures/render/direct-native/appends-root-text-via-append-element/native-log.txt +1 -0
  40. package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/native-log.txt +2 -0
  41. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-template-children-in-the-same-slot/native-log.txt +3 -0
  42. package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +3 -0
  43. package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/native-log.txt +3 -0
  44. package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/native-log.txt +3 -0
  45. package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/native-log.txt +1 -0
  46. package/runtime/__test__/element-template/fixtures/render/mapped-view-children/papi.txt +14 -7
  47. package/runtime/__test__/element-template/fixtures/render/mixed-children/papi.txt +8 -4
  48. package/runtime/__test__/element-template/fixtures/render/multiple-text/papi.txt +38 -19
  49. package/runtime/__test__/element-template/fixtures/render/nested-templates/papi.txt +6 -3
  50. package/runtime/__test__/element-template/fixtures/render/react-example/papi.txt +6 -3
  51. package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/papi.txt +6 -3
  52. package/runtime/__test__/element-template/fixtures/render/template-dedupe/papi.txt +10 -5
  53. package/runtime/__test__/element-template/lynx/performance.test.ts +1 -0
  54. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +1 -0
  55. package/runtime/__test__/element-template/native/mts-destroy.test.ts +10 -15
  56. package/runtime/__test__/element-template/native/reload.test.ts +4 -7
  57. package/runtime/__test__/element-template/runtime/background/adapter/background-adapter.et.test.tsx +0 -32
  58. package/runtime/__test__/element-template/runtime/background/commit-context.test.ts +0 -14
  59. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +10 -0
  60. package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +22 -0
  61. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +197 -252
  62. package/runtime/__test__/element-template/runtime/background/instance.test.ts +277 -126
  63. package/runtime/__test__/element-template/runtime/background/passive-update-depth.test.tsx +496 -0
  64. package/runtime/__test__/element-template/runtime/background/render/preact.test.tsx +16 -22
  65. package/runtime/__test__/element-template/runtime/background/root-render.test.tsx +5 -3
  66. package/runtime/__test__/element-template/runtime/background/suspense.test.tsx +2 -0
  67. package/runtime/__test__/element-template/runtime/background/update/compiled-fixtures.test.tsx +1 -0
  68. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +1 -0
  69. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +3 -4
  70. package/runtime/__test__/element-template/runtime/list/list-mts-compiled.test.ts +525 -0
  71. package/runtime/__test__/element-template/runtime/page/compiled-fixtures.test.tsx +2 -0
  72. package/runtime/__test__/element-template/runtime/page/root-instance.test.ts +2 -14
  73. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +425 -1032
  74. package/runtime/__test__/element-template/runtime/patch/patch-listener-alog.test.ts +1 -0
  75. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +1 -0
  76. package/runtime/__test__/element-template/runtime/prop-adapters/event.test.ts +0 -20
  77. package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +2 -1
  78. package/runtime/__test__/element-template/runtime/prop-adapters/hydrate.test.ts +1 -0
  79. package/runtime/__test__/element-template/runtime/prop-adapters/ref.test.ts +65 -0
  80. package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +12 -4
  81. package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +2 -5
  82. package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +56 -121
  83. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +18 -17
  84. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +5 -4
  85. package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -0
  86. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +1 -60
  87. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +32 -89
  88. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +8 -6
  89. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +34 -6
  90. package/runtime/__test__/element-template/test-utils/debug/updateRunner.test.tsx +20 -12
  91. package/runtime/__test__/element-template/test-utils/debug/updateRunner.ts +2 -28
  92. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.test.ts +14 -5
  93. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.ts +1 -57
  94. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +29 -13
  95. package/runtime/__test__/element-template/vitest.config.ts +1 -0
  96. package/runtime/__test__/guardrails/snapshot-containment.test.ts +98 -77
  97. package/runtime/__test__/snapshot/debug/passive-update-depth.test.jsx +549 -0
  98. package/runtime/__test__/snapshot/debug/react-hooks-profile.test.jsx +3 -3
  99. package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +138 -1
  100. package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +1 -1
  101. package/runtime/__test__/snapshot/lifecycle/transfer.mts.test.jsx +194 -0
  102. package/runtime/__test__/snapshot/lifecycle/transfer.test.jsx +210 -0
  103. package/runtime/__test__/snapshot/list.test.jsx +109 -0
  104. package/runtime/__test__/snapshot/lynxQueueMicrotask.test.jsx +2 -2
  105. package/runtime/__test__/snapshot/ref.test.jsx +124 -1
  106. package/runtime/__test__/snapshot/utils/envManager.ts +5 -0
  107. package/runtime/__test__/snapshot/utils/globals.js +1 -0
  108. package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +22 -11
  109. package/runtime/__test__/worklet-runtime/hydrate.test.js +1 -0
  110. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +24 -16
  111. package/runtime/__test__/worklet-runtime/runOnBackground.test.js +188 -0
  112. package/runtime/__test__/worklet-runtime/workletRef.test.js +16 -0
  113. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +53 -1
  114. package/runtime/lazy/internal.js +1 -0
  115. package/runtime/lib/core/attribute-name.js.map +1 -0
  116. package/runtime/lib/core/background-function/run-on-background.js +7 -7
  117. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  118. package/runtime/lib/{shared → core}/component-stack.js +1 -1
  119. package/runtime/lib/core/component-stack.js.map +1 -0
  120. package/runtime/lib/core/deep-equal.d.ts +1 -0
  121. package/runtime/lib/core/deep-equal.js +31 -0
  122. package/runtime/lib/core/deep-equal.js.map +1 -0
  123. package/runtime/lib/core/hooks/mainThreadImpl.js +1 -1
  124. package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
  125. package/runtime/lib/core/lynx-page-data.js +1 -1
  126. package/runtime/lib/core/lynx-page-data.js.map +1 -1
  127. package/runtime/lib/core/mts-capability.js +1 -1
  128. package/runtime/lib/core/mts-capability.js.map +1 -1
  129. package/runtime/lib/core/performance.js +2 -1
  130. package/runtime/lib/core/performance.js.map +1 -1
  131. package/runtime/lib/core/ref.d.ts +1 -2
  132. package/runtime/lib/core/ref.js +60 -9
  133. package/runtime/lib/core/ref.js.map +1 -1
  134. package/runtime/lib/core/sync-effect-flush.d.ts +9 -0
  135. package/runtime/lib/core/sync-effect-flush.js +31 -0
  136. package/runtime/lib/core/sync-effect-flush.js.map +1 -0
  137. package/runtime/lib/core/thread-function-call/main-thread.js +1 -1
  138. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  139. package/runtime/lib/element-template/background/attr-slots.d.ts +1 -0
  140. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  141. package/runtime/lib/element-template/background/commit-hook.js +1 -1
  142. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  143. package/runtime/lib/element-template/background/destroy.js +1 -1
  144. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  145. package/runtime/lib/element-template/background/hydrate.js +173 -85
  146. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  147. package/runtime/lib/element-template/background/instance.d.ts +7 -10
  148. package/runtime/lib/element-template/background/instance.js +65 -58
  149. package/runtime/lib/element-template/background/instance.js.map +1 -1
  150. package/runtime/lib/element-template/background/render-scope.js +2 -1
  151. package/runtime/lib/element-template/background/render-scope.js.map +1 -1
  152. package/runtime/lib/element-template/debug/alog.d.ts +1 -10
  153. package/runtime/lib/element-template/debug/alog.js +1 -16
  154. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  155. package/runtime/lib/element-template/debug/profile.js +1 -1
  156. package/runtime/lib/element-template/debug/profile.js.map +1 -1
  157. package/runtime/lib/element-template/native/index.js +2 -2
  158. package/runtime/lib/element-template/native/index.js.map +1 -1
  159. package/runtime/lib/element-template/native/patch-listener.js +4 -8
  160. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  161. package/runtime/lib/element-template/native/reload-main-thread.js +0 -4
  162. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  163. package/runtime/lib/element-template/prop-adapters/ref.d.ts +2 -1
  164. package/runtime/lib/element-template/prop-adapters/ref.js +4 -4
  165. package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
  166. package/runtime/lib/element-template/prop-adapters/spread.js +1 -1
  167. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  168. package/runtime/lib/element-template/protocol/opcodes.d.ts +0 -2
  169. package/runtime/lib/element-template/protocol/opcodes.js +0 -2
  170. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  171. package/runtime/lib/element-template/protocol/types.d.ts +8 -30
  172. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  173. package/runtime/lib/element-template/runtime/list/list.d.ts +14 -54
  174. package/runtime/lib/element-template/runtime/list/list.js +82 -546
  175. package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
  176. package/runtime/lib/element-template/runtime/list/platform-info.d.ts +2 -0
  177. package/runtime/lib/element-template/runtime/list/platform-info.js +26 -0
  178. package/runtime/lib/element-template/runtime/list/platform-info.js.map +1 -0
  179. package/runtime/lib/element-template/runtime/patch.js +42 -119
  180. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  181. package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +1 -1
  182. package/runtime/lib/element-template/runtime/render/create-rendered-host.js +24 -21
  183. package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
  184. package/runtime/lib/element-template/runtime/render/render-components.d.ts +1 -1
  185. package/runtime/lib/element-template/runtime/render/render-components.js +3 -6
  186. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  187. package/runtime/lib/element-template/runtime/render/render-direct.js +21 -20
  188. package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
  189. package/runtime/lib/element-template/runtime/render/render-main-thread.js +0 -13
  190. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  191. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +8 -0
  192. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  193. package/runtime/lib/element-template/runtime/template/handle.d.ts +3 -3
  194. package/runtime/lib/element-template/runtime/template/handle.js +2 -2
  195. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  196. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +1 -6
  197. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  198. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +2 -1
  199. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +44 -28
  200. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  201. package/runtime/lib/element-template/runtime/template/typed-attributes.d.ts +2 -0
  202. package/runtime/lib/element-template/runtime/template/typed-attributes.js +8 -1
  203. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  204. package/runtime/lib/internal.d.ts +1 -0
  205. package/runtime/lib/internal.js +1 -0
  206. package/runtime/lib/internal.js.map +1 -1
  207. package/runtime/lib/lynx-api.js +6 -1
  208. package/runtime/lib/lynx-api.js.map +1 -1
  209. package/runtime/lib/lynx.js +4 -4
  210. package/runtime/lib/lynx.js.map +1 -1
  211. package/runtime/lib/root.d.ts +5 -1
  212. package/runtime/lib/root.js +12 -1
  213. package/runtime/lib/root.js.map +1 -1
  214. package/runtime/lib/shared/microtask.d.ts +1 -0
  215. package/runtime/lib/shared/microtask.js +28 -0
  216. package/runtime/lib/shared/microtask.js.map +1 -0
  217. package/runtime/lib/shared/utils.d.ts +8 -0
  218. package/runtime/lib/shared/utils.js +27 -0
  219. package/runtime/lib/shared/utils.js.map +1 -0
  220. package/runtime/lib/{worklet-runtime/utils → shared}/version.d.ts +1 -0
  221. package/runtime/lib/{worklet-runtime/utils → shared}/version.js +4 -2
  222. package/runtime/lib/shared/version.js.map +1 -0
  223. package/runtime/lib/snapshot/alog/render.js +1 -1
  224. package/runtime/lib/snapshot/alog/render.js.map +1 -1
  225. package/runtime/lib/snapshot/debug/profileHooks.js +1 -1
  226. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  227. package/runtime/lib/snapshot/lifecycle/destroy.js +2 -2
  228. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  229. package/runtime/lib/snapshot/lifecycle/isRendering.js +2 -1
  230. package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
  231. package/runtime/lib/snapshot/lifecycle/patch/commit.d.ts +7 -2
  232. package/runtime/lib/snapshot/lifecycle/patch/commit.js +11 -6
  233. package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
  234. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.d.ts +5 -0
  235. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +1 -1
  236. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  237. package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +1 -1
  238. package/runtime/lib/snapshot/lifecycle/ref/delay.js +2 -2
  239. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  240. package/runtime/lib/snapshot/lifecycle/reload.js +1 -1
  241. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  242. package/runtime/lib/snapshot/list/list.js +12 -3
  243. package/runtime/lib/snapshot/list/list.js.map +1 -1
  244. package/runtime/lib/snapshot/lynx/tt.d.ts +3 -1
  245. package/runtime/lib/snapshot/lynx/tt.js +7 -3
  246. package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
  247. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +1 -1
  248. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  249. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  250. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  251. package/runtime/lib/snapshot/snapshot/platformInfo.js +1 -1
  252. package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
  253. package/runtime/lib/snapshot/snapshot/ref.d.ts +1 -0
  254. package/runtime/lib/snapshot/snapshot/ref.js +2 -2
  255. package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
  256. package/runtime/lib/snapshot/snapshot/snapshot.js +1 -1
  257. package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
  258. package/runtime/lib/snapshot/snapshot/spread.js +3 -2
  259. package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
  260. package/runtime/lib/snapshot/transfer.d.ts +15 -0
  261. package/runtime/lib/snapshot/transfer.js +343 -0
  262. package/runtime/lib/snapshot/transfer.js.map +1 -0
  263. package/runtime/lib/snapshot/worklet/functionality.js +1 -1
  264. package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
  265. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  266. package/runtime/lib/worklet-runtime/api/element.js +1 -1
  267. package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
  268. package/runtime/lib/worklet-runtime/api/lynxApi.js +1 -1
  269. package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
  270. package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -2
  271. package/runtime/lib/worklet-runtime/bindings/bindings.js +11 -1
  272. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
  273. package/runtime/lib/worklet-runtime/bindings/observers.js +9 -1
  274. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
  275. package/runtime/lib/worklet-runtime/bindings/types.d.ts +1 -0
  276. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
  277. package/runtime/lib/worklet-runtime/delayWorkletEvent.d.ts +2 -4
  278. package/runtime/lib/worklet-runtime/delayWorkletEvent.js +42 -44
  279. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
  280. package/runtime/lib/worklet-runtime/global.d.ts +1 -2
  281. package/runtime/lib/worklet-runtime/global.js.map +1 -1
  282. package/runtime/lib/worklet-runtime/hydrate.js +2 -32
  283. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
  284. package/runtime/lib/worklet-runtime/run-on-background/index.d.ts +28 -0
  285. package/runtime/lib/worklet-runtime/run-on-background/index.js +103 -0
  286. package/runtime/lib/worklet-runtime/run-on-background/index.js.map +1 -0
  287. package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.d.ts → run-on-background/lifecycle.d.ts} +2 -2
  288. package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.js → run-on-background/lifecycle.js} +12 -9
  289. package/runtime/lib/worklet-runtime/run-on-background/lifecycle.js.map +1 -0
  290. package/runtime/lib/worklet-runtime/workletRef.js +51 -54
  291. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
  292. package/runtime/lib/worklet-runtime/workletRuntime.js +5 -6
  293. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  294. package/runtime/src/core/background-function/run-on-background.ts +7 -7
  295. package/runtime/src/{shared → core}/component-stack.ts +1 -1
  296. package/runtime/src/core/deep-equal.ts +33 -0
  297. package/runtime/src/core/hooks/mainThreadImpl.ts +1 -1
  298. package/runtime/src/core/lynx-page-data.ts +1 -1
  299. package/runtime/src/core/mts-capability.ts +1 -1
  300. package/runtime/src/core/performance.ts +2 -1
  301. package/runtime/src/core/ref.ts +92 -15
  302. package/runtime/src/core/sync-effect-flush.ts +30 -0
  303. package/runtime/src/core/thread-function-call/main-thread.ts +1 -1
  304. package/runtime/src/element-template/background/attr-slots.ts +2 -2
  305. package/runtime/src/element-template/background/commit-hook.ts +1 -1
  306. package/runtime/src/element-template/background/destroy.ts +1 -1
  307. package/runtime/src/element-template/background/hydrate.ts +229 -119
  308. package/runtime/src/element-template/background/instance.ts +82 -82
  309. package/runtime/src/element-template/background/render-scope.ts +2 -1
  310. package/runtime/src/element-template/debug/alog.ts +2 -30
  311. package/runtime/src/element-template/debug/profile.ts +1 -1
  312. package/runtime/src/element-template/native/index.ts +2 -2
  313. package/runtime/src/element-template/native/patch-listener.ts +6 -7
  314. package/runtime/src/element-template/native/reload-main-thread.ts +0 -4
  315. package/runtime/src/element-template/prop-adapters/ref.ts +12 -5
  316. package/runtime/src/element-template/prop-adapters/spread.ts +1 -1
  317. package/runtime/src/element-template/protocol/opcodes.ts +0 -2
  318. package/runtime/src/element-template/protocol/types.ts +10 -38
  319. package/runtime/src/element-template/runtime/list/list.ts +115 -744
  320. package/runtime/src/element-template/runtime/list/platform-info.ts +31 -0
  321. package/runtime/src/element-template/runtime/patch.ts +59 -163
  322. package/runtime/src/element-template/runtime/render/create-rendered-host.ts +27 -31
  323. package/runtime/src/element-template/runtime/render/render-components.ts +2 -5
  324. package/runtime/src/element-template/runtime/render/render-direct.ts +19 -18
  325. package/runtime/src/element-template/runtime/render/render-main-thread.ts +0 -14
  326. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +9 -0
  327. package/runtime/src/element-template/runtime/template/handle.ts +3 -2
  328. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +1 -6
  329. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +44 -30
  330. package/runtime/src/element-template/runtime/template/typed-attributes.ts +17 -1
  331. package/runtime/src/element-template/types.d.ts +6 -22
  332. package/runtime/src/internal.ts +2 -0
  333. package/runtime/src/lynx-api.ts +6 -1
  334. package/runtime/src/lynx.ts +4 -4
  335. package/runtime/src/root.ts +17 -1
  336. package/runtime/src/shared/microtask.ts +26 -0
  337. package/runtime/src/shared/utils.ts +37 -0
  338. package/runtime/src/{worklet-runtime/utils → shared}/version.ts +6 -4
  339. package/runtime/src/snapshot/alog/render.ts +1 -1
  340. package/runtime/src/snapshot/debug/profileHooks.ts +1 -1
  341. package/runtime/src/snapshot/lifecycle/destroy.ts +2 -2
  342. package/runtime/src/snapshot/lifecycle/isRendering.ts +2 -1
  343. package/runtime/src/snapshot/lifecycle/patch/commit.ts +28 -7
  344. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +1 -1
  345. package/runtime/src/snapshot/lifecycle/ref/delay.ts +5 -2
  346. package/runtime/src/snapshot/lifecycle/reload.ts +1 -1
  347. package/runtime/src/snapshot/list/list.ts +12 -3
  348. package/runtime/src/snapshot/lynx/tt.ts +8 -3
  349. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +1 -1
  350. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
  351. package/runtime/src/snapshot/snapshot/platformInfo.ts +1 -1
  352. package/runtime/src/snapshot/snapshot/ref.ts +7 -4
  353. package/runtime/src/snapshot/snapshot/snapshot.ts +1 -1
  354. package/runtime/src/snapshot/snapshot/spread.ts +3 -2
  355. package/runtime/src/snapshot/transfer.ts +379 -0
  356. package/runtime/src/snapshot/worklet/functionality.ts +1 -1
  357. package/runtime/src/worklet-runtime/api/element.ts +1 -1
  358. package/runtime/src/worklet-runtime/api/lynxApi.ts +1 -1
  359. package/runtime/src/worklet-runtime/bindings/bindings.ts +12 -0
  360. package/runtime/src/worklet-runtime/bindings/observers.ts +9 -1
  361. package/runtime/src/worklet-runtime/bindings/types.ts +1 -0
  362. package/runtime/src/worklet-runtime/delayWorkletEvent.ts +49 -54
  363. package/runtime/src/worklet-runtime/global.ts +1 -2
  364. package/runtime/src/worklet-runtime/hydrate.ts +2 -35
  365. package/runtime/src/worklet-runtime/run-on-background/index.ts +145 -0
  366. package/runtime/src/worklet-runtime/{jsFunctionLifecycle.ts → run-on-background/lifecycle.ts} +11 -9
  367. package/runtime/src/worklet-runtime/workletRef.ts +63 -62
  368. package/runtime/src/worklet-runtime/workletRuntime.ts +10 -10
  369. package/testing-library/.turbo/turbo-build.log +10 -10
  370. package/testing-library/dist/pure.js +7 -4
  371. package/testing-library/dist/setupFiles/common/runtime-setup.js +3 -1
  372. package/testing-library/dist/setupFiles/inner/rstest.js +1 -1
  373. package/testing-library/dist/setupFiles/inner/vitest.js +1 -1
  374. package/testing-library/src/__tests__/list.test.jsx +52 -0
  375. package/testing-library/src/__tests__/worklet.test.jsx +81 -0
  376. package/testing-library/src/pure.jsx +5 -2
  377. package/testing-library/src/setupFiles/common/runtime-setup.js +2 -0
  378. package/transform/.turbo/turbo-build$colon$wasm.log +64 -64
  379. package/transform/crates/swc_plugin_element_template/tests/element_template.rs +19 -45
  380. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +0 -19
  381. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
  382. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +85 -85
  383. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +213 -192
  384. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.move-before-child/output.txt +0 -10
  385. package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.raw-text-key-branches/case.tsx +0 -5
  386. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/case.ts +0 -11
  387. package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/output.txt +0 -1
  388. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/case.ts +0 -23
  389. package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/output.txt +0 -6
  390. package/runtime/__test__/element-template/runtime/page/authored-page.test.ts +0 -35
  391. package/runtime/__test__/element-template/runtime/patch/update-fixture-helper.test.tsx +0 -40
  392. package/runtime/__test__/snapshot/lynx-data-processors.test.ts +0 -3
  393. package/runtime/lib/shared/attribute-name.js.map +0 -1
  394. package/runtime/lib/shared/component-stack.js.map +0 -1
  395. package/runtime/lib/snapshot/alog/index.d.ts +0 -1
  396. package/runtime/lib/snapshot/alog/index.js +0 -8
  397. package/runtime/lib/snapshot/alog/index.js.map +0 -1
  398. package/runtime/lib/utils.d.ts +0 -19
  399. package/runtime/lib/utils.js +0 -119
  400. package/runtime/lib/utils.js.map +0 -1
  401. package/runtime/lib/worklet-runtime/delayRunOnBackground.d.ts +0 -13
  402. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +0 -29
  403. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +0 -1
  404. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +0 -1
  405. package/runtime/lib/worklet-runtime/utils/version.js.map +0 -1
  406. package/runtime/src/snapshot/alog/index.ts +0 -8
  407. package/runtime/src/utils.ts +0 -134
  408. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +0 -53
  409. /package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.raw-text-key-branches → children.reconciles-raw-text-slots}/output.txt +0 -0
  410. /package/runtime/lib/{shared → core}/attribute-name.d.ts +0 -0
  411. /package/runtime/lib/{shared → core}/attribute-name.js +0 -0
  412. /package/runtime/lib/{shared → core}/component-stack.d.ts +0 -0
  413. /package/runtime/src/{shared → core}/attribute-name.ts +0 -0
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
5
 
6
6
  import {
7
7
  getFromWorkletRefMap,
8
+ initWorkletRef,
8
9
  isHydratedWorkletValue,
9
10
  removeValueFromWorkletRefMap,
10
11
  updateWorkletRefInitValueChanges,
@@ -685,4 +686,19 @@ describe('WorkletRef', () => {
685
686
  'background-thread-init-2',
686
687
  );
687
688
  });
689
+
690
+ it('keeps ref maps isolated per RefImpl instance', () => {
691
+ const first = initWorkletRef();
692
+ const second = initWorkletRef();
693
+
694
+ first.updateWorkletRefInitValueChanges([[1, 'first-value']]);
695
+ second.updateWorkletRefInitValueChanges([[1, 'second-value']]);
696
+ first.updateWorkletRef({ _wvid: -1 }, 'first-element');
697
+ second.clearFirstScreenWorkletRefMap();
698
+
699
+ expect(first._workletRefMap[1].current).toBe('first-value');
700
+ expect(second._workletRefMap[1].current).toBe('second-value');
701
+ expect(first._firstScreenWorkletRefMap[-1].current.element).toBe('first-element');
702
+ expect(second._firstScreenWorkletRefMap).toEqual({});
703
+ });
688
704
  });
@@ -1,7 +1,7 @@
1
1
  // Copyright 2024 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
- import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
4
+ import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
5
 
6
6
  import { Element } from '../../src/worklet-runtime/api/element';
7
7
  import { initApiEnv } from '../../src/worklet-runtime/api/lynxApi';
@@ -14,6 +14,11 @@ import {
14
14
  } from '../../src/worklet-runtime/workletRef';
15
15
  import { initWorklet } from '../../src/worklet-runtime/workletRuntime';
16
16
 
17
+ afterEach(() => {
18
+ globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.dispose();
19
+ delete globalThis.lynxWorkletImpl;
20
+ });
21
+
17
22
  describe('Worklet', () => {
18
23
  const consoleMock = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
19
24
 
@@ -21,6 +26,7 @@ describe('Worklet', () => {
21
26
  globalThis.SystemInfo = {
22
27
  lynxSdkVersion: '2.16',
23
28
  };
29
+ globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.dispose();
24
30
  delete globalThis.lynxWorkletImpl;
25
31
  globalThis.lynx = {
26
32
  requestAnimationFrame: vi.fn(),
@@ -808,3 +814,49 @@ it('requestAnimationFrame should throw error before 2.16 2', async () => {
808
814
  globalThis.runWorklet(worklet, [1]);
809
815
  expect(fn).toBeCalled();
810
816
  });
817
+
818
+ it('preserves an already-bound handle execId and skips unbound handles without a root execId', () => {
819
+ globalThis.SystemInfo = { lynxSdkVersion: '2.16' };
820
+ initWorklet();
821
+ globalThis.registerWorklet('main-thread', 'capture-handles', function() {
822
+ return this._jsFn;
823
+ });
824
+
825
+ const prebound = { _jsFnId: 1, _execId: 4 };
826
+ globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.addRef(4, prebound);
827
+ const unbound = { _jsFnId: 2 };
828
+
829
+ // Root without `_execId` preserves `prebound._execId` and leaves `unbound` uncounted.
830
+ const withoutExec = { _wkltId: 'capture-handles', _jsFn: { prebound, unbound } };
831
+ globalThis.runWorklet(withoutExec, []);
832
+ expect(prebound._execId).toBe(4);
833
+ expect(unbound._execId).toBeUndefined();
834
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(4)).toBe(1);
835
+
836
+ // Another root with `_execId = 9` still does not overwrite `prebound._execId`.
837
+ const withOtherExec = { _wkltId: 'capture-handles', _execId: 9, _jsFn: { prebound } };
838
+ globalThis.runWorklet(withOtherExec, []);
839
+ expect(prebound._execId).toBe(4);
840
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(4)).toBe(1);
841
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(9)).toBeUndefined();
842
+
843
+ // A hydrated handle from an older reload epoch must not register its retired `_execId` before re-hydration.
844
+ const staleEpochHandle = { _jsFnId: 3, _execId: 7, _isFirstScreen: false, _hydratedEpoch: 0 };
845
+ globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.clearDelayedBackgroundFunctions();
846
+ globalThis.runWorklet({ _wkltId: 'capture-handles', _jsFn: { staleEpochHandle } }, []);
847
+ expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(7)).toBeUndefined();
848
+
849
+ // Short-circuit checks: a prebound handle without `_hydratedEpoch` must neither read root `_execId`
850
+ // nor dereference `_runOnBackgroundDelayImpl.epoch`.
851
+ globalThis.registerWorklet('main-thread', 'capture-arg-handle', function(cb) {
852
+ return cb._execId;
853
+ });
854
+ const args = [{ _jsFnId: 4, _execId: 12 }];
855
+ Object.defineProperty(args, '_execId', {
856
+ get() {
857
+ throw new Error('root _execId should not be read for prebound handle');
858
+ },
859
+ });
860
+ delete globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl;
861
+ expect(globalThis.runWorklet({ _wkltId: 'capture-arg-handle' }, args)).toBe(12);
862
+ });
@@ -56,6 +56,7 @@ export const {
56
56
  snapshotManager,
57
57
  snapshotCreatorMap,
58
58
  SnapshotInstance,
59
+ TransferRegistry,
59
60
  transformRef,
60
61
  transformToWorklet,
61
62
  updateEvent,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribute-name.js","sourceRoot":"","sources":["../../src/core/attribute-name.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,4BAA4B,GAAG,kEAAkE,CAAC;AACxG,MAAM,wBAAwB,GAAG,6EAA6E,CAAC;AAE/G,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,OAAO,4BAA4B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,GAAW;IAClD,OAAO,wBAAwB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,yBAAyB,CAAC,IAAY;IAC7C,IACE,IAAI,CAAC,MAAM,IAAI,CAAC;WACb,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EACzB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAI,IAAI,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACjD,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC9B,IACE,CAAC,IAAI,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE,CAAC;eACrB,CAAC,IAAI,GAAG,E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CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sEAAsE;IACtE,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,IACE,MAAM,CAAC,MAAM;eACV,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAC5D,CAAC;YACD,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAE,CAAC;QAC9B,CAAC;QACD,IACE,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC;eAC5B,MAAM,CAAC,IAAI,KAAK,cAAc,EACjC,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,0DAA0D;IAC1D,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,wBAAwB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0EAA0E;IAC1E,IAAI,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;YACjC,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;IAC9C,CAAC;IAED,+DAA+D;IAC/D,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nconst lynxEventAttributeNameRegExp = /^(?:global-bind|bind|catch|capture-bind|capture-catch)[A-Za-z]+$/;\nconst namespacedEventKeyRegExp = /^[A-Za-z-]+:(?:global-bind|bind|catch|capture-bind|capture-catch)[A-Za-z]+$/;\n\nexport function isEventPropKey(key: string): boolean {\n return lynxEventAttributeNameRegExp.test(key);\n}\n\nexport function isNamespacedEventPropKey(key: string): boolean {\n return namespacedEventKeyRegExp.test(key);\n}\n\nfunction isReactEventAttributeName(name: string): boolean {\n if (\n name.length <= 2\n || !name.startsWith('on')\n ) {\n return false;\n }\n\n let code = name.charCodeAt(2);\n if (code < 65 || code > 90) {\n return false;\n }\n for (let index = 3; index < name.length; index++) {\n code = name.charCodeAt(index);\n if (\n (code < 65 || code > 90)\n && (code < 97 || code > 122)\n ) {\n return false;\n }\n }\n return true;\n}\n\nfunction toDashCase(name: string): string {\n let index = 0;\n for (; index < name.length; index++) {\n const code = name.charCodeAt(index);\n if (code >= 65 && code <= 90) {\n break;\n }\n }\n\n if (index === name.length) {\n return name;\n }\n\n let transformed = name.slice(0, index);\n for (; index < name.length; index++) {\n const code = name.charCodeAt(index);\n if (code >= 65 && code <= 90) {\n if (index !== 0) {\n transformed += '-';\n }\n transformed += name[index]!.toLowerCase();\n } else {\n transformed += name[index];\n }\n }\n return transformed;\n}\n\nexport function transformAttrName(name: string): string {\n const config = lynx.__runtime_configs__?.transformBuiltinAttributeNames;\n\n // A disabled config keeps every name unchanged.\n if (!config) {\n return name;\n }\n\n // An object config applies rules in `rename > preserve > mode` order.\n if (config !== true) {\n if (\n config.rename\n && Object.prototype.hasOwnProperty.call(config.rename, name)\n ) {\n return config.rename[name]!;\n }\n if (\n config.preserve?.includes(name)\n || config.mode === 'mapping-only'\n ) {\n return name;\n }\n }\n\n // Enabled configs keep native Lynx event names unchanged.\n if (isEventPropKey(name) || isNamespacedEventPropKey(name)) {\n return name;\n }\n\n // `true` and the default dash-case mode apply React-style event mappings.\n if (isReactEventAttributeName(name)) {\n if (name === 'onClick') {\n return 'bindtap';\n } else if (name === 'onCatchTap') {\n return 'catchtap';\n }\n return `bind${name.slice(2).toLowerCase()}`;\n }\n\n // Remaining names use dash-case when the transform is enabled.\n return toDashCase(name);\n}\n"]}
@@ -2,8 +2,8 @@
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 { BackgroundFunctionExecMap } from './exec-map.js';
5
- import { isSdkVersionGt } from '../../utils.js';
6
- import { delayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';
5
+ import { isSdkVersionGt } from '../../shared/version.js';
6
+ import { delayRunOnBackground, shouldDelayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';
7
7
  import { WorkletEvents } from '../../worklet-runtime/bindings/events.js';
8
8
  import { addReloadScopedEventListener, dispatchReloadScopedEvent } from '../reload-scoped-event.js';
9
9
  import { isRuntimeDestroyed, registerDestroyTask } from '../runtime-destroy.js';
@@ -108,18 +108,18 @@ export function runOnBackground(f) {
108
108
  return new Promise((resolve) => {
109
109
  if (isRuntimeDestroyed())
110
110
  return;
111
- const resolveId = onFunctionCall(resolve);
112
- if (obj._isFirstScreen) {
111
+ if (shouldDelayRunOnBackground(obj)) {
113
112
  delayRunOnBackground(obj, (fnId, execId) => {
114
- dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId);
113
+ dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolve);
115
114
  });
116
115
  return;
117
116
  }
118
- dispatchRunBackgroundFunctionEvent(obj._jsFnId, params, obj._execId, resolveId);
117
+ dispatchRunBackgroundFunctionEvent(obj._jsFnId, params, obj._execId, resolve);
119
118
  });
120
119
  };
121
120
  }
122
- function dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId) {
121
+ function dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolve) {
122
+ const resolveId = onFunctionCall(resolve);
123
123
  dispatchReloadScopedEvent(lynx.getJSContext(), {
124
124
  type: WorkletEvents.runOnBackground,
125
125
  data: {
@@ -1 +1 @@
1
- {"version":3,"file":"run-on-background.js","sourceRoot":"","sources":["../../../src/core/background-function/run-on-background.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,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MAAM;YACN,SAAS;SACa;KACzB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { BackgroundFunctionExecMap } from './exec-map.js';\nimport { isSdkVersionGt } from '../../utils.js';\nimport { delayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';\nimport { WorkletEvents } from '../../worklet-runtime/bindings/events.js';\nimport type { RunWorkletCtxRetData } from '../../worklet-runtime/bindings/events.js';\nimport type { ClosureValueType, JsFnHandle, Worklet } from '../../worklet-runtime/bindings/types.js';\nimport { addReloadScopedEventListener, dispatchReloadScopedEvent } from '../reload-scoped-event.js';\nimport { isRuntimeDestroyed, registerDestroyTask } from '../runtime-destroy.js';\nimport { onFunctionCall } from '../thread-function-call/return-value.js';\n\n/**\n * @internal\n */\ninterface RunOnBackgroundData {\n obj: JsFnHandle;\n params: unknown[];\n resolveId: number;\n}\n\nlet execIdMap: BackgroundFunctionExecMap | undefined;\nlet cleanupBackgroundFunctionRuntime: (() => void) | undefined;\nlet unregisterBackgroundFunctionCleanup: (() => void) | undefined;\n\nfunction initBackgroundFunctionRuntime(): void {\n 'background only';\n if (cleanupBackgroundFunctionRuntime) {\n return;\n }\n\n execIdMap ??= new BackgroundFunctionExecMap();\n const context = lynx.getCoreContext();\n const removeListener = addReloadScopedEventListener(context, WorkletEvents.runOnBackground, runBackgroundFunction);\n context.addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n\n cleanupBackgroundFunctionRuntime = () => {\n removeListener();\n context.removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n execIdMap!.clear();\n cleanupBackgroundFunctionRuntime = undefined;\n };\n}\n\n/**\n * @internal\n */\nexport function runBackgroundFunction(data: RunOnBackgroundData): void {\n 'background only';\n const obj = execIdMap!.findJsFnHandle(data.obj._execId!, data.obj._jsFnId!);\n const f = obj?._fn;\n if (!f) {\n throw new Error('runOnBackground: JS function not found: ' + JSON.stringify(data.obj));\n }\n const returnValue = f(...data.params);\n dispatchReloadScopedEvent(lynx.getCoreContext(), {\n type: WorkletEvents.FunctionCallRet,\n data: { resolveId: data.resolveId, returnValue } satisfies RunWorkletCtxRetData,\n });\n}\n\nfunction releaseBackgroundFunctionCtx(event: RuntimeProxy.Event): void {\n 'background only';\n for (const id of event.data) {\n execIdMap!.remove(id as number);\n }\n}\n\n/**\n * @internal\n */\nexport function registerBackgroundFunctionCtx(ctx: Worklet): void {\n 'background only';\n initBackgroundFunctionRuntime();\n ensureBackgroundFunctionCleanup();\n execIdMap!.add(ctx);\n}\n\nfunction ensureBackgroundFunctionCleanup(): void {\n if (unregisterBackgroundFunctionCleanup) {\n return;\n }\n unregisterBackgroundFunctionCleanup = registerDestroyTask(() => {\n resetBackgroundFunctionRuntime();\n });\n}\n\nexport function resetBackgroundFunctionRuntime(): void {\n cleanupBackgroundFunctionRuntime?.();\n unregisterBackgroundFunctionCleanup?.();\n unregisterBackgroundFunctionCleanup = undefined;\n}\n\n/**\n * `runOnBackground` allows triggering js functions on the background thread asynchronously.\n * @param f - The js function to be called.\n * @returns A function. Calling which with the arguments to be passed to the js function to trigger it on the background thread. This function returns a promise that resolves to the return value of the js function.\n * @public\n *\n * @example\n *\n * ```ts\n * import { runOnBackground } from '@lynx-js/react';\n *\n * async function someMainthreadFunction() {\n * 'main thread';\n * const fn = runOnBackground(() => {\n * return 'hello';\n * });\n * const result = await fn();\n * }\n * ```\n *\n * @group Functions\n */\nexport function runOnBackground<R, Fn extends (...args: any[]) => R>(\n f: Fn,\n): (...args: Parameters<Fn>) => Promise<R> {\n if (!isSdkVersionGt(2, 15)) {\n throw new Error('runOnBackground requires Lynx sdk version 2.16.');\n }\n if (__JS__) {\n throw new Error('runOnBackground can only be used on the main thread.');\n }\n const obj = f as any as JsFnHandle;\n if (obj._error) {\n throw new Error(obj._error);\n }\n return async (...params: ClosureValueType[]): Promise<R> => {\n return new Promise((resolve) => {\n if (isRuntimeDestroyed()) return;\n const resolveId = onFunctionCall(resolve);\n\n if (obj._isFirstScreen) {\n delayRunOnBackground(obj, (fnId: number, execId: number) => {\n dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId);\n });\n return;\n }\n\n dispatchRunBackgroundFunctionEvent(obj._jsFnId!, params, obj._execId!, resolveId);\n });\n };\n}\n\nfunction dispatchRunBackgroundFunctionEvent(\n fnId: number,\n params: ClosureValueType[],\n execId: number,\n resolveId: number,\n): void {\n dispatchReloadScopedEvent(lynx.getJSContext(), {\n type: WorkletEvents.runOnBackground,\n data: {\n obj: {\n _jsFnId: fnId,\n _execId: execId,\n },\n params,\n resolveId,\n } as RunOnBackgroundData,\n });\n}\n"]}
1
+ {"version":3,"file":"run-on-background.js","sourceRoot":"","sources":["../../../src/core/background-function/run-on-background.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAC9G,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAGzE,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAWzE,IAAI,SAAgD,CAAC;AACrD,IAAI,gCAA0D,CAAC;AAC/D,IAAI,mCAA6D,CAAC;AAElE,SAAS,6BAA6B;IACpC,iBAAiB,CAAC;IAClB,IAAI,gCAAgC,EAAE,CAAC;QACrC,OAAO;IACT,CAAC;IAED,SAAS,KAAK,IAAI,yBAAyB,EAA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gBACpC,oBAAoB,CAAC,GAAG,EAAE,CAAC,IAAY,EAAE,MAAc,EAAE,EAAE;oBACzD,kCAAkC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;gBACpE,CAAC,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YAED,kCAAkC,CAAC,GAAG,CAAC,OAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,OAAQ,EAAE,OAAO,CAAC,CAAC;QAClF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,kCAAkC,CACzC,IAAY,EACZ,MAA0B,EAC1B,MAAc,EACd,OAA6B;IAE7B,MAAM,SAAS,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IAC1C,yBAAyB,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE;QAC7C,IAAI,EAAE,aAAa,CAAC,eAAe;QACnC,IAAI,EAAE;YACJ,GAAG,EAAE;gBACH,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,MAAM;aAChB;YACD,MAAM;YACN,SAAS;SACa;KACzB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { BackgroundFunctionExecMap } from './exec-map.js';\nimport { isSdkVersionGt } from '../../shared/version.js';\nimport { delayRunOnBackground, shouldDelayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';\nimport { WorkletEvents } from '../../worklet-runtime/bindings/events.js';\nimport type { RunWorkletCtxRetData } from '../../worklet-runtime/bindings/events.js';\nimport type { ClosureValueType, JsFnHandle, Worklet } from '../../worklet-runtime/bindings/types.js';\nimport { addReloadScopedEventListener, dispatchReloadScopedEvent } from '../reload-scoped-event.js';\nimport { isRuntimeDestroyed, registerDestroyTask } from '../runtime-destroy.js';\nimport { onFunctionCall } from '../thread-function-call/return-value.js';\n\n/**\n * @internal\n */\ninterface RunOnBackgroundData {\n obj: JsFnHandle;\n params: unknown[];\n resolveId: number;\n}\n\nlet execIdMap: BackgroundFunctionExecMap | undefined;\nlet cleanupBackgroundFunctionRuntime: (() => void) | undefined;\nlet unregisterBackgroundFunctionCleanup: (() => void) | undefined;\n\nfunction initBackgroundFunctionRuntime(): void {\n 'background only';\n if (cleanupBackgroundFunctionRuntime) {\n return;\n }\n\n execIdMap ??= new BackgroundFunctionExecMap();\n const context = lynx.getCoreContext();\n const removeListener = addReloadScopedEventListener(context, WorkletEvents.runOnBackground, runBackgroundFunction);\n context.addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n\n cleanupBackgroundFunctionRuntime = () => {\n removeListener();\n context.removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n execIdMap!.clear();\n cleanupBackgroundFunctionRuntime = undefined;\n };\n}\n\n/**\n * @internal\n */\nexport function runBackgroundFunction(data: RunOnBackgroundData): void {\n 'background only';\n const obj = execIdMap!.findJsFnHandle(data.obj._execId!, data.obj._jsFnId!);\n const f = obj?._fn;\n if (!f) {\n throw new Error('runOnBackground: JS function not found: ' + JSON.stringify(data.obj));\n }\n const returnValue = f(...data.params);\n dispatchReloadScopedEvent(lynx.getCoreContext(), {\n type: WorkletEvents.FunctionCallRet,\n data: { resolveId: data.resolveId, returnValue } satisfies RunWorkletCtxRetData,\n });\n}\n\nfunction releaseBackgroundFunctionCtx(event: RuntimeProxy.Event): void {\n 'background only';\n for (const id of event.data) {\n execIdMap!.remove(id as number);\n }\n}\n\n/**\n * @internal\n */\nexport function registerBackgroundFunctionCtx(ctx: Worklet): void {\n 'background only';\n initBackgroundFunctionRuntime();\n ensureBackgroundFunctionCleanup();\n execIdMap!.add(ctx);\n}\n\nfunction ensureBackgroundFunctionCleanup(): void {\n if (unregisterBackgroundFunctionCleanup) {\n return;\n }\n unregisterBackgroundFunctionCleanup = registerDestroyTask(() => {\n resetBackgroundFunctionRuntime();\n });\n}\n\nexport function resetBackgroundFunctionRuntime(): void {\n cleanupBackgroundFunctionRuntime?.();\n unregisterBackgroundFunctionCleanup?.();\n unregisterBackgroundFunctionCleanup = undefined;\n}\n\n/**\n * `runOnBackground` allows triggering js functions on the background thread asynchronously.\n * @param f - The js function to be called.\n * @returns A function. Calling which with the arguments to be passed to the js function to trigger it on the background thread. This function returns a promise that resolves to the return value of the js function.\n * @public\n *\n * @example\n *\n * ```ts\n * import { runOnBackground } from '@lynx-js/react';\n *\n * async function someMainthreadFunction() {\n * 'main thread';\n * const fn = runOnBackground(() => {\n * return 'hello';\n * });\n * const result = await fn();\n * }\n * ```\n *\n * @group Functions\n */\nexport function runOnBackground<R, Fn extends (...args: any[]) => R>(\n f: Fn,\n): (...args: Parameters<Fn>) => Promise<R> {\n if (!isSdkVersionGt(2, 15)) {\n throw new Error('runOnBackground requires Lynx sdk version 2.16.');\n }\n if (__JS__) {\n throw new Error('runOnBackground can only be used on the main thread.');\n }\n const obj = f as any as JsFnHandle;\n if (obj._error) {\n throw new Error(obj._error);\n }\n return async (...params: ClosureValueType[]): Promise<R> => {\n return new Promise((resolve) => {\n if (isRuntimeDestroyed()) return;\n\n if (shouldDelayRunOnBackground(obj)) {\n delayRunOnBackground(obj, (fnId: number, execId: number) => {\n dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolve);\n });\n return;\n }\n\n dispatchRunBackgroundFunctionEvent(obj._jsFnId!, params, obj._execId!, resolve);\n });\n };\n}\n\nfunction dispatchRunBackgroundFunctionEvent(\n fnId: number,\n params: ClosureValueType[],\n execId: number,\n resolve: (value: any) => void,\n): void {\n const resolveId = onFunctionCall(resolve);\n dispatchReloadScopedEvent(lynx.getJSContext(), {\n type: WorkletEvents.runOnBackground,\n data: {\n obj: {\n _jsFnId: fnId,\n _execId: execId,\n },\n params,\n resolveId,\n } as RunOnBackgroundData,\n });\n}\n"]}
@@ -26,7 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
26
  SOFTWARE.
27
27
  */
28
28
  import { Fragment, options } from 'preact';
29
- import { DIFF, DIFFED, RENDER, ROOT } from './render-constants.js';
29
+ import { DIFF, DIFFED, RENDER, ROOT } from '../shared/render-constants.js';
30
30
  /**
31
31
  * Get human readable name of the component/dom node
32
32
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-stack.js","sourceRoot":"","sources":["../../src/core/component-stack.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAG3C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAW3E;;GAEG;AACH,SAAS,mBAAmB,CAAC,KAAmB;IAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,UAAU,CAAC;IACpB,CAAC;SAAM,IAAI,OAAO,KAAK,CAAC,IAAI,IAAI,UAAU,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;IACnD,CAAC;SAAM,IAAI,OAAO,KAAK,CAAC,IAAI,IAAI,QAAQ,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,WAAW,GAAmB,EAAE,CAAC;AAEvC;;;;;;;;;;;;;;;;;GAiBG;AACH,IAAI,UAAU,GAAmB,EAAE,CAAC;AACpC,IAAI,wBAAwB,GAAG,KAAK,CAAC;AAErC;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAA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CAAC;IACtC,CAAC,CAAC;IAEF,OAAO,CAAC,KAAK,GAAG,CAAC,KAAmB,EAAE,EAAE;QACtC,gFAAgF;QAChF,4EAA4E;QAC5E,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/B,KAAK,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACnF,CAAC;QACD,IAAI,QAAQ;YAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,EAAE;QACxB,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QAED,IAAI,SAAS;YAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * @license\nThe MIT License (MIT)\n\nCopyright (c) 2015-present Jason Miller\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n */\n\nimport { Fragment, options } from 'preact';\nimport type { VNode } from 'preact';\n\nimport { DIFF, DIFFED, RENDER, ROOT } from '../shared/render-constants.js';\n\ninterface PatchedVNode extends VNode {\n _owner?: PatchedVNode | null;\n\n __source?: {\n fileName: string;\n lineNumber: number;\n };\n}\n\n/**\n * Get human readable name of the component/dom node\n */\nfunction getVNodeDisplayName(vnode: PatchedVNode): string {\n if (vnode.type === Fragment) {\n return 'Fragment';\n } else if (typeof vnode.type == 'function') {\n return vnode.type.displayName ?? vnode.type.name;\n } else if (typeof vnode.type == 'string') {\n return vnode.type;\n }\n\n return '#text';\n}\n\n/**\n * Used to keep track of the currently rendered `vnode` and print it\n * in debug messages.\n */\nconst renderStack: PatchedVNode[] = [];\n\n/**\n * Keep track of the current owners. An owner describes a component\n * which was responsible to render a specific `vnode`. This exclude\n * children that are passed via `props.children`, because they belong\n * to the parent owner.\n *\n * ```jsx\n * const Foo = props => <div>{props.children}</div> // div's owner is Foo\n * const Bar = props => {\n * return (\n * <Foo><span /></Foo> // Foo's owner is Bar, span's owner is Bar\n * )\n * }\n * ```\n *\n * Note: A `vnode` may be hoisted to the root scope due to compiler\n * optimization. In these cases the `_owner` will be different.\n */\nlet ownerStack: PatchedVNode[] = [];\nlet didInstallComponentStack = false;\n\n/**\n * Get the currently rendered `vnode`\n */\nexport function getCurrentVNode(): PatchedVNode | null {\n return renderStack.length > 0 ? renderStack[renderStack.length - 1]! : null;\n}\n\n/**\n * Check if a `vnode` is a possible owner.\n */\nfunction isPossibleOwner(vnode: PatchedVNode) {\n return typeof vnode.type == 'function' && vnode.type != Fragment;\n}\n\n/**\n * Return the component stack that was captured up to this point.\n */\nexport function getOwnerStack(vnode: PatchedVNode): string {\n const stack = [vnode];\n let next = vnode;\n while (next._owner != null) {\n stack.push(next._owner);\n next = next._owner;\n }\n\n return stack.reduce((acc, owner) => {\n acc += ` in ${getVNodeDisplayName(owner)}`;\n\n const source = owner.__source;\n if (source) {\n acc += ` (at ${source.fileName}:${source.lineNumber})`;\n }\n\n return (acc += '\\n');\n }, '');\n}\n\n/**\n * Setup code to capture the component trace while rendering. Note that\n * we cannot simply traverse `vnode._parent` upwards, because we have some\n * debug messages for `this.setState` where the `vnode` is `undefined`.\n */\nexport function setupComponentStack(): void {\n renderStack.length = 0;\n ownerStack = [];\n if (didInstallComponentStack) {\n return;\n }\n didInstallComponentStack = true;\n\n /* eslint-disable @typescript-eslint/unbound-method */\n const oldDiff = options[DIFF];\n const oldDiffed = options[DIFFED];\n const oldRoot = options[ROOT];\n const oldVNode = options.vnode;\n const oldRender = options[RENDER];\n /* eslint-enable @typescript-eslint/unbound-method */\n\n options[DIFFED] = vnode => {\n if (isPossibleOwner(vnode)) {\n const ownerIndex = ownerStack.lastIndexOf(vnode);\n if (ownerIndex !== -1) {\n ownerStack.length = ownerIndex;\n }\n const renderIndex = renderStack.lastIndexOf(vnode);\n if (renderIndex !== -1) {\n renderStack.length = renderIndex;\n }\n }\n if (oldDiffed) oldDiffed(vnode);\n };\n\n options[DIFF] = vnode => {\n if (isPossibleOwner(vnode)) {\n renderStack.push(vnode);\n }\n if (oldDiff) oldDiff(vnode);\n };\n\n options[ROOT] = (vnode, parent) => {\n if (!(parent as { parentNode?: unknown } | null | undefined)?.parentNode) {\n renderStack.length = 0;\n ownerStack = [];\n }\n if (oldRoot) oldRoot(vnode, parent);\n };\n\n options.vnode = (vnode: PatchedVNode) => {\n // Scheduled component updates clone the vnode before entering its render scope.\n // Preserve the original owner when Preact invokes this hook for that clone.\n if (vnode._owner === undefined) {\n vnode._owner = ownerStack.length > 0 ? ownerStack[ownerStack.length - 1]! : null;\n }\n if (oldVNode) oldVNode(vnode);\n };\n\n options[RENDER] = vnode => {\n if (isPossibleOwner(vnode)) {\n ownerStack.push(vnode);\n }\n\n if (oldRender) oldRender(vnode);\n };\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function isDirectOrDeepEqual(a: unknown, b: unknown): boolean;
@@ -0,0 +1,31 @@
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
+ import { getCurrentVNode, getOwnerStack } from './component-stack.js';
5
+ export function isDirectOrDeepEqual(a, b) {
6
+ if (a === b) {
7
+ return true;
8
+ }
9
+ try {
10
+ if (typeof a == 'object' && a !== null && typeof b == 'object' && b !== null
11
+ && JSON.stringify(a) === JSON.stringify(b)) {
12
+ return true;
13
+ }
14
+ }
15
+ catch (error) {
16
+ if (__DEV__ && /circular|cyclic/i.test(error.message)) {
17
+ // JavaScript engines give this different errors name and messages:
18
+ // PrimJS: "circular reference"
19
+ // JavaScriptCore: "JSON.stringify cannot serialize cyclic structures"
20
+ // V8: "Converting circular structure to JSON"
21
+ const vnode = getCurrentVNode();
22
+ if (vnode) {
23
+ const stack = getOwnerStack(vnode);
24
+ error.message += `\n\n${stack}`;
25
+ }
26
+ }
27
+ throw error;
28
+ }
29
+ return false;
30
+ }
31
+ //# sourceMappingURL=deep-equal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-equal.js","sourceRoot":"","sources":["../../src/core/deep-equal.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEtE,MAAM,UAAU,mBAAmB,CAAC,CAAU,EAAE,CAAU;IACxD,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC;QACH,IACE,OAAO,CAAC,IAAI,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,QAAQ,IAAI,CAAC,KAAK,IAAI;eACrE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAC1C,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAE,KAAe,CAAC,OAAO,CAAC,EAAE,CAAC;YACjE,mEAAmE;YACnE,+BAA+B;YAC/B,sEAAsE;YACtE,8CAA8C;YAC9C,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;YAChC,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;gBAClC,KAAe,CAAC,OAAO,IAAI,OAAO,KAAK,EAAE,CAAC;YAC7C,CAAC;QACH,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { getCurrentVNode, getOwnerStack } from './component-stack.js';\n\nexport function isDirectOrDeepEqual(a: unknown, b: unknown): boolean {\n if (a === b) {\n return true;\n }\n try {\n if (\n typeof a == 'object' && a !== null && typeof b == 'object' && b !== null\n && JSON.stringify(a) === JSON.stringify(b)\n ) {\n return true;\n }\n } catch (error) {\n if (__DEV__ && /circular|cyclic/i.test((error as Error).message)) {\n // JavaScript engines give this different errors name and messages:\n // PrimJS: \"circular reference\"\n // JavaScriptCore: \"JSON.stringify cannot serialize cyclic structures\"\n // V8: \"Converting circular structure to JSON\"\n const vnode = getCurrentVNode();\n if (vnode) {\n const stack = getOwnerStack(vnode);\n (error as Error).message += `\\n\\n${stack}`;\n }\n }\n throw error;\n }\n return false;\n}\n"]}
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { options } from 'preact';
11
11
  import { CHILDREN, COMPONENT, DIFF, DIFFED, HOOK, HOOKS, LIST, MASK, PARENT, PENDING_EFFECTS, RENDER, ROOT, VALUE, VNODE, } from '../../shared/render-constants.js';
12
- import { noop } from '../../utils.js';
12
+ import { noop } from '../../shared/utils.js';
13
13
  let currentIndex;
14
14
  let currentComponent;
15
15
  let currentHook;
@@ -1 +1 @@
1
- {"version":3,"file":"mainThreadImpl.js","sourceRoot":"","sources":["../../../src/core/hooks/mainThreadImpl.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAUjC,OAAO,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,eAAe,EACf,MAAM,EACN,IAAI,EACJ,KAAK,EACL,KAAK,GACN,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,IAAI,YAAoB,CAAC;AACzB,IAAI,gBAA8C,CAAC;AACnD,IAAI,WAAmB,CAAC;AACxB,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,aAAiD,CAAC;AACtD,IAAI,eAAmD,CAAC;AACxD,IAAI,YAAgD,CAAC;AACrD,IAAI,OAA2D,CAAC;AAEhE,SAAS,sBAAsB;IAC7B,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO;IACT,CAAC;IACD,cAAc,GAAG,IAAI,CAAC;IACtB,sDAAsD;IACtD,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,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,EACb,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,UAAU,EACV,MAAM,EACN,QAAQ,GACT,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements hooks in the main thread.\n * This module is modified from preact/hooks\n *\n * internal-preact/hooks/dist/hooks.mjs\n */\n\nimport { options } from 'preact';\nimport type { Component, ErrorInfo, PreactContext } from 'preact';\nimport type {\n Dispatch,\n useEffect as useEffectType,\n useErrorBoundary as useErrorBoundaryType,\n useImperativeHandle as useImperativeHandleType,\n useLayoutEffect as useLayoutEffectType,\n} from 'preact/hooks';\n\nimport {\n CHILDREN,\n COMPONENT,\n DIFF,\n DIFFED,\n HOOK,\n HOOKS,\n LIST,\n MASK,\n PARENT,\n PENDING_EFFECTS,\n RENDER,\n ROOT,\n VALUE,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { noop } from '../../utils.js';\n\nlet currentIndex: number;\nlet currentComponent: Component | null | undefined;\nlet currentHook: number;\nlet hooksInstalled = false;\nlet oldBeforeDiff: ((vnode: any) => void) | undefined;\nlet oldBeforeRender: ((vnode: any) => void) | undefined;\nlet oldAfterDiff: ((vnode: any) => void) | undefined;\nlet oldRoot: ((vnode: any, parentDom: any) => void) | undefined;\n\nfunction installMainThreadHooks(): void {\n if (hooksInstalled) {\n return;\n }\n hooksInstalled = true;\n /* eslint-disable @typescript-eslint/unbound-method */\n oldBeforeDiff = options[DIFF];\n oldBeforeRender = options[RENDER];\n oldAfterDiff = options[DIFFED];\n oldRoot = options[ROOT];\n /* eslint-enable @typescript-eslint/unbound-method */\n\n options[DIFF] = function(vnode) {\n currentComponent = null;\n if (oldBeforeDiff) oldBeforeDiff(vnode);\n };\n\n /* v8 ignore start */\n options[ROOT] = function(vnode, parentDom) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (vnode && parentDom[CHILDREN] && parentDom[CHILDREN][MASK]) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n vnode[MASK] = parentDom[CHILDREN][MASK] as [number, number];\n }\n if (oldRoot) oldRoot(vnode, parentDom);\n };\n /* v8 ignore stop */\n\n options[RENDER] = function(vnode) {\n if (oldBeforeRender) oldBeforeRender(vnode);\n currentComponent = vnode[COMPONENT];\n currentIndex = 0;\n };\n\n options[DIFFED] = function(vnode) {\n if (oldAfterDiff) oldAfterDiff(vnode);\n currentComponent = null;\n };\n}\n\nfunction getHookState(index: number, type: number) {\n if (options[HOOK]) {\n options[HOOK](currentComponent!, index, currentHook || type);\n }\n currentHook = 0;\n const hooks = currentComponent![HOOKS] ?? (currentComponent![HOOKS] = {\n [LIST]: [],\n [PENDING_EFFECTS]: [],\n });\n if (index >= hooks[LIST]!.length) {\n hooks[LIST]!.push({});\n }\n return hooks[LIST]![index];\n}\n\nfunction invokeOrReturn(arg: unknown, f: (...args: unknown[]) => unknown) {\n return typeof f == 'function' ? f(arg) : f;\n}\n\nfunction useState<S>(initialState: S | (() => S)) {\n currentHook = 1;\n return useReducer(noop, initialState) as [S, Dispatch<unknown>];\n}\n\nfunction useReducer<S, A>(\n _reducer: (prevState: S, action: A) => S,\n initialState: S | (() => S),\n init?: (initialState: S) => S,\n) {\n const hookState = getHookState(currentIndex++, 2)!;\n if (!hookState[COMPONENT]) {\n hookState[VALUE] = [\n /* v8 ignore start */\n init ? init(initialState as S) : invokeOrReturn(undefined, initialState as (() => S)),\n /* v8 ignore stop */\n function(_action: A) {\n if (__DEV__) {\n console.error('Cannot update state in main thread!');\n }\n },\n ];\n hookState[COMPONENT] = currentComponent;\n }\n return hookState[VALUE] as [S, Dispatch<A>];\n}\n\nfunction useRef<T>(initialValue?: T): { current: T | undefined } {\n currentHook = 5;\n return useMemo(function() {\n return {\n current: initialValue,\n };\n }, []);\n}\n\n// used for first screen and need not to cache value by args\nfunction useMemo<T>(factory: () => T, _args: ReadonlyArray<unknown>): T {\n const state = getHookState(currentIndex++, 7)!;\n state[VALUE] = factory();\n return state[VALUE] as T;\n}\n\nfunction useCallback<T>(callback: T, args: ReadonlyArray<unknown>): T {\n currentHook = 8;\n return useMemo(function() {\n return callback;\n }, args);\n}\n\nfunction useContext<T>(context: PreactContext<T>): T {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const provider = currentComponent!.context[context.__c] as {\n props: {\n value: T;\n };\n };\n const state = getHookState(currentIndex++, 9)!;\n state['c'] = context;\n /* v8 ignore start */\n if (!provider) return context.__;\n /* v8 ignore stop */\n state[VALUE] = true;\n return provider.props.value;\n}\n\nfunction useDebugValue<T>(value: T, formatter?: (value: T) => string | number): void {\n if (options.useDebugValue) {\n /* v8 ignore start */\n options.useDebugValue(formatter ? formatter(value) : value as string | number);\n /* v8 ignore stop */\n }\n}\n\nfunction useErrorBoundary(cb: (error: any, errorInfo: ErrorInfo) => Promise<void> | void) {\n const state = getHookState(currentIndex++, 10)!;\n state[VALUE] = cb;\n return [undefined, noop] as ReturnType<typeof useErrorBoundaryType>;\n}\n\nfunction useId(): string {\n const state = getHookState(currentIndex++, 11)!;\n if (!state[VALUE]) {\n // Grab either the root node or the nearest async boundary node.\n let root = currentComponent![VNODE];\n while (root !== null && !root![MASK] && root![PARENT] !== null) {\n root = root![PARENT];\n }\n /**\n * init mask to [0, 0]\n * mask[0] will not change\n * mask[1] will auto increase\n */\n const mask = root![MASK] ?? (root![MASK] = [0, 0]);\n state[VALUE] = 'P' + mask[0] + '-' + mask[1]++;\n }\n return state[VALUE] as string;\n}\n\n// background hooks\nconst useEffect = noop as typeof useEffectType;\nconst useLayoutEffect = noop as typeof useLayoutEffectType;\nconst useImperativeHandle = noop as typeof useImperativeHandleType;\n\nexport {\n installMainThreadHooks,\n useCallback,\n useContext,\n useDebugValue,\n useEffect,\n useErrorBoundary,\n useId,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n};\n"]}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O,CAAC,SAAS,EAAE,IAAI,CAA4C,CAAC;AACtE,CAAC;AAED,SAAS,KAAK;IACZ,MAAM,KAAK,GAAG,YAAY,CAAC,YAAY,EAAE,EAAE,EAAE,CAAE,CAAC;IAChD,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QAClB,gEAAgE;QAChE,IAAI,IAAI,GAAG,gBAAiB,CAAC,KAAK,CAAC,CAAC;QACpC,OAAO,IAAI,KAAK,IAAI,IAAI,CAAC,IAAK,CAAC,IAAI,CAAC,IAAI,IAAK,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;YAC/D,IAAI,GAAG,IAAK,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;QACD;;;;WAIG;QACH,MAAM,IAAI,GAAG,IAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACnD,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAW,CAAC;AAChC,CAAC;AAED,mBAAmB;AACnB,MAAM,SAAS,GAAG,IAA4B,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAkC,CAAC;AAC3D,MAAM,mBAAmB,GAAG,IAAsC,CAAC;AAEnE,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,UAAU,EACV,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,UAAU,EACV,MAAM,EACN,QAAQ,GACT,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements hooks in the main thread.\n * This module is modified from preact/hooks\n *\n * internal-preact/hooks/dist/hooks.mjs\n */\n\nimport { options } from 'preact';\nimport type { Component, ErrorInfo, PreactContext } from 'preact';\nimport type {\n Dispatch,\n useEffect as useEffectType,\n useErrorBoundary as useErrorBoundaryType,\n useImperativeHandle as useImperativeHandleType,\n useLayoutEffect as useLayoutEffectType,\n} from 'preact/hooks';\n\nimport {\n CHILDREN,\n COMPONENT,\n DIFF,\n DIFFED,\n HOOK,\n HOOKS,\n LIST,\n MASK,\n PARENT,\n PENDING_EFFECTS,\n RENDER,\n ROOT,\n VALUE,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { noop } from '../../shared/utils.js';\n\nlet currentIndex: number;\nlet currentComponent: Component | null | undefined;\nlet currentHook: number;\nlet hooksInstalled = false;\nlet oldBeforeDiff: ((vnode: any) => void) | undefined;\nlet oldBeforeRender: ((vnode: any) => void) | undefined;\nlet oldAfterDiff: ((vnode: any) => void) | undefined;\nlet oldRoot: ((vnode: any, parentDom: any) => void) | undefined;\n\nfunction installMainThreadHooks(): void {\n if (hooksInstalled) {\n return;\n }\n hooksInstalled = true;\n /* eslint-disable @typescript-eslint/unbound-method */\n oldBeforeDiff = options[DIFF];\n oldBeforeRender = options[RENDER];\n oldAfterDiff = options[DIFFED];\n oldRoot = options[ROOT];\n /* eslint-enable @typescript-eslint/unbound-method */\n\n options[DIFF] = function(vnode) {\n currentComponent = null;\n if (oldBeforeDiff) oldBeforeDiff(vnode);\n };\n\n /* v8 ignore start */\n options[ROOT] = function(vnode, parentDom) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (vnode && parentDom[CHILDREN] && parentDom[CHILDREN][MASK]) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n vnode[MASK] = parentDom[CHILDREN][MASK] as [number, number];\n }\n if (oldRoot) oldRoot(vnode, parentDom);\n };\n /* v8 ignore stop */\n\n options[RENDER] = function(vnode) {\n if (oldBeforeRender) oldBeforeRender(vnode);\n currentComponent = vnode[COMPONENT];\n currentIndex = 0;\n };\n\n options[DIFFED] = function(vnode) {\n if (oldAfterDiff) oldAfterDiff(vnode);\n currentComponent = null;\n };\n}\n\nfunction getHookState(index: number, type: number) {\n if (options[HOOK]) {\n options[HOOK](currentComponent!, index, currentHook || type);\n }\n currentHook = 0;\n const hooks = currentComponent![HOOKS] ?? (currentComponent![HOOKS] = {\n [LIST]: [],\n [PENDING_EFFECTS]: [],\n });\n if (index >= hooks[LIST]!.length) {\n hooks[LIST]!.push({});\n }\n return hooks[LIST]![index];\n}\n\nfunction invokeOrReturn(arg: unknown, f: (...args: unknown[]) => unknown) {\n return typeof f == 'function' ? f(arg) : f;\n}\n\nfunction useState<S>(initialState: S | (() => S)) {\n currentHook = 1;\n return useReducer(noop, initialState) as [S, Dispatch<unknown>];\n}\n\nfunction useReducer<S, A>(\n _reducer: (prevState: S, action: A) => S,\n initialState: S | (() => S),\n init?: (initialState: S) => S,\n) {\n const hookState = getHookState(currentIndex++, 2)!;\n if (!hookState[COMPONENT]) {\n hookState[VALUE] = [\n /* v8 ignore start */\n init ? init(initialState as S) : invokeOrReturn(undefined, initialState as (() => S)),\n /* v8 ignore stop */\n function(_action: A) {\n if (__DEV__) {\n console.error('Cannot update state in main thread!');\n }\n },\n ];\n hookState[COMPONENT] = currentComponent;\n }\n return hookState[VALUE] as [S, Dispatch<A>];\n}\n\nfunction useRef<T>(initialValue?: T): { current: T | undefined } {\n currentHook = 5;\n return useMemo(function() {\n return {\n current: initialValue,\n };\n }, []);\n}\n\n// used for first screen and need not to cache value by args\nfunction useMemo<T>(factory: () => T, _args: ReadonlyArray<unknown>): T {\n const state = getHookState(currentIndex++, 7)!;\n state[VALUE] = factory();\n return state[VALUE] as T;\n}\n\nfunction useCallback<T>(callback: T, args: ReadonlyArray<unknown>): T {\n currentHook = 8;\n return useMemo(function() {\n return callback;\n }, args);\n}\n\nfunction useContext<T>(context: PreactContext<T>): T {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const provider = currentComponent!.context[context.__c] as {\n props: {\n value: T;\n };\n };\n const state = getHookState(currentIndex++, 9)!;\n state['c'] = context;\n /* v8 ignore start */\n if (!provider) return context.__;\n /* v8 ignore stop */\n state[VALUE] = true;\n return provider.props.value;\n}\n\nfunction useDebugValue<T>(value: T, formatter?: (value: T) => string | number): void {\n if (options.useDebugValue) {\n /* v8 ignore start */\n options.useDebugValue(formatter ? formatter(value) : value as string | number);\n /* v8 ignore stop */\n }\n}\n\nfunction useErrorBoundary(cb: (error: any, errorInfo: ErrorInfo) => Promise<void> | void) {\n const state = getHookState(currentIndex++, 10)!;\n state[VALUE] = cb;\n return [undefined, noop] as ReturnType<typeof useErrorBoundaryType>;\n}\n\nfunction useId(): string {\n const state = getHookState(currentIndex++, 11)!;\n if (!state[VALUE]) {\n // Grab either the root node or the nearest async boundary node.\n let root = currentComponent![VNODE];\n while (root !== null && !root![MASK] && root![PARENT] !== null) {\n root = root![PARENT];\n }\n /**\n * init mask to [0, 0]\n * mask[0] will not change\n * mask[1] will auto increase\n */\n const mask = root![MASK] ?? (root![MASK] = [0, 0]);\n state[VALUE] = 'P' + mask[0] + '-' + mask[1]++;\n }\n return state[VALUE] as string;\n}\n\n// background hooks\nconst useEffect = noop as typeof useEffectType;\nconst useLayoutEffect = noop as typeof useLayoutEffectType;\nconst useImperativeHandle = noop as typeof useImperativeHandleType;\n\nexport {\n installMainThreadHooks,\n useCallback,\n useContext,\n useDebugValue,\n useEffect,\n useErrorBoundary,\n useId,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n};\n"]}
@@ -2,7 +2,7 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { RESET_WITH_INIT_DATA_IN_STATE_ERROR, hasWithInitDataInStateUsage } from './initData.js';
5
- import { isEmptyObject } from '../utils.js';
5
+ import { isEmptyObject } from '../shared/utils.js';
6
6
  let hasReportedResetWithInitDataInState = false;
7
7
  export function applyUpdatePageData(data, options) {
8
8
  if (options?.resetPageData) {
@@ -1 +1 @@
1
- {"version":3,"file":"lynx-page-data.js","sourceRoot":"","sources":["../../src/core/lynx-page-data.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,mCAAmC,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,IAAI,mCAAmC,GAAG,KAAK,CAAC;AAEhD,MAAM,UAAU,mBAAmB,CAAC,IAAa,EAAE,OAAiD;IAClG,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;QAC3B,IAAI,OAAO,IAAI,CAAC,mCAAmC,IAAI,2BAA2B,EAAE,EAAE,CAAC;YACrF,mCAAmC,GAAG,IAAI,CAAC;YAC3C,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,IAAI,IAAI,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACrE,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC;QACvB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { RESET_WITH_INIT_DATA_IN_STATE_ERROR, hasWithInitDataInStateUsage } from './initData.js';\nimport { isEmptyObject } from '../utils.js';\n\nlet hasReportedResetWithInitDataInState = false;\n\nexport function applyUpdatePageData(data: unknown, options?: Pick<UpdatePageOption, 'resetPageData'>): void {\n if (options?.resetPageData) {\n if (__DEV__ && !hasReportedResetWithInitDataInState && hasWithInitDataInStateUsage()) {\n hasReportedResetWithInitDataInState = true;\n lynx.reportError(new Error(RESET_WITH_INIT_DATA_IN_STATE_ERROR));\n }\n lynx.__initData = {};\n }\n\n if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {\n lynx.__initData ??= {};\n Object.assign(lynx.__initData, data);\n }\n}\n"]}
1
+ {"version":3,"file":"lynx-page-data.js","sourceRoot":"","sources":["../../src/core/lynx-page-data.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,mCAAmC,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,IAAI,mCAAmC,GAAG,KAAK,CAAC;AAEhD,MAAM,UAAU,mBAAmB,CAAC,IAAa,EAAE,OAAiD;IAClG,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;QAC3B,IAAI,OAAO,IAAI,CAAC,mCAAmC,IAAI,2BAA2B,EAAE,EAAE,CAAC;YACrF,mCAAmC,GAAG,IAAI,CAAC;YAC3C,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,IAAI,IAAI,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACrE,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC;QACvB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { RESET_WITH_INIT_DATA_IN_STATE_ERROR, hasWithInitDataInStateUsage } from './initData.js';\nimport { isEmptyObject } from '../shared/utils.js';\n\nlet hasReportedResetWithInitDataInState = false;\n\nexport function applyUpdatePageData(data: unknown, options?: Pick<UpdatePageOption, 'resetPageData'>): void {\n if (options?.resetPageData) {\n if (__DEV__ && !hasReportedResetWithInitDataInState && hasWithInitDataInStateUsage()) {\n hasReportedResetWithInitDataInState = true;\n lynx.reportError(new Error(RESET_WITH_INIT_DATA_IN_STATE_ERROR));\n }\n lynx.__initData = {};\n }\n\n if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {\n lynx.__initData ??= {};\n Object.assign(lynx.__initData, data);\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  // Copyright 2026 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
- import { isSdkVersionGt } from '../utils.js';
4
+ import { isSdkVersionGt } from '../shared/version.js';
5
5
  let mtsEnabled;
6
6
  /**
7
7
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"mts-capability.js","sourceRoot":"","sources":["../../src/core/mts-capability.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,IAAI,UAA+B,CAAC;AAEpC;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,UAAU,KAAK,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B;IAC3C,UAAU,GAAG,SAAS,CAAC;AACzB,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { isSdkVersionGt } from '../utils.js';\n\nlet mtsEnabled: boolean | undefined;\n\n/**\n * @internal\n */\nexport function isMtsEnabled(): boolean {\n return mtsEnabled ??= isSdkVersionGt(2, 13);\n}\n\n/**\n * @internal\n */\nexport function clearMtsConfigCacheForTesting(): void {\n mtsEnabled = undefined;\n}\n"]}
1
+ {"version":3,"file":"mts-capability.js","sourceRoot":"","sources":["../../src/core/mts-capability.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,IAAI,UAA+B,CAAC;AAEpC;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,UAAU,KAAK,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B;IAC3C,UAAU,GAAG,SAAS,CAAC;AACzB,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { isSdkVersionGt } from '../shared/version.js';\n\nlet mtsEnabled: boolean | undefined;\n\n/**\n * @internal\n */\nexport function isMtsEnabled(): boolean {\n return mtsEnabled ??= isSdkVersionGt(2, 13);\n}\n\n/**\n * @internal\n */\nexport function clearMtsConfigCacheForTesting(): void {\n mtsEnabled = undefined;\n}\n"]}
@@ -3,7 +3,8 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { options } from 'preact';
5
5
  import { RENDER_COMPONENT, ROOT } from '../shared/render-constants.js';
6
- import { hook, isSdkVersionGt } from '../utils.js';
6
+ import { hook } from '../shared/utils.js';
7
+ import { isSdkVersionGt } from '../shared/version.js';
7
8
  const PerformanceTimingKeys = [
8
9
  'updateSetStateTrigger',
9
10
  'updateDiffVdomStart',
@@ -1 +1 @@
1
- {"version":3,"file":"performance.js","sourceRoot":"","sources":["../../src/core/performance.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ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sB,GAAuC,EAAE,GAAG,IAAO,EAAE,EAAE;QAC1F,MAAM,EAAE,CAAC;QACT,qBAAqB;QACrB,IAAI,GAAG;YAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;QACtB,oBAAoB;IACtB,CAAC,CAAC;IAEF,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACtB,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { options } from 'preact';\n\nimport { RENDER_COMPONENT, ROOT } from '../shared/render-constants.js';\nimport { hook, isSdkVersionGt } from '../utils.js';\n\nconst PerformanceTimingKeys = [\n 'updateSetStateTrigger',\n 'updateDiffVdomStart',\n 'updateDiffVdomEnd',\n // updateSetStateTrigger, updateDiffVdomStart and updateDiffVdomEnd is deprecated\n 'diffVdomStart',\n 'diffVdomEnd',\n 'packChangesStart',\n 'packChangesEnd',\n 'parseChangesStart',\n 'parseChangesEnd',\n 'patchChangesStart',\n 'patchChangesEnd',\n 'hydrateParseSnapshotStart',\n 'hydrateParseSnapshotEnd',\n 'mtsRenderStart',\n 'mtsRenderEnd',\n] as const;\n\nconst PerformanceTimingFlags = {\n reactLynxHydrate: 'react_lynx_hydrate',\n} as const;\n\nconst PipelineOrigins = {\n reactLynxHydrate: 'reactLynxHydrate',\n updateTriggeredByBts: 'updateTriggeredByBts',\n} as const;\n\ntype PerformanceTimingKey = typeof PerformanceTimingKeys[number];\ntype PipelineOrigin = typeof PipelineOrigins[keyof typeof PipelineOrigins];\n\n/**\n * @deprecated used by old timing api(setState timing flag)\n */\nconst PerfSpecificKey = '__lynx_timing_flag';\n\nlet timingFlag: string | undefined;\nlet shouldMarkDiffVdomStart = false;\nlet shouldMarkDiffVdomEnd = false;\n\nlet globalPipelineOptions: PipelineOptions | undefined;\nlet activeTimingAPIOptions: TimingAPIOptions | undefined;\nlet didInstallTimingAPIHooks = false;\n\ninterface TimingAPIOptions {\n shouldStartUpdatePipeline: () => boolean;\n beginPipeline?: typeof beginPipeline;\n}\n\n/**\n * @deprecated used by old timing api(setState timing flag)\n */\nfunction markTimingLegacy(key: PerformanceTimingKey, timingFlag_?: string): void {\n switch (key) {\n case 'updateSetStateTrigger': {\n shouldMarkDiffVdomStart = true;\n shouldMarkDiffVdomEnd = true;\n timingFlag = timingFlag_;\n break;\n }\n case 'updateDiffVdomStart': {\n if (!shouldMarkDiffVdomStart) {\n return;\n }\n shouldMarkDiffVdomStart = false;\n break;\n }\n case 'updateDiffVdomEnd': {\n if (!shouldMarkDiffVdomEnd) {\n return;\n }\n shouldMarkDiffVdomEnd = false;\n break;\n }\n }\n lynx.getNativeApp().markTiming?.(timingFlag!, key);\n}\n\nfunction beginPipeline(\n needTimestamps: boolean,\n pipelineOrigin: PipelineOrigin,\n timingFlag?: string,\n): void {\n globalPipelineOptions = lynx.performance?._generatePipelineOptions?.();\n if (globalPipelineOptions) {\n globalPipelineOptions.needTimestamps = needTimestamps;\n globalPipelineOptions.pipelineOrigin = pipelineOrigin;\n globalPipelineOptions.dsl = 'reactLynx';\n switch (pipelineOrigin) {\n case PipelineOrigins.reactLynxHydrate:\n globalPipelineOptions.stage = 'hydrate';\n break;\n case PipelineOrigins.updateTriggeredByBts:\n globalPipelineOptions.stage = 'update';\n break;\n }\n\n if (isSdkVersionGt(3, 0)) {\n lynx.performance?._onPipelineStart?.(globalPipelineOptions.pipelineID, globalPipelineOptions);\n } else {\n lynx.performance?._onPipelineStart?.(globalPipelineOptions.pipelineID);\n }\n if (timingFlag) {\n lynx.performance?._bindPipelineIdWithTimingFlag?.(globalPipelineOptions.pipelineID, timingFlag);\n }\n }\n}\n\nfunction setPipeline(pipeline: PipelineOptions | undefined): void {\n globalPipelineOptions = pipeline;\n}\n\nfunction resetTimingState(): void {\n timingFlag = undefined;\n shouldMarkDiffVdomStart = false;\n shouldMarkDiffVdomEnd = false;\n globalPipelineOptions = undefined;\n}\n\nfunction markTiming(timestampKey: PerformanceTimingKey, force?: boolean): void {\n if (globalPipelineOptions && (force || globalPipelineOptions.needTimestamps)) {\n lynx.performance?._markTiming?.(globalPipelineOptions.pipelineID, timestampKey);\n }\n}\n\nfunction initTimingAPI(timingAPIOptions: TimingAPIOptions): void {\n activeTimingAPIOptions = timingAPIOptions;\n resetTimingState();\n\n if (didInstallTimingAPIHooks) {\n return;\n }\n didInstallTimingAPIHooks = true;\n\n const helper = () => {\n const timingAPIOptions = activeTimingAPIOptions;\n /* v8 ignore start */\n if (!timingAPIOptions) {\n return;\n }\n /* v8 ignore stop */\n\n const startPipeline = timingAPIOptions.beginPipeline ?? beginPipeline;\n if (__JS__ && timingAPIOptions.shouldStartUpdatePipeline()) {\n if (!globalPipelineOptions) {\n startPipeline(false, PipelineOrigins.updateTriggeredByBts);\n markTiming('diffVdomStart', true);\n }\n if (shouldMarkDiffVdomStart) {\n markTimingLegacy('updateDiffVdomStart');\n }\n }\n };\n\n const onHook = <T extends unknown[]>(old: ((...args: T) => void) | undefined, ...args: T) => {\n helper();\n /* v8 ignore start */\n if (old) old(...args);\n /* v8 ignore stop */\n };\n\n hook(options, RENDER_COMPONENT, onHook);\n hook(options, ROOT, onHook);\n}\n\nexport {\n PerformanceTimingFlags,\n PipelineOrigins,\n PerfSpecificKey,\n markTimingLegacy,\n initTimingAPI,\n beginPipeline,\n markTiming,\n setPipeline,\n resetTimingState,\n globalPipelineOptions,\n};\nexport type { PerformanceTimingKey, PipelineOrigin };\n"]}
1
+ {"version":3,"file":"performance.js","sourceRoot":"","sources":["../../src/core/performance.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACx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AC5B,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,MAAM,GAAG,CAAsB,GAAuC,EAAE,GAAG,IAAO,EAAE,EAAE;QAC1F,MAAM,EAAE,CAAC;QACT,qBAAqB;QACrB,IAAI,GAAG;YAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;QACtB,oBAAoB;IACtB,CAAC,CAAC;IAEF,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,qBAAqB,GACtB,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { options } from 'preact';\n\nimport { RENDER_COMPONENT, ROOT } from '../shared/render-constants.js';\nimport { hook } from '../shared/utils.js';\nimport { isSdkVersionGt } from '../shared/version.js';\n\nconst PerformanceTimingKeys = [\n 'updateSetStateTrigger',\n 'updateDiffVdomStart',\n 'updateDiffVdomEnd',\n // updateSetStateTrigger, updateDiffVdomStart and updateDiffVdomEnd is deprecated\n 'diffVdomStart',\n 'diffVdomEnd',\n 'packChangesStart',\n 'packChangesEnd',\n 'parseChangesStart',\n 'parseChangesEnd',\n 'patchChangesStart',\n 'patchChangesEnd',\n 'hydrateParseSnapshotStart',\n 'hydrateParseSnapshotEnd',\n 'mtsRenderStart',\n 'mtsRenderEnd',\n] as const;\n\nconst PerformanceTimingFlags = {\n reactLynxHydrate: 'react_lynx_hydrate',\n} as const;\n\nconst PipelineOrigins = {\n reactLynxHydrate: 'reactLynxHydrate',\n updateTriggeredByBts: 'updateTriggeredByBts',\n} as const;\n\ntype PerformanceTimingKey = typeof PerformanceTimingKeys[number];\ntype PipelineOrigin = typeof PipelineOrigins[keyof typeof PipelineOrigins];\n\n/**\n * @deprecated used by old timing api(setState timing flag)\n */\nconst PerfSpecificKey = '__lynx_timing_flag';\n\nlet timingFlag: string | undefined;\nlet shouldMarkDiffVdomStart = false;\nlet shouldMarkDiffVdomEnd = false;\n\nlet globalPipelineOptions: PipelineOptions | undefined;\nlet activeTimingAPIOptions: TimingAPIOptions | undefined;\nlet didInstallTimingAPIHooks = false;\n\ninterface TimingAPIOptions {\n shouldStartUpdatePipeline: () => boolean;\n beginPipeline?: typeof beginPipeline;\n}\n\n/**\n * @deprecated used by old timing api(setState timing flag)\n */\nfunction markTimingLegacy(key: PerformanceTimingKey, timingFlag_?: string): void {\n switch (key) {\n case 'updateSetStateTrigger': {\n shouldMarkDiffVdomStart = true;\n shouldMarkDiffVdomEnd = true;\n timingFlag = timingFlag_;\n break;\n }\n case 'updateDiffVdomStart': {\n if (!shouldMarkDiffVdomStart) {\n return;\n }\n shouldMarkDiffVdomStart = false;\n break;\n }\n case 'updateDiffVdomEnd': {\n if (!shouldMarkDiffVdomEnd) {\n return;\n }\n shouldMarkDiffVdomEnd = false;\n break;\n }\n }\n lynx.getNativeApp().markTiming?.(timingFlag!, key);\n}\n\nfunction beginPipeline(\n needTimestamps: boolean,\n pipelineOrigin: PipelineOrigin,\n timingFlag?: string,\n): void {\n globalPipelineOptions = lynx.performance?._generatePipelineOptions?.();\n if (globalPipelineOptions) {\n globalPipelineOptions.needTimestamps = needTimestamps;\n globalPipelineOptions.pipelineOrigin = pipelineOrigin;\n globalPipelineOptions.dsl = 'reactLynx';\n switch (pipelineOrigin) {\n case PipelineOrigins.reactLynxHydrate:\n globalPipelineOptions.stage = 'hydrate';\n break;\n case PipelineOrigins.updateTriggeredByBts:\n globalPipelineOptions.stage = 'update';\n break;\n }\n\n if (isSdkVersionGt(3, 0)) {\n lynx.performance?._onPipelineStart?.(globalPipelineOptions.pipelineID, globalPipelineOptions);\n } else {\n lynx.performance?._onPipelineStart?.(globalPipelineOptions.pipelineID);\n }\n if (timingFlag) {\n lynx.performance?._bindPipelineIdWithTimingFlag?.(globalPipelineOptions.pipelineID, timingFlag);\n }\n }\n}\n\nfunction setPipeline(pipeline: PipelineOptions | undefined): void {\n globalPipelineOptions = pipeline;\n}\n\nfunction resetTimingState(): void {\n timingFlag = undefined;\n shouldMarkDiffVdomStart = false;\n shouldMarkDiffVdomEnd = false;\n globalPipelineOptions = undefined;\n}\n\nfunction markTiming(timestampKey: PerformanceTimingKey, force?: boolean): void {\n if (globalPipelineOptions && (force || globalPipelineOptions.needTimestamps)) {\n lynx.performance?._markTiming?.(globalPipelineOptions.pipelineID, timestampKey);\n }\n}\n\nfunction initTimingAPI(timingAPIOptions: TimingAPIOptions): void {\n activeTimingAPIOptions = timingAPIOptions;\n resetTimingState();\n\n if (didInstallTimingAPIHooks) {\n return;\n }\n didInstallTimingAPIHooks = true;\n\n const helper = () => {\n const timingAPIOptions = activeTimingAPIOptions;\n /* v8 ignore start */\n if (!timingAPIOptions) {\n return;\n }\n /* v8 ignore stop */\n\n const startPipeline = timingAPIOptions.beginPipeline ?? beginPipeline;\n if (__JS__ && timingAPIOptions.shouldStartUpdatePipeline()) {\n if (!globalPipelineOptions) {\n startPipeline(false, PipelineOrigins.updateTriggeredByBts);\n markTiming('diffVdomStart', true);\n }\n if (shouldMarkDiffVdomStart) {\n markTimingLegacy('updateDiffVdomStart');\n }\n }\n };\n\n const onHook = <T extends unknown[]>(old: ((...args: T) => void) | undefined, ...args: T) => {\n helper();\n /* v8 ignore start */\n if (old) old(...args);\n /* v8 ignore stop */\n };\n\n hook(options, RENDER_COMPONENT, onHook);\n hook(options, ROOT, onHook);\n}\n\nexport {\n PerformanceTimingFlags,\n PipelineOrigins,\n PerfSpecificKey,\n markTimingLegacy,\n initTimingAPI,\n beginPipeline,\n markTiming,\n setPipeline,\n resetTimingState,\n globalPipelineOptions,\n};\nexport type { PerformanceTimingKey, PipelineOrigin };\n"]}
@@ -29,11 +29,10 @@ export declare class OrdinaryRefEffectQueue<TProxy, TToken> {
29
29
  }
30
30
  export declare abstract class SelectorRefProxy<TProxy extends SelectorRefProxy<TProxy>> {
31
31
  private task;
32
- protected createProxy(): TProxy;
32
+ protected createProxy(template?: string): TProxy;
33
33
  protected abstract createProxyTarget(): TProxy;
34
34
  protected abstract runOrDelay(task: () => void): void;
35
35
  abstract get selector(): string;
36
- private setTask;
37
36
  exec(): void;
38
37
  }
39
38
  export {};
@@ -1,6 +1,19 @@
1
1
  // Copyright 2026 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
+ const NODE_NOT_FOUND_CODE = 2;
5
+ const NO_UI_FOR_NODE_CODE = 6;
6
+ function enrichRefError(res, method, template, execStack) {
7
+ const record = res;
8
+ if (!record
9
+ || (record.code !== NODE_NOT_FOUND_CODE && record.code !== NO_UI_FOR_NODE_CODE)
10
+ || typeof record.data !== 'string') {
11
+ return res;
12
+ }
13
+ return Object.assign({}, res, {
14
+ data: `${record.data} [ReactLynx ref: invoke(${method})${template ? `, ${template}` : ''}]${__DEV__ && execStack ? `\n${execStack}` : ''}`,
15
+ });
16
+ }
4
17
  export function assertValidRef(value) {
5
18
  if (typeof value === 'function'
6
19
  || (typeof value === 'object' && value !== null && 'current' in value)) {
@@ -86,9 +99,44 @@ export class OrdinaryRefEffectQueue {
86
99
  return this.refsToClear.length > 0 || this.refsToApply.length > 0;
87
100
  }
88
101
  }
102
+ function createRefTask(method, args, template) {
103
+ return (nodesRef, execStack, selector) => {
104
+ let callArgs = args;
105
+ if (method === 'invoke') {
106
+ const options = args[0];
107
+ if (options && typeof options.fail === 'function') {
108
+ callArgs = [
109
+ Object.assign({}, options, {
110
+ fail: (res) => options.fail.call(options, enrichRefError(res, options.method, template, execStack)),
111
+ }),
112
+ ];
113
+ }
114
+ else if (__DEV__ && options) {
115
+ callArgs = [
116
+ Object.assign({}, options, {
117
+ fail: (res) => {
118
+ if (res
119
+ && res.code !== 0
120
+ && !lynx._switches
121
+ ?.disableSelectorQueryWarningWhenFailed) {
122
+ const enriched = enrichRefError(res, options.method, template, undefined);
123
+ const message = `Failed to exec NodesRef.invoke() on ${selector}. Add a fail callback to suppress this warning. Msg: ${JSON.stringify(enriched)}\n${execStack}`;
124
+ console.warn(message);
125
+ const error = new Error(message);
126
+ error.name = 'INVOKE_ERROR';
127
+ lynx.reportError(error);
128
+ }
129
+ },
130
+ }),
131
+ ];
132
+ }
133
+ }
134
+ return nodesRef[method].apply(nodesRef, callArgs);
135
+ };
136
+ }
89
137
  export class SelectorRefProxy {
90
138
  task;
91
- createProxy() {
139
+ createProxy(template) {
92
140
  return new Proxy(this, {
93
141
  get: (target, prop, receiver) => {
94
142
  if (typeof prop === 'symbol'
@@ -98,19 +146,22 @@ export class SelectorRefProxy {
98
146
  return Reflect.get(target, prop, receiver);
99
147
  }
100
148
  return (...args) => {
101
- return target.createProxyTarget().setTask(prop, args);
149
+ const next = target.createProxyTarget();
150
+ next.task = createRefTask(prop, args, template);
151
+ return next;
102
152
  };
103
153
  },
104
154
  });
105
155
  }
106
- setTask(method, args) {
107
- this.task = (nodesRef) => {
108
- const nodesRefMethod = nodesRef[method];
109
- return nodesRefMethod.apply(nodesRef, args);
110
- };
111
- return this;
112
- }
113
156
  exec() {
157
+ if (__DEV__) {
158
+ const execStack = new Error('ReactLynx ref exec() call stack').stack;
159
+ this.runOrDelay(() => {
160
+ const selector = this.selector;
161
+ this.task(lynx.createSelectorQuery().select(selector), execStack, selector).exec();
162
+ });
163
+ return;
164
+ }
114
165
  this.runOrDelay(() => {
115
166
  this.task(lynx.createSelectorQuery().select(this.selector)).exec();
116
167
  });