@lynx-js/react 0.129.4 → 0.129.5

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 (147) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/components/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +9 -1
  4. package/refresh/.turbo/turbo-build.log +1 -1
  5. package/runtime/__test__/core/lynx/env.test.ts +146 -0
  6. package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +47 -4
  7. package/runtime/__test__/element-template/native/index.test.ts +9 -9
  8. package/runtime/__test__/element-template/native/mts-destroy.test.ts +55 -2
  9. package/runtime/__test__/element-template/native/reload.test.ts +15 -5
  10. package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +1 -1
  11. package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +1 -1
  12. package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +33 -0
  13. package/runtime/__test__/element-template/vitest.config.ts +1 -1
  14. package/runtime/__test__/snapshot/debug/profile.test.jsx +147 -26
  15. package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +54 -0
  16. package/runtime/__test__/snapshot/lifecycle/transfer.mts.test.jsx +98 -6
  17. package/runtime/__test__/snapshot/lifecycle/transfer.test.jsx +214 -9
  18. package/runtime/__test__/snapshot/lynx/suspense.test.jsx +48 -0
  19. package/runtime/__test__/snapshot/utils/envManager.ts +2 -0
  20. package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +21 -0
  21. package/runtime/__test__/worklet-runtime/lifecycle.test.js +297 -0
  22. package/runtime/__test__/worklet-runtime/profile.test.js +12 -6
  23. package/runtime/lazy/element-template-internal.js +1 -0
  24. package/runtime/lib/core/compat/componentIs.d.ts +1 -0
  25. package/runtime/lib/core/compat/componentIs.js +20 -0
  26. package/runtime/lib/core/compat/componentIs.js.map +1 -0
  27. package/runtime/lib/core/lynx/env.d.ts +1 -0
  28. package/runtime/lib/{element-template → core}/lynx/env.js +3 -2
  29. package/runtime/lib/core/lynx/env.js.map +1 -0
  30. package/runtime/lib/core/thread-function-call/main-thread.d.ts +1 -0
  31. package/runtime/lib/core/thread-function-call/main-thread.js +4 -1
  32. package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
  33. package/runtime/lib/element-template/background/commit-event.d.ts +6 -0
  34. package/runtime/lib/element-template/background/commit-event.js +36 -0
  35. package/runtime/lib/element-template/background/commit-event.js.map +1 -0
  36. package/runtime/lib/element-template/background/commit-hook.js +3 -23
  37. package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
  38. package/runtime/lib/element-template/background/destroy.js +1 -1
  39. package/runtime/lib/element-template/background/destroy.js.map +1 -1
  40. package/runtime/lib/element-template/background/hydrate.js +1 -2
  41. package/runtime/lib/element-template/background/hydrate.js.map +1 -1
  42. package/runtime/lib/element-template/background/hydration-listener.js +5 -25
  43. package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
  44. package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.js +4 -4
  45. package/runtime/lib/element-template/background/main-thread-function.js.map +1 -0
  46. package/runtime/lib/element-template/index.d.ts +1 -1
  47. package/runtime/lib/element-template/index.js +1 -1
  48. package/runtime/lib/element-template/index.js.map +1 -1
  49. package/runtime/lib/element-template/internal.js +3 -0
  50. package/runtime/lib/element-template/internal.js.map +1 -1
  51. package/runtime/lib/element-template/native/index.js +2 -2
  52. package/runtime/lib/element-template/native/index.js.map +1 -1
  53. package/runtime/lib/element-template/native/mts-destroy.d.ts +2 -1
  54. package/runtime/lib/element-template/native/mts-destroy.js +15 -4
  55. package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
  56. package/runtime/lib/element-template/native/reload-main-thread.js +2 -2
  57. package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
  58. package/runtime/lib/element-template/runtime/patch.js +4 -11
  59. package/runtime/lib/element-template/runtime/patch.js.map +1 -1
  60. package/runtime/lib/element-template/runtime/template/handle.d.ts +1 -1
  61. package/runtime/lib/element-template/runtime/template/handle.js +2 -2
  62. package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
  63. package/runtime/lib/element-template/runtime/template/main-thread-background-function.d.ts +1 -0
  64. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +7 -2
  65. package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
  66. package/runtime/lib/internal.js +4 -10
  67. package/runtime/lib/internal.js.map +1 -1
  68. package/runtime/lib/snapshot/debug/profileHooks.js +27 -62
  69. package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
  70. package/runtime/lib/snapshot/lifecycle/reload.js +2 -2
  71. package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
  72. package/runtime/lib/snapshot/lynx/env.js +2 -32
  73. package/runtime/lib/snapshot/lynx/env.js.map +1 -1
  74. package/runtime/lib/snapshot/transfer.d.ts +6 -0
  75. package/runtime/lib/snapshot/transfer.js +154 -11
  76. package/runtime/lib/snapshot/transfer.js.map +1 -1
  77. package/runtime/lib/tsconfig.tsbuildinfo +1 -1
  78. package/runtime/lib/worklet-runtime/bindings/lifecycle.d.ts +19 -0
  79. package/runtime/lib/worklet-runtime/bindings/lifecycle.js +49 -0
  80. package/runtime/lib/worklet-runtime/bindings/lifecycle.js.map +1 -0
  81. package/runtime/lib/worklet-runtime/delayWorkletEvent.d.ts +1 -1
  82. package/runtime/lib/worklet-runtime/delayWorkletEvent.js +9 -1
  83. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
  84. package/runtime/lib/worklet-runtime/utils/profile.js +1 -3
  85. package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
  86. package/runtime/src/core/compat/componentIs.ts +32 -0
  87. package/runtime/src/{element-template → core}/lynx/env.ts +6 -4
  88. package/runtime/src/core/thread-function-call/main-thread.ts +5 -1
  89. package/runtime/src/element-template/background/commit-event.ts +52 -0
  90. package/runtime/src/element-template/background/commit-hook.ts +4 -31
  91. package/runtime/src/element-template/background/destroy.ts +1 -1
  92. package/runtime/src/element-template/background/hydrate.ts +5 -3
  93. package/runtime/src/element-template/background/hydration-listener.ts +7 -32
  94. package/runtime/src/element-template/{runtime/template → background}/main-thread-function.ts +4 -7
  95. package/runtime/src/element-template/index.ts +1 -1
  96. package/runtime/src/element-template/internal.ts +4 -0
  97. package/runtime/src/element-template/native/index.ts +2 -2
  98. package/runtime/src/element-template/native/mts-destroy.ts +21 -4
  99. package/runtime/src/element-template/native/reload-main-thread.ts +2 -2
  100. package/runtime/src/element-template/runtime/patch.ts +20 -35
  101. package/runtime/src/element-template/runtime/template/handle.ts +2 -0
  102. package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -2
  103. package/runtime/src/internal.ts +4 -13
  104. package/runtime/src/snapshot/debug/profileHooks.ts +30 -91
  105. package/runtime/src/snapshot/lifecycle/reload.ts +2 -3
  106. package/runtime/src/snapshot/lynx/env.ts +3 -43
  107. package/runtime/src/snapshot/transfer.ts +169 -13
  108. package/runtime/src/worklet-runtime/bindings/lifecycle.ts +51 -0
  109. package/runtime/src/worklet-runtime/delayWorkletEvent.ts +10 -2
  110. package/runtime/src/worklet-runtime/utils/profile.ts +1 -3
  111. package/runtime/types/internal-preact.d.ts +2 -0
  112. package/runtime/vitest.config.ts +0 -1
  113. package/testing-library/.turbo/turbo-build.log +7 -7
  114. package/testing-library/src/__tests__/events.test.jsx +1 -1
  115. package/testing-library/src/fire-event.ts +1 -1
  116. package/transform/.turbo/turbo-build$colon$wasm.log +67 -66
  117. package/transform/__test__/fixture.spec.js +1 -1
  118. package/transform/cjs/browser.cjs +11 -0
  119. package/transform/crates/swc_plugin_compat/lib.rs +20 -2
  120. package/transform/crates/swc_plugin_compat/napi.rs +7 -0
  121. package/transform/crates/swc_plugin_dynamic_import/lib.rs +15 -4
  122. package/transform/crates/swc_plugin_element_template/attr_name.rs +0 -3
  123. package/transform/crates/swc_plugin_element_template/extractor.rs +0 -8
  124. package/transform/crates/swc_plugin_element_template/lib.rs +12 -1
  125. package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +35 -0
  126. package/transform/crates/swc_plugin_worklet/lib.rs +11 -7
  127. package/transform/dist/wasm.cjs +1 -1
  128. package/transform/rspack-napi/lib/index.js +1 -4
  129. package/transform/rspack-napi/lib/index.js.map +1 -1
  130. package/transform/rspack-napi/src/index.ts +1 -4
  131. package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
  132. package/transform/src/lib.rs +394 -27
  133. package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +413 -105
  134. package/transform/swc-plugin-reactlynx/src/lib.rs +99 -22
  135. package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
  136. package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +28 -359
  137. package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
  138. package/runtime/__test__/element-template/lynx/env.test.ts +0 -242
  139. package/runtime/lib/element-template/lynx/env.d.ts +0 -1
  140. package/runtime/lib/element-template/lynx/env.js.map +0 -1
  141. package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +0 -1
  142. package/runtime/lib/snapshot/compat/componentIs.d.ts +0 -4
  143. package/runtime/lib/snapshot/compat/componentIs.js +0 -20
  144. package/runtime/lib/snapshot/compat/componentIs.js.map +0 -1
  145. package/runtime/src/snapshot/compat/componentIs.ts +0 -30
  146. /package/runtime/__test__/element-template/runtime/{template → background}/main-thread-function.test.ts +0 -0
  147. /package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.d.ts +0 -0
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Retires the current page's worklet-runtime state for an in-place reload or
3
+ * entry re-evaluation on the same main-thread VM.
4
+ *
5
+ * Preserves VM-scoped registrations (`_workletMap`, MainThreadObject
6
+ * definitions, realized object brands, and positive-ID ref entries), while
7
+ * advancing the `runOnBackground` epoch, recreating the lifecycle manager for
8
+ * the next page, and dropping any aborted first-screen refs or queued legacy
9
+ * worklet events.
10
+ */
11
+ export declare function resetWorkletRuntimeForReload(): void;
12
+ /**
13
+ * Disposes worklet-runtime state for terminal main-thread destruction
14
+ * (`__DestroyLifetime`).
15
+ *
16
+ * Unlike {@link resetWorkletRuntimeForReload}, this retires the lifecycle
17
+ * manager without allocating a replacement instance.
18
+ */
19
+ export declare function disposeWorkletRuntime(): void;
@@ -0,0 +1,49 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ function clearPendingWorkletRuntimeState(impl) {
5
+ impl._runOnBackgroundDelayImpl?.clearDelayedBackgroundFunctions?.();
6
+ impl._refImpl?.clearFirstScreenWorkletRefMap?.();
7
+ impl._eventDelayImpl?.clearDelayedWorklets?.(true);
8
+ }
9
+ /**
10
+ * Retires the current page's worklet-runtime state for an in-place reload or
11
+ * entry re-evaluation on the same main-thread VM.
12
+ *
13
+ * Preserves VM-scoped registrations (`_workletMap`, MainThreadObject
14
+ * definitions, realized object brands, and positive-ID ref entries), while
15
+ * advancing the `runOnBackground` epoch, recreating the lifecycle manager for
16
+ * the next page, and dropping any aborted first-screen refs or queued legacy
17
+ * worklet events.
18
+ */
19
+ export function resetWorkletRuntimeForReload() {
20
+ const impl = globalThis.lynxWorkletImpl;
21
+ if (!impl) {
22
+ return;
23
+ }
24
+ const manager = impl._jsFunctionLifecycleManager;
25
+ if (manager?.recreate) {
26
+ impl._jsFunctionLifecycleManager = manager.recreate();
27
+ }
28
+ clearPendingWorkletRuntimeState(impl);
29
+ }
30
+ /**
31
+ * Disposes worklet-runtime state for terminal main-thread destruction
32
+ * (`__DestroyLifetime`).
33
+ *
34
+ * Unlike {@link resetWorkletRuntimeForReload}, this retires the lifecycle
35
+ * manager without allocating a replacement instance.
36
+ */
37
+ export function disposeWorkletRuntime() {
38
+ const impl = globalThis.lynxWorkletImpl;
39
+ if (!impl) {
40
+ return;
41
+ }
42
+ const manager = impl._jsFunctionLifecycleManager;
43
+ if (manager) {
44
+ manager.dispose?.();
45
+ delete impl._jsFunctionLifecycleManager;
46
+ }
47
+ clearPendingWorkletRuntimeState(impl);
48
+ }
49
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../../src/worklet-runtime/bindings/lifecycle.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,SAAS,+BAA+B,CAAC,IAAuC;IAC9E,IAAI,CAAC,yBAAyB,EAAE,+BAA+B,EAAE,EAAE,CAAC;IACpE,IAAI,CAAC,QAAQ,EAAE,6BAA6B,EAAE,EAAE,CAAC;IACjD,IAAI,CAAC,eAAe,EAAE,oBAAoB,EAAE,CAAC,IAAI,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,4BAA4B;IAC1C,MAAM,IAAI,GAAG,UAAU,CAAC,eAAe,CAAC;IACxC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,2BAA2B,CAAC;IACjD,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC;QACtB,IAAI,CAAC,2BAA2B,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IACxD,CAAC;IACD,+BAA+B,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB;IACnC,MAAM,IAAI,GAAG,UAAU,CAAC,eAAe,CAAC;IACxC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,2BAA2B,CAAC;IACjD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,2BAA2B,CAAC;IAC1C,CAAC;IACD,+BAA+B,CAAC,IAAI,CAAC,CAAC;AACxC,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\nfunction clearPendingWorkletRuntimeState(impl: typeof globalThis.lynxWorkletImpl): void {\n impl._runOnBackgroundDelayImpl?.clearDelayedBackgroundFunctions?.();\n impl._refImpl?.clearFirstScreenWorkletRefMap?.();\n impl._eventDelayImpl?.clearDelayedWorklets?.(true);\n}\n\n/**\n * Retires the current page's worklet-runtime state for an in-place reload or\n * entry re-evaluation on the same main-thread VM.\n *\n * Preserves VM-scoped registrations (`_workletMap`, MainThreadObject\n * definitions, realized object brands, and positive-ID ref entries), while\n * advancing the `runOnBackground` epoch, recreating the lifecycle manager for\n * the next page, and dropping any aborted first-screen refs or queued legacy\n * worklet events.\n */\nexport function resetWorkletRuntimeForReload(): void {\n const impl = globalThis.lynxWorkletImpl;\n if (!impl) {\n return;\n }\n const manager = impl._jsFunctionLifecycleManager;\n if (manager?.recreate) {\n impl._jsFunctionLifecycleManager = manager.recreate();\n }\n clearPendingWorkletRuntimeState(impl);\n}\n\n/**\n * Disposes worklet-runtime state for terminal main-thread destruction\n * (`__DestroyLifetime`).\n *\n * Unlike {@link resetWorkletRuntimeForReload}, this retires the lifecycle\n * manager without allocating a replacement instance.\n */\nexport function disposeWorkletRuntime(): void {\n const impl = globalThis.lynxWorkletImpl;\n if (!impl) {\n return;\n }\n const manager = impl._jsFunctionLifecycleManager;\n if (manager) {\n manager.dispose?.();\n delete impl._jsFunctionLifecycleManager;\n }\n clearPendingWorkletRuntimeState(impl);\n}\n"]}
@@ -3,7 +3,7 @@ interface EventDelayImpl {
3
3
  _delayedWorkletParamsMap: Map<string, ClosureValueType[][]>;
4
4
  delayExecUntilJsReady(hash: string, params: ClosureValueType[]): void;
5
5
  runDelayedWorklet(worklet: Worklet, element: ElementNode): void;
6
- clearDelayedWorklets(): void;
6
+ clearDelayedWorklets(cancelScheduled?: boolean): void;
7
7
  }
