@lynx-js/react 0.129.4 → 0.129.5
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/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -1
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/lynx/env.test.ts +146 -0
- package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +47 -4
- package/runtime/__test__/element-template/native/index.test.ts +9 -9
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +55 -2
- package/runtime/__test__/element-template/native/reload.test.ts +15 -5
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +1 -1
- package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +1 -1
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +33 -0
- package/runtime/__test__/element-template/vitest.config.ts +1 -1
- package/runtime/__test__/snapshot/debug/profile.test.jsx +147 -26
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +54 -0
- package/runtime/__test__/snapshot/lifecycle/transfer.mts.test.jsx +98 -6
- package/runtime/__test__/snapshot/lifecycle/transfer.test.jsx +214 -9
- package/runtime/__test__/snapshot/lynx/suspense.test.jsx +48 -0
- package/runtime/__test__/snapshot/utils/envManager.ts +2 -0
- package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +21 -0
- package/runtime/__test__/worklet-runtime/lifecycle.test.js +297 -0
- package/runtime/__test__/worklet-runtime/profile.test.js +12 -6
- package/runtime/lazy/element-template-internal.js +1 -0
- package/runtime/lib/core/compat/componentIs.d.ts +1 -0
- package/runtime/lib/core/compat/componentIs.js +20 -0
- package/runtime/lib/core/compat/componentIs.js.map +1 -0
- package/runtime/lib/core/lynx/env.d.ts +1 -0
- package/runtime/lib/{element-template → core}/lynx/env.js +3 -2
- package/runtime/lib/core/lynx/env.js.map +1 -0
- package/runtime/lib/core/thread-function-call/main-thread.d.ts +1 -0
- package/runtime/lib/core/thread-function-call/main-thread.js +4 -1
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- package/runtime/lib/element-template/background/commit-event.d.ts +6 -0
- package/runtime/lib/element-template/background/commit-event.js +36 -0
- package/runtime/lib/element-template/background/commit-event.js.map +1 -0
- package/runtime/lib/element-template/background/commit-hook.js +3 -23
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js +1 -1
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +1 -2
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js +5 -25
- package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
- package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.js +4 -4
- package/runtime/lib/element-template/background/main-thread-function.js.map +1 -0
- package/runtime/lib/element-template/index.d.ts +1 -1
- package/runtime/lib/element-template/index.js +1 -1
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.js +3 -0
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/native/index.js +2 -2
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.d.ts +2 -1
- package/runtime/lib/element-template/native/mts-destroy.js +15 -4
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js +2 -2
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js +4 -11
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.d.ts +1 -1
- package/runtime/lib/element-template/runtime/template/handle.js +2 -2
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.d.ts +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +7 -2
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
- package/runtime/lib/internal.js +4 -10
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js +27 -62
- package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.js +2 -2
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/lynx/env.js +2 -32
- package/runtime/lib/snapshot/lynx/env.js.map +1 -1
- package/runtime/lib/snapshot/transfer.d.ts +6 -0
- package/runtime/lib/snapshot/transfer.js +154 -11
- package/runtime/lib/snapshot/transfer.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/lifecycle.d.ts +19 -0
- package/runtime/lib/worklet-runtime/bindings/lifecycle.js +49 -0
- package/runtime/lib/worklet-runtime/bindings/lifecycle.js.map +1 -0
- package/runtime/lib/worklet-runtime/delayWorkletEvent.d.ts +1 -1
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js +9 -1
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/profile.js +1 -3
- package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
- package/runtime/src/core/compat/componentIs.ts +32 -0
- package/runtime/src/{element-template → core}/lynx/env.ts +6 -4
- package/runtime/src/core/thread-function-call/main-thread.ts +5 -1
- package/runtime/src/element-template/background/commit-event.ts +52 -0
- package/runtime/src/element-template/background/commit-hook.ts +4 -31
- package/runtime/src/element-template/background/destroy.ts +1 -1
- package/runtime/src/element-template/background/hydrate.ts +5 -3
- package/runtime/src/element-template/background/hydration-listener.ts +7 -32
- package/runtime/src/element-template/{runtime/template → background}/main-thread-function.ts +4 -7
- package/runtime/src/element-template/index.ts +1 -1
- package/runtime/src/element-template/internal.ts +4 -0
- package/runtime/src/element-template/native/index.ts +2 -2
- package/runtime/src/element-template/native/mts-destroy.ts +21 -4
- package/runtime/src/element-template/native/reload-main-thread.ts +2 -2
- package/runtime/src/element-template/runtime/patch.ts +20 -35
- package/runtime/src/element-template/runtime/template/handle.ts +2 -0
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -2
- package/runtime/src/internal.ts +4 -13
- package/runtime/src/snapshot/debug/profileHooks.ts +30 -91
- package/runtime/src/snapshot/lifecycle/reload.ts +2 -3
- package/runtime/src/snapshot/lynx/env.ts +3 -43
- package/runtime/src/snapshot/transfer.ts +169 -13
- package/runtime/src/worklet-runtime/bindings/lifecycle.ts +51 -0
- package/runtime/src/worklet-runtime/delayWorkletEvent.ts +10 -2
- package/runtime/src/worklet-runtime/utils/profile.ts +1 -3
- package/runtime/types/internal-preact.d.ts +2 -0
- package/runtime/vitest.config.ts +0 -1
- package/testing-library/.turbo/turbo-build.log +7 -7
- package/testing-library/src/__tests__/events.test.jsx +1 -1
- package/testing-library/src/fire-event.ts +1 -1
- package/transform/.turbo/turbo-build$colon$wasm.log +67 -66
- package/transform/__test__/fixture.spec.js +1 -1
- package/transform/cjs/browser.cjs +11 -0
- package/transform/crates/swc_plugin_compat/lib.rs +20 -2
- package/transform/crates/swc_plugin_compat/napi.rs +7 -0
- package/transform/crates/swc_plugin_dynamic_import/lib.rs +15 -4
- package/transform/crates/swc_plugin_element_template/attr_name.rs +0 -3
- package/transform/crates/swc_plugin_element_template/extractor.rs +0 -8
- package/transform/crates/swc_plugin_element_template/lib.rs +12 -1
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +35 -0
- package/transform/crates/swc_plugin_worklet/lib.rs +11 -7
- package/transform/dist/wasm.cjs +1 -1
- package/transform/rspack-napi/lib/index.js +1 -4
- package/transform/rspack-napi/lib/index.js.map +1 -1
- package/transform/rspack-napi/src/index.ts +1 -4
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/src/lib.rs +394 -27
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +413 -105
- package/transform/swc-plugin-reactlynx/src/lib.rs +99 -22
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +28 -359
- package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
- package/runtime/__test__/element-template/lynx/env.test.ts +0 -242
- package/runtime/lib/element-template/lynx/env.d.ts +0 -1
- package/runtime/lib/element-template/lynx/env.js.map +0 -1
- package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +0 -1
- package/runtime/lib/snapshot/compat/componentIs.d.ts +0 -4
- package/runtime/lib/snapshot/compat/componentIs.js +0 -20
- package/runtime/lib/snapshot/compat/componentIs.js.map +0 -1
- package/runtime/src/snapshot/compat/componentIs.ts +0 -30
- /package/runtime/__test__/element-template/runtime/{template → background}/main-thread-function.test.ts +0 -0
- /package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.d.ts +0 -0
|
@@ -11,15 +11,28 @@ import {
|
|
|
11
11
|
updateElementTemplateListAttributes,
|
|
12
12
|
updateElementTemplateListItemSubtreeHandles,
|
|
13
13
|
} from './list/list.js';
|
|
14
|
-
import { insertElementTemplateSubtree } from './template/handle.js';
|
|
14
|
+
import { createElementTemplateWithReservedHandle, insertElementTemplateSubtree } from './template/handle.js';
|
|
15
15
|
import { retainMainThreadBackgroundFunctionCtx } from './template/main-thread-background-function.js';
|
|
16
|
+
import {
|
|
17
|
+
deleteMainThreadDynamicAttrStateForSubtree,
|
|
18
|
+
initializeMainThreadDynamicAttrSlots,
|
|
19
|
+
isSpreadDynamicAttrSlot,
|
|
20
|
+
prepareSpreadAttrSlotForNative,
|
|
21
|
+
reconcileUnhydratedSpreadMTRefSlots,
|
|
22
|
+
updateGestureAttrSlot,
|
|
23
|
+
updateMainThreadEventAttrSlot,
|
|
24
|
+
updateMainThreadRefAttrSlot,
|
|
25
|
+
updateSpreadAttrSlot,
|
|
26
|
+
} from './template/main-thread-dynamic-attr-state.js';
|
|
27
|
+
import type { MainThreadDynamicAttrSubtreeHandle } from './template/main-thread-dynamic-attr-state.js';
|
|
16
28
|
import type { MTEventNativeWrapper } from './template/main-thread-event-ctx.js';
|
|
17
29
|
import { elementTemplateRegistry } from './template/registry.js';
|
|
18
30
|
import { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from './template/typed-attributes.js';
|
|
31
|
+
import { retainGestureCallbacks } from '../prop-adapters/gesture.js';
|
|
32
|
+
import type { GestureSlotValue } from '../prop-adapters/gesture.js';
|
|
19
33
|
import { ElementTemplateUpdateOps } from '../protocol/opcodes.js';
|
|
20
34
|
import type { ElementTemplateUpdateOp } from '../protocol/opcodes.js';
|
|
21
35
|
import { ELEMENT_TEMPLATE_PAGE_HANDLE_ID } from '../protocol/page.js';
|
|
22
|
-
import { elementTemplateTypeTag } from '../protocol/template-type.js';
|
|
23
36
|
import type {
|
|
24
37
|
ElementTemplateHandleSlotsCommand,
|
|
25
38
|
ElementTemplateUpdateCommandStream,
|
|
@@ -30,21 +43,6 @@ import type {
|
|
|
30
43
|
TypedElementAttributesCommand,
|
|
31
44
|
UpdateTypedListItemCommand,
|
|
32
45
|
} from '../protocol/types.js';
|
|
33
|
-
import {
|
|
34
|
-
deleteMainThreadDynamicAttrStateForSubtree,
|
|
35
|
-
initializeMainThreadDynamicAttrSlots,
|
|
36
|
-
isSpreadDynamicAttrSlot,
|
|
37
|
-
prepareMainThreadDynamicAttrSlotsForNative,
|
|
38
|
-
prepareSpreadAttrSlotForNative,
|
|
39
|
-
reconcileUnhydratedSpreadMTRefSlots,
|
|
40
|
-
updateGestureAttrSlot,
|
|
41
|
-
updateMainThreadEventAttrSlot,
|
|
42
|
-
updateMainThreadRefAttrSlot,
|
|
43
|
-
updateSpreadAttrSlot,
|
|
44
|
-
} from './template/main-thread-dynamic-attr-state.js';
|
|
45
|
-
import type { MainThreadDynamicAttrSubtreeHandle } from './template/main-thread-dynamic-attr-state.js';
|
|
46
|
-
import { retainGestureCallbacks } from '../prop-adapters/gesture.js';
|
|
47
|
-
import type { GestureSlotValue } from '../prop-adapters/gesture.js';
|
|
48
46
|
|
|
49
47
|
export type { ElementTemplateUpdateCommandStream } from '../protocol/types.js';
|
|
50
48
|
|
|
@@ -85,29 +83,16 @@ export function applyElementTemplateUpdateCommands(
|
|
|
85
83
|
continue;
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
templateType,
|
|
91
|
-
attributeSlots,
|
|
92
|
-
);
|
|
93
|
-
const nativeRef = __CreateElementTemplate(
|
|
86
|
+
createElementTemplateWithReservedHandle(
|
|
87
|
+
handleId,
|
|
94
88
|
templateKey,
|
|
95
89
|
bundleUrl,
|
|
96
|
-
|
|
90
|
+
attributeSlots,
|
|
97
91
|
resolvedChildSlots,
|
|
98
|
-
|
|
92
|
+
true,
|
|
99
93
|
options,
|
|
94
|
+
true,
|
|
100
95
|
);
|
|
101
|
-
|
|
102
|
-
if (nativeRef) {
|
|
103
|
-
elementTemplateRegistry.set(handleId, nativeRef);
|
|
104
|
-
initializeMainThreadDynamicAttrSlots(
|
|
105
|
-
handleId,
|
|
106
|
-
templateType,
|
|
107
|
-
attributeSlots,
|
|
108
|
-
true,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
96
|
break;
|
|
112
97
|
}
|
|
113
98
|
|
|
@@ -38,6 +38,7 @@ export function createElementTemplateWithReservedHandle(
|
|
|
38
38
|
childSlots: RuntimeChildSlots | null | undefined,
|
|
39
39
|
hasDynamicAttributes = true,
|
|
40
40
|
options?: RuntimeOptions | null,
|
|
41
|
+
isCreatedByPatch = false,
|
|
41
42
|
): ElementTemplateHandle {
|
|
42
43
|
// Adapter-free compiled hosts need neither dynamic state nor native slot preparation.
|
|
43
44
|
const templateType = hasDynamicAttributes ? elementTemplateTypeTag(templateKey, bundleUrl) : undefined;
|
|
@@ -59,6 +60,7 @@ export function createElementTemplateWithReservedHandle(
|
|
|
59
60
|
handleId,
|
|
60
61
|
templateType,
|
|
61
62
|
attributeSlots,
|
|
63
|
+
isCreatedByPatch,
|
|
62
64
|
);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
@@ -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
|
|
|
5
|
-
import {
|
|
5
|
+
import { retainWorkletCtx } from '@lynx-js/react/worklet-runtime/bindings';
|
|
6
6
|
|
|
7
7
|
import { createBackgroundFunctionHandle } from '../../../core/background-function/handle.js';
|
|
8
8
|
import {
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from '../../../core/background-function/run-on-background.js';
|
|
13
13
|
import { resetFunctionCallReturnListener } from '../../../core/thread-function-call/return-value.js';
|
|
14
14
|
import { isRunOnBackgroundEnabled } from '../../../shared/version.js';
|
|
15
|
+
import { disposeWorkletRuntime, resetWorkletRuntimeForReload } from '../../../worklet-runtime/bindings/lifecycle.js';
|
|
15
16
|
|
|
16
17
|
type BackgroundFunctionCtx = Parameters<typeof registerBackgroundFunctionCtx>[0];
|
|
17
18
|
type RetainableMainThreadCtx = Parameters<typeof retainWorkletCtx>[0];
|
|
@@ -45,6 +46,11 @@ export function resetElementTemplateBackgroundFunctionRuntime(): void {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export function resetElementTemplateMainThreadBackgroundFunctionRuntime(): void {
|
|
48
|
-
|
|
49
|
+
resetWorkletRuntimeForReload();
|
|
50
|
+
resetFunctionCallReturnListener();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function disposeElementTemplateMainThreadBackgroundFunctionRuntime(): void {
|
|
54
|
+
disposeWorkletRuntime();
|
|
49
55
|
resetFunctionCallReturnListener();
|
|
50
56
|
}
|
package/runtime/src/internal.ts
CHANGED
|
@@ -2,17 +2,14 @@
|
|
|
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 {
|
|
6
|
-
import type { FC } from 'react';
|
|
5
|
+
import { cloneElement as preactCloneElement } from 'preact/compat';
|
|
7
6
|
|
|
8
7
|
import './runtime-marker.js';
|
|
9
8
|
import './lynx.js';
|
|
10
9
|
|
|
11
|
-
import {
|
|
12
|
-
import { loadLazyBundle } from './core/lynx/lazy-bundle.js';
|
|
10
|
+
import { __ComponentIsPolyfill as componentIsPolyfill } from './core/compat/componentIs.js';
|
|
13
11
|
import * as ReactLynxInternalSelf from './internal.js';
|
|
14
12
|
import { __root } from './root.js';
|
|
15
|
-
import { factory as factory2 } from './snapshot/compat/componentIs.js';
|
|
16
13
|
import { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js';
|
|
17
14
|
import { __page, __pageId, createSnapshot, snapshotManager } from './snapshot/snapshot/definition.js';
|
|
18
15
|
import { DynamicPartType } from './snapshot/snapshot/dynamicPartType.js';
|
|
@@ -88,14 +85,8 @@ export { withInitDataInState } from './core/initData.js';
|
|
|
88
85
|
|
|
89
86
|
export { wrapWithLynxComponent } from './core/compat/lynxComponent.js';
|
|
90
87
|
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
*/
|
|
94
|
-
export const __ComponentIsPolyfill: FC<{ is: string }> = /* @__PURE__ */ factory2(
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
96
|
-
{ Suspense, lazy, createElement, useMemo } as any,
|
|
97
|
-
loadLazyBundle,
|
|
98
|
-
);
|
|
88
|
+
/** @internal Compatibility for the compiler lowering of <component is=? />. */
|
|
89
|
+
export const __ComponentIsPolyfill = componentIsPolyfill;
|
|
99
90
|
|
|
100
91
|
export { loadLazyBundle } from './core/lynx/lazy-bundle.js';
|
|
101
92
|
|
|
@@ -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 { Component, options } from 'preact';
|
|
5
|
-
import type { ComponentClass,
|
|
5
|
+
import type { ComponentClass, VNode } from 'preact';
|
|
6
6
|
|
|
7
7
|
import type { TraceOption } from '@lynx-js/types';
|
|
8
8
|
|
|
@@ -16,65 +16,14 @@ import {
|
|
|
16
16
|
DIFFED,
|
|
17
17
|
HOOKS,
|
|
18
18
|
LIST,
|
|
19
|
-
NEXT_STATE,
|
|
20
19
|
NEXT_VALUE,
|
|
21
20
|
RENDER,
|
|
22
|
-
VALUE,
|
|
23
21
|
VNODE,
|
|
24
22
|
} from '../../shared/render-constants.js';
|
|
25
23
|
import { getDisplayName } from '../../shared/utils.js';
|
|
26
24
|
import { globalPatchOptions } from '../lifecycle/patch/commit.js';
|
|
27
25
|
import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';
|
|
28
26
|
|
|
29
|
-
const format = (val: unknown) => {
|
|
30
|
-
if (typeof val === 'function') {
|
|
31
|
-
return val.toString();
|
|
32
|
-
}
|
|
33
|
-
return val;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function safeJsonStringify(val: unknown) {
|
|
37
|
-
const seen = new WeakSet<object>();
|
|
38
|
-
|
|
39
|
-
return JSON.stringify(val, function(_key, value: unknown) {
|
|
40
|
-
if (typeof value === 'object' && value !== null) {
|
|
41
|
-
if (seen.has(value)) {
|
|
42
|
-
return '[Unserializable: Circular]';
|
|
43
|
-
}
|
|
44
|
-
seen.add(value);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return value;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function buildSetStateProfileMarkArgs(
|
|
52
|
-
type: string | ComponentType | undefined,
|
|
53
|
-
currentState: unknown,
|
|
54
|
-
nextState: unknown,
|
|
55
|
-
): Record<string, string> {
|
|
56
|
-
const EMPTY_OBJ = {};
|
|
57
|
-
|
|
58
|
-
const currentStateObj = (currentState ?? EMPTY_OBJ) as Record<string, unknown>;
|
|
59
|
-
const nextStateObj = (nextState ?? EMPTY_OBJ) as Record<string, unknown>;
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
componentName: (type && typeof type === 'function')
|
|
63
|
-
? getDisplayName(type as ComponentClass)
|
|
64
|
-
: 'Unknown',
|
|
65
|
-
'current state keys': JSON.stringify(Object.keys(currentStateObj)),
|
|
66
|
-
'next state keys': JSON.stringify(Object.keys(nextStateObj)),
|
|
67
|
-
'changed (shallow diff) state keys': JSON.stringify(
|
|
68
|
-
// the setState is in assign manner, we assume nextState is a superset of currentState
|
|
69
|
-
Object.keys(nextStateObj).filter(
|
|
70
|
-
key => currentStateObj[key] !== nextStateObj[key],
|
|
71
|
-
),
|
|
72
|
-
),
|
|
73
|
-
currentValue: safeJsonStringify(format(currentState)),
|
|
74
|
-
nextValue: safeJsonStringify(format(nextState)),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
27
|
export function initProfileHook(): void {
|
|
79
28
|
// early-exit if required profiling APIs are unavailable
|
|
80
29
|
let p;
|
|
@@ -102,27 +51,38 @@ export function initProfileHook(): void {
|
|
|
102
51
|
const sFlowID = Symbol('FLOW_ID');
|
|
103
52
|
type PatchedComponent = Component & { [sFlowID]?: number };
|
|
104
53
|
|
|
54
|
+
function markSetState(component: PatchedComponent, hookIdx?: number): void {
|
|
55
|
+
try {
|
|
56
|
+
const type = component[VNODE]!.type;
|
|
57
|
+
if (
|
|
58
|
+
hookIdx === undefined
|
|
59
|
+
&& !(typeof type === 'function' && ('prototype' in type) && ('render' in type.prototype))
|
|
60
|
+
) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Update traces describe the framework's work without inspecting application state.
|
|
64
|
+
const args: Record<string, string> = {
|
|
65
|
+
componentName: typeof type === 'function' ? getDisplayName(type as ComponentClass) : 'Unknown',
|
|
66
|
+
};
|
|
67
|
+
if (hookIdx !== undefined) {
|
|
68
|
+
args['hookIdx'] = String(hookIdx);
|
|
69
|
+
}
|
|
70
|
+
const flowId = component[sFlowID] ?? profileFlowId();
|
|
71
|
+
profileMark(hookIdx === undefined ? 'ReactLynx::setState' : 'ReactLynx::hooks::setState', { flowId, args });
|
|
72
|
+
component[sFlowID] = flowId;
|
|
73
|
+
} catch {
|
|
74
|
+
// A profiling failure must not interrupt Preact's update or scheduling.
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
105
78
|
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
106
79
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
107
80
|
const oldSetState = Component.prototype.setState;
|
|
108
|
-
Component.prototype.setState = function(this: PatchedComponent
|
|
81
|
+
Component.prototype.setState = function(this: PatchedComponent, state, callback) {
|
|
109
82
|
oldSetState?.call(this, state, callback);
|
|
110
83
|
|
|
111
84
|
if (this[BITS] & COMPONENT_DIRTY) {
|
|
112
|
-
|
|
113
|
-
const isClassComponent = typeof type === 'function' && ('prototype' in type)
|
|
114
|
-
&& ('render' in type.prototype);
|
|
115
|
-
|
|
116
|
-
if (isClassComponent) {
|
|
117
|
-
profileMark('ReactLynx::setState', {
|
|
118
|
-
flowId: this[sFlowID] ??= profileFlowId(),
|
|
119
|
-
args: buildSetStateProfileMarkArgs(
|
|
120
|
-
type,
|
|
121
|
-
this.state,
|
|
122
|
-
this[NEXT_STATE],
|
|
123
|
-
),
|
|
124
|
-
});
|
|
125
|
-
}
|
|
85
|
+
markSetState(this);
|
|
126
86
|
}
|
|
127
87
|
};
|
|
128
88
|
}
|
|
@@ -171,34 +131,13 @@ export function initProfileHook(): void {
|
|
|
171
131
|
Object.defineProperty(hookState, NEXT_VALUE, {
|
|
172
132
|
get: () => hookState['internalNextValue'],
|
|
173
133
|
set: (value) => {
|
|
134
|
+
hookState['internalNextValue'] = value;
|
|
174
135
|
if (Array.isArray(value)) {
|
|
175
|
-
// hookState[VALUE] is [state, dispatch]
|
|
176
|
-
const currentValueTuple = hookState[VALUE] as unknown[];
|
|
177
|
-
const currentValue = currentValueTuple[0];
|
|
178
|
-
const [nextValue] = value as unknown[];
|
|
179
|
-
|
|
180
136
|
const component = hookState[COMPONENT] as PatchedComponent | undefined;
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
return;
|
|
137
|
+
if (component) {
|
|
138
|
+
markSetState(component, hookIdx);
|
|
184
139
|
}
|
|
185
|
-
|
|
186
|
-
const type = component[VNODE]!.type;
|
|
187
|
-
const flowId = component[sFlowID] ??= profileFlowId();
|
|
188
|
-
|
|
189
|
-
profileMark('ReactLynx::hooks::setState', {
|
|
190
|
-
flowId,
|
|
191
|
-
args: {
|
|
192
|
-
hookIdx: String(hookIdx),
|
|
193
|
-
...buildSetStateProfileMarkArgs(
|
|
194
|
-
type,
|
|
195
|
-
currentValue,
|
|
196
|
-
nextValue,
|
|
197
|
-
),
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
140
|
}
|
|
201
|
-
hookState['internalNextValue'] = value;
|
|
202
141
|
},
|
|
203
142
|
configurable: true,
|
|
204
143
|
});
|
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
import { render } from 'preact';
|
|
11
11
|
|
|
12
|
-
import { clearDelayedRunOnBackgroundFunctions } from '@lynx-js/react/worklet-runtime/bindings';
|
|
13
|
-
|
|
14
12
|
import { destroyBackground } from './destroy.js';
|
|
15
13
|
import { renderMainThread } from './render.js';
|
|
16
14
|
import {
|
|
@@ -25,6 +23,7 @@ import { resetFunctionCallReturnListener } from '../../core/thread-function-call
|
|
|
25
23
|
import { __root, setRoot } from '../../root.js';
|
|
26
24
|
import { profileEnd, profileStart } from '../../shared/profile.js';
|
|
27
25
|
import { isEmptyObject } from '../../shared/utils.js';
|
|
26
|
+
import { resetWorkletRuntimeForReload } from '../../worklet-runtime/bindings/lifecycle.js';
|
|
28
27
|
import { LifecycleConstant } from '../lifecycle/constant.js';
|
|
29
28
|
import { __pendingListUpdates } from '../list/pendingListUpdates.js';
|
|
30
29
|
import { hydrate } from '../renderToOpcodes/hydrate.js';
|
|
@@ -39,7 +38,7 @@ function reloadMainThread(data: unknown, options: UpdatePageOption): void {
|
|
|
39
38
|
profileStart('ReactLynx::reloadMainThread');
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
resetWorkletRuntimeForReload();
|
|
43
42
|
resetFunctionCallReturnListener();
|
|
44
43
|
increaseReloadVersion();
|
|
45
44
|
|
|
@@ -1,58 +1,18 @@
|
|
|
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
|
-
|
|
5
|
-
import
|
|
4
|
+
|
|
5
|
+
import { setupSharedLynxEnv } from '../../core/lynx/env.js';
|
|
6
6
|
|
|
7
7
|
export function setupLynxEnv(): void {
|
|
8
|
-
|
|
9
|
-
const { initData, updateData } = lynx.getApp()._params;
|
|
10
|
-
lynx.__initData = { ...initData, ...updateData };
|
|
11
|
-
lynx.registerDataProcessors = function() {};
|
|
12
|
-
}
|
|
8
|
+
setupSharedLynxEnv();
|
|
13
9
|
|
|
14
10
|
if (__LEPUS__) {
|
|
15
|
-
lynx.__initData = {
|
|
16
|
-
/* available only in renderPage */
|
|
17
|
-
};
|
|
18
|
-
// @ts-expect-error no type for lynx.SystemInfo
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
20
|
-
globalThis.SystemInfo = lynx.SystemInfo ?? {};
|
|
21
|
-
|
|
22
11
|
lynx.reportError = function(e: Error | string) {
|
|
23
12
|
const error = e instanceof Error ? e : new Error(JSON.stringify(e));
|
|
24
13
|
_ReportError(error, {
|
|
25
14
|
errorCode: 1101, // ErrCode::LYNX_ERROR_CODE_LEPUS in Lynx/base/debug/error_code.h
|
|
26
15
|
});
|
|
27
16
|
};
|
|
28
|
-
|
|
29
|
-
lynx.triggerGlobalEventFromLepus = function(
|
|
30
|
-
eventName: string,
|
|
31
|
-
params: any,
|
|
32
|
-
) {
|
|
33
|
-
__OnLifecycleEvent(['globalEventFromLepus', [eventName, params]]);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
38
|
-
function __name(empty: string) {
|
|
39
|
-
return `Native${empty}Modules`;
|
|
40
|
-
}
|
|
41
|
-
// TODO(hongzhiyuan.hzy): make sure this is run before any other code (especially code access `NativeModules`)
|
|
42
|
-
// @ts-expect-error hack
|
|
43
|
-
if (typeof globalThis[__name('')] === 'undefined') {
|
|
44
|
-
// @ts-expect-error hack
|
|
45
|
-
globalThis[__name('')] = undefined;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
lynx.registerDataProcessors = function(
|
|
50
|
-
dataProcessorDefinition?: DataProcessorDefinition,
|
|
51
|
-
) {
|
|
52
|
-
globalThis.processData = createProcessData(dataProcessorDefinition);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// register empty DataProcessors to make sure `globalThis.processData` is set
|
|
56
|
-
lynx.registerDataProcessors();
|
|
57
17
|
}
|
|
58
18
|
}
|