@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,12 +1,13 @@
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 { clearFirstScreenMainThreadRefs, flushDelayedRunOnBackgroundFunctions, runRunOnMainThreadTask, setEomShouldFlushElementTree, updateWorkletRefInitValueChanges, } from '@lynx-js/react/worklet-runtime/bindings';
4
+ import { clearFirstScreenMainThreadRefs, flushDelayedRunOnBackgroundFunctions, runRunOnMainThreadTask, setEomShouldFlushElementTree, } from '@lynx-js/react/worklet-runtime/bindings';
5
5
  import { markTiming, setPipeline } from '../../core/performance.js';
6
6
  import { getReloadVersion } from '../../core/reload-version.js';
7
7
  import { formatElementTemplateUpdateCommands } from '../debug/alog.js';
8
8
  import { ElementTemplateLifecycleConstant } from '../protocol/lifecycle-constant.js';
9
9
  import { applyElementTemplateUpdateCommands } from '../runtime/patch.js';
10
+ import { applyPendingMainThreadRefAttachments } from '../runtime/template/main-thread-dynamic-attr-state.js';
10
11
  let listener;
11
12
  export function installElementTemplatePatchListener() {
12
13
  resetElementTemplatePatchListener();
@@ -23,73 +24,76 @@ export function installElementTemplatePatchListener() {
23
24
  });
24
25
  }
25
26
  setPipeline(pipelineOptions);
