@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
@@ -5,7 +5,7 @@ import { applyUpdatePageData } from '../../core/lynx-page-data.js';
5
5
  import { markTiming, setPipeline } from '../../core/performance.js';
6
6
  import { __root, setRoot } from '../../root.js';
7
7
  import { LifecycleConstant } from '../lifecycle/constant.js';
8
- import { firstScreenEventIdSwap, isFirstScreenSynced, onFirstScreenSyncReady, onFirstScreenTreeReady, resetFirstScreenSyncState, resetFirstScreenTreeReady, syncFirstScreen, } from '../lifecycle/event/firstScreenSync.js';
8
+ import { firstScreenSync, onFirstScreenSyncReady, onFirstScreenTreeReady, resetFirstScreenSyncState, resetFirstScreenTreeReady, syncFirstScreen, } from '../lifecycle/event/firstScreenSync.js';
9
9
  import { reloadMainThread } from '../lifecycle/reload.js';
10
10
  import { renderMainThread } from '../lifecycle/render.js';
11
11
  import { __pendingListUpdates } from '../list/pendingListUpdates.js';
@@ -99,7 +99,7 @@ function updatePage(data, options) {
99
99
  }
100
100
  applyUpdatePageData(data, options);
101
101
  const flushOptions = options ?? {};
