@lynx-js/react 0.128.0 → 0.129.0

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 (174) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +1 -1
  4. package/refresh/.turbo/turbo-build.log +1 -1
  5. package/runtime/__test__/core/entry-re-eval.test.ts +161 -0
  6. package/runtime/__test__/core/reload-scoped-dual-thread-communication.test.ts +129 -0
  7. package/runtime/__test__/core/thread-function-call.test.ts +1 -0
  8. package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +2 -0
  9. package/runtime/__test__/element-template/native/index.test.ts +8 -0
  10. package/runtime/__test__/element-template/native/main-thread-ref-init-value.test.ts +100 -0
  11. package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +101 -0
  12. package/runtime/__test__/element-template/native/reload.test.ts +50 -1
  13. package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +104 -47
  14. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +7 -1
  15. package/runtime/__test__/element-template/runtime/background/re-eval-reload.test.ts +69 -0
  16. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +31 -5
  17. package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +17 -3
  18. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +2 -0
  19. package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +89 -2
  20. package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +5 -0
  21. package/runtime/__test__/snapshot/lifecycle/re-eval-reload.test.jsx +114 -0
  22. package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +169 -0
  23. package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +63 -0
  24. package/runtime/__test__/snapshot/lifecycle/reload-delayed-main-thread.test.jsx +103 -0
  25. package/runtime/__test__/snapshot/lifecycle.test.jsx +61 -1
  26. package/runtime/__test__/snapshot/lynx/lazy-effect-scheduling.test.jsx +105 -0
  27. package/runtime/__test__/snapshot/ssr.test.jsx +2 -2
  28. package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +6 -11
  29. package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +1 -1
  30. package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +24 -1
  31. package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +15 -1
  32. package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +46 -0
  33. package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +3 -3
  34. package/runtime/lib/core/background-function/exec-map.d.ts +2 -0
  35. package/runtime/lib/core/background-function/exec-map.js +7 -0
  36. package/runtime/lib/core/background-function/exec-map.js.map +1 -1
  37. package/runtime/lib/core/background-function/run-on-background.js +15 -16
  38. package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
  39. package/runtime/lib/core/card-lifetime.d.ts +5 -0
  40. package/runtime/lib/core/card-lifetime.js +17 -0
  41. package/runtime/lib/core/card-lifetime.js.map +1 -0
  42. package/runtime/lib/core/entry-reload.d.ts +7 -0
  43. package/runtime/lib/core/entry-reload.js +49 -0
  44. package/runtime/lib/core/entry-reload.js.map +1 -0
  45. package/runtime/lib/core/lynx/lazy-bundle.js +4 -1
  46. package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
  47. package/runtime/lib/core/main-thread-ref-id.js +4 -4
  48. package/runtime/lib/core/main-thread-ref-id.js.map +1 -1
  49. package/runtime/lib/core/reload-scoped-event.d.ts +5 -0
  50. package/runtime/lib/core/reload-scoped-event.js +26 -0
  51. package/runtime/lib/core/reload-scoped-event.js.map +1 -0
  52. package/runtime/lib/core/reload-version.js +4 -3
  53. package/runtime/lib/core/reload-version.js.map +1 -1
  54. package/runtime/lib/core/runtime-destroy.d.ts +2 -0
  55. package/runtime/lib/core/runtime-destroy.js +9 -0
  56. package/runtime/lib/core/runtime-destroy.js.map +1 -1
  57. package/runtime/lib/core/thread-function-call/main-thread.js +5 -4
  58. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  59. package/runtime/lib/core/thread-function-call/return-value.js +6 -5
  60. package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
  61. package/runtime/lib/element-template/background/commit-hook.js +19 -16
  62. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  63. package/runtime/lib/element-template/background/hydration-listener.js +2 -6
  64. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  65. package/runtime/lib/element-template/main-thread-ref-init-value.d.ts +3 -0
  66. package/runtime/lib/element-template/main-thread-ref-init-value.js +38 -0
  67. package/runtime/lib/element-template/main-thread-ref-init-value.js.map +1 -0
  68. package/runtime/lib/element-template/native/index.js +2 -0
  69. package/runtime/lib/element-template/native/index.js.map +1 -1
  70. package/runtime/lib/element-template/native/mts-destroy.js +2 -0
  71. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  72. package/runtime/lib/element-template/native/patch-listener.js +1 -4
  73. package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
  74. package/runtime/lib/element-template/native/reload-background.d.ts +1 -1
  75. package/runtime/lib/element-template/native/reload-background.js +12 -1
  76. package/runtime/lib/element-template/native/reload-background.js.map +1 -1
  77. package/runtime/lib/element-template/native/reload-main-thread.d.ts +6 -0
  78. package/runtime/lib/element-template/native/reload-main-thread.js +18 -2
  79. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  80. package/runtime/lib/element-template/protocol/lifecycle-constant.d.ts +2 -1
  81. package/runtime/lib/element-template/protocol/lifecycle-constant.js +1 -0
  82. package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
  83. package/runtime/lib/element-template/protocol/types.d.ts +0 -2
  84. package/runtime/lib/element-template/protocol/types.js.map +1 -1
  85. package/runtime/lib/shared/index-map.d.ts +4 -1
  86. package/runtime/lib/shared/index-map.js +5 -2
  87. package/runtime/lib/shared/index-map.js.map +1 -1
  88. package/runtime/lib/snapshot/lifecycle/destroy.js +6 -0
  89. package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
  90. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.d.ts +6 -2
  91. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js +21 -18
  92. package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
  93. package/runtime/lib/snapshot/lifecycle/reload.d.ts +9 -2
  94. package/runtime/lib/snapshot/lifecycle/reload.js +29 -8
  95. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  96. package/runtime/lib/snapshot/list/list.js +3 -2
  97. package/runtime/lib/snapshot/list/list.js.map +1 -1
  98. package/runtime/lib/snapshot/lynx/calledByNative.js +3 -3
  99. package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
  100. package/runtime/lib/snapshot/snapshot/list.js +2 -1
  101. package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
  102. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.d.ts +4 -2
  103. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js +11 -11
  104. package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
  105. package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +1 -0
  106. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +6 -1
  107. package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
  108. package/runtime/lib/snapshot/worklet/ctx.d.ts +1 -1
  109. package/runtime/lib/snapshot/worklet/ctx.js +6 -1
  110. package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
  111. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js +6 -0
  112. package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
  113. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  114. package/runtime/lib/worklet-runtime/delayRunOnBackground.js +3 -1
  115. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
  116. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +2 -1
  117. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
  118. package/runtime/lib/worklet-runtime/listeners.js +2 -2
  119. package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
  120. package/runtime/lib/worklet-runtime/mainThreadObject.js +3 -1
  121. package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -1
  122. package/runtime/lib/worklet-runtime/runOnMainThread.js +4 -3
  123. package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
  124. package/runtime/src/core/background-function/exec-map.ts +9 -0
  125. package/runtime/src/core/background-function/run-on-background.ts +14 -16
  126. package/runtime/src/core/card-lifetime.ts +18 -0
  127. package/runtime/src/core/entry-reload.ts +63 -0
  128. package/runtime/src/core/lynx/lazy-bundle.ts +4 -1
  129. package/runtime/src/core/main-thread-ref-id.ts +5 -4
  130. package/runtime/src/core/reload-scoped-event.ts +35 -0
  131. package/runtime/src/core/reload-version.ts +5 -3
  132. package/runtime/src/core/runtime-destroy.ts +11 -0
  133. package/runtime/src/core/thread-function-call/main-thread.ts +4 -4
  134. package/runtime/src/core/thread-function-call/return-value.ts +6 -5
  135. package/runtime/src/element-template/background/commit-hook.ts +20 -17
  136. package/runtime/src/element-template/background/hydration-listener.ts +2 -6
  137. package/runtime/src/element-template/main-thread-ref-init-value.ts +44 -0
  138. package/runtime/src/element-template/native/index.ts +2 -0
  139. package/runtime/src/element-template/native/mts-destroy.ts +3 -0
  140. package/runtime/src/element-template/native/patch-listener.ts +0 -5
  141. package/runtime/src/element-template/native/reload-background.ts +13 -1
  142. package/runtime/src/element-template/native/reload-main-thread.ts +30 -2
  143. package/runtime/src/element-template/protocol/lifecycle-constant.ts +1 -0
  144. package/runtime/src/element-template/protocol/types.ts +0 -2
  145. package/runtime/src/shared/index-map.ts +3 -2
  146. package/runtime/src/snapshot/lifecycle/destroy.ts +7 -0
  147. package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +26 -19
  148. package/runtime/src/snapshot/lifecycle/reload.ts +47 -11
  149. package/runtime/src/snapshot/list/list.ts +9 -2
  150. package/runtime/src/snapshot/lynx/calledByNative.ts +3 -4
  151. package/runtime/src/snapshot/snapshot/list.ts +5 -1
  152. package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +19 -12
  153. package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +10 -1
  154. package/runtime/src/snapshot/worklet/ctx.ts +10 -1
  155. package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +6 -0
  156. package/runtime/src/worklet-runtime/README.md +13 -0
  157. package/runtime/src/worklet-runtime/delayRunOnBackground.ts +3 -1
  158. package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +2 -1
  159. package/runtime/src/worklet-runtime/listeners.ts +4 -7
  160. package/runtime/src/worklet-runtime/mainThreadObject.ts +2 -1
  161. package/runtime/src/worklet-runtime/runOnMainThread.ts +4 -3
  162. package/runtime/types/types.d.ts +3 -1
  163. package/testing-library/.turbo/turbo-build.log +7 -7
  164. package/testing-library/src/__tests__/worklet.test.jsx +10 -5
  165. package/transform/.turbo/turbo-build$colon$wasm.log +339 -134
  166. package/transform/__test__/defines.spec.js +107 -0
  167. package/transform/crates/swc_plugin_worklet/definition_imports.rs +97 -0
  168. package/transform/crates/swc_plugin_worklet/lib.rs +7 -6
  169. package/transform/dist/wasm.cjs +1 -1
  170. package/transform/index.d.ts +3 -1
  171. package/transform/src/lib.rs +172 -11
  172. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +57 -55
  173. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  174. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +66 -274
