@lynx-js/react 0.129.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 (206) hide show
  1. package/CHANGELOG.md +14 -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/hooks/useLynxGlobalEventListener.test.jsx +1 -1
  6. package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
  7. package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
  8. package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
  9. package/runtime/__test__/element-template/native/mts-destroy.test.ts +83 -0
  10. package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +3 -0
  11. package/runtime/__test__/element-template/native/reload.test.ts +31 -2
  12. package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
  13. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +197 -7
  14. package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
  15. package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
  16. package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
  17. package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
  18. package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
  19. package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +121 -26
  20. package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
  21. package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
  22. package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
  23. package/runtime/__test__/shared/component-stack.test.ts +211 -0
  24. package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
  25. package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
  26. package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
  27. package/runtime/__test__/snapshot/preact.test.jsx +0 -3
  28. package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
  29. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +12 -0
  30. package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
  31. package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
  32. package/runtime/lazy/element-template-internal.js +0 -1
  33. package/runtime/lazy/internal.js +1 -1
  34. package/runtime/lazy/jsx-dev-runtime.js +1 -1
  35. package/runtime/lazy/jsx-runtime.js +1 -1
  36. package/runtime/lazy/legacy-react-runtime.js +1 -1
  37. package/runtime/lazy/react-lepus.js +1 -1
  38. package/runtime/lazy/react.js +1 -1
  39. package/runtime/lib/core/capture-main-thread-object.js +2 -1
  40. package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
  41. package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
  42. package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
  43. package/runtime/lib/core/lynx/lazy-bundle.js +1 -1
  44. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  45. package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
  46. package/runtime/lib/core/lynx-data-processors.js +3 -0
  47. package/runtime/lib/core/lynx-data-processors.js.map +1 -1
  48. package/runtime/lib/core/runtime-destroy.js +1 -1
  49. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  50. package/runtime/lib/document.js +0 -5
  51. package/runtime/lib/document.js.map +1 -1
  52. package/runtime/lib/element-template/background/commit-hook.js +11 -12
  53. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  54. package/runtime/lib/element-template/client/root.d.ts +1 -1
  55. package/runtime/lib/element-template/client/root.js.map +1 -1
  56. package/runtime/lib/element-template/index.d.ts +2 -2
  57. package/runtime/lib/element-template/index.js.map +1 -1
  58. package/runtime/lib/element-template/internal.d.ts +1 -1
  59. package/runtime/lib/element-template/internal.js +0 -13
  60. package/runtime/lib/element-template/internal.js.map +1 -1
  61. package/runtime/lib/element-template/lynx/env.js.map +1 -1
  62. package/runtime/lib/element-template/native/flush.d.ts +1 -0
  63. package/runtime/lib/element-template/native/flush.js +9 -0
  64. package/runtime/lib/element-template/native/flush.js.map +1 -0
  65. package/runtime/lib/element-template/native/main-thread-api.js +3 -7
  66. package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
  67. package/runtime/lib/element-template/native/mts-destroy.js +8 -2
  68. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  69. package/runtime/lib/element-template/native/patch-listener.js +57 -50
  70. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  71. package/runtime/lib/element-template/native/reload-main-thread.js +2 -1
  72. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  73. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  74. package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
  75. package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
  76. package/runtime/lib/element-template/runtime/patch.js +4 -0
  77. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  78. package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
  79. package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
  80. package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
  81. package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
  82. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -1
  83. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  84. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +1 -0
  85. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +41 -21
  86. package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
  87. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +1 -1
  88. package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
  89. package/runtime/lib/internal.d.ts +1 -1
  90. package/runtime/lib/internal.js +1 -1
  91. package/runtime/lib/internal.js.map +1 -1
  92. package/runtime/lib/lynx-api.d.ts +2 -125
  93. package/runtime/lib/lynx-api.js.map +1 -1
  94. package/runtime/lib/shared/component-stack.d.ts +0 -4
  95. package/runtime/lib/shared/component-stack.js +21 -5
  96. package/runtime/lib/shared/component-stack.js.map +1 -1
  97. package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
  98. package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
  99. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
  100. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
  101. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
  102. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
  103. package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  104. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
  105. package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
  106. package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
  107. package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
  108. package/runtime/lib/snapshot/lynx/calledByNative.js +11 -8
  109. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  110. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
  111. package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
  112. package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
  113. package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
  114. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
  115. package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
  116. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
  117. package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
  118. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  119. package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
  120. package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
  121. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
  122. package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
  123. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
  124. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
  125. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
  126. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +6 -0
  127. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  128. package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
  129. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
  130. package/runtime/package.json +2 -3
  131. package/runtime/src/core/capture-main-thread-object.ts +2 -1
  132. package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
  133. package/runtime/src/core/lynx/lazy-bundle.ts +1 -1
  134. package/runtime/src/core/lynx-data-processors.ts +124 -1
  135. package/runtime/src/core/runtime-destroy.ts +1 -1
  136. package/runtime/src/document.ts +0 -6
  137. package/runtime/src/element-template/background/commit-hook.ts +18 -12
  138. package/runtime/src/element-template/client/root.ts +1 -3
  139. package/runtime/src/element-template/index.ts +2 -2
  140. package/runtime/src/element-template/internal.ts +0 -20
  141. package/runtime/src/element-template/lynx/env.ts +1 -1
  142. package/runtime/src/element-template/native/flush.ts +10 -0
  143. package/runtime/src/element-template/native/main-thread-api.ts +3 -6
  144. package/runtime/src/element-template/native/mts-destroy.ts +7 -2
  145. package/runtime/src/element-template/native/patch-listener.ts +62 -57
  146. package/runtime/src/element-template/native/reload-main-thread.ts +2 -1
  147. package/runtime/src/element-template/protocol/types.ts +0 -13
  148. package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
  149. package/runtime/src/element-template/runtime/patch.ts +5 -0
  150. package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
  151. package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
  152. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
  153. package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +51 -21
  154. package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +2 -2
  155. package/runtime/src/element-template/types.d.ts +6 -0
  156. package/runtime/src/internal.ts +1 -1
  157. package/runtime/src/lynx-api.ts +2 -124
  158. package/runtime/src/shared/component-stack.ts +22 -5
  159. package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
  160. package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
  161. package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
  162. package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
  163. package/runtime/src/snapshot/lynx/calledByNative.ts +11 -9
  164. package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
  165. package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
  166. package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
  167. package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
  168. package/runtime/src/worklet-runtime/README.md +30 -10
  169. package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
  170. package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
  171. package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +6 -0
  172. package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
  173. package/runtime/vitest.config.ts +0 -2
  174. package/testing-library/.turbo/turbo-build.log +6 -6
  175. package/testing-library/src/__tests__/act.test.jsx +0 -7
  176. package/testing-library/src/__tests__/alog.test.jsx +12 -54
  177. package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
  178. package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
  179. package/testing-library/src/__tests__/worklet.test.jsx +49 -0
  180. package/transform/.turbo/turbo-build$colon$wasm.log +98 -376
  181. package/transform/__test__/defines.spec.js +30 -0
  182. package/transform/__test__/object-methods.spec.js +79 -0
  183. package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
  184. package/transform/crates/swc_plugin_worklet/gen_stmt.rs +56 -48
  185. package/transform/crates/swc_plugin_worklet/lib.rs +393 -589
  186. package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
  187. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +6 -1
  188. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -1
  189. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +9 -0
  190. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +12 -1
  191. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +1 -1
  192. package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +1 -1
  193. package/transform/dist/wasm.cjs +1 -1
  194. package/transform/package.json +0 -1
  195. package/transform/src/lib.rs +1 -1
  196. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +113 -42
  197. package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
  198. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  199. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +273 -66
  200. package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
  201. package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
  202. package/runtime/lib/snapshot/worklet/hmr.js +0 -28
  203. package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
  204. package/runtime/src/snapshot/worklet/hmr.ts +0 -34
  205. /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
  206. /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
@@ -17,7 +17,7 @@ const assign = /* @__PURE__ */ Object.assign;
17
17
  // Global state for the current render pass
18
18
  export let beforeDiff;
19
19
  export let beforeDiff2;
