@lynx-js/react 0.128.0 → 0.129.1

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 (334) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +3 -4
  4. package/refresh/.turbo/turbo-build.log +1 -1
  5. package/runtime/__test__/core/entry-re-eval.test.ts +161 -0
  6. package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
  7. package/runtime/__test__/core/reload-scoped-dual-thread-communication.test.ts +129 -0
  8. package/runtime/__test__/core/thread-function-call.test.ts +1 -0
  9. package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +2 -0
  10. package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
  11. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
  12. package/runtime/__test__/element-template/native/index.test.ts +8 -0
  13. package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
  14. package/runtime/__test__/element-template/native/main-thread-ref-init-value.test.ts +100 -0
  15. package/runtime/__test__/element-template/native/mts-destroy.test.ts +83 -0
  16. package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +104 -0
  17. package/runtime/__test__/element-template/native/reload.test.ts +79 -1
  18. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +104 -47
  19. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +7 -1
  20. package/runtime/__test__/element-template/runtime/background/re-eval-reload.test.ts +69 -0
  21. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
  22. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +31 -5
  23. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +214 -10
  24. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
  25. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
  26. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
  27. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
  28. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +2 -0
  29. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
  30. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +121 -26
  31. package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +89 -2
  32. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +5 -0
  33. package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
  34. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
  35. package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
  36. package/runtime/__test__/shared/component-stack.test.ts +211 -0
  37. package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
  38. package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
  39. package/runtime/__test__/snapshot/lifecycle/re-eval-reload.test.jsx +114 -0
  40. package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +169 -0
  41. package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +63 -0
  42. package/runtime/__test__/snapshot/lifecycle/reload-delayed-main-thread.test.jsx +103 -0
  43. package/runtime/__test__/snapshot/lifecycle.test.jsx +61 -1
  44. package/runtime/__test__/snapshot/lynx/lazy-effect-scheduling.test.jsx +105 -0
  45. package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
  46. package/runtime/__test__/snapshot/preact.test.jsx +0 -3
  47. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
  48. package/runtime/__test__/snapshot/ssr.test.jsx +2 -2
  49. package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +6 -11
  50. package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +1 -1
  51. package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +24 -1
  52. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +27 -1
  53. package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
  54. package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +46 -0
  55. package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +3 -3
  56. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
  57. package/runtime/lazy/element-template-internal.js +0 -1
  58. package/runtime/lazy/internal.js +1 -1
  59. package/runtime/lazy/jsx-dev-runtime.js +1 -1
  60. package/runtime/lazy/jsx-runtime.js +1 -1
  61. package/runtime/lazy/legacy-react-runtime.js +1 -1
  62. package/runtime/lazy/react-lepus.js +1 -1
  63. package/runtime/lazy/react.js +1 -1
  64. package/runtime/lib/core/background-function/exec-map.d.ts +2 -0
  65. package/runtime/lib/core/background-function/exec-map.js +7 -0
  66. package/runtime/lib/core/background-function/exec-map.js.map +1 -1
  67. package/runtime/lib/core/background-function/run-on-background.js +15 -16
  68. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  69. package/runtime/lib/core/capture-main-thread-object.js +2 -1
  70. package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
  71. package/runtime/lib/core/card-lifetime.d.ts +5 -0
  72. package/runtime/lib/core/card-lifetime.js +17 -0
  73. package/runtime/lib/core/card-lifetime.js.map +1 -0
  74. package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
  75. package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
  76. package/runtime/lib/core/entry-reload.d.ts +7 -0
  77. package/runtime/lib/core/entry-reload.js +49 -0
  78. package/runtime/lib/core/entry-reload.js.map +1 -0
  79. package/runtime/lib/core/lynx/lazy-bundle.js +5 -2
  80. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  81. package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
  82. package/runtime/lib/core/lynx-data-processors.js +3 -0
  83. package/runtime/lib/core/lynx-data-processors.js.map +1 -1
  84. package/runtime/lib/core/main-thread-ref-id.js +4 -4
  85. package/runtime/lib/core/main-thread-ref-id.js.map +1 -1
  86. package/runtime/lib/core/reload-scoped-event.d.ts +5 -0
  87. package/runtime/lib/core/reload-scoped-event.js +26 -0
  88. package/runtime/lib/core/reload-scoped-event.js.map +1 -0
  89. package/runtime/lib/core/reload-version.js +4 -3
  90. package/runtime/lib/core/reload-version.js.map +1 -1
  91. package/runtime/lib/core/runtime-destroy.d.ts +2 -0
  92. package/runtime/lib/core/runtime-destroy.js +10 -1
  93. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  94. package/runtime/lib/core/thread-function-call/main-thread.js +5 -4
  95. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  96. package/runtime/lib/core/thread-function-call/return-value.js +6 -5
  97. package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
  98. package/runtime/lib/document.js +0 -5
  99. package/runtime/lib/document.js.map +1 -1
  100. package/runtime/lib/element-template/background/commit-hook.js +24 -22
  101. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  102. package/runtime/lib/element-template/background/hydration-listener.js +2 -6
  103. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  104. package/runtime/lib/element-template/client/root.d.ts +1 -1
  105. package/runtime/lib/element-template/client/root.js.map +1 -1
  106. package/runtime/lib/element-template/index.d.ts +2 -2
  107. package/runtime/lib/element-template/index.js.map +1 -1
  108. package/runtime/lib/element-template/internal.d.ts +1 -1
  109. package/runtime/lib/element-template/internal.js +0 -13
  110. package/runtime/lib/element-template/internal.js.map +1 -1
  111. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  112. package/runtime/lib/element-template/main-thread-ref-init-value.d.ts +3 -0
  113. package/runtime/lib/element-template/main-thread-ref-init-value.js +38 -0
  114. package/runtime/lib/element-template/main-thread-ref-init-value.js.map +1 -0
  115. package/runtime/lib/element-template/native/flush.d.ts +1 -0
  116. package/runtime/lib/element-template/native/flush.js +9 -0
  117. package/runtime/lib/element-template/native/flush.js.map +1 -0
  118. package/runtime/lib/element-template/native/index.js +2 -0
  119. package/runtime/lib/element-template/native/index.js.map +1 -1
  120. package/runtime/lib/element-template/native/main-thread-api.js +3 -7
  121. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  122. package/runtime/lib/element-template/native/mts-destroy.js +10 -2
  123. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  124. package/runtime/lib/element-template/native/patch-listener.js +58 -54
  125. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  126. package/runtime/lib/element-template/native/reload-background.d.ts +1 -1
  127. package/runtime/lib/element-template/native/reload-background.js +12 -1
  128. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  129. package/runtime/lib/element-template/native/reload-main-thread.d.ts +6 -0
  130. package/runtime/lib/element-template/native/reload-main-thread.js +20 -3
  131. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  132. package/runtime/lib/element-template/protocol/lifecycle-constant.d.ts +2 -1
  133. package/runtime/lib/element-template/protocol/lifecycle-constant.js +1 -0
  134. package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
  135. package/runtime/lib/element-template/protocol/types.d.ts +0 -2
  136. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  137. package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
  138. package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
  139. package/runtime/lib/element-template/runtime/patch.js +4 -0
  140. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  141. package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
  142. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  143. package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
  144. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  145. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -1
  146. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  147. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +1 -0
  148. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +41 -21
  149. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  150. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +1 -1
  151. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  152. package/runtime/lib/internal.d.ts +1 -1
  153. package/runtime/lib/internal.js +1 -1
  154. package/runtime/lib/internal.js.map +1 -1
  155. package/runtime/lib/lynx-api.d.ts +2 -125
  156. package/runtime/lib/lynx-api.js.map +1 -1
  157. package/runtime/lib/shared/component-stack.d.ts +0 -4
  158. package/runtime/lib/shared/component-stack.js +21 -5
  159. package/runtime/lib/shared/component-stack.js.map +1 -1
  160. package/runtime/lib/shared/index-map.d.ts +4 -1
  161. package/runtime/lib/shared/index-map.js +5 -2
  162. package/runtime/lib/shared/index-map.js.map +1 -1
  163. package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
  164. package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
  165. package/runtime/lib/snapshot/lifecycle/destroy.js +6 -0
  166. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  167. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.d.ts +6 -2
  168. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js +21 -18
  169. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
  170. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
  171. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
  172. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
  173. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
  174. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  175. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
  176. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  177. package/runtime/lib/snapshot/lifecycle/reload.d.ts +9 -2
  178. package/runtime/lib/snapshot/lifecycle/reload.js +29 -8
  179. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  180. package/runtime/lib/snapshot/list/list.js +3 -2
  181. package/runtime/lib/snapshot/list/list.js.map +1 -1
  182. package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
  183. package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
  184. package/runtime/lib/snapshot/lynx/calledByNative.js +14 -11
  185. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  186. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
  187. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  188. package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
  189. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  190. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
  191. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  192. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  193. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  194. package/runtime/lib/snapshot/snapshot/list.js +2 -1
  195. package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
  196. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.d.ts +4 -2
  197. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js +11 -11
  198. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
  199. package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +1 -0
  200. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +6 -1
  201. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  202. package/runtime/lib/snapshot/worklet/ctx.d.ts +1 -1
  203. package/runtime/lib/snapshot/worklet/ctx.js +6 -1
  204. package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
  205. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js +6 -0
  206. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
  207. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  208. package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
  209. package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
  210. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
  211. package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
  212. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
  213. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
  214. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +3 -1
  215. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
  216. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
  217. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +8 -1
  218. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  219. package/runtime/lib/worklet-runtime/listeners.js +2 -2
  220. package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
  221. package/runtime/lib/worklet-runtime/mainThreadObject.js +3 -1
  222. package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -1
  223. package/runtime/lib/worklet-runtime/runOnMainThread.js +4 -3
  224. package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
  225. package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
  226. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  227. package/runtime/package.json +2 -3
  228. package/runtime/src/core/background-function/exec-map.ts +9 -0
  229. package/runtime/src/core/background-function/run-on-background.ts +14 -16
  230. package/runtime/src/core/capture-main-thread-object.ts +2 -1
  231. package/runtime/src/core/card-lifetime.ts +18 -0
  232. package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
  233. package/runtime/src/core/entry-reload.ts +63 -0
  234. package/runtime/src/core/lynx/lazy-bundle.ts +5 -2
  235. package/runtime/src/core/lynx-data-processors.ts +124 -1
  236. package/runtime/src/core/main-thread-ref-id.ts +5 -4
  237. package/runtime/src/core/reload-scoped-event.ts +35 -0
  238. package/runtime/src/core/reload-version.ts +5 -3
  239. package/runtime/src/core/runtime-destroy.ts +12 -1
  240. package/runtime/src/core/thread-function-call/main-thread.ts +4 -4
  241. package/runtime/src/core/thread-function-call/return-value.ts +6 -5
  242. package/runtime/src/document.ts +0 -6
  243. package/runtime/src/element-template/background/commit-hook.ts +32 -23
  244. package/runtime/src/element-template/background/hydration-listener.ts +2 -6
  245. package/runtime/src/element-template/client/root.ts +1 -3
  246. package/runtime/src/element-template/index.ts +2 -2
  247. package/runtime/src/element-template/internal.ts +0 -20
  248. package/runtime/src/element-template/lynx/env.ts +1 -1
  249. package/runtime/src/element-template/main-thread-ref-init-value.ts +44 -0
  250. package/runtime/src/element-template/native/flush.ts +10 -0
  251. package/runtime/src/element-template/native/index.ts +2 -0
  252. package/runtime/src/element-template/native/main-thread-api.ts +3 -6
  253. package/runtime/src/element-template/native/mts-destroy.ts +10 -2
  254. package/runtime/src/element-template/native/patch-listener.ts +62 -62
  255. package/runtime/src/element-template/native/reload-background.ts +13 -1
  256. package/runtime/src/element-template/native/reload-main-thread.ts +32 -3
  257. package/runtime/src/element-template/protocol/lifecycle-constant.ts +1 -0
  258. package/runtime/src/element-template/protocol/types.ts +0 -15
  259. package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
  260. package/runtime/src/element-template/runtime/patch.ts +5 -0
  261. package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
  262. package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
  263. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
  264. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +51 -21
  265. package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +2 -2
  266. package/runtime/src/element-template/types.d.ts +6 -0
  267. package/runtime/src/internal.ts +1 -1
  268. package/runtime/src/lynx-api.ts +2 -124
  269. package/runtime/src/shared/component-stack.ts +22 -5
  270. package/runtime/src/shared/index-map.ts +3 -2
  271. package/runtime/src/snapshot/lifecycle/destroy.ts +7 -0
  272. package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +26 -19
  273. package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
  274. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
  275. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
  276. package/runtime/src/snapshot/lifecycle/reload.ts +47 -11
  277. package/runtime/src/snapshot/list/list.ts +9 -2
  278. package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
  279. package/runtime/src/snapshot/lynx/calledByNative.ts +14 -13
  280. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
  281. package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
  282. package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
  283. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
  284. package/runtime/src/snapshot/snapshot/list.ts +5 -1
  285. package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +19 -12
  286. package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +10 -1
  287. package/runtime/src/snapshot/worklet/ctx.ts +10 -1
  288. package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +6 -0
  289. package/runtime/src/worklet-runtime/README.md +33 -0
  290. package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
  291. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
  292. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +3 -1
  293. package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +8 -1
  294. package/runtime/src/worklet-runtime/listeners.ts +4 -7
  295. package/runtime/src/worklet-runtime/mainThreadObject.ts +2 -1
  296. package/runtime/src/worklet-runtime/runOnMainThread.ts +4 -3
  297. package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
  298. package/runtime/types/types.d.ts +3 -1
  299. package/runtime/vitest.config.ts +0 -2
  300. package/testing-library/.turbo/turbo-build.log +7 -7
  301. package/testing-library/src/__tests__/act.test.jsx +0 -7
  302. package/testing-library/src/__tests__/alog.test.jsx +12 -54
  303. package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
  304. package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
  305. package/testing-library/src/__tests__/worklet.test.jsx +59 -5
  306. package/transform/.turbo/turbo-build$colon$wasm.log +63 -136
  307. package/transform/__test__/defines.spec.js +137 -0
  308. package/transform/__test__/object-methods.spec.js +79 -0
  309. package/transform/crates/swc_plugin_worklet/definition_imports.rs +97 -0
  310. package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
  311. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +56 -48
  312. package/transform/crates/swc_plugin_worklet/lib.rs +400 -595
  313. package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
  314. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +6 -1
  315. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -1
  316. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +9 -0
  317. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +12 -1
  318. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +1 -1
  319. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +1 -1
  320. package/transform/dist/wasm.cjs +1 -1
  321. package/transform/index.d.ts +3 -1
  322. package/transform/package.json +0 -1
  323. package/transform/src/lib.rs +173 -12
  324. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +105 -32
  325. package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
  326. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  327. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +193 -194
  328. package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
  329. package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
  330. package/runtime/lib/snapshot/worklet/hmr.js +0 -28
  331. package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
  332. package/runtime/src/snapshot/worklet/hmr.ts +0 -34
  333. /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
  334. /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
