@lynx-js/react 0.129.0 → 0.129.2

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 (282) hide show
  1. package/CHANGELOG.md +24 -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/globalProps.test.ts +27 -6
  6. package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
  7. package/runtime/__test__/element-template/fixtures/gesture/direct/index.tsx +33 -0
  8. package/runtime/__test__/element-template/fixtures/spread/mts/index.tsx +197 -0
  9. package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
  10. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
  11. package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +89 -3
  12. package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
  13. package/runtime/__test__/element-template/native/mts-destroy.test.ts +88 -0
  14. package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +3 -0
  15. package/runtime/__test__/element-template/native/reload.test.ts +118 -2
  16. package/runtime/__test__/element-template/runtime/background/global-props/compiled-fixtures.test.tsx +5 -5
  17. package/runtime/__test__/element-template/runtime/background/global-props.test.tsx +1 -1
  18. package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +70 -0
  19. package/runtime/__test__/element-template/runtime/background/ref/compiled-fixtures.test.tsx +3 -4
  20. package/runtime/__test__/element-template/runtime/background/reload.test.ts +74 -0
  21. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
  22. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +212 -7
  23. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
  24. package/runtime/__test__/element-template/runtime/prop-adapters/gesture-compiled.test.ts +200 -0
  25. package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +420 -0
  26. package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +527 -0
  27. package/runtime/__test__/element-template/runtime/prop-adapters/spread.test.ts +185 -6
  28. package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +21 -1
  29. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
  30. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
  31. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
  32. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
  33. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +309 -26
  34. package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
  35. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
  36. package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
  37. package/runtime/__test__/shared/component-stack.test.ts +211 -0
  38. package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
  39. package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
  40. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.event.test.jsx +2 -2
  41. package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx +3 -3
  42. package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
  43. package/runtime/__test__/snapshot/preact.test.jsx +0 -3
  44. package/runtime/__test__/snapshot/ref.test.jsx +30 -0
  45. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
  46. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +12 -0
  47. package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
  48. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
  49. package/runtime/lazy/element-template-internal.js +1 -1
  50. package/runtime/lazy/internal.js +1 -1
  51. package/runtime/lazy/jsx-dev-runtime.js +1 -1
  52. package/runtime/lazy/jsx-runtime.js +1 -1
  53. package/runtime/lazy/legacy-react-runtime.js +1 -1
  54. package/runtime/lazy/react-lepus.js +1 -1
  55. package/runtime/lazy/react.js +1 -1
  56. package/runtime/lib/core/capture-main-thread-object.js +2 -1
  57. package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
  58. package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
  59. package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
  60. package/runtime/lib/core/globalProps.js +1 -1
  61. package/runtime/lib/core/globalProps.js.map +1 -1
  62. package/runtime/lib/core/lynx/lazy-bundle.js +1 -1
  63. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  64. package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
  65. package/runtime/lib/core/lynx-data-processors.js +3 -0
  66. package/runtime/lib/core/lynx-data-processors.js.map +1 -1
  67. package/runtime/lib/core/runtime-destroy.js +1 -1
  68. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  69. package/runtime/lib/document.js +0 -5
  70. package/runtime/lib/document.js.map +1 -1
  71. package/runtime/lib/element-template/background/attr-slots.js +5 -2
  72. package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
  73. package/runtime/lib/element-template/background/commit-hook.js +11 -12
  74. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  75. package/runtime/lib/element-template/background/destroy.js +16 -11
  76. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  77. package/runtime/lib/element-template/background/hydrate.js +23 -0
  78. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  79. package/runtime/lib/element-template/client/root.d.ts +1 -1
  80. package/runtime/lib/element-template/client/root.js.map +1 -1
  81. package/runtime/lib/element-template/debug/alog.d.ts +1 -1
  82. package/runtime/lib/element-template/debug/alog.js +4 -1
  83. package/runtime/lib/element-template/debug/alog.js.map +1 -1
  84. package/runtime/lib/element-template/index.d.ts +2 -2
  85. package/runtime/lib/element-template/index.js.map +1 -1
  86. package/runtime/lib/element-template/internal.d.ts +2 -2
  87. package/runtime/lib/element-template/internal.js +1 -14
  88. package/runtime/lib/element-template/internal.js.map +1 -1
  89. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  90. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js +6 -1
  91. package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
  92. package/runtime/lib/element-template/native/flush.d.ts +1 -0
  93. package/runtime/lib/element-template/native/flush.js +9 -0
  94. package/runtime/lib/element-template/native/flush.js.map +1 -0
  95. package/runtime/lib/element-template/native/main-thread-api.js +3 -7
  96. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  97. package/runtime/lib/element-template/native/mts-destroy.js +8 -2
  98. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  99. package/runtime/lib/element-template/native/patch-listener.js +57 -50
  100. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  101. package/runtime/lib/element-template/native/reload-background.js +1 -1
  102. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  103. package/runtime/lib/element-template/native/reload-main-thread.js +35 -10
  104. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  105. package/runtime/lib/element-template/prop-adapters/gesture.d.ts +23 -0
  106. package/runtime/lib/element-template/prop-adapters/gesture.js +97 -0
  107. package/runtime/lib/element-template/prop-adapters/gesture.js.map +1 -0
  108. package/runtime/lib/element-template/prop-adapters/spread.d.ts +6 -1
  109. package/runtime/lib/element-template/prop-adapters/spread.js +72 -2
  110. package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
  111. package/runtime/lib/element-template/protocol/opcodes.d.ts +1 -0
  112. package/runtime/lib/element-template/protocol/opcodes.js +1 -0
  113. package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
  114. package/runtime/lib/element-template/protocol/types.d.ts +7 -1
  115. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  116. package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
  117. package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
  118. package/runtime/lib/element-template/runtime/patch.js +31 -2
  119. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  120. package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
  121. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  122. package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
  123. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  124. package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +4 -2
  125. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
  126. package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
  127. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -1
  128. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  129. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +7 -1
  130. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +380 -50
  131. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  132. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +3 -2
  133. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js +10 -1
  134. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  135. package/runtime/lib/element-template/runtime/template/typed-attributes.js +3 -3
  136. package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
  137. package/runtime/lib/internal.d.ts +1 -1
  138. package/runtime/lib/internal.js +1 -1
  139. package/runtime/lib/internal.js.map +1 -1
  140. package/runtime/lib/lynx-api.d.ts +2 -125
  141. package/runtime/lib/lynx-api.js.map +1 -1
  142. package/runtime/lib/shared/component-stack.d.ts +0 -4
  143. package/runtime/lib/shared/component-stack.js +21 -5
  144. package/runtime/lib/shared/component-stack.js.map +1 -1
  145. package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
  146. package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
  147. package/runtime/lib/snapshot/lifecycle/destroy.js +23 -17
  148. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  149. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
  150. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
  151. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
  152. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
  153. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  154. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
  155. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  156. package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +5 -0
  157. package/runtime/lib/snapshot/lifecycle/ref/delay.js +1 -1
  158. package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
  159. package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
  160. package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
  161. package/runtime/lib/snapshot/lynx/calledByNative.js +11 -8
  162. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  163. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
  164. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  165. package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
  166. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  167. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
  168. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  169. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  170. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  171. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  172. package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
  173. package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
  174. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
  175. package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
  176. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
  177. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
  178. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
  179. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +6 -0
  180. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  181. package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
  182. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  183. package/runtime/package.json +2 -3
  184. package/runtime/src/core/capture-main-thread-object.ts +2 -1
  185. package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
  186. package/runtime/src/core/globalProps.ts +1 -1
  187. package/runtime/src/core/lynx/lazy-bundle.ts +1 -1
  188. package/runtime/src/core/lynx-data-processors.ts +124 -1
  189. package/runtime/src/core/runtime-destroy.ts +1 -1
  190. package/runtime/src/document.ts +0 -6
  191. package/runtime/src/element-template/background/attr-slots.ts +5 -1
  192. package/runtime/src/element-template/background/commit-hook.ts +18 -12
  193. package/runtime/src/element-template/background/destroy.ts +16 -13
  194. package/runtime/src/element-template/background/hydrate.ts +23 -0
  195. package/runtime/src/element-template/client/root.ts +1 -3
  196. package/runtime/src/element-template/debug/alog.ts +5 -2
  197. package/runtime/src/element-template/index.ts +2 -2
  198. package/runtime/src/element-template/internal.ts +1 -20
  199. package/runtime/src/element-template/lynx/env.ts +1 -1
  200. package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +5 -1
  201. package/runtime/src/element-template/native/flush.ts +10 -0
  202. package/runtime/src/element-template/native/main-thread-api.ts +3 -6
  203. package/runtime/src/element-template/native/mts-destroy.ts +7 -2
  204. package/runtime/src/element-template/native/patch-listener.ts +62 -57
  205. package/runtime/src/element-template/native/reload-background.ts +1 -1
  206. package/runtime/src/element-template/native/reload-main-thread.ts +32 -11
  207. package/runtime/src/element-template/prop-adapters/gesture.ts +144 -0
  208. package/runtime/src/element-template/prop-adapters/spread.ts +110 -2
  209. package/runtime/src/element-template/protocol/opcodes.ts +1 -0
  210. package/runtime/src/element-template/protocol/types.ts +8 -13
  211. package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
  212. package/runtime/src/element-template/runtime/patch.ts +38 -0
  213. package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
  214. package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
  215. package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +31 -4
  216. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
  217. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +456 -50
  218. package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +14 -4
  219. package/runtime/src/element-template/runtime/template/typed-attributes.ts +3 -3
  220. package/runtime/src/element-template/types.d.ts +6 -0
  221. package/runtime/src/internal.ts +1 -1
  222. package/runtime/src/lynx-api.ts +2 -124
  223. package/runtime/src/shared/component-stack.ts +22 -5
  224. package/runtime/src/snapshot/lifecycle/destroy.ts +23 -18
  225. package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
  226. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
  227. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
  228. package/runtime/src/snapshot/lifecycle/ref/delay.ts +1 -1
  229. package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
  230. package/runtime/src/snapshot/lynx/calledByNative.ts +11 -9
  231. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
  232. package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
  233. package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
  234. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
  235. package/runtime/src/worklet-runtime/README.md +30 -10
  236. package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
  237. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
  238. package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +6 -0
  239. package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
  240. package/runtime/types/types.d.ts +2 -1
  241. package/runtime/vitest.config.ts +0 -2
  242. package/testing-library/.turbo/turbo-build.log +7 -7
  243. package/testing-library/src/__tests__/act.test.jsx +0 -7
  244. package/testing-library/src/__tests__/alog.test.jsx +12 -54
  245. package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
  246. package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
  247. package/testing-library/src/__tests__/worklet.test.jsx +49 -0
  248. package/transform/.turbo/turbo-build$colon$wasm.log +133 -297
  249. package/transform/__test__/defines.spec.js +30 -0
  250. package/transform/__test__/fixture.spec.js +11 -11
  251. package/transform/__test__/main-thread-object-compat.spec.js +111 -0
  252. package/transform/__test__/object-methods.spec.js +79 -0
  253. package/transform/crates/swc_plugin_element_template/lib.rs +11 -0
  254. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +113 -0
  255. package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
  256. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +63 -57
  257. package/transform/crates/swc_plugin_worklet/lib.rs +393 -589
  258. package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
  259. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +3 -3
  260. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +3 -3
  261. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +11 -6
  262. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +12 -6
  263. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +14 -5
  264. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +17 -6
  265. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +5 -5
  266. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +5 -5
  267. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +1 -1
  268. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +1 -1
  269. package/transform/dist/wasm.cjs +1 -1
  270. package/transform/package.json +0 -1
  271. package/transform/src/lib.rs +1 -1
  272. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +167 -69
  273. package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
  274. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  275. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +226 -132
  276. package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
  277. package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
  278. package/runtime/lib/snapshot/worklet/hmr.js +0 -28
  279. package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
  280. package/runtime/src/snapshot/worklet/hmr.ts +0 -34
  281. /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
  282. /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
