@lynx-js/react 0.108.1 → 0.109.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/package.json +3 -3
  3. package/refresh/.turbo/turbo-build.log +1 -1
  4. package/runtime/jsx-dev-runtime/index.d.ts +13 -7
  5. package/runtime/jsx-runtime/index.d.ts +17 -7
  6. package/runtime/lib/gesture/processGesture.d.ts +2 -2
  7. package/runtime/lib/gesture/processGesture.js +14 -7
  8. package/runtime/lib/gesture/processGesture.js.map +1 -1
  9. package/runtime/lib/lifecycle/patch/snapshotPatchApply.js +2 -2
  10. package/runtime/lib/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  11. package/runtime/lib/list.js +2 -2
  12. package/runtime/lib/list.js.map +1 -1
  13. package/runtime/lib/lynx/calledByNative.js +1 -1
  14. package/runtime/lib/lynx/calledByNative.js.map +1 -1
  15. package/runtime/lib/snapshot/gesture.d.ts +1 -1
  16. package/runtime/lib/snapshot/gesture.js +4 -3
  17. package/runtime/lib/snapshot/gesture.js.map +1 -1
  18. package/runtime/lib/snapshot/workletEvent.d.ts +1 -1
  19. package/runtime/lib/snapshot/workletEvent.js +3 -2
  20. package/runtime/lib/snapshot/workletEvent.js.map +1 -1
  21. package/runtime/lib/snapshot/workletRef.js +4 -4
  22. package/runtime/lib/snapshot/workletRef.js.map +1 -1
  23. package/runtime/lib/snapshot.d.ts +1 -0
  24. package/runtime/lib/snapshot.js +5 -4
  25. package/runtime/lib/snapshot.js.map +1 -1
  26. package/runtime/lib/worklet/execMap.js +4 -3
  27. package/runtime/lib/worklet/execMap.js.map +1 -1
  28. package/runtime/lib/worklet/functionality.js +2 -8
  29. package/runtime/lib/worklet/functionality.js.map +1 -1
  30. package/runtime/lib/worklet/hmr.js.map +1 -1
  31. package/runtime/lib/worklet/indexMap.js +3 -0
  32. package/runtime/lib/worklet/indexMap.js.map +1 -1
  33. package/runtime/lib/worklet/runOnBackground.js +21 -12
  34. package/runtime/lib/worklet/runOnBackground.js.map +1 -1
  35. package/runtime/src/gesture/processGesture.ts +23 -15
  36. package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +8 -2
  37. package/runtime/src/list.ts +2 -2
  38. package/runtime/src/lynx/calledByNative.ts +1 -1
  39. package/runtime/src/snapshot/gesture.ts +6 -4
  40. package/runtime/src/snapshot/workletEvent.ts +3 -2
  41. package/runtime/src/snapshot/workletRef.ts +5 -5
  42. package/runtime/src/snapshot.ts +6 -4
  43. package/runtime/src/worklet/execMap.ts +4 -3
  44. package/runtime/src/worklet/functionality.ts +2 -8
  45. package/runtime/src/worklet/hmr.ts +5 -1
  46. package/runtime/src/worklet/indexMap.ts +4 -1
  47. package/runtime/src/worklet/runOnBackground.ts +37 -15
  48. package/testing-library/dist/vitest-global-setup.js +7 -0
  49. package/transform/dist/wasm.cjs +1 -2
  50. package/transform/index.d.ts +443 -14
  51. package/types/react.d.ts +1 -1
  52. package/worklet-runtime/dist/dev.js +137 -49
  53. package/worklet-runtime/dist/dev.js.map +4 -4
  54. package/worklet-runtime/dist/main.js +137 -49
  55. package/worklet-runtime/dist/main.js.map +4 -4
  56. package/worklet-runtime/lib/api/element.d.ts +3 -3
  57. package/worklet-runtime/lib/api/element.js +3 -3
  58. package/worklet-runtime/lib/api/element.js.map +1 -1
  59. package/worklet-runtime/lib/api/lepusQuerySelector.js +1 -3
  60. package/worklet-runtime/lib/api/lepusQuerySelector.js.map +1 -1
  61. package/worklet-runtime/lib/api/lynxApi.js +10 -10
  62. package/worklet-runtime/lib/api/lynxApi.js.map +1 -1
  63. package/worklet-runtime/lib/bindings/bindings.d.ts +1 -1
  64. package/worklet-runtime/lib/bindings/bindings.js +20 -7
  65. package/worklet-runtime/lib/bindings/bindings.js.map +1 -1
  66. package/worklet-runtime/lib/bindings/events.d.ts +4 -1
  67. package/worklet-runtime/lib/bindings/events.js.map +1 -1
  68. package/worklet-runtime/lib/bindings/index.d.ts +1 -1
  69. package/worklet-runtime/lib/bindings/index.js +1 -1
  70. package/worklet-runtime/lib/bindings/index.js.map +1 -1
  71. package/worklet-runtime/lib/bindings/loadRuntime.js +0 -2
  72. package/worklet-runtime/lib/bindings/loadRuntime.js.map +1 -1
  73. package/worklet-runtime/lib/bindings/types.d.ts +8 -2
  74. package/worklet-runtime/lib/delayRunOnBackground.d.ts +12 -0
  75. package/worklet-runtime/lib/delayRunOnBackground.js +23 -0
  76. package/worklet-runtime/lib/delayRunOnBackground.js.map +1 -0
  77. package/worklet-runtime/lib/delayWorkletEvent.js +2 -2
  78. package/worklet-runtime/lib/delayWorkletEvent.js.map +1 -1
  79. package/worklet-runtime/lib/global.d.ts +6 -3
  80. package/worklet-runtime/lib/hydrate.d.ts +11 -0
  81. package/worklet-runtime/lib/hydrate.js +86 -0
  82. package/worklet-runtime/lib/hydrate.js.map +1 -0
  83. package/worklet-runtime/lib/jsFunctionLifecycle.js +2 -2
  84. package/worklet-runtime/lib/jsFunctionLifecycle.js.map +1 -1
  85. package/worklet-runtime/lib/listeners.js.map +1 -1
  86. package/worklet-runtime/lib/utils/profile.d.ts +1 -1
  87. package/worklet-runtime/lib/utils/version.js +1 -1
  88. package/worklet-runtime/lib/workletRef.d.ts +6 -3
  89. package/worklet-runtime/lib/workletRef.js +33 -6
  90. package/worklet-runtime/lib/workletRef.js.map +1 -1
  91. package/worklet-runtime/lib/workletRuntime.js +13 -18
  92. package/worklet-runtime/lib/workletRuntime.js.map +1 -1
  93. package/worklet-runtime/lib/ctxTrace.d.ts +0 -8
  94. package/worklet-runtime/lib/ctxTrace.js +0 -13
  95. package/worklet-runtime/lib/ctxTrace.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"hmr.js","sourceRoot":"","sources":["../../src/worklet/hmr.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,+EAA+E;AAE/E,iEAAiE;AAEjE,qBAAqB;AACrB;;GAEG;AACH,mCAAmC;AACnC,0GAA0G;AAC1G,SAAS,2BAA2B,CAAC,KAAa,EAAE,KAAa,EAAE,GAAa;IAC9E,kCAAkC;IAClC,YAAY;IACZ,IAAI;IACJ,4BAA4B;IAC5B,+BAA+B;IAC/B,gCAAgC;IAChC,kDAAkD;IAClD,YAAY;IACZ,mFAAmF;IACnF,qBAAqB;IACrB,OAAO;IACP,IAAI;AACN,CAAC;AACD,oBAAoB;AAEpB,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
1
+ {"version":3,"file":"hmr.js","sourceRoot":"","sources":["../../src/worklet/hmr.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,+EAA+E;AAE/E,iEAAiE;AAEjE,qBAAqB;AACrB;;GAEG;AACH,mCAAmC;AACnC,0GAA0G;AAC1G,SAAS,2BAA2B,CAClC,KAAa,EACb,KAAa,EACb,GAAoC;IAEpC,kCAAkC;IAClC,YAAY;IACZ,IAAI;IACJ,4BAA4B;IAC5B,+BAA+B;IAC/B,gCAAgC;IAChC,kDAAkD;IAClD,YAAY;IACZ,mFAAmF;IACnF,qBAAqB;IACrB,OAAO;IACP,IAAI;AACN,CAAC;AACD,oBAAoB;AAEpB,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
@@ -1,3 +1,6 @@
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.
1
4
  class IndexMap {
2
5
  lastIndex = 0;
3
6
  indexMap = new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"indexMap.js","sourceRoot":"","sources":["../../src/worklet/indexMap.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ;IACF,SAAS,GAAG,CAAC,CAAC;IACd,QAAQ,GAAmB,IAAI,GAAG,EAAE,CAAC;IAExC,GAAG,CAAC,KAAQ;QACjB,MAAM,KAAK,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC;QAC/B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,GAAG,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAEM,MAAM,CAAC,KAAa;QACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;CACF;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"indexMap.js","sourceRoot":"","sources":["../../src/worklet/indexMap.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,MAAM,QAAQ;IACF,SAAS,GAAG,CAAC,CAAC;IACd,QAAQ,GAAmB,IAAI,GAAG,EAAa,CAAC;IAEnD,GAAG,CAAC,KAAQ;QACjB,MAAM,KAAK,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC;QAC/B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,GAAG,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAEM,MAAM,CAAC,KAAa;QACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;CACF;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -1,7 +1,7 @@
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 { WorkletEvents } from '@lynx-js/react/worklet-runtime/bindings';
4
+ import { WorkletEvents, delayRunOnBackground } from '@lynx-js/react/worklet-runtime/bindings';
5
5
  import { destroyTasks } from './destroy.js';
6
6
  import { WorkletExecIdMap } from './execMap.js';
7
7
  import { isRunOnBackgroundEnabled } from './functionality.js';
@@ -87,19 +87,28 @@ function runOnBackground(f) {
87
87
  return async (...params) => {
88
88
  return new Promise((resolve) => {
89
89
  const resolveId = onFunctionCall(resolve);
90
- lynx.getJSContext().dispatchEvent({
91
- type: WorkletEvents.runOnBackground,
92
- data: JSON.stringify({
93
- obj: {
94
- _jsFnId: obj._jsFnId,
95
- _execId: obj._execId,
96
- },
97
- params,
98
- resolveId,
99
- }),
100
- });
90
+ if (obj._isFirstScreen) {
91
+ delayRunOnBackground(obj, (fnId, execId) => {
92
+ dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId);
93
+ });
94
+ return;
95
+ }
96
+ dispatchRunBackgroundFunctionEvent(obj._jsFnId, params, obj._execId, resolveId);
101
97
  });
102
98
  };
103
99
  }
100
+ function dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId) {
101
+ lynx.getJSContext().dispatchEvent({
102
+ type: WorkletEvents.runOnBackground,
103
+ data: JSON.stringify({
104
+ obj: {
105
+ _jsFnId: fnId,
106
+ _execId: execId,
107
+ },
108
+ params,
109
+ resolveId,
110
+ }),
111
+ });
112
+ }
104
113
  export { registerWorkletCtx, runJSFunction, runOnBackground };
105
114
  //# sourceMappingURL=runOnBackground.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runOnBackground.js","sourceRoot":"","sources":["../../src/worklet/runOnBackground.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC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B,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC"}
@@ -1,17 +1,21 @@
1
- import {
2
- type GestureKind,
3
- GestureTypeInner,
4
- type ComposedGesture,
5
- type BaseGesture,
6
- type GestureConfig,
7
- } from './types.js';
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.
8
4
  import { onWorkletCtxUpdate } from '@lynx-js/react/worklet-runtime/bindings';
9
5
 
6
+ import { GestureTypeInner } from './types.js';
7
+ import type { BaseGesture, ComposedGesture, GestureConfig, GestureKind } from './types.js';
8
+
10
9
  function isSerializedGesture(gesture: GestureKind): boolean {
11
10
  return gesture.__isSerialized ?? false;
12
11
  }
13
12
 
14
- function getGestureInfo(gesture: BaseGesture, dom: FiberElement) {
13
+ function getGestureInfo(
14
+ gesture: BaseGesture,
15
+ oldGesture: BaseGesture | undefined,
16
+ isFirstScreen: boolean,
17
+ dom: FiberElement,
18
+ ) {
15
19
  const config = {
16
20
  callbacks: [],
17
21
  } as GestureConfig;
@@ -22,12 +26,11 @@ function getGestureInfo(gesture: BaseGesture, dom: FiberElement) {
22
26
  }
23
27
 
24
28
  for (
25
- const key of Object.keys(baseGesture.callbacks) as Array<
26
- keyof BaseGesture['callbacks']
27
- >
29
+ const key of Object.keys(baseGesture.callbacks)
28
30
  ) {
29
31
  const callback = baseGesture.callbacks[key]!;
30
- onWorkletCtxUpdate(callback, dom);
32
+ const oldCallback = oldGesture?.callbacks[key];
33
+ onWorkletCtxUpdate(callback, oldCallback, isFirstScreen, dom);
31
34
  config.callbacks.push({
32
35
  name: key,
33
36
  callback: callback,
@@ -49,6 +52,8 @@ function getGestureInfo(gesture: BaseGesture, dom: FiberElement) {
49
52
  export function processGesture(
50
53
  dom: FiberElement,
51
54
  gesture: GestureKind,
55
+ oldGesture: GestureKind | undefined,
56
+ isFirstScreen: boolean,
52
57
  gestureOptions?: {
53
58
  domSet: boolean;
54
59
  },
@@ -63,13 +68,16 @@ export function processGesture(
63
68
  }
64
69
 
65
70
  if (gesture.type === GestureTypeInner.COMPOSED) {
66
- for (const subGesture of (gesture as ComposedGesture).gestures) {
67
- processGesture(dom, subGesture, { domSet: true });
71
+ for (const [index, subGesture] of (gesture as ComposedGesture).gestures.entries()) {
72
+ processGesture(dom, subGesture, (oldGesture as ComposedGesture)?.gestures[index], isFirstScreen, {
73
+ domSet: true,
74
+ });
68
75
  }
69
76
  } else {
70
77
  const baseGesture = gesture as BaseGesture;
78
+ const oldBaseGesture = oldGesture as BaseGesture | undefined;
71
79
 
72
- const { config, relationMap } = getGestureInfo(baseGesture, dom);
80
+ const { config, relationMap } = getGestureInfo(baseGesture, oldBaseGesture, isFirstScreen, dom);
73
81
  __SetGestureDetector(
74
82
  dom,
75
83
  baseGesture.id,
@@ -13,7 +13,13 @@
13
13
  * order and with proper error handling.
14
14
  */
15
15
 
16
- import { SnapshotInstance, createSnapshot, snapshotInstanceManager, snapshotManager } from '../../snapshot.js';
16
+ import {
17
+ SnapshotInstance,
18
+ createSnapshot,
19
+ entryUniqID,
20
+ snapshotInstanceManager,
21
+ snapshotManager,
22
+ } from '../../snapshot.js';
17
23
  import type { SnapshotPatch } from './snapshotPatch.js';
18
24
  import { SnapshotOperation } from './snapshotPatch.js';
19
25
 
@@ -94,7 +100,7 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
94
100
  const cssId: number = snapshotPatch[++i] ?? 0;
95
101
  const entryName: string | undefined = snapshotPatch[++i];
96
102
 
97
- if (!snapshotManager.values.has(uniqID)) {
103
+ if (!snapshotManager.values.has(entryUniqID(uniqID, entryName))) {
98
104
  // HMR-related
99
105
  // Update the evaluated snapshots from JS.
100
106
  createSnapshot(
@@ -184,10 +184,10 @@ export class ListUpdateInfoRecording implements ListUpdateInfo {
184
184
  const elementIndex = this.list.__snapshot_def.slot[0]![1];
185
185
  const listElement = this.list.__elements![elementIndex]!;
186
186
 
187
- // `__GetAttributeByName` is avaiable since Lynx 2.14
187
+ // `__GetAttributeByName` is available since Lynx 2.14
188
188
  if (__GetAttributeByName(listElement, 'custom-list-name') === 'list-container') {
189
189
  // `updateAction` must be full (not incremental) when Lynx version <= 2.18 and
190
- // when `custom-list-name` is `list-container` (avaiable when Lynx version >= 2.14) is true,
190
+ // when `custom-list-name` is `list-container` (available when Lynx version >= 2.14) is true,
191
191
  updates.length = 0;
192
192
  this.list.childNodes.forEach((child, index) => {
193
193
  updates.push({
@@ -86,7 +86,7 @@ function renderPage(data: any): void {
86
86
  renderMainThread();
87
87
 
88
88
  // always call this before `__FlushElementTree`
89
- // (There is an implict `__FlushElementTree` in `renderPage`)
89
+ // (There is an implicit `__FlushElementTree` in `renderPage`)
90
90
  __pendingListUpdates.flush();
91
91
 
92
92
  if (__FIRST_SCREEN_SYNC_TIMING__ === 'immediately') {
@@ -1,10 +1,12 @@
1
- import { SnapshotInstance } from '../snapshot.js';
2
1
  import { processGesture } from '../gesture/processGesture.js';
2
+ import type { GestureKind } from '../gesture/types.js';
3
+ import { isMainThreadHydrationFinished } from '../lifecycle/patch/isMainThreadHydrationFinished.js';
4
+ import { SnapshotInstance } from '../snapshot.js';
3
5
 
4
6
  export function updateGesture(
5
7
  snapshot: SnapshotInstance,
6
8
  expIndex: number,
7
- _oldValue: any,
9
+ oldValue: any,
8
10
  elementIndex: number,
9
11
  workletType: string,
10
12
  ): void {
@@ -14,10 +16,10 @@ export function updateGesture(
14
16
  if (__PROFILE__) {
15
17
  console.profile('updateGesture');
16
18
  }
17
- const value = snapshot.__values![expIndex];
19
+ const value = snapshot.__values![expIndex] as GestureKind;
18
20
 
19
21
  if (workletType === 'main-thread') {
20
- processGesture(snapshot.__elements[elementIndex]!, value);
22
+ processGesture(snapshot.__elements[elementIndex]!, value, oldValue as GestureKind, !isMainThreadHydrationFinished);
21
23
  }
22
24
  if (__PROFILE__) {
23
25
  console.profileEnd();
@@ -5,11 +5,12 @@ import { onWorkletCtxUpdate } from '@lynx-js/react/worklet-runtime/bindings';
5
5
  import type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';
6
6
 
7
7
  import { SnapshotInstance } from '../snapshot.js';
8
+ import { isMainThreadHydrationFinished } from '../lifecycle/patch/isMainThreadHydrationFinished.js';
8
9
 
9
10
  function updateWorkletEvent(
10
11
  snapshot: SnapshotInstance,
11
12
  expIndex: number,
12
- _oldValue: Worklet,
13
+ oldValue: Worklet,
13
14
  elementIndex: number,
14
15
  workletType: string,
15
16
  eventType: string,
@@ -22,7 +23,7 @@ function updateWorkletEvent(
22
23
  value._workletType = workletType;
23
24
 
24
25
  if (workletType === 'main-thread') {
25
- onWorkletCtxUpdate(value, snapshot.__elements[elementIndex]!);
26
+ onWorkletCtxUpdate(value, oldValue, !isMainThreadHydrationFinished, snapshot.__elements[elementIndex]!);
26
27
  const event = {
27
28
  type: 'worklet',
28
29
  value,
@@ -2,12 +2,12 @@
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 { runWorkletCtx, updateWorkletRef as update } from '@lynx-js/react/worklet-runtime/bindings';
5
- import type { Element, Worklet, WorkletRefId, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';
5
+ import type { Element, Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';
6
6
 
7
7
  import type { SnapshotInstance } from '../snapshot.js';
8
8
 
9
9
  function workletUnRef(value: Worklet | WorkletRefImpl<Element>): void {
10
- if ('_wvid' in value && (value._wvid as WorkletRefId) > 0) {
10
+ if ('_wvid' in value) {
11
11
  update(value as WorkletRefImpl<Element>, null);
12
12
  } else if ('_wkltId' in value) {
13
13
  if (typeof value._unmount == 'function') {
@@ -38,14 +38,14 @@ function updateWorkletRef(
38
38
  if (value === null || value === undefined) {
39
39
  // do nothing
40
40
  } else if (value._wvid) {
41
- if ((value._wvid as WorkletRefId) > 0) {
42
- update(value as WorkletRefImpl<Element>, snapshot.__elements[elementIndex]!);
43
- }
41
+ update(value as WorkletRefImpl<Element>, snapshot.__elements[elementIndex]!);
44
42
  } else if ((value as Worklet)._wkltId) {
45
43
  (value as Worklet)._unmount = runWorkletCtx(value as Worklet, [{
46
44
  elementRefptr: (snapshot.__elements[elementIndex]!) as any,
47
45
  }]) as () => void;
46
+ /* v8 ignore next 3 */
48
47
  } else if (value._type === '__LEPUS__' || (value as Worklet)._lepusWorkletHash) {
48
+ // for pre-0.99 compatibility
49
49
  // During the initial render, we will not update the WorkletRef because the background thread is not ready yet.
50
50
  } else {
51
51
  throw new Error('MainThreadRef: main-thread:ref must be of type MainThreadRef or main-thread function.');
@@ -181,6 +181,10 @@ export const backgroundSnapshotInstanceManager: {
181
181
  },
182
182
  };
183
183
 
184
+ export function entryUniqID(uniqID: string, entryName?: string): string {
185
+ return entryName ? `${entryName}:${uniqID}` : uniqID;
186
+ }
187
+
184
188
  export function createSnapshot(
185
189
  uniqID: string,
186
190
  create: Snapshot['create'] | null,
@@ -194,7 +198,7 @@ export function createSnapshot(
194
198
  // `__globalSnapshotPatch` does not exist before hydration,
195
199
  // so the snapshot of the first screen will not be sent to the main thread.
196
200
  && __globalSnapshotPatch
197
- && !snapshotManager.values.has(uniqID)
201
+ && !snapshotManager.values.has(entryUniqID(uniqID, entryName))
198
202
  // `create` may be `null` when loading a lazy bundle after hydration.
199
203
  && create !== null
200
204
  ) {
@@ -215,9 +219,7 @@ export function createSnapshot(
215
219
  );
216
220
  }
217
221
 
218
- if (entryName) {
219
- uniqID = `${entryName}:${uniqID}`;
220
- }
222
+ uniqID = entryUniqID(uniqID, entryName);
221
223
 
222
224
  const s: Snapshot = { create, update, slot, cssId, entryName };
223
225
  snapshotManager.values.set(uniqID, s);
@@ -29,11 +29,12 @@ export class WorkletExecIdMap extends IndexMap<Worklet> {
29
29
  return undefined;
30
30
  }
31
31
 
32
- const f = (obj: any): JsFnHandle | undefined => {
33
- if (obj === null || typeof obj !== 'object') {
32
+ const f = (value: unknown): JsFnHandle | undefined => {
33
+ if (value === null || typeof value !== 'object') {
34
34
  return undefined;
35
35
  }
36
- if ('_jsFnId' in obj && obj._jsFnId === fnId) {
36
+ const obj = value as Record<string, unknown>;
37
+ if ('_jsFnId' in obj && obj['_jsFnId'] === fnId) {
37
38
  return obj as JsFnHandle;
38
39
  }
39
40
  for (const i in obj) {
@@ -11,20 +11,14 @@ let runOnBackgroundEnabled: boolean | undefined;
11
11
  * @internal
12
12
  */
13
13
  function isMtsEnabled(): boolean {
14
- if (mtsEnabled === undefined) {
15
- mtsEnabled = isSdkVersionGt(2, 13);
16
- }
17
- return mtsEnabled;
14
+ return mtsEnabled ??= isSdkVersionGt(2, 13);
18
15
  }
19
16
 
20
17
  /**
21
18
  * @internal
22
19
  */
23
20
  function isRunOnBackgroundEnabled(): boolean {
24
- if (runOnBackgroundEnabled === undefined) {
25
- runOnBackgroundEnabled = isSdkVersionGt(2, 15);
26
- }
27
- return runOnBackgroundEnabled;
21
+ return runOnBackgroundEnabled ??= isSdkVersionGt(2, 15);
28
22
  }
29
23
 
30
24
  function clearConfigCacheForTesting(): void {
@@ -11,7 +11,11 @@
11
11
  */
12
12
  // disable hmr until bugs are fixed
13
13
  // TODO: re-enable hmr or change a way to impl it; also need to fix the test case DEV_ONLY_RegisterWorklet
14
- function registerWorkletOnBackground(_type: string, _hash: string, _fn: Function) {
14
+ function registerWorkletOnBackground(
15
+ _type: string,
16
+ _hash: string,
17
+ _fn: (...args: unknown[]) => unknown,
18
+ ) {
15
19
  // if (workletHashSet.has(hash)) {
16
20
  // return;
17
21
  // }
@@ -1,6 +1,9 @@
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.
1
4
  class IndexMap<T> {
2
5
  protected lastIndex = 0;
3
- protected indexMap: Map<number, T> = new Map();
6
+ protected indexMap: Map<number, T> = new Map<number, T>();
4
7
 
5
8
  public add(value: T): number {
6
9
  const index = ++this.lastIndex;
@@ -2,8 +2,13 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
- import type { JsFnHandle, RunWorkletCtxRetData, Worklet } from '@lynx-js/react/worklet-runtime/bindings';
6
- import { WorkletEvents } from '@lynx-js/react/worklet-runtime/bindings';
5
+ import type {
6
+ ClosureValueType,
7
+ JsFnHandle,
8
+ RunWorkletCtxRetData,
9
+ Worklet,
10
+ } from '@lynx-js/react/worklet-runtime/bindings';
11
+ import { WorkletEvents, delayRunOnBackground } from '@lynx-js/react/worklet-runtime/bindings';
7
12
 
8
13
  import { destroyTasks } from './destroy.js';
9
14
  import { WorkletExecIdMap } from './execMap.js';
@@ -44,7 +49,7 @@ function init() {
44
49
  function runJSFunction(event: RuntimeProxy.Event): void {
45
50
  'background only';
46
51
  const data = JSON.parse(event.data as string) as RunOnBackgroundData;
47
- const obj = execIdMap!.findJsFnHandle(data.obj._execId!, data.obj._jsFnId);
52
+ const obj = execIdMap!.findJsFnHandle(data.obj._execId!, data.obj._jsFnId!);
48
53
  const f = obj?._fn;
49
54
  if (!f) {
50
55
  throw new Error('runOnBackground: JS function not found: ' + JSON.stringify(data.obj));
@@ -104,22 +109,39 @@ function runOnBackground<R, Fn extends (...args: any[]) => R>(f: Fn): (...args:
104
109
  if (obj._error) {
105
110
  throw new Error(obj._error);
106
111
  }
107
- return async (...params: any[]): Promise<R> => {
112
+ return async (...params: ClosureValueType[]): Promise<R> => {
108
113
  return new Promise((resolve) => {
109
114
  const resolveId = onFunctionCall(resolve);
110
- lynx.getJSContext!().dispatchEvent({
111
- type: WorkletEvents.runOnBackground,
112
- data: JSON.stringify({
113
- obj: {
114
- _jsFnId: obj._jsFnId,
115
- _execId: obj._execId!,
116
- },
117
- params,
118
- resolveId,
119
- } as RunOnBackgroundData),
120
- });
115
+
116
+ if (obj._isFirstScreen) {
117
+ delayRunOnBackground(obj, (fnId: number, execId: number) => {
118
+ dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId);
119
+ });
120
+ return;
121
+ }
122
+
123
+ dispatchRunBackgroundFunctionEvent(obj._jsFnId!, params, obj._execId!, resolveId);
121
124
  });
122
125
  };
123
126
  }
124
127
 
128
+ function dispatchRunBackgroundFunctionEvent(
129
+ fnId: number,
130
+ params: ClosureValueType[],
131
+ execId: number,
132
+ resolveId: number,
133
+ ): void {
134
+ lynx.getJSContext!().dispatchEvent({
135
+ type: WorkletEvents.runOnBackground,
136
+ data: JSON.stringify({
137
+ obj: {
138
+ _jsFnId: fnId,
139
+ _execId: execId,
140
+ },
141
+ params,
142
+ resolveId,
143
+ } as RunOnBackgroundData),
144
+ });
145
+ }
146
+
125
147
  export { registerWorkletCtx, runJSFunction, runOnBackground };
@@ -86,6 +86,13 @@ globalThis.onInjectBackgroundThreadGlobals = (target)=>{
86
86
  globalThis.lynxCoreInject = target.lynxCoreInject;
87
87
  (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_tt_js_37d9bcb1__.injectTt)();
88
88
  globalThis.lynxCoreInject = oldLynxCoreInject;
89
+ target.lynx.requireModuleAsync = async (url, callback)=>{
90
+ try {
91
+ callback(null, await __vite_ssr_dynamic_import__(url));
92
+ } catch (err) {
93
+ callback(err, null);
94
+ }
95
+ };
89
96
  (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_snapshotPatch_js_c1ebb33c__.deinitGlobalSnapshotPatch)();
90
97
  (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_commit_js_9adc7328__.clearCommitTaskId)();
91
98
  };