@lynx-js/react 0.105.0 → 0.105.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +57 -5
  3. package/package.json +7 -2
  4. package/refresh/.turbo/turbo-build.log +1 -1
  5. package/refresh/package.json +1 -1
  6. package/runtime/lib/backgroundSnapshot.d.ts +1 -1
  7. package/runtime/lib/backgroundSnapshot.js +2 -2
  8. package/runtime/lib/backgroundSnapshot.js.map +1 -1
  9. package/runtime/lib/compat/initData.js +0 -2
  10. package/runtime/lib/compat/initData.js.map +1 -1
  11. package/runtime/lib/gesture/processGesture.js +3 -0
  12. package/runtime/lib/gesture/processGesture.js.map +1 -1
  13. package/runtime/lib/gesture/types.d.ts +2 -0
  14. package/runtime/lib/internal.d.ts +3 -2
  15. package/runtime/lib/internal.js +4 -3
  16. package/runtime/lib/internal.js.map +1 -1
  17. package/runtime/lib/legacy-react-runtime/index.js +4 -2
  18. package/runtime/lib/legacy-react-runtime/index.js.map +1 -1
  19. package/runtime/lib/lifecycle/destroy.js +1 -1
  20. package/runtime/lib/lifecycle/destroy.js.map +1 -1
  21. package/runtime/lib/lifecycle/{patchUpdate.d.ts → patch/commit.d.ts} +1 -3
  22. package/runtime/lib/lifecycle/{patchUpdate.js → patch/commit.js} +12 -56
  23. package/runtime/lib/lifecycle/patch/commit.js.map +1 -0
  24. package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -0
  25. package/runtime/lib/{snapshotPatchApply.js → lifecycle/patch/snapshotPatchApply.js} +1 -4
  26. package/runtime/lib/lifecycle/patch/snapshotPatchApply.js.map +1 -0
  27. package/runtime/lib/lifecycle/patch/updateMainThread.d.ts +3 -0
  28. package/runtime/lib/lifecycle/patch/updateMainThread.js +55 -0
  29. package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -0
  30. package/runtime/lib/lifecycle/reload.js +3 -1
  31. package/runtime/lib/lifecycle/reload.js.map +1 -1
  32. package/runtime/lib/lifecycle/render.js.map +1 -1
  33. package/runtime/lib/list.js +1 -1
  34. package/runtime/lib/list.js.map +1 -1
  35. package/runtime/lib/lynx/component.js +3 -3
  36. package/runtime/lib/lynx/component.js.map +1 -1
  37. package/runtime/lib/lynx/dynamic-js.js +0 -1
  38. package/runtime/lib/lynx/dynamic-js.js.map +1 -1
  39. package/runtime/lib/lynx/env.js +1 -2
  40. package/runtime/lib/lynx/env.js.map +1 -1
  41. package/runtime/lib/lynx/lazy-bundle.js.map +1 -1
  42. package/runtime/lib/lynx/performance.js +1 -1
  43. package/runtime/lib/lynx/performance.js.map +1 -1
  44. package/runtime/lib/lynx/tt.d.ts +1 -0
  45. package/runtime/lib/lynx/tt.js +46 -5
  46. package/runtime/lib/lynx/tt.js.map +1 -1
  47. package/runtime/lib/lynx-api.d.ts +3 -2
  48. package/runtime/lib/lynx-api.js +4 -4
  49. package/runtime/lib/lynx-api.js.map +1 -1
  50. package/runtime/lib/lynx.d.ts +0 -1
  51. package/runtime/lib/lynx.js +4 -46
  52. package/runtime/lib/lynx.js.map +1 -1
  53. package/runtime/lib/snapshot/ref.d.ts +2 -2
  54. package/runtime/lib/snapshot/ref.js +6 -7
  55. package/runtime/lib/snapshot/ref.js.map +1 -1
  56. package/runtime/lib/snapshot.js +1 -1
  57. package/runtime/lib/snapshot.js.map +1 -1
  58. package/runtime/lib/worklet/ctx.js +5 -5
  59. package/runtime/lib/worklet/ctx.js.map +1 -1
  60. package/runtime/lib/worklet/destroy.d.ts +2 -0
  61. package/runtime/lib/worklet/destroy.js +13 -0
  62. package/runtime/lib/worklet/destroy.js.map +1 -0
  63. package/runtime/lib/worklet/functionCall.d.ts +1 -0
  64. package/runtime/lib/worklet/functionCall.js +33 -0
  65. package/runtime/lib/worklet/functionCall.js.map +1 -0
  66. package/runtime/lib/worklet/functionality.d.ts +2 -1
  67. package/runtime/lib/worklet/functionality.js +21 -2
  68. package/runtime/lib/worklet/functionality.js.map +1 -1
  69. package/runtime/lib/worklet/hmr.js +1 -1
  70. package/runtime/lib/worklet/hmr.js.map +1 -1
  71. package/runtime/lib/worklet/runOnBackground.d.ts +20 -0
  72. package/runtime/lib/worklet/runOnBackground.js +105 -0
  73. package/runtime/lib/worklet/runOnBackground.js.map +1 -0
  74. package/runtime/lib/worklet/runOnMainThread.d.ts +19 -0
  75. package/runtime/lib/worklet/runOnMainThread.js +45 -0
  76. package/runtime/lib/worklet/runOnMainThread.js.map +1 -0
  77. package/runtime/lib/worklet/transformToWorklet.d.ts +1 -0
  78. package/runtime/lib/worklet/transformToWorklet.js +21 -0
  79. package/runtime/lib/worklet/transformToWorklet.js.map +1 -0
  80. package/runtime/lib/worklet/workletRef.js +3 -4
  81. package/runtime/lib/worklet/workletRef.js.map +1 -1
  82. package/runtime/lib/worklet/workletRefPool.d.ts +1 -2
  83. package/runtime/lib/worklet/workletRefPool.js +14 -11
  84. package/runtime/lib/worklet/workletRefPool.js.map +1 -1
  85. package/runtime/src/backgroundSnapshot.ts +3 -3
  86. package/runtime/src/compat/initData.ts +5 -6
  87. package/runtime/src/gesture/processGesture.ts +4 -0
  88. package/runtime/src/gesture/types.ts +2 -0
  89. package/runtime/src/internal.ts +5 -3
  90. package/runtime/src/legacy-react-runtime/index.ts +4 -2
  91. package/runtime/src/lifecycle/destroy.ts +1 -1
  92. package/runtime/src/lifecycle/{patchUpdate.ts → patch/commit.ts} +18 -71
  93. package/runtime/src/{snapshotPatchApply.ts → lifecycle/patch/snapshotPatchApply.ts} +2 -2
  94. package/runtime/src/lifecycle/patch/updateMainThread.ts +69 -0
  95. package/runtime/src/lifecycle/reload.ts +3 -1
  96. package/runtime/src/lifecycle/render.ts +1 -1
  97. package/runtime/src/list.ts +1 -1
  98. package/runtime/src/lynx/component.ts +3 -3
  99. package/runtime/src/lynx/dynamic-js.ts +2 -3
  100. package/runtime/src/lynx/env.ts +2 -2
  101. package/runtime/src/lynx/lazy-bundle.ts +1 -1
  102. package/runtime/src/lynx/performance.ts +3 -2
  103. package/runtime/src/lynx/tt.ts +56 -7
  104. package/runtime/src/lynx-api.ts +6 -5
  105. package/runtime/src/lynx.ts +5 -55
  106. package/runtime/src/snapshot/ref.ts +6 -9
  107. package/runtime/src/snapshot.ts +1 -1
  108. package/runtime/src/worklet/ctx.ts +5 -5
  109. package/runtime/src/worklet/destroy.ts +16 -0
  110. package/runtime/src/worklet/functionCall.ts +42 -0
  111. package/runtime/src/worklet/functionality.ts +25 -2
  112. package/runtime/src/worklet/hmr.ts +1 -1
  113. package/runtime/src/worklet/runOnBackground.ts +125 -0
  114. package/runtime/src/worklet/runOnMainThread.ts +50 -0
  115. package/runtime/src/worklet/transformToWorklet.ts +26 -0
  116. package/runtime/src/worklet/workletRef.ts +4 -4
  117. package/runtime/src/worklet/workletRefPool.ts +16 -12
  118. package/transform/dist/wasm.cjs +1 -1
  119. package/transform/index.d.ts +5 -1
  120. package/worklet-runtime/dist/dev.js +10 -3
  121. package/worklet-runtime/dist/dev.js.map +2 -2
  122. package/worklet-runtime/dist/main.js +10 -3
  123. package/worklet-runtime/dist/main.js.map +2 -2
  124. package/worklet-runtime/lib/bindings/events.d.ts +12 -1
  125. package/worklet-runtime/lib/bindings/events.js +1 -0
  126. package/worklet-runtime/lib/bindings/events.js.map +1 -1
  127. package/worklet-runtime/lib/bindings/index.d.ts +1 -1
  128. package/worklet-runtime/lib/bindings/index.js.map +1 -1
  129. package/worklet-runtime/lib/bindings/types.d.ts +1 -1
  130. package/worklet-runtime/lib/global.d.ts +1 -1
  131. package/worklet-runtime/lib/jsFunctionLifecycle.d.ts +2 -2
  132. package/worklet-runtime/lib/jsFunctionLifecycle.js +2 -2
  133. package/worklet-runtime/lib/jsFunctionLifecycle.js.map +1 -1
  134. package/worklet-runtime/lib/listeners.js +9 -2
  135. package/worklet-runtime/lib/listeners.js.map +1 -1
  136. package/worklet-runtime/lib/workletRuntime.js +2 -2
  137. package/worklet-runtime/lib/workletRuntime.js.map +1 -1
  138. package/runtime/lib/lifecycle/patchUpdate.js.map +0 -1
  139. package/runtime/lib/snapshotPatch.js.map +0 -1
  140. package/runtime/lib/snapshotPatchApply.js.map +0 -1
  141. package/runtime/lib/worklet/jsImpl.d.ts +0 -11
  142. package/runtime/lib/worklet/jsImpl.js +0 -68
  143. package/runtime/lib/worklet/jsImpl.js.map +0 -1
  144. package/runtime/lib/worklet/runWorklet.d.ts +0 -14
  145. package/runtime/lib/worklet/runWorklet.js +0 -82
  146. package/runtime/lib/worklet/runWorklet.js.map +0 -1
  147. package/runtime/src/worklet/jsImpl.ts +0 -86
  148. package/runtime/src/worklet/runWorklet.ts +0 -88
  149. /package/runtime/lib/{snapshotPatch.d.ts → lifecycle/patch/snapshotPatch.d.ts} +0 -0
  150. /package/runtime/lib/{snapshotPatch.js → lifecycle/patch/snapshotPatch.js} +0 -0
  151. /package/runtime/lib/{snapshotPatchApply.d.ts → lifecycle/patch/snapshotPatchApply.d.ts} +0 -0
  152. /package/runtime/src/{snapshotPatch.ts → lifecycle/patch/snapshotPatch.ts} +0 -0