@@ -1,6 +1,7 @@
1
1
  // Copyright 2025 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 { cardLifetime } from '../../../core/card-lifetime.js';
4
5
  import { isProcessingDefaultData } from '../../../core/lynx-data-processors.js';
5
6
  import { __root } from '../../../root.js';
6
7
  import { profileEnd, profileStart } from '../../../shared/profile.js';
@@ -8,12 +9,14 @@ import { LifecycleConstant } from '../../lifecycle/constant.js';
8
9
  // Initialized once at module load (`renderPage` runs once per runtime and does
9
10
  // not reset), so a ready mark set before `renderPage` (e.g. in `defaultDataProcessor`)
10
11
  // survives. In `'manual'` mode the first screen syncs only after both are true.
11
- let isFirstScreenSynced = false;
12
- let firstScreenEventIdSwap = {};
13
- let isMarkedFirstScreenSyncReady = false;
14
- let isFirstScreenTreeReady = false;
12
+ const firstScreenSync = /*#__PURE__*/ cardLifetime('firstScreenSync', () => ({
13
+ isSynced: false,
14
+ eventIdSwap: {},
15
+ isMarkedReady: false,
16
+ isTreeReady: false,
17
+ }));
15
18
  function syncFirstScreen() {
16
- isFirstScreenSynced = true;
19
+ firstScreenSync.isSynced = true;
17
20
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
18
21
  profileStart('ReactLynx::serializeRoot');
19
22
  }
@@ -28,23 +31,23 @@ function syncFirstScreen() {
28
31
  LifecycleConstant.firstScreen, /* FIRST_SCREEN */
29
32
  {
30
33
  root,
31
- firstScreenEventIdSwap,
34
+ firstScreenEventIdSwap: firstScreenSync.eventIdSwap,
32
35
  },
33
36
  ]);
34
37
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
35
38
  profileEnd();
36
39
  }
37
- firstScreenEventIdSwap = {};
40
+ firstScreenSync.eventIdSwap = {};
38
41
  }
39
42
  // ready signal: business/framework allows the handover. Syncs if the tree is ready.
40
43
  function onFirstScreenSyncReady() {
41
44
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
42
45
  profileStart('ReactLynx::onFirstScreenSyncReady');
43
46
  }
44
- isMarkedFirstScreenSyncReady = true;
47
+ firstScreenSync.isMarkedReady = true;
45
48
  // A mark made inside `defaultDataProcessor` (a native call before the upcoming render)
46
49
  // is recorded but not synced now; `onFirstScreenTreeReady` honors it once render ends.
