@lynx-js/react 0.129.0 → 0.129.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 +24 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/globalProps.test.ts +27 -6
- package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
- package/runtime/__test__/element-template/fixtures/gesture/direct/index.tsx +33 -0
- package/runtime/__test__/element-template/fixtures/spread/mts/index.tsx +197 -0
- package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
- package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +89 -3
- package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +88 -0
- package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +3 -0
- package/runtime/__test__/element-template/native/reload.test.ts +118 -2
- package/runtime/__test__/element-template/runtime/background/global-props/compiled-fixtures.test.tsx +5 -5
- package/runtime/__test__/element-template/runtime/background/global-props.test.tsx +1 -1
- package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +70 -0
- package/runtime/__test__/element-template/runtime/background/ref/compiled-fixtures.test.tsx +3 -4
- package/runtime/__test__/element-template/runtime/background/reload.test.ts +74 -0
- package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +212 -7
- package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/prop-adapters/gesture-compiled.test.ts +200 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +420 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +527 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/spread.test.ts +185 -6
- package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +21 -1
- package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
- package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
- package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +309 -26
- package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
- package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
- package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
- package/runtime/__test__/shared/component-stack.test.ts +211 -0
- package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
- package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
- package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.event.test.jsx +2 -2
- package/runtime/__test__/snapshot/lifecycle/updateGlobalProps.test.jsx +3 -3
- package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
- package/runtime/__test__/snapshot/preact.test.jsx +0 -3
- package/runtime/__test__/snapshot/ref.test.jsx +30 -0
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +12 -0
- package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
- package/runtime/lazy/element-template-internal.js +1 -1
- package/runtime/lazy/internal.js +1 -1
- package/runtime/lazy/jsx-dev-runtime.js +1 -1
- package/runtime/lazy/jsx-runtime.js +1 -1
- package/runtime/lazy/legacy-react-runtime.js +1 -1
- package/runtime/lazy/react-lepus.js +1 -1
- package/runtime/lazy/react.js +1 -1
- package/runtime/lib/core/capture-main-thread-object.js +2 -1
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
- package/runtime/lib/core/globalProps.js +1 -1
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
- package/runtime/lib/core/lynx-data-processors.js +3 -0
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.js +1 -1
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/document.js +0 -5
- package/runtime/lib/document.js.map +1 -1
- package/runtime/lib/element-template/background/attr-slots.js +5 -2
- package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js +11 -12
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js +16 -11
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +23 -0
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/client/root.d.ts +1 -1
- package/runtime/lib/element-template/client/root.js.map +1 -1
- package/runtime/lib/element-template/debug/alog.d.ts +1 -1
- package/runtime/lib/element-template/debug/alog.js +4 -1
- package/runtime/lib/element-template/debug/alog.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +2 -2
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +2 -2
- package/runtime/lib/element-template/internal.js +1 -14
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.js.map +1 -1
- package/runtime/lib/element-template/native/callDestroyLifetimeFun.js +6 -1
- package/runtime/lib/element-template/native/callDestroyLifetimeFun.js.map +1 -1
- package/runtime/lib/element-template/native/flush.d.ts +1 -0
- package/runtime/lib/element-template/native/flush.js +9 -0
- package/runtime/lib/element-template/native/flush.js.map +1 -0
- package/runtime/lib/element-template/native/main-thread-api.js +3 -7
- package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js +8 -2
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +57 -50
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.js +1 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js +35 -10
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/gesture.d.ts +23 -0
- package/runtime/lib/element-template/prop-adapters/gesture.js +97 -0
- package/runtime/lib/element-template/prop-adapters/gesture.js.map +1 -0
- package/runtime/lib/element-template/prop-adapters/spread.d.ts +6 -1
- package/runtime/lib/element-template/prop-adapters/spread.js +72 -2
- package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
- package/runtime/lib/element-template/protocol/opcodes.d.ts +1 -0
- package/runtime/lib/element-template/protocol/opcodes.js +1 -0
- package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +7 -1
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
- package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js +31 -2
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.d.ts +4 -2
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +17 -4
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +7 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +380 -50
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +3 -2
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js +10 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/typed-attributes.js +3 -3
- package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
- package/runtime/lib/internal.d.ts +1 -1
- package/runtime/lib/internal.js +1 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +2 -125
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/shared/component-stack.d.ts +0 -4
- package/runtime/lib/shared/component-stack.js +21 -5
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
- package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
- package/runtime/lib/snapshot/lifecycle/destroy.js +23 -17
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +5 -0
- package/runtime/lib/snapshot/lifecycle/ref/delay.js +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
- package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
- package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +11 -8
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
- package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +6 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/capture-main-thread-object.ts +2 -1
- package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
- package/runtime/src/core/globalProps.ts +1 -1
- package/runtime/src/core/lynx/lazy-bundle.ts +1 -1
- package/runtime/src/core/lynx-data-processors.ts +124 -1
- package/runtime/src/core/runtime-destroy.ts +1 -1
- package/runtime/src/document.ts +0 -6
- package/runtime/src/element-template/background/attr-slots.ts +5 -1
- package/runtime/src/element-template/background/commit-hook.ts +18 -12
- package/runtime/src/element-template/background/destroy.ts +16 -13
- package/runtime/src/element-template/background/hydrate.ts +23 -0
- package/runtime/src/element-template/client/root.ts +1 -3
- package/runtime/src/element-template/debug/alog.ts +5 -2
- package/runtime/src/element-template/index.ts +2 -2
- package/runtime/src/element-template/internal.ts +1 -20
- package/runtime/src/element-template/lynx/env.ts +1 -1
- package/runtime/src/element-template/native/callDestroyLifetimeFun.ts +5 -1
- package/runtime/src/element-template/native/flush.ts +10 -0
- package/runtime/src/element-template/native/main-thread-api.ts +3 -6
- package/runtime/src/element-template/native/mts-destroy.ts +7 -2
- package/runtime/src/element-template/native/patch-listener.ts +62 -57
- package/runtime/src/element-template/native/reload-background.ts +1 -1
- package/runtime/src/element-template/native/reload-main-thread.ts +32 -11
- package/runtime/src/element-template/prop-adapters/gesture.ts +144 -0
- package/runtime/src/element-template/prop-adapters/spread.ts +110 -2
- package/runtime/src/element-template/protocol/opcodes.ts +1 -0
- package/runtime/src/element-template/protocol/types.ts +8 -13
- package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
- package/runtime/src/element-template/runtime/patch.ts +38 -0
- package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
- package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +31 -4
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
- package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +456 -50
- package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +14 -4
- package/runtime/src/element-template/runtime/template/typed-attributes.ts +3 -3
- package/runtime/src/element-template/types.d.ts +6 -0
- package/runtime/src/internal.ts +1 -1
- package/runtime/src/lynx-api.ts +2 -124
- package/runtime/src/shared/component-stack.ts +22 -5
- package/runtime/src/snapshot/lifecycle/destroy.ts +23 -18
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
- package/runtime/src/snapshot/lifecycle/ref/delay.ts +1 -1
- package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
- package/runtime/src/snapshot/lynx/calledByNative.ts +11 -9
- package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
- package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
- package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
- package/runtime/src/worklet-runtime/README.md +30 -10
- package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
- package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
- package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +6 -0
- package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
- package/runtime/types/types.d.ts +2 -1
- package/runtime/vitest.config.ts +0 -2
- package/testing-library/.turbo/turbo-build.log +7 -7
- package/testing-library/src/__tests__/act.test.jsx +0 -7
- package/testing-library/src/__tests__/alog.test.jsx +12 -54
- package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
- package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
- package/testing-library/src/__tests__/worklet.test.jsx +49 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +133 -297
- package/transform/__test__/defines.spec.js +30 -0
- package/transform/__test__/fixture.spec.js +11 -11
- package/transform/__test__/main-thread-object-compat.spec.js +111 -0
- package/transform/__test__/object-methods.spec.js +79 -0
- package/transform/crates/swc_plugin_element_template/lib.rs +11 -0
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +113 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +63 -57
- package/transform/crates/swc_plugin_worklet/lib.rs +393 -589
- package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +3 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +3 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +11 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +12 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +14 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +17 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +5 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +5 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +1 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +1 -1
- package/transform/dist/wasm.cjs +1 -1
- package/transform/package.json +0 -1
- package/transform/src/lib.rs +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +167 -69
- package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +226 -132
- package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
- package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
- package/runtime/lib/snapshot/worklet/hmr.js +0 -28
- package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
- package/runtime/src/snapshot/worklet/hmr.ts +0 -34
- /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
- /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
|
@@ -2,14 +2,9 @@
|
|
|
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 { Suspense, createElement, lazy } from 'preact/compat';
|
|
6
|
-
// import type { FC } from 'react';
|
|
7
|
-
|
|
8
5
|
import './runtime-marker.js';
|
|
9
6
|
import './native/index.js';
|
|
10
7
|
|
|
11
|
-
// import { factory as factory2 } from '../compat/componentIs.js';
|
|
12
|
-
// import { useMemo } from '../core/hooks/react.js';
|
|
13
8
|
import { __root } from './runtime/page/root-instance.js';
|
|
14
9
|
|
|
15
10
|
/**
|
|
@@ -47,30 +42,16 @@ export { withInitDataInState } from '../core/initData.js';
|
|
|
47
42
|
|
|
48
43
|
export { wrapWithLynxComponent } from '../core/compat/lynxComponent.js';
|
|
49
44
|
|
|
50
|
-
/**
|
|
51
|
-
* @internal a polyfill for <component is=? />
|
|
52
|
-
*/
|
|
53
|
-
// export const __ComponentIsPolyfill: FC<{ is: string }> = /* @__PURE__ */ factory2(
|
|
54
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
55
|
-
// { Suspense, lazy, createElement, useMemo } as any,
|
|
56
|
-
// loadLazyBundle,
|
|
57
|
-
// );
|
|
58
|
-
|
|
59
45
|
export { loadLazyBundle } from '../core/lynx/lazy-bundle.js';
|
|
60
46
|
|
|
61
47
|
export { transformToWorklet } from './runtime/template/main-thread-background-function.js';
|
|
62
48
|
|
|
63
49
|
export { captureMainThreadObject } from '../core/capture-main-thread-object.js';
|
|
64
50
|
|
|
65
|
-
export function registerWorkletOnBackground(
|
|
66
|
-
_type: string,
|
|
67
|
-
_hash: string,
|
|
68
|
-
_fn: (...args: unknown[]) => unknown,
|
|
69
|
-
): void {}
|
|
70
|
-
|
|
71
51
|
export {
|
|
72
52
|
__etAttrPlanMap,
|
|
73
53
|
adaptEventAttrSlot,
|
|
54
|
+
adaptGestureAttrSlot,
|
|
74
55
|
adaptMTEventAttrSlot,
|
|
75
56
|
adaptMTRefAttrSlot,
|
|
76
57
|
adaptRefAttrSlot,
|
|
@@ -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 { createProcessData } from '../../core/lynx-data-processors.js';
|
|
5
|
-
import type { DataProcessorDefinition } from '../../lynx-
|
|
5
|
+
import type { DataProcessorDefinition } from '../../core/lynx-data-processors.js';
|
|
6
6
|
|
|
7
7
|
export function setupLynxEnv(): void {
|
|
8
8
|
if (!__LEPUS__) {
|
|
@@ -6,5 +6,9 @@ import { destroyElementTemplateBackgroundRuntime } from '../background/destroy.j
|
|
|
6
6
|
|
|
7
7
|
export function callDestroyLifetimeFun(): void {
|
|
8
8
|
takeMainThreadRefInitValuePatch();
|
|
9
|
-
|
|
9
|
+
try {
|
|
10
|
+
destroyElementTemplateBackgroundRuntime();
|
|
11
|
+
} finally {
|
|
12
|
+
takeMainThreadRefInitValuePatch();
|
|
13
|
+
}
|
|
10
14
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2026 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 { applyPendingMainThreadRefAttachments } from '../runtime/template/main-thread-dynamic-attr-state.js';
|
|
6
|
+
|
|
7
|
+
export function flushElementTemplate(options: FlushOptions = {}): void {
|
|
8
|
+
applyPendingMainThreadRefAttachments();
|
|
9
|
+
__FlushElementTree(undefined, options);
|
|
10
|
+
}
|
|
@@ -2,6 +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 { flushElementTemplate } from './flush.js';
|
|
5
6
|
import { reloadMainThread } from './reload-main-thread.js';
|
|
6
7
|
import { applyUpdatePageData } from '../../core/lynx-page-data.js';
|
|
7
8
|
import { createElementTemplatePage, setupPage } from '../runtime/page/page.js';
|
|
@@ -38,15 +39,11 @@ function updatePage(data: Record<string, unknown> | undefined, options?: UpdateP
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
applyUpdatePageData(data, options);
|
|
41
|
-
|
|
42
|
+
flushElementTemplate(options);
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
function updateGlobalProps(_data: unknown, options?: UpdatePageOption): void {
|
|
45
|
-
|
|
46
|
-
__FlushElementTree(undefined, options);
|
|
47
|
-
} else {
|
|
48
|
-
__FlushElementTree();
|
|
49
|
-
}
|
|
46
|
+
flushElementTemplate(options);
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
/**
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { resetElementTemplatePatchListener } from './patch-listener.js';
|
|
6
6
|
import { resetElementTemplateRefInitValueListener } from '../main-thread-ref-init-value.js';
|
|
7
7
|
import { destroyAllElementTemplateListStates } from '../runtime/list/list.js';
|
|
8
|
+
import { resetTemplateId } from '../runtime/template/handle.js';
|
|
8
9
|
import { resetElementTemplateMainThreadBackgroundFunctionRuntime } from '../runtime/template/main-thread-background-function.js';
|
|
9
10
|
import { clearMainThreadDynamicAttrState } from '../runtime/template/main-thread-dynamic-attr-state.js';
|
|
10
11
|
import { elementTemplateRegistry } from '../runtime/template/registry.js';
|
|
@@ -40,8 +41,12 @@ export function destroyElementTemplateMainThreadRuntime(): void {
|
|
|
40
41
|
// even if listener reset fails so destroy does not leave removed pages retained.
|
|
41
42
|
destroyAllElementTemplateListStates();
|
|
42
43
|
elementTemplateRegistry.clear();
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
try {
|
|
45
|
+
clearMainThreadDynamicAttrState();
|
|
46
|
+
} finally {
|
|
47
|
+
resetElementTemplateMainThreadBackgroundFunctionRuntime();
|
|
48
|
+
resetTemplateId();
|
|
49
|
+
}
|
|
45
50
|
|
|
46
51
|
if (didPatchListenerResetThrow) {
|
|
47
52
|
throw patchListenerResetError;
|
|
@@ -17,6 +17,7 @@ import { ElementTemplateLifecycleConstant } from '../protocol/lifecycle-constant
|
|
|
17
17
|
import type { ElementTemplateUpdateCommitContext } from '../protocol/types.js';
|
|
18
18
|
import type { ElementTemplateUpdateEvent } from '../protocol/update-event.js';
|
|
19
19
|
import { applyElementTemplateUpdateCommands } from '../runtime/patch.js';
|
|
20
|
+
import { applyPendingMainThreadRefAttachments } from '../runtime/template/main-thread-dynamic-attr-state.js';
|
|
20
21
|
|
|
21
22
|
let listener:
|
|
22
23
|
| ((event: Pick<ElementTemplateUpdateEvent, 'data'>) => void)
|
|
@@ -38,79 +39,83 @@ export function installElementTemplatePatchListener(): void {
|
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
setPipeline(pipelineOptions);
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
try {
|
|
43
|
+
markTiming('mtsRenderStart');
|
|
44
|
+
markTiming('parseChangesStart');
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
const payload = JSON.parse(event.data.payload) as ElementTemplateUpdateCommitContext;
|
|
47
|
+
markTiming('parseChangesEnd');
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
if (
|
|
50
|
+
typeof patchOptions.reloadVersion === 'number'
|
|
51
|
+
&& patchOptions.reloadVersion < getReloadVersion()
|
|
52
|
+
) {
|
|
53
|
+
markTiming('mtsRenderEnd');
|
|
54
|
+
if (shouldProfilePatch) {
|
|
55
|
+
lynx.performance.profileEnd();
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
54
58
|
}
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (hasOps) {
|
|
63
|
-
if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
|
|
64
|
-
console.alog?.(
|
|
65
|
-
'[ReactLynxDebug] ElementTemplate main-thread patch:\n'
|
|
66
|
-
+ JSON.stringify(
|
|
67
|
-
{
|
|
68
|
-
ops: formatElementTemplateUpdateCommands(payload.ops),
|
|
69
|
-
flushOptions,
|
|
70
|
-
flowIds,
|
|
71
|
-
},
|
|
72
|
-
null,
|
|
73
|
-
2,
|
|
74
|
-
),
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
markTiming('patchChangesStart');
|
|
60
|
+
const hasOps = payload.ops.length > 0;
|
|
61
|
+
const flushOptions = payload.flushOptions;
|
|
62
|
+
const isHydration = payload.isHydration === true;
|
|
63
|
+
const delayedRunOnMainThreadData = payload.delayedRunOnMainThreadData;
|
|
78
64
|
try {
|
|
79
|
-
|
|
65
|
+
if (hasOps) {
|
|
66
|
+
if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
|
|
67
|
+
console.alog?.(
|
|
68
|
+
'[ReactLynxDebug] ElementTemplate main-thread patch:\n'
|
|
69
|
+
+ JSON.stringify(
|
|
70
|
+
{
|
|
71
|
+
ops: formatElementTemplateUpdateCommands(payload.ops),
|
|
72
|
+
flushOptions,
|
|
73
|
+
flowIds,
|
|
74
|
+
},
|
|
75
|
+
null,
|
|
76
|
+
2,
|
|
77
|
+
),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
markTiming('patchChangesStart');
|
|
81
|
+
try {
|
|
82
|
+
applyElementTemplateUpdateCommands(payload.ops, isHydration);
|
|
83
|
+
} finally {
|
|
84
|
+
markTiming('patchChangesEnd');
|
|
85
|
+
markTiming('mtsRenderEnd');
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
markTiming('mtsRenderEnd');
|
|
89
|
+
}
|
|
90
|
+
applyPendingMainThreadRefAttachments(isHydration);
|
|
80
91
|
} finally {
|
|
81
|
-
markTiming('patchChangesEnd');
|
|
82
|
-
markTiming('mtsRenderEnd');
|
|
83
92
|
if (isHydration) {
|
|
84
93
|
flushDelayedRunOnBackgroundFunctions();
|
|
85
94
|
clearFirstScreenMainThreadRefs();
|
|
86
95
|
}
|
|
87
96
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
for (const data of delayedRunOnMainThreadData) {
|
|
99
|
-
try {
|
|
100
|
-
runRunOnMainThreadTask(data.worklet, data.params as ClosureValueType[], data.resolveId);
|
|
101
|
-
} catch (error) {
|
|
102
|
-
lynx.reportError(error as Error);
|
|
97
|
+
if (delayedRunOnMainThreadData?.length) {
|
|
98
|
+
setEomShouldFlushElementTree(false);
|
|
99
|
+
try {
|
|
100
|
+
for (const data of delayedRunOnMainThreadData) {
|
|
101
|
+
try {
|
|
102
|
+
runRunOnMainThreadTask(data.worklet, data.params as ClosureValueType[], data.resolveId);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
lynx.reportError(error as Error);
|
|
105
|
+
}
|
|
103
106
|
}
|
|
107
|
+
} finally {
|
|
108
|
+
setEomShouldFlushElementTree(true);
|
|
104
109
|
}
|
|
105
|
-
} finally {
|
|
106
|
-
setEomShouldFlushElementTree(true);
|
|
107
110
|
}
|
|
108
|
-
}
|
|
109
111
|
|
|
110
|
-
|
|
112
|
+
__FlushElementTree(undefined, flushOptions);
|
|
111
113
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
if (shouldProfilePatch) {
|
|
115
|
+
lynx.performance.profileEnd();
|
|
116
|
+
}
|
|
117
|
+
} finally {
|
|
118
|
+
setPipeline(undefined);
|
|
114
119
|
}
|
|
115
120
|
};
|
|
116
121
|
|
|
@@ -39,7 +39,7 @@ export function reloadBackground(updateData: unknown, options?: Record<string, u
|
|
|
39
39
|
// Reload creates a new object so InitData Provider / Consumer observers do
|
|
40
40
|
// not retain the pre-reload object identity.
|
|
41
41
|
lynx.__initData = Object.assign({}, lynx.__initData);
|
|
42
|
-
applyUpdatePageData(updateData);
|
|
42
|
+
applyUpdatePageData(updateData, options);
|
|
43
43
|
|
|
44
44
|
setRoot(new BackgroundPageRootInstance());
|
|
45
45
|
__root.__jsx = jsx;
|
|
@@ -2,6 +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 { flushElementTemplate } from './flush.js';
|
|
5
6
|
import { onMtsDestruction } from './mts-destroy.js';
|
|
6
7
|
import {
|
|
7
8
|
canReEvalMainThreadEntry,
|
|
@@ -37,6 +38,8 @@ export function reloadMainThread(data: unknown, options: UpdatePageOption): void
|
|
|
37
38
|
// TODO: Replace this cleanup-only serialization with a direct page-children
|
|
38
39
|
// or clear-slot PAPI once native exposes one.
|
|
39
40
|
const page = __SerializeElementTemplate(__page) as SerializedPageRoot;
|
|
41
|
+
let cleanupError: unknown;
|
|
42
|
+
let didCleanupThrow = false;
|
|
40
43
|
for (const root of page.childSlots?.[ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX] ?? []) {
|
|
41
44
|
const rootRef = elementTemplateRegistry.get(root.uid)!;
|
|
42
45
|
__RemoveNodeFromElementTemplate(__page, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX, rootRef);
|
|
@@ -45,28 +48,46 @@ export function reloadMainThread(data: unknown, options: UpdatePageOption): void
|
|
|
45
48
|
for (const handleId of removedHandleIds) {
|
|
46
49
|
elementTemplateRegistry.delete(handleId);
|
|
47
50
|
}
|
|
48
|
-
|
|
51
|
+
try {
|
|
52
|
+
deleteMainThreadDynamicAttrStateForSubtree(removedHandleIds);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (!didCleanupThrow) {
|
|
55
|
+
cleanupError = error;
|
|
56
|
+
didCleanupThrow = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
49
59
|
}
|
|
50
60
|
if (canReEvalMainThreadEntry()) {
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
try {
|
|
62
|
+
onMtsDestruction();
|
|
63
|
+
} finally {
|
|
64
|
+
increaseReloadVersion();
|
|
65
|
+
}
|
|
66
|
+
if (didCleanupThrow) {
|
|
67
|
+
throw cleanupError;
|
|
68
|
+
}
|
|
53
69
|
reEvalMainThreadEntry<MainThreadReloadHandoff>({ page: __page, options });
|
|
54
70
|
return;
|
|
55
71
|
}
|
|
56
72
|
elementTemplateRegistry.clear();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
try {
|
|
74
|
+
clearMainThreadDynamicAttrState();
|
|
75
|
+
} finally {
|
|
76
|
+
resetElementTemplateMainThreadBackgroundFunctionRuntime();
|
|
77
|
+
resetTemplateId();
|
|
78
|
+
// Ref cleanup still belongs to the old page. Advance only before rendering
|
|
79
|
+
// the new tree so calls queued by old ref/unmount callbacks remain stale.
|
|
80
|
+
increaseReloadVersion();
|
|
81
|
+
}
|
|
82
|
+
if (didCleanupThrow) {
|
|
83
|
+
throw cleanupError;
|
|
84
|
+
}
|
|
64
85
|
|
|
65
86
|
const oldRoot = __root;
|
|
66
87
|
setRoot({ __jsx: oldRoot.__jsx });
|
|
67
88
|
renderMainThread();
|
|
68
89
|
|
|
69
|
-
|
|
90
|
+
flushElementTemplate(options);
|
|
70
91
|
} finally {
|
|
71
92
|
if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
|
|
72
93
|
profileEnd();
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Copyright 2026 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 { hydrateWorkletCtx } from '@lynx-js/react/worklet-runtime/bindings';
|
|
6
|
+
import type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';
|
|
7
|
+
|
|
8
|
+
import { isMainThreadFunction } from '../../core/main-thread-function.js';
|
|
9
|
+
import {
|
|
10
|
+
registerMainThreadBackgroundFunctionCtx,
|
|
11
|
+
retainMainThreadBackgroundFunctionCtx,
|
|
12
|
+
} from '../runtime/template/main-thread-background-function.js';
|
|
13
|
+
import type { MTEventCtx } from '../runtime/template/main-thread-event-ctx.js';
|
|
14
|
+
|
|
15
|
+
interface GestureInput {
|
|
16
|
+
type: number;
|
|
17
|
+
id: number;
|
|
18
|
+
__isGesture?: boolean;
|
|
19
|
+
__isSerialized?: boolean;
|
|
20
|
+
gestures?: GestureInput[];
|
|
21
|
+
config?: Record<string, unknown>;
|
|
22
|
+
callbacks: Record<string, MTEventCtx | null | undefined>;
|
|
23
|
+
waitFor?: { id: number }[];
|
|
24
|
+
simultaneousWith?: { id: number }[];
|
|
25
|
+
continueWith?: { id: number }[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface GestureDescriptor {
|
|
29
|
+
id: number;
|
|
30
|
+
type: number;
|
|
31
|
+
config: Record<string, unknown>;
|
|
32
|
+
callbacks: { name: string; callback: MTEventCtx }[];
|
|
33
|
+
relationMap: {
|
|
34
|
+
waitFor: number[];
|
|
35
|
+
simultaneous: number[];
|
|
36
|
+
continueWith: number[];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface GestureSlotValue {
|
|
41
|
+
type: 'gesture';
|
|
42
|
+
value: GestureDescriptor[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function isGestureSlotValue(value: unknown): value is GestureSlotValue {
|
|
46
|
+
return value !== null
|
|
47
|
+
&& typeof value === 'object'
|
|
48
|
+
&& !Array.isArray(value)
|
|
49
|
+
&& (value as { type?: unknown }).type === 'gesture'
|
|
50
|
+
&& Array.isArray((value as { value?: unknown }).value);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Provenance stays outside the wire value. A repeated prepare before native
|
|
54
|
+
// delivery must reuse its registered ctx, while mutable Gesture config is copied.
|
|
55
|
+
const callbackSources = new WeakMap<MTEventCtx, MTEventCtx>();
|
|
56
|
+
|
|
57
|
+
export function prepareGestureForNative(
|
|
58
|
+
value: unknown,
|
|
59
|
+
previous?: GestureSlotValue | null,
|
|
60
|
+
): GestureSlotValue | null {
|
|
61
|
+
if (value == null || value === false) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (
|
|
65
|
+
typeof value !== 'object'
|
|
66
|
+
|| !((value as GestureInput).__isGesture === true || (value as GestureInput).__isSerialized === true)
|
|
67
|
+
) {
|
|
68
|
+
throw new Error('ElementTemplate main-thread:gesture expects a Gesture object.');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const descriptors: GestureDescriptor[] = [];
|
|
72
|
+
const seen = new Set<number>();
|
|
73
|
+
function append(gesture: GestureInput): void {
|
|
74
|
+
if (gesture.type === -1) {
|
|
75
|
+
for (const child of gesture.gestures!) {
|
|
76
|
+
append(child);
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (seen.has(gesture.id)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
seen.add(gesture.id);
|
|
84
|
+
const callbacks: GestureDescriptor['callbacks'] = [];
|
|
85
|
+
const previousGesture = previous?.value.find(item => item.id === gesture.id);
|
|
86
|
+
for (const name of Object.keys(gesture.callbacks)) {
|
|
87
|
+
const rawCallback = gesture.callbacks[name];
|
|
88
|
+
if (rawCallback == null) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (!isMainThreadFunction(rawCallback)) {
|
|
92
|
+
throw new Error(`Gesture callback '${name}' must be a main-thread function.`);
|
|
93
|
+
}
|
|
94
|
+
const previousCallback = previousGesture?.callbacks.find(item => item.name === name)?.callback;
|
|
95
|
+
let callback = previousCallback;
|
|
96
|
+
if (!callback || callbackSources.get(callback) !== rawCallback) {
|
|
97
|
+
callback = { ...rawCallback };
|
|
98
|
+
callbackSources.set(callback, rawCallback);
|
|
99
|
+
registerMainThreadBackgroundFunctionCtx(callback);
|
|
100
|
+
}
|
|
101
|
+
callbacks.push({ name, callback });
|
|
102
|
+
}
|
|
103
|
+
descriptors.push({
|
|
104
|
+
id: gesture.id,
|
|
105
|
+
type: gesture.type,
|
|
106
|
+
config: { ...gesture.config },
|
|
107
|
+
callbacks,
|
|
108
|
+
relationMap: {
|
|
109
|
+
waitFor: gesture.waitFor?.map(item => item.id) ?? [],
|
|
110
|
+
simultaneous: gesture.simultaneousWith?.map(item => item.id) ?? [],
|
|
111
|
+
continueWith: gesture.continueWith?.map(item => item.id) ?? [],
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
append(value as GestureInput);
|
|
116
|
+
return { type: 'gesture', value: descriptors };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function retainGestureCallbacks(value: GestureSlotValue): void {
|
|
120
|
+
for (const gesture of value.value) {
|
|
121
|
+
for (const { callback } of gesture.callbacks) {
|
|
122
|
+
retainMainThreadBackgroundFunctionCtx(callback);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function hydrateGestureCallbacks(value: GestureSlotValue, previous: GestureSlotValue): void {
|
|
128
|
+
// IDs belong to independent thread-local allocators. Pair each type in
|
|
129
|
+
// declaration order; the worklet hydrator also checks callback source identity.
|
|
130
|
+
const remaining = previous.value.slice();
|
|
131
|
+
for (const gesture of value.value) {
|
|
132
|
+
const index = remaining.findIndex(old => old.type === gesture.type);
|
|
133
|
+
if (index === -1) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const oldGesture = remaining.splice(index, 1)[0]!;
|
|
137
|
+
for (const { name, callback } of gesture.callbacks) {
|
|
138
|
+
const oldCallback = oldGesture.callbacks.find(item => item.name === name)?.callback;
|
|
139
|
+
if (oldCallback) {
|
|
140
|
+
hydrateWorkletCtx(callback as Worklet, oldCallback as Worklet);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -3,24 +3,51 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
|
|
5
5
|
import { getEventValue } from './event-value.js';
|
|
6
|
+
import { isGestureSlotValue, prepareGestureForNative } from './gesture.js';
|
|
6
7
|
import { prepareSpreadRefAttrValue } from './ref.js';
|
|
8
|
+
import { isMainThreadFunction } from '../../core/main-thread-function.js';
|
|
7
9
|
import { isEventPropKey, isNamespacedEventPropKey, transformAttrName } from '../../shared/attribute-name.js';
|
|
8
10
|
import type { SerializableValue } from '../protocol/types.js';
|
|
11
|
+
import type { EtAttrAdapterContext } from '../runtime/template/attr-slot-plan.js';
|
|
12
|
+
import { prepareMTEventCtxForNative } from '../runtime/template/main-thread-event-ctx.js';
|
|
13
|
+
import { prepareMTRefForNative } from '../runtime/template/main-thread-ref-ctx.js';
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
const MAIN_THREAD_NAMESPACE_PREFIX = 'main-thread:';
|
|
16
|
+
|
|
17
|
+
// Keep per-key raw callback/ref provenance outside the wire value so in-place
|
|
18
|
+
// mutation of a caller-reused spread object cannot alias historical raw values.
|
|
19
|
+
const spreadRawSources = new WeakMap<Record<string, unknown>, Record<string, unknown>>();
|
|
20
|
+
|
|
21
|
+
export function isSpreadRecord(value: unknown): value is Record<string, unknown> {
|
|
11
22
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
12
23
|
}
|
|
13
24
|
|
|
14
|
-
export function
|
|
25
|
+
export function hasOwnSpreadKey(record: Record<string, unknown>, key: string): boolean {
|
|
26
|
+
return Object.prototype.hasOwnProperty.call(record, key);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function isMainThreadEventPropKey(key: string): boolean {
|
|
30
|
+
return key.startsWith(MAIN_THREAD_NAMESPACE_PREFIX)
|
|
31
|
+
&& isEventPropKey(key.slice(MAIN_THREAD_NAMESPACE_PREFIX.length));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function prepareSpreadAttrSlotImpl(
|
|
15
35
|
handleId: number,
|
|
16
36
|
attrSlotIndex: number,
|
|
17
37
|
value: unknown,
|
|
38
|
+
allowMainThreadCapabilities: boolean,
|
|
39
|
+
context?: EtAttrAdapterContext,
|
|
18
40
|
): SerializableValue | null {
|
|
19
41
|
if (value === false || !isSpreadRecord(value)) {
|
|
20
42
|
return null;
|
|
21
43
|
}
|
|
22
44
|
|
|
45
|
+
const prevPreparedSlot = context?.previousPreparedSlots?.[attrSlotIndex];
|
|
46
|
+
const prevPreparedRecord = isSpreadRecord(prevPreparedSlot) ? prevPreparedSlot : undefined;
|
|
47
|
+
const prevRawSources = prevPreparedRecord ? spreadRawSources.get(prevPreparedRecord) : undefined;
|
|
48
|
+
|
|
23
49
|
const prepared: Record<string, SerializableValue> = {};
|
|
50
|
+
let rawSources: Record<string, unknown> | undefined;
|
|
24
51
|
|
|
25
52
|
for (const key in value) {
|
|
26
53
|
const spreadValue = value[key];
|
|
@@ -41,6 +68,66 @@ export function prepareSpreadAttrSlot(
|
|
|
41
68
|
continue;
|
|
42
69
|
}
|
|
43
70
|
|
|
71
|
+
if (allowMainThreadCapabilities) {
|
|
72
|
+
if (key === 'main-thread:ref') {
|
|
73
|
+
if (!hasOwnSpreadKey(value, key)) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const preparedRef = prepareMTRefForNative(
|
|
77
|
+
spreadValue,
|
|
78
|
+
prevPreparedRecord?.[key],
|
|
79
|
+
prevRawSources?.[key],
|
|
80
|
+
);
|
|
81
|
+
prepared[key] = preparedRef;
|
|
82
|
+
if (preparedRef !== null) {
|
|
83
|
+
(rawSources ??= Object.create(null) as Record<string, unknown>)[key] = spreadValue;
|
|
84
|
+
}
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (key === 'main-thread:gesture') {
|
|
89
|
+
if (!hasOwnSpreadKey(value, key)) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const prevGesture = prevPreparedRecord && hasOwnSpreadKey(prevPreparedRecord, key)
|
|
93
|
+
? prevPreparedRecord[key]
|
|
94
|
+
: undefined;
|
|
95
|
+
prepared[key] = prepareGestureForNative(
|
|
96
|
+
spreadValue,
|
|
97
|
+
isGestureSlotValue(prevGesture) ? prevGesture : undefined,
|
|
98
|
+
) as unknown as SerializableValue;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (isMainThreadEventPropKey(key)) {
|
|
103
|
+
if (!hasOwnSpreadKey(value, key)) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (spreadValue === null || spreadValue === undefined || spreadValue === false) {
|
|
107
|
+
prepared[key] = null;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (!isMainThreadFunction(spreadValue)) {
|
|
111
|
+
if (__DEV__) {
|
|
112
|
+
lynx.reportError(
|
|
113
|
+
new Error(
|
|
114
|
+
`ElementTemplate main-thread event slot ${handleId}:${attrSlotIndex} (${key}) expects a worklet ctx object.`,
|
|
115
|
+
),
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
prepared[key] = null;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
prepared[key] = prepareMTEventCtxForNative(
|
|
122
|
+
spreadValue,
|
|
123
|
+
prevPreparedRecord?.[key],
|
|
124
|
+
prevRawSources?.[key],
|
|
125
|
+
);
|
|
126
|
+
(rawSources ??= Object.create(null) as Record<string, unknown>)[key] = spreadValue;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
44
131
|
const transformedKey = transformAttrName(key);
|
|
45
132
|
if (isEventPropKey(transformedKey)) {
|
|
46
133
|
prepared[transformedKey] = spreadValue === null || spreadValue === undefined || spreadValue === false
|
|
@@ -62,5 +149,26 @@ export function prepareSpreadAttrSlot(
|
|
|
62
149
|
prepared[transformedKey] = spreadValue as SerializableValue;
|
|
63
150
|
}
|
|
64
151
|
|
|
152
|
+
if (rawSources) {
|
|
153
|
+
spreadRawSources.set(prepared, rawSources);
|
|
154
|
+
}
|
|
155
|
+
|
|
65
156
|
return prepared;
|
|
66
157
|
}
|
|
158
|
+
|
|
159
|
+
export function prepareSpreadAttrSlot(
|
|
160
|
+
handleId: number,
|
|
161
|
+
attrSlotIndex: number,
|
|
162
|
+
value: unknown,
|
|
163
|
+
context?: EtAttrAdapterContext,
|
|
164
|
+
): SerializableValue | null {
|
|
165
|
+
return prepareSpreadAttrSlotImpl(handleId, attrSlotIndex, value, true, context);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function prepareTypedSpreadAttrSlot(
|
|
169
|
+
handleId: number,
|
|
170
|
+
attrSlotIndex: number,
|
|
171
|
+
value: unknown,
|
|
172
|
+
): SerializableValue | null {
|
|
173
|
+
return prepareSpreadAttrSlotImpl(handleId, attrSlotIndex, value, false);
|
|
174
|
+
}
|
|
@@ -13,6 +13,7 @@ export const ElementTemplateUpdateOps = {
|
|
|
13
13
|
updateTypedListItem: 8,
|
|
14
14
|
setMainThreadEvent: 9,
|
|
15
15
|
setMainThreadRef: 10,
|
|
16
|
+
setGesture: 11,
|
|
16
17
|
} as const;
|
|
17
18
|
|
|
18
19
|
export type ElementTemplateUpdateOp = typeof ElementTemplateUpdateOps[keyof typeof ElementTemplateUpdateOps];
|