@lynx-js/react 0.108.0 → 0.108.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.
- package/CHANGELOG.md +6 -0
- package/package.json +3 -3
- package/refresh/.turbo/turbo-build.log +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/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/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 +1 -1
- package/runtime/lib/snapshot/workletEvent.js.map +1 -1
- package/runtime/lib/snapshot/workletRef.d.ts +4 -4
- package/runtime/lib/snapshot/workletRef.js +8 -6
- package/runtime/lib/snapshot/workletRef.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/lifecycle/patch/isMainThreadHydrationFinished.ts +10 -0
- package/runtime/src/lifecycle/patch/updateMainThread.ts +4 -3
- package/runtime/src/lifecycle/reload.ts +2 -0
- package/runtime/src/snapshot/ref.ts +2 -2
- package/runtime/src/snapshot/spread.ts +15 -5
- package/runtime/src/snapshot/workletEvent.ts +3 -2
- package/runtime/src/snapshot/workletRef.ts +18 -19
- package/runtime/src/worklet/workletRef.ts +15 -12
- package/transform/dist/wasm.cjs +1 -1
- package/worklet-runtime/dist/dev.js +25 -13
- package/worklet-runtime/dist/dev.js.map +3 -3
- package/worklet-runtime/dist/main.js +25 -13
- package/worklet-runtime/dist/main.js.map +3 -3
- package/worklet-runtime/lib/bindings/bindings.d.ts +1 -1
- package/worklet-runtime/lib/bindings/bindings.js +2 -2
- package/worklet-runtime/lib/bindings/bindings.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/types.d.ts +7 -3
- package/worklet-runtime/lib/bindings/types.js +3 -0
- package/worklet-runtime/lib/bindings/types.js.map +1 -1
- package/worklet-runtime/lib/ctxTrace.d.ts +8 -0
- package/worklet-runtime/lib/ctxTrace.js +13 -0
- package/worklet-runtime/lib/ctxTrace.js.map +1 -0
- package/worklet-runtime/lib/global.d.ts +3 -3
- package/worklet-runtime/lib/workletRuntime.js +11 -8
- package/worklet-runtime/lib/workletRuntime.js.map +1 -1
|
@@ -1,23 +1,19 @@
|
|
|
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 {
|
|
5
|
-
|
|
6
|
-
type WorkletRef,
|
|
7
|
-
runWorkletCtx,
|
|
8
|
-
updateWorkletRef as update,
|
|
9
|
-
} from '@lynx-js/react/worklet-runtime/bindings';
|
|
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';
|
|
10
6
|
|
|
11
|
-
import { SnapshotInstance } from '../snapshot.js';
|
|
7
|
+
import type { SnapshotInstance } from '../snapshot.js';
|
|
12
8
|
|
|
13
|
-
function workletUnRef(value: Worklet |
|
|
14
|
-
if ('_wvid' in value) {
|
|
15
|
-
update(value as
|
|
9
|
+
function workletUnRef(value: Worklet | WorkletRefImpl<Element>): void {
|
|
10
|
+
if ('_wvid' in value && (value._wvid as WorkletRefId) > 0) {
|
|
11
|
+
update(value as WorkletRefImpl<Element>, null);
|
|
16
12
|
} else if ('_wkltId' in value) {
|
|
17
13
|
if (typeof value._unmount == 'function') {
|
|
18
|
-
value._unmount();
|
|
14
|
+
(value._unmount as () => void)();
|
|
19
15
|
} else {
|
|
20
|
-
runWorkletCtx(value
|
|
16
|
+
runWorkletCtx(value, [null]);
|
|
21
17
|
}
|
|
22
18
|
}
|
|
23
19
|
}
|
|
@@ -25,7 +21,7 @@ function workletUnRef(value: Worklet | WorkletRef<unknown>): void {
|
|
|
25
21
|
function updateWorkletRef(
|
|
26
22
|
snapshot: SnapshotInstance,
|
|
27
23
|
expIndex: number,
|
|
28
|
-
oldValue:
|
|
24
|
+
oldValue: WorkletRefImpl<Element> | Worklet | undefined,
|
|
29
25
|
elementIndex: number,
|
|
30
26
|
_workletType: string,
|
|
31
27
|
): void {
|
|
@@ -38,15 +34,18 @@ function updateWorkletRef(
|
|
|
38
34
|
snapshot.__worklet_ref_set?.delete(oldValue);
|
|
39
35
|
}
|
|
40
36
|
|
|
41
|
-
const value = snapshot.__values![expIndex];
|
|
37
|
+
const value = snapshot.__values![expIndex] as (WorkletRefImpl<Element> | Worklet | undefined);
|
|
42
38
|
if (value === null || value === undefined) {
|
|
43
39
|
// do nothing
|
|
44
40
|
} else if (value._wvid) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
if ((value._wvid as WorkletRefId) > 0) {
|
|
42
|
+
update(value as WorkletRefImpl<Element>, snapshot.__elements[elementIndex]!);
|
|
43
|
+
}
|
|
44
|
+
} else if ((value as Worklet)._wkltId) {
|
|
45
|
+
(value as Worklet)._unmount = runWorkletCtx(value as Worklet, [{
|
|
46
|
+
elementRefptr: (snapshot.__elements[elementIndex]!) as any,
|
|
47
|
+
}]) as () => void;
|
|
48
|
+
} else if (value._type === '__LEPUS__' || (value as Worklet)._lepusWorkletHash) {
|
|
50
49
|
// During the initial render, we will not update the WorkletRef because the background thread is not ready yet.
|
|
51
50
|
} else {
|
|
52
51
|
throw new Error('MainThreadRef: main-thread:ref must be of type MainThreadRef or main-thread function.');
|
|
@@ -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,
|