@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,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 { sExportsLegacyReactRuntime, target } from './target';
|
|
5
|
+
import { sExportsLegacyReactRuntime, target } from './target.js';
|
|
6
6
|
|
|
7
7
|
export const {
|
|
8
8
|
Component,
|
|
@@ -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 { sExportsReactLepus, target } from './target';
|
|
5
|
+
import { sExportsReactLepus, target } from './target.js';
|
|
6
6
|
|
|
7
7
|
export const {
|
|
8
8
|
createElement,
|
package/runtime/lazy/react.js
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
|
|
|
5
|
-
import { sExportsReact, target } from './target';
|
|
5
|
+
import { sExportsReact, target } from './target.js';
|
|
6
6
|
|
|
7
7
|
export const {
|
|
8
8
|
Children,
|
|
@@ -6,7 +6,8 @@ import { isMainThreadObjectHandle } from './main-thread-object-handle-registry.j
|
|
|
6
6
|
* Preserve opaque main-thread object handles when the worklet transform narrows a
|
|
7
7
|
* captured member expression. Ordinary objects keep the transform's compact
|
|
8
8
|
* fallback shape. The transform evaluates that shape lazily with
|
|
9
|
-
* `captureMainThreadObject(source) ?? fallback
|
|
9
|
+
* `captureMainThreadObject(source) ?? fallback` (and guards optional-chain
|
|
10
|
+
* bases with `source == null ? source : ...`).
|
|
10
11
|
*
|
|
11
12
|
* @internal
|
|
12
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture-main-thread-object.js","sourceRoot":"","sources":["../../src/core/capture-main-thread-object.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AAEnF
|
|
1
|
+
{"version":3,"file":"capture-main-thread-object.js","sourceRoot":"","sources":["../../src/core/capture-main-thread-object.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AAEnF;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CAAI,MAAS;IAClD,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/D,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { isMainThreadObjectHandle } from './main-thread-object-handle-registry.js';\n\n/**\n * Preserve opaque main-thread object handles when the worklet transform narrows a\n * captured member expression. Ordinary objects keep the transform's compact\n * fallback shape. The transform evaluates that shape lazily with\n * `captureMainThreadObject(source) ?? fallback` (and guards optional-chain\n * bases with `source == null ? source : ...`).\n *\n * @internal\n */\nexport function captureMainThreadObject<T>(source: T): T | undefined {\n return isMainThreadObjectHandle(source) ? source : undefined;\n}\n"]}
|
|
@@ -14,7 +14,7 @@ export { ComponentFromReactRuntime as Component } from './lynxComponent.js';
|
|
|
14
14
|
export { ComponentFromReactRuntime as PureComponent } from './lynxComponent.js';
|
|
15
15
|
export { createContext } from 'preact';
|
|
16
16
|
export { lazy } from 'preact/compat';
|
|
17
|
-
export { useState, useReducer, useEffect, useMemo, useCallback
|
|
17
|
+
export { useState, useReducer, useEffect, useMemo, useCallback } from '../hooks/react.js';
|
|
18
18
|
export { __runInJS, createRef, useRef };
|
|
19
19
|
/**
|
|
20
20
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy-react-runtime.js","sourceRoot":"","sources":["../../../src/core/compat/legacy-react-runtime.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,OAAO,EAAE,yBAAyB,IAAI,SAAS,EAAE,yBAAyB,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElG,sBAAsB;AACtB,SAAS,SAAS,CAAI,KAAQ;IAC5B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,iDAAiD;AACjD,OAAO,EAAE,yBAAyB,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,yBAAyB,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"legacy-react-runtime.js","sourceRoot":"","sources":["../../../src/core/compat/legacy-react-runtime.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,OAAO,EAAE,yBAAyB,IAAI,SAAS,EAAE,yBAAyB,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElG,sBAAsB;AACtB,SAAS,SAAS,CAAI,KAAQ;IAC5B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,iDAAiD;AACjD,OAAO,EAAE,yBAAyB,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,yBAAyB,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AAExC;;GAEG;AACH,eAAe;IACb,SAAS;IACT,aAAa;IACb,aAAa;IACb,SAAS;IACT,IAAI;IACJ,QAAQ;IACR,UAAU;IACV,MAAM;IACN,SAAS;IACT,OAAO;IACP,WAAW;IACX,SAAS;CACV,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { createContext, createRef } from 'preact';\nimport { lazy } from 'preact/compat';\n\nimport { ComponentFromReactRuntime as Component, ComponentFromReactRuntime as PureComponent } from './lynxComponent.js';\nimport { useCallback, useEffect, useMemo, useReducer, useRef, useState } from '../hooks/react.js';\n\n/* v8 ignore next 3 */\nfunction __runInJS<T>(value: T): T | undefined | null {\n return value;\n}\n\n// should mirror @lynx-js/react-runtime's exports\nexport { ComponentFromReactRuntime as Component } from './lynxComponent.js';\nexport { ComponentFromReactRuntime as PureComponent } from './lynxComponent.js';\nexport { createContext } from 'preact';\nexport { lazy } from 'preact/compat';\nexport { useState, useReducer, useEffect, useMemo, useCallback } from '../hooks/react.js';\nexport { __runInJS, createRef, useRef };\n\n/**\n * @internal\n */\nexport default {\n Component,\n PureComponent,\n createContext,\n createRef,\n lazy,\n useState,\n useReducer,\n useRef,\n useEffect,\n useMemo,\n useCallback,\n __runInJS,\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { factory } from './initData.js';
|
|
2
2
|
export function isGlobalPropsEventMode() {
|
|
3
|
-
return
|
|
3
|
+
return lynx.__runtime_configs__?.globalPropsMode === 'event';
|
|
4
4
|
}
|
|
5
5
|
export function createGlobalProps(deps) {
|
|
6
6
|
return isGlobalPropsEventMode()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalProps.js","sourceRoot":"","sources":["../../src/core/globalProps.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAiCxC,MAAM,UAAU,sBAAsB;IACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"globalProps.js","sourceRoot":"","sources":["../../src/core/globalProps.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAiCxC,MAAM,UAAU,sBAAsB;IACpC,OAAO,IAAI,CAAC,mBAAmB,EAAE,eAAe,KAAK,OAAO,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,IAA4B;IAE5B,OAAO,sBAAsB,EAAE;QAC7B,CAAC,CAAC,eAAe,CAAC,OAAO,CACvB,IAAI,EACJ,eAAe,EACf,sBAAsB,CACvB;QACD,CAAC,CAAC,eAAe,CAAC,yBAA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AS,yBAAyB,CAChC,WAA8C;IAE9C,MAAM,UAAU,GAAG,CAAC,QAA8B,EAAQ,EAAE;QAC1D,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,EAAE,CAAC;YACnD,WAAW,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,GAAG,EAAE,CAAC,gBAAgB;QAChC,QAAQ,EAAE,GAAG,EAAE,CAAC,gBAAkC;QAClD,GAAG,EAAE,GAAG,EAAE,CAAC,sBAAoC;QAC/C,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport type { ComponentChildren, Consumer, Provider } from 'preact';\n\nimport type { useLynxGlobalEventListener } from './hooks/useLynxGlobalEventListener.js';\nimport { factory } from './initData.js';\n\ntype Getter<T> = {\n [key in keyof T]: () => T[key];\n};\n\ninterface GlobalPropsRuntimeDeps {\n createContext: typeof import('preact').createContext;\n useState: typeof import('preact/hooks').useState;\n createElement: typeof import('preact/compat').createElement;\n useLynxGlobalEventListener: typeof useLynxGlobalEventListener;\n}\n\ninterface GlobalPropsApi<Data> {\n Provider: Provider<Data>;\n Consumer: Consumer<Data>;\n use: () => Data;\n useChanged: (callback: (data: Data) => void) => void;\n}\n\n/**\n * The interface you can extends so that the `useGlobalProps` returning value can be customized\n *\n * @public\n *\n * @group Types\n */\nexport interface GlobalProps {}\n\nexport interface UpdateGlobalPropsOptions {\n forceRerender?: (() => void) | undefined;\n}\n\nexport function isGlobalPropsEventMode(): boolean {\n return lynx.__runtime_configs__?.globalPropsMode === 'event';\n}\n\nexport function createGlobalProps<Data = GlobalProps>(\n deps: GlobalPropsRuntimeDeps,\n): Getter<GlobalPropsApi<Data>> {\n return isGlobalPropsEventMode()\n ? /* @__PURE__ */ factory<Data>(\n deps,\n '__globalProps',\n 'onGlobalPropsChanged',\n )\n : /* @__PURE__ */ createFallbackGlobalProps<Data>(deps.useLynxGlobalEventListener);\n}\n\nexport function updateGlobalProps(\n newData: Record<string, any>,\n { forceRerender }: UpdateGlobalPropsOptions = {},\n): void {\n if (isGlobalPropsEventMode()) {\n // COW keeps Provider / Consumer state readers aligned in event mode.\n lynx.__globalProps = Object.assign({}, lynx.__globalProps, newData);\n } else {\n Object.assign(lynx.__globalProps, newData);\n if (forceRerender) {\n void Promise.resolve().then(forceRerender);\n }\n }\n\n lynx.getApp().GlobalEventEmitter.emit('onGlobalPropsChanged', [lynx.__globalProps]);\n}\n\nfunction warnGlobalPropsMode(): void {\n if (typeof __LEPUS__ !== 'undefined' && !__LEPUS__ && typeof __DEV__ !== 'undefined' && __DEV__) {\n console.warn(\n `No need to use this API when 'globalPropsMode' is not 'event', `\n + `updates will be triggered automatically by full re-render. `\n + `Please set 'globalPropsMode' to 'event' to enable optimized updates.`,\n );\n }\n}\n\nfunction FallbackProvider({ children }: { children?: ComponentChildren | undefined }): ComponentChildren {\n warnGlobalPropsMode();\n return children;\n}\n\nfunction FallbackConsumer<Data>({ children }: { children: (data: Data) => ComponentChildren }): ComponentChildren {\n warnGlobalPropsMode();\n return children(lynx.__globalProps as Data);\n}\n\nfunction useFallbackGlobalProps<Data>(): Data {\n warnGlobalPropsMode();\n return lynx.__globalProps as Data;\n}\n\nfunction createFallbackGlobalProps<Data>(\n useListener: typeof useLynxGlobalEventListener,\n): Getter<GlobalPropsApi<Data>> {\n const useChanged = (callback: (data: Data) => void): void => {\n if (typeof __LEPUS__ === 'undefined' || !__LEPUS__) {\n useListener('onGlobalPropsChanged', callback);\n }\n };\n\n return {\n Provider: () => FallbackProvider,\n Consumer: () => FallbackConsumer as Consumer<Data>,\n use: () => useFallbackGlobalProps as () => Data,\n useChanged: () => useChanged,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
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,CAAC;oBAAC,OAAO,CAAC,EAAE,CAAC;wBACX,MAAM,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBACxD,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,EAAE,CAAC;AAEL,SAAS,iBAAiB;IACxB,iBAAiB,CAAC;IAElB,MAAM,QAAQ,GAKV;QACF,OAAO,EAAE,CAAC,MAAS,EAAQ,EAAE;YAC3B,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QAC3B,CAAC;QACD,MAAM,EAAE,CAAC,KAAY,EAAQ,EAAE;YAC7B,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;QACzB,CAAC;QACD,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,IAAI;KACZ,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n// Inlined rather than imported from `snapshot/` so this `core/` module stays\n// free of runtime-backend dependencies (enforced by\n// `guardrails/snapshot-containment`). `PREPARE_LAZY_BUNDLE_MTS` must stay in\n// sync with `snapshot/lifecycle/constant.ts`'s\n// `LifecycleConstant.prepareLazyBundleMTS`, the lifecycle name the snapshot\n// backend registers the main-thread prepare handler under.\nconst SECTION_MAIN_THREAD = 'main-thread';\nconst SECTION_BACKGROUND = 'background';\nconst SECTION_CSS = 'CSS';\nconst LYNX_LAZY_SYNC_TIMEOUT_SECONDS = 5;\nconst PREPARE_LAZY_BUNDLE_MTS = 'rLynxPrepareLazyBundleMTS';\n\n// Background-thread dedup cache: a `source` whose FetchBundle load fully\n// succeeded maps to its exports, so a repeat load returns the same result\n// without re-fetching or re-triggering the main-thread prepare. Only populated\n// on success — a failed load stays out of the cache and can be retried, exactly\n// like `prepareLazyBundleMTS`'s main-thread cache.\nconst fetchBundleBgCache = new Map<string, unknown>();\n\n/**\n * To make code below works\n * const App1 = lazy(() => import(\"./x\").then(({App1}) => ({default: App1})))\n * const App2 = lazy(() => import(\"./x\").then(({App2}) => ({default: App2})))\n * @internal\n */\nexport const makeSyncThen = function<T>(result: T): Promise<T>['then'] {\n return function<TR1 = T, TR2 = never>(\n this: Promise<T>,\n onF?: ((value: T) => TR1 | PromiseLike<TR1>) | null,\n _onR?: ((reason: any) => TR2 | PromiseLike<TR2>) | null,\n ): Promise<TR1 | TR2> {\n if (onF) {\n let ret: TR1 | PromiseLike<TR1>;\n try {\n ret = onF(result);\n } catch (e) {\n // if (onR) {\n // return Promise.resolve(onR(e));\n // }\n return Promise.reject(e as Error);\n }\n\n if (ret && typeof (ret as PromiseLike<TR1>).then === 'function' /* `thenable` object */) {\n // lazy(() =>\n // import(\"./x\").then(() => new Promise(...))\n // )\n // Calling `then` and passing a callback is standard behavior\n // but in Lepus runtime the callback will never be called\n // So can be simplified to code below\n return ret as Promise<TR1>;\n\n // TODO(hongzhiyuan.hzy): Avoid warning that cannot be turned-off, so the warning is commented\n // lynx.reportError(\n // new Error(\n // 'You returned a Promise in promise-chain of lazy-bundle import (eg. `import(\"./x\").then(() => new Promise(...))`), which will cause related Component unavailable at first-screen, '\n // ),\n // { level: \"warning\" }\n // );\n }\n\n // The Lynx Promise polyfill shares resolved promises for primitive values.\n // Own this promise before replacing `then`, or an undefined callback\n // result would make unrelated Promise.resolve().then(...) calls synchronous.\n const p = new Promise<TR1>(resolve => resolve(ret));\n\n const then = makeSyncThen(ret as TR1);\n p.then = then as Promise<Awaited<TR1>>['then'];\n\n return p as Promise<TR1 | TR2>;\n }\n\n return this as Promise<TR1 | TR2>;\n };\n};\n\nexport type LazyBundleMode = 'sync' | 'async';\n\n// loadScript a background section with `globalThis.globDynamicComponentEntry`\n// set to `entry` (restored after). The bundle's wrapper reads it once as\n// `g.globDynamicComponentEntry || '__Card__'`, so without this its modules — and\n// any nested `import()` it triggers — would resolve against the caller's host.\nfunction loadBackgroundBundle<T>(bundleName: string, entry: string): T {\n const g = globalThis as { globDynamicComponentEntry?: string | undefined };\n const previous = g.globDynamicComponentEntry;\n g.globDynamicComponentEntry = entry;\n try {\n return lynx.loadScript<T>(SECTION_BACKGROUND, { bundleName });\n } finally {\n g.globDynamicComponentEntry = previous;\n }\n}\n\n/**\n * Load dynamic component from source. Designed to be used with `lazy`.\n *\n * The `mode` is threaded in by the chunk-loading runtime from the\n * `import(..., { with: { mode } })` import attribute (see `lynx_acm`), so each\n * lazy import carries its own mode instead of relying on shared mutable state.\n * @param source - where dynamic component template.js locates\n * @param mode - `'sync'` (first-screen blocking) or `'async'` (default)\n * @returns\n * @public\n */\nexport const loadLazyBundle: <\n T extends { default: React.ComponentType<any> },\n>(source: string, mode?: LazyBundleMode, host?: string) => Promise<T> = /*#__PURE__*/ (() => {\n // Default to QueryComponent when `__LAZY_BUNDLE_FETCHER__` is missing —\n // older react-webpack-plugin builds don't stamp it and they predate\n // FetchBundle support, so falling through to QueryComponent is the only\n // safe behavior.\n const useFetchBundle = typeof __LAZY_BUNDLE_FETCHER__ !== 'undefined'\n && __LAZY_BUNDLE_FETCHER__ === 'FetchBundle';\n\n const impl = useFetchBundle\n ? loadLazyBundleWithFetchBundle\n : loadLazyBundleWithQueryComponent;\n\n lynx.loadLazyBundle = impl;\n\n function loadLazyBundleWithQueryComponent<\n T extends { default: React.ComponentType<any> },\n >(source: string, mode?: LazyBundleMode): Promise<T> {\n if (__LEPUS__) {\n const query = __QueryComponent(source);\n let result: T;\n try {\n result = query.evalResult as T;\n } catch (e) {\n // Here we cannot return a rejected promise\n // (which will eventually be an unhandled rejection and cause unnecessary redbox)\n // But we still need a object in shape of Promise\n // So we return a Promise which will never resolve or reject,\n // which fit our principle \"lepus run only once at first-screen\" better\n return new Promise(() => {});\n }\n const r: Promise<T> = Promise.resolve(result);\n // Why we should modify the implementation of `then`?\n // We should make it `sync` so lepus first-screen render can use result above instantly\n // We also should keep promise shape\n r.then = makeSyncThen(result);\n return r;\n } else if (__JS__) {\n if (__DEV__ && mode !== undefined) {\n throw new Error(\n `Lazy bundle import \\`mode: '${mode}'\\` requires FetchBundle, but the current build uses QueryComponent. `\n + `Set \\`engineVersion: '3.9'\\` (or higher) in \\`pluginReactLynx\\` to enable FetchBundle.`,\n );\n }\n const resolver = withSyncResolvers<T>();\n\n const callback: (result: { code: number; detail: { schema: string } }) => void = result => {\n const { code, detail } = result;\n if (code === 0) {\n const { schema } = detail;\n const exports = lynx.getApp().getDynamicComponentExports(schema);\n // `code === 0` means that the lazy bundle has been successfully parsed. However,\n // its javascript files may still fail to run, which would prevent the retrieval of the exports object.\n if (exports) {\n resolver.resolve(exports as T);\n return;\n }\n }\n const e = new Error('Lazy bundle load failed, schema: ' + result.detail.schema);\n // ES5 does not support new Error('message', { cause: 'detail' })\n // So we set cause using `.cause` assignment\n e.cause = JSON.stringify(result);\n resolver.reject(e);\n };\n if (typeof lynx.QueryComponent === 'function') {\n lynx.QueryComponent(source, callback);\n } else {\n lynx.getNativeLynx().QueryComponent!(source, callback);\n }\n\n if (resolver.result !== null) {\n const p = Promise.resolve(resolver.result);\n p.then = makeSyncThen(resolver.result) as Promise<Awaited<T>>['then'];\n return p;\n } else if (resolver.error === null) {\n return new Promise((_resolve, _reject) => {\n resolver.resolve = _resolve;\n resolver.reject = _reject;\n });\n } else {\n return Promise.reject(resolver.error);\n }\n }\n\n throw new Error('unreachable');\n }\n\n function loadLazyBundleWithFetchBundle<\n T extends { default: React.ComponentType<any> },\n >(source: string, mode?: LazyBundleMode, host?: string): Promise<T> {\n if (__MAIN_THREAD__) {\n if (mode !== 'sync') {\n // Fire the fetch and ignore the result so the request goes out early\n // and warms the native bundle cache; the background `async` path then\n // waits less. The main thread renders nothing here.\n try {\n lynx.fetchBundle(source, {});\n } catch {}\n return new Promise(() => {});\n }\n let response;\n try {\n response = lynx.fetchBundle(source, {}).wait(\n LYNX_LAZY_SYNC_TIMEOUT_SECONDS,\n );\n } catch {\n return new Promise(() => {});\n }\n if (!response || response.code !== 0) {\n return new Promise(() => {});\n }\n let result: T;\n try {\n result = lynx.loadScript<(entry: string) => T>(SECTION_MAIN_THREAD, {\n bundleName: response.url,\n })(source);\n const styleSheet = __LoadStyleSheet(SECTION_CSS, response.url);\n if (styleSheet !== null) {\n __AdoptStyleSheet(styleSheet);\n }\n } catch {\n return new Promise(() => {});\n }\n const r: Promise<T> = Promise.resolve(result);\n r.then = makeSyncThen(result);\n return r;\n } else if (__JS__) {\n const cached = fetchBundleBgCache.get(source);\n if (cached !== undefined) {\n const r: Promise<T> = Promise.resolve(cached as T);\n r.then = makeSyncThen(cached as T);\n return r;\n }\n if (mode === 'sync') {\n let response;\n try {\n response = lynx.fetchBundle(source, {}).wait(\n LYNX_LAZY_SYNC_TIMEOUT_SECONDS,\n );\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n if (!response || response.code !== 0) {\n console.error('Lazy bundle load failed', response);\n const e = new Error('Lazy bundle load failed, schema: ' + source);\n e.cause = JSON.stringify(response);\n return Promise.reject(e);\n }\n let result: T;\n try {\n result = loadBackgroundBundle<T>(response.url, source);\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n // A sync bundle that wasn't part of the first-screen main-thread render\n // still needs its main-thread section prepared on the MT (the\n // createSnapshot side effect), or a later patch referencing it hits\n // \"snapshot not found\". Runs synchronously — the bundle is already in\n // the native cache — just like the async path below.\n try {\n lynx.getNativeApp().callLepusMethod(\n PREPARE_LAZY_BUNDLE_MTS,\n { url: source, host },\n () => {},\n );\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n // Fully loaded and prepared — cache so repeat loads skip the work above.\n fetchBundleBgCache.set(source, result);\n const r: Promise<T> = Promise.resolve(result);\n r.then = makeSyncThen(result);\n return r;\n }\n\n // async (default)\n return new Promise<T>((resolve, reject) => {\n let handler;\n try {\n handler = lynx.fetchBundle(source, {});\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n return;\n }\n handler.then((response) => {\n if (!response || response.code !== 0) {\n console.error('Lazy bundle load failed', response);\n const e = new Error('Lazy bundle load failed, schema: ' + source);\n e.cause = JSON.stringify(response);\n reject(e);\n return;\n }\n let btsResult: T;\n try {\n btsResult = loadBackgroundBundle<T>(response.url, source);\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n return;\n }\n // Bundle is now in native cache, so MT's `.then` fires sync and\n // the whole prepare runs synchronously inside `Call`, meaning the\n // cb fires only after MT snapshots are registered.\n try {\n lynx.getNativeApp().callLepusMethod(\n PREPARE_LAZY_BUNDLE_MTS,\n { url: source, host },\n () => {\n // Fully loaded and MT-prepared — cache so repeat loads skip\n // the fetch / background eval / MT prepare above.\n fetchBundleBgCache.set(source, btsResult);\n resolve(btsResult);\n },\n );\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n }\n });\n });\n }\n\n throw new Error('unreachable');\n }\n\n return impl;\n})();\n\nfunction withSyncResolvers<T>() {\n 'background-only';\n\n const resolver: {\n result: T | null;\n error: Error | null;\n resolve(result: T): void;\n reject(error: Error): void;\n } = {\n resolve: (result: T): void => {\n resolver.result = result;\n },\n reject: (error: Error): void => {\n resolver.error = error;\n },\n result: null,\n error: null,\n };\n\n return resolver;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lazy-bundle.js","sourceRoot":"","sources":["../../../src/core/lynx/lazy-bundle.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,6EAA6E;AAC7E,oDAAoD;AACpD,6EAA6E;AAC7E,+CAA+C;AAC/C,4EAA4E;AAC5E,2DAA2D;AAC3D,MAAM,mBAAmB,GAA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AC;QAED,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,EAAE,CAAC;AAEL,SAAS,iBAAiB;IACxB,iBAAiB,CAAC;IAElB,MAAM,QAAQ,GAKV;QACF,OAAO,EAAE,CAAC,MAAS,EAAQ,EAAE;YAC3B,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QAC3B,CAAC;QACD,MAAM,EAAE,CAAC,KAAY,EAAQ,EAAE;YAC7B,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;QACzB,CAAC;QACD,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,IAAI;KACZ,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n// Inlined rather than imported from `snapshot/` so this `core/` module stays\n// free of runtime-backend dependencies (enforced by\n// `guardrails/snapshot-containment`). `PREPARE_LAZY_BUNDLE_MTS` must stay in\n// sync with `snapshot/lifecycle/constant.ts`'s\n// `LifecycleConstant.prepareLazyBundleMTS`, the lifecycle name the snapshot\n// backend registers the main-thread prepare handler under.\nconst SECTION_MAIN_THREAD = 'main-thread';\nconst SECTION_BACKGROUND = 'background';\nconst SECTION_CSS = 'CSS';\nconst LYNX_LAZY_SYNC_TIMEOUT_SECONDS = 5;\nconst PREPARE_LAZY_BUNDLE_MTS = 'rLynxPrepareLazyBundleMTS';\n\n// Background-thread dedup cache: a `source` whose FetchBundle load fully\n// succeeded maps to its exports, so a repeat load returns the same result\n// without re-fetching or re-triggering the main-thread prepare. Only populated\n// on success — a failed load stays out of the cache and can be retried, exactly\n// like `prepareLazyBundleMTS`'s main-thread cache.\nconst fetchBundleBgCache = new Map<string, unknown>();\n\n/**\n * To make code below works\n * const App1 = lazy(() => import(\"./x\").then(({App1}) => ({default: App1})))\n * const App2 = lazy(() => import(\"./x\").then(({App2}) => ({default: App2})))\n * @internal\n */\nexport const makeSyncThen = function<T>(result: T): Promise<T>['then'] {\n return function<TR1 = T, TR2 = never>(\n this: Promise<T>,\n onF?: ((value: T) => TR1 | PromiseLike<TR1>) | null,\n _onR?: ((reason: any) => TR2 | PromiseLike<TR2>) | null,\n ): Promise<TR1 | TR2> {\n if (onF) {\n let ret: TR1 | PromiseLike<TR1>;\n try {\n ret = onF(result);\n } catch (e) {\n // if (onR) {\n // return Promise.resolve(onR(e));\n // }\n return Promise.reject(e as Error);\n }\n\n if (ret && typeof (ret as PromiseLike<TR1>).then === 'function' /* `thenable` object */) {\n // lazy(() =>\n // import(\"./x\").then(() => new Promise(...))\n // )\n // Calling `then` and passing a callback is standard behavior\n // but in Lepus runtime the callback will never be called\n // So can be simplified to code below\n return ret as Promise<TR1>;\n\n // TODO(hongzhiyuan.hzy): Avoid warning that cannot be turned-off, so the warning is commented\n // lynx.reportError(\n // new Error(\n // 'You returned a Promise in promise-chain of lazy-bundle import (eg. `import(\"./x\").then(() => new Promise(...))`), which will cause related Component unavailable at first-screen, '\n // ),\n // { level: \"warning\" }\n // );\n }\n\n // The Lynx Promise polyfill shares resolved promises for primitive values.\n // Own this promise before replacing `then`, or an undefined callback\n // result would make unrelated Promise.resolve().then(...) calls synchronous.\n const p = new Promise<TR1>(resolve => resolve(ret));\n\n const then = makeSyncThen(ret as TR1);\n p.then = then as Promise<Awaited<TR1>>['then'];\n\n return p as Promise<TR1 | TR2>;\n }\n\n return this as Promise<TR1 | TR2>;\n };\n};\n\nexport type LazyBundleMode = 'sync' | 'async';\n\n// loadScript a background section with `globalThis.globDynamicComponentEntry`\n// set to `entry` (restored after). The bundle's wrapper reads it once as\n// `g.globDynamicComponentEntry || '__Card__'`, so without this its modules — and\n// any nested `import()` it triggers — would resolve against the caller's host.\nfunction loadBackgroundBundle<T>(bundleName: string, entry: string): T {\n const g = globalThis as { globDynamicComponentEntry?: string | undefined };\n const previous = g.globDynamicComponentEntry;\n g.globDynamicComponentEntry = entry;\n try {\n return lynx.loadScript<T>(SECTION_BACKGROUND, { bundleName });\n } finally {\n g.globDynamicComponentEntry = previous;\n }\n}\n\n/**\n * Load dynamic component from source. Designed to be used with `lazy`.\n *\n * The `mode` is threaded in by the chunk-loading runtime from the\n * `import(..., { with: { mode } })` import attribute (see `lynx_acm`), so each\n * lazy import carries its own mode instead of relying on shared mutable state.\n * @param source - where dynamic component template.js locates\n * @param mode - `'sync'` (first-screen blocking) or `'async'` (default)\n * @returns\n * @public\n */\nexport const loadLazyBundle: <\n T extends { default: React.ComponentType<any> },\n>(source: string, mode?: LazyBundleMode, host?: string) => Promise<T> = /*#__PURE__*/ (() => {\n // Default to QueryComponent when `__LAZY_BUNDLE_FETCHER__` is missing —\n // older react-webpack-plugin builds don't stamp it and they predate\n // FetchBundle support, so falling through to QueryComponent is the only\n // safe behavior.\n const useFetchBundle = typeof __LAZY_BUNDLE_FETCHER__ !== 'undefined'\n && __LAZY_BUNDLE_FETCHER__ === 'FetchBundle';\n\n const impl = useFetchBundle\n ? loadLazyBundleWithFetchBundle\n : loadLazyBundleWithQueryComponent;\n\n lynx.loadLazyBundle = impl;\n\n function loadLazyBundleWithQueryComponent<\n T extends { default: React.ComponentType<any> },\n >(source: string, mode?: LazyBundleMode): Promise<T> {\n if (__LEPUS__) {\n const query = __QueryComponent(source);\n let result: T;\n try {\n result = query.evalResult as T;\n } catch (e) {\n // Here we cannot return a rejected promise\n // (which will eventually be an unhandled rejection and cause unnecessary redbox)\n // But we still need a object in shape of Promise\n // So we return a Promise which will never resolve or reject,\n // which fit our principle \"lepus run only once at first-screen\" better\n return new Promise(() => {});\n }\n const r: Promise<T> = Promise.resolve(result);\n // Why we should modify the implementation of `then`?\n // We should make it `sync` so lepus first-screen render can use result above instantly\n // We also should keep promise shape\n r.then = makeSyncThen(result);\n return r;\n } else if (__JS__) {\n if (__DEV__ && mode !== undefined) {\n throw new Error(\n `Lazy bundle import \\`mode: '${mode}'\\` requires FetchBundle, but the current build uses QueryComponent. `\n + `Set \\`engineVersion: '3.9'\\` (or higher) in \\`pluginReactLynx\\` to enable FetchBundle.`,\n );\n }\n const resolver = withSyncResolvers<T>();\n\n const callback: (result: { code: number; detail: { schema: string } }) => void = result => {\n const { code, detail } = result;\n if (code === 0) {\n const { schema } = detail;\n const exports = lynx.getApp().getDynamicComponentExports(schema);\n // `code === 0` means that the lazy bundle has been successfully parsed. However,\n // its javascript files may still fail to run, which would prevent the retrieval of the exports object.\n if (exports) {\n resolver.resolve(exports as T);\n return;\n }\n }\n const e = new Error('Lazy bundle load failed, schema: ' + result.detail.schema);\n // ES5 does not support new Error('message', { cause: 'detail' })\n // So we set cause using `.cause` assignment\n e.cause = JSON.stringify(result);\n resolver.reject(e);\n };\n if (typeof lynx.QueryComponent === 'function') {\n lynx.QueryComponent(source, callback);\n } else {\n lynx.getNativeLynx().QueryComponent!(source, callback);\n }\n\n if (resolver.result !== null) {\n const p = Promise.resolve(resolver.result);\n p.then = makeSyncThen(resolver.result) as Promise<Awaited<T>>['then'];\n return p;\n } else if (resolver.error === null) {\n return new Promise((_resolve, _reject) => {\n resolver.resolve = _resolve;\n resolver.reject = _reject;\n });\n } else {\n return Promise.reject(resolver.error);\n }\n }\n\n throw new Error('unreachable');\n }\n\n function loadLazyBundleWithFetchBundle<\n T extends { default: React.ComponentType<any> },\n >(source: string, mode?: LazyBundleMode, host?: string): Promise<T> {\n if (__MAIN_THREAD__) {\n if (mode !== 'sync') {\n // Fire the fetch and ignore the result so the request goes out early\n // and warms the native bundle cache; the background `async` path then\n // waits less. The main thread renders nothing here.\n try {\n lynx.fetchBundle(source, {});\n } catch {}\n return new Promise(() => {});\n }\n let response;\n try {\n response = lynx.fetchBundle(source, {}).wait(\n LYNX_LAZY_SYNC_TIMEOUT_SECONDS,\n );\n } catch {\n return new Promise(() => {});\n }\n if (!response || response.code !== 0) {\n return new Promise(() => {});\n }\n let result: T;\n try {\n result = lynx.loadScript<(entry: string) => T>(SECTION_MAIN_THREAD, {\n bundleName: response.url,\n })(source);\n const styleSheet = __LoadStyleSheet(SECTION_CSS, response.url);\n if (styleSheet !== null) {\n __AdoptStyleSheet(styleSheet);\n }\n } catch {\n return new Promise(() => {});\n }\n const r: Promise<T> = Promise.resolve(result);\n r.then = makeSyncThen(result);\n return r;\n } else if (__JS__) {\n const cached = fetchBundleBgCache.get(source);\n if (cached !== undefined) {\n const r: Promise<T> = Promise.resolve(cached as T);\n r.then = makeSyncThen(cached as T);\n return r;\n }\n if (mode === 'sync') {\n let response;\n try {\n response = lynx.fetchBundle(source, {}).wait(\n LYNX_LAZY_SYNC_TIMEOUT_SECONDS,\n );\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n if (!response || response.code !== 0) {\n console.error('Lazy bundle load failed', response);\n const e = new Error('Lazy bundle load failed, schema: ' + source);\n e.cause = JSON.stringify(response);\n return Promise.reject(e);\n }\n let result: T;\n try {\n result = loadBackgroundBundle<T>(response.url, source);\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n // A sync bundle that wasn't part of the first-screen main-thread render\n // still needs its main-thread section prepared on the MT (the\n // createSnapshot side effect), or a later patch referencing it hits\n // \"snapshot not found\". Runs synchronously — the bundle is already in\n // the native cache — just like the async path below.\n try {\n lynx.getNativeApp().callLepusMethod(\n PREPARE_LAZY_BUNDLE_MTS,\n { url: source, host },\n () => {},\n );\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n // Fully loaded and prepared — cache so repeat loads skip the work above.\n fetchBundleBgCache.set(source, result);\n const r: Promise<T> = Promise.resolve(result);\n r.then = makeSyncThen(result);\n return r;\n }\n\n // async (default)\n return new Promise<T>((resolve, reject) => {\n let handler;\n try {\n handler = lynx.fetchBundle(source, {});\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n return;\n }\n handler.then((response) => {\n if (!response || response.code !== 0) {\n console.error('Lazy bundle load failed', response);\n const e = new Error('Lazy bundle load failed, schema: ' + source);\n e.cause = JSON.stringify(response);\n reject(e);\n return;\n }\n let btsResult: T;\n try {\n btsResult = loadBackgroundBundle<T>(response.url, source);\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n return;\n }\n // Bundle is now in native cache, so MT's `.then` fires sync and\n // the whole prepare runs synchronously inside `Call`, meaning the\n // cb fires only after MT snapshots are registered.\n try {\n lynx.getNativeApp().callLepusMethod(\n PREPARE_LAZY_BUNDLE_MTS,\n { url: source, host },\n () => {\n // Fully loaded and MT-prepared — cache so repeat loads skip\n // the fetch / background eval / MT prepare above.\n fetchBundleBgCache.set(source, btsResult);\n resolve(btsResult);\n },\n );\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n }\n });\n });\n }\n\n throw new Error('unreachable');\n }\n\n return impl;\n})();\n\nfunction withSyncResolvers<T>() {\n 'background only';\n\n const resolver: {\n result: T | null;\n error: Error | null;\n resolve(result: T): void;\n reject(error: Error): void;\n } = {\n resolve: (result: T): void => {\n resolver.result = result;\n },\n reject: (error: Error): void => {\n resolver.error = error;\n },\n result: null,\n error: null,\n };\n\n return resolver;\n}\n"]}
|
|
@@ -1,3 +1,127 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The interface you can extends so that the `defaultDataProcessor` parameter can be customized
|
|
3
|
+
*
|
|
4
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*
|
|
8
|
+
* @group Types
|
|
9
|
+
*/
|
|
10
|
+
export interface InitDataRaw {
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The interface you can extends so that the `defaultDataProcessor` returning value can be customized
|
|
14
|
+
*
|
|
15
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*
|
|
19
|
+
* @group Types
|
|
20
|
+
*/
|
|
21
|
+
export interface InitData {
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The data processors that registered with {@link Lynx.registerDataProcessors}.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
*
|
|
28
|
+
* Extending `dataProcessors` interface
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import type { DataProcessors as WellKnownDataProcessors } from '@lynx-js/react';
|
|
32
|
+
*
|
|
33
|
+
* declare module '@lynx-js/react' {
|
|
34
|
+
* interface DataProcessors extends WellKnownDataProcessors {
|
|
35
|
+
* foo(bar: string): number;
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* Then you can use `lynx.registerDataProcessors` with types.
|
|
41
|
+
*
|
|
42
|
+
* ```js
|
|
43
|
+
* lynx.registerDataProcessors({
|
|
44
|
+
* dataProcessors: {
|
|
45
|
+
* foo(bar) {
|
|
46
|
+
* return 1;
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* })
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*
|
|
54
|
+
* @group Types
|
|
55
|
+
*/
|
|
56
|
+
export interface DataProcessors {
|
|
57
|
+
/**
|
|
58
|
+
* Optional processor to override screen metrics used by the app
|
|
59
|
+
*
|
|
60
|
+
* @param metrics - The physical screen dimensions in pixels
|
|
61
|
+
*
|
|
62
|
+
* @returns New screen dimensions to be used by the app
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* lynx.registerDataProcessors({
|
|
68
|
+
* dataProcessors: {
|
|
69
|
+
* getScreenMetricsOverride: (metrics) => {
|
|
70
|
+
* // Force a specific aspect ratio
|
|
71
|
+
* return {
|
|
72
|
+
* width: metrics.width,
|
|
73
|
+
* height: metrics.width * (16/9)
|
|
74
|
+
* };
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
getScreenMetricsOverride?(metrics: {
|
|
81
|
+
/**
|
|
82
|
+
* The physical pixel width of the screen
|
|
83
|
+
*/
|
|
84
|
+
width: number;
|
|
85
|
+
/**
|
|
86
|
+
* The physical pixel height of the screen
|
|
87
|
+
*/
|
|
88
|
+
height: number;
|
|
89
|
+
}): {
|
|
90
|
+
width: number;
|
|
91
|
+
height: number;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Custom unknown data processors.
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
*
|
|
98
|
+
* You may extends the `DataProcessors` interface for better TypeScript types. See {@link DataProcessors}.
|
|
99
|
+
*/
|
|
100
|
+
[processorName: string]: (...args: any[]) => any;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Definition of DataProcessor(s)
|
|
104
|
+
* @public
|
|
105
|
+
*
|
|
106
|
+
* @group Types
|
|
107
|
+
*/
|
|
108
|
+
export interface DataProcessorDefinition {
|
|
109
|
+
/**
|
|
110
|
+
* You can custom input and output type of `defaultDataProcessor` by extends {@link InitDataRaw} and {@link InitData}
|
|
111
|
+
*
|
|
112
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
113
|
+
*
|
|
114
|
+
* @param rawInitData - initData passed from native code
|
|
115
|
+
* @returns
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
defaultDataProcessor?: (rawInitData: InitDataRaw) => InitData;
|
|
119
|
+
/**
|
|
120
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
dataProcessors?: DataProcessors;
|
|
125
|
+
}
|
|
2
126
|
export declare function isProcessingDefaultData(): boolean;
|
|
3
127
|
export declare function createProcessData(dataProcessorDefinition?: DataProcessorDefinition): (data: InitDataRaw, processorName?: string) => InitData | InitDataRaw;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Copyright 2024 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.
|
|
1
4
|
import { profileEnd, profileStart } from '../shared/profile.js';
|
|
2
5
|
// `true` only while the default data processor is running. `defaultDataProcessor` is
|
|
3
6
|
// invoked by the native side as a separate call *before* `renderPage` / `updatePage`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lynx-data-processors.js","sourceRoot":"","sources":["../../src/core/lynx-data-processors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lynx-data-processors.js","sourceRoot":"","sources":["../../src/core/lynx-data-processors.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA8HhE,qFAAqF;AACrF,sFAAsF;AACtF,qFAAqF;AACrF,mFAAmF;AACnF,oFAAoF;AACpF,2DAA2D;AAC3D,IAAI,qBAAqB,GAAG,KAAK,CAAC;AAElC,MAAM,UAAU,uBAAuB;IACrC,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,uBAAiD;IAEjD,IAAI,+BAA+B,GAAG,KAAK,CAAC;IAE5C,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE;QAC7B,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,YAAY,CAAC,aAAa,CAAC,CAAC;QAC9B,CAAC;QAED,IAAI,MAA8B,CAAC;QACnC,IAAI,CAAC;YACH,IAAI,aAAa,EAAE,CAAC;gBAClB,MAAM,GAAG,uBAAuB,EAAE,cAAc,EAAE,CAAC,aAAa,CAAC,EAAE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Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { profileEnd, profileStart } from '../shared/profile.js';\n\n/**\n * The interface you can extends so that the `defaultDataProcessor` parameter can be customized\n *\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @public\n *\n * @group Types\n */\nexport interface InitDataRaw {}\n/**\n * The interface you can extends so that the `defaultDataProcessor` returning value can be customized\n *\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @public\n *\n * @group Types\n */\nexport interface InitData {}\n\n/**\n * The data processors that registered with {@link Lynx.registerDataProcessors}.\n *\n * @example\n *\n * Extending `dataProcessors` interface\n *\n * ```ts\n * import type { DataProcessors as WellKnownDataProcessors } from '@lynx-js/react';\n *\n * declare module '@lynx-js/react' {\n * interface DataProcessors extends WellKnownDataProcessors {\n * foo(bar: string): number;\n * }\n * }\n * ```\n *\n * Then you can use `lynx.registerDataProcessors` with types.\n *\n * ```js\n * lynx.registerDataProcessors({\n * dataProcessors: {\n * foo(bar) {\n * return 1;\n * }\n * }\n * })\n * ```\n *\n * @public\n *\n * @group Types\n */\nexport interface DataProcessors {\n /**\n * Optional processor to override screen metrics used by the app\n *\n * @param metrics - The physical screen dimensions in pixels\n *\n * @returns New screen dimensions to be used by the app\n *\n * @example\n *\n * ```ts\n * lynx.registerDataProcessors({\n * dataProcessors: {\n * getScreenMetricsOverride: (metrics) => {\n * // Force a specific aspect ratio\n * return {\n * width: metrics.width,\n * height: metrics.width * (16/9)\n * };\n * }\n * }\n * });\n * ```\n */\n getScreenMetricsOverride?(metrics: {\n /**\n * The physical pixel width of the screen\n */\n width: number;\n /**\n * The physical pixel height of the screen\n */\n height: number;\n }): { width: number; height: number };\n\n /**\n * Custom unknown data processors.\n *\n * @remarks\n *\n * You may extends the `DataProcessors` interface for better TypeScript types. See {@link DataProcessors}.\n */\n [processorName: string]: (...args: any[]) => any;\n}\n\n/**\n * Definition of DataProcessor(s)\n * @public\n *\n * @group Types\n */\nexport interface DataProcessorDefinition {\n /**\n * You can custom input and output type of `defaultDataProcessor` by extends {@link InitDataRaw} and {@link InitData}\n *\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @param rawInitData - initData passed from native code\n * @returns\n * @public\n */\n defaultDataProcessor?: (rawInitData: InitDataRaw) => InitData;\n /**\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @public\n */\n dataProcessors?: DataProcessors;\n}\n\n// `true` only while the default data processor is running. `defaultDataProcessor` is\n// invoked by the native side as a separate call *before* `renderPage` / `updatePage`,\n// so a `markFirstScreenSyncReady()` made inside it must not sync the *previous* tree\n// (still latched ready) — a re-render of the data being processed is imminent. The\n// first-screen sync backend reads this to defer such a mark. Lives here (not in the\n// backend) so `core` does not depend on a runtime backend.\nlet processingDefaultData = false;\n\nexport function isProcessingDefaultData(): boolean {\n return processingDefaultData;\n}\n\nexport function createProcessData(\n dataProcessorDefinition?: DataProcessorDefinition,\n): (data: InitDataRaw, processorName?: string) => InitData | InitDataRaw {\n let hasDefaultDataProcessorExecuted = false;\n\n return (data, processorName) => {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('processData');\n }\n\n let result: InitData | InitDataRaw;\n try {\n if (processorName) {\n result = dataProcessorDefinition?.dataProcessors?.[processorName]?.(data) as InitData ?? data;\n } else {\n // a `markFirstScreenSyncReady()` made inside `defaultDataProcessor` must be\n // deferred until the data being processed renders (see `processingDefaultData`)\n processingDefaultData = true;\n try {\n result = dataProcessorDefinition?.defaultDataProcessor?.(data) ?? data;\n } finally {\n processingDefaultData = false;\n }\n }\n } catch (error: unknown) {\n lynx.reportError(error as Error);\n result = {};\n }\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n\n if (!hasDefaultDataProcessorExecuted) {\n result = appendInitDataMetadata(result);\n }\n\n if (!processorName) {\n hasDefaultDataProcessorExecuted = true;\n }\n\n return result;\n };\n}\n\nfunction appendInitDataMetadata(result: InitData | InitDataRaw): InitData | InitDataRaw {\n // @ts-expect-error todo: add types to i18n logic\n const i18nResourceTranslation: unknown = globalThis.__I18N_RESOURCE_TRANSLATION__;\n if (i18nResourceTranslation) {\n result = {\n ...result,\n __I18N_RESOURCE_TRANSLATION__: i18nResourceTranslation,\n };\n }\n\n // @ts-expect-error todo: add types to __EXTRACT_STR__\n if (__EXTRACT_STR__) {\n // @ts-expect-error todo: add types to __EXTRACT_STR__\n const extractStrIdentFlag: unknown = __EXTRACT_STR_IDENT_FLAG__;\n result = {\n ...result,\n _EXTRACT_STR: extractStrIdentFlag,\n };\n }\n\n return result;\n}\n"]}
|
|
@@ -19,9 +19,9 @@ export function registerDestroyTask(task) {
|
|
|
19
19
|
}
|
|
20
20
|
export function runDestroyTasks() {
|
|
21
21
|
const tasks = Array.from(destroyTasks);
|
|
22
|
+
destroyTasks.clear();
|
|
22
23
|
for (const task of tasks) {
|
|
23
24
|
task();
|
|
24
25
|
}
|
|
25
|
-
destroyTasks.clear();
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=runtime-destroy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-destroy.js","sourceRoot":"","sources":["../../src/core/runtime-destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,MAAM,YAAY,GAAG,IAAI,GAAG,EAAe,CAAC;AAC5C,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,sFAAsF;AACtF,MAAM,UAAU,kBAAkB;IAChC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,SAAS,GAAG,IAAI,CAAC;IACjB,eAAe,EAAE,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAiB;IACnD,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,GAAG,EAAE;QACV,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,EAAE,CAAC;IACT,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime-destroy.js","sourceRoot":"","sources":["../../src/core/runtime-destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,MAAM,YAAY,GAAG,IAAI,GAAG,EAAe,CAAC;AAC5C,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,sFAAsF;AACtF,MAAM,UAAU,kBAAkB;IAChC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,SAAS,GAAG,IAAI,CAAC;IACjB,eAAe,EAAE,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAiB;IACnD,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,GAAG,EAAE;QACV,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,YAAY,CAAC,KAAK,EAAE,CAAC;IACrB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,EAAE,CAAC;IACT,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\ntype DestroyTask = () => void;\n\nconst destroyTasks = new Set<DestroyTask>();\nlet destroyed = false;\n\n// Calls from a retired entry stay pending: settling them would run its continuations.\nexport function isRuntimeDestroyed(): boolean {\n return destroyed;\n}\n\nexport function destroyRuntime(): void {\n destroyed = true;\n runDestroyTasks();\n}\n\nexport function registerDestroyTask(task: DestroyTask): () => void {\n destroyTasks.add(task);\n return () => {\n destroyTasks.delete(task);\n };\n}\n\nexport function runDestroyTasks(): void {\n const tasks = Array.from(destroyTasks);\n destroyTasks.clear();\n for (const task of tasks) {\n task();\n }\n}\n"]}
|
package/runtime/lib/document.js
CHANGED
|
@@ -50,10 +50,5 @@ function setupDocument(_document = document) {
|
|
|
50
50
|
return i;
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
// if (__JS__) {
|
|
54
|
-
// setupBackgroundDocument();
|
|
55
|
-
// } else if (__LEPUS__) {
|
|
56
|
-
// setupDocument();
|
|
57
|
-
// }
|
|
58
53
|
export { document, setupBackgroundDocument, setupDocument };
|
|
59
54
|
//# sourceMappingURL=document.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAyBnE,MAAM,QAAQ,GAA4B,EAA6B,CAAC;AAExE;;;GAGG;AACH,SAAS,uBAAuB,CAAC,YAAqC,QAAQ;IAC5E,SAAS,CAAC,aAAa,GAAG,UAAS,IAAY;QAC7C,OAAO,IAAI,0BAA0B,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC;IACF,SAAS,CAAC,eAAe,GAAG,UAAS,GAAW,EAAE,IAAY,EAAE,GAAY;QAC1E,OAAO,IAAI,0BAA0B,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC;IACF,SAAS,C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AAS,CAAC,cAAc,GAAG,UAAS,IAAY;QAC9C,MAAM,CAAC,GAAG,IAAI,gBAAgB,CAAC,IAAyB,CAAC,CAAC;QAC1D,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACxB,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE;YAC/B,GAAG,CAAC,CAAC;gBACH,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACvB,CAAC;SACF,CAAC,CAAC;QACH,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,aAAa,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js';\nimport { SnapshotInstance } from './snapshot/snapshot/snapshot.js';\n\n/**\n * This module implements an Interface Adapter Pattern to integrate Preact's\n * rendering system with Lynx's custom Snapshot-based virtual DOM.\n *\n * It works by:\n * 1. Defining a minimal {@link Document}-like interface that Preact expects\n * 2. Implementing this interface to return our {@link Snapshot} instances\n * 3. Maintaining the same method signatures as the standard DOM API\n *\n * This allows Preact to build its virtual tree using our Snapshot system\n * without knowing it's not working with a real DOM.\n */\n\n/**\n * Defines the minimal document interface that Preact expects, depending on\n * which thread is running.\n */\ninterface SnapshotDocumentAdapter {\n createElement(type: string): BackgroundSnapshotInstance | SnapshotInstance;\n createElementNS(ns: string | null, type: string): BackgroundSnapshotInstance | SnapshotInstance;\n createTextNode(text: string): BackgroundSnapshotInstance | SnapshotInstance;\n}\n\nconst document: SnapshotDocumentAdapter = {} as SnapshotDocumentAdapter;\n\n/**\n * Sets up the document interface for the background thread.\n * All DOM operations are intercepted to create {@link BackgroundSnapshotInstance}.\n */\nfunction setupBackgroundDocument(_document: SnapshotDocumentAdapter = document): void {\n _document.createElement = function(type: string) {\n return new BackgroundSnapshotInstance(type);\n };\n _document.createElementNS = function(_ns: string, type: string, _is?: string) {\n return new BackgroundSnapshotInstance(type);\n };\n _document.createTextNode = function(text: string) {\n const i = new BackgroundSnapshotInstance(null as unknown as string);\n i.setAttribute(0, text);\n Object.defineProperty(i, 'data', {\n set(v) {\n i.setAttribute(0, v);\n },\n });\n return i;\n };\n}\n\n/**\n * Sets up the document interface for the main thread.\n * All DOM operations are intercepted to create {@link SnapshotInstance}.\n */\nfunction setupDocument(_document: SnapshotDocumentAdapter = document): void {\n _document.createElement = function(type: string) {\n const si = new SnapshotInstance(type);\n return si;\n };\n _document.createElementNS = function(_ns: string, type: string, _is?: string) {\n const si = new SnapshotInstance(type);\n return si;\n };\n _document.createTextNode = function(text: string) {\n const i = new SnapshotInstance(null as unknown as string);\n i.setAttribute(0, text);\n Object.defineProperty(i, 'data', {\n set(v) {\n i.setAttribute(0, v);\n },\n });\n return i;\n };\n}\n\nexport { document, setupBackgroundDocument, setupDocument };\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { getSpreadRefFromValue, queueRefAttrUpdate } from '../prop-adapters/ref.js';
|
|
5
5
|
import { ElementTemplateUpdateOps } from '../protocol/opcodes.js';
|
|
6
|
-
import { __etAttrPlanMap, adaptRefAttrSlot, adaptSpreadAttrSlot, getMainThreadDynamicAttrSlotKinds, } from '../runtime/template/attr-slot-plan.js';
|
|
6
|
+
import { __etAttrPlanMap, adaptRefAttrSlot, adaptSpreadAttrSlot, adaptTypedSpreadAttrSlot, getMainThreadDynamicAttrSlotKinds, } from '../runtime/template/attr-slot-plan.js';
|
|
7
7
|
function normalizeAttributeSlots(rawSlots) {
|
|
8
8
|
let normalizedSlots;
|
|
9
9
|
for (let slotIndex = 0; slotIndex < rawSlots.length; slotIndex += 1) {
|
|
@@ -24,7 +24,7 @@ function queuePlannedRefAttributeSlotUpdates(instance, attrPlan, previousRawSlot
|
|
|
24
24
|
queueRefAttrUpdate(previousRawSlots?.[attrSlotIndex], nextRawSlots?.[attrSlotIndex], instance, attrSlotIndex);
|
|
25
25
|
continue;
|
|
26
26
|
}
|
|
27
|
-
if (adapter === adaptSpreadAttrSlot) {
|
|
27
|
+
if (adapter === adaptSpreadAttrSlot || adapter === adaptTypedSpreadAttrSlot) {
|
|
28
28
|
const previousSpreadRef = getSpreadRefFromValue(previousRawSlots?.[attrSlotIndex]);
|
|
29
29
|
const nextSpreadRef = getSpreadRefFromValue(nextRawSlots?.[attrSlotIndex]);
|
|
30
30
|
if (previousSpreadRef === undefined && nextSpreadRef === undefined) {
|
|
@@ -68,6 +68,9 @@ export function queueRefAttributeSlotUpdates(templateKey, instance, previousRawS
|
|
|
68
68
|
}
|
|
69
69
|
export function getAttributeSlotUpdateOp(templateType, attrSlotIndex) {
|
|
70
70
|
const kind = getMainThreadDynamicAttrSlotKinds(templateType)?.get(attrSlotIndex);
|
|
71
|
+
if (kind === 'gesture') {
|
|
72
|
+
return ElementTemplateUpdateOps.setGesture;
|
|
73
|
+
}
|
|
71
74
|
if (kind === 'mt-event') {
|
|
72
75
|
return ElementTemplateUpdateOps.setMainThreadEvent;
|
|
73
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attr-slots.js","sourceRoot":"","sources":["../../../src/element-template/background/attr-slots.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,iCAAiC,GAClC,MAAM,uCAAuC,CAAC;AAS/C,SAAS,uBAAuB,CAAC,QAA4B;IAC3D,IAAI,eAAgD,CAAC;IACrD,KAAK,IAAI,SAA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AAa,CAAC,GAAG,OAAO,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;IAC5F,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,WAAmB,EACnB,QAAyC,EACzC,gBAAqC,EACrC,YAAiC,EACjC,aAA0B;IAE1B,MAAM,QAAQ,GAAG,aAAa,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;IAC/D,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO;IACT,CAAC;IAED,mCAAmC,CAAC,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC;AAC1F,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,YAAoB,EACpB,aAAqB;IAErB,MAAM,IAAI,GAAG,iCAAiC,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;IACjF,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,wBAAwB,CAAC,UAAU,CAAC;IAC7C,CAAC;IACD,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,OAAO,wBAAwB,CAAC,kBAAkB,CAAC;IACrD,CAAC;IACD,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,OAAO,wBAAwB,CAAC,gBAAgB,CAAC;IACnD,CAAC;IACD,OAAO,wBAAwB,CAAC,YAAY,CAAC;AAC/C,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { getSpreadRefFromValue, queueRefAttrUpdate } from '../prop-adapters/ref.js';\nimport { ElementTemplateUpdateOps } from '../protocol/opcodes.js';\nimport type { ElementTemplateUpdateOp } from '../protocol/opcodes.js';\nimport type { SerializableValue } from '../protocol/types.js';\nimport {\n __etAttrPlanMap,\n adaptRefAttrSlot,\n adaptSpreadAttrSlot,\n adaptTypedSpreadAttrSlot,\n getMainThreadDynamicAttrSlotKinds,\n} from '../runtime/template/attr-slot-plan.js';\nimport type { EtAttrAdapter, EtAttrAdapterContext, EtAttrPlan } from '../runtime/template/attr-slot-plan.js';\n\nexport interface PrepareAttributeSlotsOptions {\n previousPreparedSlots?: readonly unknown[];\n previousRawSlots?: readonly unknown[];\n attributePlan?: EtAttrPlan | undefined;\n}\n\nfunction normalizeAttributeSlots(rawSlots: readonly unknown[]): SerializableValue[] {\n let normalizedSlots: SerializableValue[] | undefined;\n for (let slotIndex = 0; slotIndex < rawSlots.length; slotIndex += 1) {\n const rawSlot = rawSlots[slotIndex];\n if (rawSlot !== undefined) {\n continue;\n }\n normalizedSlots ??= rawSlots.slice() as SerializableValue[];\n normalizedSlots[slotIndex] = null;\n }\n return normalizedSlots ?? rawSlots as SerializableValue[];\n}\n\nfunction queuePlannedRefAttributeSlotUpdates(\n instance: { readonly instanceId: number },\n attrPlan: readonly (number | EtAttrAdapter)[],\n previousRawSlots?: readonly unknown[],\n nextRawSlots?: readonly unknown[],\n): void {\n for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {\n const attrSlotIndex = attrPlan[planIndex] as number;\n const adapter = attrPlan[planIndex + 1] as EtAttrAdapter;\n\n if (adapter === adaptRefAttrSlot) {\n queueRefAttrUpdate(\n previousRawSlots?.[attrSlotIndex],\n nextRawSlots?.[attrSlotIndex],\n instance,\n attrSlotIndex,\n );\n continue;\n }\n\n if (adapter === adaptSpreadAttrSlot || adapter === adaptTypedSpreadAttrSlot) {\n const previousSpreadRef = getSpreadRefFromValue(previousRawSlots?.[attrSlotIndex]);\n const nextSpreadRef = getSpreadRefFromValue(nextRawSlots?.[attrSlotIndex]);\n if (previousSpreadRef === undefined && nextSpreadRef === undefined) {\n continue;\n }\n queueRefAttrUpdate(\n previousSpreadRef,\n nextSpreadRef ?? null,\n instance,\n attrSlotIndex,\n );\n }\n }\n}\n\nexport function prepareAttributeSlots(\n templateKey: string,\n handleId: number,\n rawSlots: readonly unknown[],\n options?: PrepareAttributeSlotsOptions,\n): SerializableValue[] {\n const attrPlan = options?.attributePlan ?? __etAttrPlanMap[templateKey];\n if (!attrPlan || attrPlan.length === 0) {\n return normalizeAttributeSlots(rawSlots);\n }\n\n const normalizedSlots = normalizeAttributeSlots(rawSlots);\n const preparedSlots = normalizedSlots === rawSlots\n ? rawSlots.slice() as SerializableValue[]\n : normalizedSlots;\n const previousPreparedSlots = options?.previousPreparedSlots;\n const previousRawSlots = options?.previousRawSlots;\n const adapterContext: EtAttrAdapterContext | undefined = previousPreparedSlots && previousRawSlots\n ? {\n previousPreparedSlots,\n previousRawSlots,\n }\n : undefined;\n for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {\n const attrSlotIndex = attrPlan[planIndex] as number;\n const adapter = attrPlan[planIndex + 1] as EtAttrAdapter;\n const rawValue = rawSlots[attrSlotIndex];\n preparedSlots[attrSlotIndex] = adapter(handleId, attrSlotIndex, rawValue, adapterContext);\n }\n\n return preparedSlots;\n}\n\nexport function queueRefAttributeSlotUpdates(\n templateKey: string,\n instance: { readonly instanceId: number },\n previousRawSlots?: readonly unknown[],\n nextRawSlots?: readonly unknown[],\n attributePlan?: EtAttrPlan,\n): void {\n const attrPlan = attributePlan ?? __etAttrPlanMap[templateKey];\n if (!attrPlan || attrPlan.length === 0) {\n return;\n }\n\n queuePlannedRefAttributeSlotUpdates(instance, attrPlan, previousRawSlots, nextRawSlots);\n}\n\nexport function getAttributeSlotUpdateOp(\n templateType: string,\n attrSlotIndex: number,\n): ElementTemplateUpdateOp {\n const kind = getMainThreadDynamicAttrSlotKinds(templateType)?.get(attrSlotIndex);\n if (kind === 'gesture') {\n return ElementTemplateUpdateOps.setGesture;\n }\n if (kind === 'mt-event') {\n return ElementTemplateUpdateOps.setMainThreadEvent;\n }\n if (kind === 'mt-ref') {\n return ElementTemplateUpdateOps.setMainThreadRef;\n }\n return ElementTemplateUpdateOps.setAttribute;\n}\n"]}
|
|
@@ -48,6 +48,15 @@ export function cancelElementTemplateRemovedSubtreeCleanup() {
|
|
|
48
48
|
}
|
|
49
49
|
scheduledRemovedSubtreeCleanupTimers.clear();
|
|
50
50
|
}
|
|
51
|
+
function cleanupFailedElementTemplateCommit(removedSubtreesAwaitingTeardown, delayedRunOnMainThreadPayload) {
|
|
52
|
+
if (delayedRunOnMainThreadPayload) {
|
|
53
|
+
dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));
|
|
54
|
+
}
|
|
55
|
+
clearPendingRefs();
|
|
56
|
+
resetGlobalCommitContext();
|
|
57
|
+
setPipeline(undefined);
|
|
58
|
+
scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);
|
|
59
|
+
}
|
|
51
60
|
function flushElementTemplateCommitChanges() {
|
|
52
61
|
const hasNativeOps = globalCommitContext.ops.length > 0;
|
|
53
62
|
const hasDelayedRunOnMainThread = delayedRunOnMainThreadData.length > 0;
|
|
@@ -98,12 +107,7 @@ function flushElementTemplateCommitChanges() {
|
|
|
98
107
|
});
|
|
99
108
|
}
|
|
100
109
|
catch (error) {
|
|
101
|
-
|
|
102
|
-
dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));
|
|
103
|
-
}
|
|
104
|
-
clearPendingRefs();
|
|
105
|
-
resetGlobalCommitContext();
|
|
106
|
-
scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);
|
|
110
|
+
cleanupFailedElementTemplateCommit(removedSubtreesAwaitingTeardown, delayedRunOnMainThreadPayload);
|
|
107
111
|
throw error;
|
|
108
112
|
}
|
|
109
113
|
lynx.getCoreContext().dispatchEvent(updateEvent);
|
|
@@ -131,12 +135,7 @@ export function installElementTemplateCommitHook() {
|
|
|
131
135
|
sendMTRefInitValueToMainThread();
|
|
132
136
|
}
|
|
133
137
|
catch (error) {
|
|
134
|
-
|
|
135
|
-
dropFunctionCallReturnIds(takeDelayedRunOnMainThreadData().map(data => data.resolveId));
|
|
136
|
-
clearPendingRefs();
|
|
137
|
-
resetGlobalCommitContext();
|
|
138
|
-
setPipeline(undefined);
|
|
139
|
-
scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);
|
|
138
|
+
cleanupFailedElementTemplateCommit(takeRemovedSubtreesForPostDispatchTeardown(), takeDelayedRunOnMainThreadData());
|
|
140
139
|
throw error;
|
|
141
140
|
}
|
|
142
141
|
}
|