@@ -1 +1 @@
1
- {"version":3,"file":"reload-main-thread.js","sourceRoot":"","sources":["../../../src/element-template/native/reload-main-thread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,mBAAmB,E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AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { applyUpdatePageData } from '../../core/lynx-page-data.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../protocol/page.js';\nimport type { SerializedEtNode, SerializedPageRoot } from '../protocol/types.js';\nimport { destroyAllElementTemplateListStates } from '../runtime/list/list.js';\nimport { __page } from '../runtime/page/page.js';\nimport { __root, setRoot } from '../runtime/page/root-instance.js';\nimport { renderMainThread } from '../runtime/render/render-main-thread.js';\nimport { resetTemplateId } from '../runtime/template/handle.js';\nimport { resetElementTemplateMainThreadBackgroundFunctionRuntime } from '../runtime/template/main-thread-background-function.js';\nimport {\n clearMainThreadDynamicAttrState,\n deleteMainThreadDynamicAttrStateForSubtree,\n} from '../runtime/template/main-thread-dynamic-attr-state.js';\nimport { elementTemplateRegistry } from '../runtime/template/registry.js';\n\nexport function reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n try {\n increaseReloadVersion();\n applyUpdatePageData(data, options);\n\n destroyAllElementTemplateListStates();\n // TODO: Replace this cleanup-only serialization with a direct page-children\n // or clear-slot PAPI once native exposes one.\n const page = __SerializeElementTemplate(__page) as SerializedPageRoot;\n for (const root of page.childSlots?.[ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX] ?? []) {\n const rootRef = elementTemplateRegistry.get(root.uid)!;\n __RemoveNodeFromElementTemplate(__page, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX, rootRef);\n const removedHandleIds: number[] = [];\n collectSerializedSubtreeHandleIds(root, removedHandleIds);\n for (const handleId of removedHandleIds) {\n elementTemplateRegistry.delete(handleId);\n }\n deleteMainThreadDynamicAttrStateForSubtree(removedHandleIds);\n }\n elementTemplateRegistry.clear();\n clearMainThreadDynamicAttrState();\n resetElementTemplateMainThreadBackgroundFunctionRuntime();\n resetTemplateId();\n\n const oldRoot = __root;\n setRoot({ __jsx: oldRoot.__jsx });\n renderMainThread();\n\n __FlushElementTree(undefined, options);\n } finally {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n\nfunction collectSerializedSubtreeHandleIds(\n node: SerializedEtNode,\n handleIds: number[],\n): void {\n handleIds.push(node.uid as number);\n for (const slot of node.childSlots ?? []) {\n for (const child of slot ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n }\n const listChildren = (node as { options?: { listChildren?: SerializedEtNode[] } }).options?.listChildren;\n for (const child of listChildren ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n}\n"]}
1
+ {"version":3,"file":"reload-main-thread.js","sourceRoot":"","sources":["../../../src/element-template/native/reload-main-thread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,wBAAwB,EACxB,gCAAgC,EAChC,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,qCAAqC,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,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AE,EAAE,CAAC;QACvC,iCAAiC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACtD,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { onMtsDestruction } from './mts-destroy.js';\nimport {\n canReEvalMainThreadEntry,\n installMainThreadReloadCompleter,\n reEvalMainThreadEntry,\n} from '../../core/entry-reload.js';\nimport { applyUpdatePageData } from '../../core/lynx-page-data.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../protocol/page.js';\nimport type { SerializedEtNode, SerializedPageRoot } from '../protocol/types.js';\nimport { destroyAllElementTemplateListStates } from '../runtime/list/list.js';\nimport { __page, setupPage } from '../runtime/page/page.js';\nimport { __root, setRoot } from '../runtime/page/root-instance.js';\nimport { renderMainThread } from '../runtime/render/render-main-thread.js';\nimport { resetTemplateId } from '../runtime/template/handle.js';\nimport { resetElementTemplateMainThreadBackgroundFunctionRuntime } from '../runtime/template/main-thread-background-function.js';\nimport {\n clearMainThreadDynamicAttrState,\n deleteMainThreadDynamicAttrStateForSubtree,\n} from '../runtime/template/main-thread-dynamic-attr-state.js';\nimport { elementTemplateRegistry } from '../runtime/template/registry.js';\n\nexport function reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n try {\n applyUpdatePageData(data, options);\n\n destroyAllElementTemplateListStates();\n // TODO: Replace this cleanup-only serialization with a direct page-children\n // or clear-slot PAPI once native exposes one.\n const page = __SerializeElementTemplate(__page) as SerializedPageRoot;\n for (const root of page.childSlots?.[ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX] ?? []) {\n const rootRef = elementTemplateRegistry.get(root.uid)!;\n __RemoveNodeFromElementTemplate(__page, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX, rootRef);\n const removedHandleIds: number[] = [];\n collectSerializedSubtreeHandleIds(root, removedHandleIds);\n for (const handleId of removedHandleIds) {\n elementTemplateRegistry.delete(handleId);\n }\n deleteMainThreadDynamicAttrStateForSubtree(removedHandleIds);\n }\n if (canReEvalMainThreadEntry()) {\n onMtsDestruction();\n increaseReloadVersion();\n reEvalMainThreadEntry<MainThreadReloadHandoff>({ page: __page, options });\n return;\n }\n elementTemplateRegistry.clear();\n clearMainThreadDynamicAttrState();\n resetElementTemplateMainThreadBackgroundFunctionRuntime();\n resetTemplateId();\n\n // Ref cleanup still belongs to the old page. Advance only before rendering\n // the new tree so calls queued by old ref/unmount callbacks remain stale.\n increaseReloadVersion();\n\n const oldRoot = __root;\n setRoot({ __jsx: oldRoot.__jsx });\n renderMainThread();\n\n __FlushElementTree(undefined, options);\n } finally {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n\ninterface MainThreadReloadHandoff {\n page: ElementTemplateHandle;\n options: UpdatePageOption;\n}\n\nexport function completeMainThreadReload({ page, options }: MainThreadReloadHandoff): void {\n setupPage(page);\n renderMainThread();\n __FlushElementTree(undefined, options);\n}\n\ninstallMainThreadReloadCompleter(completeMainThreadReload);\n\nfunction collectSerializedSubtreeHandleIds(\n node: SerializedEtNode,\n handleIds: number[],\n): void {\n handleIds.push(node.uid as number);\n for (const slot of node.childSlots ?? []) {\n for (const child of slot ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n }\n const listChildren = (node as { options?: { listChildren?: SerializedEtNode[] } }).options?.listChildren;\n for (const child of listChildren ?? []) {\n collectSerializedSubtreeHandleIds(child, handleIds);\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  export declare const enum ElementTemplateLifecycleConstant {
2
2
  hydrate = "rLynxElementTemplateHydrate",
3
- update = "rLynxElementTemplateUpdate"
3
+ update = "rLynxElementTemplateUpdate",
4
+ updateMTRefInitValue = "rLynxElementTemplateRefInitValue"
4
5
  }
@@ -5,5 +5,6 @@ export var ElementTemplateLifecycleConstant;
5
5
  (function (ElementTemplateLifecycleConstant) {
6
6
  ElementTemplateLifecycleConstant["hydrate"] = "rLynxElementTemplateHydrate";
7
7
  ElementTemplateLifecycleConstant["update"] = "rLynxElementTemplateUpdate";
8
+ ElementTemplateLifecycleConstant["updateMTRefInitValue"] = "rLynxElementTemplateRefInitValue";
8
9
  })(ElementTemplateLifecycleConstant || (ElementTemplateLifecycleConstant = {}));
9
10
  //# sourceMappingURL=lifecycle-constant.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle-constant.js","sourceRoot":"","sources":["../../../src/element-template/protocol/lifecycle-constant.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAN,IAAkB,gCAGjB;AAHD,WAAkB,gCAAgC;IAChD,2EAAuC,CAAA;IACvC,yEAAqC,CAAA;AACvC,CAAC,EAHiB,gCAAgC,KAAhC,gCAAgC,QAGjD","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nexport const enum ElementTemplateLifecycleConstant {\n hydrate = 'rLynxElementTemplateHydrate',\n update = 'rLynxElementTemplateUpdate',\n}\n"]}
1
+ {"version":3,"file":"lifecycle-constant.js","sourceRoot":"","sources":["../../../src/element-template/protocol/lifecycle-constant.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAN,IAAkB,gCAIjB;AAJD,WAAkB,gCAAgC;IAChD,2EAAuC,CAAA;IACvC,yEAAqC,CAAA;IACrC,6FAAyD,CAAA;AAC3D,CAAC,EAJiB,gCAAgC,KAAhC,gCAAgC,QAIjD","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nexport const enum ElementTemplateLifecycleConstant {\n hydrate = 'rLynxElementTemplateHydrate',\n update = 'rLynxElementTemplateUpdate',\n updateMTRefInitValue = 'rLynxElementTemplateRefInitValue',\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  import type { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';
2
2
  import { ElementTemplateUpdateOps } from './opcodes.js';
3
3
  import { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_TYPE } from './page.js';
4
- import type { MainThreadRefInitValuePatch } from '../../worklet-runtime/bindings/types.js';
5
4
  export type SerializableValue = string | number | boolean | null | SerializableValue[] | {
6
5
  [key: string]: SerializableValue;
7
6
  };
@@ -146,5 +145,4 @@ export interface ElementTemplateUpdateCommitContext {
146
145
  isHydration?: boolean | undefined;
147
146
  reloadVersion?: number | undefined;
148
147
  delayedRunOnMainThreadData?: RunWorkletCtxData[] | undefined;
149
- mainThreadRefInitValuePatch?: MainThreadRefInitValuePatch | undefined;
150
148
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/element-template/protocol/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { ElementTemplateUpdateOps } from './opcodes.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_TYPE } from './page.js';\nimport type { MainThreadRefInitValuePatch } from '../../worklet-runtime/bindings/types.js';\n\nexport type SerializableValue =\n | string\n | number\n | boolean\n | null\n | SerializableValue[]\n | { [key: string]: SerializableValue };\n\nexport type RuntimeOptionValue =\n | SerializableValue\n | FiberElement\n | RuntimeOptionValue[]\n | { [key: string]: RuntimeOptionValue };\n\nexport type RuntimeOptions = Record<string, RuntimeOptionValue>;\n\nexport type RuntimeAttributeSlotValue =\n | SerializableValue\n | ((...args: unknown[]) => unknown)\n | RuntimeAttributeSlotValue[]\n | { [key: string]: RuntimeAttributeSlotValue };\n\nexport type RuntimeTypedElementAttributes = Record<string, RuntimeAttributeSlotValue>;\n\nexport type TypedElementAttributesCommand = Record<string, SerializableValue>;\n\nexport type RuntimeChildSlots = Array<ElementTemplateHandle[] | null | undefined>;\n\nexport type ElementTemplateHandleSlotsCommand = Array<number[] | null | undefined>;\n\nexport type SerializedEtNodeChildSlots = Array<SerializedEtNode[] | null | undefined>;\n\nexport interface ElementTemplateHandleRefCommandValue {\n __etHandleRef: number;\n [key: string]: SerializableValue;\n}\n\nexport interface UpdateTypedListItemCommand extends ElementTemplateHandleRefCommandValue {\n type: string;\n platformInfo: Record<string, SerializableValue>;\n subtreeHandleIds: number[];\n}\n\nexport type RuntimeOptionsCommand = Record<string, SerializableValue>;\n\n// Deferred typed-list create carries logical item records here. Its future\n// main-thread consumer resolves these refs into the list-specific runtime carrier.\nexport interface TypedListOptionsCommand extends RuntimeOptionsCommand {\n listChildren: UpdateTypedListItemCommand[];\n}\n\nexport interface RuntimeTypedListOptions {\n listChildren: ElementTemplateHandle[];\n}\n\nexport type SerializedRuntimeOptions = Record<string, SerializableValue>;\n\nexport interface SerializedTypedListOptions {\n listChildren: SerializedEtNode[];\n}\n\nexport interface SerializedEtNodeBase {\n attributeSlots?: SerializableValue[] | null;\n childSlots?: SerializedEtNodeChildSlots | null;\n uid: number;\n options?: SerializedRuntimeOptions | null;\n}\n\nexport interface SerializedCompiledNode extends SerializedEtNodeBase {\n templateKey: string;\n bundleUrl?: string;\n attributeSlots?: SerializableValue[] | null;\n}\n\nexport interface SerializedTypedNode extends SerializedEtNodeBase {\n // Native __SerializeElementTemplate returns typed hosts as { tag, attributes }.\n tag: string;\n attributes?: TypedElementAttributesCommand | null;\n}\n\nexport interface SerializedTypedListNode extends Omit<SerializedEtNodeBase, 'options'> {\n tag: 'list';\n attributes?: TypedElementAttributesCommand | null;\n options?: SerializedTypedListOptions | null;\n}\n\nexport type SerializedEtNode = SerializedCompiledNode | SerializedTypedNode | SerializedTypedListNode;\n\nexport interface SerializedPageRoot extends SerializedTypedNode {\n tag: typeof ELEMENT_TEMPLATE_PAGE_TYPE;\n uid: typeof ELEMENT_TEMPLATE_PAGE_HANDLE_ID;\n}\n\nexport interface ElementTemplateHydrateCommitContext {\n page: SerializedPageRoot;\n reloadVersion: number;\n}\n\nexport type CreateTemplateCommand = [\n typeof ElementTemplateUpdateOps.createTemplate,\n handleId: number,\n templateKey: string,\n bundleUrl: string | null | undefined,\n attributeSlots: SerializableValue[] | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n];\n\nexport type SetAttributeCommand = [\n typeof ElementTemplateUpdateOps.setAttribute,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadEventCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadEvent,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadRefCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadRef,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type InsertNodeCommand = [\n typeof ElementTemplateUpdateOps.insertNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n referenceHandleId: number,\n attachedSubtreeHandleIds: number[] | null,\n];\n\nexport type RemoveNodeCommand = [\n typeof ElementTemplateUpdateOps.removeNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type CreateTypedElementCommand = [\n typeof ElementTemplateUpdateOps.createTypedElement,\n handleId: number,\n type: string,\n attributes: TypedElementAttributesCommand | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n options: RuntimeOptionsCommand | TypedListOptionsCommand | null | undefined,\n];\n\nexport type InsertTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.insertTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n beforeHandleId: number,\n];\n\nexport type RemoveTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.removeTypedListItem,\n listHandleId: number,\n itemHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type UpdateTypedListItemInfoCommand = [\n typeof ElementTemplateUpdateOps.updateTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n];\n\nexport type ElementTemplateUpdateCommand =\n | CreateTemplateCommand\n | SetAttributeCommand\n | SetMainThreadEventCommand\n | SetMainThreadRefCommand\n | InsertNodeCommand\n | RemoveNodeCommand\n | CreateTypedElementCommand\n | InsertTypedListItemCommand\n | RemoveTypedListItemCommand\n | UpdateTypedListItemInfoCommand;\n\n// Commands are transported as a flat stream to match the native update payload.\n// Tuple aliases above define each opcode's shape; this item union preserves the\n// existing flat buffer ergonomics while making command contracts explicit.\nexport type ElementTemplateUpdateCommandStream = ElementTemplateUpdateCommand[number][];\n\nexport interface ElementTemplateFlushOptions {\n // triggerLayout?: boolean;\n // operationID?: any;\n // __lynx_timing_flag?: string;\n // nativeUpdateDataOrder?: number;\n // elementID?: number;\n // listID?: number;\n // listReuseNotification?: {\n // listElement: FiberElement;\n // itemKey: string;\n // };\n pipelineOptions?: PipelineOptions;\n // elementIDs?: number[];\n // operationIDs?: any[];\n // asyncFlush?: boolean;\n triggerDataUpdated?: boolean;\n emptyPatch?: boolean;\n}\n\nexport interface ElementTemplateUpdateCommitContext {\n ops: ElementTemplateUpdateCommandStream;\n flushOptions: ElementTemplateFlushOptions;\n flowIds?: number[] | undefined;\n isHydration?: boolean | undefined;\n reloadVersion?: number | undefined;\n delayedRunOnMainThreadData?: RunWorkletCtxData[] | undefined;\n mainThreadRefInitValuePatch?: MainThreadRefInitValuePatch | undefined;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/element-template/protocol/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { ElementTemplateUpdateOps } from './opcodes.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_TYPE } from './page.js';\n\nexport type SerializableValue =\n | string\n | number\n | boolean\n | null\n | SerializableValue[]\n | { [key: string]: SerializableValue };\n\nexport type RuntimeOptionValue =\n | SerializableValue\n | FiberElement\n | RuntimeOptionValue[]\n | { [key: string]: RuntimeOptionValue };\n\nexport type RuntimeOptions = Record<string, RuntimeOptionValue>;\n\nexport type RuntimeAttributeSlotValue =\n | SerializableValue\n | ((...args: unknown[]) => unknown)\n | RuntimeAttributeSlotValue[]\n | { [key: string]: RuntimeAttributeSlotValue };\n\nexport type RuntimeTypedElementAttributes = Record<string, RuntimeAttributeSlotValue>;\n\nexport type TypedElementAttributesCommand = Record<string, SerializableValue>;\n\nexport type RuntimeChildSlots = Array<ElementTemplateHandle[] | null | undefined>;\n\nexport type ElementTemplateHandleSlotsCommand = Array<number[] | null | undefined>;\n\nexport type SerializedEtNodeChildSlots = Array<SerializedEtNode[] | null | undefined>;\n\nexport interface ElementTemplateHandleRefCommandValue {\n __etHandleRef: number;\n [key: string]: SerializableValue;\n}\n\nexport interface UpdateTypedListItemCommand extends ElementTemplateHandleRefCommandValue {\n type: string;\n platformInfo: Record<string, SerializableValue>;\n subtreeHandleIds: number[];\n}\n\nexport type RuntimeOptionsCommand = Record<string, SerializableValue>;\n\n// Deferred typed-list create carries logical item records here. Its future\n// main-thread consumer resolves these refs into the list-specific runtime carrier.\nexport interface TypedListOptionsCommand extends RuntimeOptionsCommand {\n listChildren: UpdateTypedListItemCommand[];\n}\n\nexport interface RuntimeTypedListOptions {\n listChildren: ElementTemplateHandle[];\n}\n\nexport type SerializedRuntimeOptions = Record<string, SerializableValue>;\n\nexport interface SerializedTypedListOptions {\n listChildren: SerializedEtNode[];\n}\n\nexport interface SerializedEtNodeBase {\n attributeSlots?: SerializableValue[] | null;\n childSlots?: SerializedEtNodeChildSlots | null;\n uid: number;\n options?: SerializedRuntimeOptions | null;\n}\n\nexport interface SerializedCompiledNode extends SerializedEtNodeBase {\n templateKey: string;\n bundleUrl?: string;\n attributeSlots?: SerializableValue[] | null;\n}\n\nexport interface SerializedTypedNode extends SerializedEtNodeBase {\n // Native __SerializeElementTemplate returns typed hosts as { tag, attributes }.\n tag: string;\n attributes?: TypedElementAttributesCommand | null;\n}\n\nexport interface SerializedTypedListNode extends Omit<SerializedEtNodeBase, 'options'> {\n tag: 'list';\n attributes?: TypedElementAttributesCommand | null;\n options?: SerializedTypedListOptions | null;\n}\n\nexport type SerializedEtNode = SerializedCompiledNode | SerializedTypedNode | SerializedTypedListNode;\n\nexport interface SerializedPageRoot extends SerializedTypedNode {\n tag: typeof ELEMENT_TEMPLATE_PAGE_TYPE;\n uid: typeof ELEMENT_TEMPLATE_PAGE_HANDLE_ID;\n}\n\nexport interface ElementTemplateHydrateCommitContext {\n page: SerializedPageRoot;\n reloadVersion: number;\n}\n\nexport type CreateTemplateCommand = [\n typeof ElementTemplateUpdateOps.createTemplate,\n handleId: number,\n templateKey: string,\n bundleUrl: string | null | undefined,\n attributeSlots: SerializableValue[] | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n];\n\nexport type SetAttributeCommand = [\n typeof ElementTemplateUpdateOps.setAttribute,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadEventCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadEvent,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type SetMainThreadRefCommand = [\n typeof ElementTemplateUpdateOps.setMainThreadRef,\n targetHandleId: number,\n attrSlotIndex: number,\n value: SerializableValue | null,\n];\n\nexport type InsertNodeCommand = [\n typeof ElementTemplateUpdateOps.insertNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n referenceHandleId: number,\n attachedSubtreeHandleIds: number[] | null,\n];\n\nexport type RemoveNodeCommand = [\n typeof ElementTemplateUpdateOps.removeNode,\n targetHandleId: number,\n childSlotIndex: number,\n childHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type CreateTypedElementCommand = [\n typeof ElementTemplateUpdateOps.createTypedElement,\n handleId: number,\n type: string,\n attributes: TypedElementAttributesCommand | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n options: RuntimeOptionsCommand | TypedListOptionsCommand | null | undefined,\n];\n\nexport type InsertTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.insertTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n beforeHandleId: number,\n];\n\nexport type RemoveTypedListItemCommand = [\n typeof ElementTemplateUpdateOps.removeTypedListItem,\n listHandleId: number,\n itemHandleId: number,\n removedSubtreeHandleIds: number[],\n];\n\nexport type UpdateTypedListItemInfoCommand = [\n typeof ElementTemplateUpdateOps.updateTypedListItem,\n listHandleId: number,\n item: UpdateTypedListItemCommand,\n];\n\nexport type ElementTemplateUpdateCommand =\n | CreateTemplateCommand\n | SetAttributeCommand\n | SetMainThreadEventCommand\n | SetMainThreadRefCommand\n | InsertNodeCommand\n | RemoveNodeCommand\n | CreateTypedElementCommand\n | InsertTypedListItemCommand\n | RemoveTypedListItemCommand\n | UpdateTypedListItemInfoCommand;\n\n// Commands are transported as a flat stream to match the native update payload.\n// Tuple aliases above define each opcode's shape; this item union preserves the\n// existing flat buffer ergonomics while making command contracts explicit.\nexport type ElementTemplateUpdateCommandStream = ElementTemplateUpdateCommand[number][];\n\nexport interface ElementTemplateFlushOptions {\n // triggerLayout?: boolean;\n // operationID?: any;\n // __lynx_timing_flag?: string;\n // nativeUpdateDataOrder?: number;\n // elementID?: number;\n // listID?: number;\n // listReuseNotification?: {\n // listElement: FiberElement;\n // itemKey: string;\n // };\n pipelineOptions?: PipelineOptions;\n // elementIDs?: number[];\n // operationIDs?: any[];\n // asyncFlush?: boolean;\n triggerDataUpdated?: boolean;\n emptyPatch?: boolean;\n}\n\nexport interface ElementTemplateUpdateCommitContext {\n ops: ElementTemplateUpdateCommandStream;\n flushOptions: ElementTemplateFlushOptions;\n flowIds?: number[] | undefined;\n isHydration?: boolean | undefined;\n reloadVersion?: number | undefined;\n delayedRunOnMainThreadData?: RunWorkletCtxData[] | undefined;\n}\n"]}
@@ -1,6 +1,9 @@
1
1
  export declare class IndexMap<T> {
2
- protected lastIndex: number;
2
+ private counter;
3
3
  protected indexMap: Map<number, T>;
4
+ constructor(counter?: {
5
+ lastIndex: number;
6
+ });
4
7
  add(value: T): number;
5
8
  get(index: number): T | undefined;
6
9
  remove(index: number): void;
@@ -2,10 +2,13 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  export class IndexMap {
5
- lastIndex = 0;
5
+ counter;
6
6
  indexMap = new Map();
7
+ constructor(counter = { lastIndex: 0 }) {
8
+ this.counter = counter;
9
+ }
7
10
  add(value) {
8
- const index = ++this.lastIndex;
11
+ const index = ++this.counter.lastIndex;
9
12
  this.indexMap.set(index, value);
10
13
  return index;
11
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index-map.js","sourceRoot":"","sources":["../../src/shared/index-map.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,OAAO,QAAQ;IACT,SAAS,GAAG,CAAC,CAAC;IACd,QAAQ,GAAmB,IAAI,GAAG,EAAa,CAAC;IAEnD,GAAG,CAAC,KAAQ;QACjB,MAAM,KAAK,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC;QAC/B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,GAAG,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAEM,MAAM,CAAC,KAAa;QACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;CACF","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nexport class IndexMap<T> {\n protected lastIndex = 0;\n protected indexMap: Map<number, T> = new Map<number, T>();\n\n public add(value: T): number {\n const index = ++this.lastIndex;\n this.indexMap.set(index, value);\n return index;\n }\n\n public get(index: number): T | undefined {\n return this.indexMap.get(index);\n }\n\n public remove(index: number): void {\n this.indexMap.delete(index);\n }\n\n public get size(): number {\n return this.indexMap.size;\n }\n}\n"]}
1
+ {"version":3,"file":"index-map.js","sourceRoot":"","sources":["../../src/shared/index-map.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,OAAO,QAAQ;IAGC;IAFV,QAAQ,GAAmB,IAAI,GAAG,EAAa,CAAC;IAE1D,YAAoB,UAAiC,EAAE,SAAS,EAAE,CAAC,EAAE;QAAjD,YAAO,GAAP,OAAO,CAA0C;IAAG,CAAC;IAElE,GAAG,CAAC,KAAQ;QACjB,MAAM,KAAK,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;QACvC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,GAAG,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAEM,MAAM,CAAC,KAAa;QACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;CACF","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nexport class IndexMap<T> {\n protected indexMap: Map<number, T> = new Map<number, T>();\n\n constructor(private counter: { lastIndex: number } = { lastIndex: 0 }) {}\n\n public add(value: T): number {\n const index = ++this.counter.lastIndex;\n this.indexMap.set(index, value);\n return index;\n }\n\n public get(index: number): T | undefined {\n return this.indexMap.get(index);\n }\n\n public remove(index: number): void {\n this.indexMap.delete(index);\n }\n\n public get size(): number {\n return this.indexMap.size;\n }\n}\n"]}
@@ -6,12 +6,16 @@ import { __root } from '../../root.js';
6
6
  import { delayedEvents } from './event/delayEvents.js';
7
7
  import { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';
8
8
  import { globalCommitTaskMap } from './patch/commit.js';
9
+ import { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';
9
10
  import { profileEnd, profileStart } from '../../shared/profile.js';
10
11
  import { withSyncEffectFlush } from '../../utils.js';
12
+ import { resetSnapshotMainThreadFunctionRuntime } from '../worklet/call/runOnMainThread.js';
13
+ import { resetSnapshotBackgroundFunctionRuntime } from '../worklet/ctx.js';
11
14
  function destroyBackground() {
12
15
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
13
16
  profileStart('ReactLynx::destroyBackground');
14
17
  }
18
+ deinitGlobalSnapshotPatch();
15
19
  withSyncEffectFlush(() => {
16
20
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
17
21
  render(null, __root);
@@ -26,6 +30,8 @@ function destroyBackground() {
26
30
  if (delayedEvents) {
27
31
  delayedEvents.length = 0;
28
32
  }
33
+ resetSnapshotBackgroundFunctionRuntime();
34
+ resetSnapshotMainThreadFunctionRuntime();
29
35
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
30
36
  profileEnd();
31
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,SAAS,iBAAiB;IACxB,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,8BAA8B,CAAC,CAAC;IAC/C,CAAC;IAED,mBAAmB,CAAC,GAAG,EAAE;QACvB,iEAAiE;QACjE,MAAM,CAAC,IAAI,EAAE,MAAa,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACjC,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;IACH,mBAAmB,CAAC,KAAK,EAAE,CAAC;IAC5B,qEAAqE;IACrE,0DAA0D;IAC1D,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IAClC,IAAI,aAAa,EAAE,CAAC;QAClB,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,OAAO,EAAE,iBAAiB,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.\nimport { render } from 'preact';\n\nimport { __root } from '../../root.js';\nimport { delayedEvents } from './event/delayEvents.js';\nimport { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';\nimport { globalCommitTaskMap } from './patch/commit.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { withSyncEffectFlush } from '../../utils.js';\n\nfunction destroyBackground(): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::destroyBackground');\n }\n\n withSyncEffectFlush(() => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(null, __root as any);\n });\n\n globalCommitTaskMap.forEach(task => {\n task();\n });\n globalCommitTaskMap.clear();\n // Clear delayed events which should not be executed after destroyed.\n // This is important when the page is performing a reload.\n delayedLifecycleEvents.length = 0;\n if (delayedEvents) {\n delayedEvents.length = 0;\n }\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nexport { destroyBackground };\n"]}
1
+ {"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/destroy.ts"],"names":[],"mappings":"AAAA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W,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,OAAO,EAAE,iBAAiB,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.\nimport { render } from 'preact';\n\nimport { __root } from '../../root.js';\nimport { delayedEvents } from './event/delayEvents.js';\nimport { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';\nimport { globalCommitTaskMap } from './patch/commit.js';\nimport { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { withSyncEffectFlush } from '../../utils.js';\nimport { resetSnapshotMainThreadFunctionRuntime } from '../worklet/call/runOnMainThread.js';\nimport { resetSnapshotBackgroundFunctionRuntime } from '../worklet/ctx.js';\n\nfunction destroyBackground(): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::destroyBackground');\n }\n\n deinitGlobalSnapshotPatch();\n\n withSyncEffectFlush(() => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(null, __root as any);\n });\n\n globalCommitTaskMap.forEach(task => {\n task();\n });\n globalCommitTaskMap.clear();\n // Clear delayed events which should not be executed after destroyed.\n // This is important when the page is performing a reload.\n delayedLifecycleEvents.length = 0;\n if (delayedEvents) {\n delayedEvents.length = 0;\n }\n resetSnapshotBackgroundFunctionRuntime();\n resetSnapshotMainThreadFunctionRuntime();\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nexport { destroyBackground };\n"]}
@@ -1,5 +1,9 @@
1
- declare let isFirstScreenSynced: boolean;
2
- declare let firstScreenEventIdSwap: Record<string | number, number>;
1
+ declare const firstScreenSync: {
2
+ isSynced: boolean;
3
+ eventIdSwap: Record<string | number, number>;
4
+ isMarkedReady: boolean;
5
+ isTreeReady: boolean;
6
+ };
3
7
  declare function syncFirstScreen(): void;
4
8
  declare function onFirstScreenSyncReady(): void;
5
9
  declare function onFirstScreenTreeReady(): void;
@@ -1,6 +1,7 @@
1
1
  // Copyright 2025 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
+ import { cardLifetime } from '../../../core/card-lifetime.js';
4
5
  import { isProcessingDefaultData } from '../../../core/lynx-data-processors.js';
5
6
  import { __root } from '../../../root.js';
6
7
  import { profileEnd, profileStart } from '../../../shared/profile.js';
@@ -8,12 +9,14 @@ import { LifecycleConstant } from '../../lifecycle/constant.js';
8
9
  // Initialized once at module load (`renderPage` runs once per runtime and does
9
10
  // not reset), so a ready mark set before `renderPage` (e.g. in `defaultDataProcessor`)
10
11
  // survives. In `'manual'` mode the first screen syncs only after both are true.
11
- let isFirstScreenSynced = false;
12
- let firstScreenEventIdSwap = {};
13
- let isMarkedFirstScreenSyncReady = false;
14
- let isFirstScreenTreeReady = false;
12
+ const firstScreenSync = /*#__PURE__*/ cardLifetime('firstScreenSync', () => ({
13
+ isSynced: false,
14
+ eventIdSwap: {},
15
+ isMarkedReady: false,
16
+ isTreeReady: false,
17
+ }));
15
18
  function syncFirstScreen() {
16
- isFirstScreenSynced = true;
19
+ firstScreenSync.isSynced = true;
17
20
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
18
21
  profileStart('ReactLynx::serializeRoot');
19
22
  }
@@ -28,23 +31,23 @@ function syncFirstScreen() {
28
31
  LifecycleConstant.firstScreen, /* FIRST_SCREEN */
29
32
  {
30
33
  root,
31
- firstScreenEventIdSwap,
34
+ firstScreenEventIdSwap: firstScreenSync.eventIdSwap,
32
35
  },
33
36
  ]);
34
37
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
35
38
  profileEnd();
36
39
  }
37
- firstScreenEventIdSwap = {};
40
+ firstScreenSync.eventIdSwap = {};
38
41
  }
39
42
  // ready signal: business/framework allows the handover. Syncs if the tree is ready.
40
43
  function onFirstScreenSyncReady() {
41
44
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
42
45
  profileStart('ReactLynx::onFirstScreenSyncReady');
43
46
  }
44
- isMarkedFirstScreenSyncReady = true;
47
+ firstScreenSync.isMarkedReady = true;
45
48
  // A mark made inside `defaultDataProcessor` (a native call before the upcoming render)
46
49
  // is recorded but not synced now; `onFirstScreenTreeReady` honors it once render ends.
47
- if (isFirstScreenTreeReady && !isProcessingDefaultData() && !isFirstScreenSynced) {
50
+ if (firstScreenSync.isTreeReady && !isProcessingDefaultData() && !firstScreenSync.isSynced) {
48
51
  syncFirstScreen();
49
52
  }
50
53
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
@@ -53,28 +56,28 @@ function onFirstScreenSyncReady() {
53
56
  }
54
57
  // tree built (`renderPage` / `updatePage` done). Syncs if the ready signal already came.
55
58
  function onFirstScreenTreeReady() {
56
- isFirstScreenTreeReady = true;
57
- if (isMarkedFirstScreenSyncReady && !isFirstScreenSynced) {
59
+ firstScreenSync.isTreeReady = true;
60
+ if (firstScreenSync.isMarkedReady && !firstScreenSync.isSynced) {
58
61
  syncFirstScreen();
59
62
  }
60
63
  }
61
64
  // the first-screen tree is being (re-)rendered, a mark during this period
62
65
  // must not sync until the next `onFirstScreenTreeReady`
63
66
  function resetFirstScreenTreeReady() {
64
- isFirstScreenTreeReady = false;
67
+ firstScreenSync.isTreeReady = false;
65
68
  }
66
69
  function clearFirstScreenEventIdSwap() {
67
- firstScreenEventIdSwap = {};
70
+ firstScreenSync.eventIdSwap = {};
68
71
  }
69
72
  // Full reset of all first-screen state. Used by SSR hydration to re-initialize.
70
73
  function resetFirstScreenSyncState() {
71
- isFirstScreenSynced = false;
72
- firstScreenEventIdSwap = {};
73
- isMarkedFirstScreenSyncReady = false;
74
- isFirstScreenTreeReady = false;
74
+ firstScreenSync.isSynced = false;
75
+ firstScreenSync.eventIdSwap = {};
76
+ firstScreenSync.isMarkedReady = false;
77
+ firstScreenSync.isTreeReady = false;
75
78
  }
76
79
  /**
77
80
  * @internal
78
81
  */
79
- export { syncFirstScreen, isFirstScreenSynced, firstScreenEventIdSwap, clearFirstScreenEventIdSwap, resetFirstScreenSyncState, onFirstScreenSyncReady, onFirstScreenTreeReady, resetFirstScreenTreeReady, };
82
+ export { syncFirstScreen, firstScreenSync, clearFirstScreenEventIdSwap, resetFirstScreenSyncState, onFirstScreenSyncReady, onFirstScreenTreeReady, resetFirstScreenTreeReady, };
80
83
  //# sourceMappingURL=firstScreenSync.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"firstScreenSync.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/event/firstScreenSync.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,+EAA+E;AAC/E,uFAAuF;AACvF,gFAAgF;AAChF,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAChC,IAAI,sBAAsB,GAAoC,EAAE,CAAC;AACjE,IAAI,4BAA4B,GAAG,KAAK,CAAC;AACzC,IAAI,sBAAsB,GAAG,KAAK,CAAC;AAEnC,SAAS,eAAe;IACtB,mBAAmB,GAAG,IAAI,CAAC;IAE3B,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,0BAA0B,CAAC,CAAC;IAC3C,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf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BAA4B,GAAG,KAAK,CAAC;IACrC,sBAAsB,GAAG,KAAK,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,2BAA2B,EAC3B,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,GAC1B,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { isProcessingDefaultData } from '../../../core/lynx-data-processors.js';\nimport { __root } from '../../../root.js';\nimport { profileEnd, profileStart } from '../../../shared/profile.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\n\n// Initialized once at module load (`renderPage` runs once per runtime and does\n// not reset), so a ready mark set before `renderPage` (e.g. in `defaultDataProcessor`)\n// survives. In `'manual'` mode the first screen syncs only after both are true.\nlet isFirstScreenSynced = false;\nlet firstScreenEventIdSwap: Record<string | number, number> = {};\nlet isMarkedFirstScreenSyncReady = false;\nlet isFirstScreenTreeReady = false;\n\nfunction syncFirstScreen(): void {\n isFirstScreenSynced = true;\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::serializeRoot');\n }\n const root = JSON.stringify(__root);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::transferRoot');\n }\n __OnLifecycleEvent([\n LifecycleConstant.firstScreen, /* FIRST_SCREEN */\n {\n root,\n firstScreenEventIdSwap,\n },\n ]);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n firstScreenEventIdSwap = {};\n}\n\n// ready signal: business/framework allows the handover. Syncs if the tree is ready.\nfunction onFirstScreenSyncReady(): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::onFirstScreenSyncReady');\n }\n isMarkedFirstScreenSyncReady = true;\n // A mark made inside `defaultDataProcessor` (a native call before the upcoming render)\n // is recorded but not synced now; `onFirstScreenTreeReady` honors it once render ends.\n if (isFirstScreenTreeReady && !isProcessingDefaultData() && !isFirstScreenSynced) {\n syncFirstScreen();\n }\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\n// tree built (`renderPage` / `updatePage` done). Syncs if the ready signal already came.\nfunction onFirstScreenTreeReady(): void {\n isFirstScreenTreeReady = true;\n if (isMarkedFirstScreenSyncReady && !isFirstScreenSynced) {\n syncFirstScreen();\n }\n}\n\n// the first-screen tree is being (re-)rendered, a mark during this period\n// must not sync until the next `onFirstScreenTreeReady`\nfunction resetFirstScreenTreeReady(): void {\n isFirstScreenTreeReady = false;\n}\n\nfunction clearFirstScreenEventIdSwap(): void {\n firstScreenEventIdSwap = {};\n}\n\n// Full reset of all first-screen state. Used by SSR hydration to re-initialize.\nfunction resetFirstScreenSyncState(): void {\n isFirstScreenSynced = false;\n firstScreenEventIdSwap = {};\n isMarkedFirstScreenSyncReady = false;\n isFirstScreenTreeReady = false;\n}\n\n/**\n * @internal\n */\nexport {\n syncFirstScreen,\n isFirstScreenSynced,\n firstScreenEventIdSwap,\n clearFirstScreenEventIdSwap,\n resetFirstScreenSyncState,\n onFirstScreenSyncReady,\n onFirstScreenTreeReady,\n resetFirstScreenTreeReady,\n};\n"]}
1
+ {"version":3,"file":"firstScreenSync.js","sourceRoot":"","sources":["../../../../src/snapshot/lifecycle/event/firstScreenSync.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC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uF;IACvF,uFAAuF;IACvF,IAAI,eAAe,CAAC,WAAW,IAAI,CAAC,uBAAuB,EAAE,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC;QAC3F,eAAe,EAAE,CAAC;IACpB,CAAC;IACD,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,yFAAyF;AACzF,SAAS,sBAAsB;IAC7B,eAAe,CAAC,WAAW,GAAG,IAAI,CAAC;IACnC,IAAI,eAAe,CAAC,aAAa,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC;QAC/D,eAAe,EAAE,CAAC;IACpB,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,wDAAwD;AACxD,SAAS,yBAAyB;IAChC,eAAe,CAAC,WAAW,GAAG,KAAK,CAAC;AACtC,CAAC;AAED,SAAS,2BAA2B;IAClC,eAAe,CAAC,WAAW,GAAG,EAAE,CAAC;AACnC,CAAC;AAED,gFAAgF;AAChF,SAAS,yBAAyB;IAChC,eAAe,CAAC,QAAQ,GAAG,KAAK,CAAC;IACjC,eAAe,CAAC,WAAW,GAAG,EAAE,CAAC;IACjC,eAAe,CAAC,aAAa,GAAG,KAAK,CAAC;IACtC,eAAe,CAAC,WAAW,GAAG,KAAK,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,OAAO,EACL,eAAe,EACf,eAAe,EACf,2BAA2B,EAC3B,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,GAC1B,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { cardLifetime } from '../../../core/card-lifetime.js';\nimport { isProcessingDefaultData } from '../../../core/lynx-data-processors.js';\nimport { __root } from '../../../root.js';\nimport { profileEnd, profileStart } from '../../../shared/profile.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\n\n// Initialized once at module load (`renderPage` runs once per runtime and does\n// not reset), so a ready mark set before `renderPage` (e.g. in `defaultDataProcessor`)\n// survives. In `'manual'` mode the first screen syncs only after both are true.\nconst firstScreenSync: {\n isSynced: boolean;\n eventIdSwap: Record<string | number, number>;\n isMarkedReady: boolean;\n isTreeReady: boolean;\n} = /*#__PURE__*/ cardLifetime('firstScreenSync', () => ({\n isSynced: false,\n eventIdSwap: {},\n isMarkedReady: false,\n isTreeReady: false,\n}));\n\nfunction syncFirstScreen(): void {\n firstScreenSync.isSynced = true;\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::serializeRoot');\n }\n const root = JSON.stringify(__root);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::transferRoot');\n }\n __OnLifecycleEvent([\n LifecycleConstant.firstScreen, /* FIRST_SCREEN */\n {\n root,\n firstScreenEventIdSwap: firstScreenSync.eventIdSwap,\n },\n ]);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n firstScreenSync.eventIdSwap = {};\n}\n\n// ready signal: business/framework allows the handover. Syncs if the tree is ready.\nfunction onFirstScreenSyncReady(): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::onFirstScreenSyncReady');\n }\n firstScreenSync.isMarkedReady = true;\n // A mark made inside `defaultDataProcessor` (a native call before the upcoming render)\n // is recorded but not synced now; `onFirstScreenTreeReady` honors it once render ends.\n if (firstScreenSync.isTreeReady && !isProcessingDefaultData() && !firstScreenSync.isSynced) {\n syncFirstScreen();\n }\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\n// tree built (`renderPage` / `updatePage` done). Syncs if the ready signal already came.\nfunction onFirstScreenTreeReady(): void {\n firstScreenSync.isTreeReady = true;\n if (firstScreenSync.isMarkedReady && !firstScreenSync.isSynced) {\n syncFirstScreen();\n }\n}\n\n// the first-screen tree is being (re-)rendered, a mark during this period\n// must not sync until the next `onFirstScreenTreeReady`\nfunction resetFirstScreenTreeReady(): void {\n firstScreenSync.isTreeReady = false;\n}\n\nfunction clearFirstScreenEventIdSwap(): void {\n firstScreenSync.eventIdSwap = {};\n}\n\n// Full reset of all first-screen state. Used by SSR hydration to re-initialize.\nfunction resetFirstScreenSyncState(): void {\n firstScreenSync.isSynced = false;\n firstScreenSync.eventIdSwap = {};\n firstScreenSync.isMarkedReady = false;\n firstScreenSync.isTreeReady = false;\n}\n\n/**\n * @internal\n */\nexport {\n syncFirstScreen,\n firstScreenSync,\n clearFirstScreenEventIdSwap,\n resetFirstScreenSyncState,\n onFirstScreenSyncReady,\n onFirstScreenTreeReady,\n resetFirstScreenTreeReady,\n};\n"]}
@@ -1,3 +1,10 @@
1
+ import { SnapshotInstance } from '../snapshot/snapshot.js';
1
2
  declare function reloadMainThread(data: unknown, options: UpdatePageOption): void;
2
- declare function reloadBackground(updateData: Record<string, any>): void;
3
- export { reloadBackground, reloadMainThread };
3
+ interface MainThreadReloadHandoff {
4
+ oldRoot: SnapshotInstance;
5
+ page: FiberElement;
6
+ options: UpdatePageOption;
7
+ }
8
+ declare function completeMainThreadReload({ oldRoot, page, options }: MainThreadReloadHandoff): void;
9
+ declare function reloadBackground(updateData: Record<string, any>, options?: Record<string, unknown>): void;
10
+ export { completeMainThreadReload, reloadBackground, reloadMainThread };
@@ -6,25 +6,29 @@
6
6
  * and background thread.
7
7
  */
8
8
  import { render } from 'preact';
9
+ import { clearDelayedRunOnBackgroundFunctions } from '@lynx-js/react/worklet-runtime/bindings';
9
10
  import { destroyBackground } from './destroy.js';
10
11
  import { renderMainThread } from './render.js';
12
+ import { canReEvalBackgroundEntry, canReEvalMainThreadEntry, installMainThreadReloadCompleter, reEvalBackgroundEntry, reEvalMainThreadEntry, } from '../../core/entry-reload.js';
11
13
  import { increaseReloadVersion } from '../../core/reload-version.js';
14
+ import { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';
12
15
  import { __root, setRoot } from '../../root.js';
13
16
  import { profileEnd, profileStart } from '../../shared/profile.js';
14
17
  import { isEmptyObject } from '../../utils.js';
15
18
  import { LifecycleConstant } from '../lifecycle/constant.js';
16
19
  import { __pendingListUpdates } from '../list/pendingListUpdates.js';
17
20
  import { hydrate } from '../renderToOpcodes/hydrate.js';
18
- import { __page } from '../snapshot/definition.js';
21
+ import { __page, setupPage } from '../snapshot/definition.js';
19
22
  import { SnapshotInstance, snapshotInstanceManager } from '../snapshot/snapshot.js';
20
23
  import { applyRefQueue } from '../snapshot/workletRef.js';
21
- import { clearFirstScreenEventIdSwap, isFirstScreenSynced } from './event/firstScreenSync.js';
22
- import { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';
24
+ import { clearFirstScreenEventIdSwap, firstScreenSync } from './event/firstScreenSync.js';
23
25
  import { shouldDelayUiOps } from './ref/delay.js';
24
26
  function reloadMainThread(data, options) {
25
27
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
26
28
  profileStart('ReactLynx::reloadMainThread');
27
29
  }
30
+ clearDelayedRunOnBackgroundFunctions();
31
+ resetFunctionCallReturnListener();
28
32
  increaseReloadVersion();
29
33
  if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {
30
34
  Object.assign(lynx.__initData, data);
@@ -33,8 +37,20 @@ function reloadMainThread(data, options) {
33
37
  __pendingListUpdates.clearAttachedLists();
34
38
  clearFirstScreenEventIdSwap();
35
39
  const oldRoot = __root;
40
+ if (canReEvalMainThreadEntry()) {
41
+ reEvalMainThreadEntry({ oldRoot: oldRoot, page: __page, options });
42
+ return;
43
+ }
36
44
  setRoot(new SnapshotInstance('root'));
37
45
  __root.__jsx = oldRoot.__jsx;
46
+ finishMainThreadReload(oldRoot, options);
47
+ }
48
+ function completeMainThreadReload({ oldRoot, page, options }) {
49
+ setupPage(page);
50
+ finishMainThreadReload(oldRoot, options);
51
+ }
52
+ installMainThreadReloadCompleter(completeMainThreadReload);
53
+ function finishMainThreadReload(oldRoot, options) {
38
54
  renderMainThread();
39
55
  hydrate(oldRoot, __root, {
40
56
  skipUnRef: true,
@@ -45,7 +61,7 @@ function reloadMainThread(data, options) {
45
61
  if (typeof lepusng_gc === 'function') {
46
62
  lepusng_gc();
47
63
  }
48
- if (isFirstScreenSynced) {
64
+ if (firstScreenSync.isSynced) {
49
65
  __OnLifecycleEvent([
50
66
  LifecycleConstant.firstScreen, /* FIRST_SCREEN */
51
67
  {
@@ -57,13 +73,18 @@ function reloadMainThread(data, options) {
57
73
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
58
74
  profileEnd();
59
75
  }
60
- return;
61
76
  }
62
- function reloadBackground(updateData) {
77
+ function reloadBackground(updateData, options) {
78
+ if (canReEvalBackgroundEntry()) {
79
+ reEvalBackgroundEntry(updateData, options, () => {
80
+ // A queued `updateGlobalProps` callback must not render it again.
81
+ __root.__jsx = undefined;
82
+ });
83
+ return;
84
+ }
63
85
  if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
64
86
  profileStart('ReactLynx::reloadBackground');
65
87
  }
66
- deinitGlobalSnapshotPatch();
67
88
  destroyBackground();
68
89
  increaseReloadVersion();
69
90
  // COW when modify `lynx.__initData` to make sure Provider & Consumer works
@@ -75,5 +96,5 @@ function reloadBackground(updateData) {
75
96
  profileEnd();
76
97
  }
77
98
  }
78
- export { reloadBackground, reloadMainThread };
99
+ export { completeMainThreadReload, reloadBackground, reloadMainThread };
79
100
  //# sourceMappingURL=reload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reload.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/reload.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,iBAAiB,EAAE,MAAM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B,iEAAiE;IACjE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAa,CAAC,CAAC;IAEpC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements the reload (thinking of \"refresh\" in browser) for both main thread\n * and background thread.\n */\n\nimport { render } from 'preact';\n\nimport { destroyBackground } from './destroy.js';\nimport { renderMainThread } from './render.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { __root, setRoot } from '../../root.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { isEmptyObject } from '../../utils.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport { __pendingListUpdates } from '../list/pendingListUpdates.js';\nimport { hydrate } from '../renderToOpcodes/hydrate.js';\nimport { __page } from '../snapshot/definition.js';\nimport { SnapshotInstance, snapshotInstanceManager } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\nimport { clearFirstScreenEventIdSwap, isFirstScreenSynced } from './event/firstScreenSync.js';\nimport { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';\nimport { shouldDelayUiOps } from './ref/delay.js';\n\nfunction reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n increaseReloadVersion();\n\n if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {\n Object.assign(lynx.__initData, data);\n }\n\n snapshotInstanceManager.clear();\n __pendingListUpdates.clearAttachedLists();\n clearFirstScreenEventIdSwap();\n\n const oldRoot = __root;\n setRoot(new SnapshotInstance('root'));\n __root.__jsx = oldRoot.__jsx;\n renderMainThread();\n hydrate(oldRoot as SnapshotInstance, __root as SnapshotInstance, {\n skipUnRef: true,\n });\n\n // always call this before `__FlushElementTree`\n __pendingListUpdates.flush();\n applyRefQueue();\n\n if (typeof lepusng_gc === 'function') {\n lepusng_gc();\n }\n\n if (isFirstScreenSynced) {\n __OnLifecycleEvent([\n LifecycleConstant.firstScreen, /* FIRST_SCREEN */\n {\n root: JSON.stringify(__root),\n },\n ]);\n }\n\n __FlushElementTree(__page, options);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n return;\n}\n\nfunction reloadBackground(updateData: Record<string, any>): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadBackground');\n }\n\n deinitGlobalSnapshotPatch();\n\n destroyBackground();\n\n increaseReloadVersion();\n\n // COW when modify `lynx.__initData` to make sure Provider & Consumer works\n lynx.__initData = Object.assign({}, lynx.__initData, updateData);\n\n shouldDelayUiOps.value = true;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(__root.__jsx, __root as any);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nexport { reloadBackground, reloadMainThread };\n"]}
1
+ {"version":3,"file":"reload.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/reload.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,oCAAoC,EAAE,MAAM,yCAAyC,CAAC;AAE/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,gCAAgC,EAChC,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,O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,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,UAA+B,EAAE,OAAiC;IAC1F,IAAI,wBAAwB,EAAE,EAAE,CAAC;QAC/B,qBAAqB,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE;YAC9C,kEAAkE;YAClE,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC;QAC3B,CAAC,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,6BAA6B,CAAC,CAAC;IAC9C,CAAC;IAED,iBAAiB,EAAE,CAAC;IACpB,qBAAqB,EAAE,CAAC;IAExB,2EAA2E;IAC3E,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEjE,gBAAgB,CAAC,KAAK,GAAG,IAAI,CAAC;IAC9B,iEAAiE;IACjE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAa,CAAC,CAAC;IAEpC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements the reload (thinking of \"refresh\" in browser) for both main thread\n * and background thread.\n */\n\nimport { render } from 'preact';\n\nimport { clearDelayedRunOnBackgroundFunctions } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { destroyBackground } from './destroy.js';\nimport { renderMainThread } from './render.js';\nimport {\n canReEvalBackgroundEntry,\n canReEvalMainThreadEntry,\n installMainThreadReloadCompleter,\n reEvalBackgroundEntry,\n reEvalMainThreadEntry,\n} from '../../core/entry-reload.js';\nimport { increaseReloadVersion } from '../../core/reload-version.js';\nimport { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';\nimport { __root, setRoot } from '../../root.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { isEmptyObject } from '../../utils.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport { __pendingListUpdates } from '../list/pendingListUpdates.js';\nimport { hydrate } from '../renderToOpcodes/hydrate.js';\nimport { __page, setupPage } from '../snapshot/definition.js';\nimport { SnapshotInstance, snapshotInstanceManager } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\nimport { clearFirstScreenEventIdSwap, firstScreenSync } from './event/firstScreenSync.js';\nimport { shouldDelayUiOps } from './ref/delay.js';\n\nfunction reloadMainThread(data: unknown, options: UpdatePageOption): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadMainThread');\n }\n\n clearDelayedRunOnBackgroundFunctions();\n resetFunctionCallReturnListener();\n increaseReloadVersion();\n\n if (typeof data == 'object' && data !== null && !isEmptyObject(data)) {\n Object.assign(lynx.__initData, data);\n }\n\n snapshotInstanceManager.clear();\n __pendingListUpdates.clearAttachedLists();\n clearFirstScreenEventIdSwap();\n\n const oldRoot = __root;\n if (canReEvalMainThreadEntry()) {\n reEvalMainThreadEntry<MainThreadReloadHandoff>({ oldRoot: oldRoot as SnapshotInstance, page: __page, options });\n return;\n }\n setRoot(new SnapshotInstance('root'));\n __root.__jsx = oldRoot.__jsx;\n finishMainThreadReload(oldRoot as SnapshotInstance, options);\n}\n\ninterface MainThreadReloadHandoff {\n oldRoot: SnapshotInstance;\n page: FiberElement;\n options: UpdatePageOption;\n}\n\nfunction completeMainThreadReload({ oldRoot, page, options }: MainThreadReloadHandoff): void {\n setupPage(page);\n finishMainThreadReload(oldRoot, options);\n}\n\ninstallMainThreadReloadCompleter(completeMainThreadReload);\n\nfunction finishMainThreadReload(oldRoot: SnapshotInstance, options: UpdatePageOption): void {\n renderMainThread();\n hydrate(oldRoot, __root as SnapshotInstance, {\n skipUnRef: true,\n });\n\n // always call this before `__FlushElementTree`\n __pendingListUpdates.flush();\n applyRefQueue();\n\n if (typeof lepusng_gc === 'function') {\n lepusng_gc();\n }\n\n if (firstScreenSync.isSynced) {\n __OnLifecycleEvent([\n LifecycleConstant.firstScreen, /* FIRST_SCREEN */\n {\n root: JSON.stringify(__root),\n },\n ]);\n }\n\n __FlushElementTree(__page, options);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nfunction reloadBackground(updateData: Record<string, any>, options?: Record<string, unknown>): void {\n if (canReEvalBackgroundEntry()) {\n reEvalBackgroundEntry(updateData, options, () => {\n // A queued `updateGlobalProps` callback must not render it again.\n __root.__jsx = undefined;\n });\n return;\n }\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::reloadBackground');\n }\n\n destroyBackground();\n increaseReloadVersion();\n\n // COW when modify `lynx.__initData` to make sure Provider & Consumer works\n lynx.__initData = Object.assign({}, lynx.__initData, updateData);\n\n shouldDelayUiOps.value = true;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(__root.__jsx, __root as any);\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n}\n\nexport { completeMainThreadReload, reloadBackground, reloadMainThread };\n"]}
@@ -1,11 +1,12 @@
1
1
  // Copyright 2024 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
+ import { cardLifetime } from '../../core/card-lifetime.js';
4
5
  import { maybePromise } from '../../utils.js';
5
6
  import { LifecycleConstant } from '../lifecycle/constant.js';
6
7
  import { applyRefQueue } from '../snapshot/workletRef.js';
7
- export const gSignMap = {};
8
- export const gRecycleMap = {};
8
+ export const gSignMap = /*#__PURE__*/ cardLifetime('listSignMap', () => ({}));
9
+ export const gRecycleMap = /*#__PURE__*/ cardLifetime('listRecycleMap', () => ({}));
9
10
  const gParentWeakMap = /*#__PURE__*/ new WeakMap();
10
11
  const resolvedPromise = /* @__PURE__ */ Promise.resolve();
11
12
  export function clearListGlobal() {
@@ -1 +1 @@
1
- {"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/snapshot/list/list.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,MAAM,CAAC,MAAM,QAAQ,GAAkD,EAAE,CAAC;AAC1E,MAAM,CAAC,MAAM,WAAW,GAA+D,EAAE,CAAC;AAC1F,MAAM,cAAc,GAAuC,aAAa,CAAC,IAAI,OAAO,EAAE,CAAC;AACvF,MAAM,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AAE1D,MAAM,UAAU,eAAe;IAC7B,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,GAAuB,EACvB,eAA4E;IAE5E,2FAA2F;IAC3F,wBAAwB;IACxB,qEAAqE;IACrE,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QACvB,IAAI,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjC,kBAAkB;QACpB,CAAC;aAAM,CAA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AE,QAAQ,CAAC,CAAC;IAC9C,CAAC,CAAC;IACF,OAAO,gBAAgB,CAAC;AAC1B,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.\nimport { maybePromise } from '../../utils.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport type { SnapshotInstance } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\n\nexport const gSignMap: Record<number, Map<number, SnapshotInstance>> = {};\nexport const gRecycleMap: Record<number, Map<string, Map<number, SnapshotInstance>>> = {};\nconst gParentWeakMap: WeakMap<SnapshotInstance, unknown> = /*#__PURE__*/ new WeakMap();\nconst resolvedPromise = /* @__PURE__ */ Promise.resolve();\n\nexport function clearListGlobal(): void {\n for (const key in gSignMap) {\n delete gSignMap[key];\n }\n for (const key in gRecycleMap) {\n delete gRecycleMap[key];\n }\n}\n\nexport function componentAtIndexFactory(\n ctx: SnapshotInstance[],\n hydrateFunction: (before: SnapshotInstance, after: SnapshotInstance) => void,\n): [ComponentAtIndexCallback, ComponentAtIndexesCallback] {\n // A hack workaround to ensure childCtx has no direct reference through `__parent` to list,\n // to avoid memory leak.\n // TODO(hzy): make `__parent` a WeakRef or `#__parent` in the future.\n ctx.forEach((childCtx) => {\n if (gParentWeakMap.has(childCtx)) {\n // do it only once\n } else {\n gParentWeakMap.set(childCtx, childCtx.parentNode!);\n Object.defineProperty(childCtx, '__parent', {\n get: () => gParentWeakMap.get(childCtx)!,\n set: (value: unknown) => {\n gParentWeakMap.set(childCtx, value);\n },\n });\n }\n });\n\n const componentAtChildCtx = (\n list: FiberElement,\n listID: number,\n childCtx: SnapshotInstance,\n operationID: number,\n enableReuseNotification: boolean,\n enableBatchRender: boolean = false,\n asyncFlush: boolean = false,\n ) => {\n const signMap = gSignMap[listID];\n const recycleMap = gRecycleMap[listID];\n\n /* v8 ignore start */\n if (!signMap || !recycleMap) {\n // Theoretically unreachable since snapshotDestroyList clears componentAtIndex with a noop function.\n // Kept as a safeguard in case the callback is somehow invoked after list removal.\n throw new Error('componentAtIndex called on removed list');\n }\n /* v8 ignore end */\n\n const platformInfo = childCtx.__listItemPlatformInfo ?? {};\n\n // The lifecycle of this `__extraProps.isReady`:\n // 0 -> Promise<number> -> 1\n // 0: The initial state, the list-item is not ready yet, we will send a event to background\n // when `componentAtIndex` is called on it\n // Promise<number>: A promise that will be resolved when the list-item is ready\n // 1: The list-item is ready, we can use it to render the list\n if (childCtx.__extraProps?.['isReady'] === 0) {\n if (\n typeof __GetAttributeByName === 'function'\n && __GetAttributeByName(list, 'custom-list-name') === 'list-container'\n ) {\n // we are in supported env\n // do not throw\n } else {\n throw new Error(\n 'Unsupported: `<list-item/>` with `defer={true}` must be used with `<list custom-list-name=\"list-container\"/>`',\n );\n }\n\n // send a event to background to render the list-item\n __OnLifecycleEvent([LifecycleConstant.publishEvent, {\n handlerName: `${childCtx.__id}:__extraProps:onComponentAtIndex`,\n data: {},\n }]);\n\n // use a promise to track the list-item's readiness\n let p: Promise<number>;\n return (p = new Promise<number>((resolve) => {\n Object.defineProperty(childCtx.__extraProps, 'isReady', {\n set(isReady) {\n if (isReady === 1) {\n delete childCtx.__extraProps!['isReady'];\n childCtx.__extraProps!['isReady'] = 1;\n\n void resolvedPromise.then(() => {\n // the cellIndex may be changed already, but the `childCtx` is the same\n resolve(componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification));\n });\n }\n },\n get() {\n return p;\n },\n });\n }));\n } else if (maybePromise<number>(childCtx.__extraProps?.['isReady'])) {\n throw new Error('componentAtIndex was called on a pending deferred list item');\n }\n\n const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');\n const recycleSignMap = recycleMap.get(uniqID);\n\n if (childCtx.__elements) {\n /**\n * If this situation is encountered, there might be two cases:\n * 1. Reusing with itself\n * In this case, enqueueComponent will be triggered first, followed by componentAtIndex.\n * 2. Moving\n * In this case, the trigger order is uncertain; componentAtIndex might be triggered first, or enqueueComponent might be triggered first.\n *\n * When enqueueComponent is triggered first, there must be an item in the reuse pool with the same sign as here, which can be returned directly.\n * When componentAtIndex is triggered first, a clone needs to be made first, then follow the logic for adding or reusing. The cloned item will enter the reuse pool in the subsequent enqueueComponent.\n */\n const root = childCtx.__elements[0]!;\n const sign = __GetElementUniqueID(root);\n\n if (recycleSignMap?.has(sign)) {\n signMap.set(sign, childCtx);\n recycleSignMap.delete(sign);\n if (!enableBatchRender) {\n __FlushElementTree(root, { triggerLayout: true, operationID, elementID: sign, listID });\n } else if (enableBatchRender && asyncFlush) {\n __FlushElementTree(root, { asyncFlush: true });\n }\n // enableBatchRender == true && asyncFlush == false\n // in this case, no need to invoke __FlushElementTree because in the end of componentAtIndexes(), the list will invoke __FlushElementTree.\n return sign;\n } else {\n const newCtx = childCtx.takeElements();\n signMap.set(sign, newCtx);\n }\n }\n\n if (recycleSignMap && recycleSignMap.size > 0) {\n const [first] = recycleSignMap;\n const [sign, oldCtx] = first!;\n recycleSignMap.delete(sign);\n hydrateFunction(oldCtx, childCtx);\n oldCtx.unRenderElements();\n if (!oldCtx.__id) {\n oldCtx.tearDown();\n } else if (oldCtx.__extraProps?.['isReady'] === 1) {\n // send a event to background to recycle the list-item\n __OnLifecycleEvent([LifecycleConstant.publishEvent, {\n handlerName: `${oldCtx.__id}:__extraProps:onRecycleComponent`,\n data: {},\n }]);\n }\n const root = childCtx.__element_root!;\n applyRefQueue();\n // In the defer `list-item` scenario, `componentAtIndex` occurs with delay.\n // Within `componentAtIndex`, nodes that quickly appear and disappear due to re-layout will be enqueued again,\n // causing the mapping relationship between sign and SnapshotInstance to become corrupted.\n // This results in a SnapshotInstance without `__elements` being enqueued.\n signMap.set(sign, childCtx);\n if (!enableBatchRender) {\n const flushOptions: FlushOptions = {\n triggerLayout: true,\n operationID,\n elementID: sign,\n listID,\n };\n if (enableReuseNotification) {\n flushOptions.listReuseNotification = {\n listElement: list,\n itemKey: platformInfo['item-key']!,\n };\n }\n __FlushElementTree(root, flushOptions);\n } else if (enableBatchRender && asyncFlush) {\n const flushOptions: FlushOptions = {\n asyncFlush: true,\n };\n if (enableReuseNotification) {\n flushOptions.listReuseNotification = {\n listElement: list,\n itemKey: platformInfo['item-key']!,\n };\n }\n __FlushElementTree(root, flushOptions);\n }\n return sign;\n }\n\n childCtx.ensureElements();\n const root = childCtx.__element_root!;\n __AppendElement(list, root);\n const sign = __GetElementUniqueID(root);\n applyRefQueue();\n signMap.set(sign, childCtx);\n if (!enableBatchRender) {\n __FlushElementTree(root, {\n triggerLayout: true,\n operationID,\n elementID: sign,\n listID,\n });\n } else if (enableBatchRender && asyncFlush) {\n __FlushElementTree(root, {\n asyncFlush: true,\n });\n }\n return sign;\n };\n\n function componentAtIndex(\n list: FiberElement,\n listID: number,\n cellIndex: number,\n operationID: number,\n enableReuseNotification: boolean,\n ) {\n const childCtx = ctx[cellIndex];\n if (!childCtx) {\n throw new Error('childCtx not found');\n }\n const r = componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification);\n\n /* v8 ignore start */\n if (process.env['NODE_ENV'] === 'test') {\n return r;\n } else {\n return typeof r === 'number' ? r : undefined;\n }\n /* v8 ignore end */\n }\n\n function componentAtIndexes(\n list: FiberElement,\n listID: number,\n cellIndexes: number[],\n operationIDs: number[],\n enableReuseNotification: boolean,\n asyncFlush: boolean,\n ) {\n let hasUnready = false;\n const p: Array<Promise<number> | number> = [];\n\n cellIndexes.forEach((cellIndex, index) => {\n const operationID = operationIDs[index]!;\n const childCtx = ctx[cellIndex];\n if (!childCtx) {\n throw new Error('childCtx not found');\n }\n\n const u = componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification, true, asyncFlush);\n if (typeof u === 'number') {\n // ready\n } else {\n hasUnready = true;\n }\n p.push(u);\n });\n\n // We need __FlushElementTree twice:\n // 1. The first time is sync, we flush the items that are ready, with unready items' uiSign as -1.\n // 2. The second time is async, with all the uiSigns.\n // NOTE: The `operationIDs` passed to __FlushElementTree must be the one passed in,\n // not the one generated by any code here, to workaround a bug of Lynx Engine.\n // So we CANNOT split the `operationIDs` into two parts: one for ready items, one for unready items.\n if (hasUnready) {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n void Promise.all(p).then((uiSigns) => {\n __FlushElementTree(list, {\n triggerLayout: true,\n operationIDs,\n elementIDs: uiSigns,\n listID,\n });\n });\n }\n __FlushElementTree(list, {\n triggerLayout: true,\n operationIDs,\n elementIDs: cellIndexes.map((_, index) => typeof p[index] === 'number' ? p[index] : -1),\n listID,\n });\n }\n return [componentAtIndex, componentAtIndexes] as const;\n}\n\nexport function enqueueComponentFactory(): EnqueueComponentCallback {\n // eslint-disable-next-line unicorn/consistent-function-scoping\n const enqueueComponent = (_: FiberElement, listID: number, sign: number) => {\n const signMap = gSignMap[listID];\n const recycleMap = gRecycleMap[listID];\n if (!signMap || !recycleMap) {\n throw new Error('enqueueComponent called on removed list');\n }\n\n const childCtx = signMap.get(sign)!;\n if (!childCtx) {\n return;\n }\n\n const platformInfo = childCtx.__listItemPlatformInfo ?? {};\n\n const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');\n if (!recycleMap.has(uniqID)) {\n recycleMap.set(uniqID, new Map());\n }\n recycleMap.get(uniqID)!.set(sign, childCtx);\n };\n return enqueueComponent;\n}\n"]}
1
+ {"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/snapshot/list/list.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,MAAM,CAAC,MAAM,QAAQ,GAAkD,aAAa,CAAC,YAAY,CAC/F,aAAa,EACb,GAAG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AC,CAAe,EAAE,MAAc,EAAE,IAAY,EAAE,EAAE;QACzE,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC7D,CAAC;QAED,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;QACpC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO;QACT,CAAC;QAED,MAAM,YAAY,GAAG,QAAQ,CAAC,sBAAsB,IAAI,EAAE,CAAC;QAE3D,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5B,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACpC,CAAC;QACD,UAAU,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC,CAAC;IACF,OAAO,gBAAgB,CAAC;AAC1B,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.\nimport { cardLifetime } from '../../core/card-lifetime.js';\nimport { maybePromise } from '../../utils.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport type { SnapshotInstance } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\n\nexport const gSignMap: Record<number, Map<number, SnapshotInstance>> = /*#__PURE__*/ cardLifetime(\n 'listSignMap',\n () => ({}),\n);\nexport const gRecycleMap: Record<number, Map<string, Map<number, SnapshotInstance>>> = /*#__PURE__*/ cardLifetime(\n 'listRecycleMap',\n () => ({}),\n);\nconst gParentWeakMap: WeakMap<SnapshotInstance, unknown> = /*#__PURE__*/ new WeakMap();\nconst resolvedPromise = /* @__PURE__ */ Promise.resolve();\n\nexport function clearListGlobal(): void {\n for (const key in gSignMap) {\n delete gSignMap[key];\n }\n for (const key in gRecycleMap) {\n delete gRecycleMap[key];\n }\n}\n\nexport function componentAtIndexFactory(\n ctx: SnapshotInstance[],\n hydrateFunction: (before: SnapshotInstance, after: SnapshotInstance) => void,\n): [ComponentAtIndexCallback, ComponentAtIndexesCallback] {\n // A hack workaround to ensure childCtx has no direct reference through `__parent` to list,\n // to avoid memory leak.\n // TODO(hzy): make `__parent` a WeakRef or `#__parent` in the future.\n ctx.forEach((childCtx) => {\n if (gParentWeakMap.has(childCtx)) {\n // do it only once\n } else {\n gParentWeakMap.set(childCtx, childCtx.parentNode!);\n Object.defineProperty(childCtx, '__parent', {\n get: () => gParentWeakMap.get(childCtx)!,\n set: (value: unknown) => {\n gParentWeakMap.set(childCtx, value);\n },\n });\n }\n });\n\n const componentAtChildCtx = (\n list: FiberElement,\n listID: number,\n childCtx: SnapshotInstance,\n operationID: number,\n enableReuseNotification: boolean,\n enableBatchRender: boolean = false,\n asyncFlush: boolean = false,\n ) => {\n const signMap = gSignMap[listID];\n const recycleMap = gRecycleMap[listID];\n\n /* v8 ignore start */\n if (!signMap || !recycleMap) {\n // Theoretically unreachable since snapshotDestroyList clears componentAtIndex with a noop function.\n // Kept as a safeguard in case the callback is somehow invoked after list removal.\n throw new Error('componentAtIndex called on removed list');\n }\n /* v8 ignore end */\n\n const platformInfo = childCtx.__listItemPlatformInfo ?? {};\n\n // The lifecycle of this `__extraProps.isReady`:\n // 0 -> Promise<number> -> 1\n // 0: The initial state, the list-item is not ready yet, we will send a event to background\n // when `componentAtIndex` is called on it\n // Promise<number>: A promise that will be resolved when the list-item is ready\n // 1: The list-item is ready, we can use it to render the list\n if (childCtx.__extraProps?.['isReady'] === 0) {\n if (\n typeof __GetAttributeByName === 'function'\n && __GetAttributeByName(list, 'custom-list-name') === 'list-container'\n ) {\n // we are in supported env\n // do not throw\n } else {\n throw new Error(\n 'Unsupported: `<list-item/>` with `defer={true}` must be used with `<list custom-list-name=\"list-container\"/>`',\n );\n }\n\n // send a event to background to render the list-item\n __OnLifecycleEvent([LifecycleConstant.publishEvent, {\n handlerName: `${childCtx.__id}:__extraProps:onComponentAtIndex`,\n data: {},\n }]);\n\n // use a promise to track the list-item's readiness\n let p: Promise<number>;\n return (p = new Promise<number>((resolve) => {\n Object.defineProperty(childCtx.__extraProps, 'isReady', {\n set(isReady) {\n if (isReady === 1) {\n delete childCtx.__extraProps!['isReady'];\n childCtx.__extraProps!['isReady'] = 1;\n\n void resolvedPromise.then(() => {\n // the cellIndex may be changed already, but the `childCtx` is the same\n resolve(componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification));\n });\n }\n },\n get() {\n return p;\n },\n });\n }));\n } else if (maybePromise<number>(childCtx.__extraProps?.['isReady'])) {\n throw new Error('componentAtIndex was called on a pending deferred list item');\n }\n\n const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');\n const recycleSignMap = recycleMap.get(uniqID);\n\n if (childCtx.__elements) {\n /**\n * If this situation is encountered, there might be two cases:\n * 1. Reusing with itself\n * In this case, enqueueComponent will be triggered first, followed by componentAtIndex.\n * 2. Moving\n * In this case, the trigger order is uncertain; componentAtIndex might be triggered first, or enqueueComponent might be triggered first.\n *\n * When enqueueComponent is triggered first, there must be an item in the reuse pool with the same sign as here, which can be returned directly.\n * When componentAtIndex is triggered first, a clone needs to be made first, then follow the logic for adding or reusing. The cloned item will enter the reuse pool in the subsequent enqueueComponent.\n */\n const root = childCtx.__elements[0]!;\n const sign = __GetElementUniqueID(root);\n\n if (recycleSignMap?.has(sign)) {\n signMap.set(sign, childCtx);\n recycleSignMap.delete(sign);\n if (!enableBatchRender) {\n __FlushElementTree(root, { triggerLayout: true, operationID, elementID: sign, listID });\n } else if (enableBatchRender && asyncFlush) {\n __FlushElementTree(root, { asyncFlush: true });\n }\n // enableBatchRender == true && asyncFlush == false\n // in this case, no need to invoke __FlushElementTree because in the end of componentAtIndexes(), the list will invoke __FlushElementTree.\n return sign;\n } else {\n const newCtx = childCtx.takeElements();\n signMap.set(sign, newCtx);\n }\n }\n\n if (recycleSignMap && recycleSignMap.size > 0) {\n const [first] = recycleSignMap;\n const [sign, oldCtx] = first!;\n recycleSignMap.delete(sign);\n hydrateFunction(oldCtx, childCtx);\n oldCtx.unRenderElements();\n if (!oldCtx.__id) {\n oldCtx.tearDown();\n } else if (oldCtx.__extraProps?.['isReady'] === 1) {\n // send a event to background to recycle the list-item\n __OnLifecycleEvent([LifecycleConstant.publishEvent, {\n handlerName: `${oldCtx.__id}:__extraProps:onRecycleComponent`,\n data: {},\n }]);\n }\n const root = childCtx.__element_root!;\n applyRefQueue();\n // In the defer `list-item` scenario, `componentAtIndex` occurs with delay.\n // Within `componentAtIndex`, nodes that quickly appear and disappear due to re-layout will be enqueued again,\n // causing the mapping relationship between sign and SnapshotInstance to become corrupted.\n // This results in a SnapshotInstance without `__elements` being enqueued.\n signMap.set(sign, childCtx);\n if (!enableBatchRender) {\n const flushOptions: FlushOptions = {\n triggerLayout: true,\n operationID,\n elementID: sign,\n listID,\n };\n if (enableReuseNotification) {\n flushOptions.listReuseNotification = {\n listElement: list,\n itemKey: platformInfo['item-key']!,\n };\n }\n __FlushElementTree(root, flushOptions);\n } else if (enableBatchRender && asyncFlush) {\n const flushOptions: FlushOptions = {\n asyncFlush: true,\n };\n if (enableReuseNotification) {\n flushOptions.listReuseNotification = {\n listElement: list,\n itemKey: platformInfo['item-key']!,\n };\n }\n __FlushElementTree(root, flushOptions);\n }\n return sign;\n }\n\n childCtx.ensureElements();\n const root = childCtx.__element_root!;\n __AppendElement(list, root);\n const sign = __GetElementUniqueID(root);\n applyRefQueue();\n signMap.set(sign, childCtx);\n if (!enableBatchRender) {\n __FlushElementTree(root, {\n triggerLayout: true,\n operationID,\n elementID: sign,\n listID,\n });\n } else if (enableBatchRender && asyncFlush) {\n __FlushElementTree(root, {\n asyncFlush: true,\n });\n }\n return sign;\n };\n\n function componentAtIndex(\n list: FiberElement,\n listID: number,\n cellIndex: number,\n operationID: number,\n enableReuseNotification: boolean,\n ) {\n const childCtx = ctx[cellIndex];\n if (!childCtx) {\n throw new Error('childCtx not found');\n }\n const r = componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification);\n\n /* v8 ignore start */\n if (process.env['NODE_ENV'] === 'test') {\n return r;\n } else {\n return typeof r === 'number' ? r : undefined;\n }\n /* v8 ignore end */\n }\n\n function componentAtIndexes(\n list: FiberElement,\n listID: number,\n cellIndexes: number[],\n operationIDs: number[],\n enableReuseNotification: boolean,\n asyncFlush: boolean,\n ) {\n let hasUnready = false;\n const p: Array<Promise<number> | number> = [];\n\n cellIndexes.forEach((cellIndex, index) => {\n const operationID = operationIDs[index]!;\n const childCtx = ctx[cellIndex];\n if (!childCtx) {\n throw new Error('childCtx not found');\n }\n\n const u = componentAtChildCtx(list, listID, childCtx, operationID, enableReuseNotification, true, asyncFlush);\n if (typeof u === 'number') {\n // ready\n } else {\n hasUnready = true;\n }\n p.push(u);\n });\n\n // We need __FlushElementTree twice:\n // 1. The first time is sync, we flush the items that are ready, with unready items' uiSign as -1.\n // 2. The second time is async, with all the uiSigns.\n // NOTE: The `operationIDs` passed to __FlushElementTree must be the one passed in,\n // not the one generated by any code here, to workaround a bug of Lynx Engine.\n // So we CANNOT split the `operationIDs` into two parts: one for ready items, one for unready items.\n if (hasUnready) {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n void Promise.all(p).then((uiSigns) => {\n __FlushElementTree(list, {\n triggerLayout: true,\n operationIDs,\n elementIDs: uiSigns,\n listID,\n });\n });\n }\n __FlushElementTree(list, {\n triggerLayout: true,\n operationIDs,\n elementIDs: cellIndexes.map((_, index) => typeof p[index] === 'number' ? p[index] : -1),\n listID,\n });\n }\n return [componentAtIndex, componentAtIndexes] as const;\n}\n\nexport function enqueueComponentFactory(): EnqueueComponentCallback {\n // eslint-disable-next-line unicorn/consistent-function-scoping\n const enqueueComponent = (_: FiberElement, listID: number, sign: number) => {\n const signMap = gSignMap[listID];\n const recycleMap = gRecycleMap[listID];\n if (!signMap || !recycleMap) {\n throw new Error('enqueueComponent called on removed list');\n }\n\n const childCtx = signMap.get(sign)!;\n if (!childCtx) {\n return;\n }\n\n const platformInfo = childCtx.__listItemPlatformInfo ?? {};\n\n const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');\n if (!recycleMap.has(uniqID)) {\n recycleMap.set(uniqID, new Map());\n }\n recycleMap.get(uniqID)!.set(sign, childCtx);\n };\n return enqueueComponent;\n}\n"]}