47
- if (isFirstScreenTreeReady && !isProcessingDefaultData() && !isFirstScreenSynced) {
50
+ if (firstScreenSync.isTreeReady && !isProcessingDefaultData() && !firstScreenSync.isSynced) {
48
51
  syncFirstScreen();
49
52
  }
50
53
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
@@ -53,28 +56,28 @@ function onFirstScreenSyncReady() {
53
56
  }
54
57
  // tree built (`renderPage` / `updatePage` done). Syncs if the ready signal already came.
55
58
  function onFirstScreenTreeReady() {
56
- isFirstScreenTreeReady = true;
57
- if (isMarkedFirstScreenSyncReady && !isFirstScreenSynced) {
59
+ firstScreenSync.isTreeReady = true;
60
+ if (firstScreenSync.isMarkedReady && !firstScreenSync.isSynced) {
58
61
  syncFirstScreen();
59
62
  }
60
63
  }
61
64
  // the first-screen tree is being (re-)rendered, a mark during this period
62
65
  // must not sync until the next `onFirstScreenTreeReady`
63
66
  function resetFirstScreenTreeReady() {
64
- isFirstScreenTreeReady = false;
67
+ firstScreenSync.isTreeReady = false;
65
68
  }
66
69
  function clearFirstScreenEventIdSwap() {
67
- firstScreenEventIdSwap = {};
70
+ firstScreenSync.eventIdSwap = {};
68
71
  }
69
72
  // Full reset of all first-screen state. Used by SSR hydration to re-initialize.
70
73
  function resetFirstScreenSyncState() {
71
- isFirstScreenSynced = false;
72
- firstScreenEventIdSwap = {};
73
- isMarkedFirstScreenSyncReady = false;
74
- isFirstScreenTreeReady = false;
74
+ firstScreenSync.isSynced = false;
75
+ firstScreenSync.eventIdSwap = {};
76
+ firstScreenSync.isMarkedReady = false;
77
+ firstScreenSync.isTreeReady = false;
75
78
  }
76
79
  /**
77
80
  * @internal
78
81
  */
79
- export { syncFirstScreen, isFirstScreenSynced, firstScreenEventIdSwap, clearFirstScreenEventIdSwap, resetFirstScreenSyncState, onFirstScreenSyncReady, onFirstScreenTreeReady, resetFirstScreenTreeReady, };
82
+ export { syncFirstScreen, firstScreenSync, clearFirstScreenEventIdSwap, resetFirstScreenSyncState, onFirstScreenSyncReady, onFirstScreenTreeReady, resetFirstScreenTreeReady, };
80
83
  //# sourceMappingURL=firstScreenSync.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"firstScreenSync.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/event/firstScreenSync.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,+EAA+E;AAC/E,uFAAuF;AACvF,gFAAgF;AAChF,IAAI,mBAAmB,GAAG,KAAK,CAAC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AAED,yFAAyF;AACzF,SAAS,sBAAsB;IAC7B,sBAAsB,GAAG,IAAI,CAAC;IAC9B,IAAI,4BAA4B,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzD,eAAe,EAAE,CAAC;IACpB,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,wDAAwD;AACxD,SAAS,yBAAyB;IAChC,sBAAsB,GAAG,KAAK,CAAC;AACjC,CAAC;AAED,SAAS,2BAA2B;IAClC,sBAAsB,GAAG,EAAE,CAAC;AAC9B,CAAC;AAED,gFAAgF;AAChF,SAAS,yBAAyB;IAChC,mBAAmB,GAAG,KAAK,CAAC;IAC5B,sBAAsB,GAAG,EAAE,CAAC;IAC5B,4BAA4B,GAAG,KAAK,CAAC;IACrC,sBAAsB,GAAG,KAAK,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,2BAA2B,EAC3B,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,GAC1B,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.\nimport { isProcessingDefaultData } from '../../../core/lynx-data-processors.js';\nimport { __root } from '../../../root.js';\nimport { profileEnd, profileStart } from '../../../shared/profile.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\n\n// Initialized once at module load (`renderPage` runs once per runtime and does\n// not reset), so a ready mark set before `renderPage` (e.g. in `defaultDataProcessor`)\n// survives. In `'manual'` mode the first screen syncs only after both are true.\nlet isFirstScreenSynced = false;\nlet firstScreenEventIdSwap: Record<string | number, number> = {};\nlet isMarkedFirstScreenSyncReady = false;\nlet isFirstScreenTreeReady = false;\n\nfunction syncFirstScreen(): void {\n isFirstScreenSynced = true;\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::serializeRoot');\n }\n const root = JSON.stringify(__root);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::transferRoot');\n }\n __OnLifecycleEvent([\n LifecycleConstant.firstScreen, /* FIRST_SCREEN */\n {\n root,\n firstScreenEventIdSwap,\n },\n ]);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n firstScreenEventIdSwap = {};\n}\n\n// ready signal: business/framework allows the handover. Syncs if the tree is ready.\nfunction onFirstScreenSyncReady(): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::onFirstScreenSyncReady');\n }\n isMarkedFirstScreenSyncReady = true;\n // A mark made inside `defaultDataProcessor` (a native call before the upcoming render)\n // is recorded but not synced now; `onFirstScreenTreeReady` honors it once render ends.\n if (isFirstScreenTreeReady && !isProcessingDefaultData() && !isFirstScreenSynced) {\n syncFirstScreen();\n }\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\n// tree built (`renderPage` / `updatePage` done). Syncs if the ready signal already came.\nfunction onFirstScreenTreeReady(): void {\n isFirstScreenTreeReady = true;\n if (isMarkedFirstScreenSyncReady && !isFirstScreenSynced) {\n syncFirstScreen();\n }\n}\n\n// the first-screen tree is being (re-)rendered, a mark during this period\n// must not sync until the next `onFirstScreenTreeReady`\nfunction resetFirstScreenTreeReady(): void {\n isFirstScreenTreeReady = false;\n}\n\nfunction clearFirstScreenEventIdSwap(): void {\n firstScreenEventIdSwap = {};\n}\n\n// Full reset of all first-screen state. Used by SSR hydration to re-initialize.\nfunction resetFirstScreenSyncState(): void {\n isFirstScreenSynced = false;\n firstScreenEventIdSwap = {};\n isMarkedFirstScreenSyncReady = false;\n isFirstScreenTreeReady = false;\n}\n\n/**\n * @internal\n */\nexport {\n syncFirstScreen,\n isFirstScreenSynced,\n firstScreenEventIdSwap,\n clearFirstScreenEventIdSwap,\n resetFirstScreenSyncState,\n onFirstScreenSyncReady,\n onFirstScreenTreeReady,\n resetFirstScreenTreeReady,\n};\n"]}
1
+ {"version":3,"file":"firstScreenSync.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/event/firstScreenSync.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,+EAA+E;AAC/E,uFAAuF;AACvF,gFAAgF;AAChF,MAAM,eAAe,GAKjB,aAAa,CAAC,YAAY,CAAC,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC;IACvD,QAAQ,EAAE,KAAK;IACf,WAAW,EAAE,EAAE;IACf,aAAa,EAAE,KAAK;IACpB,WAAW,EAAE,KAAK;CACnB,CAAC,CAAC,CAAC;AAEJ,SAAS,eAAe;IACtB,eAAe,CAAC,QAAQ,GAAG,IAAI,CAAC;IAEhC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,0BAA0B,CAAC,CAAC;IAC3C,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;IACD,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,yBAAyB,CAAC,CAAC;IAC1C,CAAC;IACD,kBAAkB,CAAC;QACjB,iBAAiB,CAAC,WAAW,E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IACtC,eAAe,CAAC,WAAW,GAAG,KAAK,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,OAAO,EACL,eAAe,EACf,eAAe,EACf,2BAA2B,EAC3B,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,GAC1B,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.\nimport { cardLifetime } from '../../../core/card-lifetime.js';\nimport { isProcessingDefaultData } from '../../../core/lynx-data-processors.js';\nimport { __root } from '../../../root.js';\nimport { profileEnd, profileStart } from '../../../shared/profile.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\n\n// Initialized once at module load (`renderPage` runs once per runtime and does\n// not reset), so a ready mark set before `renderPage` (e.g. in `defaultDataProcessor`)\n// survives. In `'manual'` mode the first screen syncs only after both are true.\nconst firstScreenSync: {\n isSynced: boolean;\n eventIdSwap: Record<string | number, number>;\n isMarkedReady: boolean;\n isTreeReady: boolean;\n} = /*#__PURE__*/ cardLifetime('firstScreenSync', () => ({\n isSynced: false,\n eventIdSwap: {},\n isMarkedReady: false,\n isTreeReady: false,\n}));\n\nfunction syncFirstScreen(): void {\n firstScreenSync.isSynced = true;\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::serializeRoot');\n }\n const root = JSON.stringify(__root);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::transferRoot');\n }\n __OnLifecycleEvent([\n LifecycleConstant.firstScreen, /* FIRST_SCREEN */\n {\n root,\n firstScreenEventIdSwap: firstScreenSync.eventIdSwap,\n },\n ]);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n firstScreenSync.eventIdSwap = {};\n}\n\n// ready signal: business/framework allows the handover. Syncs if the tree is ready.\nfunction onFirstScreenSyncReady(): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::onFirstScreenSyncReady');\n }\n firstScreenSync.isMarkedReady = true;\n // A mark made inside `defaultDataProcessor` (a native call before the upcoming render)\n // is recorded but not synced now; `onFirstScreenTreeReady` honors it once render ends.\n if (firstScreenSync.isTreeReady && !isProcessingDefaultData() && !firstScreenSync.isSynced) {\n syncFirstScreen();\n }\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\n// tree built (`renderPage` / `updatePage` done). Syncs if the ready signal already came.\nfunction onFirstScreenTreeReady(): void {\n firstScreenSync.isTreeReady = true;\n if (firstScreenSync.isMarkedReady && !firstScreenSync.isSynced) {\n syncFirstScreen();\n }\n}\n\n// the first-screen tree is being (re-)rendered, a mark during this period\n// must not sync until the next `onFirstScreenTreeReady`\nfunction resetFirstScreenTreeReady(): void {\n firstScreenSync.isTreeReady = false;\n}\n\nfunction clearFirstScreenEventIdSwap(): void {\n firstScreenSync.eventIdSwap = {};\n}\n\n// Full reset of all first-screen state. Used by SSR hydration to re-initialize.\nfunction resetFirstScreenSyncState(): void {\n firstScreenSync.isSynced = false;\n firstScreenSync.eventIdSwap = {};\n firstScreenSync.isMarkedReady = false;\n firstScreenSync.isTreeReady = false;\n}\n\n/**\n * @internal\n */\nexport {\n syncFirstScreen,\n firstScreenSync,\n clearFirstScreenEventIdSwap,\n resetFirstScreenSyncState,\n onFirstScreenSyncReady,\n onFirstScreenTreeReady,\n resetFirstScreenTreeReady,\n};\n"]}
@@ -12,7 +12,6 @@ export declare const SnapshotOperation: {
12
12
  readonly nodesRefInsertBefore: 5;
13
13
  readonly nodesRefRemoveChild: 6;
14
14
  readonly DEV_ONLY_AddSnapshot: 100;
15
- readonly DEV_ONLY_RegisterWorklet: 101;
16
15
  readonly DEV_ONLY_SetSnapshotEntryName: 102;
17
16
  };
18
17
  export declare const SnapshotOperationParams: Record<number, {
@@ -15,7 +15,6 @@ export const SnapshotOperation = {
15
15
  nodesRefInsertBefore: 5,
16
16
  nodesRefRemoveChild: 6,
17
17
  DEV_ONLY_AddSnapshot: 100,
18
- DEV_ONLY_RegisterWorklet: 101,
19
18
  DEV_ONLY_SetSnapshotEntryName: 102,
20
19
  };
21
20
  export const SnapshotOperationParams = /* @__PURE__ */ {
@@ -60,10 +59,6 @@ export const SnapshotOperationParams = /* @__PURE__ */ {
60
59
  'snapshotCreator', /* string */
61
60
  ],
62
61
  },
63
- [SnapshotOperation.DEV_ONLY_RegisterWorklet]: {
64
- name: 'DEV_ONLY_RegisterWorklet',
65
- params: ['hash', /* string */ 'fnStr' /* string */],
66
- },
67
62
  [SnapshotOperation.DEV_ONLY_SetSnapshotEntryName]: {
68
63
  name: 'DEV_ONLY_SetSnapshotEntryName',
69
64
  params: ['uniqID', /* string */ 'entryName' /* string */],
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotPatch.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/snapshotPatch.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;GAIG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,aAAa,EAAE,CAAC;IAChB,YAAY,EAAE,CAAC;IACf,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;IACf,aAAa,EAAE,CAAC;IAChB,oBAAoB,EAAE,CAAC;IACvB,mBAAmB,EAAE,CAAC;IAEtB,oBAAoB,EAAE,GAAG;IACzB,wBAAwB,EAAE,GAAG;IAC7B,6BAA6B,EAAE,GAAG;CAC1B,CAAC;AAEX,MAAM,CAAC,MAAM,uBAAuB,GAAuD,eAAe,CAAC;IACzG,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE;QACjC,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;KACjD;IACD,CAAC,iBAAiB,C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AE,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC;KACpD;IACD,CAAC,iBAAiB,CAAC,6BAA6B,CAAC,EAAE;QACjD,IAAI,EAAE,+BAA+B;QACrC,MAAM,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC;KAC1D;CACO,CAAC;AAIX,MAAM,CAAC,IAAI,qBAAgD,CAAC;AAE5D,MAAM,UAAU,uBAAuB;IACrC,IAAI,qBAAqB,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,qBAAqB,CAAC;QACnC,qBAAqB,GAAG,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,qBAAqB,GAAG,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,qBAAqB,GAAG,SAAS,CAAC;AACpC,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Defines the core patch operations for the snapshot system.\n * The patch operations are designed to be serializable and minimal, allowing\n * efficient transmission between threads and application to element tree.\n */\n\nexport const SnapshotOperation = {\n CreateElement: 0,\n InsertBefore: 1,\n RemoveChild: 2,\n SetAttribute: 3,\n SetAttributes: 4,\n nodesRefInsertBefore: 5,\n nodesRefRemoveChild: 6,\n\n DEV_ONLY_AddSnapshot: 100,\n DEV_ONLY_RegisterWorklet: 101,\n DEV_ONLY_SetSnapshotEntryName: 102,\n} as const;\n\nexport const SnapshotOperationParams: Record<number, { name: string; params: string[] }> = /* @__PURE__ */ {\n [SnapshotOperation.CreateElement]: {\n name: 'CreateElement',\n params: ['type', /* string */ 'id' /* number */],\n },\n [SnapshotOperation.InsertBefore]: {\n name: 'InsertBefore',\n params: [\n 'parentId',\n /* number */ 'childId',\n /* number */ 'beforeId',\n /* number | undefined */ 'slotIndex', /* number | undefined */\n ],\n },\n [SnapshotOperation.RemoveChild]: { name: 'RemoveChild', params: ['parentId', /* number */ 'childId' /* number */] },\n [SnapshotOperation.SetAttribute]: {\n name: 'SetAttribute',\n params: ['id', /* number */ 'dynamicPartIndex', /* number */ 'value' /* any */],\n },\n [SnapshotOperation.SetAttributes]: { name: 'SetAttributes', params: ['id', /* number */ 'values' /* any */] },\n [SnapshotOperation.nodesRefInsertBefore]: {\n name: 'nodesRefInsertBefore',\n params: [\n 'identifier', /* string — CSS selector */\n 'childId', /* number */\n 'beforeId', /* number | undefined */\n ],\n },\n [SnapshotOperation.nodesRefRemoveChild]: {\n name: 'nodesRefRemoveChild',\n params: [\n 'identifier', /* string — CSS selector */\n 'childId', /* number */\n ],\n },\n [SnapshotOperation.DEV_ONLY_AddSnapshot]: {\n name: 'DEV_ONLY_AddSnapshot',\n params: [\n 'uniqID', /* string */\n 'snapshotCreator', /* string */\n ],\n },\n [SnapshotOperation.DEV_ONLY_RegisterWorklet]: {\n name: 'DEV_ONLY_RegisterWorklet',\n params: ['hash', /* string */ 'fnStr' /* string */],\n },\n [SnapshotOperation.DEV_ONLY_SetSnapshotEntryName]: {\n name: 'DEV_ONLY_SetSnapshotEntryName',\n params: ['uniqID', /* string */ 'entryName' /* string */],\n },\n} as const;\n\nexport type SnapshotPatch = unknown[];\n\nexport let __globalSnapshotPatch: SnapshotPatch | undefined;\n\nexport function takeGlobalSnapshotPatch(): SnapshotPatch | undefined {\n if (__globalSnapshotPatch) {\n const list = __globalSnapshotPatch;\n __globalSnapshotPatch = [];\n return list;\n } else {\n return undefined;\n }\n}\n\nexport function initGlobalSnapshotPatch(): void {\n __globalSnapshotPatch = [];\n}\n\nexport function deinitGlobalSnapshotPatch(): void {\n __globalSnapshotPatch = undefined;\n}\n"]}
1
+ {"version":3,"file":"snapshotPatch.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/snapshotPatch.ts"],"names":[],"mapp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AoB,CAAC,EAAE;QACxC,IAAI,EAAE,sBAAsB;QAC5B,MAAM,EAAE;YACN,YAAY,EAAE,2BAA2B;YACzC,SAAS,EAAE,YAAY;YACvB,UAAU,EAAE,wBAAwB;SACrC;KACF;IACD,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,EAAE;QACvC,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE;YACN,YAAY,EAAE,2BAA2B;YACzC,SAAS,EAAE,YAAY;SACxB;KACF;IACD,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,EAAE;QACxC,IAAI,EAAE,sBAAsB;QAC5B,MAAM,EAAE;YACN,QAAQ,EAAE,YAAY;YACtB,iBAAiB,EAAE,YAAY;SAChC;KACF;IACD,CAAC,iBAAiB,CAAC,6BAA6B,CAAC,EAAE;QACjD,IAAI,EAAE,+BAA+B;QACrC,MAAM,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC;KAC1D;CACO,CAAC;AAIX,MAAM,CAAC,IAAI,qBAAgD,CAAC;AAE5D,MAAM,UAAU,uBAAuB;IACrC,IAAI,qBAAqB,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,qBAAqB,CAAC;QACnC,qBAAqB,GAAG,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,qBAAqB,GAAG,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,qBAAqB,GAAG,SAAS,CAAC;AACpC,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Defines the core patch operations for the snapshot system.\n * The patch operations are designed to be serializable and minimal, allowing\n * efficient transmission between threads and application to element tree.\n */\n\nexport const SnapshotOperation = {\n CreateElement: 0,\n InsertBefore: 1,\n RemoveChild: 2,\n SetAttribute: 3,\n SetAttributes: 4,\n nodesRefInsertBefore: 5,\n nodesRefRemoveChild: 6,\n\n DEV_ONLY_AddSnapshot: 100,\n DEV_ONLY_SetSnapshotEntryName: 102,\n} as const;\n\nexport const SnapshotOperationParams: Record<number, { name: string; params: string[] }> = /* @__PURE__ */ {\n [SnapshotOperation.CreateElement]: {\n name: 'CreateElement',\n params: ['type', /* string */ 'id' /* number */],\n },\n [SnapshotOperation.InsertBefore]: {\n name: 'InsertBefore',\n params: [\n 'parentId',\n /* number */ 'childId',\n /* number */ 'beforeId',\n /* number | undefined */ 'slotIndex', /* number | undefined */\n ],\n },\n [SnapshotOperation.RemoveChild]: { name: 'RemoveChild', params: ['parentId', /* number */ 'childId' /* number */] },\n [SnapshotOperation.SetAttribute]: {\n name: 'SetAttribute',\n params: ['id', /* number */ 'dynamicPartIndex', /* number */ 'value' /* any */],\n },\n [SnapshotOperation.SetAttributes]: { name: 'SetAttributes', params: ['id', /* number */ 'values' /* any */] },\n [SnapshotOperation.nodesRefInsertBefore]: {\n name: 'nodesRefInsertBefore',\n params: [\n 'identifier', /* string — CSS selector */\n 'childId', /* number */\n 'beforeId', /* number | undefined */\n ],\n },\n [SnapshotOperation.nodesRefRemoveChild]: {\n name: 'nodesRefRemoveChild',\n params: [\n 'identifier', /* string — CSS selector */\n 'childId', /* number */\n ],\n },\n [SnapshotOperation.DEV_ONLY_AddSnapshot]: {\n name: 'DEV_ONLY_AddSnapshot',\n params: [\n 'uniqID', /* string */\n 'snapshotCreator', /* string */\n ],\n },\n [SnapshotOperation.DEV_ONLY_SetSnapshotEntryName]: {\n name: 'DEV_ONLY_SetSnapshotEntryName',\n params: ['uniqID', /* string */ 'entryName' /* string */],\n },\n} as const;\n\nexport type SnapshotPatch = unknown[];\n\nexport let __globalSnapshotPatch: SnapshotPatch | undefined;\n\nexport function takeGlobalSnapshotPatch(): SnapshotPatch | undefined {\n if (__globalSnapshotPatch) {\n const list = __globalSnapshotPatch;\n __globalSnapshotPatch = [];\n return list;\n } else {\n return undefined;\n }\n}\n\nexport function initGlobalSnapshotPatch(): void {\n __globalSnapshotPatch = [];\n}\n\nexport function deinitGlobalSnapshotPatch(): void {\n __globalSnapshotPatch = undefined;\n}\n"]}
@@ -160,16 +160,6 @@ export function snapshotPatchApply(snapshotPatch, commitId, isHydration) {
160
160
  }
161
161
  break;
162
162
  }