@@ -17,6 +17,10 @@ function getGestureInfo(gesture: BaseGesture, dom: FiberElement) {
17
17
  } as GestureConfig;
18
18
  const baseGesture = gesture;
19
19
 
20
+ if (baseGesture.config) {
21
+ config.config = baseGesture.config;
22
+ }
23
+
20
24
  for (
21
25
  const key of Object.keys(baseGesture.callbacks) as Array<
22
26
  keyof BaseGesture['callbacks']
@@ -29,6 +29,7 @@ export interface BaseGesture extends GestureKind {
29
29
  waitFor: BaseGesture[];
30
30
  simultaneousWith: BaseGesture[];
31
31
  continueWith: BaseGesture[];
32
+ config?: Record<string, unknown>;
32
33
  }
33
34
 
34
35
  export interface GestureConfig {
@@ -36,4 +37,5 @@ export interface GestureConfig {
36
37
  name: string;
37
38
  callback: Worklet;
38
39
  }[];
40
+ config?: Record<string, unknown>;
39
41
  }
@@ -5,12 +5,14 @@
5
5
  import { Suspense, createElement, lazy } from 'preact/compat';
6
6
  import type { FC } from 'react';
7
7
 
8
+ import './lynx.js';
9
+
8
10
  import { factory as factory2 } from './compat/componentIs.js';
9
11
  import { useMemo } from './hooks/react.js';
10
12
  import { snapshotCreateList } from './list.js';
11
13
  import { loadLazyBundle } from './lynx/lazy-bundle.js';
12
14
  import { __root } from './root.js';
13
- import { DynamicPartType, SnapshotInstance, snapshotManager, __page, __pageId, createSnapshot } from './snapshot.js';
15
+ import { DynamicPartType, SnapshotInstance, __page, __pageId, createSnapshot, snapshotManager } from './snapshot.js';
14
16
 
15
17
  export { __page, __pageId, __root };
16
18
 
@@ -47,14 +49,14 @@ export { wrapWithLynxComponent } from './compat/lynxComponent.js';
47
49
  * @internal a polyfill for <component is=? />
48
50
  */
49
51
  export const __ComponentIsPolyfill: FC<{ is: string }> = /* @__PURE__ */ factory2(
50
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
52
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
51
53
  { Suspense, lazy, createElement, useMemo } as any,
52
54
  loadLazyBundle,
53
55
  );
54
56
 
55
57
  export { loadLazyBundle } from './lynx/lazy-bundle.js';
56
58
 
57
- export { transformToWorklet } from './worklet/runWorklet.js';
59
+ export { transformToWorklet } from './worklet/transformToWorklet.js';
58
60
  export { registerWorkletOnBackground } from './worklet/hmr.js';
59
61
 
60
62
  export { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings';
@@ -1,14 +1,14 @@
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 { createContext } from 'preact';
4
+ import { createContext, createRef } from 'preact';
5
5
  import { lazy } from 'preact/compat';
6
6
 
7
7
  import {
8
8
  ComponentFromReactRuntime as Component,
9
9
  ComponentFromReactRuntime as PureComponent,
10
10
  } from '../compat/lynxComponent.js';
11
- import { useCallback, useEffect, useMemo, useReducer, useState } from '../hooks/react.js';
11
+ import { useCallback, useEffect, useMemo, useReducer, useState, useRef } from '../hooks/react.js';
12
12
 
13
13
  /* v8 ignore next 3 */
14
14
  function __runInJS<T>(value: T): T | undefined | null {
@@ -30,9 +30,11 @@ export default {
30
30
  Component,
31
31
  PureComponent,
32
32
  createContext,
33
+ createRef,
33
34
  lazy,
34
35
  useState,
35
36
  useReducer,
37
+ useRef,
36
38
  useEffect,
37
39
  useMemo,
38
40
  useCallback,
@@ -4,7 +4,7 @@
4
4
  import { render } from 'preact';
5
5
 
6
6
  import { __root } from '../root.js';
7
- import { globalCommitTaskMap } from './patchUpdate.js';
7
+ import { globalCommitTaskMap } from './patch/commit.js';
8
8
 
9
9
  function destroyBackground(): void {
10
10
  if (__PROFILE__) {
@@ -1,31 +1,27 @@
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 { options } from 'preact';
5
4
  import type { VNode } from 'preact';
5
+ import { options } from 'preact';
6
6
  import type { Component } from 'preact/compat';
7
7
 
8
- import { clearDelayedWorklets, updateWorkletRefInitValueChanges } from '@lynx-js/react/worklet-runtime/bindings';
9
-
10
- import { LifecycleConstant } from '../lifecycleConstant.js';
11
- import { __pendingListUpdates } from '../list.js';
12
- import { runDelayedUnmounts, takeDelayedUnmounts } from './delayUnmount.js';
13
- import { getReloadVersion } from './pass.js';
8
+ import type { SnapshotPatch } from './snapshotPatch.js';
9
+ import { takeGlobalSnapshotPatch } from './snapshotPatch.js';
10
+ import { LifecycleConstant } from '../../lifecycleConstant.js';
14
11
  import {
15
12
  PerformanceTimingKeys,
16
13
  globalPipelineOptions,
17
14
  markTiming,
18
15
  markTimingLegacy,
19
16
  setPipeline,
20
- } from '../lynx/performance.js';
21
- import { CATCH_ERROR, COMMIT, RENDER_CALLBACKS, VNODE } from '../renderToOpcodes/constants.js';
22
- import { takeGlobalRefPatchMap, updateBackgroundRefs } from '../snapshot/ref.js';
23
- import { __page, backgroundSnapshotInstanceManager } from '../snapshot.js';
24
- import { takeGlobalSnapshotPatch } from '../snapshotPatch.js';
25
- import type { SnapshotPatch } from '../snapshotPatch.js';
26
- import { snapshotPatchApply } from '../snapshotPatchApply.js';
27
- import { isEmptyObject } from '../utils.js';
28
- import { takeWorkletRefInitValuePatch } from '../worklet/workletRefPool.js';
17
+ } from '../../lynx/performance.js';
18
+ import { CATCH_ERROR, COMMIT, RENDER_CALLBACKS, VNODE } from '../../renderToOpcodes/constants.js';
19
+ import { updateBackgroundRefs } from '../../snapshot/ref.js';
20
+ import { backgroundSnapshotInstanceManager } from '../../snapshot.js';
21
+ import { isEmptyObject } from '../../utils.js';
22
+ import { takeWorkletRefInitValuePatch } from '../../worklet/workletRefPool.js';
23
+ import { runDelayedUnmounts, takeDelayedUnmounts } from '../delayUnmount.js';
24
+ import { getReloadVersion } from '../pass.js';
29
25
 
30
26
  let globalFlushOptions: FlushOptions = {};
31
27
 
@@ -47,48 +43,6 @@ interface PatchOptions {
47
43
  isHydration?: boolean;
48
44
  }
49
45
 
50
- function injectUpdatePatch(): void {
51
- function updatePatch(
52
- { data, patchOptions }: {
53
- data: string;
54
- patchOptions: PatchOptions;
55
- },
56
- ): void {
57
- if ((patchOptions.reloadVersion ?? 0) < getReloadVersion()) {
58
- return;
59
- }
60
-
61
- setPipeline(patchOptions.pipelineOptions);
62
- markTiming(PerformanceTimingKeys.parse_changes_start);
63
- let { snapshotPatch, workletRefInitValuePatch, flushOptions } = JSON.parse(data) as Patch;
64
- markTiming(PerformanceTimingKeys.parse_changes_end);
65
-
66
- markTiming(PerformanceTimingKeys.patch_changes_start);
67
- updateWorkletRefInitValueChanges(workletRefInitValuePatch);
68
- __pendingListUpdates.clear();
69
- if (snapshotPatch) {
70
- snapshotPatchApply(snapshotPatch);
71
- }
72
- __pendingListUpdates.flush();
73
- // console.debug('********** Lepus updatePatch:');
74
- // printSnapshotInstance(snapshotInstanceManager.values.get(-1)!);
75
-
76
- commitMainThreadPatchUpdate(patchOptions.commitTaskId);
77
- if (patchOptions.isHydration) {
78
- clearDelayedWorklets();
79
- }
80
- markTiming(PerformanceTimingKeys.patch_changes_end);
81
- flushOptions ||= {};
82
- if (patchOptions.pipelineOptions) {
83
- flushOptions.pipelineOptions = patchOptions.pipelineOptions;
84
- }
85
- // TODO: triggerDataUpdated?
86
- __FlushElementTree(__page, flushOptions);
87
- }
88
-
89
- Object.assign(globalThis, { [LifecycleConstant.patchUpdate]: updatePatch });
90
- }
91
-
92
46
  function replaceCommitHook(): void {
93
47
  const oldCommit = options[COMMIT];
94
48
  options[COMMIT] = async (vnode: VNode, commitQueue: any[]) => {
@@ -204,13 +158,6 @@ function commitPatchUpdate(data: Patch, patchOptions: PatchOptions): Promise<voi
204
158
  });
205
159
  }
206
160
 
207
- function commitMainThreadPatchUpdate(commitTaskId?: number): void {
208
- const refPatch = takeGlobalRefPatchMap();
209
- if (!isEmptyObject(refPatch)) {
210
- __OnLifecycleEvent([LifecycleConstant.ref, { commitTaskId, refPatch: JSON.stringify(refPatch) }]);
211
- }
212
- }
213
-
214
161
  function genCommitTaskId(): number {
215
162
  return nextCommitTaskId++;
216
163
  }
@@ -227,14 +174,14 @@ function replaceRequestAnimationFrame(): void {
227
174
  * @internal
228
175
  */
229
176
  export {
230
- injectUpdatePatch,
231
177
  commitPatchUpdate,
232
- replaceCommitHook,
233
178
  genCommitTaskId,
234
- commitMainThreadPatchUpdate,
235
- replaceRequestAnimationFrame,
236
- globalFlushOptions,
237
- globalCommitTaskMap,
238
179
  globalBackgroundSnapshotInstancesToRemove,
180
+ globalCommitTaskMap,
181
+ globalFlushOptions,
239
182
  nextCommitTaskId,
183
+ replaceCommitHook,
184
+ replaceRequestAnimationFrame,
185
+ type PatchOptions,
186
+ type Patch,
240
187
  };
@@ -1,9 +1,9 @@
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 { createSnapshot, SnapshotInstance, snapshotInstanceManager, snapshotManager } from './snapshot.js';
5
4
  import type { SnapshotPatch } from './snapshotPatch.js';
6
5
  import { SnapshotOperation } from './snapshotPatch.js';
6
+ import { SnapshotInstance, createSnapshot, snapshotInstanceManager, snapshotManager } from '../../snapshot.js';
7
7
 
8
8
  function reportCtxNotFound(): void {
9
9
  lynx.reportError(new Error(`snapshotPatchApply failed: ctx not found`));
@@ -25,7 +25,7 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
25
25
  const beforeId = snapshotPatch[++i];
26
26
  const parent = snapshotInstanceManager.values.get(parentId);
27
27
  const child = snapshotInstanceManager.values.get(childId);
28
- const existingNode = snapshotInstanceManager.values.get(beforeId!);
28
+ const existingNode = snapshotInstanceManager.values.get(beforeId);
29
29
  if (!parent || !child) {
30
30
  reportCtxNotFound();
31
31
  } else {
@@ -0,0 +1,69 @@
1
+ // Copyright 2025 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 { clearDelayedWorklets, updateWorkletRefInitValueChanges } from '@lynx-js/react/worklet-runtime/bindings';
6
+
7
+ import { snapshotPatchApply } from './snapshotPatchApply.js';
8
+ import { LifecycleConstant } from '../../lifecycleConstant.js';
9
+ import { __pendingListUpdates } from '../../list.js';
10
+ import { PerformanceTimingKeys, markTiming, setPipeline } from '../../lynx/performance.js';
11
+ import { takeGlobalRefPatchMap } from '../../snapshot/ref.js';
12
+ import { __page } from '../../snapshot.js';
13
+ import { isEmptyObject } from '../../utils.js';
14
+ import { getReloadVersion } from '../pass.js';
15
+ import type { Patch, PatchOptions } from './commit.js';
16
+
17
+ function updateMainThread(
18
+ { data, patchOptions }: {
19
+ data: string;
20
+ patchOptions: PatchOptions;
21
+ },
22
+ ): void {
23
+ if ((patchOptions.reloadVersion ?? 0) < getReloadVersion()) {
24
+ return;
25
+ }
26
+
27
+ setPipeline(patchOptions.pipelineOptions);
28
+ markTiming(PerformanceTimingKeys.parse_changes_start);
29
+ let { snapshotPatch, workletRefInitValuePatch, flushOptions } = JSON.parse(data) as Patch;
30
+ markTiming(PerformanceTimingKeys.parse_changes_end);
31
+
32
+ markTiming(PerformanceTimingKeys.patch_changes_start);
33
+ updateWorkletRefInitValueChanges(workletRefInitValuePatch);
34
+ __pendingListUpdates.clear();
35
+ if (snapshotPatch) {
36
+ snapshotPatchApply(snapshotPatch);
37
+ }
38
+ __pendingListUpdates.flush();
39
+ // console.debug('********** Lepus updatePatch:');
40
+ // printSnapshotInstance(snapshotInstanceManager.values.get(-1)!);
41
+
42
+ commitMainThreadPatchUpdate(patchOptions.commitTaskId);
43
+ if (patchOptions.isHydration) {
44
+ clearDelayedWorklets();
45
+ }
46
+ markTiming(PerformanceTimingKeys.patch_changes_end);
47
+ flushOptions ||= {};
48
+ if (patchOptions.pipelineOptions) {
49
+ flushOptions.pipelineOptions = patchOptions.pipelineOptions;
50
+ }
51
+ // TODO: triggerDataUpdated?
52
+ __FlushElementTree(__page, flushOptions);
53
+ }
54
+
55
+ function injectUpdateMainThread(): void {
56
+ Object.assign(globalThis, { [LifecycleConstant.patchUpdate]: updateMainThread });
57
+ }
58
+
59
+ function commitMainThreadPatchUpdate(commitTaskId?: number): void {
60
+ const refPatch = takeGlobalRefPatchMap();
61
+ if (!isEmptyObject(refPatch)) {
62
+ __OnLifecycleEvent([LifecycleConstant.ref, { commitTaskId, refPatch: JSON.stringify(refPatch) }]);
63
+ }
64
+ }
65
+
66
+ /**
67
+ * @internal
68
+ */
69
+ export { injectUpdateMainThread, commitMainThreadPatchUpdate };
@@ -13,7 +13,8 @@ import { hydrate } from '../hydrate.js';
13
13
  import { LifecycleConstant } from '../lifecycleConstant.js';
14
14
  import { __pendingListUpdates } from '../list.js';
15
15
  import { takeGlobalRefPatchMap } from '../snapshot/ref.js';
16
- import { deinitGlobalSnapshotPatch } from '../snapshotPatch.js';
16
+ import { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';
17
+ import { destroyWorklet } from '../worklet/destroy.js';
17
18
 
18
19
  function reloadMainThread(data: any, options: UpdatePageOption): void {
19
20
  if (__PROFILE__) {
@@ -26,6 +27,7 @@ function reloadMainThread(data: any, options: UpdatePageOption): void {
26
27
  Object.assign(lynx.__initData, data);
27
28
  }
28
29
 
30
+ destroyWorklet();
29
31
  snapshotInstanceManager.clear();
30
32
  __pendingListUpdates.clear();
31
33
 
@@ -24,7 +24,7 @@ function renderMainThread(): void {
24
24
  // @ts-ignore
25
25
  opcodes = renderToString(__root.__jsx);
26
26
  } catch (e) {
27
- lynx.reportError(e);
27
+ lynx.reportError(e as Error);
28
28
  opcodes = [];
29
29
  } finally {
30
30
  if (__PROFILE__) {
@@ -2,7 +2,7 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { hydrate } from './hydrate.js';
5
- import { commitMainThreadPatchUpdate } from './lifecycle/patchUpdate.js';
5
+ import { commitMainThreadPatchUpdate } from './lifecycle/patch/updateMainThread.js';
6
6
  import type { SnapshotInstance } from './snapshot.js';
7
7
 
8
8
  export interface ListUpdateInfo {
@@ -4,7 +4,7 @@
4
4
  import { Component } from 'preact';
5
5
 
6
6
  import { PerfSpecificKey, PerformanceTimingKeys, markTimingLegacy } from './performance.js';
7
- import { globalFlushOptions } from '../lifecycle/patchUpdate.js';
7
+ import { globalFlushOptions } from '../lifecycle/patch/commit.js';
8
8
  import { NEXT_STATE } from '../renderToOpcodes/constants.js';
9
9
 
10
10
  if (__JS__) {
@@ -91,7 +91,7 @@ if (__JS__) {
91
91
 
92
92
  __Component.prototype.GlobalEventEmitter = lynxCoreInject.tt.GlobalEventEmitter;
93
93
 
94
- __Component.prototype.createSelectorQuery = function(...args: any[]) {
94
+ __Component.prototype.createSelectorQuery = function() {
95
95
  if (!__DISABLE_CREATE_SELECTOR_QUERY_INCOMPATIBLE_WARNING__) {
96
96
  lynx.reportError(
97
97
  new Error(
@@ -99,7 +99,7 @@ if (__JS__) {
99
99
  ),
100
100
  );
101
101
  }
102
- return lynx.createSelectorQuery(...args);
102
+ return lynx.createSelectorQuery();
103
103
  };
104
104
 
105
105
  const oldSetState = __Component.prototype.setState;
@@ -12,12 +12,11 @@ export function loadDynamicJS<T>(url: string): Promise<T> {
12
12
  return Promise.reject();
13
13
  }
14
14
  return new Promise((resolve, reject) => {
15
- // @ts-ignore
16
- lynx.requireModuleAsync(url, (err, data) => {
15
+ lynx.requireModuleAsync<T>(url, (err, data) => {
17
16
  if (err) {
18
17
  reject(err);
19
18
  } else {
20
- resolve(data);
19
+ resolve(data as T);
21
20
  }
22
21
  });
23
22
  });
@@ -94,8 +94,8 @@ export function setupLynxEnv(): void {
94
94
  }
95
95
  }
96
96
 
97
- if (processorName) {
98
- } else {
97
+ if (processorName) {}
98
+ else {
99
99
  hasDefaultDataProcessorExecuted = true;
100
100
  }
101
101
 
@@ -96,7 +96,7 @@ export function loadLazyBundle<
96
96
  if (typeof lynx.QueryComponent === 'function') {
97
97
  lynx.QueryComponent(source, callback);
98
98
  } else {
99
- lynx.getNativeLynx().QueryComponent(source, callback);
99
+ lynx.getNativeLynx().QueryComponent!(source, callback);
100
100
  }
101
101
  });
102
102
  }
@@ -3,8 +3,9 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  import { options } from 'preact';
5
5
  import type { VNode } from 'preact';
6
+
6
7
  import { DIFF } from '../renderToOpcodes/constants.js';
7
- import { __globalSnapshotPatch } from '../snapshotPatch.js';
8
+ import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';
8
9
 
9
10
  enum PerformanceTimingKeys {
10
11
  update_set_state_trigger,
@@ -61,7 +62,7 @@ function markTimingLegacy(key: PerformanceTimingKeys, timingFlag_?: string): voi
61
62
  break;
62
63
  }
63
64
  }
64
- lynx.getNativeApp().markTiming?.(timingFlag, PerformanceTimingKeys[key]);
65
+ lynx.getNativeApp().markTiming?.(timingFlag!, PerformanceTimingKeys[key]);
65
66
  }
66
67
 
67
68
  function beginPipeline(needTimestamps: boolean, timingFlag?: string): void {
@@ -1,20 +1,69 @@
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 { render } from 'preact';
4
+ import { options, render } from 'preact';
5
+ import type { VNode } from 'preact';
5
6
 
6
7
  import { LifecycleConstant, NativeUpdateDataType } from '../lifecycleConstant.js';
7
8
  import { PerformanceTimingKeys, beginPipeline, markTiming } from './performance.js';
8
9
  import { BackgroundSnapshotInstance, hydrate } from '../backgroundSnapshot.js';
9
10
  import { destroyBackground } from '../lifecycle/destroy.js';
10
- import { commitPatchUpdate, genCommitTaskId, globalCommitTaskMap } from '../lifecycle/patchUpdate.js';
11
+ import { commitPatchUpdate, genCommitTaskId, globalCommitTaskMap } from '../lifecycle/patch/commit.js';
11
12
  import { reloadBackground } from '../lifecycle/reload.js';
12
- import { runWithForce } from '../lynx.js';
13
- import { CHILDREN } from '../renderToOpcodes/constants.js';
13
+ import { CHILDREN, COMPONENT, DIFF, DIFFED, FORCE } from '../renderToOpcodes/constants.js';
14
14
  import { __root } from '../root.js';
15
15
  import { globalRefsToSet, updateBackgroundRefs } from '../snapshot/ref.js';
16
16
  import { backgroundSnapshotInstanceManager } from '../snapshot.js';
17
- import { destroyWorklet } from '../worklet/jsImpl.js';
17
+ import { destroyWorklet } from '../worklet/destroy.js';
18
+
19
+ export function runWithForce(cb: () => void): void {
20
+ // save vnode and its `_component` in WeakMap
21
+ const m = new WeakMap<VNode, any>();
22
+
23
+ const oldDiff = options[DIFF];
24
+
25
+ options[DIFF] = (vnode: VNode) => {
26
+ if (oldDiff) {
27
+ oldDiff(vnode);
28
+ }
29
+
30
+ // when `options[DIFF]` is called, a newVnode is passed in
31
+ // so its `vnode[COMPONENT]` should be null,
32
+ // but it will be set later
33
+ Object.defineProperty(vnode, COMPONENT, {
34
+ configurable: true,
35
+ set(c) {
36
+ m.set(vnode, c);
37
+ if (c) {
38
+ c[FORCE] = true;
39
+ }
40
+ },
41
+ get() {
42
+ return m.get(vnode);
43
+ },
44
+ });
45
+ };
46
+
47
+ const oldDiffed = options[DIFFED];
48
+
49
+ options[DIFFED] = (vnode: VNode) => {
50
+ if (oldDiffed) {
51
+ oldDiffed(vnode);
52
+ }
53
+
54
+ // delete is a reverse operation of previous `Object.defineProperty`
55
+ delete vnode[COMPONENT];
56
+ // restore
57
+ vnode[COMPONENT] = m.get(vnode);
58
+ };
59
+
60
+ try {
61
+ cb();
62
+ } finally {
63
+ options[DIFF] = oldDiff as (vnode: VNode) => void;
64
+ options[DIFFED] = oldDiffed as (vnode: VNode) => void;
65
+ }
66
+ }
18
67
 
19
68
  function injectTt(): void {
20
69
  // @ts-ignore
@@ -76,7 +125,7 @@ async function OnLifecycleEvent([type, data]: [string, any]) {
76
125
  try {
77
126
  publishEvent([idStr, ...rest].join(':'), data);
78
127
  } catch (e) {
79
- lynx.reportError(e);
128
+ lynx.reportError(e as Error);
80
129
  }
81
130
  });
82
131
  delayedEvents.length = 0;
@@ -139,7 +188,7 @@ function flushDelayedLifecycleEvents(): void {
139
188
  try {
140
189
  OnLifecycleEvent(e);
141
190
  } catch (e) {
142
- lynx.reportError(e);
191
+ lynx.reportError(e as Error);
143
192
  }
144
193
  });
145
194
  delayedLifecycleEvents.length = 0;
@@ -7,9 +7,9 @@ import { useState } from 'preact/hooks';
7
7
  import type { Consumer, FC, ReactNode } from 'react';
8
8
 
9
9
  import { factory, withInitDataInState } from './compat/initData.js';
10
+ import { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';
10
11
  import { LifecycleConstant } from './lifecycleConstant.js';
11
12
  import { flushDelayedLifecycleEvents } from './lynx/tt.js';
12
- import { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';
13
13
  import { __root } from './root.js';
14
14
 
15
15
  /**
@@ -87,8 +87,8 @@ export const root: Root = {
87
87
  } else {
88
88
  __root.__jsx = jsx;
89
89
  render(jsx, __root as any);
90
- if (__FIRST_SCREEN_SYNC_TIMING__ === 'immediately') {
91
- } else {
90
+ if (__FIRST_SCREEN_SYNC_TIMING__ === 'immediately') {}
91
+ else {
92
92
  lynx.getNativeApp().callLepusMethod(LifecycleConstant.jsReady, {});
93
93
  }
94
94
 
@@ -366,9 +366,10 @@ export interface Lynx {
366
366
  * ```
367
367
  * @public
368
368
  */
369
- registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition) => void;
369
+ registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void;
370
370
  }
371
371
 
372
- export { runOnBackground, runOnMainThread } from './worklet/runWorklet.js';
372
+ export { runOnMainThread } from './worklet/runOnMainThread.js';
373
+ export { runOnBackground } from './worklet/runOnBackground.js';
373
374
  export { MainThreadRef, useMainThreadRef } from './worklet/workletRef.js';
374
375
  export { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';
@@ -2,81 +2,31 @@
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
  import { options } from 'preact';
5
- import type { VNode } from 'preact';
6
5
  // to make sure preact's hooks to register earlier than ours
7
6
  import './hooks/react.js';
8
7
 
9
8
  import { initProfileHook } from './debug/profile.js';
10
9
  import { document, setupBackgroundDocument } from './document.js';
11
10
  import { initDelayUnmount } from './lifecycle/delayUnmount.js';
12
- import { injectUpdatePatch, replaceCommitHook, replaceRequestAnimationFrame } from './lifecycle/patchUpdate.js';
11
+ import { replaceCommitHook, replaceRequestAnimationFrame } from './lifecycle/patch/commit.js';
12
+ import { injectUpdateMainThread } from './lifecycle/patch/updateMainThread.js';
13
13
  import { injectCalledByNative } from './lynx/calledByNative.js';
14
14
  import { setupLynxEnv } from './lynx/env.js';
15
15
  import { injectLepusMethods } from './lynx/injectLepusMethods.js';
16
16
  import { initTimingAPI } from './lynx/performance.js';
17
17
  import { injectTt } from './lynx/tt.js';
18
- import { COMPONENT, DIFF, DIFFED, FORCE } from './renderToOpcodes/constants.js';
19
18
 
20
19
  // @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature
21
20
  if (__LEPUS__ && typeof globalThis.processEvalResult === 'undefined') {
22
21
  // @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature
23
- globalThis.processEvalResult = <T>(result: (schema: string) => T, schema: string) => {
24
- return result(schema);
22
+ globalThis.processEvalResult = <T>(result: ((schema: string) => T) | undefined, schema: string) => {
23
+ return result?.(schema);
25
24
  };
26
25
  }
27
26
 
28
- export function runWithForce(cb: () => void): void {
29
- // save vnode and its `_component` in WeakMap
30
- const m = new WeakMap<VNode, any>();
31
-
32
- const oldDiff = options[DIFF];
33
-
34
- options[DIFF] = (vnode: VNode) => {
35
- if (oldDiff) {
36
- oldDiff(vnode);
37
- }
38
-
39
- // when `options[DIFF]` is called, a newVnode is passed in
40
- // so its `vnode[COMPONENT]` should be null,
41
- // but it will be set later
42
- Object.defineProperty(vnode, COMPONENT, {
43
- configurable: true,
44
- set(c) {
45
- m.set(vnode, c);
46
- if (c) {
47
- c[FORCE] = true;
48
- }
49
- },
50
- get() {
51
- return m.get(vnode);
52
- },
53
- });
54
- };
55
-
56
- const oldDiffed = options[DIFFED];
57
-
58
- options[DIFFED] = (vnode: VNode) => {
59
- if (oldDiffed) {
60
- oldDiffed(vnode);
61
- }
62
-
63
- // delete is a reverse operation of previous `Object.defineProperty`
64
- delete vnode[COMPONENT];
65
- // restore
66
- vnode[COMPONENT] = m.get(vnode);
67
- };
68
-
69
- try {
70
- cb();
71
- } finally {
72
- options[DIFF] = oldDiff as (vnode: VNode) => void;
73
- options[DIFFED] = oldDiffed as (vnode: VNode) => void;
74
- }
75
- }
76
-
77
27
  if (__LEPUS__) {
78
28
  injectCalledByNative();
79
- injectUpdatePatch();
29
+ injectUpdateMainThread();
80
30
  if (__DEV__) {
81
31
  injectLepusMethods();
82
32
  }