@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
|
@@ -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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QACpB,sDAAsD;QACtD,MAAM,mBAAmB,GAAY,0BAA0B,CAAC;QAChE,MAAM,GAAG;YACP,GAAG,MAAM;YACT,YAAY,EAAE,mBAAmB;SAClC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,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 { 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"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { cardLifetime } from './card-lifetime.js';
|
|
5
|
+
const lastId = /*#__PURE__*/ cardLifetime('mainThreadRefId', () => ({ bg: 0, mt: 0 }));
|
|
6
6
|
/** @internal */
|
|
7
7
|
export function allocateMainThreadRefId() {
|
|
8
|
-
return __JS__ ? ++
|
|
8
|
+
return __JS__ ? ++lastId.bg : --lastId.mt;
|
|
9
9
|
}
|
|
10
10
|
/** @internal */
|
|
11
11
|
export function clearMainThreadRefIdsForTesting() {
|
|
12
|
-
|
|
12
|
+
lastId.bg = lastId.mt = 0;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=main-thread-ref-id.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main-thread-ref-id.js","sourceRoot":"","sources":["../../src/core/main-thread-ref-id.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,
|
|
1
|
+
{"version":3,"file":"main-thread-ref-id.js","sourceRoot":"","sources":["../../src/core/main-thread-ref-id.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,MAAM,GAAG,aAAa,CAAC,YAAY,CAAC,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEvF,gBAAgB;AAChB,MAAM,UAAU,uBAAuB;IACrC,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC;AAC5C,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,+BAA+B;IAC7C,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC;AAC5B,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 { cardLifetime } from './card-lifetime.js';\n\nconst lastId = /*#__PURE__*/ cardLifetime('mainThreadRefId', () => ({ bg: 0, mt: 0 }));\n\n/** @internal */\nexport function allocateMainThreadRefId(): number {\n return __JS__ ? ++lastId.bg : --lastId.mt;\n}\n\n/** @internal */\nexport function clearMainThreadRefIdsForTesting(): void {\n lastId.bg = lastId.mt = 0;\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 { getReloadVersion } from './reload-version.js';
|
|
5
|
+
export function dispatchReloadScopedEvent(context, event) {
|
|
6
|
+
context.dispatchEvent({
|
|
7
|
+
type: event.type,
|
|
8
|
+
data: JSON.stringify({ ...event.data, reloadVersion: getReloadVersion() }),
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
// Deliver parsed payloads only while their page is current. Return cleanup for
|
|
12
|
+
// the actual registered wrapper, so callers need no listener identity registry.
|
|
13
|
+
export function addReloadScopedEventListener(context, type, listener) {
|
|
14
|
+
const handle = (event) => {
|
|
15
|
+
const data = JSON.parse(event.data);
|
|
16
|
+
// Unversioned events belong to the initial page only.
|
|
17
|
+
if ((data.reloadVersion ?? 0) !== getReloadVersion())
|
|
18
|
+
return;
|
|
19
|
+
listener(data);
|
|
20
|
+
};
|
|
21
|
+
context.addEventListener(type, handle);
|
|
22
|
+
return () => {
|
|
23
|
+
context.removeEventListener(type, handle);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=reload-scoped-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reload-scoped-event.js","sourceRoot":"","sources":["../../src/core/reload-scoped-event.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAMvD,MAAM,UAAU,yBAAyB,CAAC,OAAqB,EAAE,KAAqC;IACpG,OAAO,CAAC,aAAa,CAAC;QACpB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,gBAAgB,EAAE,EAAE,CAAC;KAC3E,CAAC,CAAC;AACL,CAAC;AAED,+EAA+E;AAC/E,gFAAgF;AAChF,MAAM,UAAU,4BAA4B,CAC1C,OAAqB,EACrB,IAAY,EACZ,QAA2B;IAE3B,MAAM,MAAM,GAAG,CAAC,KAAyB,EAAQ,EAAE;QACjD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAc,CAAoB,CAAC;QACjE,sDAAsD;QACtD,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,CAAC,KAAK,gBAAgB,EAAE;YAAE,OAAO;QAC7D,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC,CAAC;IACF,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACvC,OAAO,GAAG,EAAE;QACV,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC,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.\n\nimport { getReloadVersion } from './reload-version.js';\n\ninterface ReloadScope {\n reloadVersion?: number | undefined;\n}\n\nexport function dispatchReloadScopedEvent(context: RuntimeProxy, event: { type: string; data: object }): void {\n context.dispatchEvent({\n type: event.type,\n data: JSON.stringify({ ...event.data, reloadVersion: getReloadVersion() }),\n });\n}\n\n// Deliver parsed payloads only while their page is current. Return cleanup for\n// the actual registered wrapper, so callers need no listener identity registry.\nexport function addReloadScopedEventListener<T>(\n context: RuntimeProxy,\n type: string,\n listener: (data: T) => void,\n): () => void {\n const handle = (event: RuntimeProxy.Event): void => {\n const data = JSON.parse(event.data as string) as T & ReloadScope;\n // Unversioned events belong to the initial page only.\n if ((data.reloadVersion ?? 0) !== getReloadVersion()) return;\n listener(data);\n };\n context.addEventListener(type, handle);\n return () => {\n context.removeEventListener(type, handle);\n };\n}\n"]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
|
|
4
|
+
import { cardLifetime } from './card-lifetime.js';
|
|
5
|
+
const state = /*#__PURE__*/ cardLifetime('reloadVersion', () => ({ value: 0 }));
|
|
5
6
|
export function getReloadVersion() {
|
|
6
|
-
return
|
|
7
|
+
return state.value;
|
|
7
8
|
}
|
|
8
9
|
export function increaseReloadVersion() {
|
|
9
|
-
return ++
|
|
10
|
+
return ++state.value;
|
|
10
11
|
}
|
|
11
12
|
//# sourceMappingURL=reload-version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reload-version.js","sourceRoot":"","sources":["../../src/core/reload-version.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,
|
|
1
|
+
{"version":3,"file":"reload-version.js","sourceRoot":"","sources":["../../src/core/reload-version.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,KAAK,GAAG,aAAa,CAAC,YAAY,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEhF,MAAM,UAAU,gBAAgB;IAC9B,OAAO,KAAK,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,qBAAqB;IACnC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC;AACvB,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 { cardLifetime } from './card-lifetime.js';\n\nconst state = /*#__PURE__*/ cardLifetime('reloadVersion', () => ({ value: 0 }));\n\nexport function getReloadVersion(): number {\n return state.value;\n}\n\nexport function increaseReloadVersion(): number {\n return ++state.value;\n}\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
type DestroyTask = () => void;
|
|
2
|
+
export declare function isRuntimeDestroyed(): boolean;
|
|
3
|
+
export declare function destroyRuntime(): void;
|
|
2
4
|
export declare function registerDestroyTask(task: DestroyTask): () => void;
|
|
3
5
|
export declare function runDestroyTasks(): void;
|
|
4
6
|
export {};
|
|
@@ -2,6 +2,15 @@
|
|
|
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
|
const destroyTasks = new Set();
|
|
5
|
+
let destroyed = false;
|
|
6
|
+
// Calls from a retired entry stay pending: settling them would run its continuations.
|
|
7
|
+
export function isRuntimeDestroyed() {
|
|
8
|
+
return destroyed;
|
|
9
|
+
}
|
|
10
|
+
export function destroyRuntime() {
|
|
11
|
+
destroyed = true;
|
|
12
|
+
runDestroyTasks();
|
|
13
|
+
}
|
|
5
14
|
export function registerDestroyTask(task) {
|
|
6
15
|
destroyTasks.add(task);
|
|
7
16
|
return () => {
|
|
@@ -10,9 +19,9 @@ export function registerDestroyTask(task) {
|
|
|
10
19
|
}
|
|
11
20
|
export function runDestroyTasks() {
|
|
12
21
|
const tasks = Array.from(destroyTasks);
|
|
22
|
+
destroyTasks.clear();
|
|
13
23
|
for (const task of tasks) {
|
|
14
24
|
task();
|
|
15
25
|
}
|
|
16
|
-
destroyTasks.clear();
|
|
17
26
|
}
|
|
18
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;
|
|
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"]}
|
|
@@ -7,6 +7,8 @@ import { WorkletEvents } from '../../worklet-runtime/bindings/events.js';
|
|
|
7
7
|
import { registerBackgroundFunctionCtx } from '../background-function/run-on-background.js';
|
|
8
8
|
import { isMainThreadFunction } from '../main-thread-function.js';
|
|
9
9
|
import { isMtsEnabled } from '../mts-capability.js';
|
|
10
|
+
import { dispatchReloadScopedEvent } from '../reload-scoped-event.js';
|
|
11
|
+
import { isRuntimeDestroyed } from '../runtime-destroy.js';
|
|
10
12
|
export let delayedRunOnMainThreadData = [];
|
|
11
13
|
export function enqueueDelayedRunOnMainThreadData(data) {
|
|
12
14
|
delayedRunOnMainThreadData.push(data);
|
|
@@ -29,6 +31,8 @@ export function createRunOnMainThread(options) {
|
|
|
29
31
|
}
|
|
30
32
|
return async (...params) => {
|
|
31
33
|
return new Promise((resolve) => {
|
|
34
|
+
if (isRuntimeDestroyed())
|
|
35
|
+
return;
|
|
32
36
|
const worklet = fn;
|
|
33
37
|
prepareMainThreadFunctionCtx(worklet);
|
|
34
38
|
const data = {
|
|
@@ -54,9 +58,6 @@ function prepareMainThreadFunctionCtx(worklet) {
|
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
function dispatchRunOnMainThreadEvent(data) {
|
|
57
|
-
lynx.getCoreContext().
|
|
58
|
-
type: WorkletEvents.runWorkletCtx,
|
|
59
|
-
data: JSON.stringify(data),
|
|
60
|
-
});
|
|
61
|
+
dispatchReloadScopedEvent(lynx.getCoreContext(), { type: WorkletEvents.runWorkletCtx, data });
|
|
61
62
|
}
|
|
62
63
|
//# sourceMappingURL=main-thread.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main-thread.js","sourceRoot":"","sources":["../../../src/core/thread-function-call/main-thread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,C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B,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,KAAK,EAAE,GAAG,MAAsB,EAAc,EAAE;YACrD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC7B,IAAI,kBAAkB,EAAE;oBAAE,OAAO;gBACjC,MAAM,OAAO,GAAG,EAAwB,CAAC;gBACzC,4BAA4B,CAAC,OAAO,CAAC,CAAC;gBACtC,MAAM,IAAI,GAAG;oBACX,OAAO;oBACP,MAAM;oBACN,SAAS,EAAE,cAAc,CAAC,OAAO,CAAC;iBACd,CAAC;gBAEvB,IAAI,OAAO,CAAC,qCAAqC,EAAE,EAAE,CAAC;oBACpD,4BAA4B,CAAC,IAAI,CAAC,CAAC;oBACnC,OAAO;gBACT,CAAC;gBAED,iCAAiC,CAAC,IAAI,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,0BAA0B;IACjC,OAAO,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,4BAA4B,CAAC,OAAgB;IACpD,IAAI,oBAAoB,CAAC,OAAO,CAAC,IAAI,0BAA0B,EAAE,EAAE,CAAC;QAClE,6BAA6B,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;AACH,CAAC;AAED,SAAS,4BAA4B,CAAC,IAAuB;IAC3D,yBAAyB,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,EAAE,IAAI,EAAE,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;AAChG,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 { onFunctionCall } from './return-value.js';\nimport { isSdkVersionGt } from '../../utils.js';\nimport { WorkletEvents } from '../../worklet-runtime/bindings/events.js';\nimport type { RunWorkletCtxData } from '../../worklet-runtime/bindings/events.js';\nimport type { Worklet } from '../../worklet-runtime/bindings/types.js';\nimport { registerBackgroundFunctionCtx } from '../background-function/run-on-background.js';\nimport { isMainThreadFunction } from '../main-thread-function.js';\nimport { isMtsEnabled } from '../mts-capability.js';\nimport { dispatchReloadScopedEvent } from '../reload-scoped-event.js';\nimport { isRuntimeDestroyed } from '../runtime-destroy.js';\n\ninterface RunOnMainThreadOptions {\n shouldDispatchRunOnMainThreadDirectly: () => boolean;\n}\n\nexport type RunOnMainThread = <R, Fn extends (...args: any[]) => R>(fn: Fn) => (...args: Parameters<Fn>) => Promise<R>;\n\nexport let delayedRunOnMainThreadData: RunWorkletCtxData[] = [];\n\nexport function enqueueDelayedRunOnMainThreadData(data: RunWorkletCtxData): void {\n delayedRunOnMainThreadData.push(data);\n}\n\nexport function takeDelayedRunOnMainThreadData(): typeof delayedRunOnMainThreadData {\n const data = delayedRunOnMainThreadData;\n delayedRunOnMainThreadData = [];\n return data;\n}\n\n/**\n * @internal\n */\nexport function createRunOnMainThread(\n options: RunOnMainThreadOptions,\n): RunOnMainThread {\n return <R, Fn extends (...args: any[]) => R>(fn: Fn): (...args: Parameters<Fn>) => Promise<R> => {\n if (__LEPUS__) {\n throw new Error('runOnMainThread can only be used on the background thread.');\n }\n if (!isMtsEnabled()) {\n throw new Error('runOnMainThread requires Lynx sdk version 2.14.');\n }\n return async (...params: Parameters<Fn>): Promise<R> => {\n return new Promise((resolve) => {\n if (isRuntimeDestroyed()) return;\n const worklet = fn as unknown as Worklet;\n prepareMainThreadFunctionCtx(worklet);\n const data = {\n worklet,\n params,\n resolveId: onFunctionCall(resolve),\n } as RunWorkletCtxData;\n\n if (options.shouldDispatchRunOnMainThreadDirectly()) {\n dispatchRunOnMainThreadEvent(data);\n return;\n }\n\n enqueueDelayedRunOnMainThreadData(data);\n });\n };\n };\n}\n\nfunction isRunOnBackgroundSupported(): boolean {\n return isSdkVersionGt(2, 15);\n}\n\nfunction prepareMainThreadFunctionCtx(worklet: unknown): void {\n if (isMainThreadFunction(worklet) && isRunOnBackgroundSupported()) {\n registerBackgroundFunctionCtx(worklet);\n }\n}\n\nfunction dispatchRunOnMainThreadEvent(data: RunWorkletCtxData): void {\n dispatchReloadScopedEvent(lynx.getCoreContext(), { type: WorkletEvents.runWorkletCtx, data });\n}\n"]}
|
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { IndexMap } from '../../shared/index-map.js';
|
|
5
5
|
import { WorkletEvents } from '../../worklet-runtime/bindings/events.js';
|
|
6
|
+
import { cardLifetime } from '../card-lifetime.js';
|
|
7
|
+
import { addReloadScopedEventListener } from '../reload-scoped-event.js';
|
|
6
8
|
import { registerDestroyTask } from '../runtime-destroy.js';
|
|
7
9
|
let resolveMap;
|
|
8
10
|
let cleanupReturnValueListener;
|
|
9
11
|
let unregisterReturnValueCleanup;
|
|
10
12
|
function initReturnValueListener() {
|
|
11
13
|
const context = __JS__ ? lynx.getCoreContext() : lynx.getJSContext();
|
|
12
|
-
resolveMap = new IndexMap();
|
|
13
|
-
context
|
|
14
|
+
resolveMap = new IndexMap(cardLifetime('functionCallId', () => ({ lastIndex: 0 })));
|
|
15
|
+
const removeListener = addReloadScopedEventListener(context, WorkletEvents.FunctionCallRet, onFunctionCallRet);
|
|
14
16
|
cleanupReturnValueListener = () => {
|
|
15
|
-
|
|
17
|
+
removeListener();
|
|
16
18
|
resolveMap = undefined;
|
|
17
19
|
cleanupReturnValueListener = undefined;
|
|
18
20
|
};
|
|
@@ -51,8 +53,7 @@ export function dropFunctionCallReturnIds(resolveIds) {
|
|
|
51
53
|
resetFunctionCallReturnListener();
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
|
-
function onFunctionCallRet(
|
|
55
|
-
const data = JSON.parse(event.data);
|
|
56
|
+
function onFunctionCallRet(data) {
|
|
56
57
|
const map = resolveMap;
|
|
57
58
|
if (!map) {
|
|
58
59
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"return-value.js","sourceRoot":"","sources":["../../../src/core/thread-function-call/return-value.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAEzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,IAAI,UAAsD,CAAC;AAC3D,IAAI,0BAAoD,CAAC;AACzD,IAAI,4BAAsD,CAAC;AAE3D,SAAS,uBAAuB;IAC9B,MAAM,OAAO,GAAiB,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;IAEnF,UAAU,GAAG,IAAI,QAAQ,
|
|
1
|
+
{"version":3,"file":"return-value.js","sourceRoot":"","sources":["../../../src/core/thread-function-call/return-value.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,IAAI,UAAsD,CAAC;AAC3D,IAAI,0BAAoD,CAAC;AACzD,IAAI,4BAAsD,CAAC;AAE3D,SAAS,uBAAuB;IAC9B,MAAM,OAAO,GAAiB,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;IAEnF,UAAU,GAAG,IAAI,QAAQ,CAAC,YAAY,CAAC,gBAAg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G,UAAU,CAAC;IACvB,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;IACT,CAAC;IACD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["// Copyright 2025 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 { WorkletEvents } from '../../worklet-runtime/bindings/events.js';\nimport type { RunWorkletCtxRetData } from '../../worklet-runtime/bindings/events.js';\nimport { cardLifetime } from '../card-lifetime.js';\nimport { addReloadScopedEventListener } from '../reload-scoped-event.js';\nimport { registerDestroyTask } from '../runtime-destroy.js';\n\nlet resolveMap: IndexMap<(value: any) => void> | undefined;\nlet cleanupReturnValueListener: (() => void) | undefined;\nlet unregisterReturnValueCleanup: (() => void) | undefined;\n\nfunction initReturnValueListener(): void {\n const context: RuntimeProxy = __JS__ ? lynx.getCoreContext() : lynx.getJSContext();\n\n resolveMap = new IndexMap(cardLifetime('functionCallId', () => ({ lastIndex: 0 })));\n const removeListener = addReloadScopedEventListener(context, WorkletEvents.FunctionCallRet, onFunctionCallRet);\n\n cleanupReturnValueListener = () => {\n removeListener();\n resolveMap = undefined;\n cleanupReturnValueListener = undefined;\n };\n}\n\n/**\n * @internal\n */\nexport function onFunctionCall(resolve: (value: any) => void): number {\n ensureFunctionCallReturnCleanup();\n if (!resolveMap) {\n initReturnValueListener();\n }\n return resolveMap!.add(resolve);\n}\n\nfunction ensureFunctionCallReturnCleanup(): void {\n if (unregisterReturnValueCleanup) {\n return;\n }\n unregisterReturnValueCleanup = registerDestroyTask(() => {\n resetFunctionCallReturnListener();\n });\n}\n\nexport function resetFunctionCallReturnListener(): void {\n cleanupReturnValueListener?.();\n unregisterReturnValueCleanup?.();\n unregisterReturnValueCleanup = undefined;\n}\n\nexport function dropFunctionCallReturnIds(resolveIds: readonly number[]): void {\n if (!resolveMap) {\n return;\n }\n for (const resolveId of resolveIds) {\n resolveMap.remove(resolveId);\n }\n if (resolveMap.size === 0) {\n resetFunctionCallReturnListener();\n }\n}\n\nfunction onFunctionCallRet(data: RunWorkletCtxRetData): void {\n const map = resolveMap;\n if (!map) {\n return;\n }\n const resolve = map.get(data.resolveId);\n if (!resolve) {\n return;\n }\n map.remove(data.resolveId);\n resolve(data.returnValue);\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,EA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MAAM,EAAE,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACtC,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;IACF,SAAS,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"]}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { options } from 'preact';
|
|
5
5
|
import { globalCommitContext, resetGlobalCommitContext, takeRemovedSubtreesForPostDispatchTeardown, } from './commit-context.js';
|
|
6
6
|
import { clearElementTemplateRenderScope, resetElementTemplateRenderScope } from './render-scope.js';
|
|
7
|
-
import { takeMainThreadRefInitValuePatch } from '../../core/main-thread-ref-init-value.js';
|
|
8
7
|
import { globalPipelineOptions, markTiming, markTimingLegacy, setPipeline } from '../../core/performance.js';
|
|
9
8
|
import { getReloadVersion } from '../../core/reload-version.js';
|
|
10
9
|
import { delayedRunOnMainThreadData, takeDelayedRunOnMainThreadData, } from '../../core/thread-function-call/main-thread.js';
|
|
@@ -13,6 +12,7 @@ import { COMMIT } from '../../shared/render-constants.js';
|
|
|
13
12
|
import { hook, isEmptyObject } from '../../utils.js';
|
|
14
13
|
import { formatElementTemplateUpdateCommands } from '../debug/alog.js';
|
|
15
14
|
import { profileEnd, profileStart } from '../debug/profile.js';
|
|
15
|
+
import { sendMTRefInitValueToMainThread } from '../main-thread-ref-init-value.js';
|
|
16
16
|
import { clearPendingRefs, flushPendingRefs, hasPendingRefs } from '../prop-adapters/ref.js';
|
|
17
17
|
import { createElementTemplateUpdateEvent } from '../protocol/update-event.js';
|
|
18
18
|
let installed = false;
|
|
@@ -48,14 +48,21 @@ export function cancelElementTemplateRemovedSubtreeCleanup() {
|
|
|
48
48
|
}
|
|
49
49
|
scheduledRemovedSubtreeCleanupTimers.clear();
|
|
50
50
|
}
|
|
51
|
-
function
|
|
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
|
+
}
|
|
60
|
+
function flushElementTemplateCommitChanges() {
|
|
52
61
|
const hasNativeOps = globalCommitContext.ops.length > 0;
|
|
53
62
|
const hasDelayedRunOnMainThread = delayedRunOnMainThreadData.length > 0;
|
|
54
|
-
const hasMainThreadRefInitValuePatch = mainThreadRefInitValuePatch.length > 0;
|
|
55
63
|
const hasUpdatePayload = hasNativeOps
|
|
56
64
|
|| !isEmptyObject(globalCommitContext.flushOptions)
|
|
57
|
-
|| hasDelayedRunOnMainThread
|
|
58
|
-
|| hasMainThreadRefInitValuePatch;
|
|
65
|
+
|| hasDelayedRunOnMainThread;
|
|
59
66
|
const removedSubtreesAwaitingTeardown = hasNativeOps ? takeRemovedSubtreesForPostDispatchTeardown() : [];
|
|
60
67
|
if (hasUpdatePayload) {
|
|
61
68
|
markTimingLegacy('updateDiffVdomEnd');
|
|
@@ -89,7 +96,6 @@ function flushElementTemplateCommitChanges(mainThreadRefInitValuePatch) {
|
|
|
89
96
|
flushOptions: globalCommitContext.flushOptions,
|
|
90
97
|
flowIds: globalCommitContext.flowIds,
|
|
91
98
|
delayedRunOnMainThreadDataCount: delayedRunOnMainThreadPayload?.length,
|
|
92
|
-
mainThreadRefInitValuePatchCount: mainThreadRefInitValuePatch.length,
|
|
93
99
|
}, null, 2));
|
|
94
100
|
}
|
|
95
101
|
updateEvent = createElementTemplateUpdateEvent({
|
|
@@ -98,18 +104,10 @@ function flushElementTemplateCommitChanges(mainThreadRefInitValuePatch) {
|
|
|
98
104
|
reloadVersion: getReloadVersion(),
|
|
99
105
|
flowIds: globalCommitContext.flowIds,
|
|
100
106
|
delayedRunOnMainThreadData: delayedRunOnMainThreadPayload,
|
|
101
|
-
mainThreadRefInitValuePatch: hasMainThreadRefInitValuePatch
|
|
102
|
-
? mainThreadRefInitValuePatch
|
|
103
|
-
: undefined,
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
catch (error) {
|
|
107
|
-
|
|
108
|
-
dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));
|
|
109
|
-
}
|
|
110
|
-
clearPendingRefs();
|
|
111
|
-
resetGlobalCommitContext();
|
|
112
|
-
scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);
|
|
110
|
+
cleanupFailedElementTemplateCommit(removedSubtreesAwaitingTeardown, delayedRunOnMainThreadPayload);
|
|
113
111
|
throw error;
|
|
114
112
|
}
|
|
115
113
|
lynx.getCoreContext().dispatchEvent(updateEvent);
|
|
@@ -133,21 +131,25 @@ export function installElementTemplateCommitHook() {
|
|
|
133
131
|
hook(options, COMMIT, (originalCommit, vnode, commitQueue) => {
|
|
134
132
|
if (__BACKGROUND__) {
|
|
135
133
|
clearElementTemplateRenderScope();
|
|
134
|
+
try {
|
|
135
|
+
sendMTRefInitValueToMainThread();
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
cleanupFailedElementTemplateCommit(takeRemovedSubtreesForPostDispatchTeardown(), takeDelayedRunOnMainThreadData());
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
136
141
|
}
|
|
137
142
|
if (__BACKGROUND__ && !hasHydrated && hasPendingRefs()) {
|
|
138
143
|
// User effects can run before ET hydrate arrives, so ordinary refs must be
|
|
139
144
|
// attached on the background commit even though native UI ops are delayed.
|
|
140
145
|
flushPendingRefs();
|
|
141
146
|
}
|
|
142
|
-
else if (__BACKGROUND__ && hasHydrated
|
|
143
|
-
|
|
144
|
-
if (globalCommitContext.ops.length > 0
|
|
147
|
+
else if (__BACKGROUND__ && hasHydrated
|
|
148
|
+
&& (globalCommitContext.ops.length > 0
|
|
145
149
|
|| !isEmptyObject(globalCommitContext.flushOptions)
|
|
146
150
|
|| hasPendingRefs()
|
|
147
|
-
|| delayedRunOnMainThreadData.length > 0
|
|
148
|
-
|
|
149
|
-
flushElementTemplateCommitChanges(mainThreadRefInitValuePatch);
|
|
150
|
-
}
|
|
151
|
+
|| delayedRunOnMainThreadData.length > 0)) {
|
|
152
|
+
flushElementTemplateCommitChanges();
|
|
151
153
|
}
|
|
152
154
|
originalCommit?.(vnode, commitQueue);
|
|
153
155
|
});
|