@lynx-js/react 0.128.0 → 0.129.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/entry-re-eval.test.ts +161 -0
- package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
- package/runtime/__test__/core/reload-scoped-dual-thread-communication.test.ts +129 -0
- package/runtime/__test__/core/thread-function-call.test.ts +1 -0
- package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +2 -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/index.test.ts +8 -0
- package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
- package/runtime/__test__/element-template/native/main-thread-ref-init-value.test.ts +100 -0
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +83 -0
- package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +104 -0
- package/runtime/__test__/element-template/native/reload.test.ts +79 -1
- package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +104 -47
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +7 -1
- package/runtime/__test__/element-template/runtime/background/re-eval-reload.test.ts +69 -0
- package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
- package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +31 -5
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +214 -10
- package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -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/render/render-transform.contract.test.ts +2 -0
- 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 +121 -26
- package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +89 -2
- package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +5 -0
- 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/re-eval-reload.test.jsx +114 -0
- package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +169 -0
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +63 -0
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-main-thread.test.jsx +103 -0
- package/runtime/__test__/snapshot/lifecycle.test.jsx +61 -1
- package/runtime/__test__/snapshot/lynx/lazy-effect-scheduling.test.jsx +105 -0
- package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
- package/runtime/__test__/snapshot/preact.test.jsx +0 -3
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
- package/runtime/__test__/snapshot/ssr.test.jsx +2 -2
- package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +6 -11
- package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +1 -1
- package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +24 -1
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +27 -1
- package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +46 -0
- package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +3 -3
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
- package/runtime/lazy/element-template-internal.js +0 -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/background-function/exec-map.d.ts +2 -0
- package/runtime/lib/core/background-function/exec-map.js +7 -0
- package/runtime/lib/core/background-function/exec-map.js.map +1 -1
- package/runtime/lib/core/background-function/run-on-background.js +15 -16
- package/runtime/lib/core/background-function/run-on-background.js.map +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/card-lifetime.d.ts +5 -0
- package/runtime/lib/core/card-lifetime.js +17 -0
- package/runtime/lib/core/card-lifetime.js.map +1 -0
- 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/entry-reload.d.ts +7 -0
- package/runtime/lib/core/entry-reload.js +49 -0
- package/runtime/lib/core/entry-reload.js.map +1 -0
- package/runtime/lib/core/lynx/lazy-bundle.js +5 -2
- 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/main-thread-ref-id.js +4 -4
- package/runtime/lib/core/main-thread-ref-id.js.map +1 -1
- package/runtime/lib/core/reload-scoped-event.d.ts +5 -0
- package/runtime/lib/core/reload-scoped-event.js +26 -0
- package/runtime/lib/core/reload-scoped-event.js.map +1 -0
- package/runtime/lib/core/reload-version.js +4 -3
- package/runtime/lib/core/reload-version.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.d.ts +2 -0
- package/runtime/lib/core/runtime-destroy.js +10 -1
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/core/thread-function-call/main-thread.js +5 -4
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- package/runtime/lib/core/thread-function-call/return-value.js +6 -5
- package/runtime/lib/core/thread-function-call/return-value.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/commit-hook.js +24 -22
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js +2 -6
- package/runtime/lib/element-template/background/hydration-listener.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/index.d.ts +2 -2
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +1 -1
- package/runtime/lib/element-template/internal.js +0 -13
- 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/main-thread-ref-init-value.d.ts +3 -0
- package/runtime/lib/element-template/main-thread-ref-init-value.js +38 -0
- package/runtime/lib/element-template/main-thread-ref-init-value.js.map +1 -0
- 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/index.js +2 -0
- package/runtime/lib/element-template/native/index.js.map +1 -1
- 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 +10 -2
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +58 -54
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.d.ts +1 -1
- package/runtime/lib/element-template/native/reload-background.js +12 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.d.ts +6 -0
- package/runtime/lib/element-template/native/reload-main-thread.js +20 -3
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.d.ts +2 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.js +1 -0
- package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +0 -2
- 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 +4 -0
- 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/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 +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +41 -21
- 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 +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.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/shared/index-map.d.ts +4 -1
- package/runtime/lib/shared/index-map.js +5 -2
- package/runtime/lib/shared/index-map.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 +6 -0
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.d.ts +6 -2
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js +21 -18
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.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/reload.d.ts +9 -2
- package/runtime/lib/snapshot/lifecycle/reload.js +29 -8
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/list/list.js +3 -2
- package/runtime/lib/snapshot/list/list.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 +14 -11
- 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/snapshot/snapshot/list.js +2 -1
- package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.d.ts +4 -2
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js +11 -11
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +1 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +6 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ctx.d.ts +1 -1
- package/runtime/lib/snapshot/worklet/ctx.js +6 -1
- package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js +6 -0
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.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/delayRunOnBackground.js +3 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +8 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/listeners.js +2 -2
- package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.js +3 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -1
- package/runtime/lib/worklet-runtime/runOnMainThread.js +4 -3
- package/runtime/lib/worklet-runtime/runOnMainThread.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/background-function/exec-map.ts +9 -0
- package/runtime/src/core/background-function/run-on-background.ts +14 -16
- package/runtime/src/core/capture-main-thread-object.ts +2 -1
- package/runtime/src/core/card-lifetime.ts +18 -0
- package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
- package/runtime/src/core/entry-reload.ts +63 -0
- package/runtime/src/core/lynx/lazy-bundle.ts +5 -2
- package/runtime/src/core/lynx-data-processors.ts +124 -1
- package/runtime/src/core/main-thread-ref-id.ts +5 -4
- package/runtime/src/core/reload-scoped-event.ts +35 -0
- package/runtime/src/core/reload-version.ts +5 -3
- package/runtime/src/core/runtime-destroy.ts +12 -1
- package/runtime/src/core/thread-function-call/main-thread.ts +4 -4
- package/runtime/src/core/thread-function-call/return-value.ts +6 -5
- package/runtime/src/document.ts +0 -6
- package/runtime/src/element-template/background/commit-hook.ts +32 -23
- package/runtime/src/element-template/background/hydration-listener.ts +2 -6
- package/runtime/src/element-template/client/root.ts +1 -3
- package/runtime/src/element-template/index.ts +2 -2
- package/runtime/src/element-template/internal.ts +0 -20
- package/runtime/src/element-template/lynx/env.ts +1 -1
- package/runtime/src/element-template/main-thread-ref-init-value.ts +44 -0
- package/runtime/src/element-template/native/flush.ts +10 -0
- package/runtime/src/element-template/native/index.ts +2 -0
- package/runtime/src/element-template/native/main-thread-api.ts +3 -6
- package/runtime/src/element-template/native/mts-destroy.ts +10 -2
- package/runtime/src/element-template/native/patch-listener.ts +62 -62
- package/runtime/src/element-template/native/reload-background.ts +13 -1
- package/runtime/src/element-template/native/reload-main-thread.ts +32 -3
- package/runtime/src/element-template/protocol/lifecycle-constant.ts +1 -0
- package/runtime/src/element-template/protocol/types.ts +0 -15
- package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
- package/runtime/src/element-template/runtime/patch.ts +5 -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/main-thread-background-function.ts +8 -1
- package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +51 -21
- package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +2 -2
- 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/shared/index-map.ts +3 -2
- package/runtime/src/snapshot/lifecycle/destroy.ts +7 -0
- package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +26 -19
- 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/reload.ts +47 -11
- package/runtime/src/snapshot/list/list.ts +9 -2
- package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
- package/runtime/src/snapshot/lynx/calledByNative.ts +14 -13
- 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/snapshot/snapshot/list.ts +5 -1
- package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +19 -12
- package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +10 -1
- package/runtime/src/snapshot/worklet/ctx.ts +10 -1
- package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +6 -0
- package/runtime/src/worklet-runtime/README.md +33 -0
- 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/delayRunOnBackground.ts +3 -1
- package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +8 -1
- package/runtime/src/worklet-runtime/listeners.ts +4 -7
- package/runtime/src/worklet-runtime/mainThreadObject.ts +2 -1
- package/runtime/src/worklet-runtime/runOnMainThread.ts +4 -3
- package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
- package/runtime/types/types.d.ts +3 -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 +59 -5
- package/transform/.turbo/turbo-build$colon$wasm.log +63 -136
- package/transform/__test__/defines.spec.js +137 -0
- package/transform/__test__/object-methods.spec.js +79 -0
- package/transform/crates/swc_plugin_worklet/definition_imports.rs +97 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +56 -48
- package/transform/crates/swc_plugin_worklet/lib.rs +400 -595
- package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +6 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +9 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +12 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +1 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +1 -1
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +3 -1
- package/transform/package.json +0 -1
- package/transform/src/lib.rs +173 -12
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +105 -32
- 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 +193 -194
- 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
|
@@ -37,7 +37,7 @@ describe('runOnMainThread', () => {
|
|
|
37
37
|
[
|
|
38
38
|
[
|
|
39
39
|
{
|
|
40
|
-
"data": "{"resolveId":10,"returnValue":"ret"}",
|
|
40
|
+
"data": "{"resolveId":10,"returnValue":"ret","reloadVersion":0}",
|
|
41
41
|
"type": "Lynx.Worklet.FunctionCallRet",
|
|
42
42
|
},
|
|
43
43
|
],
|
|
@@ -45,7 +45,7 @@ describe('runOnMainThread', () => {
|
|
|
45
45
|
`);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it('
|
|
48
|
+
it('sends a scoped return event when the worklet throws', () => {
|
|
49
49
|
const error = new Error('main-thread worklet failed');
|
|
50
50
|
globalThis.registerWorklet('main-thread', '1', () => {
|
|
51
51
|
throw error;
|
|
@@ -56,7 +56,7 @@ describe('runOnMainThread', () => {
|
|
|
56
56
|
[
|
|
57
57
|
[
|
|
58
58
|
{
|
|
59
|
-
"data": "{"resolveId":10}",
|
|
59
|
+
"data": "{"resolveId":10,"reloadVersion":0}",
|
|
60
60
|
"type": "Lynx.Worklet.FunctionCallRet",
|
|
61
61
|
},
|
|
62
62
|
],
|
|
@@ -61,6 +61,36 @@ describe('Worklet', () => {
|
|
|
61
61
|
if (kind === 'metadata') expect(value.nested).toEqual({ _wvid: 999 });
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
+
it('executes the original Native-held context without replacing its captures', () => {
|
|
65
|
+
initWorklet();
|
|
66
|
+
registerWorklet('main-thread', 'background-owner', function() {
|
|
67
|
+
return this._jsFn;
|
|
68
|
+
});
|
|
69
|
+
const handle = { _jsFnId: 7 };
|
|
70
|
+
const ctx = { _wkltId: 'background-owner', _execId: 3, _jsFn: { a: handle, b: handle } };
|
|
71
|
+
lynxWorkletImpl._jsFunctionLifecycleManager.addRef(3, ctx);
|
|
72
|
+
const nativeContext = ctx;
|
|
73
|
+
const first = runWorklet(nativeContext, []);
|
|
74
|
+
expect(first.a).toBe(first.b);
|
|
75
|
+
expect(first.a).toBe(ctx._jsFn.a);
|
|
76
|
+
expect(runWorklet(nativeContext, [])).toBe(first);
|
|
77
|
+
expect(lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(3)).toBe(2);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it.each(['2.15', '2.16'])('prepares captured execution metadata without a lifecycle manager on SDK %s', (version) => {
|
|
81
|
+
SystemInfo.lynxSdkVersion = version;
|
|
82
|
+
initWorklet();
|
|
83
|
+
lynxWorkletImpl._jsFunctionLifecycleManager = undefined;
|
|
84
|
+
registerWorklet('main-thread', 'fallback', function() {
|
|
85
|
+
return this._jsFn.callback;
|
|
86
|
+
});
|
|
87
|
+
const descriptor = { _jsFnId: 7 };
|
|
88
|
+
const ctx = { _wkltId: 'fallback', _execId: 3, _jsFn: { callback: descriptor } };
|
|
89
|
+
expect(runWorklet(ctx, [])).toEqual({ _jsFnId: 7, _execId: 3 });
|
|
90
|
+
expect(ctx._jsFn.callback).toEqual({ _jsFnId: 7, _execId: 3 });
|
|
91
|
+
expect(ctx._jsFn.callback).toBe(descriptor);
|
|
92
|
+
});
|
|
93
|
+
|
|
64
94
|
it('worklet should be called', () => {
|
|
65
95
|
initWorklet();
|
|
66
96
|
|
package/runtime/lazy/internal.js
CHANGED
|
@@ -46,12 +46,12 @@ export const {
|
|
|
46
46
|
getRuntimeVersion,
|
|
47
47
|
loadDynamicJS,
|
|
48
48
|
loadLazyBundle,
|
|
49
|
+
loadWorkletRuntime,
|
|
49
50
|
options,
|
|
50
51
|
preactCloneElement,
|
|
51
52
|
process,
|
|
52
53
|
registerRuntimeBackend,
|
|
53
54
|
registerRuntimeVersion,
|
|
54
|
-
registerWorkletOnBackground,
|
|
55
55
|
snapshotCreateList,
|
|
56
56
|
snapshotManager,
|
|
57
57
|
snapshotCreatorMap,
|
|
@@ -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 { sExportsJSXDevRuntime, target } from './target';
|
|
5
|
+
import { sExportsJSXDevRuntime, target } from './target.js';
|
|
6
6
|
|
|
7
7
|
export const {
|
|
8
8
|
Fragment,
|
|
@@ -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 { sExportsJSXRuntime, target } from './target';
|
|
5
|
+
import { sExportsJSXRuntime, target } from './target.js';
|
|
6
6
|
|
|
7
7
|
export const {
|
|
8
8
|
Fragment,
|
|
@@ -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,
|
|
@@ -5,6 +5,8 @@ import type { JsFnHandle, Worklet } from '../../worklet-runtime/bindings/types.j
|
|
|
5
5
|
* a handle to one of its background functions.
|
|
6
6
|
*/
|
|
7
7
|
export declare class BackgroundFunctionExecMap extends IndexMap<Worklet> {
|
|
8
|
+
constructor();
|
|
9
|
+
clear(): void;
|
|
8
10
|
add(worklet: Worklet): number;
|
|
9
11
|
findJsFnHandle(execId: number, fnId: number): JsFnHandle | undefined;
|
|
10
12
|
private findJsFnHandleInValue;
|
|
@@ -2,11 +2,18 @@
|
|
|
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 { IndexMap } from '../../shared/index-map.js';
|
|
5
|
+
import { cardLifetime } from '../card-lifetime.js';
|
|
5
6
|
/**
|
|
6
7
|
* Keeps the background-thread worklet ctx alive while main thread still holds
|
|
7
8
|
* a handle to one of its background functions.
|
|
8
9
|
*/
|
|
9
10
|
export class BackgroundFunctionExecMap extends IndexMap {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(cardLifetime('backgroundFunctionCtxId', () => ({ lastIndex: 0 })));
|
|
13
|
+
}
|
|
14
|
+
clear() {
|
|
15
|
+
this.indexMap.clear();
|
|
16
|
+
}
|
|
10
17
|
add(worklet) {
|
|
11
18
|
const execId = super.add(worklet);
|
|
12
19
|
worklet._execId = execId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec-map.js","sourceRoot":"","sources":["../../../src/core/background-function/exec-map.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"exec-map.js","sourceRoot":"","sources":["../../../src/core/background-function/exec-map.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,yBAA0B,SAAQ,QAAiB;IAC9D;QACE,KAAK,CAAC,YAAY,CAAC,yBAAyB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3E,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;IAEe,GAAG,CAAC,OAAgB;QAClC,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAClC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;QACzB,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,cAAc,CAAC,MAAc,EAAE,IAAY;QAChD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAEO,qBAAqB,CAAC,KAAc,EAAE,IAAY;QACxD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAChD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,GAAG,GAAG,KAAgC,CAAC;QAC7C,IAAI,SAAS,IAAI,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;YAChD,OAAO,GAAiB,CAAC;QAC3B,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;YACxD,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","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\nimport { IndexMap } from '../../shared/index-map.js';\nimport type { JsFnHandle, Worklet } from '../../worklet-runtime/bindings/types.js';\nimport { cardLifetime } from '../card-lifetime.js';\n\n/**\n * Keeps the background-thread worklet ctx alive while main thread still holds\n * a handle to one of its background functions.\n */\nexport class BackgroundFunctionExecMap extends IndexMap<Worklet> {\n constructor() {\n super(cardLifetime('backgroundFunctionCtxId', () => ({ lastIndex: 0 })));\n }\n\n public clear(): void {\n this.indexMap.clear();\n }\n\n public override add(worklet: Worklet): number {\n const execId = super.add(worklet);\n worklet._execId = execId;\n return execId;\n }\n\n public findJsFnHandle(execId: number, fnId: number): JsFnHandle | undefined {\n const worklet = this.get(execId);\n if (!worklet) {\n return undefined;\n }\n\n return this.findJsFnHandleInValue(worklet, fnId);\n }\n\n private findJsFnHandleInValue(value: unknown, fnId: number): JsFnHandle | undefined {\n if (value === null || typeof value !== 'object') {\n return undefined;\n }\n const obj = value as Record<string, unknown>;\n if ('_jsFnId' in obj && obj['_jsFnId'] === fnId) {\n return obj as JsFnHandle;\n }\n for (const i in obj) {\n const result = this.findJsFnHandleInValue(obj[i], fnId);\n if (result) {\n return result;\n }\n }\n return undefined;\n }\n}\n"]}
|
|
@@ -5,45 +5,42 @@ import { BackgroundFunctionExecMap } from './exec-map.js';
|
|
|
5
5
|
import { isSdkVersionGt } from '../../utils.js';
|
|
6
6
|
import { delayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';
|
|
7
7
|
import { WorkletEvents } from '../../worklet-runtime/bindings/events.js';
|
|
8
|
-
import {
|
|
8
|
+
import { addReloadScopedEventListener, dispatchReloadScopedEvent } from '../reload-scoped-event.js';
|
|
9
|
+
import { isRuntimeDestroyed, registerDestroyTask } from '../runtime-destroy.js';
|
|
9
10
|
import { onFunctionCall } from '../thread-function-call/return-value.js';
|
|
10
11
|
let execIdMap;
|
|
11
12
|
let cleanupBackgroundFunctionRuntime;
|
|
12
13
|
let unregisterBackgroundFunctionCleanup;
|
|
13
14
|
function initBackgroundFunctionRuntime() {
|
|
14
15
|
'background only';
|
|
15
|
-
if (
|
|
16
|
+
if (cleanupBackgroundFunctionRuntime) {
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
18
|
-
execIdMap
|
|
19
|
+
execIdMap ??= new BackgroundFunctionExecMap();
|
|
19
20
|
const context = lynx.getCoreContext();
|
|
20
|
-
context
|
|
21
|
+
const removeListener = addReloadScopedEventListener(context, WorkletEvents.runOnBackground, runBackgroundFunction);
|
|
21
22
|
context.addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);
|
|
22
23
|
cleanupBackgroundFunctionRuntime = () => {
|
|
23
|
-
|
|
24
|
+
removeListener();
|
|
24
25
|
context.removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);
|
|
25
|
-
execIdMap
|
|
26
|
+
execIdMap.clear();
|
|
26
27
|
cleanupBackgroundFunctionRuntime = undefined;
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
30
31
|
* @internal
|
|
31
32
|
*/
|
|
32
|
-
export function runBackgroundFunction(
|
|
33
|
+
export function runBackgroundFunction(data) {
|
|
33
34
|
'background only';
|
|
34
|
-
const data = JSON.parse(event.data);
|
|
35
35
|
const obj = execIdMap.findJsFnHandle(data.obj._execId, data.obj._jsFnId);
|
|
36
36
|
const f = obj?._fn;
|
|
37
37
|
if (!f) {
|
|
38
38
|
throw new Error('runOnBackground: JS function not found: ' + JSON.stringify(data.obj));
|
|
39
39
|
}
|
|
40
40
|
const returnValue = f(...data.params);
|
|
41
|
-
lynx.getCoreContext()
|
|
41
|
+
dispatchReloadScopedEvent(lynx.getCoreContext(), {
|
|
42
42
|
type: WorkletEvents.FunctionCallRet,
|
|
43
|
-
data:
|
|
44
|
-
resolveId: data.resolveId,
|
|
45
|
-
returnValue,
|
|
46
|
-
}),
|
|
43
|
+
data: { resolveId: data.resolveId, returnValue },
|
|
47
44
|
});
|
|
48
45
|
}
|
|
49
46
|
function releaseBackgroundFunctionCtx(event) {
|
|
@@ -109,6 +106,8 @@ export function runOnBackground(f) {
|
|
|
109
106
|
}
|
|
110
107
|
return async (...params) => {
|
|
111
108
|
return new Promise((resolve) => {
|
|
109
|
+
if (isRuntimeDestroyed())
|
|
110
|
+
return;
|
|
112
111
|
const resolveId = onFunctionCall(resolve);
|
|
113
112
|
if (obj._isFirstScreen) {
|
|
114
113
|
delayRunOnBackground(obj, (fnId, execId) => {
|
|
@@ -121,16 +120,16 @@ export function runOnBackground(f) {
|
|
|
121
120
|
};
|
|
122
121
|
}
|
|
123
122
|
function dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId) {
|
|
124
|
-
lynx.getJSContext()
|
|
123
|
+
dispatchReloadScopedEvent(lynx.getJSContext(), {
|
|
125
124
|
type: WorkletEvents.runOnBackground,
|
|
126
|
-
data:
|
|
125
|
+
data: {
|
|
127
126
|
obj: {
|
|
128
127
|
_jsFnId: fnId,
|
|
129
128
|
_execId: execId,
|
|
130
129
|
},
|
|
131
130
|
params,
|
|
132
131
|
resolveId,
|
|
133
|
-
}
|
|
132
|
+
},
|
|
134
133
|
});
|
|
135
134
|
}
|
|
136
135
|
//# sourceMappingURL=run-on-background.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-on-background.js","sourceRoot":"","sources":["../../../src/core/background-function/run-on-background.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAGzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"run-on-background.js","sourceRoot":"","sources":["../../../src/core/background-function/run-on-background.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C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,CAAC;IACrE,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IACD,MAAM,GAAG,GAAG,CAAsB,CAAC;IACnC,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,EAAE,GAAG,MAA0B,EAAc,EAAE;QACzD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,IAAI,kBAAkB,EAAE;gBAAE,OAAO;YACjC,MAAM,SAAS,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;YAE1C,IAAI,GAAG,CAAC,cAAc,EAAE,CAAC;gBACvB,oBAAoB,CAAC,GAAG,EAAE,CAAC,IAAY,EAAE,MAAc,EAAE,EAAE;oBACzD,kCAAkC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;gBACtE,CAAC,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YAED,kCAAkC,CAAC,GAAG,CAAC,OAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,OAAQ,EAAE,SAAS,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,kCAAkC,CACzC,IAAY,EACZ,MAA0B,EAC1B,MAAc,EACd,SAAiB;IAEjB,yBAAyB,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE;QAC7C,IAAI,EAAE,aAAa,CAAC,eAAe;QACnC,IAAI,EAAE;YACJ,GAAG,EAAE;gBACH,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,MAAM;aAChB;YACD,MAAM;YACN,SAAS;SACa;KACzB,CAAC,CAAC;AACL,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\nimport { BackgroundFunctionExecMap } from './exec-map.js';\nimport { isSdkVersionGt } from '../../utils.js';\nimport { delayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';\nimport { WorkletEvents } from '../../worklet-runtime/bindings/events.js';\nimport type { RunWorkletCtxRetData } from '../../worklet-runtime/bindings/events.js';\nimport type { ClosureValueType, JsFnHandle, Worklet } from '../../worklet-runtime/bindings/types.js';\nimport { addReloadScopedEventListener, dispatchReloadScopedEvent } from '../reload-scoped-event.js';\nimport { isRuntimeDestroyed, registerDestroyTask } from '../runtime-destroy.js';\nimport { onFunctionCall } from '../thread-function-call/return-value.js';\n\n/**\n * @internal\n */\ninterface RunOnBackgroundData {\n obj: JsFnHandle;\n params: unknown[];\n resolveId: number;\n}\n\nlet execIdMap: BackgroundFunctionExecMap | undefined;\nlet cleanupBackgroundFunctionRuntime: (() => void) | undefined;\nlet unregisterBackgroundFunctionCleanup: (() => void) | undefined;\n\nfunction initBackgroundFunctionRuntime(): void {\n 'background only';\n if (cleanupBackgroundFunctionRuntime) {\n return;\n }\n\n execIdMap ??= new BackgroundFunctionExecMap();\n const context = lynx.getCoreContext();\n const removeListener = addReloadScopedEventListener(context, WorkletEvents.runOnBackground, runBackgroundFunction);\n context.addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n\n cleanupBackgroundFunctionRuntime = () => {\n removeListener();\n context.removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n execIdMap!.clear();\n cleanupBackgroundFunctionRuntime = undefined;\n };\n}\n\n/**\n * @internal\n */\nexport function runBackgroundFunction(data: RunOnBackgroundData): void {\n 'background only';\n const obj = execIdMap!.findJsFnHandle(data.obj._execId!, data.obj._jsFnId!);\n const f = obj?._fn;\n if (!f) {\n throw new Error('runOnBackground: JS function not found: ' + JSON.stringify(data.obj));\n }\n const returnValue = f(...data.params);\n dispatchReloadScopedEvent(lynx.getCoreContext(), {\n type: WorkletEvents.FunctionCallRet,\n data: { resolveId: data.resolveId, returnValue } satisfies RunWorkletCtxRetData,\n });\n}\n\nfunction releaseBackgroundFunctionCtx(event: RuntimeProxy.Event): void {\n 'background only';\n for (const id of event.data) {\n execIdMap!.remove(id as number);\n }\n}\n\n/**\n * @internal\n */\nexport function registerBackgroundFunctionCtx(ctx: Worklet): void {\n 'background only';\n initBackgroundFunctionRuntime();\n ensureBackgroundFunctionCleanup();\n execIdMap!.add(ctx);\n}\n\nfunction ensureBackgroundFunctionCleanup(): void {\n if (unregisterBackgroundFunctionCleanup) {\n return;\n }\n unregisterBackgroundFunctionCleanup = registerDestroyTask(() => {\n resetBackgroundFunctionRuntime();\n });\n}\n\nexport function resetBackgroundFunctionRuntime(): void {\n cleanupBackgroundFunctionRuntime?.();\n unregisterBackgroundFunctionCleanup?.();\n unregisterBackgroundFunctionCleanup = undefined;\n}\n\n/**\n * `runOnBackground` allows triggering js functions on the background thread asynchronously.\n * @param f - The js function to be called.\n * @returns A function. Calling which with the arguments to be passed to the js function to trigger it on the background thread. This function returns a promise that resolves to the return value of the js function.\n * @public\n *\n * @example\n *\n * ```ts\n * import { runOnBackground } from '@lynx-js/react';\n *\n * async function someMainthreadFunction() {\n * 'main thread';\n * const fn = runOnBackground(() => {\n * return 'hello';\n * });\n * const result = await fn();\n * }\n * ```\n *\n * @group Functions\n */\nexport function runOnBackground<R, Fn extends (...args: any[]) => R>(\n f: Fn,\n): (...args: Parameters<Fn>) => Promise<R> {\n if (!isSdkVersionGt(2, 15)) {\n throw new Error('runOnBackground requires Lynx sdk version 2.16.');\n }\n if (__JS__) {\n throw new Error('runOnBackground can only be used on the main thread.');\n }\n const obj = f as any as JsFnHandle;\n if (obj._error) {\n throw new Error(obj._error);\n }\n return async (...params: ClosureValueType[]): Promise<R> => {\n return new Promise((resolve) => {\n if (isRuntimeDestroyed()) return;\n const resolveId = onFunctionCall(resolve);\n\n if (obj._isFirstScreen) {\n delayRunOnBackground(obj, (fnId: number, execId: number) => {\n dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolveId);\n });\n return;\n }\n\n dispatchRunBackgroundFunctionEvent(obj._jsFnId!, params, obj._execId!, resolveId);\n });\n };\n}\n\nfunction dispatchRunBackgroundFunctionEvent(\n fnId: number,\n params: ClosureValueType[],\n execId: number,\n resolveId: number,\n): void {\n dispatchReloadScopedEvent(lynx.getJSContext(), {\n type: WorkletEvents.runOnBackground,\n data: {\n obj: {\n _jsFnId: fnId,\n _execId: execId,\n },\n params,\n resolveId,\n } as RunOnBackgroundData,\n });\n}\n"]}
|
|
@@ -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"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
const storeKey = Symbol.for('__REACT_LYNX_CARD_LIFETIME__');
|
|
5
|
+
/**
|
|
6
|
+
* Module-level state that survives an entry re-evaluation, for state tied to
|
|
7
|
+
* native objects that outlive the entry or IDs that late messages may carry.
|
|
8
|
+
*/
|
|
9
|
+
export function cardLifetime(key, init) {
|
|
10
|
+
if (typeof __EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__ === 'undefined' || !__EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__) {
|
|
11
|
+
return init();
|
|
12
|
+
}
|
|
13
|
+
const host = lynx;
|
|
14
|
+
const store = host[storeKey] ??= {};
|
|
15
|
+
return (store[key] ??= init());
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=card-lifetime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-lifetime.js","sourceRoot":"","sources":["../../src/core/card-lifetime.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAmB,GAAW,EAAE,IAAa;IACvE,IAAI,OAAO,qCAAqC,KAAK,WAAW,IAAI,CAAC,qCAAqC,EAAE,CAAC;QAC3G,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IACD,MAAM,IAAI,GAAG,IAAqE,CAAC;IACnF,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACpC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAM,CAAC;AACtC,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\nconst storeKey = Symbol.for('__REACT_LYNX_CARD_LIFETIME__');\n\n/**\n * Module-level state that survives an entry re-evaluation, for state tied to\n * native objects that outlive the entry or IDs that late messages may carry.\n */\nexport function cardLifetime<T extends object>(key: string, init: () => T): T {\n if (typeof __EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__ === 'undefined' || !__EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__) {\n return init();\n }\n const host = lynx as unknown as Record<symbol, Record<string, object> | undefined>;\n const store = host[storeKey] ??= {};\n return (store[key] ??= init()) as T;\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"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function canReEvalMainThreadEntry(): boolean;
|
|
2
|
+
export declare function canReEvalBackgroundEntry(): boolean;
|
|
3
|
+
/** Lets the entry being evaluated finish a reload started by the previous one. */
|
|
4
|
+
export declare function installMainThreadReloadCompleter<Handoff>(complete: (handoff: Handoff) => void): void;
|
|
5
|
+
export declare function reEvalMainThreadEntry<Handoff>(handoff: Handoff): void;
|
|
6
|
+
/** @param retire - stops this entry from sending work to the main thread */
|
|
7
|
+
export declare function reEvalBackgroundEntry(updateData: Record<string, unknown>, options: Record<string, unknown> | undefined, retire: () => void): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
import { increaseReloadVersion } from './reload-version.js';
|
|
5
|
+
import { destroyRuntime } from './runtime-destroy.js';
|
|
6
|
+
const supportsReEvalKey = Symbol.for('__LYNX_ENTRY_SUPPORTS_RE_EVAL__');
|
|
7
|
+
const reloaderKey = Symbol.for('__LYNX_MAIN_THREAD_ENTRY_RELOADER__');
|
|
8
|
+
const completerKey = Symbol.for('__LYNX_MAIN_THREAD_RELOAD_COMPLETER__');
|
|
9
|
+
const externalGlobalKey = Symbol.for('__LYNX_EXTERNAL_GLOBAL__');
|
|
10
|
+
const host = () => lynx;
|
|
11
|
+
function isEntryReEvalEnabled() {
|
|
12
|
+
return typeof __EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__ !== 'undefined'
|
|
13
|
+
&& __EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__
|
|
14
|
+
&& host()[supportsReEvalKey] === true;
|
|
15
|
+
}
|
|
16
|
+
export function canReEvalMainThreadEntry() {
|
|
17
|
+
return isEntryReEvalEnabled() && typeof host()[reloaderKey] === 'function';
|
|
18
|
+
}
|
|
19
|
+
export function canReEvalBackgroundEntry() {
|
|
20
|
+
return isEntryReEvalEnabled() && typeof lynx.getApp().reloadCard === 'function';
|
|
21
|
+
}
|
|
22
|
+
/** Lets the entry being evaluated finish a reload started by the previous one. */
|
|
23
|
+
export function installMainThreadReloadCompleter(complete) {
|
|
24
|
+
if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__
|
|
25
|
+
&& typeof __EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__ !== 'undefined' && __EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__) {
|
|
26
|
+
host()[completerKey] = complete;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function reEvalMainThreadEntry(handoff) {
|
|
30
|
+
// Evaluating the entry resets `__initData`.
|
|
31
|
+
const initData = lynx.__initData;
|
|
32
|
+
destroyRuntime();
|
|
33
|
+
Reflect.deleteProperty(lynx, externalGlobalKey);
|
|
34
|
+
host()[reloaderKey]();
|
|
35
|
+
lynx.__initData = initData;
|
|
36
|
+
host()[completerKey](handoff);
|
|
37
|
+
}
|
|
38
|
+
/** @param retire - stops this entry from sending work to the main thread */
|
|
39
|
+
export function reEvalBackgroundEntry(updateData, options, retire) {
|
|
40
|
+
const data = Object.assign({}, lynx.__initData, updateData);
|
|
41
|
+
destroyRuntime();
|
|
42
|
+
increaseReloadVersion();
|
|
43
|
+
retire();
|
|
44
|
+
const app = lynx.getApp();
|
|
45
|
+
app.callDestroyLifetimeFun();
|
|
46
|
+
Reflect.deleteProperty(lynx, externalGlobalKey);
|
|
47
|
+
app.reloadCard(data, options);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=entry-reload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-reload.js","sourceRo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M,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC;IACjC,cAAc,EAAE,CAAC;IACjB,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IAC/C,IAAI,EAAE,CAAC,WAAW,CAAgB,EAAE,CAAC;IACtC,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;IAC1B,IAAI,EAAE,CAAC,YAAY,CAAgC,CAAC,OAAO,CAAC,CAAC;AAChE,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,qBAAqB,CACnC,UAAmC,EACnC,OAA4C,EAC5C,MAAkB;IAElB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC5D,cAAc,EAAE,CAAC;IACjB,qBAAqB,EAAE,CAAC;IACxB,MAAM,EAAE,CAAC;IACT,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC1B,GAAG,CAAC,sBAAsB,EAAE,CAAC;IAC7B,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IAChD,GAAG,CAAC,UAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACjC,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 { increaseReloadVersion } from './reload-version.js';\nimport { destroyRuntime } from './runtime-destroy.js';\n\nconst supportsReEvalKey = Symbol.for('__LYNX_ENTRY_SUPPORTS_RE_EVAL__');\nconst reloaderKey = Symbol.for('__LYNX_MAIN_THREAD_ENTRY_RELOADER__');\nconst completerKey = Symbol.for('__LYNX_MAIN_THREAD_RELOAD_COMPLETER__');\nconst externalGlobalKey = Symbol.for('__LYNX_EXTERNAL_GLOBAL__');\n\nconst host = () => lynx as unknown as Record<symbol, unknown>;\n\nfunction isEntryReEvalEnabled(): boolean {\n return typeof __EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__ !== 'undefined'\n && __EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__\n && host()[supportsReEvalKey] === true;\n}\n\nexport function canReEvalMainThreadEntry(): boolean {\n return isEntryReEvalEnabled() && typeof host()[reloaderKey] === 'function';\n}\n\nexport function canReEvalBackgroundEntry(): boolean {\n return isEntryReEvalEnabled() && typeof lynx.getApp().reloadCard === 'function';\n}\n\n/** Lets the entry being evaluated finish a reload started by the previous one. */\nexport function installMainThreadReloadCompleter<Handoff>(complete: (handoff: Handoff) => void): void {\n if (\n typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__\n && typeof __EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__ !== 'undefined' && __EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__\n ) {\n host()[completerKey] = complete;\n }\n}\n\nexport function reEvalMainThreadEntry<Handoff>(handoff: Handoff): void {\n // Evaluating the entry resets `__initData`.\n const initData = lynx.__initData;\n destroyRuntime();\n Reflect.deleteProperty(lynx, externalGlobalKey);\n (host()[reloaderKey] as () => void)();\n lynx.__initData = initData;\n (host()[completerKey] as (handoff: Handoff) => void)(handoff);\n}\n\n/** @param retire - stops this entry from sending work to the main thread */\nexport function reEvalBackgroundEntry(\n updateData: Record<string, unknown>,\n options: Record<string, unknown> | undefined,\n retire: () => void,\n): void {\n const data = Object.assign({}, lynx.__initData, updateData);\n destroyRuntime();\n increaseReloadVersion();\n retire();\n const app = lynx.getApp();\n app.callDestroyLifetimeFun();\n Reflect.deleteProperty(lynx, externalGlobalKey);\n app.reloadCard!(data, options);\n}\n"]}
|
|
@@ -53,7 +53,10 @@ export const makeSyncThen = function (result) {
|
|
|
53
53
|
// { level: "warning" }
|
|
54
54
|
// );
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
// The Lynx Promise polyfill shares resolved promises for primitive values.
|
|
57
|
+
// Own this promise before replacing `then`, or an undefined callback
|
|
58
|
+
// result would make unrelated Promise.resolve().then(...) calls synchronous.
|
|
59
|
+
const p = new Promise(resolve => resolve(ret));
|
|
57
60
|
const then = makeSyncThen(ret);
|
|
58
61
|
p.then = then;
|
|
59
62
|
return p;
|
|
@@ -299,7 +302,7 @@ export const loadLazyBundle = /*#__PURE__*/ (() => {
|
|
|
299
302
|
return impl;
|
|
300
303
|
})();
|
|
301
304
|
function withSyncResolvers() {
|
|
302
|
-
'background
|
|
305
|
+
'background only';
|
|
303
306
|
const resolver = {
|
|
304
307
|
resolve: (result) => {
|
|
305
308
|
resolver.result = result;
|
|
@@ -1 +1 @@
|
|
|
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,GAAG,aAAa,CAAC;AAC1C,MAAM,kBAAkB,GAAG,YAAY,CAAC;AACxC,MAAM,WAAW,GAAG,KAAK,CAAC;AAC1B,MAAM,8BAA8B,GAAG,CAAC,CAAC;AACzC,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAE5D,yEAAyE;AACzE,0EAA0E;AAC1E,+EAA+E;AAC/E,gFAAgF;AAChF,mDAAmD;AACnD,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAmB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,UAAY,MAAS;IAC/C,OAAO,UAEL,GAAmD,EACnD,IAAuD;QAEvD,IAAI,GAAG,EAAE,CAAC;YACR,IAAI,GAA2B,CAAC;YAChC,IAAI,CAAC;gBACH,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,aAAa;gBACb,oCAAoC;gBACpC,I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BACnD,IAAI,CAAC;wBACH,IAAI,CAAC,YAAY,EAAE,CAAC,eAAe,CACjC,uBAAuB,EACvB,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,EACrB,GAAG,EAAE;4BACH,4DAA4D;4BAC5D,kDAAkD;4BAClD,kBAAkB,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;4BAC1C,OAAO,CAAC,SAAS,CAAC,CAAC;wBACrB,CAAC,CACF,CAAC;oBACJ,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 const p = Promise.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/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M,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"]}
|