@@ -64,6 +64,19 @@ function walkFiles(dir: string, pattern = /\.(?:[cm]?[jt]sx?)$/): string[] {
64
64
  });
65
65
  }
66
66
 
67
+ function getResolvedRelativeImports(file: string): string[] {
68
+ const source = fs.readFileSync(file, 'utf8');
69
+ const relativeImportPattern = /(?:from\s+|import\s*\(\s*|import\s+)['"](\.[^'"]+)['"]/g;
70
+ return Array.from(
71
+ source.matchAll(relativeImportPattern),
72
+ (match) => path.resolve(path.dirname(file), match[1]!),
73
+ );
74
+ }
75
+
76
+ function stripModuleExtension(filePath: string): string {
77
+ return filePath.replace(/\.(?:[cm]?[jt]sx?)$/, '');
78
+ }
79
+
67
80
  describe('snapshot containment guardrails', () => {
68
81
  test('keeps legacy runtime implementation directories under snapshot backend', () => {
69
82
  for (const dir of legacySourceDirs) {
@@ -89,13 +102,14 @@ describe('snapshot containment guardrails', () => {
89
102
  });
90
103
 
91
104
  test('does not import old implementation paths outside the snapshot backend', () => {
92
- const oldPathPattern = new RegExp(
93
- String.raw`(?:from\s+|import\s*\(\s*)['"](?:\./|\../)+(?:${legacySourceDirPattern})(?:/|['"])`,
94
- );
105
+ const legacyRootPrefixes = legacySourceDirs.map((dir) => `${path.join(srcRoot, dir)}${path.sep}`);
95
106
  const offenders = walkFiles(srcRoot)
96
107
  .filter((file) => !file.includes(`${path.sep}src${path.sep}snapshot${path.sep}`))
97
- .filter((file) => !file.includes(`${path.sep}src${path.sep}element-template${path.sep}`))
98
- .filter((file) => oldPathPattern.test(fs.readFileSync(file, 'utf8')))
108
+ .filter((file) =>
109
+ getResolvedRelativeImports(file).some((resolved) =>
110
+ legacyRootPrefixes.some((prefix) => resolved.startsWith(prefix))
111
+ )
112
+ )
99
113
  .map((file) => path.relative(runtimeRoot, file));
100
114
 
101
115
  expect(offenders).toEqual([]);
@@ -103,10 +117,18 @@ describe('snapshot containment guardrails', () => {
103
117
 
104
118
  test('prevents element-template from depending on snapshot private paths', () => {
105
119
  const elementTemplateRoot = path.join(srcRoot, 'element-template');
106
- const forbiddenImportPattern =
107
- /(?:from\s+|import\s*\(\s*)['"](?:\.\/|\.\.\/)+(?:snapshot|internal|root|lifecycle|renderToOpcodes)(?:\/|['"])/;
120
+ const snapshotPrefix = `${path.join(srcRoot, 'snapshot')}${path.sep}`;
121
+ const snapshotRootFiles = new Set(
122
+ ['document', 'index', 'internal', 'lynx', 'lynx-api', 'root', 'runtime-marker'].map((name) =>
123
+ path.join(srcRoot, name)
124
+ ),
125
+ );
108
126
  const offenders = walkFiles(elementTemplateRoot)
109
- .filter((file) => forbiddenImportPattern.test(fs.readFileSync(file, 'utf8')))
127
+ .filter((file) =>
128
+ getResolvedRelativeImports(file).some((resolved) =>
129
+ resolved.startsWith(snapshotPrefix) || snapshotRootFiles.has(stripModuleExtension(resolved))
130
+ )
131
+ )
110
132
  .map((file) => path.relative(runtimeRoot, file));
111
133
 
112
134
  expect(offenders).toEqual([]);
@@ -135,13 +157,25 @@ describe('snapshot containment guardrails', () => {
135
157
  });
136
158
 
137
159
  test('prevents core and shared modules from depending on runtime backends', () => {
138
- const backendImportPattern =
139
- /(?:from\s+|import\s*\(\s*)['"](?:\.\/|\.\.\/)+(?:snapshot|element-template)(?:\/|['"])/;
160
+ const backendPrefixes = [
161
+ `${path.join(srcRoot, 'snapshot')}${path.sep}`,
162
+ `${path.join(srcRoot, 'element-template')}${path.sep}`,
163
+ ];
164
+ const snapshotRootFiles = new Set(
165
+ ['document', 'index', 'internal', 'lynx', 'lynx-api', 'root', 'runtime-marker'].map((name) =>
166
+ path.join(srcRoot, name)
167
+ ),
168
+ );
140
169
  const offenders = [
141
170
  ...walkFiles(coreRoot),
142
171
  ...walkFiles(sharedRoot),
143
172
  ]
144
- .filter((file) => backendImportPattern.test(fs.readFileSync(file, 'utf8')))
173
+ .filter((file) =>
174
+ getResolvedRelativeImports(file).some((resolved) =>
175
+ backendPrefixes.some((prefix) => resolved.startsWith(prefix))
176
+ || snapshotRootFiles.has(stripModuleExtension(resolved))
177
+ )
178
+ )
145
179
  .map((file) => path.relative(runtimeRoot, file));
146
180
 
147
181
  expect(offenders).toEqual([]);
@@ -0,0 +1,211 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import type { VNode } from 'preact';
6
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
7
+
8
+ import { DIFF, DIFFED, RENDER, ROOT } from '../../src/shared/render-constants.js';
9
+
10
+ describe('shared/component-stack', () => {
11
+ beforeEach(() => {
12
+ vi.resetModules();
13
+ });
14
+
15
+ it('is idempotent and clears leaked renderStack entries on next root render or re-setup', async () => {
16
+ const { options } = await import('preact');
17
+ delete options[DIFF];
18
+ delete options[DIFFED];
19
+ delete options[ROOT];
20
+ delete options.vnode;
21
+ delete options[RENDER];
22
+
23
+ const { getCurrentVNode, setupComponentStack } = await import('../../src/shared/component-stack.js');
24
+ setupComponentStack();
25
+
26
+ const installedDiff = options[DIFF];
27
+ const installedDiffed = options[DIFFED];
28
+ const installedRoot = options[ROOT];
29
+ // eslint-disable-next-line @typescript-eslint/unbound-method
30
+ const installedVNode = options.vnode;
31
+ const installedRender = options[RENDER];
32
+
33
+ function ThrowingChild() {
34
+ return null;
35
+ }
36
+
37
+ const throwingVNode = { type: ThrowingChild, props: {} } as unknown as VNode;
38
+ options[ROOT]?.(throwingVNode, {} as never);
39
+ options[DIFF]?.(throwingVNode);
40
+ options[RENDER]?.(throwingVNode);
41
+ // Simulate a component throwing during render before DIFFED runs.
42
+ expect(getCurrentVNode()).toBe(throwingVNode);
43
+
44
+ // Next root render must clear renderStack as well as ownerStack.
45
+ const nextRootVNode = { type: 'view', props: {} } as unknown as VNode;
46
+ options[ROOT]?.(nextRootVNode, {} as never);
47
+ expect(getCurrentVNode()).toBeNull();
48
+
49
+ // Repeated setupComponentStack() must not double-wrap hooks and must reset stacks.
50
+ options[DIFF]?.(throwingVNode);
51
+ expect(getCurrentVNode()).toBe(throwingVNode);
52
+ setupComponentStack();
53
+ expect(getCurrentVNode()).toBeNull();
54
+ expect(options[DIFF]).toBe(installedDiff);
55
+ expect(options[DIFFED]).toBe(installedDiffed);
56
+ expect(options[ROOT]).toBe(installedRoot);
57
+ // eslint-disable-next-line @typescript-eslint/unbound-method
58
+ expect(options.vnode).toBe(installedVNode);
59
+ expect(options[RENDER]).toBe(installedRender);
60
+ });
61
+
62
+ it('chains existing Preact option hooks and formats owner stacks across vnode types', async () => {
63
+ const { Fragment, options } = await import('preact');
64
+ const oldDiff = vi.fn();
65
+ const oldDiffed = vi.fn();
66
+ const oldRoot = vi.fn();
67
+ const oldVNode = vi.fn();
68
+ const oldRender = vi.fn();
69
+
70
+ options[DIFF] = oldDiff;
71
+ options[DIFFED] = oldDiffed;
72
+ options[ROOT] = oldRoot;
73
+ options.vnode = oldVNode;
74
+ options[RENDER] = oldRender;
75
+
76
+ const { getCurrentVNode, getOwnerStack, setupComponentStack } = await import(
77
+ '../../src/shared/component-stack.js'
78
+ );
79
+ setupComponentStack();
80
+
81
+ function Outer() {
82
+ return null;
83
+ }
84
+ function NamedInner() {
85
+ return null;
86
+ }
87
+ NamedInner.displayName = 'CustomInner';
88
+
89
+ const rootVNode = { type: Outer, props: {}, __source: { fileName: 'App.tsx', lineNumber: 10 } } as unknown as VNode;
90
+ options.vnode?.(rootVNode);
91
+ options[ROOT]?.(rootVNode, {} as never);
92
+ options[DIFF]?.(rootVNode);
93
+ options[RENDER]?.(rootVNode);
94
+ expect(getCurrentVNode()).toBe(rootVNode);
95
+
96
+ const innerVNode = { type: NamedInner, props: {} } as unknown as VNode;
97
+ options.vnode?.(innerVNode);
98
+ // Cloning a vnode with an existing _owner must preserve that _owner.
99
+ const preOwnedVNode = { type: 'view', props: {}, _owner: rootVNode } as unknown as VNode;
100
+ options.vnode?.(preOwnedVNode);
101
+ expect((preOwnedVNode as unknown as { _owner: unknown })._owner).toBe(rootVNode);
102
+
103
+ options[DIFF]?.(innerVNode);
104
+ options[RENDER]?.(innerVNode);
105
+ expect(getCurrentVNode()).toBe(innerVNode);
106
+
107
+ const fragmentVNode = { type: Fragment, props: {} } as unknown as VNode;
108
+ options.vnode?.(fragmentVNode);
109
+ options[DIFF]?.(fragmentVNode);
110
+ options[RENDER]?.(fragmentVNode);
111
+ options[DIFFED]?.(fragmentVNode);
112
+ expect(getCurrentVNode()).toBe(innerVNode);
113
+
114
+ // Nested portal root render (parent with parentNode) must preserve outer stacks,
115
+ // including when an inner portal component throws and unwinds to an outer boundary.
116
+ const portalContextVNode = { type: Outer, props: {} } as unknown as VNode;
117
+ const throwingPortalChildVNode = { type: NamedInner, props: {} } as unknown as VNode;
118
+ options.vnode?.(portalContextVNode);
119
+ options[ROOT]?.(portalContextVNode, { parentNode: {} } as never);
120
+ expect(getCurrentVNode()).toBe(innerVNode);
121
+ options[DIFF]?.(portalContextVNode);
122
+ options[RENDER]?.(portalContextVNode);
123
+ options[DIFF]?.(throwingPortalChildVNode);
124
+ options[RENDER]?.(throwingPortalChildVNode);
125
+ expect(getCurrentVNode()).toBe(throwingPortalChildVNode);
126
+ // Simulate throwingPortalChildVNode and portalContextVNode skipping DIFFED
127
+ // when an outer boundary catches the error and finishes DIFFED on innerVNode.
128
+ options[DIFFED]?.(innerVNode);
129
+ expect(getCurrentVNode()).toBe(rootVNode);
130
+
131
+ // Component bailout (DIFF + DIFFED without RENDER) must not pop parent owner.
132
+ const bailoutVNode = { type: NamedInner, props: {} } as unknown as VNode;
133
+ options[DIFF]?.(bailoutVNode);
134
+ expect(getCurrentVNode()).toBe(bailoutVNode);
135
+ options[DIFFED]?.(bailoutVNode);
136
+ expect(getCurrentVNode()).toBe(rootVNode);
137
+
138
+ // Guard against DIFFED on a component vnode that was never pushed to renderStack.
139
+ const unpushedVNode = { type: NamedInner, props: {} } as unknown as VNode;
140
+ options[DIFFED]?.(unpushedVNode);
141
+ expect(getCurrentVNode()).toBe(rootVNode);
142
+
143
+ const postPortalChildVNode = { type: 'view', props: {} } as unknown as VNode;
144
+ options.vnode?.(postPortalChildVNode);
145
+ expect((postPortalChildVNode as unknown as { _owner: unknown })._owner).toBe(rootVNode);
146
+
147
+ const hostVNode = { type: 'view', props: {}, _owner: fragmentVNode } as unknown as VNode;
148
+ const textVNode = { type: null, props: {}, _owner: hostVNode } as unknown as VNode;
149
+
150
+ expect(getOwnerStack(textVNode)).toBe(
151
+ ' in #text\n'
152
+ + ' in view\n'
153
+ + ' in Fragment\n'
154
+ + ' in CustomInner\n'
155
+ + ' in Outer (at App.tsx:10)\n',
156
+ );
157
+
158
+ options[DIFFED]?.(rootVNode);
159
+ expect(getCurrentVNode()).toBeNull();
160
+
161
+ expect(oldRoot).toHaveBeenCalledTimes(2);
162
+ expect(oldDiff).toHaveBeenCalledTimes(6);
163
+ expect(oldRender).toHaveBeenCalledTimes(5);
164
+ expect(oldDiffed).toHaveBeenCalledTimes(5);
165
+ expect(oldVNode).toHaveBeenCalledTimes(6);
166
+ });
167
+
168
+ it('unwinds renderStack and ownerStack when a Portal child throws into an outer ErrorBoundary', async () => {
169
+ const { Component, createElement, render } = await import('preact');
170
+ const { createPortal } = await import('../../src/snapshot/lynx/portals.js');
171
+ const { getCurrentVNode, setupComponentStack } = await import(
172
+ '../../src/shared/component-stack.js'
173
+ );
174
+ setupComponentStack();
175
+
176
+ class Boundary extends Component<{ children?: unknown }, { failed: boolean }> {
177
+ override state = { failed: false };
178
+ static override getDerivedStateFromError() {
179
+ return { failed: true };
180
+ }
181
+ override render() {
182
+ return this.state.failed ? null : this.props.children;
183
+ }
184
+ }
185
+
186
+ function Boom(): null {
187
+ throw new Error('portal boom');
188
+ }
189
+
190
+ const fakeTarget = {
191
+ _nodeSelectToken: { type: 0, identifier: '#host', rootUniqueId: 0 },
192
+ } as never;
193
+
194
+ function App() {
195
+ return createElement(Boundary, null, createPortal(createElement(Boom, null), fakeTarget));
196
+ }
197
+
198
+ const rootContainer = {
199
+ nodeType: 1,
200
+ childNodes: [],
201
+ insertBefore() {},
202
+ removeChild() {},
203
+ } as never;
204
+
205
+ render(createElement(App, null), rootContainer);
206
+
207
+ expect(getCurrentVNode()).toBeNull();
208
+ const afterRenderVNode = createElement('view', null) as unknown as { _owner?: unknown };
209
+ expect(afterRenderVNode._owner).toBeNull();
210
+ });
211
+ });
@@ -33,9 +33,6 @@ describe('formatPatch', () => {
33
33
  SnapshotOperation.DEV_ONLY_AddSnapshot,
34
34
  'unique-1',
35
35
  'snapshotCreator-val',
36
- SnapshotOperation.DEV_ONLY_RegisterWorklet,
37
- 'hash-1',
38
- '() => {}',
39
36
  ];
40
37
  const formatted = prettyFormatSnapshotPatch(snapshotPatch);
41
38
  expect(formatted).toEqual([
@@ -60,11 +57,6 @@ describe('formatPatch', () => {
60
57
  uniqID: 'unique-1',
61
58
  snapshotCreator: 'snapshotCreator-val',
62
59
  },
63
- {
64
- op: 'DEV_ONLY_RegisterWorklet',
65
- hash: 'hash-1',
66
- fnStr: '() => {}',
67
- },
68
60
  ]);
69
61
  });
70
62
 
@@ -1,6 +1,6 @@
1
1
  import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2
2
 
3
- import { prepareGestureForCommit } from '../../../src/snapshot/gesture/processGestureBagkround';
3
+ import { prepareGestureForCommit } from '../../../src/snapshot/gesture/processGestureBackground';
4
4
  import { clearConfigCacheForTesting } from '../../../src/snapshot/worklet/functionality';
5
5
 
6
6
  describe('prepareGestureForCommit', () => {
@@ -15,13 +15,13 @@ beforeAll(() => {
15
15
 
16
16
  beforeEach(() => {
17
17
  globalEnvManager.resetEnv();
18
- globalThis.__GLOBAL_PROPS_MODE__ = 'event';
18
+ lynx.__runtime_configs__ = { globalPropsMode: 'event' };
19
19
  });
20
20
 
21
21
  afterEach(() => {
22
22
  elementTree.clear();
23
23
  vi.restoreAllMocks();
24
- globalThis.__GLOBAL_PROPS_MODE__ = 'reactive';
24
+ lynx.__runtime_configs__ = { globalPropsMode: 'reactive' };
25
25
  });
26
26
 
27
27
  async function renderWithCurrentPreact(element, root) {
@@ -24,7 +24,7 @@ beforeEach(() => {
24
24
  afterEach(() => {
25
25
  elementTree.clear();
26
26
  vi.restoreAllMocks();
27
- globalThis.__GLOBAL_PROPS_MODE__ = 'reactive';
27
+ lynx.__runtime_configs__ = { globalPropsMode: 'reactive' };
28
28
  });
29
29
 
30
30
  async function renderWithCurrentPreact(element, root) {
@@ -308,8 +308,8 @@ describe('updateGlobalProps', () => {
308
308
  }
309
309
  });
310
310
 
311
- it('should not trigger re-render when __GLOBAL_PROPS_MODE__ is event', async () => {
312
- globalThis.__GLOBAL_PROPS_MODE__ = 'event';
311
+ it('should not trigger re-render when globalPropsMode is event', async () => {
312
+ lynx.__runtime_configs__ = { globalPropsMode: 'event' };
313
313
 
314
314
  lynx.__globalProps = { theme: 'dark' };
315
315
  const Comp = () => {
@@ -9,6 +9,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite
9
9
  import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit';
10
10
  import { injectUpdateMainThread } from '../../../src/snapshot/lifecycle/patch/updateMainThread';
11
11
  import { installComponentCompat } from '../../../src/core/component';
12
+ import { globalPipelineOptions } from '../../../src/core/performance';
12
13
  import { initTimingAPI } from '../../../src/snapshot/lynx/performance';
13
14
  import { __root } from '../../../src/root';
14
15
  import { setupPage } from '../../../src/snapshot';
@@ -128,6 +129,7 @@ describe('setState timing api', () => {
128
129
 
129
130
  globalEnvManager.switchToMainThread();
130
131
  rLynxChange(mtCallbacks[0][1]);
132
+ expect(globalPipelineOptions).toBeUndefined();
131
133
  expect(__root.__element_root).toMatchInlineSnapshot(`
132
134
  <page
133
135
  cssId="default-entry-from-native:0"
@@ -210,6 +212,7 @@ describe('attribute timing api', () => {
210
212
 
211
213
  globalEnvManager.switchToMainThread();
212
214
  rLynxChange(mtCallbacks[0][1]);
215
+ expect(globalPipelineOptions).toBeUndefined();
213
216
  expect(__root.__element_root).toMatchInlineSnapshot(`
214
217
  <page
215
218
  cssId="default-entry-from-native:0"
@@ -93,9 +93,6 @@ function collectSnapshotPatchOps(patch) {
93
93
  case SnapshotOperation.DEV_ONLY_AddSnapshot:
94
94
  i += 2;
95
95
  break;
96
- case SnapshotOperation.DEV_ONLY_RegisterWorklet:
97
- i += 2;
98
- break;
99
96
  case SnapshotOperation.DEV_ONLY_SetSnapshotEntryName:
100
97
  i += 2;
101
98
  break;
@@ -7,6 +7,7 @@ import { render } from 'preact';
7
7
  import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
8
8
 
9
9
  import { RefProxy, runDelayedUiOps, shouldDelayUiOps } from '../../src/snapshot/lifecycle/ref/delay';
10
+ import { destroyBackground } from '../../src/snapshot/lifecycle/destroy';
10
11
 
11
12
  import { Component, createRef, useState } from '../../src/index';
12
13
  import { clearCommitTaskId, replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit';
@@ -2365,4 +2366,33 @@ describe('runDelayedUiOps helper', () => {
2365
2366
  runDelayedUiOps();
2366
2367
  expect(shouldDelayUiOps.value).toBe(false);
2367
2368
  });
2369
+
2370
+ it('should clear pre-hydration delayed UI operations on destroyBackground even when unmount cleanup throws', () => {
2371
+ shouldDelayUiOps.value = true;
2372
+ const invoke = vi.fn();
2373
+ vi.spyOn(lynx, 'createSelectorQuery').mockReturnValue({
2374
+ selectUniqueID: () => ({ invoke }),
2375
+ });
2376
+
2377
+ const proxy = new RefProxy([1, 0]);
2378
+ proxy.invoke({ method: 'focus' }).exec();
2379
+ expect(invoke).not.toHaveBeenCalled();
2380
+
2381
+ class ThrowingUnmount extends Component {
2382
+ componentWillUnmount() {
2383
+ throw new Error('unmount boom');
2384
+ }
2385
+ render() {
2386
+ return <view />;
2387
+ }
2388
+ }
2389
+
2390
+ globalEnvManager.switchToBackground();
2391
+ render(<ThrowingUnmount />, __root);
2392
+
2393
+ expect(() => destroyBackground()).toThrow('unmount boom');
2394
+ runDelayedUiOps();
2395
+
2396
+ expect(invoke).not.toHaveBeenCalled();
2397
+ });
2368
2398
  });
@@ -5,7 +5,6 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite
5
5
 
6
6
  import { globalEnvManager } from './utils/envManager';
7
7
  import { elementTree } from './utils/nativeMethod';
8
- import { registerWorkletOnBackground } from '../../src/internal';
9
8
  import { addCtxNotFoundEventListener } from '../../src/snapshot/lifecycle/patch/error';
10
9
  import {
11
10
  SnapshotOperation,
@@ -1637,38 +1636,6 @@ describe('DEV_ONLY_addSnapshot', () => {
1637
1636
  });
1638
1637
  });
1639
1638
 
1640
- describe.skip('DEV_ONLY_RegisterWorklet', () => {
1641
- beforeEach(() => {
1642
- initGlobalSnapshotPatch();
1643
- });
1644
-
1645
- it('basic', () => {
1646
- registerWorkletOnBackground('main-thread', 'hash-1', () => 'fn-1');
1647
- globalThis.registerWorklet = vi.fn();
1648
-
1649
- const patch = takeGlobalSnapshotPatch();
1650
-
1651
- expect(patch).toMatchInlineSnapshot(`
1652
- [
1653
- 101,
1654
- "hash-1",
1655
- "() => "fn-1"",
1656
- ]
1657
- `);
1658
-
1659
- // Apply patches in main thread
1660
- snapshotPatchApply(patch, 42, false);
1661
-
1662
- expect(globalThis.registerWorklet).toBeCalledTimes(1);
1663
- expect(globalThis.registerWorklet.mock.calls[0][0]).toMatch('main-thread');
1664
- expect(globalThis.registerWorklet.mock.calls[0][1]).toMatch('hash-1');
1665
- expect(globalThis.registerWorklet.mock.calls[0][2]()).toMatch('fn-1');
1666
-
1667
- registerWorkletOnBackground('main-thread', 'hash-1', () => 'fn-1');
1668
- expect(globalThis.registerWorklet).toBeCalledTimes(1);
1669
- });
1670
- });
1671
-
1672
1639
  describe('list', () => {
1673
1640
  beforeEach(() => {
1674
1641
  initGlobalSnapshotPatch();
@@ -100,4 +100,16 @@ describe('jsFunctionLifecycle', () => {
100
100
  expect(register).toHaveBeenCalledTimes(2);
101
101
  expect(manager.execIdRefCount.get(3)).toBe(1);
102
102
  });
103
+
104
+ it('does not release a new runtime execution when retired finalizers run', () => {
105
+ const previous = new JsFunctionLifecycleManager();
106
+ previous.addRef(3, {});
107
+ previous.removeRef(3);
108
+ previous.dispose();
109
+ const current = new JsFunctionLifecycleManager();
110
+ current.addRef(3, {});
111
+ previous.fire();
112
+ expect(events).toEqual([]);
113
+ expect(current.execIdRefCount.get(3)).toBe(1);
114
+ });
103
115
  });
@@ -0,0 +1,68 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
+
6
+ describe('worklet-runtime legacy fallback', () => {
7
+ beforeEach(() => {
8
+ vi.resetModules();
9
+ vi.stubGlobal('__LoadLepusChunk', undefined);
10
+ vi.stubGlobal('lynxWorkletImpl', undefined);
11
+ });
12
+
13
+ afterEach(() => {
14
+ vi.unstubAllGlobals();
15
+ vi.resetModules();
16
+ });
17
+
18
+ it('exports the compatibility helper without initializing the worklet runtime', async () => {
19
+ const reactInternal = await import('@lynx-js/react/internal');
20
+ const bindings = await import('@lynx-js/react/worklet-runtime/bindings');
21
+
22
+ expect(reactInternal.loadWorkletRuntime).toBeTypeOf('function');
23
+ expect(reactInternal.loadWorkletRuntime).toBe(bindings.loadWorkletRuntime);
24
+ expect(globalThis.lynxWorkletImpl).toBeUndefined();
25
+ });
26
+
27
+ it('returns false when the legacy chunk loader is unavailable', async () => {
28
+ const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
29
+
30
+ expect(loadWorkletRuntime('__Card__')).toBe(false);
31
+ });
32
+
33
+ it('reuses the in-memory runtime without loading the legacy chunk', async () => {
34
+ const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
35
+ const runtime = { _workletMap: {} };
36
+ const loader = vi.fn();
37
+ vi.stubGlobal('lynxWorkletImpl', runtime);
38
+ vi.stubGlobal('__LoadLepusChunk', loader);
39
+
40
+ expect(loadWorkletRuntime('__Card__')).toBe(true);
41
+ expect(globalThis.lynxWorkletImpl).toBe(runtime);
42
+ expect(loader).not.toHaveBeenCalled();
43
+ });
44
+
45
+ it.each([true, false])('returns the legacy chunk loader result (%s)', async (result) => {
46
+ const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
47
+ const loader = vi.fn(() => result);
48
+ vi.stubGlobal('__LoadLepusChunk', loader);
49
+
50
+ expect(loadWorkletRuntime('__Card__')).toBe(result);
51
+ expect(loader).toHaveBeenCalledExactlyOnceWith('worklet-runtime', {
52
+ dynamicComponentEntry: '__Card__',
53
+ chunkType: 0,
54
+ });
55
+ });
56
+
57
+ it('supports callers without a dynamic component entry', async () => {
58
+ const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
59
+ const loader = vi.fn(() => true);
60
+ vi.stubGlobal('__LoadLepusChunk', loader);
61
+
62
+ expect(loadWorkletRuntime()).toBe(true);
63
+ expect(loader).toHaveBeenCalledExactlyOnceWith('worklet-runtime', {
64
+ dynamicComponentEntry: undefined,
65
+ chunkType: 0,
66
+ });
67
+ });
68
+ });
@@ -61,6 +61,36 @@ describe('Worklet', () => {
61
61
  if (kind === 'metadata') expect(value.nested).toEqual({ _wvid: 999 });
62
62
  });
63
63
 
64
+ it('executes the original Native-held context without replacing its captures', () => {
65
+ initWorklet();
66
+ registerWorklet('main-thread', 'background-owner', function() {
67
+ return this._jsFn;
68
+ });
69
+ const handle = { _jsFnId: 7 };
70
+ const ctx = { _wkltId: 'background-owner', _execId: 3, _jsFn: { a: handle, b: handle } };
71
+ lynxWorkletImpl._jsFunctionLifecycleManager.addRef(3, ctx);
72
+ const nativeContext = ctx;
73
+ const first = runWorklet(nativeContext, []);
74
+ expect(first.a).toBe(first.b);
75
+ expect(first.a).toBe(ctx._jsFn.a);
76
+ expect(runWorklet(nativeContext, [])).toBe(first);
77
+ expect(lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(3)).toBe(2);
78
+ });
79
+
80
+ it.each(['2.15', '2.16'])('prepares captured execution metadata without a lifecycle manager on SDK %s', (version) => {
81
+ SystemInfo.lynxSdkVersion = version;
82
+ initWorklet();
83
+ lynxWorkletImpl._jsFunctionLifecycleManager = undefined;
84
+ registerWorklet('main-thread', 'fallback', function() {
85
+ return this._jsFn.callback;
86
+ });
87
+ const descriptor = { _jsFnId: 7 };
88
+ const ctx = { _wkltId: 'fallback', _execId: 3, _jsFn: { callback: descriptor } };
89
+ expect(runWorklet(ctx, [])).toEqual({ _jsFnId: 7, _execId: 3 });
90
+ expect(ctx._jsFn.callback).toEqual({ _jsFnId: 7, _execId: 3 });
91
+ expect(ctx._jsFn.callback).toBe(descriptor);
92
+ });
93
+
64
94
  it('worklet should be called', () => {
65
95
  initWorklet();
66
96
 
@@ -26,6 +26,7 @@ export const {
26
26
  __etHost,
27
27
  __root,
28
28
  adaptEventAttrSlot,
29
+ adaptGestureAttrSlot,
29
30
  adaptMTEventAttrSlot,
30
31
  adaptMTRefAttrSlot,
31
32
  adaptRefAttrSlot,
@@ -38,7 +39,6 @@ export const {
38
39
  process,
39
40
  registerRuntimeBackend,
40
41
  registerRuntimeVersion,
41
- registerWorkletOnBackground,
42
42
  transformToWorklet,
43
43
  withInitDataInState,
44
44
  wrapWithLynxComponent,
@@ -46,12 +46,12 @@ export const {
46
46
  getRuntimeVersion,
47
47
  loadDynamicJS,
48
48
  loadLazyBundle,
49
+ loadWorkletRuntime,
49
50
  options,
50
51
  preactCloneElement,
51
52
  process,
52
53
  registerRuntimeBackend,
53
54
  registerRuntimeVersion,
54
- registerWorkletOnBackground,
55
55
  snapshotCreateList,
56
56
  snapshotManager,
57
57
  snapshotCreatorMap,
@@ -2,7 +2,7 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
- import { sExportsJSXDevRuntime, target } from './target';
5
+ import { sExportsJSXDevRuntime, target } from './target.js';
6
6
 
7
7
  export const {
8
8
  Fragment,
@@ -2,7 +2,7 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
- import { sExportsJSXRuntime, target } from './target';
5
+ import { sExportsJSXRuntime, target } from './target.js';
6
6
 
7
7
  export const {
8
8
  Fragment,