102
- if (!isFirstScreenSynced) {
102
+ if (!firstScreenSync.isSynced) {
103
103
  if (__FIRST_SCREEN_SYNC_TIMING__ === 'manual') {
104
104
  // a `markFirstScreenSyncReady` call during the re-render below must not
105
105
  // sync the half-rendered tree; it is deferred to `onFirstScreenTreeReady`
@@ -115,7 +115,7 @@ function updatePage(data, options) {
115
115
  renderMainThread();
116
116
  // As said by codename `firstScreenEventIdSwap`, this swap will only be used for event remap,
117
117
  // because ref & unref cause by previous render will be ignored
118
- hydrate(oldRoot, __root, { skipUnRef: true, swap: firstScreenEventIdSwap });
118
+ hydrate(oldRoot, __root, { skipUnRef: true, swap: firstScreenSync.eventIdSwap });
119
119
  // always call this before `__FlushElementTree`
120
120
  __pendingListUpdates.flush();
121
121
  applyRefQueue();
@@ -1 +1 @@
1
- {"version":3,"file":"calledByNative.js","sourceRoot":"","sources":["../../../src/snapshot/lynx/calledByNative.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,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AgB,CAAC,MAAM,CAAC,CAAC,CAAC;QACtC,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE7B,WAAW,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QACtC,UAAU,CAAC,qBAAqB,CAAC,CAAC;QAClC,CAAC;YACC,oBAAoB,CAAC,kBAAkB,EAAE,CAAC;YAC1C,gBAAgB,EAAE,CAAC;YACnB,6FAA6F;YAC7F,+DAA+D;YAC/D,OAAO,CACL,OAA2B,EAC3B,MAA0B,EAC1B,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAClD,CAAC;YAEF,+CAA+C;YAC/C,oBAAoB,CAAC,KAAK,EAAE,CAAC;YAC7B,aAAa,EAAE,CAAC;QAClB,CAAC;QAED,IAAI,4BAA4B,KAAK,QAAQ,EAAE,CAAC;YAC9C,sBAAsB,EAAE,CAAC;QAC3B,CAAC;QAED,YAAY,CAAC,kBAAkB,GAAG,IAAI,CAAC;QACvC,UAAU,CAAC,mBAAmB,CAAC,CAAC;QAEhC,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE,CAAC;YACrC,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED,kBAAkB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAU,EAAE,OAA0B;IAC/D,IAAI,OAAO,EAAE,CAAC;QACZ,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,kBAAkB,EAAE,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,OAAO,EAAE,oBAAoB,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 { applyUpdatePageData } from '../../core/lynx-page-data.js';\nimport { markTiming, setPipeline } from '../../core/performance.js';\nimport { __root, setRoot } from '../../root.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport {\n firstScreenEventIdSwap,\n isFirstScreenSynced,\n onFirstScreenSyncReady,\n onFirstScreenTreeReady,\n resetFirstScreenSyncState,\n resetFirstScreenTreeReady,\n syncFirstScreen,\n} from '../lifecycle/event/firstScreenSync.js';\nimport { reloadMainThread } from '../lifecycle/reload.js';\nimport { renderMainThread } from '../lifecycle/render.js';\nimport { __pendingListUpdates } from '../list/pendingListUpdates.js';\nimport { hydrate } from '../renderToOpcodes/hydrate.js';\nimport { ssrHydrateByOpcodes } from '../renderToOpcodes/opcodes.js';\nimport { __page, setupPage } from '../snapshot/definition.js';\nimport { SnapshotInstance } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\n\nfunction ssrEncode() {\n const { __opcodes } = __root;\n delete __root.__opcodes;\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldToJSON = SnapshotInstance.prototype.toJSON;\n SnapshotInstance.prototype.toJSON = function(this: SnapshotInstance): any {\n return [\n this.type,\n this.__id,\n this.__elements,\n ];\n };\n\n try {\n const replacer = (_key: string, value: unknown): unknown => {\n if (value && typeof value === 'object' && '_wkltId' in (value as Record<string, unknown>)) {\n return null;\n }\n return value;\n };\n return JSON.stringify({ __opcodes, __root_values: __root.__values }, replacer);\n } finally {\n SnapshotInstance.prototype.toJSON = oldToJSON;\n }\n}\n\nfunction ssrHydrate(info: string) {\n const nativePage = __GetPageElement();\n if (!nativePage) {\n throw new Error('SSR Hydration Failed! Please check if the SSR content loaded successfully!');\n }\n\n resetFirstScreenSyncState();\n setupPage(nativePage);\n const refsMap = __GetTemplateParts(nativePage);\n\n const { __opcodes, __root_values } = JSON.parse(info) as {\n __opcodes: unknown[];\n __root_values: unknown[] | undefined;\n };\n if (__root_values) {\n __root.setAttribute('values', __root_values);\n }\n ssrHydrateByOpcodes(__opcodes, __root as SnapshotInstance, refsMap);\n\n (__root as SnapshotInstance).__elements = [nativePage];\n (__root as SnapshotInstance).__element_root = nativePage;\n}\n\nfunction injectCalledByNative(): void {\n if (process.env['NODE_ENV'] !== 'test' && __FIRST_SCREEN_SYNC_TIMING__ !== 'jsReady' && __ENABLE_SSR__) {\n throw new Error('`firstScreenSyncTiming` must be `jsReady` when SSR is enabled');\n }\n\n const calledByNative: LynxCallByNative = {\n renderPage,\n updatePage,\n updateGlobalProps,\n getPageData: function() {\n return null;\n },\n removeComponents: function(): void {},\n ...(__ENABLE_SSR__ ? { ssrEncode, ssrHydrate } : {}),\n };\n\n Object.assign(globalThis, calledByNative);\n Object.assign(globalThis, {\n [LifecycleConstant.firstScreenSyncReady]: onFirstScreenSyncReady,\n });\n}\n\nfunction renderPage(data: Record<string, unknown> | undefined): void {\n lynx.__initData = data ?? {};\n\n setupPage(__CreatePage('0', 0));\n (__root as SnapshotInstance).ensureElements();\n\n renderMainThread();\n\n // always call this before `__FlushElementTree`\n // (There is an implicit `__FlushElementTree` in `renderPage`)\n __pendingListUpdates.flush();\n applyRefQueue();\n\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'immediately') {\n syncFirstScreen();\n } else {\n // `jsReady` / `manual`: the tree is ready, but the sync waits for the\n // `rLynxFirstScreenSyncReady` signal.\n onFirstScreenTreeReady();\n }\n}\n\nfunction updatePage(data: Record<string, unknown> | undefined, options?: UpdatePageOption): void {\n if (options?.reloadTemplate) {\n reloadMainThread(data, options);\n return;\n }\n\n applyUpdatePageData(data, options);\n\n const flushOptions = options ?? {};\n if (!isFirstScreenSynced) {\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'manual') {\n // a `markFirstScreenSyncReady` call during the re-render below must not\n // sync the half-rendered tree; it is deferred to `onFirstScreenTreeReady`\n resetFirstScreenTreeReady();\n }\n\n const oldRoot = __root;\n setRoot(new SnapshotInstance('root'));\n __root.__jsx = oldRoot.__jsx;\n\n setPipeline(options?.pipelineOptions);\n markTiming('updateDiffVdomStart');\n {\n __pendingListUpdates.clearAttachedLists();\n renderMainThread();\n // As said by codename `firstScreenEventIdSwap`, this swap will only be used for event remap,\n // because ref & unref cause by previous render will be ignored\n hydrate(\n oldRoot as SnapshotInstance,\n __root as SnapshotInstance,\n { skipUnRef: true, swap: firstScreenEventIdSwap },\n );\n\n // always call this before `__FlushElementTree`\n __pendingListUpdates.flush();\n applyRefQueue();\n }\n\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'manual') {\n onFirstScreenTreeReady();\n }\n\n flushOptions.triggerDataUpdated = true;\n markTiming('updateDiffVdomEnd');\n\n if (typeof lepusng_gc === 'function') {\n lepusng_gc();\n }\n }\n\n __FlushElementTree(__page, flushOptions);\n}\n\nfunction updateGlobalProps(_data: any, options?: UpdatePageOption): void {\n if (options) {\n __FlushElementTree(__page, options);\n } else {\n __FlushElementTree();\n }\n}\n\n/**\n * @internal\n */\nexport { injectCalledByNative };\n"]}
1
+ {"version":3,"file":"calledByNative.js","sourceRoot":"","sources":["../../../src/snapshot/lynx/calledByNative.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EACzB,yBAAyB,EACzB,eAAe,GAChB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAA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AAE,CACvD,CAAC;YAEF,+CAA+C;YAC/C,oBAAoB,CAAC,KAAK,EAAE,CAAC;YAC7B,aAAa,EAAE,CAAC;QAClB,CAAC;QAED,IAAI,4BAA4B,KAAK,QAAQ,EAAE,CAAC;YAC9C,sBAAsB,EAAE,CAAC;QAC3B,CAAC;QAED,YAAY,CAAC,kBAAkB,GAAG,IAAI,CAAC;QACvC,UAAU,CAAC,mBAAmB,CAAC,CAAC;QAEhC,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE,CAAC;YACrC,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED,kBAAkB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAU,EAAE,OAA0B;IAC/D,IAAI,OAAO,EAAE,CAAC;QACZ,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,kBAAkB,EAAE,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,OAAO,EAAE,oBAAoB,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 { applyUpdatePageData } from '../../core/lynx-page-data.js';\nimport { markTiming, setPipeline } from '../../core/performance.js';\nimport { __root, setRoot } from '../../root.js';\nimport { LifecycleConstant } from '../lifecycle/constant.js';\nimport {\n firstScreenSync,\n onFirstScreenSyncReady,\n onFirstScreenTreeReady,\n resetFirstScreenSyncState,\n resetFirstScreenTreeReady,\n syncFirstScreen,\n} from '../lifecycle/event/firstScreenSync.js';\nimport { reloadMainThread } from '../lifecycle/reload.js';\nimport { renderMainThread } from '../lifecycle/render.js';\nimport { __pendingListUpdates } from '../list/pendingListUpdates.js';\nimport { hydrate } from '../renderToOpcodes/hydrate.js';\nimport { ssrHydrateByOpcodes } from '../renderToOpcodes/opcodes.js';\nimport { __page, setupPage } from '../snapshot/definition.js';\nimport { SnapshotInstance } from '../snapshot/snapshot.js';\nimport { applyRefQueue } from '../snapshot/workletRef.js';\n\nfunction ssrEncode() {\n const { __opcodes } = __root;\n delete __root.__opcodes;\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldToJSON = SnapshotInstance.prototype.toJSON;\n SnapshotInstance.prototype.toJSON = function(this: SnapshotInstance): any {\n return [\n this.type,\n this.__id,\n this.__elements,\n ];\n };\n\n try {\n const replacer = (_key: string, value: unknown): unknown => {\n if (value && typeof value === 'object' && '_wkltId' in (value as Record<string, unknown>)) {\n return null;\n }\n return value;\n };\n return JSON.stringify({ __opcodes, __root_values: __root.__values }, replacer);\n } finally {\n SnapshotInstance.prototype.toJSON = oldToJSON;\n }\n}\n\nfunction ssrHydrate(info: string) {\n const nativePage = __GetPageElement();\n if (!nativePage) {\n throw new Error('SSR Hydration Failed! Please check if the SSR content loaded successfully!');\n }\n\n resetFirstScreenSyncState();\n setupPage(nativePage);\n const refsMap = __GetTemplateParts(nativePage);\n\n const { __opcodes, __root_values } = JSON.parse(info) as {\n __opcodes: unknown[];\n __root_values: unknown[] | undefined;\n };\n if (__root_values) {\n __root.setAttribute('values', __root_values);\n }\n ssrHydrateByOpcodes(__opcodes, __root as SnapshotInstance, refsMap);\n\n (__root as SnapshotInstance).__elements = [nativePage];\n (__root as SnapshotInstance).__element_root = nativePage;\n}\n\nfunction injectCalledByNative(): void {\n if (process.env['NODE_ENV'] !== 'test' && __FIRST_SCREEN_SYNC_TIMING__ !== 'jsReady' && __ENABLE_SSR__) {\n throw new Error('`firstScreenSyncTiming` must be `jsReady` when SSR is enabled');\n }\n\n const calledByNative: LynxCallByNative = {\n renderPage,\n updatePage,\n updateGlobalProps,\n getPageData: function() {\n return null;\n },\n removeComponents: function(): void {},\n ...(__ENABLE_SSR__ ? { ssrEncode, ssrHydrate } : {}),\n };\n\n Object.assign(globalThis, calledByNative);\n Object.assign(globalThis, {\n [LifecycleConstant.firstScreenSyncReady]: onFirstScreenSyncReady,\n });\n}\n\nfunction renderPage(data: Record<string, unknown> | undefined): void {\n lynx.__initData = data ?? {};\n\n setupPage(__CreatePage('0', 0));\n (__root as SnapshotInstance).ensureElements();\n\n renderMainThread();\n\n // always call this before `__FlushElementTree`\n // (There is an implicit `__FlushElementTree` in `renderPage`)\n __pendingListUpdates.flush();\n applyRefQueue();\n\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'immediately') {\n syncFirstScreen();\n } else {\n // `jsReady` / `manual`: the tree is ready, but the sync waits for the\n // `rLynxFirstScreenSyncReady` signal.\n onFirstScreenTreeReady();\n }\n}\n\nfunction updatePage(data: Record<string, unknown> | undefined, options?: UpdatePageOption): void {\n if (options?.reloadTemplate) {\n reloadMainThread(data, options);\n return;\n }\n\n applyUpdatePageData(data, options);\n\n const flushOptions = options ?? {};\n if (!firstScreenSync.isSynced) {\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'manual') {\n // a `markFirstScreenSyncReady` call during the re-render below must not\n // sync the half-rendered tree; it is deferred to `onFirstScreenTreeReady`\n resetFirstScreenTreeReady();\n }\n\n const oldRoot = __root;\n setRoot(new SnapshotInstance('root'));\n __root.__jsx = oldRoot.__jsx;\n\n setPipeline(options?.pipelineOptions);\n markTiming('updateDiffVdomStart');\n {\n __pendingListUpdates.clearAttachedLists();\n renderMainThread();\n // As said by codename `firstScreenEventIdSwap`, this swap will only be used for event remap,\n // because ref & unref cause by previous render will be ignored\n hydrate(\n oldRoot as SnapshotInstance,\n __root as SnapshotInstance,\n { skipUnRef: true, swap: firstScreenSync.eventIdSwap },\n );\n\n // always call this before `__FlushElementTree`\n __pendingListUpdates.flush();\n applyRefQueue();\n }\n\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'manual') {\n onFirstScreenTreeReady();\n }\n\n flushOptions.triggerDataUpdated = true;\n markTiming('updateDiffVdomEnd');\n\n if (typeof lepusng_gc === 'function') {\n lepusng_gc();\n }\n }\n\n __FlushElementTree(__page, flushOptions);\n}\n\nfunction updateGlobalProps(_data: any, options?: UpdatePageOption): void {\n if (options) {\n __FlushElementTree(__page, options);\n } else {\n __FlushElementTree();\n }\n}\n\n/**\n * @internal\n */\nexport { injectCalledByNative };\n"]}
@@ -1,9 +1,10 @@
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 { componentAtIndexFactory, enqueueComponentFactory, gRecycleMap, gSignMap } from '../list/list.js';
5
6
  import { hydrate } from '../renderToOpcodes/hydrate.js';
6
- const destroyLifetimeHandlerMap = /*#__PURE__*/ new Map();
7
+ const destroyLifetimeHandlerMap = /*#__PURE__*/ cardLifetime('listDestroyLifetimeHandlerMap', () => new Map());
7
8
  export function snapshotCreateList(pageId, _ctx, _expIndex) {
8
9
  const signMap = new Map();
9
10
  const recycleMap = new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/snapshot/snapshot/list.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC1G,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAGxD,MAAM,yBAAyB,GAAG,aAAa,CAAC,IAAI,GAAG,EAAsB,CAAC;AAE9E,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,IAAsB,EACtB,SAAiB;IAEjB,MAAM,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IACpD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAyC,CAAC;IACpE,MAAM,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,GAAG,uBAAuB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACpF,MAAM,IAAI,GAAG,YAAY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,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;QACxE,MAAM,EAAE,GAAG,yBAAyB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjD,IAAI,EAAE,EAAE,CAAC;YACP,IAAI,CAAC,SAAS,EAAE,EAAE,mBAAmB,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;YAC/D,yBAAyB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAC7B,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 { componentAtIndexFactory, enqueueComponentFactory, gRecycleMap, gSignMap } from '../list/list.js';\nimport { hydrate } from '../renderToOpcodes/hydrate.js';\nimport type { SnapshotInstance } from '../snapshot/snapshot.js';\n\nconst destroyLifetimeHandlerMap = /*#__PURE__*/ new Map<number, () => void>();\n\nexport function snapshotCreateList(\n pageId: number,\n _ctx: SnapshotInstance,\n _expIndex: number,\n): FiberElement {\n const signMap = new Map<number, SnapshotInstance>();\n const recycleMap = new Map<string, Map<number, SnapshotInstance>>();\n const [componentAtIndex, componentAtIndexes] = componentAtIndexFactory([], hydrate);\n const list = __CreateList(\n pageId,\n componentAtIndex,\n enqueueComponentFactory(),\n {},\n componentAtIndexes,\n );\n const listID = __GetElementUniqueID(list);\n\n if (typeof lynx !== 'undefined' && typeof lynx.getNative === 'function') {\n const cb = () => {\n __UpdateListCallbacks(list, null, null, null);\n destroyLifetimeHandlerMap.delete(listID);\n };\n lynx.getNative()?.addEventListener('__DestroyLifetime', cb);\n destroyLifetimeHandlerMap.set(listID, cb);\n }\n\n gSignMap[listID] = signMap;\n gRecycleMap[listID] = recycleMap;\n return list;\n}\n\nexport function snapshotDestroyList(si: SnapshotInstance): void {\n const [, elementIndex] = si.__snapshot_def.slot[0]!;\n const list = si.__elements?.[elementIndex];\n // `takeElements` and hydration transfer the rendered elements to a new\n // SnapshotInstance while leaving the old instance tree available for\n // teardown. Only the instance that still owns the list element may clean up\n // its callbacks and recycling state.\n if (list === undefined) {\n return;\n }\n const listID = __GetElementUniqueID(list);\n\n __UpdateListCallbacks(list, () => -1, () => {}, () => {});\n\n if (typeof lynx !== 'undefined' && typeof lynx.getNative === 'function') {\n const cb = destroyLifetimeHandlerMap.get(listID);\n if (cb) {\n lynx.getNative()?.removeEventListener('__DestroyLifetime', cb);\n destroyLifetimeHandlerMap.delete(listID);\n }\n }\n\n delete gSignMap[listID];\n delete gRecycleMap[listID];\n}\n"]}
1
+ {"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/snapshot/snapshot/list.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC1G,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAGxD,MAAM,yBAAyB,GAAG,aAAa,CAAC,YAAY,CAC1D,+BAA+B,EAC/B,GAAG,EAAE,CAAC,IAAI,GAAG,EAAsB,CACpC,CAAC;AAEF,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,IAAsB,EACtB,SAAiB;IAEjB,MAAM,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IACpD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAyC,CAAC;IACpE,MAAM,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,GAAG,uBAAuB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACpF,MAAM,IAAI,GAAG,YAAY,CACvB,MAAM,EACN,g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KAAK,WAAW,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;QACxE,MAAM,EAAE,GAAG,yBAAyB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjD,IAAI,EAAE,EAAE,CAAC;YACP,IAAI,CAAC,SAAS,EAAE,EAAE,mBAAmB,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;YAC/D,yBAAyB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAC7B,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 { cardLifetime } from '../../core/card-lifetime.js';\nimport { componentAtIndexFactory, enqueueComponentFactory, gRecycleMap, gSignMap } from '../list/list.js';\nimport { hydrate } from '../renderToOpcodes/hydrate.js';\nimport type { SnapshotInstance } from '../snapshot/snapshot.js';\n\nconst destroyLifetimeHandlerMap = /*#__PURE__*/ cardLifetime(\n 'listDestroyLifetimeHandlerMap',\n () => new Map<number, () => void>(),\n);\n\nexport function snapshotCreateList(\n pageId: number,\n _ctx: SnapshotInstance,\n _expIndex: number,\n): FiberElement {\n const signMap = new Map<number, SnapshotInstance>();\n const recycleMap = new Map<string, Map<number, SnapshotInstance>>();\n const [componentAtIndex, componentAtIndexes] = componentAtIndexFactory([], hydrate);\n const list = __CreateList(\n pageId,\n componentAtIndex,\n enqueueComponentFactory(),\n {},\n componentAtIndexes,\n );\n const listID = __GetElementUniqueID(list);\n\n if (typeof lynx !== 'undefined' && typeof lynx.getNative === 'function') {\n const cb = () => {\n __UpdateListCallbacks(list, null, null, null);\n destroyLifetimeHandlerMap.delete(listID);\n };\n lynx.getNative()?.addEventListener('__DestroyLifetime', cb);\n destroyLifetimeHandlerMap.set(listID, cb);\n }\n\n gSignMap[listID] = signMap;\n gRecycleMap[listID] = recycleMap;\n return list;\n}\n\nexport function snapshotDestroyList(si: SnapshotInstance): void {\n const [, elementIndex] = si.__snapshot_def.slot[0]!;\n const list = si.__elements?.[elementIndex];\n // `takeElements` and hydration transfer the rendered elements to a new\n // SnapshotInstance while leaving the old instance tree available for\n // teardown. Only the instance that still owns the list element may clean up\n // its callbacks and recycling state.\n if (list === undefined) {\n return;\n }\n const listID = __GetElementUniqueID(list);\n\n __UpdateListCallbacks(list, () => -1, () => {}, () => {});\n\n if (typeof lynx !== 'undefined' && typeof lynx.getNative === 'function') {\n const cb = destroyLifetimeHandlerMap.get(listID);\n if (cb) {\n lynx.getNative()?.removeEventListener('__DestroyLifetime', cb);\n destroyLifetimeHandlerMap.delete(listID);\n }\n }\n\n delete gSignMap[listID];\n delete gRecycleMap[listID];\n}\n"]}
@@ -1,6 +1,8 @@
1
1
  import type { SnapshotInstance } from './snapshot.js';
2
- export declare const snapshotInstanceManager: {
2
+ interface SnapshotInstanceManager {
3
3
  nextId: number;
4
4
  values: Map<number, SnapshotInstance>;
5
5
  clear(): void;
6
- };
6
+ }
7
+ export declare const snapshotInstanceManager: SnapshotInstanceManager;
8
+ export {};
@@ -1,16 +1,16 @@
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 { clearSnapshotVNodeSource } from '../debug/vnodeSource.js';
5
- export const snapshotInstanceManager = {
6
- nextId: 0,
7
- values: /* @__PURE__ */ new Map(),
8
- clear() {
9
- // not resetting `nextId` to prevent id collision
10
- this.values.clear();
11
- if (__DEV__) {
12
- clearSnapshotVNodeSource();
13
- }
14
- },
15
- };
6
+ function clear() {
7
+ // not resetting `nextId` to prevent id collision
8
+ this.values.clear();
9
+ if (__DEV__) {
10
+ clearSnapshotVNodeSource();
11
+ }
12
+ }
13
+ export const snapshotInstanceManager = /*#__PURE__*/ cardLifetime('snapshotInstanceManager', () => ({ nextId: 0, values: new Map(), clear }));
14
+ // Rebound so that it clears the debug state of the current entry.
15
+ snapshotInstanceManager.clear = clear;
16
16
  //# sourceMappingURL=snapshotInstanceManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotInstanceManager.js","sourceRoot":"","sources":["../../../src/snapshot/snapshot/snapshotInstanceManager.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,CAAC,MAAM,uBAAuB,GAIhC;IACF,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,eAAe,CAAC,IAAI,GAAG,EAA4B;IAC3D,KAAK;QACH,iDAAiD;QACjD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,OAAO,EAAE,CAAC;YACZ,wBAAwB,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { SnapshotInstance } from './snapshot.js';\nimport { clearSnapshotVNodeSource } from '../debug/vnodeSource.js';\n\nexport const snapshotInstanceManager: {\n nextId: number;\n values: Map<number, SnapshotInstance>;\n clear(): void;\n} = {\n nextId: 0,\n values: /* @__PURE__ */ new Map<number, SnapshotInstance>(),\n clear() {\n // not resetting `nextId` to prevent id collision\n this.values.clear();\n if (__DEV__) {\n clearSnapshotVNodeSource();\n }\n },\n};\n"]}
1
+ {"version":3,"file":"snapshotInstanceManager.js","sourceRoot":"","sources":["../../../src/snapshot/snapshot/snapshotInstanceManager.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAQnE,SAAS,KAAK;IACZ,iDAAiD;IACjD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACpB,IAAI,OAAO,EAAE,CAAC;QACZ,wBAAwB,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,uBAAuB,GAA4B,aAAa,CAAC,YAAY,CACxF,yBAAyB,EACzB,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,GAAG,EAA4B,EAAE,KAAK,EAAE,CAAC,CAC1E,CAAC;AAEF,kEAAkE;AAClE,uBAAuB,CAAC,KAAK,GAAG,KAAK,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { SnapshotInstance } from './snapshot.js';\nimport { cardLifetime } from '../../core/card-lifetime.js';\nimport { clearSnapshotVNodeSource } from '../debug/vnodeSource.js';\n\ninterface SnapshotInstanceManager {\n nextId: number;\n values: Map<number, SnapshotInstance>;\n clear(): void;\n}\n\nfunction clear(this: SnapshotInstanceManager): void {\n // not resetting `nextId` to prevent id collision\n this.values.clear();\n if (__DEV__) {\n clearSnapshotVNodeSource();\n }\n}\n\nexport const snapshotInstanceManager: SnapshotInstanceManager = /*#__PURE__*/ cardLifetime(\n 'snapshotInstanceManager',\n () => ({ nextId: 0, values: new Map<number, SnapshotInstance>(), clear }),\n);\n\n// Rebound so that it clears the debug state of the current entry.\nsnapshotInstanceManager.clear = clear;\n"]}
@@ -19,3 +19,4 @@
19
19
  * @group Functions
20
20
  */
21
21
  export declare function runOnMainThread<R, Fn extends (...args: any[]) => R>(fn: Fn): (...args: Parameters<Fn>) => Promise<R>;
22
+ export declare function resetSnapshotMainThreadFunctionRuntime(): void;
@@ -1,7 +1,8 @@
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 { createRunOnMainThread } from '../../../core/thread-function-call/main-thread.js';
4
+ import { createRunOnMainThread, takeDelayedRunOnMainThreadData, } from '../../../core/thread-function-call/main-thread.js';
5
+ import { resetFunctionCallReturnListener } from '../../../core/thread-function-call/return-value.js';
5
6
  import { isRendering } from '../../lifecycle/isRendering.js';
6
7
  import { __globalSnapshotPatch } from '../../lifecycle/patch/snapshotPatch.js';
7
8
  const runOnMainThreadImpl = createRunOnMainThread({
@@ -32,4 +33,8 @@ const runOnMainThreadImpl = createRunOnMainThread({
32
33
  export function runOnMainThread(fn) {
33
34
  return runOnMainThreadImpl(fn);
34
35
  }
36
+ export function resetSnapshotMainThreadFunctionRuntime() {
37
+ takeDelayedRunOnMainThreadData();
38
+ resetFunctionCallReturnListener();
39
+ }
35
40
  //# sourceMappingURL=runOnMainThread.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runOnMainThread.js","sourceRoot":"","sources":["../../../../src/snapshot/worklet/call/runOnMainThread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;IAChD,qCAAqC;QACnC,OAAO,qBAAqB,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;IACnE,CAAC;CACF,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,eAAe,CAC7B,EAAM;IAEN,OAAO,mBAAmB,CAAC,EAAE,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { createRunOnMainThread } from '../../../core/thread-function-call/main-thread.js';\nimport { isRendering } from '../../lifecycle/isRendering.js';\nimport { __globalSnapshotPatch } from '../../lifecycle/patch/snapshotPatch.js';\n\nconst runOnMainThreadImpl = createRunOnMainThread({\n shouldDispatchRunOnMainThreadDirectly() {\n return __globalSnapshotPatch !== undefined && !isRendering.value;\n },\n});\n\n/**\n * `runOnMainThread` allows triggering main thread functions on the main thread asynchronously.\n * @param fn - The main thread functions to be called.\n * @returns A function. Calling which with the arguments to be passed to the main thread function to trigger it on the main thread. This function returns a promise that resolves to the return value of the main thread function.\n * @example\n * ```ts\n * import { runOnMainThread } from '@lynx-js/react';\n *\n * async function someFunction() {\n * const fn = runOnMainThread(() => {\n * 'main thread';\n * return 'hello';\n * });\n * const result = await fn();\n * }\n * ```\n * @public\n *\n * @group Functions\n */\nexport function runOnMainThread<R, Fn extends (...args: any[]) => R>(\n fn: Fn,\n): (...args: Parameters<Fn>) => Promise<R> {\n return runOnMainThreadImpl(fn);\n}\n"]}
1
+ {"version":3,"file":"runOnMainThread.js","sourceRoot":"","sources":["../../../../src/snapshot/worklet/call/runOnMainThread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EACL,qBAAqB,EACrB,8BAA8B,GAC/B,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;IAChD,qCAAqC;QACnC,OAAO,qBAAqB,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;IACnE,CAAC;CACF,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,eAAe,CAC7B,EAAM;IAEN,OAAO,mBAAmB,CAAC,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,sCAAsC;IACpD,8BAA8B,EAAE,CAAC;IACjC,+BAA+B,EAAE,CAAC;AACpC,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport {\n createRunOnMainThread,\n takeDelayedRunOnMainThreadData,\n} from '../../../core/thread-function-call/main-thread.js';\nimport { resetFunctionCallReturnListener } from '../../../core/thread-function-call/return-value.js';\nimport { isRendering } from '../../lifecycle/isRendering.js';\nimport { __globalSnapshotPatch } from '../../lifecycle/patch/snapshotPatch.js';\n\nconst runOnMainThreadImpl = createRunOnMainThread({\n shouldDispatchRunOnMainThreadDirectly() {\n return __globalSnapshotPatch !== undefined && !isRendering.value;\n },\n});\n\n/**\n * `runOnMainThread` allows triggering main thread functions on the main thread asynchronously.\n * @param fn - The main thread functions to be called.\n * @returns A function. Calling which with the arguments to be passed to the main thread function to trigger it on the main thread. This function returns a promise that resolves to the return value of the main thread function.\n * @example\n * ```ts\n * import { runOnMainThread } from '@lynx-js/react';\n *\n * async function someFunction() {\n * const fn = runOnMainThread(() => {\n * 'main thread';\n * return 'hello';\n * });\n * const result = await fn();\n * }\n * ```\n * @public\n *\n * @group Functions\n */\nexport function runOnMainThread<R, Fn extends (...args: any[]) => R>(\n fn: Fn,\n): (...args: Parameters<Fn>) => Promise<R> {\n return runOnMainThreadImpl(fn);\n}\n\nexport function resetSnapshotMainThreadFunctionRuntime(): void {\n takeDelayedRunOnMainThreadData();\n resetFunctionCallReturnListener();\n}\n"]}
@@ -1 +1 @@
1
- export {};
1
+ export declare function resetSnapshotBackgroundFunctionRuntime(): void;
@@ -1,5 +1,6 @@
1
1
  import { isMtsEnabled, isRunOnBackgroundEnabled } from './functionality.js';
2
- import { registerBackgroundFunctionCtx } from '../../core/background-function/run-on-background.js';
2
+ import { registerBackgroundFunctionCtx, resetBackgroundFunctionRuntime, } from '../../core/background-function/run-on-background.js';
3
+ import { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';
3
4
  /**
4
5
  * @internal
5
6
  */
@@ -14,4 +15,8 @@ export function onPostWorkletCtx(afterValue) {
14
15
  registerBackgroundFunctionCtx(afterValue);
15
16
  return afterValue;
16
17
  }
18
+ export function resetSnapshotBackgroundFunctionRuntime() {
19
+ resetBackgroundFunctionRuntime();
20
+ resetFunctionCallReturnListener();
21
+ }
17
22
  //# sourceMappingURL=ctx.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ctx.js","sourceRoot":"","sources":["../../../src/snapshot/worklet/ctx.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,6BAA6B,EAAE,MAAM,qDAAqD,CAAC;AAEpG;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAA0B;IACzD,IAAI,CAAC,YAAY,EAAE,IAAI,UAAU,EAAE,CAAC;QAClC,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC,CAAC;QACjF,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,UAAU,IAAI,CAAC,wBAAwB,EAAE,EAAE,CAAC;QAC/C,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,6BAA6B,CAAC,UAAU,CAAC,CAAC;IAC1C,OAAO,UAAU,CAAC;AACpB,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 type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { isMtsEnabled, isRunOnBackgroundEnabled } from './functionality.js';\nimport { registerBackgroundFunctionCtx } from '../../core/background-function/run-on-background.js';\n\n/**\n * @internal\n */\nexport function onPostWorkletCtx(afterValue: Worklet | null): Worklet | null {\n if (!isMtsEnabled() && afterValue) {\n lynx.reportError(new Error('Main thread script requires Lynx sdk version 2.14'));\n return null;\n }\n if (!afterValue || !isRunOnBackgroundEnabled()) {\n return afterValue;\n }\n registerBackgroundFunctionCtx(afterValue);\n return afterValue;\n}\n"]}
1
+ {"version":3,"file":"ctx.js","sourceRoot":"","sources":["../../../src/snapshot/worklet/ctx.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EACL,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,iDAAiD,CAAC;AAElG;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAA0B;IACzD,IAAI,CAAC,YAAY,EAAE,IAAI,UAAU,EAAE,CAAC;QAClC,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC,CAAC;QACjF,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC,UAAU,IAAI,CAAC,wBAAwB,EAAE,EAAE,CAAC;QAC/C,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,6BAA6B,CAAC,UAAU,CAAC,CAAC;IAC1C,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,sCAAsC;IACpD,8BAA8B,EAAE,CAAC;IACjC,+BAA+B,EAAE,CAAC;AACpC,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { isMtsEnabled, isRunOnBackgroundEnabled } from './functionality.js';\nimport {\n registerBackgroundFunctionCtx,\n resetBackgroundFunctionRuntime,\n} from '../../core/background-function/run-on-background.js';\nimport { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';\n\n/**\n * @internal\n */\nexport function onPostWorkletCtx(afterValue: Worklet | null): Worklet | null {\n if (!isMtsEnabled() && afterValue) {\n lynx.reportError(new Error('Main thread script requires Lynx sdk version 2.14'));\n return null;\n }\n if (!afterValue || !isRunOnBackgroundEnabled()) {\n return afterValue;\n }\n registerBackgroundFunctionCtx(afterValue);\n return afterValue;\n}\n\nexport function resetSnapshotBackgroundFunctionRuntime(): void {\n resetBackgroundFunctionRuntime();\n resetFunctionCallReturnListener();\n}\n"]}
@@ -8,6 +8,9 @@ function updateMTRefInitValue({ data }) {
8
8
  // This update ignores reloadVersion check.
9
9
  // MainThreadRefs created before reloadTemplate may still be referenced by user in some cases after reloadTemplate.
10
10
  const patch = JSON.parse(data);
11
+ if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
12
+ console.alog?.('[ReactLynxDebug] Snapshot MTS updateMTRefInitValue:\n' + data);
13
+ }
11
14
  updateWorkletRefInitValueChanges(patch);
12
15
  }
13
16
  export function injectUpdateMTRefInitValue() {
@@ -19,6 +22,9 @@ export function sendMTRefInitValueToMainThread() {
19
22
  return;
20
23
  }
21
24
  const data = JSON.stringify(patch);
25
+ if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
26
+ console.alog?.('[ReactLynxDebug] Snapshot BTS -> MTS sendMTRefInitValue:\n' + data);
27
+ }
22
28
  lynx.getNativeApp().callLepusMethod(LifecycleConstant.updateMTRefInitValue, { data });
23
29
  }
24
30
  //# sourceMappingURL=updateInitValue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateInitValue.js","sourceRoot":"","sources":["../../../../src/snapshot/worklet/ref/updateInitValue.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,gCAAgC,EAAE,MAAM,yCAAyC,CAAC;AAG3F,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,SAAS,oBAAoB,CAAC,EAAE,IAAI,EAAoB;IACtD,2CAA2C;IAC3C,mHAAmH;IACnH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAgC,CAAC;IAC9D,gCAAgC,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC;AAChG,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,MAAM,KAAK,GAAG,+BAA+B,EAAE,CAAC;IAChD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,CAAC,YAAY,EAAE,CAAC,eAAe,CAAC,iBAAiB,CAAC,oBAAoB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACxF,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 { updateWorkletRefInitValueChanges } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { MainThreadRefInitValuePatch } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { takeMainThreadRefInitValuePatch } from '../../../core/main-thread-ref-init-value.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\n\nfunction updateMTRefInitValue({ data }: { data: string }): void {\n // This update ignores reloadVersion check.\n // MainThreadRefs created before reloadTemplate may still be referenced by user in some cases after reloadTemplate.\n const patch = JSON.parse(data) as MainThreadRefInitValuePatch;\n updateWorkletRefInitValueChanges(patch);\n}\n\nexport function injectUpdateMTRefInitValue(): void {\n Object.assign(globalThis, { [LifecycleConstant.updateMTRefInitValue]: updateMTRefInitValue });\n}\n\nexport function sendMTRefInitValueToMainThread(): void {\n const patch = takeMainThreadRefInitValuePatch();\n if (patch.length === 0) {\n return;\n }\n\n const data = JSON.stringify(patch);\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.updateMTRefInitValue, { data });\n}\n"]}
1
+ {"version":3,"file":"updateInitValue.js","sourceRoot":"","sources":["../../../../src/snapshot/worklet/ref/updateInitValue.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,gCAAgC,EAAE,MAAM,yCAAyC,CAAC;AAG3F,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,SAAS,oBAAoB,CAAC,EAAE,IAAI,EAAoB;IACtD,2CAA2C;IAC3C,mHAAmH;IACnH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAgC,CAAC;IAC9D,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,QAAQ,EAAE,CAAC;QAChD,OAAO,CAAC,IAAI,EAAE,CAAC,uDAAuD,GAAG,IAAI,CAAC,CAAC;IACjF,CAAC;IACD,gCAAgC,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC;AAChG,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,MAAM,KAAK,GAAG,+BAA+B,EAAE,CAAC;IAChD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,QAAQ,EAAE,CAAC;QAChD,OAAO,CAAC,IAAI,EAAE,CAAC,4DAA4D,GAAG,IAAI,CAAC,CAAC;IACtF,CAAC;IACD,IAAI,CAAC,YAAY,EAAE,CAAC,eAAe,CAAC,iBAAiB,CAAC,oBAAoB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACxF,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 { updateWorkletRefInitValueChanges } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { MainThreadRefInitValuePatch } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { takeMainThreadRefInitValuePatch } from '../../../core/main-thread-ref-init-value.js';\nimport { LifecycleConstant } from '../../lifecycle/constant.js';\n\nfunction updateMTRefInitValue({ data }: { data: string }): void {\n // This update ignores reloadVersion check.\n // MainThreadRefs created before reloadTemplate may still be referenced by user in some cases after reloadTemplate.\n const patch = JSON.parse(data) as MainThreadRefInitValuePatch;\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.('[ReactLynxDebug] Snapshot MTS updateMTRefInitValue:\\n' + data);\n }\n updateWorkletRefInitValueChanges(patch);\n}\n\nexport function injectUpdateMTRefInitValue(): void {\n Object.assign(globalThis, { [LifecycleConstant.updateMTRefInitValue]: updateMTRefInitValue });\n}\n\nexport function sendMTRefInitValueToMainThread(): void {\n const patch = takeMainThreadRefInitValuePatch();\n if (patch.length === 0) {\n return;\n }\n\n const data = JSON.stringify(patch);\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.('[ReactLynxDebug] Snapshot BTS -> MTS sendMTRefInitValue:\\n' + data);\n }\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.updateMTRefInitValue, { data });\n}\n"]}