@lynx-js/react 0.108.1 → 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 +16 -0
- package/package.json +2 -2
- 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/snapshotPatchApply.js +2 -2
- package/runtime/lib/lifecycle/patch/snapshotPatchApply.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/workletEvent.d.ts +1 -1
- package/runtime/lib/snapshot/workletEvent.js +3 -2
- package/runtime/lib/snapshot/workletEvent.js.map +1 -1
- package/runtime/lib/snapshot/workletRef.js +4 -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/src/gesture/processGesture.ts +23 -15
- package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +8 -2
- package/runtime/src/snapshot/gesture.ts +6 -4
- package/runtime/src/snapshot/workletEvent.ts +3 -2
- package/runtime/src/snapshot/workletRef.ts +5 -5
- package/runtime/src/snapshot.ts +6 -4
- package/runtime/src/worklet/runOnBackground.ts +37 -15
- 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 +137 -49
- package/worklet-runtime/dist/dev.js.map +4 -4
- package/worklet-runtime/dist/main.js +137 -49
- 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 +20 -7
- 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 +8 -2
- 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 +13 -18
- package/worklet-runtime/lib/workletRuntime.js.map +1 -1
- package/worklet-runtime/lib/ctxTrace.d.ts +0 -8
- package/worklet-runtime/lib/ctxTrace.js +0 -13
- package/worklet-runtime/lib/ctxTrace.js.map +0 -1
|
@@ -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
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
|
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
|
-
|
|
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.');
|
package/runtime/src/snapshot.ts
CHANGED
|
@@ -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
|
-
|
|
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);
|
|
@@ -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 };
|
|
@@ -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
|
};
|