26
- markTiming('mtsRenderStart');
27
- markTiming('parseChangesStart');
28
- const payload = JSON.parse(event.data.payload);
29
- markTiming('parseChangesEnd');
30
- if (payload.mainThreadRefInitValuePatch?.length) {
31
- updateWorkletRefInitValueChanges(payload.mainThreadRefInitValuePatch);
32
- }
33
- if (typeof patchOptions.reloadVersion === 'number'
34
- && patchOptions.reloadVersion < getReloadVersion()) {
35
- markTiming('mtsRenderEnd');
36
- if (shouldProfilePatch) {
37
- lynx.performance.profileEnd();
38
- }
39
- return;
40
- }
41
- const hasOps = payload.ops.length > 0;
42
- const flushOptions = payload.flushOptions;
43
- const isHydration = payload.isHydration === true;
44
- const delayedRunOnMainThreadData = payload.delayedRunOnMainThreadData;
45
- if (hasOps) {
46
- if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
47
- console.alog?.('[ReactLynxDebug] ElementTemplate main-thread patch:\n'
48
- + JSON.stringify({
49
- ops: formatElementTemplateUpdateCommands(payload.ops),
50
- flushOptions,
51
- flowIds,
52
- }, null, 2));
27
+ try {
28
+ markTiming('mtsRenderStart');
29
+ markTiming('parseChangesStart');
30
+ const payload = JSON.parse(event.data.payload);
31
+ markTiming('parseChangesEnd');
32
+ if (typeof patchOptions.reloadVersion === 'number'
33
+ && patchOptions.reloadVersion < getReloadVersion()) {
34
+ markTiming('mtsRenderEnd');
35
+ if (shouldProfilePatch) {
36
+ lynx.performance.profileEnd();
37
+ }
38
+ return;
53
39
  }
54
- markTiming('patchChangesStart');
40
+ const hasOps = payload.ops.length > 0;
41
+ const flushOptions = payload.flushOptions;
42
+ const isHydration = payload.isHydration === true;
43
+ const delayedRunOnMainThreadData = payload.delayedRunOnMainThreadData;
55
44
  try {
56
- applyElementTemplateUpdateCommands(payload.ops, isHydration);
45
+ if (hasOps) {
46
+ if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
47
+ console.alog?.('[ReactLynxDebug] ElementTemplate main-thread patch:\n'
48
+ + JSON.stringify({
49
+ ops: formatElementTemplateUpdateCommands(payload.ops),
50
+ flushOptions,
51
+ flowIds,
52
+ }, null, 2));
53
+ }
54
+ markTiming('patchChangesStart');
55
+ try {
56
+ applyElementTemplateUpdateCommands(payload.ops, isHydration);
57
+ }
58
+ finally {
59
+ markTiming('patchChangesEnd');
60
+ markTiming('mtsRenderEnd');
61
+ }
62
+ }
63
+ else {
64
+ markTiming('mtsRenderEnd');
65
+ }
66
+ applyPendingMainThreadRefAttachments();
57
67
  }
58
68
  finally {
59
- markTiming('patchChangesEnd');
60
- markTiming('mtsRenderEnd');
61
69
  if (isHydration) {
62
70
  flushDelayedRunOnBackgroundFunctions();
63
71
  clearFirstScreenMainThreadRefs();
64
72
  }
65
73
  }
66
- }
67
- else {
68
- markTiming('mtsRenderEnd');
69
- if (isHydration) {
70
- flushDelayedRunOnBackgroundFunctions();
71
- clearFirstScreenMainThreadRefs();
72
- }
73
- }
74
- if (delayedRunOnMainThreadData?.length) {
75
- setEomShouldFlushElementTree(false);
76
- try {
77
- for (const data of delayedRunOnMainThreadData) {
78
- try {
79
- runRunOnMainThreadTask(data.worklet, data.params, data.resolveId);
80
- }
81
- catch (error) {
82
- lynx.reportError(error);
74
+ if (delayedRunOnMainThreadData?.length) {
75
+ setEomShouldFlushElementTree(false);
76
+ try {
77
+ for (const data of delayedRunOnMainThreadData) {
78
+ try {
79
+ runRunOnMainThreadTask(data.worklet, data.params, data.resolveId);
80
+ }
81
+ catch (error) {
82
+ lynx.reportError(error);
83
+ }
83
84
  }
84
85
  }
86
+ finally {
87
+ setEomShouldFlushElementTree(true);
88
+ }
85
89
  }
86
- finally {
87
- setEomShouldFlushElementTree(true);
90
+ __FlushElementTree(undefined, flushOptions);
91
+ if (shouldProfilePatch) {
92
+ lynx.performance.profileEnd();
88
93
  }
89
94
  }
90
- __FlushElementTree(undefined, flushOptions);
91
- if (shouldProfilePatch) {
92
- lynx.performance.profileEnd();
95
+ finally {
96
+ setPipeline(undefined);
93
97
  }
94
98
  };
95
99
  lynx.getJSContext().addEventListener(ElementTemplateLifecycleConstant.update, listener);
@@ -1 +1 @@
1
- {"version":3,"file":"patch-listener.js","sourceRoot":"","sources":["../../../src/element-template/native/patch-listener.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EACL,8BAA8B,EAC9B,oCAAoC,EACpC,sBAAsB,EACtB,4BAA4B,EAC5B,gCAAgC,GACjC,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,mCAAmC,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AAGrF,OAAO,EAAE,kCAAkC,EAAE,MAAM,qBAAqB,CAAC;AAEzE,IAAI,QAES,CAAC;AAEd,MAAM,UAAU,mCAAmC;IACjD,iCAAiC,EAAE,CAAC;IAEpC,QAAQ,GAAG,CAAC,KAA+C,EAAE,EAAE;QAC7D,MAAM,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC;QACpC,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,YAAY,CAAC;QAClD,MAAM,kBAAkB,GAAG,CAAC,CAAC,OAAO;eAC/B,OAAO,IAAI,CAAC,WAAW,EAAE,YAAY,KAAK,UAAU;eACpD,OAAO,IAAI,CAAC,WAAW,EAAE,UAAU,KAAK,UAAU,CAAC;QACxD,IAAI,kBAAkB,EAAE,CAAC;YACvB,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,kBAAkB,EAAE;gBAChD,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;gBAClB,OAAO;aACR,CAAC,CAAC;QACL,CAAC;QACD,WAAW,CAAC,eAAe,CAAC,CAAC;QAC7B,U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B,CACrC,gCAAgC,CAAC,MAAM,EACvC,QAAQ,CACT,CAAC;IACJ,CAAC;IACD,QAAQ,GAAG,SAAS,CAAC;AACvB,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { ClosureValueType } from '@lynx-js/react/worklet-runtime/bindings';\nimport {\n clearFirstScreenMainThreadRefs,\n flushDelayedRunOnBackgroundFunctions,\n runRunOnMainThreadTask,\n setEomShouldFlushElementTree,\n updateWorkletRefInitValueChanges,\n} from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { markTiming, setPipeline } from '../../core/performance.js';\nimport { getReloadVersion } from '../../core/reload-version.js';\nimport { formatElementTemplateUpdateCommands } from '../debug/alog.js';\nimport { ElementTemplateLifecycleConstant } from '../protocol/lifecycle-constant.js';\nimport type { ElementTemplateUpdateCommitContext } from '../protocol/types.js';\nimport type { ElementTemplateUpdateEvent } from '../protocol/update-event.js';\nimport { applyElementTemplateUpdateCommands } from '../runtime/patch.js';\n\nlet listener:\n | ((event: Pick<ElementTemplateUpdateEvent, 'data'>) => void)\n | undefined;\n\nexport function installElementTemplatePatchListener(): void {\n resetElementTemplatePatchListener();\n\n listener = (event: Pick<ElementTemplateUpdateEvent, 'data'>) => {\n const { patchOptions } = event.data;\n const { flowIds, pipelineOptions } = patchOptions;\n const shouldProfilePatch = !!flowIds\n && typeof lynx.performance?.profileStart === 'function'\n && typeof lynx.performance?.profileEnd === 'function';\n if (shouldProfilePatch) {\n lynx.performance.profileStart('ReactLynx::patch', {\n flowId: flowIds[0],\n flowIds,\n });\n }\n setPipeline(pipelineOptions);\n markTiming('mtsRenderStart');\n markTiming('parseChangesStart');\n\n const payload = JSON.parse(event.data.payload) as ElementTemplateUpdateCommitContext;\n markTiming('parseChangesEnd');\n\n if (payload.mainThreadRefInitValuePatch?.length) {\n updateWorkletRefInitValueChanges(payload.mainThreadRefInitValuePatch);\n }\n\n if (\n typeof patchOptions.reloadVersion === 'number'\n && patchOptions.reloadVersion < getReloadVersion()\n ) {\n markTiming('mtsRenderEnd');\n if (shouldProfilePatch) {\n lynx.performance.profileEnd();\n }\n return;\n }\n\n const hasOps = payload.ops.length > 0;\n const flushOptions = payload.flushOptions;\n const isHydration = payload.isHydration === true;\n const delayedRunOnMainThreadData = payload.delayedRunOnMainThreadData;\n if (hasOps) {\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] ElementTemplate main-thread patch:\\n'\n + JSON.stringify(\n {\n ops: formatElementTemplateUpdateCommands(payload.ops),\n flushOptions,\n flowIds,\n },\n null,\n 2,\n ),\n );\n }\n markTiming('patchChangesStart');\n try {\n applyElementTemplateUpdateCommands(payload.ops, isHydration);\n } finally {\n markTiming('patchChangesEnd');\n markTiming('mtsRenderEnd');\n if (isHydration) {\n flushDelayedRunOnBackgroundFunctions();\n clearFirstScreenMainThreadRefs();\n }\n }\n } else {\n markTiming('mtsRenderEnd');\n if (isHydration) {\n flushDelayedRunOnBackgroundFunctions();\n clearFirstScreenMainThreadRefs();\n }\n }\n if (delayedRunOnMainThreadData?.length) {\n setEomShouldFlushElementTree(false);\n try {\n for (const data of delayedRunOnMainThreadData) {\n try {\n runRunOnMainThreadTask(data.worklet, data.params as ClosureValueType[], data.resolveId);\n } catch (error) {\n lynx.reportError(error as Error);\n }\n }\n } finally {\n setEomShouldFlushElementTree(true);\n }\n }\n\n __FlushElementTree(undefined, flushOptions);\n\n if (shouldProfilePatch) {\n lynx.performance.profileEnd();\n }\n };\n\n lynx.getJSContext().addEventListener(\n ElementTemplateLifecycleConstant.update,\n listener,\n );\n}\n\nexport function resetElementTemplatePatchListener(): void {\n if (listener) {\n lynx.getJSContext().removeEventListener(\n ElementTemplateLifecycleConstant.update,\n listener,\n );\n }\n listener = undefined;\n}\n"]}
1
+ {"version":3,"file":"patch-listener.js","sourceRoot":"","sources":["../../../src/element-template/native/patch-listener.ts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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 {\n clearFirstScreenMainThreadRefs,\n flushDelayedRunOnBackgroundFunctions,\n runRunOnMainThreadTask,\n setEomShouldFlushElementTree,\n} from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { markTiming, setPipeline } from '../../core/performance.js';\nimport { getReloadVersion } from '../../core/reload-version.js';\nimport { formatElementTemplateUpdateCommands } from '../debug/alog.js';\nimport { ElementTemplateLifecycleConstant } from '../protocol/lifecycle-constant.js';\nimport type { ElementTemplateUpdateCommitContext } from '../protocol/types.js';\nimport type { ElementTemplateUpdateEvent } from '../protocol/update-event.js';\nimport { applyElementTemplateUpdateCommands } from '../runtime/patch.js';\nimport { applyPendingMainThreadRefAttachments } from '../runtime/template/main-thread-dynamic-attr-state.js';\n\nlet listener:\n | ((event: Pick<ElementTemplateUpdateEvent, 'data'>) => void)\n | undefined;\n\nexport function installElementTemplatePatchListener(): void {\n resetElementTemplatePatchListener();\n\n listener = (event: Pick<ElementTemplateUpdateEvent, 'data'>) => {\n const { patchOptions } = event.data;\n const { flowIds, pipelineOptions } = patchOptions;\n const shouldProfilePatch = !!flowIds\n && typeof lynx.performance?.profileStart === 'function'\n && typeof lynx.performance?.profileEnd === 'function';\n if (shouldProfilePatch) {\n lynx.performance.profileStart('ReactLynx::patch', {\n flowId: flowIds[0],\n flowIds,\n });\n }\n setPipeline(pipelineOptions);\n try {\n markTiming('mtsRenderStart');\n markTiming('parseChangesStart');\n\n const payload = JSON.parse(event.data.payload) as ElementTemplateUpdateCommitContext;\n markTiming('parseChangesEnd');\n\n if (\n typeof patchOptions.reloadVersion === 'number'\n && patchOptions.reloadVersion < getReloadVersion()\n ) {\n markTiming('mtsRenderEnd');\n if (shouldProfilePatch) {\n lynx.performance.profileEnd();\n }\n return;\n }\n\n const hasOps = payload.ops.length > 0;\n const flushOptions = payload.flushOptions;\n const isHydration = payload.isHydration === true;\n const delayedRunOnMainThreadData = payload.delayedRunOnMainThreadData;\n try {\n if (hasOps) {\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] ElementTemplate main-thread patch:\\n'\n + JSON.stringify(\n {\n ops: formatElementTemplateUpdateCommands(payload.ops),\n flushOptions,\n flowIds,\n },\n null,\n 2,\n ),\n );\n }\n markTiming('patchChangesStart');\n try {\n applyElementTemplateUpdateCommands(payload.ops, isHydration);\n } finally {\n markTiming('patchChangesEnd');\n markTiming('mtsRenderEnd');\n }\n } else {\n markTiming('mtsRenderEnd');\n }\n applyPendingMainThreadRefAttachments();\n } finally {\n if (isHydration) {\n flushDelayedRunOnBackgroundFunctions();\n clearFirstScreenMainThreadRefs();\n }\n }\n if (delayedRunOnMainThreadData?.length) {\n setEomShouldFlushElementTree(false);\n try {\n for (const data of delayedRunOnMainThreadData) {\n try {\n runRunOnMainThreadTask(data.worklet, data.params as ClosureValueType[], data.resolveId);\n } catch (error) {\n lynx.reportError(error as Error);\n }\n }\n } finally {\n setEomShouldFlushElementTree(true);\n }\n }\n\n __FlushElementTree(undefined, flushOptions);\n\n if (shouldProfilePatch) {\n lynx.performance.profileEnd();\n }\n } finally {\n setPipeline(undefined);\n }\n };\n\n lynx.getJSContext().addEventListener(\n ElementTemplateLifecycleConstant.update,\n listener,\n );\n}\n\nexport function resetElementTemplatePatchListener(): void {\n if (listener) {\n lynx.getJSContext().removeEventListener(\n ElementTemplateLifecycleConstant.update,\n listener,\n );\n }\n listener = undefined;\n}\n"]}
@@ -1 +1 @@
1
- export declare function reloadBackground(updateData: unknown): void;
1
+ export declare function reloadBackground(updateData: unknown, options?: Record<string, unknown>): void;
@@ -2,8 +2,10 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { render } from 'preact';
5
+ import { canReEvalBackgroundEntry, reEvalBackgroundEntry } from '../../core/entry-reload.js';
5
6
  import { applyUpdatePageData } from '../../core/lynx-page-data.js';
6
7
  import { increaseReloadVersion } from '../../core/reload-version.js';
8
+ import { resetElementTemplateCommitState } from '../background/commit-hook.js';
7
9
  import { destroyElementTemplateBackgroundRuntime } from '../background/destroy.js';
8
10
  import { setupBackgroundElementTemplateDocument } from '../background/document.js';
9
11
  import { installElementTemplateHydrationListener } from '../background/hydration-listener.js';
@@ -11,7 +13,16 @@ import { BackgroundPageRootInstance } from '../background/instance.js';
11
13
  import { profileEnd, profileStart } from '../debug/profile.js';
12
14
  import { resetEventStateForRuntime } from '../prop-adapters/event.js';
13
15
  import { __root, setRoot } from '../runtime/page/root-instance.js';
14
- export function reloadBackground(updateData) {
16
+ export function reloadBackground(updateData, options) {
17
+ if (canReEvalBackgroundEntry()) {
18
+ reEvalBackgroundEntry(updateData, options, () => {
19
+ // The unmount of the old tree must not reach the new entry.
20
+ resetElementTemplateCommitState();
21
+ // A queued `updateGlobalProps` callback must not render it again.
22
+ __root.__jsx = undefined;
23
+ });
24
+ return;
25
+ }
15
26
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
16
27
  profileStart('ReactLynx::reloadBackground');
17
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"reload-background.js","sourceRoot":"","sources":["../../../src/element-template/native/reload-background.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,uCAAuC,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,sCAAsC,EAAE,MAAM,2BAA2B,CAAC;AACnF,OAAO,EAAE,uCAAuC,EAAE,MAAM,qCAAqC,CAAC;AAC9F,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAEnE,MAAM,UAAU,gBAAgB,CAAC,UAAmB;IAClD,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,6BAA6B,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC;QACzB,uCAAuC,EAAE,CAAC;QAC1C,qBAAqB,EAAE,CAAC;QACxB,2EAA2E;QAC3E,6CAA6C;QAC7C,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACrD,mBAAmB,CAAC,UAAU,CAAC,CAAC;QAEhC,OAAO,CAAC,IAAI,0BAA0B,EAAE,CAAC,CAAC;QAC1C,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC;QACnB,sCAAsC,EAAE,CAAC;QACzC,uCAAuC,EAAE,CAAC;QAC1C,yBAAyB,EAAE,CAAC;QAC5B,MAAM,CAAC,GAAqB,EAAE,MAAkC,CAAC,CAAC;IACpE,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { ComponentChild, ContainerNode } from 'preact';\nimport { render } from 'preact';\n\nimport { applyUpdatePageData } from '../../core/lynx-page-data.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { destroyElementTemplateBackgroundRuntime } from '../background/destroy.js';\nimport { setupBackgroundElementTemplateDocument } from '../background/document.js';\nimport { installElementTemplateHydrationListener } from '../background/hydration-listener.js';\nimport { BackgroundPageRootInstance } from '../background/instance.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { resetEventStateForRuntime } from '../prop-adapters/event.js';\nimport { __root, setRoot } from '../runtime/page/root-instance.js';\n\nexport function reloadBackground(updateData: unknown): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadBackground');\n }\n\n try {\n const jsx = __root.__jsx;\n destroyElementTemplateBackgroundRuntime();\n increaseReloadVersion();\n // Reload creates a new object so InitData Provider / Consumer observers do\n // not retain the pre-reload object identity.\n lynx.__initData = Object.assign({}, lynx.__initData);\n applyUpdatePageData(updateData);\n\n setRoot(new BackgroundPageRootInstance());\n __root.__jsx = jsx;\n setupBackgroundElementTemplateDocument();\n installElementTemplateHydrationListener();\n resetEventStateForRuntime();\n render(jsx as ComponentChild, __root as unknown as ContainerNode);\n } finally {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"reload-background.js","sourceRoot":"","sources":["../../../src/element-template/native/reload-background.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAC7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAAE,uCAAuC,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,sCAAsC,EAAE,MAAM,2BAA2B,CAAC;AACnF,OAAO,EAAE,u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,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { ComponentChild, ContainerNode } from 'preact';\nimport { render } from 'preact';\n\nimport { canReEvalBackgroundEntry, reEvalBackgroundEntry } from '../../core/entry-reload.js';\nimport { applyUpdatePageData } from '../../core/lynx-page-data.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { resetElementTemplateCommitState } from '../background/commit-hook.js';\nimport { destroyElementTemplateBackgroundRuntime } from '../background/destroy.js';\nimport { setupBackgroundElementTemplateDocument } from '../background/document.js';\nimport { installElementTemplateHydrationListener } from '../background/hydration-listener.js';\nimport { BackgroundPageRootInstance } from '../background/instance.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { resetEventStateForRuntime } from '../prop-adapters/event.js';\nimport { __root, setRoot } from '../runtime/page/root-instance.js';\n\nexport function reloadBackground(updateData: unknown, options?: Record<string, unknown>): void {\n if (canReEvalBackgroundEntry()) {\n reEvalBackgroundEntry(updateData as Record<string, unknown>, options, () => {\n // The unmount of the old tree must not reach the new entry.\n resetElementTemplateCommitState();\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 try {\n const jsx = __root.__jsx;\n destroyElementTemplateBackgroundRuntime();\n increaseReloadVersion();\n // Reload creates a new object so InitData Provider / Consumer observers do\n // not retain the pre-reload object identity.\n lynx.__initData = Object.assign({}, lynx.__initData);\n applyUpdatePageData(updateData);\n\n setRoot(new BackgroundPageRootInstance());\n __root.__jsx = jsx;\n setupBackgroundElementTemplateDocument();\n installElementTemplateHydrationListener();\n resetEventStateForRuntime();\n render(jsx as ComponentChild, __root as unknown as ContainerNode);\n } finally {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n"]}
@@ -1 +1,7 @@
1
1
  export declare function reloadMainThread(data: unknown, options: UpdatePageOption): void;
2
+ interface MainThreadReloadHandoff {
3
+ page: ElementTemplateHandle;
4
+ options: UpdatePageOption;
5
+ }
6
+ export declare function completeMainThreadReload({ page, options }: MainThreadReloadHandoff): void;
7
+ export {};
@@ -1,12 +1,15 @@
1
1
  // Copyright 2026 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
+ import { flushElementTemplate } from './flush.js';
5
+ import { onMtsDestruction } from './mts-destroy.js';
6
+ import { canReEvalMainThreadEntry, installMainThreadReloadCompleter, reEvalMainThreadEntry, } from '../../core/entry-reload.js';
4
7
  import { applyUpdatePageData } from '../../core/lynx-page-data.js';
5
8
  import { increaseReloadVersion } from '../../core/reload-version.js';
6
9
  import { profileEnd, profileStart } from '../debug/profile.js';
7
10
  import { ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../protocol/page.js';
8
11
  import { destroyAllElementTemplateListStates } from '../runtime/list/list.js';
9
- import { __page } from '../runtime/page/page.js';
12
+ import { __page, setupPage } from '../runtime/page/page.js';
10
13
  import { __root, setRoot } from '../runtime/page/root-instance.js';
11
14
  import { renderMainThread } from '../runtime/render/render-main-thread.js';
12
15
  import { resetTemplateId } from '../runtime/template/handle.js';
@@ -18,7 +21,6 @@ export function reloadMainThread(data, options) {
18
21
  profileStart('ReactLynx::reloadMainThread');
19
22
  }
20
23
  try {
21
- increaseReloadVersion();
22
24
  applyUpdatePageData(data, options);
23
25
  destroyAllElementTemplateListStates();
24
26
  // TODO: Replace this cleanup-only serialization with a direct page-children
@@ -34,14 +36,23 @@ export function reloadMainThread(data, options) {
34
36
  }
35
37
  deleteMainThreadDynamicAttrStateForSubtree(removedHandleIds);
36
38
  }
39
+ if (canReEvalMainThreadEntry()) {
40
+ onMtsDestruction();
41
+ increaseReloadVersion();
42
+ reEvalMainThreadEntry({ page: __page, options });
43
+ return;
44
+ }
37
45
  elementTemplateRegistry.clear();
38
46
  clearMainThreadDynamicAttrState();
39
47
  resetElementTemplateMainThreadBackgroundFunctionRuntime();
40
48
  resetTemplateId();
49
+ // Ref cleanup still belongs to the old page. Advance only before rendering
50
+ // the new tree so calls queued by old ref/unmount callbacks remain stale.
51
+ increaseReloadVersion();
41
52
  const oldRoot = __root;
42
53
  setRoot({ __jsx: oldRoot.__jsx });
43
54
  renderMainThread();
44
- __FlushElementTree(undefined, options);
55
+ flushElementTemplate(options);
45
56
  }
46
57
  finally {
47
58
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
@@ -49,6 +60,12 @@ export function reloadMainThread(data, options) {
49
60
  }
50
61
  }
51
62
  }
63
+ export function completeMainThreadReload({ page, options }) {
64
+ setupPage(page);
65
+ renderMainThread();
66
+ __FlushElementTree(undefined, options);
67
+ }
68
+ installMainThreadReloadCompleter(completeMainThreadReload);
52
69
  function collectSerializedSubtreeHandleIds(node, handleIds) {
53
70
  handleIds.push(node.uid);
54
71
  for (const slot of node.childSlots ?? []) {
@@ -1 +1 @@
1
- {"version":3,"file":"reload-main-thread.js","sourceRoot":"","sources":["../../../src/element-template/native/reload-main-thread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,qCAAqC,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD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,CAAC,KAAK,EAAE,CAAC;QAChC,+BAA+B,EAAE,CAAC;QAClC,uDAAuD,EAAE,CAAC;QAC1D,eAAe,EAAE,CAAC;QAElB,MAAM,OAAO,GAAG,MAAM,CAAC;QACvB,OAAO,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QAClC,gBAAgB,EAAE,CAAC;QAEnB,kBAAkB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,iCAAiC,CACxC,IAAsB,EACtB,SAAmB;IAEnB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAa,CAAC,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QACzC,KAAK,MAAM,KAAK,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC;YAC/B,iCAAiC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IACD,MAAM,YAAY,GAAI,IAA4D,CAAC,OAAO,EAAE,YAAY,CAAC;IACzG,KAAK,MAAM,KAAK,IAAI,YAAY,IAAI,EAAE,EAAE,CAAC;QACvC,iCAAiC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { applyUpdatePageData } from '../../core/lynx-page-data.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../protocol/page.js';\nimport type { SerializedEtNode, SerializedPageRoot } from '../protocol/types.js';\nimport { destroyAllElementTemplateListStates } from '../runtime/list/list.js';\nimport { __page } from '../runtime/page/page.js';\nimport { __root, setRoot } from '../runtime/page/root-instance.js';\nimport { renderMainThread } from '../runtime/render/render-main-thread.js';\nimport { resetTemplateId } from '../runtime/template/handle.js';\nimport { resetElementTemplateMainThreadBackgroundFunctionRuntime } from '../runtime/template/main-thread-background-function.js';\nimport {\n clearMainThreadDynamicAttrState,\n deleteMainThreadDynamicAttrStateForSubtree,\n} from '../runtime/template/main-thread-dynamic-attr-state.js';\nimport { elementTemplateRegistry } from '../runtime/template/registry.js';\n\nexport function reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n try {\n increaseReloadVersion();\n applyUpdatePageData(data, options);\n\n destroyAllElementTemplateListStates();\n // TODO: Replace this cleanup-only serialization with a direct page-children\n // or clear-slot PAPI once native exposes one.\n const page = __SerializeElementTemplate(__page) as SerializedPageRoot;\n for (const root of page.childSlots?.[ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX] ?? []) {\n const rootRef = elementTemplateRegistry.get(root.uid)!;\n __RemoveNodeFromElementTemplate(__page, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX, rootRef);\n const removedHandleIds: number[] = [];\n collectSerializedSubtreeHandleIds(root, removedHandleIds);\n for (const handleId of removedHandleIds) {\n elementTemplateRegistry.delete(handleId);\n }\n deleteMainThreadDynamicAttrStateForSubtree(removedHandleIds);\n }\n elementTemplateRegistry.clear();\n clearMainThreadDynamicAttrState();\n resetElementTemplateMainThreadBackgroundFunctionRuntime();\n resetTemplateId();\n\n const oldRoot = __root;\n setRoot({ __jsx: oldRoot.__jsx });\n renderMainThread();\n\n __FlushElementTree(undefined, options);\n } finally {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n\nfunction collectSerializedSubtreeHandleIds(\n node: SerializedEtNode,\n handleIds: number[],\n): void {\n handleIds.push(node.uid as number);\n for (const slot of node.childSlots ?? []) {\n for (const child of slot ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n }\n const listChildren = (node as { options?: { listChildren?: SerializedEtNode[] } }).options?.listChildren;\n for (const child of listChildren ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n}\n"]}
1
+ {"version":3,"file":"reload-main-thread.js","sourceRoot":"","sources":["../../../src/element-template/native/reload-main-thread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,wBAAwB,EACxB,gCAAgC,EAChC,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,qCAAqC,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,uDAAuD,EAAE,MAAM,wDAAwD,CAAC;AACjI,OAAO,EACL,+BAA+B,EAC/B,0CAA0C,GAC3C,MAAM,uDAAuD,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,i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;QAExB,MAAM,OAAO,GAAG,MAAM,CAAC;QACvB,OAAO,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QAClC,gBAAgB,EAAE,CAAC;QAEnB,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;AACH,CAAC;AAOD,MAAM,UAAU,wBAAwB,CAAC,EAAE,IAAI,EAAE,OAAO,EAA2B;IACjF,SAAS,CAAC,IAAI,CAAC,CAAC;IAChB,gBAAgB,EAAE,CAAC;IACnB,kBAAkB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAED,gCAAgC,CAAC,wBAAwB,CAAC,CAAC;AAE3D,SAAS,iCAAiC,CACxC,IAAsB,EACtB,SAAmB;IAEnB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAa,CAAC,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QACzC,KAAK,MAAM,KAAK,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC;YAC/B,iCAAiC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IACD,MAAM,YAAY,GAAI,IAA4D,CAAC,OAAO,EAAE,YAAY,CAAC;IACzG,KAAK,MAAM,KAAK,IAAI,YAAY,IAAI,EAAE,EAAE,CAAC;QACvC,iCAAiC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { flushElementTemplate } from './flush.js';\nimport { onMtsDestruction } from './mts-destroy.js';\nimport {\n canReEvalMainThreadEntry,\n installMainThreadReloadCompleter,\n reEvalMainThreadEntry,\n} from '../../core/entry-reload.js';\nimport { applyUpdatePageData } from '../../core/lynx-page-data.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../protocol/page.js';\nimport type { SerializedEtNode, SerializedPageRoot } from '../protocol/types.js';\nimport { destroyAllElementTemplateListStates } from '../runtime/list/list.js';\nimport { __page, setupPage } from '../runtime/page/page.js';\nimport { __root, setRoot } from '../runtime/page/root-instance.js';\nimport { renderMainThread } from '../runtime/render/render-main-thread.js';\nimport { resetTemplateId } from '../runtime/template/handle.js';\nimport { resetElementTemplateMainThreadBackgroundFunctionRuntime } from '../runtime/template/main-thread-background-function.js';\nimport {\n clearMainThreadDynamicAttrState,\n deleteMainThreadDynamicAttrStateForSubtree,\n} from '../runtime/template/main-thread-dynamic-attr-state.js';\nimport { elementTemplateRegistry } from '../runtime/template/registry.js';\n\nexport function reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n try {\n applyUpdatePageData(data, options);\n\n destroyAllElementTemplateListStates();\n // TODO: Replace this cleanup-only serialization with a direct page-children\n // or clear-slot PAPI once native exposes one.\n const page = __SerializeElementTemplate(__page) as SerializedPageRoot;\n for (const root of page.childSlots?.[ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX] ?? []) {\n const rootRef = elementTemplateRegistry.get(root.uid)!;\n __RemoveNodeFromElementTemplate(__page, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX, rootRef);\n const removedHandleIds: number[] = [];\n collectSerializedSubtreeHandleIds(root, removedHandleIds);\n for (const handleId of removedHandleIds) {\n elementTemplateRegistry.delete(handleId);\n }\n deleteMainThreadDynamicAttrStateForSubtree(removedHandleIds);\n }\n if (canReEvalMainThreadEntry()) {\n onMtsDestruction();\n increaseReloadVersion();\n reEvalMainThreadEntry<MainThreadReloadHandoff>({ page: __page, options });\n return;\n }\n elementTemplateRegistry.clear();\n clearMainThreadDynamicAttrState();\n resetElementTemplateMainThreadBackgroundFunctionRuntime();\n resetTemplateId();\n\n // Ref cleanup still belongs to the old page. Advance only before rendering\n // the new tree so calls queued by old ref/unmount callbacks remain stale.\n increaseReloadVersion();\n\n const oldRoot = __root;\n setRoot({ __jsx: oldRoot.__jsx });\n renderMainThread();\n\n flushElementTemplate(options);\n } finally {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n\ninterface MainThreadReloadHandoff {\n page: ElementTemplateHandle;\n options: UpdatePageOption;\n}\n\nexport function completeMainThreadReload({ page, options }: MainThreadReloadHandoff): void {\n setupPage(page);\n renderMainThread();\n __FlushElementTree(undefined, options);\n}\n\ninstallMainThreadReloadCompleter(completeMainThreadReload);\n\nfunction collectSerializedSubtreeHandleIds(\n node: SerializedEtNode,\n handleIds: number[],\n): void {\n handleIds.push(node.uid as number);\n for (const slot of node.childSlots ?? []) {\n for (const child of slot ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n }\n const listChildren = (node as { options?: { listChildren?: SerializedEtNode[] } }).options?.listChildren;\n for (const child of listChildren ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  export declare const enum ElementTemplateLifecycleConstant {
2
2
  hydrate = "rLynxElementTemplateHydrate",
3
- update = "rLynxElementTemplateUpdate"
3
+ update = "rLynxElementTemplateUpdate",
4
+ updateMTRefInitValue = "rLynxElementTemplateRefInitValue"
4
5
  }
@@ -5,5 +5,6 @@ export var ElementTemplateLifecycleConstant;
5
5
  (function (ElementTemplateLifecycleConstant) {
6
6
  ElementTemplateLifecycleConstant["hydrate"] = "rLynxElementTemplateHydrate";
7
7
  ElementTemplateLifecycleConstant["update"] = "rLynxElementTemplateUpdate";
8
+ ElementTemplateLifecycleConstant["updateMTRefInitValue"] = "rLynxElementTemplateRefInitValue";
8
9
  })(ElementTemplateLifecycleConstant || (ElementTemplateLifecycleConstant = {}));
9
10
  //# sourceMappingURL=lifecycle-constant.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle-constant.js","sourceRoot":"","sources":["../../../src/element-template/protocol/lifecycle-constant.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAN,IAAkB,gCAGjB;AAHD,WAAkB,gCAAgC;IAChD,2EAAuC,CAAA;IACvC,yEAAqC,CAAA;AACvC,CAAC,EAHiB,gCAAgC,KAAhC,gCAAgC,QAGjD","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nexport const enum ElementTemplateLifecycleConstant {\n hydrate = 'rLynxElementTemplateHydrate',\n update = 'rLynxElementTemplateUpdate',\n}\n"]}
1
+ {"version":3,"file":"lifecycle-constant.js","sourceRoot":"","sources":["../../../src/element-template/protocol/lifecycle-constant.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAN,IAAkB,gCAIjB;AAJD,WAAkB,gCAAgC;IAChD,2EAAuC,CAAA;IACvC,yEAAqC,CAAA;IACrC,6FAAyD,CAAA;AAC3D,CAAC,EAJiB,gCAAgC,KAAhC,gCAAgC,QAIjD","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nexport const enum ElementTemplateLifecycleConstant {\n hydrate = 'rLynxElementTemplateHydrate',\n update = 'rLynxElementTemplateUpdate',\n updateMTRefInitValue = 'rLynxElementTemplateRefInitValue',\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  import type { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';
2
2
  import { ElementTemplateUpdateOps } from './opcodes.js';
3
3
  import { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_TYPE } from './page.js';
4
- import type { MainThreadRefInitValuePatch } from '../../worklet-runtime/bindings/types.js';
5
4
  export type SerializableValue = string | number | boolean | null | SerializableValue[] | {
6
5
  [key: string]: SerializableValue;
7
6
  };
@@ -146,5 +145,4 @@ export interface ElementTemplateUpdateCommitContext {
146
145
  isHydration?: boolean | undefined;
147
146
  reloadVersion?: number | undefined;
148
147
  delayedRunOnMainThreadData?: RunWorkletCtxData[] | undefined;
149
- mainThreadRefInitValuePatch?: MainThreadRefInitValuePatch | undefined;
150
148
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/element-template/protocol/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,MAAM,WAAW,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 { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { ElementTemplateUpdateOps } from './opcodes.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_TYPE } from './page.js';\nimport type { MainThreadRefInitValuePatch } from '../../worklet-runtime/bindings/types.js';\n\nexport type SerializableValue =\n | string\n | number\n | boolean\n | null\n | SerializableValue[]\n | { [key: string]: SerializableValue };\n\nexport type RuntimeOptionValue =\n | SerializableValue\n | FiberElement\n | RuntimeOptionValue[]\n | { [key: string]: RuntimeOptionValue };\n\nexport type RuntimeOptions = Record<string, RuntimeOptionValue>;\n\nexport type RuntimeAttributeSlotValue =\n | SerializableValue\n | ((...args: unknown[]) => unknown)\n | RuntimeAttributeSlotValue[]\n | { [key: string]: RuntimeAttributeSlotValue };\n\nexport type RuntimeTypedElementAttributes = Record<string, RuntimeAttributeSlotValue>;\n\nexport type TypedElementAttributesCommand = Record<string, SerializableValue>;\n\nexport type RuntimeChildSlots = Array<ElementTemplateHandle[] | null | undefined>;\n\nexport type ElementTemplateHandleSlotsCommand = Array<number[] | null | undefined>;\n\nexport type SerializedEtNodeChildSlots = Array<SerializedEtNode[] | null | undefined>;\n\nexport interface ElementTemplateHandleRefCommandValue {\n __etHandleRef: number;\n [key: string]: SerializableValue;\n}\n\nexport interface UpdateTypedListItemCommand extends ElementTemplateHandleRefCommandValue {\n type: string;\n platformInfo: Record<string, SerializableValue>;\n subtreeHandleIds: number[];\n}\n\nexport type RuntimeOptionsCommand = Record<string, SerializableValue>;\n\n// Deferred typed-list create carries logical item records here. Its future\n// main-thread consumer resolves these refs into the list-specific runtime carrier.\nexport interface TypedListOptionsCommand extends RuntimeOptionsCommand {\n listChildren: UpdateTypedListItemCommand[];\n}\n\nexport interface RuntimeTypedListOptions {\n listChildren: ElementTemplateHandle[];\n}\n\nexport type SerializedRuntimeOptions = Record<string, SerializableValue>;\n\nexport interface SerializedTypedListOptions {\n listChildren: SerializedEtNode[];\n}\n\nexport interface SerializedEtNodeBase {\n attributeSlots?: SerializableValue[] | null;\n childSlots?: SerializedEtNodeChildSlots | null;\n uid: number;\n options?: SerializedRuntimeOptions | null;\n}\n\nexport interface SerializedCompiledNode extends SerializedEtNodeBase {\n templateKey: string;\n bundleUrl?: string;\n attributeSlots?: SerializableValue[] | null;\n}\n\nexport interface SerializedTypedNode extends SerializedEtNodeBase {\n // Native __SerializeElementTemplate returns typed hosts as { tag, attributes }.\n tag: string;\n attributes?: TypedElementAttributesCommand | null;\n}\n\nexport interface SerializedTypedListNode extends Omit<SerializedEtNodeBase, 'options'> {\n tag: 'list';\n attributes?: TypedElementAttributesCommand | null;\n options?: SerializedTypedListOptions | null;\n}\n\nexport type SerializedEtNode = SerializedCompiledNode | SerializedTypedNode | SerializedTypedListNode;\n\nexport interface SerializedPageRoot extends SerializedTypedNode {\n tag: typeof ELEMENT_TEMPLATE_PAGE_TYPE;\n uid: typeof ELEMENT_TEMPLATE_PAGE_HANDLE_ID;\n}\n\nexport interface ElementTemplateHydrateCommitContext {\n page: SerializedPageRoot;\n reloadVersion: number;\n}\n\nexport type CreateTemplateCommand = [\n typeof ElementTemplateUpdateOps.createTemplate,\n handleId: number,\n templateKey: string,\n bundleUrl: string | null | undefined,\n attributeSlots: SerializableValue[] | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n];\n\nexport type SetAttributeCommand = [\n typeof ElementTemplateUpdateOps.setAttribute,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadEventCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadEvent,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadRefCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadRef,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type InsertNodeCommand = [\n typeof ElementTemplateUpdateOps.insertNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n referenceHandleId: number,\n attachedSubtreeHandleIds: number[] | null,\n];\n\nexport type RemoveNodeCommand = [\n typeof ElementTemplateUpdateOps.removeNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type CreateTypedElementCommand = [\n typeof ElementTemplateUpdateOps.createTypedElement,\n handleId: number,\n type: string,\n attributes: TypedElementAttributesCommand | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n options: RuntimeOptionsCommand | TypedListOptionsCommand | null | undefined,\n];\n\nexport type InsertTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.insertTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n beforeHandleId: number,\n];\n\nexport type RemoveTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.removeTypedListItem,\n listHandleId: number,\n itemHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type UpdateTypedListItemInfoCommand = [\n typeof ElementTemplateUpdateOps.updateTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n];\n\nexport type ElementTemplateUpdateCommand =\n | CreateTemplateCommand\n | SetAttributeCommand\n | SetMainThreadEventCommand\n | SetMainThreadRefCommand\n | InsertNodeCommand\n | RemoveNodeCommand\n | CreateTypedElementCommand\n | InsertTypedListItemCommand\n | RemoveTypedListItemCommand\n | UpdateTypedListItemInfoCommand;\n\n// Commands are transported as a flat stream to match the native update payload.\n// Tuple aliases above define each opcode's shape; this item union preserves the\n// existing flat buffer ergonomics while making command contracts explicit.\nexport type ElementTemplateUpdateCommandStream = ElementTemplateUpdateCommand[number][];\n\nexport interface ElementTemplateFlushOptions {\n // triggerLayout?: boolean;\n // operationID?: any;\n // __lynx_timing_flag?: string;\n // nativeUpdateDataOrder?: number;\n // elementID?: number;\n // listID?: number;\n // listReuseNotification?: {\n // listElement: FiberElement;\n // itemKey: string;\n // };\n pipelineOptions?: PipelineOptions;\n // elementIDs?: number[];\n // operationIDs?: any[];\n // asyncFlush?: boolean;\n triggerDataUpdated?: boolean;\n emptyPatch?: boolean;\n}\n\nexport interface ElementTemplateUpdateCommitContext {\n ops: ElementTemplateUpdateCommandStream;\n flushOptions: ElementTemplateFlushOptions;\n flowIds?: number[] | undefined;\n isHydration?: boolean | undefined;\n reloadVersion?: number | undefined;\n delayedRunOnMainThreadData?: RunWorkletCtxData[] | undefined;\n mainThreadRefInitValuePatch?: MainThreadRefInitValuePatch | undefined;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/element-template/protocol/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,MAAM,WAAW,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 { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { ElementTemplateUpdateOps } from './opcodes.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_TYPE } from './page.js';\n\nexport type SerializableValue =\n | string\n | number\n | boolean\n | null\n | SerializableValue[]\n | { [key: string]: SerializableValue };\n\nexport type RuntimeOptionValue =\n | SerializableValue\n | FiberElement\n | RuntimeOptionValue[]\n | { [key: string]: RuntimeOptionValue };\n\nexport type RuntimeOptions = Record<string, RuntimeOptionValue>;\n\nexport type RuntimeAttributeSlotValue =\n | SerializableValue\n | ((...args: unknown[]) => unknown)\n | RuntimeAttributeSlotValue[]\n | { [key: string]: RuntimeAttributeSlotValue };\n\nexport type RuntimeTypedElementAttributes = Record<string, RuntimeAttributeSlotValue>;\n\nexport type TypedElementAttributesCommand = Record<string, SerializableValue>;\n\nexport type RuntimeChildSlots = Array<ElementTemplateHandle[] | null | undefined>;\n\nexport type ElementTemplateHandleSlotsCommand = Array<number[] | null | undefined>;\n\nexport type SerializedEtNodeChildSlots = Array<SerializedEtNode[] | null | undefined>;\n\nexport interface ElementTemplateHandleRefCommandValue {\n __etHandleRef: number;\n [key: string]: SerializableValue;\n}\n\nexport interface UpdateTypedListItemCommand extends ElementTemplateHandleRefCommandValue {\n type: string;\n platformInfo: Record<string, SerializableValue>;\n subtreeHandleIds: number[];\n}\n\nexport type RuntimeOptionsCommand = Record<string, SerializableValue>;\n\n// Deferred typed-list create carries logical item records here. Its future\n// main-thread consumer resolves these refs into the list-specific runtime carrier.\nexport interface TypedListOptionsCommand extends RuntimeOptionsCommand {\n listChildren: UpdateTypedListItemCommand[];\n}\n\nexport interface RuntimeTypedListOptions {\n listChildren: ElementTemplateHandle[];\n}\n\nexport type SerializedRuntimeOptions = Record<string, SerializableValue>;\n\nexport interface SerializedTypedListOptions {\n listChildren: SerializedEtNode[];\n}\n\nexport interface SerializedEtNodeBase {\n attributeSlots?: SerializableValue[] | null;\n childSlots?: SerializedEtNodeChildSlots | null;\n uid: number;\n options?: SerializedRuntimeOptions | null;\n}\n\nexport interface SerializedCompiledNode extends SerializedEtNodeBase {\n templateKey: string;\n bundleUrl?: string;\n attributeSlots?: SerializableValue[] | null;\n}\n\nexport interface SerializedTypedNode extends SerializedEtNodeBase {\n // Native __SerializeElementTemplate returns typed hosts as { tag, attributes }.\n tag: string;\n attributes?: TypedElementAttributesCommand | null;\n}\n\nexport interface SerializedTypedListNode extends Omit<SerializedEtNodeBase, 'options'> {\n tag: 'list';\n attributes?: TypedElementAttributesCommand | null;\n options?: SerializedTypedListOptions | null;\n}\n\nexport type SerializedEtNode = SerializedCompiledNode | SerializedTypedNode | SerializedTypedListNode;\n\nexport interface SerializedPageRoot extends SerializedTypedNode {\n tag: typeof ELEMENT_TEMPLATE_PAGE_TYPE;\n uid: typeof ELEMENT_TEMPLATE_PAGE_HANDLE_ID;\n}\n\nexport interface ElementTemplateHydrateCommitContext {\n page: SerializedPageRoot;\n reloadVersion: number;\n}\n\nexport type CreateTemplateCommand = [\n typeof ElementTemplateUpdateOps.createTemplate,\n handleId: number,\n templateKey: string,\n bundleUrl: string | null | undefined,\n attributeSlots: SerializableValue[] | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n];\n\nexport type SetAttributeCommand = [\n typeof ElementTemplateUpdateOps.setAttribute,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadEventCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadEvent,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadRefCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadRef,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type InsertNodeCommand = [\n typeof ElementTemplateUpdateOps.insertNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n referenceHandleId: number,\n attachedSubtreeHandleIds: number[] | null,\n];\n\nexport type RemoveNodeCommand = [\n typeof ElementTemplateUpdateOps.removeNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type CreateTypedElementCommand = [\n typeof ElementTemplateUpdateOps.createTypedElement,\n handleId: number,\n type: string,\n attributes: TypedElementAttributesCommand | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n options: RuntimeOptionsCommand | TypedListOptionsCommand | null | undefined,\n];\n\nexport type InsertTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.insertTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n beforeHandleId: number,\n];\n\nexport type RemoveTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.removeTypedListItem,\n listHandleId: number,\n itemHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type UpdateTypedListItemInfoCommand = [\n typeof ElementTemplateUpdateOps.updateTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n];\n\nexport type ElementTemplateUpdateCommand =\n | CreateTemplateCommand\n | SetAttributeCommand\n | SetMainThreadEventCommand\n | SetMainThreadRefCommand\n | InsertNodeCommand\n | RemoveNodeCommand\n | CreateTypedElementCommand\n | InsertTypedListItemCommand\n | RemoveTypedListItemCommand\n | UpdateTypedListItemInfoCommand;\n\n// Commands are transported as a flat stream to match the native update payload.\n// Tuple aliases above define each opcode's shape; this item union preserves the\n// existing flat buffer ergonomics while making command contracts explicit.\nexport type ElementTemplateUpdateCommandStream = ElementTemplateUpdateCommand[number][];\n\nexport interface ElementTemplateFlushOptions {\n pipelineOptions?: PipelineOptions;\n triggerDataUpdated?: boolean;\n emptyPatch?: boolean;\n}\n\nexport interface ElementTemplateUpdateCommitContext {\n ops: ElementTemplateUpdateCommandStream;\n flushOptions: ElementTemplateFlushOptions;\n flowIds?: number[] | undefined;\n isHydration?: boolean | undefined;\n reloadVersion?: number | undefined;\n delayedRunOnMainThreadData?: RunWorkletCtxData[] | undefined;\n}\n"]}
@@ -3,7 +3,6 @@
3
3
  */
4
4
  declare let __root: {
5
5
  __jsx?: React.ReactNode;
6
- __opcodes?: any[];
7
6
  nodeType?: Element['nodeType'];
8
7
  };
9
8
  declare function setRoot(root: typeof __root): void;
@@ -1 +1 @@
1
- {"version":3,"file":"root-instance.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/page/root-instance.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;GAEG;AACH,IAAI,MAIH,CAAC;AAEF,SAAS,OAAO,CAAC,IAAmB;IAClC,MAAM,GAAG,IAAI,CAAC;IAEd,kDAAkD;IAClD,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACtB,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,OAAO,CAAC,EAAE,CAAC,CAAC;AAEZ,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Element Template-only root for renderPage.\n */\nlet __root: {\n __jsx?: React.ReactNode;\n __opcodes?: any[];\n nodeType?: Element['nodeType'];\n};\n\nfunction setRoot(root: typeof __root): void {\n __root = root;\n\n // A fake ELEMENT_NODE to make preact/debug happy.\n if (__DEV__ && __root) {\n __root.nodeType = 1;\n }\n}\n\nsetRoot({});\n\nexport { __root, setRoot };\n"]}
1
+ {"version":3,"file":"root-instance.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/page/root-instance.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;GAEG;AACH,IAAI,MAGH,CAAC;AAEF,SAAS,OAAO,CAAC,IAAmB;IAClC,MAAM,GAAG,IAAI,CAAC;IAEd,kDAAkD;IAClD,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACtB,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,OAAO,CAAC,EAAE,CAAC,CAAC;AAEZ,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Element Template-only root for renderPage.\n */\nlet __root: {\n __jsx?: React.ReactNode;\n nodeType?: Element['nodeType'];\n};\n\nfunction setRoot(root: typeof __root): void {\n __root = root;\n\n // A fake ELEMENT_NODE to make preact/debug happy.\n if (__DEV__ && __root) {\n __root.nodeType = 1;\n }\n}\n\nsetRoot({});\n\nexport { __root, setRoot };\n"]}
@@ -3,6 +3,7 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { composeElementTemplateListAttributes, createElementTemplateListStateFromItems, flushInitialElementTemplateListUpdates, flushPendingElementTemplateListUpdates, insertElementTemplateListItem, markElementTemplateListDestroyed, registerElementTemplateListState, removeElementTemplateListItem, updateElementTemplateListAttributes, updateElementTemplateListItem, } from './list/list.js';
5
5
  import { insertElementTemplateSubtree } from './template/handle.js';
6
+ import { retainMainThreadBackgroundFunctionCtx } from './template/main-thread-background-function.js';
6
7
  import { elementTemplateRegistry } from './template/registry.js';
7
8
  import { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from './template/typed-attributes.js';
8
9
  import { ElementTemplateUpdateOps } from '../protocol/opcodes.js';
@@ -68,6 +69,9 @@ export function applyElementTemplateUpdateCommands(stream, isHydration = false)
68
69
  if (!nativeRef) {
69
70
  continue;
70
71
  }
72
+ if (value != null) {
73
+ retainMainThreadBackgroundFunctionCtx(value.value);
74
+ }
71
75
  __SetAttributeOfElementTemplate(nativeRef, attrSlotIndex, value);
72
76
  updateMainThreadEventAttrSlot(targetId, attrSlotIndex, value, isHydration);
73
77
  break;