@lynx-js/react 0.105.1 → 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.
- package/CHANGELOG.md +18 -0
- package/package.json +1 -1
- package/refresh/.turbo/turbo-build.log +1 -1
- package/refresh/package.json +1 -1
- package/runtime/lib/backgroundSnapshot.d.ts +1 -1
- package/runtime/lib/backgroundSnapshot.js +2 -2
- package/runtime/lib/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/compat/initData.js +0 -2
- package/runtime/lib/compat/initData.js.map +1 -1
- package/runtime/lib/gesture/processGesture.js +3 -0
- package/runtime/lib/gesture/processGesture.js.map +1 -1
- package/runtime/lib/gesture/types.d.ts +2 -0
- package/runtime/lib/internal.d.ts +2 -1
- package/runtime/lib/internal.js +3 -2
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lifecycle/destroy.js +1 -1
- package/runtime/lib/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/lifecycle/{patchUpdate.d.ts → patch/commit.d.ts} +1 -3
- package/runtime/lib/lifecycle/{patchUpdate.js → patch/commit.js} +12 -56
- package/runtime/lib/lifecycle/patch/commit.js.map +1 -0
- package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -0
- package/runtime/lib/{snapshotPatchApply.js → lifecycle/patch/snapshotPatchApply.js} +1 -4
- package/runtime/lib/lifecycle/patch/snapshotPatchApply.js.map +1 -0
- package/runtime/lib/lifecycle/patch/updateMainThread.d.ts +3 -0
- package/runtime/lib/lifecycle/patch/updateMainThread.js +55 -0
- package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -0
- package/runtime/lib/lifecycle/reload.js +1 -1
- package/runtime/lib/lifecycle/reload.js.map +1 -1
- package/runtime/lib/lifecycle/render.js.map +1 -1
- package/runtime/lib/list.js +1 -1
- package/runtime/lib/list.js.map +1 -1
- package/runtime/lib/lynx/component.js +3 -3
- package/runtime/lib/lynx/component.js.map +1 -1
- package/runtime/lib/lynx/dynamic-js.js +0 -1
- package/runtime/lib/lynx/dynamic-js.js.map +1 -1
- package/runtime/lib/lynx/env.js +1 -2
- package/runtime/lib/lynx/env.js.map +1 -1
- package/runtime/lib/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/lynx/performance.js +1 -1
- package/runtime/lib/lynx/performance.js.map +1 -1
- package/runtime/lib/lynx/tt.d.ts +1 -0
- package/runtime/lib/lynx/tt.js +45 -4
- package/runtime/lib/lynx/tt.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +1 -1
- package/runtime/lib/lynx.d.ts +0 -1
- package/runtime/lib/lynx.js +4 -46
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/snapshot/ref.d.ts +2 -2
- package/runtime/lib/snapshot/ref.js +6 -7
- package/runtime/lib/snapshot/ref.js.map +1 -1
- package/runtime/lib/snapshot.js +1 -1
- package/runtime/lib/snapshot.js.map +1 -1
- package/runtime/lib/worklet/functionCall.js.map +1 -1
- package/runtime/lib/worklet/hmr.js +1 -1
- package/runtime/lib/worklet/hmr.js.map +1 -1
- package/runtime/lib/worklet/runOnBackground.js.map +1 -1
- package/runtime/lib/worklet/workletRef.js +1 -1
- package/runtime/lib/worklet/workletRef.js.map +1 -1
- package/runtime/src/backgroundSnapshot.ts +3 -3
- package/runtime/src/compat/initData.ts +5 -6
- package/runtime/src/gesture/processGesture.ts +4 -0
- package/runtime/src/gesture/types.ts +2 -0
- package/runtime/src/internal.ts +4 -2
- package/runtime/src/lifecycle/destroy.ts +1 -1
- package/runtime/src/lifecycle/{patchUpdate.ts → patch/commit.ts} +18 -71
- package/runtime/src/{snapshotPatchApply.ts → lifecycle/patch/snapshotPatchApply.ts} +2 -2
- package/runtime/src/lifecycle/patch/updateMainThread.ts +69 -0
- package/runtime/src/lifecycle/reload.ts +1 -1
- package/runtime/src/lifecycle/render.ts +1 -1
- package/runtime/src/list.ts +1 -1
- package/runtime/src/lynx/component.ts +3 -3
- package/runtime/src/lynx/dynamic-js.ts +2 -3
- package/runtime/src/lynx/env.ts +2 -2
- package/runtime/src/lynx/lazy-bundle.ts +1 -1
- package/runtime/src/lynx/performance.ts +3 -2
- package/runtime/src/lynx/tt.ts +55 -6
- package/runtime/src/lynx-api.ts +1 -1
- package/runtime/src/lynx.ts +5 -55
- package/runtime/src/snapshot/ref.ts +6 -9
- package/runtime/src/snapshot.ts +1 -1
- package/runtime/src/worklet/functionCall.ts +1 -1
- package/runtime/src/worklet/hmr.ts +1 -1
- package/runtime/src/worklet/runOnBackground.ts +4 -4
- package/runtime/src/worklet/workletRef.ts +1 -1
- package/transform/dist/wasm.cjs +1 -1
- package/runtime/lib/lifecycle/patchUpdate.js.map +0 -1
- package/runtime/lib/snapshotPatch.js.map +0 -1
- package/runtime/lib/snapshotPatchApply.js.map +0 -1
- /package/runtime/lib/{snapshotPatch.d.ts → lifecycle/patch/snapshotPatch.d.ts} +0 -0
- /package/runtime/lib/{snapshotPatch.js → lifecycle/patch/snapshotPatch.js} +0 -0
- /package/runtime/lib/{snapshotPatchApply.d.ts → lifecycle/patch/snapshotPatchApply.d.ts} +0 -0
- /package/runtime/src/{snapshotPatch.ts → lifecycle/patch/snapshotPatch.ts} +0 -0
package/runtime/src/internal.ts
CHANGED
|
@@ -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,
|
|
15
|
+
import { DynamicPartType, SnapshotInstance, __page, __pageId, createSnapshot, snapshotManager } from './snapshot.js';
|
|
14
16
|
|
|
15
17
|
export { __page, __pageId, __root };
|
|
16
18
|
|
|
@@ -47,7 +49,7 @@ 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
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
51
53
|
{ Suspense, lazy, createElement, useMemo } as any,
|
|
52
54
|
loadLazyBundle,
|
|
53
55
|
);
|
|
@@ -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 {
|
|
9
|
-
|
|
10
|
-
import { LifecycleConstant } from '
|
|
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 '
|
|
21
|
-
import { CATCH_ERROR, COMMIT, RENDER_CALLBACKS, VNODE } from '
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
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,7 @@ 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 '
|
|
16
|
+
import { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';
|
|
17
17
|
import { destroyWorklet } from '../worklet/destroy.js';
|
|
18
18
|
|
|
19
19
|
function reloadMainThread(data: any, options: UpdatePageOption): void {
|
package/runtime/src/list.ts
CHANGED
|
@@ -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/
|
|
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/
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
});
|
package/runtime/src/lynx/env.ts
CHANGED
|
@@ -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
|
|
65
|
+
lynx.getNativeApp().markTiming?.(timingFlag!, PerformanceTimingKeys[key]);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
function beginPipeline(needTimestamps: boolean, timingFlag?: string): void {
|
package/runtime/src/lynx/tt.ts
CHANGED
|
@@ -1,21 +1,70 @@
|
|
|
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/
|
|
11
|
+
import { commitPatchUpdate, genCommitTaskId, globalCommitTaskMap } from '../lifecycle/patch/commit.js';
|
|
11
12
|
import { reloadBackground } from '../lifecycle/reload.js';
|
|
12
|
-
import {
|
|
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
17
|
import { destroyWorklet } from '../worklet/destroy.js';
|
|
18
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
|
+
}
|
|
67
|
+
|
|
19
68
|
function injectTt(): void {
|
|
20
69
|
// @ts-ignore
|
|
21
70
|
const tt = lynxCoreInject.tt;
|
|
@@ -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;
|
package/runtime/src/lynx-api.ts
CHANGED
|
@@ -366,7 +366,7 @@ export interface Lynx {
|
|
|
366
366
|
* ```
|
|
367
367
|
* @public
|
|
368
368
|
*/
|
|
369
|
-
registerDataProcessors: (dataProcessorDefinition
|
|
369
|
+
registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void;
|
|
370
370
|
}
|
|
371
371
|
|
|
372
372
|
export { runOnMainThread } from './worklet/runOnMainThread.js';
|
package/runtime/src/lynx.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
29
|
+
injectUpdateMainThread();
|
|
80
30
|
if (__DEV__) {
|
|
81
31
|
injectLepusMethods();
|
|
82
32
|
}
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import type { Worklet, WorkletRef } from '@lynx-js/react/worklet-runtime/bindings';
|
|
5
5
|
|
|
6
|
-
import { nextCommitTaskId } from '../lifecycle/
|
|
6
|
+
import { nextCommitTaskId } from '../lifecycle/patch/commit.js';
|
|
7
7
|
import { SnapshotInstance, backgroundSnapshotInstanceManager } from '../snapshot.js';
|
|
8
8
|
import { workletUnRef } from './workletRef.js';
|
|
9
9
|
|
|
10
10
|
let globalRefPatch: Record<string, number | null> = {};
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const globalRefsToRemove: Map</* commitId */ number, Map</* sign */ string, /* ref */ any>> = /* @__PURE__ */ new Map();
|
|
12
|
+
const globalRefsToSet: Map</* commitId */ number, Record<string, number>> = /* @__PURE__ */ new Map();
|
|
13
13
|
let nextRefId = 1;
|
|
14
14
|
|
|
15
15
|
function unref(snapshot: SnapshotInstance, recursive: boolean): void {
|
|
@@ -35,7 +35,7 @@ function unref(snapshot: SnapshotInstance, recursive: boolean): void {
|
|
|
35
35
|
function applyRef(ref: any, value: any) {
|
|
36
36
|
// TODO: ref: exceptions thrown in user functions should be able to be caught by an Error Boundary
|
|
37
37
|
if (typeof ref == 'function') {
|
|
38
|
-
|
|
38
|
+
const hasRefUnmount = typeof ref._unmount == 'function';
|
|
39
39
|
if (hasRefUnmount) {
|
|
40
40
|
// @ts-ignore TS doesn't like moving narrowing checks into variables
|
|
41
41
|
ref._unmount();
|
|
@@ -54,7 +54,7 @@ function updateBackgroundRefs(commitId: number): void {
|
|
|
54
54
|
const oldRefMap = globalRefsToRemove.get(commitId);
|
|
55
55
|
if (oldRefMap) {
|
|
56
56
|
globalRefsToRemove.delete(commitId);
|
|
57
|
-
for (
|
|
57
|
+
for (const ref of oldRefMap.values()) {
|
|
58
58
|
applyRef(ref, null);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -65,10 +65,7 @@ function updateBackgroundRefs(commitId: number): void {
|
|
|
65
65
|
const ref = backgroundSnapshotInstanceManager.getValueBySign(sign);
|
|
66
66
|
if (ref) {
|
|
67
67
|
// TODO: ref: support __REF_FIRE_IMMEDIATELY__
|
|
68
|
-
const v = newRefMap[sign]
|
|
69
|
-
&& lynx.createSelectorQuery().selectUniqueID(
|
|
70
|
-
newRefMap[sign],
|
|
71
|
-
);
|
|
68
|
+
const v = newRefMap[sign] && lynx.createSelectorQuery().selectUniqueID(newRefMap[sign]);
|
|
72
69
|
applyRef(ref, v);
|
|
73
70
|
}
|
|
74
71
|
}
|
package/runtime/src/snapshot.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bin
|
|
|
6
6
|
import type { BackgroundSnapshotInstance } from './backgroundSnapshot.js';
|
|
7
7
|
import { ListUpdateInfoRecording, __pendingListUpdates, snapshotDestroyList } from './list.js';
|
|
8
8
|
import { unref } from './snapshot/ref.js';
|
|
9
|
-
import { SnapshotOperation, __globalSnapshotPatch } from './snapshotPatch.js';
|
|
9
|
+
import { SnapshotOperation, __globalSnapshotPatch } from './lifecycle/patch/snapshotPatch.js';
|
|
10
10
|
import { isDirectOrDeepEqual } from './utils.js';
|
|
11
11
|
|
|
12
12
|
export const enum DynamicPartType {
|
|
@@ -11,7 +11,7 @@ import { IndexMap } from './indexMap.js';
|
|
|
11
11
|
let resolveMap: IndexMap<(value: any) => void> | undefined;
|
|
12
12
|
|
|
13
13
|
function initReturnValueListener(): void {
|
|
14
|
-
const context: RuntimeProxy = __JS__ ? lynx.getCoreContext() : lynx.getJSContext();
|
|
14
|
+
const context: RuntimeProxy = __JS__ ? lynx.getCoreContext!() : lynx.getJSContext!();
|
|
15
15
|
|
|
16
16
|
resolveMap = new IndexMap();
|
|
17
17
|
context.addEventListener(WorkletEvents.FunctionCallRet, onFunctionCallRet);
|
|
@@ -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 { SnapshotOperation, __globalSnapshotPatch } from '../snapshotPatch.js';
|
|
4
|
+
import { SnapshotOperation, __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';
|
|
5
5
|
|
|
6
6
|
const workletHashSet: Set<string> = /* @__PURE__ */ new Set();
|
|
7
7
|
|
|
@@ -28,12 +28,12 @@ function init() {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
execIdMap = new WorkletExecIdMap();
|
|
31
|
-
lynx.getCoreContext().addEventListener(WorkletEvents.runOnBackground, runJSFunction);
|
|
32
|
-
lynx.getCoreContext().addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundWorkletCtx);
|
|
31
|
+
lynx.getCoreContext!().addEventListener(WorkletEvents.runOnBackground, runJSFunction);
|
|
32
|
+
lynx.getCoreContext!().addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundWorkletCtx);
|
|
33
33
|
|
|
34
34
|
destroyTasks.push(() => {
|
|
35
|
-
lynx.getCoreContext().removeEventListener(WorkletEvents.runOnBackground, runJSFunction);
|
|
36
|
-
lynx.getCoreContext().removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundWorkletCtx);
|
|
35
|
+
lynx.getCoreContext!().removeEventListener(WorkletEvents.runOnBackground, runJSFunction);
|
|
36
|
+
lynx.getCoreContext!().removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundWorkletCtx);
|
|
37
37
|
execIdMap = undefined;
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -89,7 +89,7 @@ export class MainThreadRef<T> extends WorkletRef<T> {
|
|
|
89
89
|
super(initValue, 'main-thread');
|
|
90
90
|
if (__JS__) {
|
|
91
91
|
const id = this._id;
|
|
92
|
-
this._lifecycleObserver = lynx.getNativeApp().createJSObjectDestructionObserver(() => {
|
|
92
|
+
this._lifecycleObserver = lynx.getNativeApp().createJSObjectDestructionObserver?.(() => {
|
|
93
93
|
lynx.getCoreContext?.().dispatchEvent({
|
|
94
94
|
type: WorkletEvents.releaseWorkletRef,
|
|
95
95
|
data: {
|