8
8
  declare function initEventDelay(): EventDelayImpl;
9
9
  export { type EventDelayImpl, initEventDelay };
@@ -1,5 +1,6 @@
1
1
  import { profile } from './utils/profile.js';
2
2
  function initEventDelay() {
3
+ let generation = 0;
3
4
  const instance = {
4
5
  _delayedWorkletParamsMap: new Map(),
5
6
  delayExecUntilJsReady(hash, params) {
@@ -20,11 +21,15 @@ function initEventDelay() {
20
21
  if (paramsVec === undefined) {
21
22
  return;
22
23
  }
24
+ const scheduledGeneration = generation;
23
25
  const leftParamsVec = [];
24
26
  paramsVec.forEach((params) => {
25
27
  const firstParam = params[0];
26
28
  if (firstParam?.currentTarget?.elementRefptr === element) {
27
29
  setTimeout(() => {
30
+ if (scheduledGeneration !== generation) {
31
+ return;
32
+ }
28
33
  profile('runDelayedWorklet', () => {
29
34
  runWorklet(worklet, params);
30
35
  });
@@ -37,7 +42,10 @@ function initEventDelay() {
37
42
  instance._delayedWorkletParamsMap.set(worklet._wkltId, leftParamsVec);
38
43
  });
39
44
  },
40
- clearDelayedWorklets() {
45
+ clearDelayedWorklets(cancelScheduled) {
46
+ if (cancelScheduled) {
47
+ generation++;
48
+ }
41
49
  instance._delayedWorkletParamsMap.clear();
42
50
  },
43
51
  };
@@ -1 +1 @@
1
- {"version":3,"file":"delayWorkletEvent.js","sourceRoot":"","sources":["../../src/worklet-runtime/delayWorkletEvent.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAS7C,SAAS,cAAc;IACrB,MAAM,QAAQ,GAAmB;QAC/B,wBAAwB,EAAE,IAAI,GAAG,EAAE;QACnC,qBAAqB,CACnB,IAAY,EACZ,MAA0B;YAE1B,OAAO,CAAC,yBAAyB,GAAG,IAAI,EAAE,GAAG,EAAE;gBAC7C,MAAM,GAAG,GAAG,QAAQ,CAAC,wBAAwB,CAAC;gBAC9C,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC/B,IAAI,QAAQ,EAAE,CAAC;oBACb,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACxB,CAAC;qBAAM,CAAC;oBACN,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC1B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QACD,iBAAiB,CAAC,OAAgB,EAAE,OAAoB;YACtD,OAAO,CAAC,sBAAsB,EAAE,GAAG,EAAE;gBACnC,MAAM,SAAS,GAAG,QAAQ,CAAC,wBAAwB,CAAC,GAAG,CACrD,OAAO,CAAC,OAAO,CAChB,CAAC;gBACF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;oBAC5B,OAAO;gBACT,CAAC;gBACD,MAAM,aAAa,GAAyB,EAAE,CAAC;gBAC/C,SAAS,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;oBAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAoE,CAAC;oBAChG,IAAI,UAAU,EAAE,aAAa,EAAE,aAAa,KAAK,OAAO,EAAE,CAAC;wBACzD,UAAU,CAAC,GAAG,EAAE;4BACd,OAAO,CAAC,mBAAmB,EAAE,GAAG,EAAE;gCAChC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;4BAC9B,CAAC,CAAC,CAAC;wBACL,CAAC,EAAE,CAAC,CAAC,CAAC;oBACR,CAAC;yBAAM,CAAC;wBACN,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAC7B,CAAC;gBACH,CAAC,CAAC,CAAC;gBACH,QAAQ,CAAC,wBAAwB,CAAC,GAAG,CACnC,OAAO,CAAC,OAAO,EACf,aAAa,CACd,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,oBAAoB;YAClB,QAAQ,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC;QAC5C,CAAC;KACF,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,OAAO,EAAuB,cAAc,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 type { ClosureValueType, Worklet } from './bindings/types.js';\nimport { profile } from './utils/profile.js';\n\ninterface EventDelayImpl {\n _delayedWorkletParamsMap: Map<string, ClosureValueType[][]>;\n delayExecUntilJsReady(hash: string, params: ClosureValueType[]): void;\n runDelayedWorklet(worklet: Worklet, element: ElementNode): void;\n clearDelayedWorklets(): void;\n}\n\nfunction initEventDelay(): EventDelayImpl {\n const instance: EventDelayImpl = {\n _delayedWorkletParamsMap: new Map(),\n delayExecUntilJsReady(\n hash: string,\n params: ClosureValueType[],\n ): void {\n profile('delayExecUntilJsReady: ' + hash, () => {\n const map = instance._delayedWorkletParamsMap;\n const paramVec = map.get(hash);\n if (paramVec) {\n paramVec.push(params);\n } else {\n map.set(hash, [params]);\n }\n });\n },\n runDelayedWorklet(worklet: Worklet, element: ElementNode): void {\n profile('commitDelayedWorklet', () => {\n const paramsVec = instance._delayedWorkletParamsMap.get(\n worklet._wkltId,\n );\n if (paramsVec === undefined) {\n return;\n }\n const leftParamsVec: ClosureValueType[][] = [];\n paramsVec.forEach((params) => {\n const firstParam = params[0] as { currentTarget?: { elementRefptr?: ElementNode } } | undefined;\n if (firstParam?.currentTarget?.elementRefptr === element) {\n setTimeout(() => {\n profile('runDelayedWorklet', () => {\n runWorklet(worklet, params);\n });\n }, 0);\n } else {\n leftParamsVec.push(params);\n }\n });\n instance._delayedWorkletParamsMap.set(\n worklet._wkltId,\n leftParamsVec,\n );\n });\n },\n clearDelayedWorklets(): void {\n instance._delayedWorkletParamsMap.clear();\n },\n };\n return instance;\n}\n\nexport { type EventDelayImpl, initEventDelay };\n"]}
1
+ {"version":3,"file":"delayWorkletEvent.js","sourceRoot":"","sources":["../../src/worklet-runtime/delayWorkletEvent.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAS7C,SAAS,cAAc;IACrB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,MAAM,QAAQ,GAAmB;QAC/B,wBAAwB,EAAE,IAAI,GAAG,EAAE;QACnC,qBAAqB,CACnB,IAAY,EACZ,MAA0B;YAE1B,OAAO,CAAC,yBAAyB,GAAG,IAAI,EAAE,GAAG,EAAE;gBAC7C,MAAM,GAAG,GAAG,QAAQ,CAAC,wBAAwB,CAAC;gBAC9C,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC/B,IAAI,QAAQ,EAAE,CAAC;oBACb,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACxB,CAAC;qBAAM,CAAC;oBACN,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC1B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QACD,iBAAiB,CAAC,OAAgB,EAAE,OAAoB;YACtD,OAAO,CAAC,sBAAsB,EAAE,GAAG,EAAE;gBACnC,MAAM,SAAS,GAAG,QAAQ,CAAC,wBAAwB,CAAC,GAAG,CACrD,OAAO,CAAC,OAAO,CAChB,CAAC;gBACF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;oBAC5B,OAAO;gBACT,CAAC;gBACD,MAAM,mBAAmB,GAAG,UAAU,CAAC;gBACvC,MAAM,aAAa,GAAyB,EAAE,CAAC;gBAC/C,SAAS,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;oBAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAoE,CAAC;oBAChG,IAAI,UAAU,EAAE,aAAa,EAAE,aAAa,KAAK,OAAO,EAAE,CAAC;wBACzD,UAAU,CAAC,GAAG,EAAE;4BACd,IAAI,mBAAmB,KAAK,UAAU,EAAE,CAAC;gCACvC,OAAO;4BACT,CAAC;4BACD,OAAO,CAAC,mBAAmB,EAAE,GAAG,EAAE;gCAChC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;4BAC9B,CAAC,CAAC,CAAC;wBACL,CAAC,EAAE,CAAC,CAAC,CAAC;oBACR,CAAC;yBAAM,CAAC;wBACN,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAC7B,CAAC;gBACH,CAAC,CAAC,CAAC;gBACH,QAAQ,CAAC,wBAAwB,CAAC,GAAG,CACnC,OAAO,CAAC,OAAO,EACf,aAAa,CACd,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,oBAAoB,CAAC,eAAyB;YAC5C,IAAI,eAAe,EAAE,CAAC;gBACpB,UAAU,EAAE,CAAC;YACf,CAAC;YACD,QAAQ,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC;QAC5C,CAAC;KACF,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,OAAO,EAAuB,cAAc,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 type { ClosureValueType, Worklet } from './bindings/types.js';\nimport { profile } from './utils/profile.js';\n\ninterface EventDelayImpl {\n _delayedWorkletParamsMap: Map<string, ClosureValueType[][]>;\n delayExecUntilJsReady(hash: string, params: ClosureValueType[]): void;\n runDelayedWorklet(worklet: Worklet, element: ElementNode): void;\n clearDelayedWorklets(cancelScheduled?: boolean): void;\n}\n\nfunction initEventDelay(): EventDelayImpl {\n let generation = 0;\n const instance: EventDelayImpl = {\n _delayedWorkletParamsMap: new Map(),\n delayExecUntilJsReady(\n hash: string,\n params: ClosureValueType[],\n ): void {\n profile('delayExecUntilJsReady: ' + hash, () => {\n const map = instance._delayedWorkletParamsMap;\n const paramVec = map.get(hash);\n if (paramVec) {\n paramVec.push(params);\n } else {\n map.set(hash, [params]);\n }\n });\n },\n runDelayedWorklet(worklet: Worklet, element: ElementNode): void {\n profile('commitDelayedWorklet', () => {\n const paramsVec = instance._delayedWorkletParamsMap.get(\n worklet._wkltId,\n );\n if (paramsVec === undefined) {\n return;\n }\n const scheduledGeneration = generation;\n const leftParamsVec: ClosureValueType[][] = [];\n paramsVec.forEach((params) => {\n const firstParam = params[0] as { currentTarget?: { elementRefptr?: ElementNode } } | undefined;\n if (firstParam?.currentTarget?.elementRefptr === element) {\n setTimeout(() => {\n if (scheduledGeneration !== generation) {\n return;\n }\n profile('runDelayedWorklet', () => {\n runWorklet(worklet, params);\n });\n }, 0);\n } else {\n leftParamsVec.push(params);\n }\n });\n instance._delayedWorkletParamsMap.set(\n worklet._wkltId,\n leftParamsVec,\n );\n });\n },\n clearDelayedWorklets(cancelScheduled?: boolean): void {\n if (cancelScheduled) {\n generation++;\n }\n instance._delayedWorkletParamsMap.clear();\n },\n };\n return instance;\n}\n\nexport { type EventDelayImpl, initEventDelay };\n"]}
@@ -2,9 +2,7 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  export function profile(sliceName, f) {
5
- /* v8 ignore next 9 */
6
- // TODO: change it to __PROFILE__
7
- if (__DEV__) {
5
+ if (__PROFILE__) {
8
6
  console.profile?.(sliceName);
9
7
  try {
10
8
  return f();
@@ -1 +1 @@
1
- {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../src/worklet-runtime/utils/profile.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,MAAM,UAAU,OAAO,CACrB,SAAiB,EACjB,CAAK;IAEL,sBAAsB;IACtB,iCAAiC;IACjC,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;QAC7B,IAAI,CAAC;YACH,OAAO,CAAC,EAAE,CAAC;QACb,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,EAAE,CAAC;IACb,CAAC;AACH,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.\nexport function profile<Ret, Fn extends (...args: unknown[]) => Ret>(\n sliceName: string,\n f: Fn,\n): Ret {\n /* v8 ignore next 9 */\n // TODO: change it to __PROFILE__\n if (__DEV__) {\n console.profile?.(sliceName);\n try {\n return f();\n } finally {\n console.profileEnd?.();\n }\n } else {\n return f();\n }\n}\n"]}
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../src/worklet-runtime/utils/profile.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,MAAM,UAAU,OAAO,CACrB,SAAiB,EACjB,CAAK;IAEL,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;QAC7B,IAAI,CAAC;YACH,OAAO,CAAC,EAAE,CAAC;QACb,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,EAAE,CAAC;IACb,CAAC;AACH,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.\nexport function profile<Ret, Fn extends (...args: unknown[]) => Ret>(\n sliceName: string,\n f: Fn,\n): Ret {\n if (__PROFILE__) {\n console.profile?.(sliceName);\n try {\n return f();\n } finally {\n console.profileEnd?.();\n }\n } else {\n return f();\n }\n}\n"]}
@@ -0,0 +1,32 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import type { ComponentType } from 'preact';
6
+ import { Suspense, createElement, lazy } from 'preact/compat';
7
+
8
+ import { useMemo } from '../hooks/react.js';
9
+ import { loadLazyBundle } from '../lynx/lazy-bundle.js';
10
+
11
+ /**
12
+ * @internal Compatibility for the compiler lowering of <component is=? />.
13
+ */
14
+ export function __ComponentIsPolyfill({ is, ...props }: { is: string }) {
15
+ const DynamicComponent = useMemo(
16
+ // Lazy bundles expose React types but run on the host's Preact renderer.
17
+ () =>
18
+ lazy<ComponentType<Record<string, unknown>>>(() =>
19
+ loadLazyBundle(is) as Promise<{ default: ComponentType<Record<string, unknown>> }>
20
+ ),
21
+ [is],
22
+ );
23
+ if (typeof is !== 'string') {
24
+ lynx.reportError(
25
+ new Error(
26
+ 'You must provide a string to props `is` when using syntax `<component is=? />`.',
27
+ ),
28
+ );
29
+ return null;
30
+ }
31
+ return createElement(Suspense, { key: is, fallback: null }, createElement(DynamicComponent, props));
32
+ }
@@ -1,10 +1,11 @@
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 { createProcessData } from '../../core/lynx-data-processors.js';
5
- import type { DataProcessorDefinition } from '../../core/lynx-data-processors.js';
6
4
 
7
- export function setupLynxEnv(): void {
5
+ import { createProcessData } from '../lynx-data-processors.js';
6
+ import type { DataProcessorDefinition } from '../lynx-data-processors.js';
7
+
8
+ export function setupSharedLynxEnv(): void {
8
9
  if (!__LEPUS__) {
9
10
  let initData: Record<string, unknown> = {};
10
11
  let updateData: Record<string, unknown> = {};
@@ -30,7 +31,7 @@ export function setupLynxEnv(): void {
30
31
 
31
32
  lynx.triggerGlobalEventFromLepus = function(
32
33
  eventName: string,
33
- params: any,
34
+ params: unknown,
34
35
  ) {
35
36
  __OnLifecycleEvent(['globalEventFromLepus', [eventName, params]]);
36
37
  };
@@ -54,6 +55,7 @@ export function setupLynxEnv(): void {
54
55
  globalThis.processData = createProcessData(dataProcessorDefinition);
55
56
  };
56
57
 
58
+ // register empty DataProcessors to make sure `globalThis.processData` is set
57
59
  lynx.registerDataProcessors();
58
60
  }
59
61
  }
@@ -2,6 +2,8 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
+ import { options as preactOptions } from 'preact';
6
+
5
7
  import { onFunctionCall } from './return-value.js';
6
8
  import { isSdkVersionGt } from '../../shared/version.js';
7
9
  import { WorkletEvents } from '../../worklet-runtime/bindings/events.js';
@@ -48,6 +50,8 @@ export function createRunOnMainThread(
48
50
  return new Promise((resolve) => {
49
51
  if (isRuntimeDestroyed()) return;
50
52
  const worklet = fn as unknown as Worklet;
53
+ if (preactOptions.scheduleMainThreadWorklet?.({ worklet, params, resolve })) return;
54
+
51
55
  prepareMainThreadFunctionCtx(worklet);
52
56
  const data = {
53
57
  worklet,
@@ -70,7 +74,7 @@ function isRunOnBackgroundSupported(): boolean {
70
74
  return isSdkVersionGt(2, 15);
71
75
  }
72
76
 
73
- function prepareMainThreadFunctionCtx(worklet: unknown): void {
77
+ export function prepareMainThreadFunctionCtx(worklet: unknown): void {
74
78
  if (isMainThreadFunction(worklet) && isRunOnBackgroundSupported()) {
75
79
  registerBackgroundFunctionCtx(worklet);
76
80
  }
@@ -0,0 +1,52 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import { globalCommitContext } from './commit-context.js';
6
+ import { getReloadVersion } from '../../core/reload-version.js';
7
+ import { dropFunctionCallReturnIds } from '../../core/thread-function-call/return-value.js';
8
+ import type { RunWorkletCtxData } from '../../worklet-runtime/bindings/events.js';
9
+ import { formatElementTemplateUpdateCommands } from '../debug/alog.js';
10
+ import { createElementTemplateUpdateEvent } from '../protocol/update-event.js';
11
+ import type { ElementTemplateUpdateEvent } from '../protocol/update-event.js';
12
+
13
+ export function dropDelayedRunOnMainThreadReturnIds(
14
+ delayedRunOnMainThreadPayload: readonly { resolveId: number }[] | undefined,
15
+ ): void {
16
+ if (delayedRunOnMainThreadPayload) {
17
+ dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));
18
+ }
19
+ }
20
+
21
+ export function packElementTemplateCommitUpdateEvent(
22
+ delayedRunOnMainThreadData: RunWorkletCtxData[] | undefined,
23
+ isHydration = false,
24
+ ): ElementTemplateUpdateEvent {
25
+ if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
26
+ console.alog?.(
27
+ (isHydration
28
+ ? '[ReactLynxDebug] ElementTemplate hydrate update commands:\n'
29
+ : '[ReactLynxDebug] ElementTemplate BTS -> MTS update:\n')
30
+ + JSON.stringify(
31
+ {
32
+ ops: formatElementTemplateUpdateCommands(globalCommitContext.ops),
33
+ flushOptions: globalCommitContext.flushOptions,
34
+ flowIds: globalCommitContext.flowIds,
35
+ isHydration: isHydration || undefined,
36
+ delayedRunOnMainThreadDataCount: delayedRunOnMainThreadData?.length,
37
+ },
38
+ null,
39
+ 2,
40
+ ),
41
+ );
42
+ }
43
+
44
+ return createElementTemplateUpdateEvent({
45
+ ops: globalCommitContext.ops,
46
+ flushOptions: globalCommitContext.flushOptions,
47
+ isHydration: isHydration || undefined,
48
+ reloadVersion: getReloadVersion(),
49
+ flowIds: globalCommitContext.flowIds,
50
+ delayedRunOnMainThreadData,
51
+ });
52
+ }
@@ -9,22 +9,19 @@ import {
9
9
  resetGlobalCommitContext,
10
10
  takeRemovedSubtreesForPostDispatchTeardown,
11
11
  } from './commit-context.js';
12
+ import { dropDelayedRunOnMainThreadReturnIds, packElementTemplateCommitUpdateEvent } from './commit-event.js';
12
13
  import type { BackgroundElementTemplateInstance } from './instance.js';
13
14
  import { clearElementTemplateRenderScope, resetElementTemplateRenderScope } from './render-scope.js';
14
15
  import { globalPipelineOptions, markTiming, markTimingLegacy, setPipeline } from '../../core/performance.js';
15
- import { getReloadVersion } from '../../core/reload-version.js';
16
16
  import {
17
17
  delayedRunOnMainThreadData,
18
18
  takeDelayedRunOnMainThreadData,
19
19
  } from '../../core/thread-function-call/main-thread.js';
20
- import { dropFunctionCallReturnIds } from '../../core/thread-function-call/return-value.js';
21
20
  import { COMMIT } from '../../shared/render-constants.js';
22
21
  import { hook, isEmptyObject } from '../../shared/utils.js';
23
- import { formatElementTemplateUpdateCommands } from '../debug/alog.js';
24
22
  import { profileEnd, profileStart } from '../debug/profile.js';
25
23
  import { sendMTRefInitValueToMainThread } from '../main-thread-ref-init-value.js';
26
24
  import { clearPendingRefs, flushPendingRefs, hasPendingRefs } from '../prop-adapters/ref.js';
27
- import { createElementTemplateUpdateEvent } from '../protocol/update-event.js';
28
25
 
29
26
  let installed = false;
30
27
  let previousCommit: typeof options[typeof COMMIT];
@@ -71,9 +68,7 @@ function cleanupFailedElementTemplateCommit(
71
68
  removedSubtreesAwaitingTeardown: BackgroundElementTemplateInstance[],
72
69
  delayedRunOnMainThreadPayload: readonly { resolveId: number }[] | undefined,
73
70
  ): void {
74
- if (delayedRunOnMainThreadPayload) {
75
- dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));
76
- }
71
+ dropDelayedRunOnMainThreadReturnIds(delayedRunOnMainThreadPayload);
77
72
  clearPendingRefs();
78
73
  resetGlobalCommitContext();
79
74
  setPipeline(undefined);
@@ -114,31 +109,9 @@ function flushElementTemplateCommitChanges(): void {
114
109
  ? takeDelayedRunOnMainThreadData()
115
110
  : undefined;
116
111
 
117
- let updateEvent: ReturnType<typeof createElementTemplateUpdateEvent>;
112
+ let updateEvent: ReturnType<typeof packElementTemplateCommitUpdateEvent>;
118
113
  try {
119
- if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
120
- console.alog?.(
121
- '[ReactLynxDebug] ElementTemplate BTS -> MTS update:\n'
122
- + JSON.stringify(
123
- {
124
- ops: formatElementTemplateUpdateCommands(globalCommitContext.ops),
125
- flushOptions: globalCommitContext.flushOptions,
126
- flowIds: globalCommitContext.flowIds,
127
- delayedRunOnMainThreadDataCount: delayedRunOnMainThreadPayload?.length,
128
- },
129
- null,
130
- 2,
131
- ),
132
- );
133
- }
134
-
135
- updateEvent = createElementTemplateUpdateEvent({
136
- ops: globalCommitContext.ops,
137
- flushOptions: globalCommitContext.flushOptions,
138
- reloadVersion: getReloadVersion(),
139
- flowIds: globalCommitContext.flowIds,
140
- delayedRunOnMainThreadData: delayedRunOnMainThreadPayload,
141
- });
114
+ updateEvent = packElementTemplateCommitUpdateEvent(delayedRunOnMainThreadPayload);
142
115
  } catch (error) {
143
116
  cleanupFailedElementTemplateCommit(removedSubtreesAwaitingTeardown, delayedRunOnMainThreadPayload);
144
117
  throw error;
@@ -6,13 +6,13 @@ import { render } from 'preact';
6
6
 
7
7
  import { cancelElementTemplateRemovedSubtreeCleanup, resetElementTemplateCommitState } from './commit-hook.js';
8
8
  import { resetElementTemplateHydrationListener } from './hydration-listener.js';
9
+ import { resetElementTemplateMainThreadFunctionRuntime } from './main-thread-function.js';
9
10
  import { backgroundElementTemplateInstanceManager } from './manager.js';
10
11
  import { withSyncEffectFlush } from '../../core/sync-effect-flush.js';
11
12
  import { clearEventState } from '../prop-adapters/event.js';
12
13
  import { clearRefState, flushPendingRefs } from '../prop-adapters/ref.js';
13
14
  import { __root } from '../runtime/page/root-instance.js';
14
15
  import { resetElementTemplateBackgroundFunctionRuntime } from '../runtime/template/main-thread-background-function.js';
15
- import { resetElementTemplateMainThreadFunctionRuntime } from '../runtime/template/main-thread-function.js';
16
16
 
17
17
  export function destroyElementTemplateBackgroundRuntime(): void {
18
18
  resetElementTemplateHydrationListener();
@@ -20,7 +20,11 @@ import { isGestureSlotValue } from '../prop-adapters/gesture.js';
20
20
  import { isMainThreadEventPropKey, isSpreadRecord } from '../prop-adapters/spread.js';
21
21
  import { ElementTemplateUpdateOps } from '../protocol/opcodes.js';
22
22
  import { ELEMENT_TEMPLATE_PAGE_HANDLE_ID, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../protocol/page.js';
23
- import { elementTemplateIdentityKey, parseElementTemplateType } from '../protocol/template-type.js';
23
+ import {
24
+ MAIN_BUNDLE_URL_SENTINEL,
25
+ elementTemplateIdentityKey,
26
+ parseElementTemplateType,
27
+ } from '../protocol/template-type.js';
24
28
  import type {
25
29
  SerializableValue,
26
30
  SerializedCompiledNode,
@@ -33,8 +37,6 @@ import type { MainThreadDynamicAttrKind } from '../runtime/template/attr-slot-pl
33
37
  import { isMTEventNativeWrapper } from '../runtime/template/main-thread-event-ctx.js';
34
38
  import type { MTRefNativeWrapper } from '../runtime/template/main-thread-ref-ctx.js';
35
39
 
36
- const MAIN_BUNDLE_URL_SENTINEL = '__Card__';
37
-
38
40
  export function hydrateRootChildrenIntoContext(
39
41
  serializedChildren: SerializedEtNode[],
40
42
  root: BackgroundElementTemplateInstance,
@@ -6,12 +6,14 @@ import {
6
6
  resetGlobalCommitContext,
7
7
  takeRemovedSubtreesForPostDispatchTeardown,
8
8
  } from './commit-context.js';
9
+ import { dropDelayedRunOnMainThreadReturnIds, packElementTemplateCommitUpdateEvent } from './commit-event.js';
9
10
  import {
10
11
  markElementTemplateHydrated,
11
12
  resetElementTemplateCommitState,
12
13
  scheduleElementTemplateRemovedSubtreeCleanup,
13
14
  } from './commit-hook.js';
14
15
  import type { BackgroundPageRootInstance } from './instance.js';
16
+ import { resetElementTemplateMainThreadFunctionRuntime } from './main-thread-function.js';
15
17
  import { hydratePageRootIntoContext } from './page-root-hydrate.js';
16
18
  import { takeMainThreadRefInitValuePatch } from '../../core/main-thread-ref-init-value.js';
17
19
  import {
@@ -27,17 +29,15 @@ import {
27
29
  delayedRunOnMainThreadData,
28
30
  takeDelayedRunOnMainThreadData,
29
31
  } from '../../core/thread-function-call/main-thread.js';
30
- import { dropFunctionCallReturnIds } from '../../core/thread-function-call/return-value.js';
31
- import { formatElementTemplateUpdateCommands, printElementTemplateTreeToString } from '../debug/alog.js';
32
+ import { printElementTemplateTreeToString } from '../debug/alog.js';
32
33
  import { profileEnd, profileStart } from '../debug/profile.js';
33
34
  import { sendMTRefInitValueToMainThread } from '../main-thread-ref-init-value.js';
34
35
  import { clearPendingEvents, flushPendingEvents } from '../prop-adapters/event.js';
35
36
  import { clearDelayedRefUiOps, clearPendingRefs, flushDelayedRefUiOps } from '../prop-adapters/ref.js';
36
37
  import { ElementTemplateLifecycleConstant } from '../protocol/lifecycle-constant.js';
37
38
  import type { ElementTemplateHydrateCommitContext } from '../protocol/types.js';
38
- import { createElementTemplateUpdateEvent } from '../protocol/update-event.js';
39
+ import type { ElementTemplateUpdateEvent } from '../protocol/update-event.js';
39
40
  import { __root } from '../runtime/page/root-instance.js';
40
- import { resetElementTemplateMainThreadFunctionRuntime } from '../runtime/template/main-thread-function.js';
41
41
 
42
42
  let listener:
43
43
  | ((event: { data: ElementTemplateHydrateCommitContext }) => void)
@@ -115,41 +115,16 @@ export function installElementTemplateHydrationListener(): void {
115
115
  const removedSubtreesAwaitingTeardown = globalCommitContext.ops.length > 0
116
116
  ? takeRemovedSubtreesForPostDispatchTeardown()
117
117
  : [];
118
- let hydrateUpdateEvent: ReturnType<typeof createElementTemplateUpdateEvent> | undefined;
118
+ let hydrateUpdateEvent: ElementTemplateUpdateEvent | undefined;
119
119
  if (__PROFILE__) {
120
120
  profileStart('ReactLynx::commitChanges');
121
121
  }
122
122
  markTiming('packChangesStart');
123
123
  try {
124
124
  sendMTRefInitValueToMainThread();
125
- if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
126
- console.alog?.(
127
- '[ReactLynxDebug] ElementTemplate hydrate update commands:\n'
128
- + JSON.stringify(
129
- {
130
- ops: formatElementTemplateUpdateCommands(globalCommitContext.ops),
131
- flushOptions: globalCommitContext.flushOptions,
132
- flowIds: globalCommitContext.flowIds,
133
- isHydration: true,
134
- delayedRunOnMainThreadDataCount: delayedRunOnMainThreadPayload?.length,
135
- },
136
- null,
137
- 2,
138
- ),
139
- );
140
- }
141
- hydrateUpdateEvent = createElementTemplateUpdateEvent({
142
- ops: globalCommitContext.ops,
143
- flushOptions: globalCommitContext.flushOptions,
144
- isHydration: true,
145
- reloadVersion: getReloadVersion(),
146
- flowIds: globalCommitContext.flowIds,
147
- delayedRunOnMainThreadData: delayedRunOnMainThreadPayload,
148
- });
125
+ hydrateUpdateEvent = packElementTemplateCommitUpdateEvent(delayedRunOnMainThreadPayload, true);
149
126
  } catch (error) {
150
- if (delayedRunOnMainThreadPayload) {
151
- dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));
152
- }
127
+ dropDelayedRunOnMainThreadReturnIds(delayedRunOnMainThreadPayload);
153
128
  // Do not expose refs or replay delayed selector ops if the hydrate
154
129
  // patch failed to serialize; selectors may still point at stale
155
130
  // pre-hydration ids in that case.
@@ -2,13 +2,10 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
- import {
6
- createRunOnMainThread,
7
- takeDelayedRunOnMainThreadData,
8
- } from '../../../core/thread-function-call/main-thread.js';
9
- import { resetFunctionCallReturnListener } from '../../../core/thread-function-call/return-value.js';
10
- import { isElementTemplateHydrated } from '../../background/commit-hook.js';
11
- import { isElementTemplateRendering } from '../../background/render-scope.js';
5
+ import { isElementTemplateHydrated } from './commit-hook.js';
6
+ import { isElementTemplateRendering } from './render-scope.js';
7
+ import { createRunOnMainThread, takeDelayedRunOnMainThreadData } from '../../core/thread-function-call/main-thread.js';
8
+ import { resetFunctionCallReturnListener } from '../../core/thread-function-call/return-value.js';
12
9
 
13
10
  const runOnMainThreadImpl = createRunOnMainThread({
14
11
  shouldDispatchRunOnMainThreadDirectly() {
@@ -131,7 +131,7 @@ export { useLynxGlobalEventListener };
131
131
 
132
132
  export * from './client/root.js';
133
133
  export { runOnBackground } from './runtime/template/main-thread-background-function.js';
134
- export { runOnMainThread } from './runtime/template/main-thread-function.js';
134
+ export { runOnMainThread } from './background/main-thread-function.js';
135
135
  export { MainThreadRef, useMainThreadRef } from '../core/main-thread-ref.js';
136
136
  export { defineMainThreadObjectType, useMainThreadObject } from '../core/main-thread-object.js';
137
137
 
@@ -5,6 +5,7 @@
5
5
  import './runtime-marker.js';
6
6
  import './native/index.js';
7
7
 
8
+ import { __ComponentIsPolyfill as componentIsPolyfill } from '../core/compat/componentIs.js';
8
9
  import { __root } from './runtime/page/root-instance.js';
9
10
 
10
11
  /**
@@ -40,6 +41,9 @@ export {
40
41
 
41
42
  export { withInitDataInState } from '../core/initData.js';
42
43
 
44
+ /** @internal Compatibility for the compiler lowering of <component is=? />. */
45
+ export const __ComponentIsPolyfill = componentIsPolyfill;
46
+
43
47
  export { wrapWithLynxComponent } from '../core/compat/lynxComponent.js';
44
48
 
45
49
  export { loadLazyBundle } from '../core/lynx/lazy-bundle.js';
@@ -14,6 +14,7 @@ import { setupComponentStack } from '../../core/component-stack.js';
14
14
  import { runWithForceRootRender } from '../../core/forceRootRender.js';
15
15
  import { updateGlobalProps as updateGlobalPropsCore } from '../../core/globalProps.js';
16
16
  import { installMainThreadHooks } from '../../core/hooks/mainThreadImpl.js';
17
+ import { setupSharedLynxEnv } from '../../core/lynx/env.js';
17
18
  import { updateCardData } from '../../core/lynx-update-data.js';
18
19
  import { lynxQueueMicrotask } from '../../shared/microtask.js';
19
20
  import { installElementTemplateCommitHook } from '../background/commit-hook.js';
@@ -23,7 +24,6 @@ import { BackgroundPageRootInstance } from '../background/instance.js';
23
24
  import { installElementTemplateRenderScopeHooks } from '../background/render-scope.js';
24
25
  import { initElementTemplatePAPICallAlog } from '../debug/elementPAPICall.js';
25
26
  import { initProfileHook } from '../debug/profile.js';
26
- import { setupLynxEnv } from '../lynx/env.js';
27
27
  import { initTimingAPI } from '../lynx/performance.js';
28
28
  import { installElementTemplateRefInitValueListener } from '../main-thread-ref-init-value.js';
29
29
  import { publicComponentEvent, publishEvent, resetEventStateForRuntime } from '../prop-adapters/event.js';
@@ -92,7 +92,7 @@ function init(): void {
92
92
  }
93
93
  }
94
94
 
95
- setupLynxEnv();
95
+ setupSharedLynxEnv();
96
96
  }
97
97
 
98
98
  init();
@@ -6,7 +6,10 @@ import { resetElementTemplatePatchListener } from './patch-listener.js';
6
6
  import { resetElementTemplateRefInitValueListener } from '../main-thread-ref-init-value.js';
7
7
  import { destroyAllElementTemplateListStates } from '../runtime/list/list.js';
8
8
  import { resetTemplateId } from '../runtime/template/handle.js';
9
- import { resetElementTemplateMainThreadBackgroundFunctionRuntime } from '../runtime/template/main-thread-background-function.js';
9
+ import {
10
+ disposeElementTemplateMainThreadBackgroundFunctionRuntime,
11
+ resetElementTemplateMainThreadBackgroundFunctionRuntime,
12
+ } from '../runtime/template/main-thread-background-function.js';
10
13
  import { clearMainThreadDynamicAttrState } from '../runtime/template/main-thread-dynamic-attr-state.js';
11
14
  import { elementTemplateRegistry } from '../runtime/template/registry.js';
12
15
 
@@ -15,17 +18,27 @@ export function installOnMtsDestruction(): void {
15
18
  }
16
19
 
17
20
  export function onMtsDestruction(): void {
21
+ teardownOnMtsDestruction('destroy');
22
+ }
23
+
24
+ export function retireElementTemplateMainThreadForReload(): void {
25
+ teardownOnMtsDestruction('reload');
26
+ }
27
+
28
+ function teardownOnMtsDestruction(mode: 'destroy' | 'reload'): void {
18
29
  const performance = lynx.performance;
19
30
  performance?.profileStart?.('ReactLynx::onMtsDestruction');
20
31
  try {
21
- destroyElementTemplateMainThreadRuntime();
32
+ destroyElementTemplateMainThreadRuntime(mode);
22
33
  } finally {
23
34
  performance?.profileEnd?.();
24
35
  lynx.getNative?.().removeEventListener('__DestroyLifetime', onMtsDestruction);
25
36
  }
26
37
  }
27
38
 
28
- export function destroyElementTemplateMainThreadRuntime(): void {
39
+ export function destroyElementTemplateMainThreadRuntime(
40
+ mode: 'destroy' | 'reload' = 'destroy',
41
+ ): void {
29
42
  let patchListenerResetError: unknown;
30
43
  let didPatchListenerResetThrow = false;
31
44
  try {
@@ -44,7 +57,11 @@ export function destroyElementTemplateMainThreadRuntime(): void {
44
57
  try {
45
58
  clearMainThreadDynamicAttrState();
46
59
  } finally {
47
- resetElementTemplateMainThreadBackgroundFunctionRuntime();
60
+ if (mode === 'reload') {
61
+ resetElementTemplateMainThreadBackgroundFunctionRuntime();
62
+ } else {
63
+ disposeElementTemplateMainThreadBackgroundFunctionRuntime();
64
+ }
48
65
  resetTemplateId();
49
66
  }
50
67
 
@@ -3,7 +3,7 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
5
  import { flushElementTemplate } from './flush.js';
6
- import { onMtsDestruction } from './mts-destroy.js';
6
+ import { retireElementTemplateMainThreadForReload } from './mts-destroy.js';
7
7
  import {
8
8
  canReEvalMainThreadEntry,
9
9
  installMainThreadReloadCompleter,
@@ -59,7 +59,7 @@ export function reloadMainThread(data: unknown, options: UpdatePageOption): void
59
59
  }
60
60
  if (canReEvalMainThreadEntry()) {
61
61
  try {
62
- onMtsDestruction();
62
+ retireElementTemplateMainThreadForReload();
63
63
  } finally {
64
64
  increaseReloadVersion();
65
65
  }