20
- let afterDiff, renderHook, ummountHook;
20
+ let afterDiff, renderHook, unmountHook;
21
21
  export function renderWithHooks(vnode, context, output, renderVNode, result) {
22
22
  // Performance optimization: main-thread rendering is synchronous and we
23
23
  // therefore don't execute any effects. To do that we pass an empty
@@ -31,7 +31,7 @@ export function renderWithHooks(vnode, context, output, renderVNode, result) {
31
31
  beforeDiff2 = options[DIFF2];
32
32
  afterDiff = options[DIFFED];
33
33
  renderHook = options[RENDER];
34
- ummountHook = options.unmount;
34
+ unmountHook = options.unmount;
35
35
  const parent = h(Fragment, null);
36
36
  parent[CHILDREN] = [vnode];
37
37
  try {
@@ -91,8 +91,8 @@ export function cleanupVNode(vnode) {
91
91
  if (afterDiff)
92
92
  afterDiff(vnode);
93
93
  vnode[PARENT] = undefined;
94
- if (ummountHook)
95
- ummountHook(vnode);
94
+ if (unmountHook)
95
+ unmountHook(vnode);
96
96
  }
97
97
  export function renderComponentVNode(vnode, type, props, context, output, renderVNode, result, parentType, subtreeHandles, listItemUids) {
98
98
  let cctx = context;
@@ -1 +1 @@
1
- {"version":3,"file":"render-components.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/render-components.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;GAIG;AAEH,cAAc;AAEd,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEj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AAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAEzD,MAAM,CAAC,MAAM,GAAG,YAAY,CAAC;YAC7B,MAAM,CAAC,kBAAkB,CAAC,MAAM,GAAG,UAAU,CAAC,wBAAwB,CAAC;YACvE,IAAI,cAAc;gBAAE,cAAc,CAAC,MAAM,GAAG,UAAU,CAAC,oBAAoB,CAAC;YAC5E,IAAI,YAAY;gBAAE,YAAY,CAAC,MAAM,GAAG,UAAU,CAAC,kBAAkB,CAAC;YACtE,yBAAyB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAC7C,MAAM,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;YAClD,IAAI,OAAO;gBAAE,MAAM,CAAC,oBAAoB,GAAG,UAAU,CAAC,oBAAoB,CAAC;YAC3E,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;QAClG,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,yDAAyD;AACzD,SAAS,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO;IACrC,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAC1C,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 * Synchronous component traversal for Element Template rendering.\n * This module is modified from preact-render-to-string@6.0.3 to generate\n * host output instead of HTML strings for Lynx.\n */\n\n// @ts-nocheck\n\nimport { Fragment, h, options } from 'preact';\n\nimport { discardRenderedHostsSince } from './create-rendered-host.js';\nimport { getNextElementTemplateId } from '../template/handle.js';\n\nimport {\n BITS,\n CHILDREN,\n COMMIT,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DIFF2,\n DIFFED,\n GLOBAL_CONTEXT,\n NEXT_STATE,\n PARENT,\n RENDER,\n SKIP_EFFECTS,\n VNODE,\n} from '../../../shared/render-constants.js';\n\n/** @typedef {import('preact').VNode} VNode */\n\nconst EMPTY_ARR = [];\nconst assign = /* @__PURE__ */ Object.assign;\n\n// Global state for the current render pass\nexport let beforeDiff: ((vnode: unknown) => void) | undefined;\nexport let beforeDiff2: ((vnode: unknown, context: Record<string, unknown>) => void) | undefined;\nlet afterDiff, renderHook, ummountHook;\n\nexport function renderWithHooks(\n vnode: unknown,\n context: unknown,\n output: unknown[],\n renderVNode: Function,\n result: unknown,\n): unknown[] {\n // Performance optimization: main-thread rendering is synchronous and we\n // therefore don't execute any effects. To do that we pass an empty\n // array to `options._commit` (`__c`). But we can go one step further\n // and avoid a lot of dirty checks and allocations by setting\n // `options._skipEffects` (`__s`) too.\n const previousSkipEffects = options[SKIP_EFFECTS];\n options[SKIP_EFFECTS] = true;\n\n // store options hooks once before each synchronous render call\n beforeDiff = options[DIFF];\n beforeDiff2 = options[DIFF2];\n afterDiff = options[DIFFED];\n renderHook = options[RENDER];\n ummountHook = options.unmount;\n\n const parent = h(Fragment, null);\n parent[CHILDREN] = [vnode];\n\n try {\n renderVNode(\n vnode,\n context || EMPTY_OBJ,\n parent,\n output,\n result,\n );\n } finally {\n // options._commit, we don't schedule any effects in this library right now,\n // so we can pass an empty queue to this hook.\n if (options[COMMIT]) options[COMMIT](vnode, EMPTY_ARR);\n options[SKIP_EFFECTS] = previousSkipEffects;\n EMPTY_ARR.length = 0;\n }\n\n return output;\n}\n\n// Installed as setState/forceUpdate for function components\n/* v8 ignore start */\nfunction markAsDirty() {\n this[BITS] |= COMPONENT_DIRTY;\n}\n/* v8 ignore stop */\n\nexport const EMPTY_OBJ: Record<string, unknown> = {};\n\n/**\n * @param {VNode} vnode\n * @param {Record<string, unknown>} context\n */\nfunction renderClassComponent(vnode, context, globalContext) {\n const type = /** @type {import(\"preact\").ComponentClass<typeof vnode.props>} */ (vnode.type);\n\n let c;\n if (vnode[COMPONENT]) {\n c = vnode[COMPONENT];\n c.state = c[NEXT_STATE];\n } else {\n c = new type(vnode.props, context);\n }\n\n vnode[COMPONENT] = c;\n c[VNODE] = vnode;\n\n c.props = vnode.props;\n c.context = context;\n c[GLOBAL_CONTEXT] = globalContext;\n // turn off stateful re-rendering:\n c[BITS] |= COMPONENT_DIRTY;\n\n if (c.state == null) c.state = EMPTY_OBJ;\n\n if (c[NEXT_STATE] == null) {\n c[NEXT_STATE] = c.state;\n }\n\n if (type.getDerivedStateFromProps) {\n c.state = assign(\n {},\n c.state,\n type.getDerivedStateFromProps(c.props, c.state),\n );\n }\n\n if (renderHook) renderHook(vnode);\n\n return c.render(c.props, c.state, context);\n}\n\nexport function cleanupVNode(vnode: unknown): void {\n if (afterDiff) afterDiff(vnode);\n vnode[PARENT] = undefined;\n if (ummountHook) ummountHook(vnode);\n}\n\nexport function renderComponentVNode(\n vnode: unknown,\n type: unknown,\n props: unknown,\n context: unknown,\n output: unknown[],\n renderVNode: Function,\n result: unknown,\n parentType?: string,\n subtreeHandles?: unknown[],\n listItemUids?: number[],\n): void {\n let cctx = context;\n let rendered;\n let component;\n const outputLength = output.length;\n\n if (type === Fragment) {\n rendered = props.children;\n } else {\n const contextType = type.contextType;\n if (contextType != null) {\n const provider = context[contextType.__c];\n cctx = provider ? provider.props.value : contextType.__;\n }\n\n if (type.prototype && typeof type.prototype.render === 'function') {\n rendered = /**#__NOINLINE__**/ renderClassComponent(vnode, cctx, context);\n component = vnode[COMPONENT];\n } else {\n component = {\n __v: vnode,\n props,\n context: cctx,\n [GLOBAL_CONTEXT]: context,\n // silently drop state updates\n setState: markAsDirty,\n forceUpdate: markAsDirty,\n __g: COMPONENT_DIRTY,\n // hooks\n __h: [],\n };\n vnode[COMPONENT] = component;\n component.constructor = type;\n component.render = doRender;\n\n let count = 0;\n while (component[BITS] & COMPONENT_DIRTY && count++ < 25) {\n component[BITS] &= ~COMPONENT_DIRTY;\n\n if (renderHook) renderHook(vnode);\n\n rendered = component.render(props, component.state, cctx);\n }\n component[BITS] |= COMPONENT_DIRTY;\n }\n\n if (component.getChildContext != null) {\n context = assign({}, context, component.getChildContext());\n }\n }\n\n const isTopLevelFragment = rendered != null && rendered.type === Fragment\n && rendered.key == null;\n rendered = isTopLevelFragment ? rendered.props.children : rendered;\n\n // A Suspense boundary owns the IDs allocated while rendering its children,\n // as well as the entries added to the enclosing commit collectors.\n const checkpoint = component && component.__c\n ? {\n rootSubtreeHandlesLength: result.rootSubtreeHandles.length,\n subtreeHandlesLength: subtreeHandles?.length,\n listItemUidsLength: listItemUids?.length,\n nextId: getNextElementTemplateId(),\n pageAttributes: result.pageAttributes,\n isInsideAuthoredPage: result.isInsideAuthoredPage,\n }\n : undefined;\n\n try {\n renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles, listItemUids);\n } catch (e) {\n if (\n checkpoint && e && typeof e === 'object' && e.then\n ) {\n component.setState({ /* _suspended */ __a: true });\n\n rendered = renderClassComponent(vnode, context, context);\n\n output.length = outputLength;\n result.rootSubtreeHandles.length = checkpoint.rootSubtreeHandlesLength;\n if (subtreeHandles) subtreeHandles.length = checkpoint.subtreeHandlesLength;\n if (listItemUids) listItemUids.length = checkpoint.listItemUidsLength;\n discardRenderedHostsSince(checkpoint.nextId);\n result.pageAttributes = checkpoint.pageAttributes;\n if (__DEV__) result.isInsideAuthoredPage = checkpoint.isInsideAuthoredPage;\n renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles, listItemUids);\n } else {\n throw e;\n }\n } finally {\n cleanupVNode(vnode);\n }\n}\n\n/** The `.render()` method for a PFC backing instance. */\nfunction doRender(props, state, context) {\n return this.constructor(props, context);\n}\n"]}
1
+ {"version":3,"file":"render-components.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/render-components.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACz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C;QACX,IACE,UAAU,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,EAClD,CAAC;YACD,SAAS,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;YAEnD,QAAQ,GAAG,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAEzD,MAAM,CAAC,MAAM,GAAG,YAAY,CAAC;YAC7B,MAAM,CAAC,kBAAkB,CAAC,MAAM,GAAG,UAAU,CAAC,wBAAwB,CAAC;YACvE,IAAI,cAAc;gBAAE,cAAc,CAAC,MAAM,GAAG,UAAU,CAAC,oBAAoB,CAAC;YAC5E,IAAI,YAAY;gBAAE,YAAY,CAAC,MAAM,GAAG,UAAU,CAAC,kBAAkB,CAAC;YACtE,yBAAyB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAC7C,MAAM,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;YAClD,IAAI,OAAO;gBAAE,MAAM,CAAC,oBAAoB,GAAG,UAAU,CAAC,oBAAoB,CAAC;YAC3E,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;QAClG,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,yDAAyD;AACzD,SAAS,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO;IACrC,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAC1C,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 * Synchronous component traversal for Element Template rendering.\n * This module is modified from preact-render-to-string@6.0.3 to generate\n * host output instead of HTML strings for Lynx.\n */\n\n// @ts-nocheck\n\nimport { Fragment, h, options } from 'preact';\n\nimport { discardRenderedHostsSince } from './create-rendered-host.js';\nimport { getNextElementTemplateId } from '../template/handle.js';\n\nimport {\n BITS,\n CHILDREN,\n COMMIT,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DIFF2,\n DIFFED,\n GLOBAL_CONTEXT,\n NEXT_STATE,\n PARENT,\n RENDER,\n SKIP_EFFECTS,\n VNODE,\n} from '../../../shared/render-constants.js';\n\n/** @typedef {import('preact').VNode} VNode */\n\nconst EMPTY_ARR = [];\nconst assign = /* @__PURE__ */ Object.assign;\n\n// Global state for the current render pass\nexport let beforeDiff: ((vnode: unknown) => void) | undefined;\nexport let beforeDiff2: ((vnode: unknown, context: Record<string, unknown>) => void) | undefined;\nlet afterDiff, renderHook, unmountHook;\n\nexport function renderWithHooks(\n vnode: unknown,\n context: unknown,\n output: unknown[],\n renderVNode: Function,\n result: unknown,\n): unknown[] {\n // Performance optimization: main-thread rendering is synchronous and we\n // therefore don't execute any effects. To do that we pass an empty\n // array to `options._commit` (`__c`). But we can go one step further\n // and avoid a lot of dirty checks and allocations by setting\n // `options._skipEffects` (`__s`) too.\n const previousSkipEffects = options[SKIP_EFFECTS];\n options[SKIP_EFFECTS] = true;\n\n // store options hooks once before each synchronous render call\n beforeDiff = options[DIFF];\n beforeDiff2 = options[DIFF2];\n afterDiff = options[DIFFED];\n renderHook = options[RENDER];\n unmountHook = options.unmount;\n\n const parent = h(Fragment, null);\n parent[CHILDREN] = [vnode];\n\n try {\n renderVNode(\n vnode,\n context || EMPTY_OBJ,\n parent,\n output,\n result,\n );\n } finally {\n // options._commit, we don't schedule any effects in this library right now,\n // so we can pass an empty queue to this hook.\n if (options[COMMIT]) options[COMMIT](vnode, EMPTY_ARR);\n options[SKIP_EFFECTS] = previousSkipEffects;\n EMPTY_ARR.length = 0;\n }\n\n return output;\n}\n\n// Installed as setState/forceUpdate for function components\n/* v8 ignore start */\nfunction markAsDirty() {\n this[BITS] |= COMPONENT_DIRTY;\n}\n/* v8 ignore stop */\n\nexport const EMPTY_OBJ: Record<string, unknown> = {};\n\n/**\n * @param {VNode} vnode\n * @param {Record<string, unknown>} context\n */\nfunction renderClassComponent(vnode, context, globalContext) {\n const type = /** @type {import(\"preact\").ComponentClass<typeof vnode.props>} */ (vnode.type);\n\n let c;\n if (vnode[COMPONENT]) {\n c = vnode[COMPONENT];\n c.state = c[NEXT_STATE];\n } else {\n c = new type(vnode.props, context);\n }\n\n vnode[COMPONENT] = c;\n c[VNODE] = vnode;\n\n c.props = vnode.props;\n c.context = context;\n c[GLOBAL_CONTEXT] = globalContext;\n // turn off stateful re-rendering:\n c[BITS] |= COMPONENT_DIRTY;\n\n if (c.state == null) c.state = EMPTY_OBJ;\n\n if (c[NEXT_STATE] == null) {\n c[NEXT_STATE] = c.state;\n }\n\n if (type.getDerivedStateFromProps) {\n c.state = assign(\n {},\n c.state,\n type.getDerivedStateFromProps(c.props, c.state),\n );\n }\n\n if (renderHook) renderHook(vnode);\n\n return c.render(c.props, c.state, context);\n}\n\nexport function cleanupVNode(vnode: unknown): void {\n if (afterDiff) afterDiff(vnode);\n vnode[PARENT] = undefined;\n if (unmountHook) unmountHook(vnode);\n}\n\nexport function renderComponentVNode(\n vnode: unknown,\n type: unknown,\n props: unknown,\n context: unknown,\n output: unknown[],\n renderVNode: Function,\n result: unknown,\n parentType?: string,\n subtreeHandles?: unknown[],\n listItemUids?: number[],\n): void {\n let cctx = context;\n let rendered;\n let component;\n const outputLength = output.length;\n\n if (type === Fragment) {\n rendered = props.children;\n } else {\n const contextType = type.contextType;\n if (contextType != null) {\n const provider = context[contextType.__c];\n cctx = provider ? provider.props.value : contextType.__;\n }\n\n if (type.prototype && typeof type.prototype.render === 'function') {\n rendered = /**#__NOINLINE__**/ renderClassComponent(vnode, cctx, context);\n component = vnode[COMPONENT];\n } else {\n component = {\n __v: vnode,\n props,\n context: cctx,\n [GLOBAL_CONTEXT]: context,\n // silently drop state updates\n setState: markAsDirty,\n forceUpdate: markAsDirty,\n __g: COMPONENT_DIRTY,\n // hooks\n __h: [],\n };\n vnode[COMPONENT] = component;\n component.constructor = type;\n component.render = doRender;\n\n let count = 0;\n while (component[BITS] & COMPONENT_DIRTY && count++ < 25) {\n component[BITS] &= ~COMPONENT_DIRTY;\n\n if (renderHook) renderHook(vnode);\n\n rendered = component.render(props, component.state, cctx);\n }\n component[BITS] |= COMPONENT_DIRTY;\n }\n\n if (component.getChildContext != null) {\n context = assign({}, context, component.getChildContext());\n }\n }\n\n const isTopLevelFragment = rendered != null && rendered.type === Fragment\n && rendered.key == null;\n rendered = isTopLevelFragment ? rendered.props.children : rendered;\n\n // A Suspense boundary owns the IDs allocated while rendering its children,\n // as well as the entries added to the enclosing commit collectors.\n const checkpoint = component && component.__c\n ? {\n rootSubtreeHandlesLength: result.rootSubtreeHandles.length,\n subtreeHandlesLength: subtreeHandles?.length,\n listItemUidsLength: listItemUids?.length,\n nextId: getNextElementTemplateId(),\n pageAttributes: result.pageAttributes,\n isInsideAuthoredPage: result.isInsideAuthoredPage,\n }\n : undefined;\n\n try {\n renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles, listItemUids);\n } catch (e) {\n if (\n checkpoint && e && typeof e === 'object' && e.then\n ) {\n component.setState({ /* _suspended */ __a: true });\n\n rendered = renderClassComponent(vnode, context, context);\n\n output.length = outputLength;\n result.rootSubtreeHandles.length = checkpoint.rootSubtreeHandlesLength;\n if (subtreeHandles) subtreeHandles.length = checkpoint.subtreeHandlesLength;\n if (listItemUids) listItemUids.length = checkpoint.listItemUidsLength;\n discardRenderedHostsSince(checkpoint.nextId);\n result.pageAttributes = checkpoint.pageAttributes;\n if (__DEV__) result.isInsideAuthoredPage = checkpoint.isInsideAuthoredPage;\n renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles, listItemUids);\n } else {\n throw e;\n }\n } finally {\n cleanupVNode(vnode);\n }\n}\n\n/** The `.render()` method for a PFC backing instance. */\nfunction doRender(props, state, context) {\n return this.constructor(props, context);\n}\n"]}
@@ -13,6 +13,7 @@ import { flushInitialElementTemplateListUpdates } from '../list/list.js';
13
13
  import { __page } from '../page/page.js';
14
14
  import { __root } from '../page/root-instance.js';
15
15
  import { insertElementTemplateSubtree } from '../template/handle.js';
16
+ import { applyPendingMainThreadRefAttachments } from '../template/main-thread-dynamic-attr-state.js';
16
17
  import { getElementTemplateNativeRef } from '../template/registry.js';
17
18
  import { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from '../template/typed-attributes.js';
18
19
  function renderMainThread() {
@@ -39,6 +40,7 @@ function renderMainThread() {
39
40
  insertElementTemplateSubtree(__page, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX, rootRef, null, rootSubtreeHandles[index]);
40
41
  }
41
42
  flushInitialListUpdates();
43
+ applyPendingMainThreadRefAttachments();
42
44
  }
43
45
  finally {
44
46
  profileEnd();
@@ -1 +1 @@
1
- {"version":3,"file":"render-main-thread.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/render-main-thread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,gCAAgC,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,EAAE,qCAAqC,EAAE,MAAM,wBAAwB,CAAC;AAE/E,OAAO,EAAE,sCAAsC,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CA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IACpD,IAAI,CAAC;QACH,MAAM,OAAO,GAAwC;YACnD,IAAI,EAAE,0BAA0B,CAAC,MAAM,CAAuB;YAC9D,aAAa,EAAE,gBAAgB,EAAE;SAClC,CAAC;QAEF,IAAI,CAAC,YAAY,EAAE,CAAC,aAAa,CAAC;YAChC,IAAI,EAAE,gCAAgC,CAAC,OAAO;YAC9C,IAAI,EAAE,OAAO;SACd,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,uBAAuB;IAC9B,MAAM,OAAO,GAAG,sCAAsC,EAAE,CAAC;IACzD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACvD,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,2BAA2B,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxD,IAAI,OAAO,EAAE,CAAC;YACZ,+BAA+B,CAAC,OAAO,EAAE,mCAAmC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QACnG,CAAC;IACH,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements the IFR (Instant First-Frame Rendering) on main thread.\n */\n\nimport { renderToElementTemplate } from './render-direct.js';\nimport { getReloadVersion } from '../../../core/reload-version.js';\nimport { profileEnd, profileStart } from '../../debug/profile.js';\nimport { ElementTemplateLifecycleConstant } from '../../protocol/lifecycle-constant.js';\nimport { ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../../protocol/page.js';\nimport type { ElementTemplateHydrateCommitContext, SerializedPageRoot } from '../../protocol/types.js';\nimport { flushInitialElementTemplateListUpdates } from '../list/list.js';\nimport { __page } from '../page/page.js';\nimport { __root } from '../page/root-instance.js';\nimport { insertElementTemplateSubtree } from '../template/handle.js';\nimport { getElementTemplateNativeRef } from '../template/registry.js';\nimport { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from '../template/typed-attributes.js';\n\nfunction renderMainThread(): void {\n let rendered;\n profileStart('ReactLynx::renderMainThread');\n try {\n rendered = renderToElementTemplate(__root.__jsx, undefined);\n } catch (error) {\n // Like Snapshot, any failure during synchronous rendering is reported at\n // the lifecycle boundary before committing an empty result.\n lynx.reportError(error as Error);\n rendered = { pageAttributes: null, rootRefs: [], rootSubtreeHandles: [] };\n } finally {\n profileEnd();\n }\n\n profileStart('ReactLynx::commitElementTemplate');\n try {\n const { pageAttributes, rootRefs, rootSubtreeHandles } = rendered;\n __SetAttributeOfElementTemplate(__page, TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, pageAttributes);\n for (let index = 0; index < rootRefs.length; index += 1) {\n const rootRef = rootRefs[index]!;\n insertElementTemplateSubtree(\n __page,\n ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX,\n rootRef,\n null,\n rootSubtreeHandles[index]!,\n );\n }\n flushInitialListUpdates();\n } finally {\n profileEnd();\n }\n\n profileStart('ReactLynx::packSerializedETInstance');\n try {\n const payload: ElementTemplateHydrateCommitContext = {\n page: __SerializeElementTemplate(__page) as SerializedPageRoot,\n reloadVersion: getReloadVersion(),\n };\n\n lynx.getJSContext().dispatchEvent({\n type: ElementTemplateLifecycleConstant.hydrate,\n data: payload,\n });\n } finally {\n profileEnd();\n }\n}\n\nfunction flushInitialListUpdates(): void {\n const results = flushInitialElementTemplateListUpdates();\n for (let index = 0; index < results.length; index += 1) {\n const result = results[index]!;\n const listRef = getElementTemplateNativeRef(result.uid);\n if (listRef) {\n __SetAttributeOfElementTemplate(listRef, TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, result.attributes);\n }\n }\n}\n\nexport { renderMainThread };\n"]}
1
+ {"version":3,"file":"render-main-thread.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/render-main-thread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,gCAAgC,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,EAAE,qCAAqC,EAAE,MAAM,wBAAwB,CAAC;AAE/E,OAAO,EAAE,sCAAsC,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,oCAAoC,EAAE,MAAM,+CAA+C,CAAC;AACrG,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,mCAAmC,EAAE,MAAM,iCAAiC,CAAC;AAEtF,SAAS,gBAAgB;IACvB,IAAI,QAAQ,CAAC;IACb,YAAY,CAAC,6BAA6B,CAAC,CAAC;IAC5C,IAAI,CAAC;QACH,QAAQ,GAAG,uBAAuB,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC9D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,yEAAyE;QACzE,4DAA4D;QAC5D,IAAI,CAAC,WAAW,CAAC,KAAc,CAAC,CAAC;QACjC,QAAQ,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,CAAC;IAC5E,CAAC;YAAS,CAAC;QACT,UAAU,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AAG,2BAA2B,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxD,IAAI,OAAO,EAAE,CAAC;YACZ,+BAA+B,CAAC,OAAO,EAAE,mCAAmC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QACnG,CAAC;IACH,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements the IFR (Instant First-Frame Rendering) on main thread.\n */\n\nimport { renderToElementTemplate } from './render-direct.js';\nimport { getReloadVersion } from '../../../core/reload-version.js';\nimport { profileEnd, profileStart } from '../../debug/profile.js';\nimport { ElementTemplateLifecycleConstant } from '../../protocol/lifecycle-constant.js';\nimport { ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../../protocol/page.js';\nimport type { ElementTemplateHydrateCommitContext, SerializedPageRoot } from '../../protocol/types.js';\nimport { flushInitialElementTemplateListUpdates } from '../list/list.js';\nimport { __page } from '../page/page.js';\nimport { __root } from '../page/root-instance.js';\nimport { insertElementTemplateSubtree } from '../template/handle.js';\nimport { applyPendingMainThreadRefAttachments } from '../template/main-thread-dynamic-attr-state.js';\nimport { getElementTemplateNativeRef } from '../template/registry.js';\nimport { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from '../template/typed-attributes.js';\n\nfunction renderMainThread(): void {\n let rendered;\n profileStart('ReactLynx::renderMainThread');\n try {\n rendered = renderToElementTemplate(__root.__jsx, undefined);\n } catch (error) {\n // Like Snapshot, any failure during synchronous rendering is reported at\n // the lifecycle boundary before committing an empty result.\n lynx.reportError(error as Error);\n rendered = { pageAttributes: null, rootRefs: [], rootSubtreeHandles: [] };\n } finally {\n profileEnd();\n }\n\n profileStart('ReactLynx::commitElementTemplate');\n try {\n const { pageAttributes, rootRefs, rootSubtreeHandles } = rendered;\n __SetAttributeOfElementTemplate(__page, TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, pageAttributes);\n for (let index = 0; index < rootRefs.length; index += 1) {\n const rootRef = rootRefs[index]!;\n insertElementTemplateSubtree(\n __page,\n ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX,\n rootRef,\n null,\n rootSubtreeHandles[index]!,\n );\n }\n flushInitialListUpdates();\n applyPendingMainThreadRefAttachments();\n } finally {\n profileEnd();\n }\n\n profileStart('ReactLynx::packSerializedETInstance');\n try {\n const payload: ElementTemplateHydrateCommitContext = {\n page: __SerializeElementTemplate(__page) as SerializedPageRoot,\n reloadVersion: getReloadVersion(),\n };\n\n lynx.getJSContext().dispatchEvent({\n type: ElementTemplateLifecycleConstant.hydrate,\n data: payload,\n });\n } finally {\n profileEnd();\n }\n}\n\nfunction flushInitialListUpdates(): void {\n const results = flushInitialElementTemplateListUpdates();\n for (let index = 0; index < results.length; index += 1) {\n const result = results[index]!;\n const listRef = getElementTemplateNativeRef(result.uid);\n if (listRef) {\n __SetAttributeOfElementTemplate(listRef, TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, result.attributes);\n }\n }\n}\n\nexport { renderMainThread };\n"]}
@@ -5,7 +5,7 @@ import { clearDelayedRunOnBackgroundFunctions, retainWorkletCtx } from '@lynx-js
5
5
  import { createBackgroundFunctionHandle } from '../../../core/background-function/handle.js';
6
6
  import { registerBackgroundFunctionCtx, resetBackgroundFunctionRuntime, runOnBackground, } from '../../../core/background-function/run-on-background.js';
7
7
  import { resetFunctionCallReturnListener } from '../../../core/thread-function-call/return-value.js';
8
- import { isRunOnBackgroundEnabled } from '../../../worklet-runtime/jsFunctionLifecycle.js';
8
+ import { JsFunctionLifecycleManager, isRunOnBackgroundEnabled } from '../../../worklet-runtime/jsFunctionLifecycle.js';
9
9
  /**
10
10
  * @internal transform-generated runtime helper for background JS function handles.
11
11
  */
@@ -16,6 +16,8 @@ export function registerMainThreadBackgroundFunctionCtx(ctx) {
16
16
  registerBackgroundFunctionCtx(ctx);
17
17
  }
18
18
  }
19
+ // Track the input before Native takes ownership. If Native rejects it, collection
20
+ // must still release its already-registered background execution; slot state commits later.
19
21
  export function retainMainThreadBackgroundFunctionCtx(ctx) {
20
22
  retainWorkletCtx(ctx);
21
23
  }
@@ -24,6 +26,11 @@ export function resetElementTemplateBackgroundFunctionRuntime() {
24
26
  resetFunctionCallReturnListener();
25
27
  }
26
28
  export function resetElementTemplateMainThreadBackgroundFunctionRuntime() {
29
+ const manager = globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager;
30
+ if (manager) {
31
+ manager.dispose();
32
+ globalThis.lynxWorkletImpl._jsFunctionLifecycleManager = new JsFunctionLifecycleManager();
33
+ }
27
34
  clearDelayedRunOnBackgroundFunctions();
28
35
  resetFunctionCallReturnListener();
29
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"main-thread-background-function.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-background-function.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,oCAAoC,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAEjH,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EACL,6BAA6B,EAC7B,8BAA8B,EAC9B,eAAe,GAChB,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;AAU3F;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,MAAM,UAAU,uCAAuC,CAAC,GAAoC;IAC1F,IAAI,MAAM,IAAI,wBAAwB,EAAE,EAAE,CAAC;QACzC,6BAA6B,CAAC,GAA4B,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED,MAAM,UAAU,qCAAqC,CAAC,GAAoC;IACxF,gBAAgB,CAAC,GAA8B,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,6CAA6C;IAC3D,8BAA8B,EAAE,CAAC;IACjC,+BAA+B,EAAE,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,uDAAuD;IACrE,oCAAoC,EAAE,CAAC;IACvC,+BAA+B,EAAE,CAAC;AACpC,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 { clearDelayedRunOnBackgroundFunctions, retainWorkletCtx } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { createBackgroundFunctionHandle } from '../../../core/background-function/handle.js';\nimport {\n registerBackgroundFunctionCtx,\n resetBackgroundFunctionRuntime,\n runOnBackground,\n} from '../../../core/background-function/run-on-background.js';\nimport { resetFunctionCallReturnListener } from '../../../core/thread-function-call/return-value.js';\nimport { isRunOnBackgroundEnabled } from '../../../worklet-runtime/jsFunctionLifecycle.js';\n\ntype BackgroundFunctionCtx = Parameters<typeof registerBackgroundFunctionCtx>[0];\ntype RetainableMainThreadCtx = Parameters<typeof retainWorkletCtx>[0];\n\ninterface MainThreadBackgroundFunctionCtx {\n _wkltId: string;\n [key: string]: unknown;\n}\n\n/**\n * @internal transform-generated runtime helper for background JS function handles.\n */\nexport const transformToWorklet = createBackgroundFunctionHandle;\nexport { runOnBackground };\n\nexport function registerMainThreadBackgroundFunctionCtx(ctx: MainThreadBackgroundFunctionCtx): void {\n if (__JS__ && isRunOnBackgroundEnabled()) {\n registerBackgroundFunctionCtx(ctx as BackgroundFunctionCtx);\n }\n}\n\nexport function retainMainThreadBackgroundFunctionCtx(ctx: MainThreadBackgroundFunctionCtx): void {\n retainWorkletCtx(ctx as RetainableMainThreadCtx);\n}\n\nexport function resetElementTemplateBackgroundFunctionRuntime(): void {\n resetBackgroundFunctionRuntime();\n resetFunctionCallReturnListener();\n}\n\nexport function resetElementTemplateMainThreadBackgroundFunctionRuntime(): void {\n clearDelayedRunOnBackgroundFunctions();\n resetFunctionCallReturnListener();\n}\n"]}
1
+ {"version":3,"file":"main-thread-background-function.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-background-function.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,oCAAoC,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAEjH,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EACL,6BAA6B,EAC7B,8BAA8B,EAC9B,eAAe,GAChB,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;AAUvH;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,MAAM,UAAU,uCAAuC,CAAC,GAAoC;IAC1F,IAAI,MAAM,IAAI,wBAAwB,EAAE,EAAE,CAAC;QACzC,6BAA6B,CAAC,GAA4B,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED,kFAAkF;AAClF,4FAA4F;AAC5F,MAAM,UAAU,qCAAqC,CAAC,GAAoC;IACxF,gBAAgB,CAAC,GAA8B,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,6CAA6C;IAC3D,8BAA8B,EAAE,CAAC;IACjC,+BAA+B,EAAE,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,uDAAuD;IACrE,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,EAAE,2BAA2B,CAAC;IACxE,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,OAAO,EAAE,CAAC;QAClB,UAAU,CAAC,eAAe,CAAC,2BAA2B,GAAG,IAAI,0BAA0B,EAAE,CAAC;IAC5F,CAAC;IACD,oCAAoC,EAAE,CAAC;IACvC,+BAA+B,EAAE,CAAC;AACpC,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 { clearDelayedRunOnBackgroundFunctions, retainWorkletCtx } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { createBackgroundFunctionHandle } from '../../../core/background-function/handle.js';\nimport {\n registerBackgroundFunctionCtx,\n resetBackgroundFunctionRuntime,\n runOnBackground,\n} from '../../../core/background-function/run-on-background.js';\nimport { resetFunctionCallReturnListener } from '../../../core/thread-function-call/return-value.js';\nimport { JsFunctionLifecycleManager, isRunOnBackgroundEnabled } from '../../../worklet-runtime/jsFunctionLifecycle.js';\n\ntype BackgroundFunctionCtx = Parameters<typeof registerBackgroundFunctionCtx>[0];\ntype RetainableMainThreadCtx = Parameters<typeof retainWorkletCtx>[0];\n\ninterface MainThreadBackgroundFunctionCtx {\n _wkltId: string;\n [key: string]: unknown;\n}\n\n/**\n * @internal transform-generated runtime helper for background JS function handles.\n */\nexport const transformToWorklet = createBackgroundFunctionHandle;\nexport { runOnBackground };\n\nexport function registerMainThreadBackgroundFunctionCtx(ctx: MainThreadBackgroundFunctionCtx): void {\n if (__JS__ && isRunOnBackgroundEnabled()) {\n registerBackgroundFunctionCtx(ctx as BackgroundFunctionCtx);\n }\n}\n\n// Track the input before Native takes ownership. If Native rejects it, collection\n// must still release its already-registered background execution; slot state commits later.\nexport function retainMainThreadBackgroundFunctionCtx(ctx: MainThreadBackgroundFunctionCtx): void {\n retainWorkletCtx(ctx as RetainableMainThreadCtx);\n}\n\nexport function resetElementTemplateBackgroundFunctionRuntime(): void {\n resetBackgroundFunctionRuntime();\n resetFunctionCallReturnListener();\n}\n\nexport function resetElementTemplateMainThreadBackgroundFunctionRuntime(): void {\n const manager = globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager;\n if (manager) {\n manager.dispose();\n globalThis.lynxWorkletImpl._jsFunctionLifecycleManager = new JsFunctionLifecycleManager();\n }\n clearDelayedRunOnBackgroundFunctions();\n resetFunctionCallReturnListener();\n}\n"]}
@@ -19,6 +19,7 @@ export declare function initializeMainThreadDynamicAttrSlots(handleId: number, t
19
19
  export declare function updateMainThreadEventAttrSlot(handleId: number, attrSlotIndex: number, value: unknown, isHydration?: boolean): void;
20
20
  export declare function updateMainThreadRefAttrSlot(handleId: number, attrSlotIndex: number, value: unknown, nativeRef: ElementTemplateHandle, isHydration?: boolean): void;
21
21
  export declare function attachMainThreadDynamicAttrRefsForSubtree(handles: readonly MainThreadDynamicAttrSubtreeHandle[]): void;
22
+ export declare function applyPendingMainThreadRefAttachments(): void;
22
23
  export declare function detachMainThreadDynamicAttrRefsForSubtree(handles: readonly MainThreadDynamicAttrSubtreeHandle[]): void;
23
24
  export declare function deleteMainThreadDynamicAttrStateForSubtree(handleIds: readonly number[]): void;
24
25
  export {};
@@ -7,7 +7,8 @@ import { retainMainThreadBackgroundFunctionCtx } from './main-thread-background-
7
7
  import { attachMTRefValue, cleanupMTRefValue, hydrateMTRefValue, retainMTRefValue } from './main-thread-ref-ctx.js';
8
8
  const mtEventAttrState = new Map();
9
9
  const mtRefAttrState = new Map();
10
- const materializedMTRefHandleIds = new Set();
10
+ const attachedMTRefHandleIds = new Set();
11
+ let pendingMTRefAttachments = [];
11
12
  function deleteSlotState(state, handleId, attrSlotIndex) {
12
13
  const handleState = state.get(handleId);
13
14
  if (!handleState) {
@@ -32,7 +33,6 @@ function setSlotState(state, handleId, attrSlotIndex, value) {
32
33
  handleState.set(attrSlotIndex, value);
33
34
  }
34
35
  function setMTEventSlotState(handleId, attrSlotIndex, nativeHeldValue) {
35
- retainMainThreadBackgroundFunctionCtx(nativeHeldValue);
36
36
  setSlotState(mtEventAttrState, handleId, attrSlotIndex, nativeHeldValue);
37
37
  }
38
38
  function setMTRefSlotState(handleId, attrSlotIndex, value) {
@@ -49,6 +49,9 @@ export function prepareMainThreadDynamicAttrSlotsForNative(templateType, attribu
49
49
  }
50
50
  let nativeSlots;
51
51
  for (const [attrSlotIndex, kind] of slotKinds) {
52
+ if (kind === 'mt-event' && attributeSlots[attrSlotIndex] != null) {
53
+ retainMainThreadBackgroundFunctionCtx(attributeSlots[attrSlotIndex].value);
54
+ }
52
55
  if (kind !== 'mt-ref') {
53
56
  continue;
54
57
  }
@@ -58,14 +61,19 @@ export function prepareMainThreadDynamicAttrSlotsForNative(templateType, attribu
58
61
  return nativeSlots ?? attributeSlots;
59
62
  }
60
63
  export function clearMainThreadDynamicAttrState() {
61
- for (const [handleId, handleState] of mtRefAttrState) {
62
- if (materializedMTRefHandleIds.has(handleId)) {
63
- cleanupMTRefHandleState(handleState);
64
+ try {
65
+ for (const [handleId, handleState] of mtRefAttrState) {
66
+ if (attachedMTRefHandleIds.has(handleId)) {
67
+ cleanupMTRefHandleState(handleState);
68
+ }
64
69
  }
65
70
  }
66
- mtEventAttrState.clear();
67
- mtRefAttrState.clear();
68
- materializedMTRefHandleIds.clear();
71
+ finally {
72
+ mtEventAttrState.clear();
73
+ mtRefAttrState.clear();
74
+ attachedMTRefHandleIds.clear();
75
+ pendingMTRefAttachments = [];
76
+ }
69
77
  }
70
78
  export function getMainThreadDynamicAttrState(handleId, attrSlotIndex) {
71
79
  const event = mtEventAttrState.get(handleId)?.get(attrSlotIndex);
@@ -106,15 +114,15 @@ export function updateMainThreadEventAttrSlot(handleId, attrSlotIndex, value, is
106
114
  }
107
115
  export function updateMainThreadRefAttrSlot(handleId, attrSlotIndex, value, nativeRef, isHydration = false) {
108
116
  const previousState = mtRefAttrState.get(handleId)?.get(attrSlotIndex);
109
- const isMaterialized = materializedMTRefHandleIds.has(handleId);
117
+ const isAttached = attachedMTRefHandleIds.has(handleId);
110
118
  if (value == null) {
111
- if (previousState && isMaterialized) {
119
+ if (previousState && isAttached) {
112
120
  cleanupMTRefValue(previousState);
113
121
  }
114
122
  deleteSlotState(mtRefAttrState, handleId, attrSlotIndex);
115
123
  return;
116
124
  }
117
- if (previousState && isMaterialized) {
125
+ if (previousState && isAttached) {
118
126
  cleanupMTRefValue(previousState);
119
127
  }
120
128
  const nextValue = value.value;
@@ -122,33 +130,45 @@ export function updateMainThreadRefAttrSlot(handleId, attrSlotIndex, value, nati
122
130
  if (isHydration) {
123
131
  hydrateMTRefValue(nextValue, previousState);
124
132
  }
125
- if (isMaterialized) {
126
- attachMTRefValue(nextValue, nativeRef);
133
+ if (isAttached) {
134
+ pendingMTRefAttachments.push({ handleId, attrSlotIndex, value: nextValue, nativeRef });
127
135
  }
128
136
  }
129
137
  export function attachMainThreadDynamicAttrRefsForSubtree(handles) {
130
138
  for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {
131
139
  const handle = handles[handleIndex];
132
- if (materializedMTRefHandleIds.has(handle.uid)) {
140
+ if (attachedMTRefHandleIds.has(handle.uid)) {
133
141
  continue;
134
142
  }
135
- materializedMTRefHandleIds.add(handle.uid);
143
+ attachedMTRefHandleIds.add(handle.uid);
136
144
  const handleState = mtRefAttrState.get(handle.uid);
137
145
  if (!handleState) {
138
146
  continue;
139
147
  }
140
- for (const value of handleState.values()) {
141
- attachMTRefValue(value, handle.ref);
148
+ for (const [attrSlotIndex, value] of handleState) {
149
+ pendingMTRefAttachments.push({ handleId: handle.uid, attrSlotIndex, value, nativeRef: handle.ref });
150
+ }
151
+ }
152
+ }
153
+ // Consume one queue snapshot, matching Snapshot's ref delivery boundary.
154
+ export function applyPendingMainThreadRefAttachments() {
155
+ const pending = pendingMTRefAttachments;
156
+ pendingMTRefAttachments = [];
157
+ for (const { handleId, attrSlotIndex, value, nativeRef } of pending) {
158
+ const element = __GetElementByAttrSlot(nativeRef, attrSlotIndex);
159
+ if (!element) {
160
+ throw new Error(`ElementTemplate main-thread:ref target ${handleId}:${attrSlotIndex} could not be materialized.`);
142
161
  }
162
+ attachMTRefValue(value, element);
143
163
  }
144
164
  }
145
165
  export function detachMainThreadDynamicAttrRefsForSubtree(handles) {
146
166
  for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {
147
167
  const handleId = handles[handleIndex].uid;
148
- if (!materializedMTRefHandleIds.has(handleId)) {
168
+ if (!attachedMTRefHandleIds.has(handleId)) {
149
169
  continue;
150
170
  }
151
- materializedMTRefHandleIds.delete(handleId);
171
+ attachedMTRefHandleIds.delete(handleId);
152
172
  const handleState = mtRefAttrState.get(handleId);
153
173
  if (handleState) {
154
174
  cleanupMTRefHandleState(handleState);
@@ -158,10 +178,10 @@ export function detachMainThreadDynamicAttrRefsForSubtree(handles) {
158
178
  export function deleteMainThreadDynamicAttrStateForSubtree(handleIds) {
159
179
  for (const handleId of handleIds) {
160
180
  const handleState = mtRefAttrState.get(handleId);
161
- if (handleState && materializedMTRefHandleIds.has(handleId)) {
181
+ if (handleState && attachedMTRefHandleIds.has(handleId)) {
162
182
  cleanupMTRefHandleState(handleState);
163
183
  }
164
- materializedMTRefHandleIds.delete(handleId);
184
+ attachedMTRefHandleIds.delete(handleId);
165
185
  mtEventAttrState.delete(handleId);
166
186
  mtRefAttrState.delete(handleId);
167
187
  }
@@ -1 +1 @@
1
- {"version":3,"file":"main-thread-dynamic-attr-state.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAG5E,OAAO,EAAE,iCAAiC,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,qCAAqC,EAAE,MAAM,sCAAsC,CAAC;AAE7F,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAUpH,MAAM,gBAAgB,GAA8C,IAAI,GAAG,EAAE,CAAC;AAC9E,MAAM,cAAc,GAA8C,IAAI,GAA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WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACjD,IAAI,WAAW,IAAI,0BAA0B,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5D,uBAAuB,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QACD,0BAA0B,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5C,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,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 { hydrateWorkletCtx } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { getMainThreadDynamicAttrSlotKinds } from './attr-slot-plan.js';\nimport { retainMainThreadBackgroundFunctionCtx } from './main-thread-background-function.js';\nimport type { MTEventCtx, MTEventNativeWrapper } from './main-thread-event-ctx.js';\nimport { attachMTRefValue, cleanupMTRefValue, hydrateMTRefValue, retainMTRefValue } from './main-thread-ref-ctx.js';\nimport type { MTRefNativeWrapper, MTRefValue } from './main-thread-ref-ctx.js';\nimport type { SerializableValue } from '../../protocol/types.js';\n\ntype MainThreadDynamicAttrState =\n | { kind: 'mt-event'; nativeHeldValue: MTEventCtx }\n | { kind: 'mt-ref'; value: MTRefValue };\n\ntype MainThreadDynamicAttrStateMap<T> = Map<number, Map<number, T>>;\n\nconst mtEventAttrState: MainThreadDynamicAttrStateMap<MTEventCtx> = new Map();\nconst mtRefAttrState: MainThreadDynamicAttrStateMap<MTRefValue> = new Map();\nconst materializedMTRefHandleIds = new Set<number>();\n\nexport interface MainThreadDynamicAttrSubtreeHandle {\n uid: number;\n ref: ElementTemplateHandle;\n}\n\nfunction deleteSlotState<T>(\n state: MainThreadDynamicAttrStateMap<T>,\n handleId: number,\n attrSlotIndex: number,\n): void {\n const handleState = state.get(handleId);\n if (!handleState) {\n return;\n }\n handleState.delete(attrSlotIndex);\n if (handleState.size === 0) {\n state.delete(handleId);\n }\n}\n\nfunction cleanupMTRefHandleState(handleState: Map<number, MTRefValue>): void {\n for (const value of handleState.values()) {\n cleanupMTRefValue(value);\n }\n}\n\nfunction setSlotState<T>(\n state: MainThreadDynamicAttrStateMap<T>,\n handleId: number,\n attrSlotIndex: number,\n value: T,\n): void {\n let handleState = state.get(handleId);\n if (!handleState) {\n handleState = new Map();\n state.set(handleId, handleState);\n }\n handleState.set(attrSlotIndex, value);\n}\n\nfunction setMTEventSlotState(handleId: number, attrSlotIndex: number, nativeHeldValue: MTEventCtx): void {\n retainMainThreadBackgroundFunctionCtx(nativeHeldValue);\n setSlotState(mtEventAttrState, handleId, attrSlotIndex, nativeHeldValue);\n}\n\nfunction setMTRefSlotState(\n handleId: number,\n attrSlotIndex: number,\n value: MTRefValue,\n): void {\n retainMTRefValue(value);\n setSlotState(mtRefAttrState, handleId, attrSlotIndex, value);\n}\n\nexport function prepareMainThreadDynamicAttrSlotsForNative(\n templateType: string,\n attributeSlots: readonly unknown[] | null | undefined,\n): SerializableValue[] | null | undefined {\n if (attributeSlots == null) {\n return attributeSlots;\n }\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n if (!slotKinds) {\n return attributeSlots as SerializableValue[];\n }\n let nativeSlots: SerializableValue[] | undefined;\n for (const [attrSlotIndex, kind] of slotKinds) {\n if (kind !== 'mt-ref') {\n continue;\n }\n nativeSlots ??= attributeSlots.slice() as SerializableValue[];\n nativeSlots[attrSlotIndex] = null;\n }\n return nativeSlots ?? attributeSlots as SerializableValue[];\n}\n\nexport function clearMainThreadDynamicAttrState(): void {\n for (const [handleId, handleState] of mtRefAttrState) {\n if (materializedMTRefHandleIds.has(handleId)) {\n cleanupMTRefHandleState(handleState);\n }\n }\n mtEventAttrState.clear();\n mtRefAttrState.clear();\n materializedMTRefHandleIds.clear();\n}\n\nexport function getMainThreadDynamicAttrState(\n handleId: number,\n attrSlotIndex: number,\n): MainThreadDynamicAttrState | undefined {\n const event = mtEventAttrState.get(handleId)?.get(attrSlotIndex);\n if (event) {\n return { kind: 'mt-event', nativeHeldValue: event };\n }\n const ref = mtRefAttrState.get(handleId)?.get(attrSlotIndex);\n return ref ? { kind: 'mt-ref', value: ref } : undefined;\n}\n\nexport function initializeMainThreadDynamicAttrSlots(\n handleId: number,\n templateType: string,\n attributeSlots: readonly unknown[] | null | undefined,\n): void {\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n if (!slotKinds) {\n return;\n }\n for (const [attrSlotIndex, kind] of slotKinds) {\n const value = attributeSlots?.[attrSlotIndex];\n if (kind === 'mt-event' && value != null) {\n setMTEventSlotState(handleId, attrSlotIndex, (value as MTEventNativeWrapper).value);\n } else if (kind === 'mt-ref' && value != null) {\n setMTRefSlotState(handleId, attrSlotIndex, (value as MTRefNativeWrapper).value);\n }\n }\n}\n\nexport function updateMainThreadEventAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n isHydration = false,\n): void {\n const previousState = isHydration\n ? mtEventAttrState.get(handleId)?.get(attrSlotIndex)\n : undefined;\n if (value == null) {\n deleteSlotState(mtEventAttrState, handleId, attrSlotIndex);\n return;\n }\n const nextValue = (value as MTEventNativeWrapper).value;\n setMTEventSlotState(handleId, attrSlotIndex, nextValue);\n if (previousState) {\n hydrateWorkletCtx(\n nextValue as Worklet,\n previousState as Worklet,\n );\n }\n}\n\nexport function updateMainThreadRefAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n nativeRef: ElementTemplateHandle,\n isHydration = false,\n): void {\n const previousState = mtRefAttrState.get(handleId)?.get(attrSlotIndex);\n const isMaterialized = materializedMTRefHandleIds.has(handleId);\n if (value == null) {\n if (previousState && isMaterialized) {\n cleanupMTRefValue(previousState);\n }\n deleteSlotState(mtRefAttrState, handleId, attrSlotIndex);\n return;\n }\n if (previousState && isMaterialized) {\n cleanupMTRefValue(previousState);\n }\n const nextValue = (value as MTRefNativeWrapper).value;\n setMTRefSlotState(handleId, attrSlotIndex, nextValue);\n if (isHydration) {\n hydrateMTRefValue(nextValue, previousState);\n }\n if (isMaterialized) {\n attachMTRefValue(nextValue, nativeRef);\n }\n}\n\nexport function attachMainThreadDynamicAttrRefsForSubtree(\n handles: readonly MainThreadDynamicAttrSubtreeHandle[],\n): void {\n for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {\n const handle = handles[handleIndex]!;\n if (materializedMTRefHandleIds.has(handle.uid)) {\n continue;\n }\n materializedMTRefHandleIds.add(handle.uid);\n const handleState = mtRefAttrState.get(handle.uid);\n if (!handleState) {\n continue;\n }\n for (const value of handleState.values()) {\n attachMTRefValue(value, handle.ref);\n }\n }\n}\n\nexport function detachMainThreadDynamicAttrRefsForSubtree(\n handles: readonly MainThreadDynamicAttrSubtreeHandle[],\n): void {\n for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {\n const handleId = handles[handleIndex]!.uid;\n if (!materializedMTRefHandleIds.has(handleId)) {\n continue;\n }\n materializedMTRefHandleIds.delete(handleId);\n const handleState = mtRefAttrState.get(handleId);\n if (handleState) {\n cleanupMTRefHandleState(handleState);\n }\n }\n}\n\nexport function deleteMainThreadDynamicAttrStateForSubtree(\n handleIds: readonly number[],\n): void {\n for (const handleId of handleIds) {\n const handleState = mtRefAttrState.get(handleId);\n if (handleState && materializedMTRefHandleIds.has(handleId)) {\n cleanupMTRefHandleState(handleState);\n }\n materializedMTRefHandleIds.delete(handleId);\n mtEventAttrState.delete(handleId);\n mtRefAttrState.delete(handleId);\n }\n}\n"]}
1
+ {"version":3,"file":"main-thread-dynamic-attr-state.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,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CAAC,CAAC;QACjD,IAAI,WAAW,IAAI,sBAAsB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxD,uBAAuB,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QACD,sBAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACxC,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,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 { hydrateWorkletCtx } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { getMainThreadDynamicAttrSlotKinds } from './attr-slot-plan.js';\nimport { retainMainThreadBackgroundFunctionCtx } from './main-thread-background-function.js';\nimport type { MTEventCtx, MTEventNativeWrapper } from './main-thread-event-ctx.js';\nimport { attachMTRefValue, cleanupMTRefValue, hydrateMTRefValue, retainMTRefValue } from './main-thread-ref-ctx.js';\nimport type { MTRefNativeWrapper, MTRefValue } from './main-thread-ref-ctx.js';\nimport type { SerializableValue } from '../../protocol/types.js';\n\ntype MainThreadDynamicAttrState =\n | { kind: 'mt-event'; nativeHeldValue: MTEventCtx }\n | { kind: 'mt-ref'; value: MTRefValue };\n\ntype MainThreadDynamicAttrStateMap<T> = Map<number, Map<number, T>>;\n\nconst mtEventAttrState: MainThreadDynamicAttrStateMap<MTEventCtx> = new Map();\nconst mtRefAttrState: MainThreadDynamicAttrStateMap<MTRefValue> = new Map();\nconst attachedMTRefHandleIds = new Set<number>();\n\ninterface PendingMTRefAttachment {\n handleId: number;\n attrSlotIndex: number;\n value: MTRefValue;\n nativeRef: ElementTemplateHandle;\n}\n\nlet pendingMTRefAttachments: PendingMTRefAttachment[] = [];\n\nexport interface MainThreadDynamicAttrSubtreeHandle {\n uid: number;\n ref: ElementTemplateHandle;\n}\n\nfunction deleteSlotState<T>(\n state: MainThreadDynamicAttrStateMap<T>,\n handleId: number,\n attrSlotIndex: number,\n): void {\n const handleState = state.get(handleId);\n if (!handleState) {\n return;\n }\n handleState.delete(attrSlotIndex);\n if (handleState.size === 0) {\n state.delete(handleId);\n }\n}\n\nfunction cleanupMTRefHandleState(handleState: Map<number, MTRefValue>): void {\n for (const value of handleState.values()) {\n cleanupMTRefValue(value);\n }\n}\n\nfunction setSlotState<T>(\n state: MainThreadDynamicAttrStateMap<T>,\n handleId: number,\n attrSlotIndex: number,\n value: T,\n): void {\n let handleState = state.get(handleId);\n if (!handleState) {\n handleState = new Map();\n state.set(handleId, handleState);\n }\n handleState.set(attrSlotIndex, value);\n}\n\nfunction setMTEventSlotState(handleId: number, attrSlotIndex: number, nativeHeldValue: MTEventCtx): void {\n setSlotState(mtEventAttrState, handleId, attrSlotIndex, nativeHeldValue);\n}\n\nfunction setMTRefSlotState(\n handleId: number,\n attrSlotIndex: number,\n value: MTRefValue,\n): void {\n retainMTRefValue(value);\n setSlotState(mtRefAttrState, handleId, attrSlotIndex, value);\n}\n\nexport function prepareMainThreadDynamicAttrSlotsForNative(\n templateType: string,\n attributeSlots: readonly unknown[] | null | undefined,\n): SerializableValue[] | null | undefined {\n if (attributeSlots == null) {\n return attributeSlots;\n }\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n if (!slotKinds) {\n return attributeSlots as SerializableValue[];\n }\n let nativeSlots: SerializableValue[] | undefined;\n for (const [attrSlotIndex, kind] of slotKinds) {\n if (kind === 'mt-event' && attributeSlots[attrSlotIndex] != null) {\n retainMainThreadBackgroundFunctionCtx((attributeSlots[attrSlotIndex] as MTEventNativeWrapper).value);\n }\n if (kind !== 'mt-ref') {\n continue;\n }\n nativeSlots ??= attributeSlots.slice() as SerializableValue[];\n nativeSlots[attrSlotIndex] = null;\n }\n return nativeSlots ?? attributeSlots as SerializableValue[];\n}\n\nexport function clearMainThreadDynamicAttrState(): void {\n try {\n for (const [handleId, handleState] of mtRefAttrState) {\n if (attachedMTRefHandleIds.has(handleId)) {\n cleanupMTRefHandleState(handleState);\n }\n }\n } finally {\n mtEventAttrState.clear();\n mtRefAttrState.clear();\n attachedMTRefHandleIds.clear();\n pendingMTRefAttachments = [];\n }\n}\n\nexport function getMainThreadDynamicAttrState(\n handleId: number,\n attrSlotIndex: number,\n): MainThreadDynamicAttrState | undefined {\n const event = mtEventAttrState.get(handleId)?.get(attrSlotIndex);\n if (event) {\n return { kind: 'mt-event', nativeHeldValue: event };\n }\n const ref = mtRefAttrState.get(handleId)?.get(attrSlotIndex);\n return ref ? { kind: 'mt-ref', value: ref } : undefined;\n}\n\nexport function initializeMainThreadDynamicAttrSlots(\n handleId: number,\n templateType: string,\n attributeSlots: readonly unknown[] | null | undefined,\n): void {\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n if (!slotKinds) {\n return;\n }\n for (const [attrSlotIndex, kind] of slotKinds) {\n const value = attributeSlots?.[attrSlotIndex];\n if (kind === 'mt-event' && value != null) {\n setMTEventSlotState(handleId, attrSlotIndex, (value as MTEventNativeWrapper).value);\n } else if (kind === 'mt-ref' && value != null) {\n setMTRefSlotState(handleId, attrSlotIndex, (value as MTRefNativeWrapper).value);\n }\n }\n}\n\nexport function updateMainThreadEventAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n isHydration = false,\n): void {\n const previousState = isHydration\n ? mtEventAttrState.get(handleId)?.get(attrSlotIndex)\n : undefined;\n if (value == null) {\n deleteSlotState(mtEventAttrState, handleId, attrSlotIndex);\n return;\n }\n const nextValue = (value as MTEventNativeWrapper).value;\n setMTEventSlotState(handleId, attrSlotIndex, nextValue);\n if (previousState) {\n hydrateWorkletCtx(\n nextValue as Worklet,\n previousState as Worklet,\n );\n }\n}\n\nexport function updateMainThreadRefAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n nativeRef: ElementTemplateHandle,\n isHydration = false,\n): void {\n const previousState = mtRefAttrState.get(handleId)?.get(attrSlotIndex);\n const isAttached = attachedMTRefHandleIds.has(handleId);\n if (value == null) {\n if (previousState && isAttached) {\n cleanupMTRefValue(previousState);\n }\n deleteSlotState(mtRefAttrState, handleId, attrSlotIndex);\n return;\n }\n if (previousState && isAttached) {\n cleanupMTRefValue(previousState);\n }\n const nextValue = (value as MTRefNativeWrapper).value;\n setMTRefSlotState(handleId, attrSlotIndex, nextValue);\n if (isHydration) {\n hydrateMTRefValue(nextValue, previousState);\n }\n if (isAttached) {\n pendingMTRefAttachments.push({ handleId, attrSlotIndex, value: nextValue, nativeRef });\n }\n}\n\nexport function attachMainThreadDynamicAttrRefsForSubtree(\n handles: readonly MainThreadDynamicAttrSubtreeHandle[],\n): void {\n for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {\n const handle = handles[handleIndex]!;\n if (attachedMTRefHandleIds.has(handle.uid)) {\n continue;\n }\n attachedMTRefHandleIds.add(handle.uid);\n const handleState = mtRefAttrState.get(handle.uid);\n if (!handleState) {\n continue;\n }\n for (const [attrSlotIndex, value] of handleState) {\n pendingMTRefAttachments.push({ handleId: handle.uid, attrSlotIndex, value, nativeRef: handle.ref });\n }\n }\n}\n\n// Consume one queue snapshot, matching Snapshot's ref delivery boundary.\nexport function applyPendingMainThreadRefAttachments(): void {\n const pending = pendingMTRefAttachments;\n pendingMTRefAttachments = [];\n for (const { handleId, attrSlotIndex, value, nativeRef } of pending) {\n const element = __GetElementByAttrSlot(nativeRef, attrSlotIndex);\n if (!element) {\n throw new Error(\n `ElementTemplate main-thread:ref target ${handleId}:${attrSlotIndex} could not be materialized.`,\n );\n }\n attachMTRefValue(value, element);\n }\n}\n\nexport function detachMainThreadDynamicAttrRefsForSubtree(\n handles: readonly MainThreadDynamicAttrSubtreeHandle[],\n): void {\n for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {\n const handleId = handles[handleIndex]!.uid;\n if (!attachedMTRefHandleIds.has(handleId)) {\n continue;\n }\n attachedMTRefHandleIds.delete(handleId);\n const handleState = mtRefAttrState.get(handleId);\n if (handleState) {\n cleanupMTRefHandleState(handleState);\n }\n }\n}\n\nexport function deleteMainThreadDynamicAttrStateForSubtree(\n handleIds: readonly number[],\n): void {\n for (const handleId of handleIds) {\n const handleState = mtRefAttrState.get(handleId);\n if (handleState && attachedMTRefHandleIds.has(handleId)) {\n cleanupMTRefHandleState(handleState);\n }\n attachedMTRefHandleIds.delete(handleId);\n mtEventAttrState.delete(handleId);\n mtRefAttrState.delete(handleId);\n }\n}\n"]}
@@ -8,6 +8,6 @@ export interface MTRefNativeWrapper {
8
8
  export declare function isMTRefValue(value: unknown): value is MTRefValue;
9
9
  export declare function retainMTRefValue(value: MTRefValue): void;
10
10
  export declare function hydrateMTRefValue(value: MTRefValue, previousValue: MTRefValue | undefined): void;
11
- export declare function attachMTRefValue(value: MTRefValue, nativeRef: ElementTemplateHandle): void;
11
+ export declare function attachMTRefValue(value: MTRefValue, nativeRef: ElementRef): void;
12
12
  export declare function cleanupMTRefValue(value: MTRefValue): void;
13
13
  export declare function prepareMTRefForNative(rawValue: unknown, previousPreparedValue?: unknown, previousRawValue?: unknown): SerializableValue | null;
@@ -1 +1 @@
1
- {"version":3,"file":"main-thread-ref-ctx.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-ref-ctx.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG7G,OAAO,EACL,uCAAuC,EACvC,qCAAqC,GACtC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAUnE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,eAAe,CAAC,KAAK,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OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,2FAA2F,CAAC,CAAC;IAC/G,CAAC;IACD,IAAI,gBAAgB,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,qBAA0C,CAAC;IACpD,CAAC;IAED,IAAI,KAAiB,CAAC;IACtB,IAAI,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnC,KAAK,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QACxB,uCAAuC,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,QAAQ,CAAC;IACnB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,KAAK;KAC0B,CAAC;AACpC,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 { hydrateWorkletCtx, runWorkletCtx, updateWorkletRef } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { Element, Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport {\n registerMainThreadBackgroundFunctionCtx,\n retainMainThreadBackgroundFunctionCtx,\n} from './main-thread-background-function.js';\nimport { isMainThreadFunction } from '../../../core/main-thread-function.js';\nimport { isMainThreadRef } from '../../../core/main-thread-ref.js';\nimport type { SerializableValue } from '../../protocol/types.js';\n\nexport type MTRefValue = WorkletRefImpl<Element> | Worklet;\n\nexport interface MTRefNativeWrapper {\n type: 'main-thread-ref';\n value: MTRefValue;\n}\n\nexport function isMTRefValue(value: unknown): value is MTRefValue {\n return isMainThreadRef(value) || isMainThreadFunction(value);\n}\n\nexport function retainMTRefValue(value: MTRefValue): void {\n if (isMainThreadFunction(value)) {\n retainMainThreadBackgroundFunctionCtx(value);\n }\n}\n\nexport function hydrateMTRefValue(\n value: MTRefValue,\n previousValue: MTRefValue | undefined,\n): void {\n if (isMainThreadFunction(value) && previousValue && isMainThreadFunction(previousValue)) {\n hydrateWorkletCtx(value, previousValue);\n }\n}\n\nexport function attachMTRefValue(\n value: MTRefValue,\n nativeRef: ElementTemplateHandle,\n): void {\n if (isMainThreadRef(value)) {\n updateWorkletRef(value, nativeRef as unknown as ElementNode);\n return;\n }\n value._unmount = runWorkletCtx(\n value,\n [{ elementRefptr: nativeRef }] as unknown as Parameters<typeof runWorkletCtx>[1],\n ) as () => void;\n}\n\nexport function cleanupMTRefValue(value: MTRefValue): void {\n if (isMainThreadRef(value)) {\n updateWorkletRef(value, null);\n return;\n }\n if (typeof value._unmount === 'function') {\n value._unmount();\n return;\n }\n runWorkletCtx(value, [null]);\n}\n\nexport function prepareMTRefForNative(\n rawValue: unknown,\n previousPreparedValue?: unknown,\n previousRawValue?: unknown,\n): SerializableValue | null {\n if (rawValue === null || rawValue === undefined) {\n return null;\n }\n if (!isMTRefValue(rawValue)) {\n throw new Error('ElementTemplate main-thread:ref expects a MainThreadRef object or a main-thread function.');\n }\n if (previousRawValue === rawValue) {\n return previousPreparedValue as SerializableValue;\n }\n\n let value: MTRefValue;\n if (isMainThreadFunction(rawValue)) {\n value = { ...rawValue };\n registerMainThreadBackgroundFunctionCtx(value);\n } else {\n value = rawValue;\n }\n\n return {\n type: 'main-thread-ref',\n value,\n } as unknown as SerializableValue;\n}\n"]}
1
+ {"version":3,"file":"main-thread-ref-ctx.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-ref-ctx.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG7G,OAAO,EACL,uCAAuC,EACvC,qCAAqC,GACtC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;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C,QAAiB,EACjB,qBAA+B,EAC/B,gBAA0B;IAE1B,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,2FAA2F,CAAC,CAAC;IAC/G,CAAC;IACD,IAAI,gBAAgB,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,qBAA0C,CAAC;IACpD,CAAC;IAED,IAAI,KAAiB,CAAC;IACtB,IAAI,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnC,KAAK,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QACxB,uCAAuC,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,QAAQ,CAAC;IACnB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,KAAK;KAC0B,CAAC;AACpC,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 { hydrateWorkletCtx, runWorkletCtx, updateWorkletRef } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { Element, Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport {\n registerMainThreadBackgroundFunctionCtx,\n retainMainThreadBackgroundFunctionCtx,\n} from './main-thread-background-function.js';\nimport { isMainThreadFunction } from '../../../core/main-thread-function.js';\nimport { isMainThreadRef } from '../../../core/main-thread-ref.js';\nimport type { SerializableValue } from '../../protocol/types.js';\n\nexport type MTRefValue = WorkletRefImpl<Element> | Worklet;\n\nexport interface MTRefNativeWrapper {\n type: 'main-thread-ref';\n value: MTRefValue;\n}\n\nexport function isMTRefValue(value: unknown): value is MTRefValue {\n return isMainThreadRef(value) || isMainThreadFunction(value);\n}\n\nexport function retainMTRefValue(value: MTRefValue): void {\n if (isMainThreadFunction(value)) {\n retainMainThreadBackgroundFunctionCtx(value);\n }\n}\n\nexport function hydrateMTRefValue(\n value: MTRefValue,\n previousValue: MTRefValue | undefined,\n): void {\n if (isMainThreadFunction(value) && previousValue && isMainThreadFunction(previousValue)) {\n hydrateWorkletCtx(value, previousValue);\n }\n}\n\nexport function attachMTRefValue(\n value: MTRefValue,\n nativeRef: ElementRef,\n): void {\n if (isMainThreadRef(value)) {\n updateWorkletRef(value, nativeRef);\n return;\n }\n value._unmount = runWorkletCtx(\n value,\n [{ elementRefptr: nativeRef }] as unknown as Parameters<typeof runWorkletCtx>[1],\n ) as () => void;\n}\n\nexport function cleanupMTRefValue(value: MTRefValue): void {\n if (isMainThreadRef(value)) {\n updateWorkletRef(value, null);\n return;\n }\n if (typeof value._unmount === 'function') {\n value._unmount();\n return;\n }\n runWorkletCtx(value, [null]);\n}\n\nexport function prepareMTRefForNative(\n rawValue: unknown,\n previousPreparedValue?: unknown,\n previousRawValue?: unknown,\n): SerializableValue | null {\n if (rawValue === null || rawValue === undefined) {\n return null;\n }\n if (!isMTRefValue(rawValue)) {\n throw new Error('ElementTemplate main-thread:ref expects a MainThreadRef object or a main-thread function.');\n }\n if (previousRawValue === rawValue) {\n return previousPreparedValue as SerializableValue;\n }\n\n let value: MTRefValue;\n if (isMainThreadFunction(rawValue)) {\n value = { ...rawValue };\n registerMainThreadBackgroundFunctionCtx(value);\n } else {\n value = rawValue;\n }\n\n return {\n type: 'main-thread-ref',\n value,\n } as unknown as SerializableValue;\n}\n"]}
@@ -34,5 +34,5 @@ export { withInitDataInState } from './core/initData.js';
34
34
  export { wrapWithLynxComponent } from './core/compat/lynxComponent.js';
35
35
  export { loadLazyBundle } from './core/lynx/lazy-bundle.js';
36
36
  export { createBackgroundFunctionHandle as transformToWorklet } from './core/background-function/handle.js';
37
- export { registerWorkletOnBackground } from './snapshot/worklet/hmr.js';
37
+ export { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings';
38
38
  export { captureMainThreadObject } from './core/capture-main-thread-object.js';
@@ -52,7 +52,7 @@ export const __ComponentIsPolyfill = /* @__PURE__ */ factory2(
52
52
  { Suspense, lazy, createElement, useMemo }, loadLazyBundle);
53
53
  export { loadLazyBundle } from './core/lynx/lazy-bundle.js';
54
54
  export { createBackgroundFunctionHandle as transformToWorklet } from './core/background-function/handle.js';
55
- export { registerWorkletOnBackground } from './snapshot/worklet/hmr.js';
55
+ export { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings';
56
56
  export { captureMainThreadObject } from './core/capture-main-thread-object.js';
57
57
  if (__DEV__) {
58
58
  // Dev snapshot creators take the runtime as a parameter (they are
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGlG,OAAO,qBAAqB,CAAC;AAC7B,OAAO,WAAW,CAAC;AAEnB,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,qBAAqB,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACtG,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,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AAE,MAAM,qCAAqC,CAAC;AAEjF,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,OAAO,EACL,OAAO;AACP,+EAA+E;AAC/E,SAAS,EACT,OAAO,GACR,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAE/E,oEAAoE;AACpE,uCAAuC;AACvC,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAC3F,OAAO,EACL,gCAAgC,EAChC,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAuB,eAAe,CAAC,QAAQ;AAC/E,iEAAiE;AACjE,EAAE,QAAQ,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAS,EACjD,cAAc,CACf,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,8BAA8B,IAAI,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC5G,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAExE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAE/E,IAAI,OAAO,EAAE,CAAC;IACZ,kEAAkE;IAClE,0EAA0E;IAC1E,0EAA0E;IAC1E,yEAAyE;IACzE,yBAAyB,CAAC,qBAAqB,CAAC,CAAC;AACnD,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 { Suspense, createElement, lazy, cloneElement as preactCloneElement } from 'preact/compat';\nimport type { FC } from 'react';\n\nimport './runtime-marker.js';\nimport './lynx.js';\n\nimport { useMemo } from './core/hooks/react.js';\nimport { loadLazyBundle } from './core/lynx/lazy-bundle.js';\nimport * as ReactLynxInternalSelf from './internal.js';\nimport { __root } from './root.js';\nimport { factory as factory2 } from './snapshot/compat/componentIs.js';\nimport { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js';\nimport { __page, __pageId, createSnapshot, snapshotManager } from './snapshot/snapshot/definition.js';\nimport { DynamicPartType } from './snapshot/snapshot/dynamicPartType.js';\nimport { snapshotCreateList } from './snapshot/snapshot/list.js';\nimport { SnapshotInstance, snapshotCreatorMap } from './snapshot/snapshot/snapshot.js';\nimport { setSnapshotCreatorRuntime } from './snapshot/snapshot/snapshotCreatorMap.js';\n\nexport {\n BITS,\n CHILDREN,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DOM,\n FLAGS,\n INDEX,\n PARENT,\n} from './shared/render-constants.js';\n\nexport { __page, __pageId, __root };\n\nexport {\n BackgroundSnapshotInstance,\n SnapshotInstance,\n snapshotCreateList,\n createSnapshot,\n snapshotManager,\n snapshotCreatorMap,\n};\n\nexport const __DynamicPartSlot: DynamicPartType = DynamicPartType.Slot;\nexport const __DynamicPartMultiChildren: DynamicPartType = DynamicPartType.MultiChildren;\nexport const __DynamicPartChildren: DynamicPartType = DynamicPartType.Children;\nexport const __DynamicPartListChildren: DynamicPartType = DynamicPartType.ListChildren;\nexport { __DynamicPartChildren_0, __DynamicPartSlotV2_0 } from './snapshot/snapshot/dynamicPartType.js';\n\n// v2 slot\nexport const __DynamicPartSlotV2: DynamicPartType = DynamicPartType.SlotV2;\nexport const __DynamicPartListSlotV2: DynamicPartType = DynamicPartType.ListSlotV2;\n\nexport { updateSpread } from './snapshot/snapshot/spread.js';\nexport { updateEvent } from './snapshot/snapshot/event.js';\nexport { updateRef, transformRef } from './snapshot/snapshot/ref.js';\nexport { updateWorkletEvent } from './snapshot/snapshot/workletEvent.js';\nexport { updateWorkletRef } from './snapshot/snapshot/workletRef.js';\nexport { updateGesture } from './snapshot/snapshot/gesture.js';\nexport { updateListItemPlatformInfo } from './snapshot/snapshot/platformInfo.js';\n\nexport { preactCloneElement };\n\nexport {\n options,\n // Component is not an internal API, but refresh needs it from 'react/internal'\n Component,\n process,\n} from 'preact';\nexport type { Options } from 'preact';\n\nexport { loadDynamicJS, __dynamicImport } from './core/lynx/dynamic-import.js';\n\n// Re-exported so lazy bundle shells can reach the host runtime APIs\n// via `target[sExportsReactInternal]`.\nexport { registerRuntimeVersion, getRuntimeVersion } from './core/lynx/runtime-version.js';\nexport {\n RUNTIME_BACKEND_ELEMENT_TEMPLATE,\n RUNTIME_BACKEND_SNAPSHOT,\n registerRuntimeBackend,\n} from './core/lynx/runtime-backend.js';\n\nexport { withInitDataInState } from './core/initData.js';\n\nexport { wrapWithLynxComponent } from './core/compat/lynxComponent.js';\n\n/**\n * @internal a polyfill for <component is=? />\n */\nexport const __ComponentIsPolyfill: FC<{ is: string }> = /* @__PURE__ */ factory2(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n { Suspense, lazy, createElement, useMemo } as any,\n loadLazyBundle,\n);\n\nexport { loadLazyBundle } from './core/lynx/lazy-bundle.js';\n\nexport { createBackgroundFunctionHandle as transformToWorklet } from './core/background-function/handle.js';\nexport { registerWorkletOnBackground } from './snapshot/worklet/hmr.js';\n\nexport { captureMainThreadObject } from './core/capture-main-thread-object.js';\n\nif (__DEV__) {\n // Dev snapshot creators take the runtime as a parameter (they are\n // stringified for cross-thread HMR and must not capture module bindings);\n // register this namespace as that runtime. Production creators close over\n // their own module's runtime import, so this reference is dropped there.\n setSnapshotCreatorRuntime(ReactLynxInternalSelf);\n}\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,IAAI,kBAAkB,EAAE,MA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S,EACjD,cAAc,CACf,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,8BAA8B,IAAI,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAE5G,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAE/E,IAAI,OAAO,EAAE,CAAC;IACZ,kEAAkE;IAClE,0EAA0E;IAC1E,0EAA0E;IAC1E,yEAAyE;IACzE,yBAAyB,CAAC,qBAAqB,CAAC,CAAC;AACnD,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 { Suspense, createElement, lazy, cloneElement as preactCloneElement } from 'preact/compat';\nimport type { FC } from 'react';\n\nimport './runtime-marker.js';\nimport './lynx.js';\n\nimport { useMemo } from './core/hooks/react.js';\nimport { loadLazyBundle } from './core/lynx/lazy-bundle.js';\nimport * as ReactLynxInternalSelf from './internal.js';\nimport { __root } from './root.js';\nimport { factory as factory2 } from './snapshot/compat/componentIs.js';\nimport { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js';\nimport { __page, __pageId, createSnapshot, snapshotManager } from './snapshot/snapshot/definition.js';\nimport { DynamicPartType } from './snapshot/snapshot/dynamicPartType.js';\nimport { snapshotCreateList } from './snapshot/snapshot/list.js';\nimport { SnapshotInstance, snapshotCreatorMap } from './snapshot/snapshot/snapshot.js';\nimport { setSnapshotCreatorRuntime } from './snapshot/snapshot/snapshotCreatorMap.js';\n\nexport {\n BITS,\n CHILDREN,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DOM,\n FLAGS,\n INDEX,\n PARENT,\n} from './shared/render-constants.js';\n\nexport { __page, __pageId, __root };\n\nexport {\n BackgroundSnapshotInstance,\n SnapshotInstance,\n snapshotCreateList,\n createSnapshot,\n snapshotManager,\n snapshotCreatorMap,\n};\n\nexport const __DynamicPartSlot: DynamicPartType = DynamicPartType.Slot;\nexport const __DynamicPartMultiChildren: DynamicPartType = DynamicPartType.MultiChildren;\nexport const __DynamicPartChildren: DynamicPartType = DynamicPartType.Children;\nexport const __DynamicPartListChildren: DynamicPartType = DynamicPartType.ListChildren;\nexport { __DynamicPartChildren_0, __DynamicPartSlotV2_0 } from './snapshot/snapshot/dynamicPartType.js';\n\n// v2 slot\nexport const __DynamicPartSlotV2: DynamicPartType = DynamicPartType.SlotV2;\nexport const __DynamicPartListSlotV2: DynamicPartType = DynamicPartType.ListSlotV2;\n\nexport { updateSpread } from './snapshot/snapshot/spread.js';\nexport { updateEvent } from './snapshot/snapshot/event.js';\nexport { updateRef, transformRef } from './snapshot/snapshot/ref.js';\nexport { updateWorkletEvent } from './snapshot/snapshot/workletEvent.js';\nexport { updateWorkletRef } from './snapshot/snapshot/workletRef.js';\nexport { updateGesture } from './snapshot/snapshot/gesture.js';\nexport { updateListItemPlatformInfo } from './snapshot/snapshot/platformInfo.js';\n\nexport { preactCloneElement };\n\nexport {\n options,\n // Component is not an internal API, but refresh needs it from 'react/internal'\n Component,\n process,\n} from 'preact';\nexport type { Options } from 'preact';\n\nexport { loadDynamicJS, __dynamicImport } from './core/lynx/dynamic-import.js';\n\n// Re-exported so lazy bundle shells can reach the host runtime APIs\n// via `target[sExportsReactInternal]`.\nexport { registerRuntimeVersion, getRuntimeVersion } from './core/lynx/runtime-version.js';\nexport {\n RUNTIME_BACKEND_ELEMENT_TEMPLATE,\n RUNTIME_BACKEND_SNAPSHOT,\n registerRuntimeBackend,\n} from './core/lynx/runtime-backend.js';\n\nexport { withInitDataInState } from './core/initData.js';\n\nexport { wrapWithLynxComponent } from './core/compat/lynxComponent.js';\n\n/**\n * @internal a polyfill for <component is=? />\n */\nexport const __ComponentIsPolyfill: FC<{ is: string }> = /* @__PURE__ */ factory2(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n { Suspense, lazy, createElement, useMemo } as any,\n loadLazyBundle,\n);\n\nexport { loadLazyBundle } from './core/lynx/lazy-bundle.js';\n\nexport { createBackgroundFunctionHandle as transformToWorklet } from './core/background-function/handle.js';\n\nexport { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings';\nexport { captureMainThreadObject } from './core/capture-main-thread-object.js';\n\nif (__DEV__) {\n // Dev snapshot creators take the runtime as a parameter (they are\n // stringified for cross-thread HMR and must not capture module bindings);\n // register this namespace as that runtime. Production creators close over\n // their own module's runtime import, so this reference is dropped there.\n setSnapshotCreatorRuntime(ReactLynxInternalSelf);\n}\n"]}