@lynx-js/react 0.108.0 → 0.109.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/package.json +4 -4
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/jsx-dev-runtime/index.d.ts +13 -7
- package/runtime/jsx-runtime/index.d.ts +17 -7
- package/runtime/lib/gesture/processGesture.d.ts +2 -2
- package/runtime/lib/gesture/processGesture.js +14 -7
- package/runtime/lib/gesture/processGesture.js.map +1 -1
- package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.d.ts +2 -0
- package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.js +9 -0
- package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.js.map +1 -0
- package/runtime/lib/lifecycle/patch/snapshotPatchApply.js +2 -2
- package/runtime/lib/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/lifecycle/patch/updateMainThread.js +4 -3
- package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/lifecycle/reload.js +2 -0
- package/runtime/lib/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/gesture.d.ts +1 -1
- package/runtime/lib/snapshot/gesture.js +4 -3
- package/runtime/lib/snapshot/gesture.js.map +1 -1
- package/runtime/lib/snapshot/ref.js.map +1 -1
- package/runtime/lib/snapshot/spread.d.ts +0 -6
- package/runtime/lib/snapshot/spread.js +4 -10
- package/runtime/lib/snapshot/spread.js.map +1 -1
- package/runtime/lib/snapshot/workletEvent.d.ts +2 -1
- package/runtime/lib/snapshot/workletEvent.js +4 -3
- package/runtime/lib/snapshot/workletEvent.js.map +1 -1
- package/runtime/lib/snapshot/workletRef.d.ts +4 -4
- package/runtime/lib/snapshot/workletRef.js +6 -4
- package/runtime/lib/snapshot/workletRef.js.map +1 -1
- package/runtime/lib/snapshot.d.ts +1 -0
- package/runtime/lib/snapshot.js +5 -4
- package/runtime/lib/snapshot.js.map +1 -1
- package/runtime/lib/worklet/runOnBackground.js +21 -12
- package/runtime/lib/worklet/runOnBackground.js.map +1 -1
- package/runtime/lib/worklet/workletRef.d.ts +1 -0
- package/runtime/lib/worklet/workletRef.js +14 -12
- package/runtime/lib/worklet/workletRef.js.map +1 -1
- package/runtime/src/gesture/processGesture.ts +23 -15
- package/runtime/src/lifecycle/patch/isMainThreadHydrationFinished.ts +10 -0
- package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +8 -2
- package/runtime/src/lifecycle/patch/updateMainThread.ts +4 -3
- package/runtime/src/lifecycle/reload.ts +2 -0
- package/runtime/src/snapshot/gesture.ts +6 -4
- package/runtime/src/snapshot/ref.ts +2 -2
- package/runtime/src/snapshot/spread.ts +15 -5
- package/runtime/src/snapshot/workletEvent.ts +5 -3
- package/runtime/src/snapshot/workletRef.ts +17 -18
- package/runtime/src/snapshot.ts +6 -4
- package/runtime/src/worklet/runOnBackground.ts +37 -15
- package/runtime/src/worklet/workletRef.ts +15 -12
- package/testing-library/dist/vitest-global-setup.js +7 -0
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +443 -14
- package/types/react.d.ts +1 -1
- package/worklet-runtime/dist/dev.js +133 -33
- package/worklet-runtime/dist/dev.js.map +4 -4
- package/worklet-runtime/dist/main.js +133 -33
- package/worklet-runtime/dist/main.js.map +4 -4
- package/worklet-runtime/lib/api/element.d.ts +3 -3
- package/worklet-runtime/lib/api/element.js +3 -3
- package/worklet-runtime/lib/api/element.js.map +1 -1
- package/worklet-runtime/lib/api/lepusQuerySelector.js +1 -3
- package/worklet-runtime/lib/api/lepusQuerySelector.js.map +1 -1
- package/worklet-runtime/lib/api/lynxApi.js +10 -10
- package/worklet-runtime/lib/api/lynxApi.js.map +1 -1
- package/worklet-runtime/lib/bindings/bindings.d.ts +1 -1
- package/worklet-runtime/lib/bindings/bindings.js +21 -8
- package/worklet-runtime/lib/bindings/bindings.js.map +1 -1
- package/worklet-runtime/lib/bindings/events.d.ts +4 -1
- package/worklet-runtime/lib/bindings/events.js.map +1 -1
- package/worklet-runtime/lib/bindings/index.d.ts +1 -1
- package/worklet-runtime/lib/bindings/index.js +1 -1
- package/worklet-runtime/lib/bindings/index.js.map +1 -1
- package/worklet-runtime/lib/bindings/loadRuntime.js +0 -2
- package/worklet-runtime/lib/bindings/loadRuntime.js.map +1 -1
- package/worklet-runtime/lib/bindings/types.d.ts +15 -5
- package/worklet-runtime/lib/bindings/types.js +3 -0
- package/worklet-runtime/lib/bindings/types.js.map +1 -1
- package/worklet-runtime/lib/delayRunOnBackground.d.ts +12 -0
- package/worklet-runtime/lib/delayRunOnBackground.js +23 -0
- package/worklet-runtime/lib/delayRunOnBackground.js.map +1 -0
- package/worklet-runtime/lib/delayWorkletEvent.js +2 -2
- package/worklet-runtime/lib/delayWorkletEvent.js.map +1 -1
- package/worklet-runtime/lib/global.d.ts +6 -3
- package/worklet-runtime/lib/hydrate.d.ts +11 -0
- package/worklet-runtime/lib/hydrate.js +86 -0
- package/worklet-runtime/lib/hydrate.js.map +1 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.js +2 -2
- package/worklet-runtime/lib/jsFunctionLifecycle.js.map +1 -1
- package/worklet-runtime/lib/listeners.js.map +1 -1
- package/worklet-runtime/lib/utils/profile.d.ts +1 -1
- package/worklet-runtime/lib/utils/version.js +1 -1
- package/worklet-runtime/lib/workletRef.d.ts +6 -3
- package/worklet-runtime/lib/workletRef.js +33 -6
- package/worklet-runtime/lib/workletRef.js.map +1 -1
- package/worklet-runtime/lib/workletRuntime.js +12 -14
- package/worklet-runtime/lib/workletRuntime.js.map +1 -1
|
@@ -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 {
|
|
6
|
-
|
|
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:
|
|
112
|
+
return async (...params: ClosureValueType[]): Promise<R> => {
|
|
108
113
|
return new Promise((resolve) => {
|
|
109
114
|
const resolveId = onFunctionCall(resolve);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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 };
|
|
@@ -9,13 +9,19 @@ import { WorkletEvents } from '@lynx-js/react/worklet-runtime/bindings';
|
|
|
9
9
|
import { addWorkletRefInitValue } from './workletRefPool.js';
|
|
10
10
|
import { useMemo } from '../hooks/react.js';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
// Split into two variables for testing purposes
|
|
13
|
+
let lastIdBG = 0;
|
|
14
|
+
let lastIdMT = 0;
|
|
15
|
+
|
|
16
|
+
export function clearWorkletRefLastIdForTesting(): void {
|
|
17
|
+
lastIdBG = lastIdMT = 0;
|
|
18
|
+
}
|
|
13
19
|
|
|
14
20
|
abstract class WorkletRef<T> {
|
|
15
21
|
/**
|
|
16
22
|
* @internal
|
|
17
23
|
*/
|
|
18
|
-
protected
|
|
24
|
+
protected _wvid: number;
|
|
19
25
|
/**
|
|
20
26
|
* @internal
|
|
21
27
|
*/
|
|
@@ -33,16 +39,13 @@ abstract class WorkletRef<T> {
|
|
|
33
39
|
* @internal
|
|
34
40
|
*/
|
|
35
41
|
protected constructor(initValue: T, type: string) {
|
|
42
|
+
this._initValue = initValue;
|
|
43
|
+
this._type = type;
|
|
36
44
|
if (__JS__) {
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
this._type = type;
|
|
40
|
-
addWorkletRefInitValue(this._id, initValue);
|
|
45
|
+
this._wvid = ++lastIdBG;
|
|
46
|
+
addWorkletRefInitValue(this._wvid, initValue);
|
|
41
47
|
} else {
|
|
42
|
-
|
|
43
|
-
// The real WorkletRef will be generated by the worklet runtime.
|
|
44
|
-
this._id = -1;
|
|
45
|
-
this._type = '__LEPUS__';
|
|
48
|
+
this._wvid = --lastIdMT;
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
|
|
@@ -72,7 +75,7 @@ abstract class WorkletRef<T> {
|
|
|
72
75
|
*/
|
|
73
76
|
toJSON(): { _wvid: WorkletRefImpl<T>['_wvid'] } {
|
|
74
77
|
return {
|
|
75
|
-
_wvid: this.
|
|
78
|
+
_wvid: this._wvid,
|
|
76
79
|
};
|
|
77
80
|
}
|
|
78
81
|
}
|
|
@@ -88,7 +91,7 @@ export class MainThreadRef<T> extends WorkletRef<T> {
|
|
|
88
91
|
constructor(initValue: T) {
|
|
89
92
|
super(initValue, 'main-thread');
|
|
90
93
|
if (__JS__) {
|
|
91
|
-
const id = this.
|
|
94
|
+
const id = this._wvid;
|
|
92
95
|
this._lifecycleObserver = lynx.getNativeApp().createJSObjectDestructionObserver?.(() => {
|
|
93
96
|
lynx.getCoreContext?.().dispatchEvent({
|
|
94
97
|
type: WorkletEvents.releaseWorkletRef,
|
|
@@ -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
|
};
|