163
- // case SnapshotOperation.DEV_ONLY_RegisterWorklet: {
164
- // // HMR-related
165
- // if (__DEV__) {
166
- // const hash: string = snapshotPatch[++i];
167
- // const fnStr: string = snapshotPatch[++i];
168
- // const fn = evaluate<(ctx: SnapshotInstance) => FiberElement[]>(fnStr);
169
- // registerWorklet('main-thread', hash, fn);
170
- // }
171
- // break;
172
- // }
173
163
  }
174
164
  }
175
165
  }
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotPatchApply.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/snapshotPatchApply.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;;;;;GASG;AAEH,OAAO,EAAE,gCAAgC,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAEzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAE3G;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,aAA4B,EAAE,QAAgB,EAAE,WAAoB;IACrG,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QAChC,QAAQ,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;YACzB,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,CAAC,CAAW,CAAC;oBAE/C,cAAc;oBACd,mDAAmD;oBACnD,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;oBACtD,IAAI,MAAM,EAAE,QAAQ,CAAC,2BAA2B,CAAC,EAAE,CAAC;wBAClD,IAAI,CAAC;4BACH,kBAAkB,CAAC,MAAM,CAAC,GAAG,QAAQ,CACnC,MAAM,CAAC,OAAO,CAAC,4BAA4B,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CACxE,CAAC;wBACJ,CAAC;wBAAC,OAAO,CAAC,EAAE,CAAC;4BACX,OAAO,CAAC,IAAI,CAAC,wDAAwD,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;wBACpF,CAAC;oBACH,CAAC;gBACH,CAAC;gBACD,MAAM;YACR,CAAC;YACC,qDAAqD;YACrD,mBAAmB;YACnB,mBAAmB;YACnB,+CAA+C;YAC/C,gDAAgD;YAChD,6EAA6E;YAC7E,gDAAgD;YAChD,MAAM;YACN,WAAW;YACX,IAAI;QACR,CAAC;IACH,CAAC;AACH,CAAC;AAED,qBAAqB;AACrB;;GAEG;AACH,SAAS,QAAQ,CAAI,IAAY;IAC/B,IAAI,OAAO,EAAE,CAAC;QACZ,2EAA2E;QAC3E,qEAAqE;QACrE,oEAAoE;QACpE,sDAAsD;QACtD,OAAO,IAAI,CAAC,UAAU,IAAI,KAAK,CAAM,CAAC;IACxC,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;AAC1E,CAAC;AACD,oBAAoB","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements the patch application logic for the snapshot system.\n * This module is responsible for interpreting and executing patch operations\n * that were generated in the background thread, applying them to the DOM\n * in the main thread.\n *\n * The module handles various operations like element creation, insertion,\n * removal, and attribute updates, ensuring they are applied in the correct\n * order and with proper error handling.\n */\n\nimport { sendCtxNotFoundEventToBackground } from './error.js';\nimport { applyNodesRefInsertBefore, applyNodesRefRemoveChild } from './nodesRefApply.js';\nimport type { SnapshotPatch } from './snapshotPatch.js';\nimport { SnapshotOperation } from './snapshotPatch.js';\nimport { SnapshotInstance, snapshotCreatorMap, snapshotInstanceManager } from '../../snapshot/snapshot.js';\n\n/**\n * Applies a patch of snapshot operations to the main thread.\n * This is the counterpart to the patch generation in the background thread.\n * Each operation in the patch is processed sequentially to update the DOM.\n */\nexport function snapshotPatchApply(snapshotPatch: SnapshotPatch, commitId: number, isHydration: boolean): void {\n const length = snapshotPatch.length;\n for (let i = 0; i < length; ++i) {\n switch (snapshotPatch[i]) {\n case SnapshotOperation.CreateElement: {\n const type = snapshotPatch[++i] as string;\n const id = snapshotPatch[++i] as number;\n new SnapshotInstance(type, id);\n break;\n }\n case SnapshotOperation.InsertBefore: {\n const parentId = snapshotPatch[++i] as number;\n const childId = snapshotPatch[++i] as number;\n const beforeId = snapshotPatch[++i] as number | undefined;\n const __slotIndex = snapshotPatch[++i] as number;\n const parent = snapshotInstanceManager.values.get(parentId);\n const child = snapshotInstanceManager.values.get(childId);\n const existingNode = snapshotInstanceManager.values.get(beforeId!);\n if (!parent || !child) {\n sendCtxNotFoundEventToBackground(parent ? childId : parentId, {\n operation: 'InsertBefore',\n commitId,\n isHydration,\n parent: parentId,\n child: childId,\n missingNode: parent ? 2 : (child ? 1 : 3),\n });\n } else {\n child.__slotIndex = __slotIndex;\n parent.insertBefore(child, existingNode);\n }\n break;\n }\n case SnapshotOperation.RemoveChild: {\n const parentId = snapshotPatch[++i] as number;\n const childId = snapshotPatch[++i] as number;\n const parent = snapshotInstanceManager.values.get(parentId);\n const child = snapshotInstanceManager.values.get(childId);\n if (!parent || !child) {\n sendCtxNotFoundEventToBackground(parent ? childId : parentId, {\n operation: 'RemoveChild',\n commitId,\n isHydration,\n parent: parentId,\n child: childId,\n missingNode: parent ? 2 : (child ? 1 : 3),\n });\n } else {\n parent.removeChild(child);\n }\n break;\n }\n case SnapshotOperation.nodesRefInsertBefore: {\n const identifier = snapshotPatch[++i] as string;\n const childId = snapshotPatch[++i] as number;\n const beforeId = snapshotPatch[++i] as number | undefined;\n const child = snapshotInstanceManager.values.get(childId);\n if (child) {\n applyNodesRefInsertBefore(identifier, child, beforeId);\n } else {\n sendCtxNotFoundEventToBackground(childId, {\n operation: 'nodesRefInsertBefore',\n commitId,\n isHydration,\n });\n }\n break;\n }\n case SnapshotOperation.nodesRefRemoveChild: {\n const identifier = snapshotPatch[++i] as string;\n const childId = snapshotPatch[++i] as number;\n const child = snapshotInstanceManager.values.get(childId);\n if (child) {\n applyNodesRefRemoveChild(identifier, child);\n } else {\n sendCtxNotFoundEventToBackground(childId, {\n operation: 'nodesRefRemoveChild',\n commitId,\n isHydration,\n });\n }\n break;\n }\n case SnapshotOperation.SetAttribute: {\n const id = snapshotPatch[++i] as number;\n const dynamicPartIndex = snapshotPatch[++i] as number;\n const value = snapshotPatch[++i];\n const si = snapshotInstanceManager.values.get(id);\n if (si) {\n si.setAttribute(dynamicPartIndex, value);\n } else {\n sendCtxNotFoundEventToBackground(id, { operation: 'SetAttribute', commitId, isHydration });\n }\n break;\n }\n case SnapshotOperation.SetAttributes: {\n const id = snapshotPatch[++i] as number;\n const values = snapshotPatch[++i];\n const si = snapshotInstanceManager.values.get(id);\n if (si) {\n si.setAttribute('values', values);\n } else {\n sendCtxNotFoundEventToBackground(id, { operation: 'SetAttributes', commitId, isHydration });\n }\n break;\n }\n case SnapshotOperation.DEV_ONLY_AddSnapshot: {\n if (__DEV__) {\n const uniqID = snapshotPatch[++i] as string;\n const snapshotCreator = snapshotPatch[++i] as string;\n\n // HMR-related\n // Update the evaluated snapshots from JS.\n snapshotCreatorMap[uniqID] = evaluate<(uniqId: string) => string>(snapshotCreator);\n }\n break;\n }\n case SnapshotOperation.DEV_ONLY_SetSnapshotEntryName: {\n if (__DEV__) {\n const uniqID = snapshotPatch[++i] as string;\n const entryName = snapshotPatch[++i] as string;\n\n // HMR-related\n // Update the evaluated snapshot entryName from JS.\n const source = snapshotCreatorMap[uniqID]?.toString();\n if (source?.includes('globDynamicComponentEntry')) {\n try {\n snapshotCreatorMap[uniqID] = evaluate<(uniqId: string) => string>(\n source.replace(/globDynamicComponentEntry/g, JSON.stringify(entryName)),\n );\n } catch (e) {\n console.warn(`[ReactLynx] failed to rewrite snapshot entryName for ${uniqID}`, e);\n }\n }\n }\n break;\n }\n // case SnapshotOperation.DEV_ONLY_RegisterWorklet: {\n // // HMR-related\n // if (__DEV__) {\n // const hash: string = snapshotPatch[++i];\n // const fnStr: string = snapshotPatch[++i];\n // const fn = evaluate<(ctx: SnapshotInstance) => FiberElement[]>(fnStr);\n // registerWorklet('main-thread', hash, fn);\n // }\n // break;\n // }\n }\n }\n}\n\n/* v8 ignore start */\n/**\n * Deserializes a stringified snapshot creator for HMR.\n */\nfunction evaluate<T>(code: string): T {\n if (__DEV__) {\n // Creators receive the runtime as a call argument (see `SnapshotCreator`).\n // Direct `eval` is kept for the legacy `__runtime__ || require(...)`\n // fallback, which resolves `__webpack_require__` from this scope on\n // runtimes that call creators with a single argument.\n return eval(`(() => ${code})()`) as T;\n }\n throw new Error('unreachable: evaluate is not supported in production');\n}\n/* v8 ignore stop */\n"]}
1
+ {"version":3,"file":"snapshotPatchApply.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/snapshotPatchApply.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;;;;;GASG;AAEH,OAAO,EAAE,gCAAgC,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAEzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,4BAA4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kB,CAAC,MAAM,CAAC,GAAG,QAAQ,CAA6B,eAAe,CAAC,CAAC;gBACrF,CAAC;gBACD,MAAM;YACR,CAAC;YACD,KAAK,iBAAiB,CAAC,6BAA6B,CAAC,CAAC,CAAC;gBACrD,IAAI,OAAO,EAAE,CAAC;oBACZ,MAAM,MAAM,GAAG,aAAa,CAAC,EAAE,CAAC,CAAW,CAAC;oBAC5C,MAAM,SAAS,GAAG,aAAa,CAAC,EAAE,CAAC,CAAW,CAAC;oBAE/C,cAAc;oBACd,mDAAmD;oBACnD,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;oBACtD,IAAI,MAAM,EAAE,QAAQ,CAAC,2BAA2B,CAAC,EAAE,CAAC;wBAClD,IAAI,CAAC;4BACH,kBAAkB,CAAC,MAAM,CAAC,GAAG,QAAQ,CACnC,MAAM,CAAC,OAAO,CAAC,4BAA4B,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CACxE,CAAC;wBACJ,CAAC;wBAAC,OAAO,CAAC,EAAE,CAAC;4BACX,OAAO,CAAC,IAAI,CAAC,wDAAwD,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;wBACpF,CAAC;oBACH,CAAC;gBACH,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED,qBAAqB;AACrB;;GAEG;AACH,SAAS,QAAQ,CAAI,IAAY;IAC/B,IAAI,OAAO,EAAE,CAAC;QACZ,2EAA2E;QAC3E,qEAAqE;QACrE,oEAAoE;QACpE,sDAAsD;QACtD,OAAO,IAAI,CAAC,UAAU,IAAI,KAAK,CAAM,CAAC;IACxC,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;AAC1E,CAAC;AACD,oBAAoB","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements the patch application logic for the snapshot system.\n * This module is responsible for interpreting and executing patch operations\n * that were generated in the background thread, applying them to the DOM\n * in the main thread.\n *\n * The module handles various operations like element creation, insertion,\n * removal, and attribute updates, ensuring they are applied in the correct\n * order and with proper error handling.\n */\n\nimport { sendCtxNotFoundEventToBackground } from './error.js';\nimport { applyNodesRefInsertBefore, applyNodesRefRemoveChild } from './nodesRefApply.js';\nimport type { SnapshotPatch } from './snapshotPatch.js';\nimport { SnapshotOperation } from './snapshotPatch.js';\nimport { SnapshotInstance, snapshotCreatorMap, snapshotInstanceManager } from '../../snapshot/snapshot.js';\n\n/**\n * Applies a patch of snapshot operations to the main thread.\n * This is the counterpart to the patch generation in the background thread.\n * Each operation in the patch is processed sequentially to update the DOM.\n */\nexport function snapshotPatchApply(snapshotPatch: SnapshotPatch, commitId: number, isHydration: boolean): void {\n const length = snapshotPatch.length;\n for (let i = 0; i < length; ++i) {\n switch (snapshotPatch[i]) {\n case SnapshotOperation.CreateElement: {\n const type = snapshotPatch[++i] as string;\n const id = snapshotPatch[++i] as number;\n new SnapshotInstance(type, id);\n break;\n }\n case SnapshotOperation.InsertBefore: {\n const parentId = snapshotPatch[++i] as number;\n const childId = snapshotPatch[++i] as number;\n const beforeId = snapshotPatch[++i] as number | undefined;\n const __slotIndex = snapshotPatch[++i] as number;\n const parent = snapshotInstanceManager.values.get(parentId);\n const child = snapshotInstanceManager.values.get(childId);\n const existingNode = snapshotInstanceManager.values.get(beforeId!);\n if (!parent || !child) {\n sendCtxNotFoundEventToBackground(parent ? childId : parentId, {\n operation: 'InsertBefore',\n commitId,\n isHydration,\n parent: parentId,\n child: childId,\n missingNode: parent ? 2 : (child ? 1 : 3),\n });\n } else {\n child.__slotIndex = __slotIndex;\n parent.insertBefore(child, existingNode);\n }\n break;\n }\n case SnapshotOperation.RemoveChild: {\n const parentId = snapshotPatch[++i] as number;\n const childId = snapshotPatch[++i] as number;\n const parent = snapshotInstanceManager.values.get(parentId);\n const child = snapshotInstanceManager.values.get(childId);\n if (!parent || !child) {\n sendCtxNotFoundEventToBackground(parent ? childId : parentId, {\n operation: 'RemoveChild',\n commitId,\n isHydration,\n parent: parentId,\n child: childId,\n missingNode: parent ? 2 : (child ? 1 : 3),\n });\n } else {\n parent.removeChild(child);\n }\n break;\n }\n case SnapshotOperation.nodesRefInsertBefore: {\n const identifier = snapshotPatch[++i] as string;\n const childId = snapshotPatch[++i] as number;\n const beforeId = snapshotPatch[++i] as number | undefined;\n const child = snapshotInstanceManager.values.get(childId);\n if (child) {\n applyNodesRefInsertBefore(identifier, child, beforeId);\n } else {\n sendCtxNotFoundEventToBackground(childId, {\n operation: 'nodesRefInsertBefore',\n commitId,\n isHydration,\n });\n }\n break;\n }\n case SnapshotOperation.nodesRefRemoveChild: {\n const identifier = snapshotPatch[++i] as string;\n const childId = snapshotPatch[++i] as number;\n const child = snapshotInstanceManager.values.get(childId);\n if (child) {\n applyNodesRefRemoveChild(identifier, child);\n } else {\n sendCtxNotFoundEventToBackground(childId, {\n operation: 'nodesRefRemoveChild',\n commitId,\n isHydration,\n });\n }\n break;\n }\n case SnapshotOperation.SetAttribute: {\n const id = snapshotPatch[++i] as number;\n const dynamicPartIndex = snapshotPatch[++i] as number;\n const value = snapshotPatch[++i];\n const si = snapshotInstanceManager.values.get(id);\n if (si) {\n si.setAttribute(dynamicPartIndex, value);\n } else {\n sendCtxNotFoundEventToBackground(id, { operation: 'SetAttribute', commitId, isHydration });\n }\n break;\n }\n case SnapshotOperation.SetAttributes: {\n const id = snapshotPatch[++i] as number;\n const values = snapshotPatch[++i];\n const si = snapshotInstanceManager.values.get(id);\n if (si) {\n si.setAttribute('values', values);\n } else {\n sendCtxNotFoundEventToBackground(id, { operation: 'SetAttributes', commitId, isHydration });\n }\n break;\n }\n case SnapshotOperation.DEV_ONLY_AddSnapshot: {\n if (__DEV__) {\n const uniqID = snapshotPatch[++i] as string;\n const snapshotCreator = snapshotPatch[++i] as string;\n\n // HMR-related\n // Update the evaluated snapshots from JS.\n snapshotCreatorMap[uniqID] = evaluate<(uniqId: string) => string>(snapshotCreator);\n }\n break;\n }\n case SnapshotOperation.DEV_ONLY_SetSnapshotEntryName: {\n if (__DEV__) {\n const uniqID = snapshotPatch[++i] as string;\n const entryName = snapshotPatch[++i] as string;\n\n // HMR-related\n // Update the evaluated snapshot entryName from JS.\n const source = snapshotCreatorMap[uniqID]?.toString();\n if (source?.includes('globDynamicComponentEntry')) {\n try {\n snapshotCreatorMap[uniqID] = evaluate<(uniqId: string) => string>(\n source.replace(/globDynamicComponentEntry/g, JSON.stringify(entryName)),\n );\n } catch (e) {\n console.warn(`[ReactLynx] failed to rewrite snapshot entryName for ${uniqID}`, e);\n }\n }\n }\n break;\n }\n }\n }\n}\n\n/* v8 ignore start */\n/**\n * Deserializes a stringified snapshot creator for HMR.\n */\nfunction evaluate<T>(code: string): T {\n if (__DEV__) {\n // Creators receive the runtime as a call argument (see `SnapshotCreator`).\n // Direct `eval` is kept for the legacy `__runtime__ || require(...)`\n // fallback, which resolves `__webpack_require__` from this scope on\n // runtimes that call creators with a single argument.\n return eval(`(() => ${code})()`) as T;\n }\n throw new Error('unreachable: evaluate is not supported in production');\n}\n/* v8 ignore stop */\n"]}
@@ -24,65 +24,70 @@ function updateMainThread({ data, patchOptions }) {
24
24
  });
25
25
  }
26
26
  setPipeline(patchOptions.pipelineOptions);
27
- markTiming('mtsRenderStart');
28
- markTiming('parseChangesStart');
29
- const parsedData = JSON.parse(data);
30
- const { patchList, flushOptions = {}, delayedRunOnMainThreadData } = parsedData;
31
- if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
32
- console.alog?.('[ReactLynxDebug] BTS -> MTS updateMainThread:\n' + JSON.stringify({
33
- data: {
34
- ...parsedData,
35
- patchList: parsedData.patchList.map(patch => ({
36
- ...patch,
37
- snapshotPatch: prettyFormatSnapshotPatch(patch.snapshotPatch),
38
- })),
39
- },
40
- patchOptions,
41
- }, null, 2));
42
- }
43
- markTiming('parseChangesEnd');
44
- markTiming('patchChangesStart');
45
- if (patchOptions.isHydration) {
46
- setMainThreadHydrating(true);
47
- }
48
27
  try {
49
- for (const { snapshotPatch, id } of patchList) {
50
- __pendingListUpdates.clearAttachedLists();
51
- if (snapshotPatch) {
52
- snapshotPatchApply(snapshotPatch, id, patchOptions.isHydration === true);
53
- }
54
- __pendingListUpdates.flush();
55
- // console.debug('********** Lepus updatePatch:');
56
- // printSnapshotInstance(snapshotInstanceManager.values.get(-1)!);
28
+ markTiming('mtsRenderStart');
29
+ markTiming('parseChangesStart');
30
+ const parsedData = JSON.parse(data);
31
+ const { patchList, flushOptions = {}, delayedRunOnMainThreadData } = parsedData;
32
+ if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
33
+ console.alog?.('[ReactLynxDebug] BTS -> MTS updateMainThread:\n' + JSON.stringify({
34
+ data: {
35
+ ...parsedData,
36
+ patchList: parsedData.patchList.map(patch => ({
37
+ ...patch,
38
+ snapshotPatch: prettyFormatSnapshotPatch(patch.snapshotPatch),
39
+ })),
40
+ },
41
+ patchOptions,
42
+ }, null, 2));
57
43
  }
58
- }
59
- finally {
60
- markTiming('patchChangesEnd');
61
- markTiming('mtsRenderEnd');
44
+ markTiming('parseChangesEnd');
45
+ markTiming('patchChangesStart');
62
46
  if (patchOptions.isHydration) {
63
- setMainThreadHydrating(false);
47
+ setMainThreadHydrating(true);
64
48
  }
65
- }
66
- applyRefQueue();
67
- if (delayedRunOnMainThreadData && isMtsEnabled()) {
68
- setEomShouldFlushElementTree(false);
69
- for (const data of delayedRunOnMainThreadData) {
70
- try {
71
- runRunOnMainThreadTask(data.worklet, data.params, data.resolveId);
72
- /* v8 ignore next 3 */
49
+ try {
50
+ for (const { snapshotPatch, id } of patchList) {
51
+ __pendingListUpdates.clearAttachedLists();
52
+ if (snapshotPatch) {
53
+ snapshotPatchApply(snapshotPatch, id, patchOptions.isHydration === true);
54
+ }
55
+ __pendingListUpdates.flush();
56
+ // console.debug('********** Lepus updatePatch:');
57
+ // printSnapshotInstance(snapshotInstanceManager.values.get(-1)!);
58
+ }
59
+ }
60
+ finally {
61
+ markTiming('patchChangesEnd');
62
+ markTiming('mtsRenderEnd');
63
+ if (patchOptions.isHydration) {
64
+ setMainThreadHydrating(false);
73
65
  }
74
- catch (e) {
75
- lynx.reportError(e);
66
+ }
67
+ applyRefQueue();
68
+ if (delayedRunOnMainThreadData && isMtsEnabled()) {
69
+ setEomShouldFlushElementTree(false);
70
+ for (const data of delayedRunOnMainThreadData) {
71
+ try {
72
+ runRunOnMainThreadTask(data.worklet, data.params, data.resolveId);
73
+ /* v8 ignore next 3 */
74
+ }
75
+ catch (e) {
76
+ lynx.reportError(e);
77
+ }
76
78
  }
79
+ setEomShouldFlushElementTree(true);
80
+ }
81
+ if (patchOptions.pipelineOptions) {
82
+ flushOptions.pipelineOptions = patchOptions.pipelineOptions;
83
+ }
84
+ __FlushElementTree(__page, flushOptions);
85
+ if (flowIds) {
86
+ lynx.performance.profileEnd();
77
87
  }
78
- setEomShouldFlushElementTree(true);
79
- }
80
- if (patchOptions.pipelineOptions) {
81
- flushOptions.pipelineOptions = patchOptions.pipelineOptions;
82
88
  }
83
- __FlushElementTree(__page, flushOptions);
84
- if (flowIds) {
85
- lynx.performance.profileEnd();
89
+ finally {
90
+ setPipeline(undefined);
86
91
  }
87
92
  }
88
93
  function injectUpdateMainThread() {
@@ -1 +1 @@
1
- {"version":3,"file":"updateMainThread.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/updateMainThread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAG/G,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,C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xB,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,IAAI,CAAC,WAAW,CAAC,CAAU,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QACD,4BAA4B,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,YAAY,CAAC,eAAe,EAAE,CAAC;QACjC,YAAY,CAAC,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC;IAC9D,CAAC;IACD,kBAAkB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAEzC,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC;IAChC,CAAC;AACH,CAAC;AAED,SAAS,sBAAsB;IAC7B,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC;AACnF,CAAC;AAED;;GAEG;AACH,OAAO,EAAE,sBAAsB,EAAE,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { ClosureValueType } from '@lynx-js/react/worklet-runtime/bindings';\nimport { runRunOnMainThreadTask, setEomShouldFlushElementTree } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport type { PatchList, PatchOptions } from './commit.js';\nimport { setMainThreadHydrating } from './isMainThreadHydrating.js';\nimport { snapshotPatchApply } from './snapshotPatchApply.js';\nimport { markTiming, setPipeline } from '../../../core/performance.js';\nimport { getReloadVersion } from '../../../core/reload-version.js';\nimport { prettyFormatSnapshotPatch } from '../../debug/formatPatch.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\nimport { __pendingListUpdates } from '../../list/pendingListUpdates.js';\nimport { __page } from '../../snapshot/definition.js';\nimport { applyRefQueue } from '../../snapshot/workletRef.js';\nimport { isMtsEnabled } from '../../worklet/functionality.js';\n\nfunction updateMainThread(\n { data, patchOptions }: {\n data: string;\n patchOptions: PatchOptions;\n },\n): void {\n if ((patchOptions.reloadVersion) < getReloadVersion()) {\n return;\n }\n\n const flowIds = patchOptions.flowIds;\n if (flowIds) {\n lynx.performance.profileStart('ReactLynx::patch', {\n flowId: flowIds[0],\n flowIds,\n });\n }\n\n setPipeline(patchOptions.pipelineOptions);\n markTiming('mtsRenderStart');\n markTiming('parseChangesStart');\n const parsedData = JSON.parse(data) as PatchList;\n const { patchList, flushOptions = {}, delayedRunOnMainThreadData } = parsedData;\n\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] BTS -> MTS updateMainThread:\\n' + JSON.stringify(\n {\n data: {\n ...parsedData,\n patchList: parsedData.patchList.map(patch => ({\n ...patch,\n snapshotPatch: prettyFormatSnapshotPatch(patch.snapshotPatch),\n })),\n },\n patchOptions,\n },\n null,\n 2,\n ),\n );\n }\n\n markTiming('parseChangesEnd');\n markTiming('patchChangesStart');\n if (patchOptions.isHydration) {\n setMainThreadHydrating(true);\n }\n try {\n for (const { snapshotPatch, id } of patchList) {\n __pendingListUpdates.clearAttachedLists();\n if (snapshotPatch) {\n snapshotPatchApply(snapshotPatch, id, patchOptions.isHydration === true);\n }\n __pendingListUpdates.flush();\n // console.debug('********** Lepus updatePatch:');\n // printSnapshotInstance(snapshotInstanceManager.values.get(-1)!);\n }\n } finally {\n markTiming('patchChangesEnd');\n markTiming('mtsRenderEnd');\n if (patchOptions.isHydration) {\n setMainThreadHydrating(false);\n }\n }\n applyRefQueue();\n if (delayedRunOnMainThreadData && isMtsEnabled()) {\n setEomShouldFlushElementTree(false);\n for (const data of delayedRunOnMainThreadData) {\n try {\n runRunOnMainThreadTask(data.worklet, data.params as ClosureValueType[], data.resolveId);\n /* v8 ignore next 3 */\n } catch (e) {\n lynx.reportError(e as Error);\n }\n }\n setEomShouldFlushElementTree(true);\n }\n if (patchOptions.pipelineOptions) {\n flushOptions.pipelineOptions = patchOptions.pipelineOptions;\n }\n __FlushElementTree(__page, flushOptions);\n\n if (flowIds) {\n lynx.performance.profileEnd();\n }\n}\n\nfunction injectUpdateMainThread(): void {\n Object.assign(globalThis, { [LifecycleConstant.patchUpdate]: updateMainThread });\n}\n\n/**\n * @internal\n */\nexport { injectUpdateMainThread };\n"]}
1
+ {"version":3,"file":"updateMainThread.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/patch/updateMainThread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAG/G,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE9D,SAAS,gBAAgB,CACvB,EAAE,IAAI,EAAE,YAAY,EAGnB;IAED,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,gBAAgB,EAAE,EAAE,CAAC;QACtD,OAAO;IACT,CAAC;IAED,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC;IACrC,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,kBAAkB,EAAE;YAChD,MAAM,EAAE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;;GAEG;AACH,OAAO,EAAE,sBAAsB,EAAE,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { ClosureValueType } from '@lynx-js/react/worklet-runtime/bindings';\nimport { runRunOnMainThreadTask, setEomShouldFlushElementTree } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport type { PatchList, PatchOptions } from './commit.js';\nimport { setMainThreadHydrating } from './isMainThreadHydrating.js';\nimport { snapshotPatchApply } from './snapshotPatchApply.js';\nimport { markTiming, setPipeline } from '../../../core/performance.js';\nimport { getReloadVersion } from '../../../core/reload-version.js';\nimport { prettyFormatSnapshotPatch } from '../../debug/formatPatch.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\nimport { __pendingListUpdates } from '../../list/pendingListUpdates.js';\nimport { __page } from '../../snapshot/definition.js';\nimport { applyRefQueue } from '../../snapshot/workletRef.js';\nimport { isMtsEnabled } from '../../worklet/functionality.js';\n\nfunction updateMainThread(\n { data, patchOptions }: {\n data: string;\n patchOptions: PatchOptions;\n },\n): void {\n if ((patchOptions.reloadVersion) < getReloadVersion()) {\n return;\n }\n\n const flowIds = patchOptions.flowIds;\n if (flowIds) {\n lynx.performance.profileStart('ReactLynx::patch', {\n flowId: flowIds[0],\n flowIds,\n });\n }\n\n setPipeline(patchOptions.pipelineOptions);\n try {\n markTiming('mtsRenderStart');\n markTiming('parseChangesStart');\n const parsedData = JSON.parse(data) as PatchList;\n const { patchList, flushOptions = {}, delayedRunOnMainThreadData } = parsedData;\n\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] BTS -> MTS updateMainThread:\\n' + JSON.stringify(\n {\n data: {\n ...parsedData,\n patchList: parsedData.patchList.map(patch => ({\n ...patch,\n snapshotPatch: prettyFormatSnapshotPatch(patch.snapshotPatch),\n })),\n },\n patchOptions,\n },\n null,\n 2,\n ),\n );\n }\n\n markTiming('parseChangesEnd');\n markTiming('patchChangesStart');\n if (patchOptions.isHydration) {\n setMainThreadHydrating(true);\n }\n try {\n for (const { snapshotPatch, id } of patchList) {\n __pendingListUpdates.clearAttachedLists();\n if (snapshotPatch) {\n snapshotPatchApply(snapshotPatch, id, patchOptions.isHydration === true);\n }\n __pendingListUpdates.flush();\n // console.debug('********** Lepus updatePatch:');\n // printSnapshotInstance(snapshotInstanceManager.values.get(-1)!);\n }\n } finally {\n markTiming('patchChangesEnd');\n markTiming('mtsRenderEnd');\n if (patchOptions.isHydration) {\n setMainThreadHydrating(false);\n }\n }\n applyRefQueue();\n if (delayedRunOnMainThreadData && isMtsEnabled()) {\n setEomShouldFlushElementTree(false);\n for (const data of delayedRunOnMainThreadData) {\n try {\n runRunOnMainThreadTask(data.worklet, data.params as ClosureValueType[], data.resolveId);\n /* v8 ignore next 3 */\n } catch (e) {\n lynx.reportError(e as Error);\n }\n }\n setEomShouldFlushElementTree(true);\n }\n if (patchOptions.pipelineOptions) {\n flushOptions.pipelineOptions = patchOptions.pipelineOptions;\n }\n __FlushElementTree(__page, flushOptions);\n\n if (flowIds) {\n lynx.performance.profileEnd();\n }\n } finally {\n setPipeline(undefined);\n }\n}\n\nfunction injectUpdateMainThread(): void {\n Object.assign(globalThis, { [LifecycleConstant.patchUpdate]: updateMainThread });\n}\n\n/**\n * @internal\n */\nexport { injectUpdateMainThread };\n"]}
@@ -1,3 +1,10 @@
1
+ import { SnapshotInstance } from '../snapshot/snapshot.js';
1
2
  declare function reloadMainThread(data: unknown, options: UpdatePageOption): void;
2
- declare function reloadBackground(updateData: Record<string, any>): void;
3
- export { reloadBackground, reloadMainThread };
3
+ interface MainThreadReloadHandoff {
4
+ oldRoot: SnapshotInstance;
5
+ page: FiberElement;
6
+ options: UpdatePageOption;
7
+ }
8
+ declare function completeMainThreadReload({ oldRoot, page, options }: MainThreadReloadHandoff): void;
9
+ declare function reloadBackground(updateData: Record<string, any>, options?: Record<string, unknown>): void;
10
+ export { completeMainThreadReload, reloadBackground, reloadMainThread };
@@ -6,25 +6,29 @@
6
6
  * and background thread.
7
7
  */
8
8
  import { render } from 'preact';
9
+ import { clearDelayedRunOnBackgroundFunctions } from '@lynx-js/react/worklet-runtime/bindings';
9
10
  import { destroyBackground } from './destroy.js';
10
11
  import { renderMainThread } from './render.js';
12
+ import { canReEvalBackgroundEntry, canReEvalMainThreadEntry, installMainThreadReloadCompleter, reEvalBackgroundEntry, reEvalMainThreadEntry, } from '../../core/entry-reload.js';
11
13
  import { increaseReloadVersion } from '../../core/reload-version.js';
14
+ import { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';
12
15
  import { __root, setRoot } from '../../root.js';
13
16
  import { profileEnd, profileStart } from '../../shared/profile.js';
14
17
  import { isEmptyObject } from '../../utils.js';
15
18
  import { LifecycleConstant } from '../lifecycle/constant.js';
16
19
  import { __pendingListUpdates } from '../list/pendingListUpdates.js';
17
20
  import { hydrate } from '../renderToOpcodes/hydrate.js';
18
- import { __page } from '../snapshot/definition.js';
21
+ import { __page, setupPage } from '../snapshot/definition.js';
19
22
  import { SnapshotInstance, snapshotInstanceManager } from '../snapshot/snapshot.js';
20
23
  import { applyRefQueue } from '../snapshot/workletRef.js';
21
- import { clearFirstScreenEventIdSwap, isFirstScreenSynced } from './event/firstScreenSync.js';
22
- import { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';
24
+ import { clearFirstScreenEventIdSwap, firstScreenSync } from './event/firstScreenSync.js';
23
25
  import { shouldDelayUiOps } from './ref/delay.js';
24
26
  function reloadMainThread(data, options) {
25
27
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
26
28
  profileStart('ReactLynx::reloadMainThread');
27
29
  }
30
+ clearDelayedRunOnBackgroundFunctions();
31
+ resetFunctionCallReturnListener();
28
32
  increaseReloadVersion();
29
33
  if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {
30
34
  Object.assign(lynx.__initData, data);
@@ -33,8 +37,20 @@ function reloadMainThread(data, options) {
33
37
  __pendingListUpdates.clearAttachedLists();
34
38
  clearFirstScreenEventIdSwap();
35
39
  const oldRoot = __root;
40
+ if (canReEvalMainThreadEntry()) {
41
+ reEvalMainThreadEntry({ oldRoot: oldRoot, page: __page, options });
42
+ return;
43
+ }
36
44
  setRoot(new SnapshotInstance('root'));
37
45
  __root.__jsx = oldRoot.__jsx;
46
+ finishMainThreadReload(oldRoot, options);
47
+ }
48
+ function completeMainThreadReload({ oldRoot, page, options }) {
49
+ setupPage(page);
50
+ finishMainThreadReload(oldRoot, options);
51
+ }
52
+ installMainThreadReloadCompleter(completeMainThreadReload);
53
+ function finishMainThreadReload(oldRoot, options) {
38
54
  renderMainThread();
39
55
  hydrate(oldRoot, __root, {
40
56
  skipUnRef: true,
@@ -45,7 +61,7 @@ function reloadMainThread(data, options) {
45
61
  if (typeof lepusng_gc === 'function') {
46
62
  lepusng_gc();
47
63
  }
48
- if (isFirstScreenSynced) {
64
+ if (firstScreenSync.isSynced) {
49
65
  __OnLifecycleEvent([
50
66
  LifecycleConstant.firstScreen, /* FIRST_SCREEN */
51
67
  {
@@ -57,13 +73,18 @@ function reloadMainThread(data, options) {
57
73
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
58
74
  profileEnd();
59
75
  }
60
- return;
61
76
  }
62
- function reloadBackground(updateData) {
77
+ function reloadBackground(updateData, options) {
78
+ if (canReEvalBackgroundEntry()) {
79
+ reEvalBackgroundEntry(updateData, options, () => {
80
+ // A queued `updateGlobalProps` callback must not render it again.
81
+ __root.__jsx = undefined;
82
+ });
83
+ return;
84
+ }
63
85
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
64
86
  profileStart('ReactLynx::reloadBackground');
65
87
  }
66
- deinitGlobalSnapshotPatch();
67
88
  destroyBackground();
68
89
  increaseReloadVersion();
69
90
  // COW when modify `lynx.__initData` to make sure Provider & Consumer works
@@ -75,5 +96,5 @@ function reloadBackground(updateData) {
75
96
  profileEnd();
76
97
  }
77
98
  }
78
- export { reloadBackground, reloadMainThread };
99
+ export { completeMainThreadReload, reloadBackground, reloadMainThread };
79
100
  //# sourceMappingURL=reload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reload.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/reload.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC9F,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,SAAS,gBAAgB,CAAC,IAAa,EAAE,OAAyB;IAChE,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE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K,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,6BAA6B,CAAC,CAAC;IAC9C,CAAC;IAED,yBAAyB,EAAE,CAAC;IAE5B,iBAAiB,EAAE,CAAC;IAEpB,qBAAqB,EAAE,CAAC;IAExB,2EAA2E;IAC3E,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEjE,gBAAgB,CAAC,KAAK,GAAG,IAAI,CAAC;IAC9B,iEAAiE;IACjE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAa,CAAC,CAAC;IAEpC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements the reload (thinking of \"refresh\" in browser) for both main thread\n * and background thread.\n */\n\nimport { render } from 'preact';\n\nimport { destroyBackground } from './destroy.js';\nimport { renderMainThread } from './render.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { __root, setRoot } from '../../root.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { isEmptyObject } from '../../utils.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport { __pendingListUpdates } from '../list/pendingListUpdates.js';\nimport { hydrate } from '../renderToOpcodes/hydrate.js';\nimport { __page } from '../snapshot/definition.js';\nimport { SnapshotInstance, snapshotInstanceManager } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\nimport { clearFirstScreenEventIdSwap, isFirstScreenSynced } from './event/firstScreenSync.js';\nimport { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';\nimport { shouldDelayUiOps } from './ref/delay.js';\n\nfunction reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n increaseReloadVersion();\n\n if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {\n Object.assign(lynx.__initData, data);\n }\n\n snapshotInstanceManager.clear();\n __pendingListUpdates.clearAttachedLists();\n clearFirstScreenEventIdSwap();\n\n const oldRoot = __root;\n setRoot(new SnapshotInstance('root'));\n __root.__jsx = oldRoot.__jsx;\n renderMainThread();\n hydrate(oldRoot as SnapshotInstance, __root as SnapshotInstance, {\n skipUnRef: true,\n });\n\n // always call this before `__FlushElementTree`\n __pendingListUpdates.flush();\n applyRefQueue();\n\n if (typeof lepusng_gc === 'function') {\n lepusng_gc();\n }\n\n if (isFirstScreenSynced) {\n __OnLifecycleEvent([\n LifecycleConstant.firstScreen, /* FIRST_SCREEN */\n {\n root: JSON.stringify(__root),\n },\n ]);\n }\n\n __FlushElementTree(__page, options);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n return;\n}\n\nfunction reloadBackground(updateData: Record<string, any>): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadBackground');\n }\n\n deinitGlobalSnapshotPatch();\n\n destroyBackground();\n\n increaseReloadVersion();\n\n // COW when modify `lynx.__initData` to make sure Provider & Consumer works\n lynx.__initData = Object.assign({}, lynx.__initData, updateData);\n\n shouldDelayUiOps.value = true;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(__root.__jsx, __root as any);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nexport { reloadBackground, reloadMainThread };\n"]}
1
+ {"version":3,"file":"reload.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/reload.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;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,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements the reload (thinking of \"refresh\" in browser) for both main thread\n * and background thread.\n */\n\nimport { render } from 'preact';\n\nimport { clearDelayedRunOnBackgroundFunctions } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { destroyBackground } from './destroy.js';\nimport { renderMainThread } from './render.js';\nimport {\n canReEvalBackgroundEntry,\n canReEvalMainThreadEntry,\n installMainThreadReloadCompleter,\n reEvalBackgroundEntry,\n reEvalMainThreadEntry,\n} from '../../core/entry-reload.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';\nimport { __root, setRoot } from '../../root.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { isEmptyObject } from '../../utils.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport { __pendingListUpdates } from '../list/pendingListUpdates.js';\nimport { hydrate } from '../renderToOpcodes/hydrate.js';\nimport { __page, setupPage } from '../snapshot/definition.js';\nimport { SnapshotInstance, snapshotInstanceManager } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\nimport { clearFirstScreenEventIdSwap, firstScreenSync } from './event/firstScreenSync.js';\nimport { shouldDelayUiOps } from './ref/delay.js';\n\nfunction reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n clearDelayedRunOnBackgroundFunctions();\n resetFunctionCallReturnListener();\n increaseReloadVersion();\n\n if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {\n Object.assign(lynx.__initData, data);\n }\n\n snapshotInstanceManager.clear();\n __pendingListUpdates.clearAttachedLists();\n clearFirstScreenEventIdSwap();\n\n const oldRoot = __root;\n if (canReEvalMainThreadEntry()) {\n reEvalMainThreadEntry<MainThreadReloadHandoff>({ oldRoot: oldRoot as SnapshotInstance, page: __page, options });\n return;\n }\n setRoot(new SnapshotInstance('root'));\n __root.__jsx = oldRoot.__jsx;\n finishMainThreadReload(oldRoot as SnapshotInstance, options);\n}\n\ninterface MainThreadReloadHandoff {\n oldRoot: SnapshotInstance;\n page: FiberElement;\n options: UpdatePageOption;\n}\n\nfunction completeMainThreadReload({ oldRoot, page, options }: MainThreadReloadHandoff): void {\n setupPage(page);\n finishMainThreadReload(oldRoot, options);\n}\n\ninstallMainThreadReloadCompleter(completeMainThreadReload);\n\nfunction finishMainThreadReload(oldRoot: SnapshotInstance, options: UpdatePageOption): void {\n renderMainThread();\n hydrate(oldRoot, __root as SnapshotInstance, {\n skipUnRef: true,\n });\n\n // always call this before `__FlushElementTree`\n __pendingListUpdates.flush();\n applyRefQueue();\n\n if (typeof lepusng_gc === 'function') {\n lepusng_gc();\n }\n\n if (firstScreenSync.isSynced) {\n __OnLifecycleEvent([\n LifecycleConstant.firstScreen, /* FIRST_SCREEN */\n {\n root: JSON.stringify(__root),\n },\n ]);\n }\n\n __FlushElementTree(__page, options);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nfunction reloadBackground(updateData: Record<string, any>, options?: Record<string, unknown>): void {\n if (canReEvalBackgroundEntry()) {\n reEvalBackgroundEntry(updateData, options, () => {\n // A queued `updateGlobalProps` callback must not render it again.\n __root.__jsx = undefined;\n });\n return;\n }\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadBackground');\n }\n\n destroyBackground();\n increaseReloadVersion();\n\n // COW when modify `lynx.__initData` to make sure Provider & Consumer works\n lynx.__initData = Object.assign({}, lynx.__initData, updateData);\n\n shouldDelayUiOps.value = true;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(__root.__jsx, __root as any);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nexport { completeMainThreadReload, reloadBackground, reloadMainThread };\n"]}
@@ -1,11 +1,12 @@
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 { cardLifetime } from '../../core/card-lifetime.js';
4
5
  import { maybePromise } from '../../utils.js';
5
6
  import { LifecycleConstant } from '../lifecycle/constant.js';
6
7
  import { applyRefQueue } from '../snapshot/workletRef.js';
7
- export const gSignMap = {};
8
- export const gRecycleMap = {};
8
+ export const gSignMap = /*#__PURE__*/ cardLifetime('listSignMap', () => ({}));
9
+ export const gRecycleMap = /*#__PURE__*/ cardLifetime('listRecycleMap', () => ({}));
9
10
  const gParentWeakMap = /*#__PURE__*/ new WeakMap();
10
11
  const resolvedPromise = /* @__PURE__ */ Promise.resolve();
11
12
  export function clearListGlobal() {