@lynx-js/react 0.127.0 → 0.129.0
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 +38 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -14
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/entry-re-eval.test.ts +161 -0
- 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/internal/legacy-internal-guardrail.test.ts +1 -1
- package/runtime/__test__/element-template/native/index.test.ts +8 -0
- package/runtime/__test__/element-template/native/main-thread-ref-init-value.test.ts +100 -0
- package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +101 -0
- package/runtime/__test__/element-template/native/reload.test.ts +50 -1
- package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +104 -47
- package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +39 -48
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +14 -10
- package/runtime/__test__/element-template/runtime/background/re-eval-reload.test.ts +69 -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 +17 -3
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +8 -3
- 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/mock/globals.js +6 -0
- package/runtime/__test__/element-template/vitest.config.ts +4 -0
- 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/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/initEntry.test.js +109 -0
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +15 -1
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +46 -0
- package/runtime/__test__/worklet-runtime/object-methods.test.js +2 -3
- package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +3 -3
- package/runtime/lazy/element-template-internal.js +0 -1
- package/runtime/lazy/internal.js +0 -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/handle.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.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/commit-context.js.map +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
- package/runtime/lib/core/compat/lynxComponent.js.map +1 -1
- package/runtime/lib/core/component.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/forceRootRender.js.map +1 -1
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/hooks/mainThread.js.map +1 -1
- package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
- package/runtime/lib/core/hooks/react.js.map +1 -1
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
- package/runtime/lib/core/initData.js.map +1 -1
- package/runtime/lib/core/lynx/dynamic-import.js.map +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js +4 -1
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx/runtime-backend.js.map +1 -1
- package/runtime/lib/core/lynx/runtime-version.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/core/lynx-page-data.js.map +1 -1
- package/runtime/lib/core/lynx-update-data.js.map +1 -1
- package/runtime/lib/core/main-thread-function.js.map +1 -1
- package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -1
- package/runtime/lib/core/main-thread-object.js +1 -4
- package/runtime/lib/core/main-thread-object.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/main-thread-ref-init-value.js.map +1 -1
- package/runtime/lib/core/main-thread-ref.js.map +1 -1
- package/runtime/lib/core/mts-capability.js.map +1 -1
- package/runtime/lib/core/performance.js.map +1 -1
- package/runtime/lib/core/ref.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 +9 -0
- 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.map +1 -1
- package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
- package/runtime/lib/element-template/background/commit-context.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js +19 -16
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/document.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.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/background/instance.js.map +1 -1
- package/runtime/lib/element-template/background/manager.js.map +1 -1
- package/runtime/lib/element-template/background/page-root-hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/render-scope.js.map +1 -1
- package/runtime/lib/element-template/client/root.js.map +1 -1
- package/runtime/lib/element-template/debug/alog.js.map +1 -1
- package/runtime/lib/element-template/debug/elementPAPICall.js.map +1 -1
- package/runtime/lib/element-template/debug/profile.js.map +1 -1
- package/runtime/lib/element-template/hydration-map.js.map +1 -1
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +0 -1
- package/runtime/lib/element-template/internal.js +0 -1
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/jsx-dev-runtime/index.js.map +1 -1
- package/runtime/lib/element-template/jsx-runtime/index.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.js.map +1 -1
- package/runtime/lib/element-template/lynx/performance.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/callDestroyLifetimeFun.js.map +1 -1
- 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.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js +2 -0
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +1 -4
- 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 +18 -2
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/event-value.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/event.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/spread.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/opcodes.js.map +1 -1
- package/runtime/lib/element-template/protocol/page.js.map +1 -1
- package/runtime/lib/element-template/protocol/template-type.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/protocol/update-event.js.map +1 -1
- package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/authored-page.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/page.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/host.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -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.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-event-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/registry.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
- package/runtime/lib/element-template/runtime-marker.js.map +1 -1
- package/runtime/lib/index.js.map +1 -1
- package/runtime/lib/internal.d.ts +0 -1
- package/runtime/lib/internal.js +0 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/root.js.map +1 -1
- package/runtime/lib/runtime-marker.js.map +1 -1
- package/runtime/lib/shared/attribute-name.js.map +1 -1
- 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/shared/profile.js.map +1 -1
- package/runtime/lib/shared/render-constants.js.map +1 -1
- package/runtime/lib/snapshot/alog/elementPAPICall.js.map +1 -1
- package/runtime/lib/snapshot/alog/index.js.map +1 -1
- package/runtime/lib/snapshot/alog/render.js.map +1 -1
- package/runtime/lib/snapshot/compat/componentIs.js.map +1 -1
- package/runtime/lib/snapshot/debug/debug.js.map +1 -1
- package/runtime/lib/snapshot/debug/describeInvalidValue.js.map +1 -1
- package/runtime/lib/snapshot/debug/formatPatch.js.map +1 -1
- package/runtime/lib/snapshot/debug/printSnapshot.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
- package/runtime/lib/snapshot/debug/vnodeSource.js.map +1 -1
- package/runtime/lib/snapshot/gesture/processGesture.js.map +1 -1
- package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +1 -1
- package/runtime/lib/snapshot/gesture/types.js.map +1 -1
- package/runtime/lib/snapshot/index.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/constant.js.map +1 -1
- 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/delayEvents.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/delayLifecycleEvents.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/isRendering.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/globalState.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/isMainThreadHydrating.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/nodesRefApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.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/lifecycle/render.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.map +1 -1
- package/runtime/lib/snapshot/list/pendingListUpdates.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +3 -3
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/lynx/children.js.map +1 -1
- package/runtime/lib/snapshot/lynx/element.js.map +1 -1
- package/runtime/lib/snapshot/lynx/env.js.map +1 -1
- package/runtime/lib/snapshot/lynx/injectLepusMethods.js.map +1 -1
- package/runtime/lib/snapshot/lynx/lazyBundleConstants.js.map +1 -1
- package/runtime/lib/snapshot/lynx/nodesRef.js.map +1 -1
- package/runtime/lib/snapshot/lynx/performance.js.map +1 -1
- package/runtime/lib/snapshot/lynx/portals.js.map +1 -1
- package/runtime/lib/snapshot/lynx/portalsPending.js.map +1 -1
- package/runtime/lib/snapshot/lynx/prepareLazyBundleMTS.js.map +1 -1
- package/runtime/lib/snapshot/lynx/runWithForce.js.map +1 -1
- package/runtime/lib/snapshot/lynx/suspense.js.map +1 -1
- package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/constants.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/definition.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/dynamicPartType.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/event.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/gesture.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/index.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/platformInfo.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/reconstructInstanceTree.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotCreatorMap.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceHydrationMap.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/snapshot/spread.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/types.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/utils.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/workletEvent.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/workletRef.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/destroy.js.map +1 -1
- package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
- package/runtime/lib/snapshot/worklet/hmr.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/utils.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/animation/animation.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/animation/effect.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/lepusQuerySelector.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/events.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/index.d.ts +0 -1
- package/runtime/lib/worklet-runtime/bindings/index.js +0 -1
- package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js +3 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
- package/runtime/lib/worklet-runtime/eomImpl.js.map +1 -1
- package/runtime/lib/worklet-runtime/eventPropagation.js.map +1 -1
- package/runtime/lib/worklet-runtime/global.js.map +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
- package/runtime/lib/worklet-runtime/index.js +6 -0
- package/runtime/lib/worklet-runtime/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +2 -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/utils/mainThreadFlushLoopGuard.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
- package/runtime/lib/worklet-runtime/utils/version.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- 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/card-lifetime.ts +18 -0
- package/runtime/src/core/entry-reload.ts +63 -0
- package/runtime/src/core/lynx/lazy-bundle.ts +4 -1
- package/runtime/src/core/main-thread-object.ts +1 -8
- 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 +11 -0
- 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/element-template/background/commit-hook.ts +20 -17
- package/runtime/src/element-template/background/hydration-listener.ts +2 -6
- package/runtime/src/element-template/internal.ts +0 -1
- package/runtime/src/element-template/main-thread-ref-init-value.ts +44 -0
- package/runtime/src/element-template/native/index.ts +2 -0
- package/runtime/src/element-template/native/mts-destroy.ts +3 -0
- package/runtime/src/element-template/native/patch-listener.ts +0 -5
- package/runtime/src/element-template/native/reload-background.ts +13 -1
- package/runtime/src/element-template/native/reload-main-thread.ts +30 -2
- package/runtime/src/element-template/protocol/lifecycle-constant.ts +1 -0
- package/runtime/src/element-template/protocol/types.ts +0 -2
- package/runtime/src/internal.ts +0 -1
- 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/reload.ts +47 -11
- package/runtime/src/snapshot/list/list.ts +9 -2
- package/runtime/src/snapshot/lynx/calledByNative.ts +3 -4
- 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 +13 -0
- package/runtime/src/worklet-runtime/bindings/index.ts +0 -1
- package/runtime/src/worklet-runtime/delayRunOnBackground.ts +3 -1
- package/runtime/src/worklet-runtime/index.ts +7 -0
- package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +2 -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/tsconfig.json +2 -0
- package/runtime/types/types.d.ts +3 -1
- package/runtime/vitest.config.ts +4 -0
- package/testing-library/.turbo/turbo-build.log +12 -12
- package/testing-library/dist/env/index.js +3 -15
- package/testing-library/dist/plugins/index.js +10 -0
- package/testing-library/dist/rstest-config.js +15 -0
- package/testing-library/dist/setupFiles/common/worklet-runtime-init.js +11 -0
- package/testing-library/rstest.config.ts +3 -0
- package/testing-library/src/__tests__/rstest-config.test.js +34 -1
- package/testing-library/src/__tests__/worklet.test.jsx +51 -37
- package/testing-library/src/plugins/vitest.ts +5 -1
- package/testing-library/src/rstest-config.ts +17 -1
- package/testing-library/src/setupFiles/common/worklet-runtime-init.js +22 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +345 -150
- package/transform/__test__/defines.spec.js +187 -12
- package/transform/__test__/fixture.spec.js +166 -48
- package/transform/__test__/object-methods.spec.js +1 -3
- package/transform/crates/swc_plugin_worklet/definition_imports.rs +97 -0
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +26 -10
- package/transform/crates/swc_plugin_worklet/lib.rs +138 -153
- package/transform/crates/swc_plugin_worklet/napi.rs +10 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +4 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_ident_from_this_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +4 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_3_lepus.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_4_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +4 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_globals.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_type_annotations.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_destructure_from_closure.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_catch_clause_params.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_extract_idents_inside_of_ctx.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_transform_recursively.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +6 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_arrow_function.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_fn_decl_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_function_expr.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_property_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_in_class_static_property_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js_fn_in_run_on_js_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +4 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_alias.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus_general_mixed.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_multiple_worklets_in_func.js +3 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +2 -4
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_ui_worklet_lepus.js +2 -4
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +27 -1
- package/transform/src/lib.rs +354 -23
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +53 -52
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +63 -293
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +0 -8
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +0 -23
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +0 -1
- package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +0 -25
- package/runtime/worklet-runtime/dev.js +0 -775
- package/runtime/worklet-runtime/main.js +0 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_inner_ident.js +0 -13
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_add_worklet_runtime_ident_with_outer_ident.js +0 -13
|
@@ -0,0 +1,109 @@
|
|
|
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 { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
describe('worklet-runtime init entry', () => {
|
|
7
|
+
let originalLynx;
|
|
8
|
+
let originalSystemInfo;
|
|
9
|
+
let jsContext;
|
|
10
|
+
let originalSetTimeout;
|
|
11
|
+
let originalSetInterval;
|
|
12
|
+
let originalClearTimeout;
|
|
13
|
+
let originalClearInterval;
|
|
14
|
+
let originalRequestAnimationFrame;
|
|
15
|
+
let originalCancelAnimationFrame;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
originalLynx = globalThis.lynx;
|
|
19
|
+
originalSystemInfo = globalThis.SystemInfo;
|
|
20
|
+
jsContext = { addEventListener: vi.fn() };
|
|
21
|
+
originalSetTimeout = globalThis.setTimeout;
|
|
22
|
+
originalSetInterval = globalThis.setInterval;
|
|
23
|
+
originalClearTimeout = globalThis.clearTimeout;
|
|
24
|
+
originalClearInterval = globalThis.clearInterval;
|
|
25
|
+
originalRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
26
|
+
originalCancelAnimationFrame = globalThis.cancelAnimationFrame;
|
|
27
|
+
|
|
28
|
+
vi.resetModules();
|
|
29
|
+
globalThis.SystemInfo = {
|
|
30
|
+
lynxSdkVersion: '2.16',
|
|
31
|
+
};
|
|
32
|
+
delete globalThis.lynxWorkletImpl;
|
|
33
|
+
delete globalThis.registerWorklet;
|
|
34
|
+
delete globalThis.registerWorkletInternal;
|
|
35
|
+
delete globalThis.runWorklet;
|
|
36
|
+
globalThis.lynx = {
|
|
37
|
+
...originalLynx,
|
|
38
|
+
getJSContext: () => jsContext,
|
|
39
|
+
setTimeout: originalSetTimeout,
|
|
40
|
+
setInterval: originalSetInterval,
|
|
41
|
+
clearTimeout: originalClearTimeout,
|
|
42
|
+
clearInterval: originalClearInterval,
|
|
43
|
+
requestAnimationFrame: originalRequestAnimationFrame,
|
|
44
|
+
cancelAnimationFrame: originalCancelAnimationFrame,
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
globalThis.lynx = originalLynx;
|
|
50
|
+
globalThis.SystemInfo = originalSystemInfo;
|
|
51
|
+
globalThis.setTimeout = originalSetTimeout;
|
|
52
|
+
globalThis.setInterval = originalSetInterval;
|
|
53
|
+
globalThis.clearTimeout = originalClearTimeout;
|
|
54
|
+
globalThis.clearInterval = originalClearInterval;
|
|
55
|
+
globalThis.requestAnimationFrame = originalRequestAnimationFrame;
|
|
56
|
+
globalThis.cancelAnimationFrame = originalCancelAnimationFrame;
|
|
57
|
+
delete globalThis.lynxWorkletImpl;
|
|
58
|
+
delete globalThis.registerWorklet;
|
|
59
|
+
delete globalThis.registerWorkletInternal;
|
|
60
|
+
delete globalThis.runWorklet;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('initializes the main-thread runtime through the public entry', async () => {
|
|
64
|
+
const { registerWorklet } = await import('@lynx-js/react/worklet-runtime/init');
|
|
65
|
+
|
|
66
|
+
expect(globalThis.lynxWorkletImpl).toBeDefined();
|
|
67
|
+
expect(globalThis.registerWorklet).toBeTypeOf('function');
|
|
68
|
+
expect(globalThis.registerWorkletInternal).toBeTypeOf('function');
|
|
69
|
+
expect(globalThis.runWorklet).toBeTypeOf('function');
|
|
70
|
+
expect(registerWorklet).toBe(globalThis.registerWorkletInternal);
|
|
71
|
+
|
|
72
|
+
const worklet = vi.fn(value => value + 1);
|
|
73
|
+
registerWorklet('main-thread', 'cold-entry', worklet);
|
|
74
|
+
expect(globalThis.lynxWorkletImpl._workletMap['cold-entry']).toBe(worklet);
|
|
75
|
+
expect(globalThis.runWorklet({ _wkltId: 'cold-entry' }, [41])).toBe(42);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('preserves runtime state when the init entry is evaluated again', async () => {
|
|
79
|
+
const initialEntry = await import('@lynx-js/react/worklet-runtime/init');
|
|
80
|
+
expect(initialEntry.registerWorklet).toBe(globalThis.registerWorkletInternal);
|
|
81
|
+
|
|
82
|
+
const workletImpl = globalThis.lynxWorkletImpl;
|
|
83
|
+
const registerWorklet = globalThis.registerWorklet;
|
|
84
|
+
const registerWorkletInternal = vi.fn(globalThis.registerWorkletInternal);
|
|
85
|
+
globalThis.registerWorkletInternal = registerWorkletInternal;
|
|
86
|
+
const runWorklet = globalThis.runWorklet;
|
|
87
|
+
const existingWorklet = vi.fn();
|
|
88
|
+
registerWorklet('main-thread', 'existing', existingWorklet);
|
|
89
|
+
expect(jsContext.addEventListener).toHaveBeenCalled();
|
|
90
|
+
jsContext.addEventListener.mockClear();
|
|
91
|
+
|
|
92
|
+
vi.resetModules();
|
|
93
|
+
const entry = await import('@lynx-js/react/worklet-runtime/init');
|
|
94
|
+
|
|
95
|
+
expect(globalThis.lynxWorkletImpl).toBe(workletImpl);
|
|
96
|
+
expect(globalThis.registerWorklet).toBe(registerWorklet);
|
|
97
|
+
expect(globalThis.registerWorkletInternal).toBe(registerWorkletInternal);
|
|
98
|
+
expect(globalThis.runWorklet).toBe(runWorklet);
|
|
99
|
+
expect(jsContext.addEventListener).not.toHaveBeenCalled();
|
|
100
|
+
expect(entry.registerWorklet).toBe(registerWorkletInternal);
|
|
101
|
+
|
|
102
|
+
const worklet = vi.fn(() => 42);
|
|
103
|
+
entry.registerWorklet('main-thread', 'warm-entry', worklet);
|
|
104
|
+
expect(registerWorkletInternal).toHaveBeenCalledWith('main-thread', 'warm-entry', worklet);
|
|
105
|
+
expect(workletImpl._workletMap.existing).toBe(existingWorklet);
|
|
106
|
+
expect(workletImpl._workletMap['warm-entry']).toBe(worklet);
|
|
107
|
+
expect(runWorklet({ _wkltId: 'warm-entry' }, [])).toBe(42);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
|
|
6
6
|
import { JsFunctionLifecycleManager } from '../../src/worklet-runtime/jsFunctionLifecycle';
|
|
7
7
|
|
|
@@ -86,4 +86,18 @@ describe('jsFunctionLifecycle', () => {
|
|
|
86
86
|
}
|
|
87
87
|
`);
|
|
88
88
|
});
|
|
89
|
+
it('leaves failed registrations retryable', () => {
|
|
90
|
+
const manager = new JsFunctionLifecycleManager();
|
|
91
|
+
const target = {};
|
|
92
|
+
const error = new TypeError('target must be an object');
|
|
93
|
+
const register = vi.spyOn(manager.registry, 'register').mockImplementationOnce(() => {
|
|
94
|
+
throw error;
|
|
95
|
+
});
|
|
96
|
+
expect(() => manager.addRef(3, target)).toThrow(error);
|
|
97
|
+
expect(manager.execIdRefCount.size).toBe(0);
|
|
98
|
+
expect(manager.retainedObjects.has(target)).toBe(false);
|
|
99
|
+
manager.addRef(3, target);
|
|
100
|
+
expect(register).toHaveBeenCalledTimes(2);
|
|
101
|
+
expect(manager.execIdRefCount.get(3)).toBe(1);
|
|
102
|
+
});
|
|
89
103
|
});
|
|
@@ -152,6 +152,52 @@ describe('MainThreadObject registry and realization', () => {
|
|
|
152
152
|
}).not.toThrow();
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
+
it('keeps the resolved factory when the same create is registered again', () => {
|
|
156
|
+
const create = vi.fn(value => ({ value }));
|
|
157
|
+
const createDescriptor = { _wkltId: 'create-repeat' };
|
|
158
|
+
globalThis.registerWorklet('main-thread', 'create-repeat', create);
|
|
159
|
+
const lookupFactory = vi.fn(() => create);
|
|
160
|
+
Object.defineProperty(lynxWorkletImpl._workletMap, 'create-repeat', { get: lookupFactory });
|
|
161
|
+
|
|
162
|
+
const register = () =>
|
|
163
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType('@test/repeat', createDescriptor);
|
|
164
|
+
register();
|
|
165
|
+
updateWorkletRefInitValueChanges([[81, 'first', '@test/repeat']]);
|
|
166
|
+
// `useMainThreadObject` registers the type again on its first use.
|
|
167
|
+
register();
|
|
168
|
+
updateWorkletRefInitValueChanges([[82, 'second', '@test/repeat']]);
|
|
169
|
+
|
|
170
|
+
expect(lookupFactory).toHaveBeenCalledOnce();
|
|
171
|
+
removeValueFromWorkletRefMap(81);
|
|
172
|
+
removeValueFromWorkletRefMap(82);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('uses the factory of the latest evaluation of the defining module', () => {
|
|
176
|
+
// Each evaluation of the module creates its own descriptor and its own
|
|
177
|
+
// module state; the worklet ID and source stay the same.
|
|
178
|
+
const evaluateModule = (generation) => {
|
|
179
|
+
globalThis.registerWorklet('main-thread', 'create-generation', value => ({ value, generation }));
|
|
180
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
181
|
+
'@test/generation',
|
|
182
|
+
{ _wkltId: 'create-generation' },
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
evaluateModule('old');
|
|
187
|
+
updateWorkletRefInitValueChanges([[91, 'a', '@test/generation']]);
|
|
188
|
+
const oldObject = getFromWorkletRefMap({ _wvid: 91 });
|
|
189
|
+
expect(oldObject).toMatchObject({ generation: 'old' });
|
|
190
|
+
|
|
191
|
+
evaluateModule('new');
|
|
192
|
+
updateWorkletRefInitValueChanges([[92, 'b', '@test/generation']]);
|
|
193
|
+
expect(getFromWorkletRefMap({ _wvid: 92 })).toMatchObject({ generation: 'new' });
|
|
194
|
+
// Objects that already exist keep their identity.
|
|
195
|
+
expect(getFromWorkletRefMap({ _wvid: 91 })).toBe(oldObject);
|
|
196
|
+
|
|
197
|
+
removeValueFromWorkletRefMap(91);
|
|
198
|
+
removeValueFromWorkletRefMap(92);
|
|
199
|
+
});
|
|
200
|
+
|
|
155
201
|
it('rejects factories that do not create objects', () => {
|
|
156
202
|
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
157
203
|
'@test/invalid',
|
|
@@ -43,10 +43,9 @@ it('resolves a compiler-generated object method through whole-object captures',
|
|
|
43
43
|
},
|
|
44
44
|
);
|
|
45
45
|
const source = new Function(
|
|
46
|
-
'
|
|
47
|
-
'registerWorkletInternal',
|
|
46
|
+
'__registerWorklet',
|
|
48
47
|
`${result.code.replace(/^import .*;$/gm, '').replace('export const source', 'const source')}\nreturn source;`,
|
|
49
|
-
)(
|
|
48
|
+
)(registerWorklet);
|
|
50
49
|
registerWorklet('main-thread', 'parent', function() {
|
|
51
50
|
return this._c.source.method;
|
|
52
51
|
});
|
|
@@ -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
|
],
|
package/runtime/lazy/internal.js
CHANGED
|
@@ -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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../../../src/core/background-function/handle.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,IAAI,MAAM,GAAG,CAAC,CAAC;AAEf;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAC5C,GAA0D;IAE1D,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC;IACpB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO;YACL,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,8DAA8D,OAAO,GAAG,WAAW;SAC5F,CAAC;IACJ,CAAC;IACD,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC,sBAAsB,CAAC;IAC5C,OAAO;QACL,OAAO,EAAE,EAAE;QACX,GAAG,EAAE,GAAG;KACT,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yCAAyC;IACvD,MAAM,GAAG,CAAC,CAAC;AACb,CAAC"}
|
|
1
|
+
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../../../src/core/background-function/handle.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,IAAI,MAAM,GAAG,CAAC,CAAC;AAEf;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAC5C,GAA0D;IAE1D,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC;IACpB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO;YACL,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,8DAA8D,OAAO,GAAG,WAAW;SAC5F,CAAC;IACJ,CAAC;IACD,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC,sBAAsB,CAAC;IAC5C,OAAO;QACL,OAAO,EAAE,EAAE;QACX,GAAG,EAAE,GAAG;KACT,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yCAAyC;IACvD,MAAM,GAAG,CAAC,CAAC;AACb,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 type { JsFnHandle } from '../../worklet-runtime/bindings/types.js';\n\nlet lastId = 0;\n\n/**\n * Creates the serializable handle used by main-thread code to call a background function.\n */\nexport function createBackgroundFunctionHandle(\n obj: ((...args: any[]) => any) & { toJSON?: () => string },\n): JsFnHandle {\n const id = ++lastId;\n if (typeof obj !== 'function') {\n return {\n _jsFnId: id,\n _error: `Argument of runOnBackground should be a function, but got [${typeof obj}] instead`,\n };\n }\n obj.toJSON ??= () => '[BackgroundFunction]';\n return {\n _jsFnId: id,\n _fn: obj,\n };\n}\n\nexport function resetBackgroundFunctionHandleIdForTesting(): void {\n lastId = 0;\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":"A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E;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"]}
|
|
@@ -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;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAI,MAAS;IAClD,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/D,CAAC"}
|
|
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;;;;;;;GAOG;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`.\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit-context.js","sourceRoot":"","sources":["../../src/core/commit-context.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAQ1D,MAAM,CAAC,MAAM,mBAAmB,GAAwB;IACtD,GAAG,EAAE,EAAE;IACP,YAAY,EAAE,EAAE;CACjB,CAAC;AAEF,MAAM,UAAU,wBAAwB;IACtC,mBAAmB,CAAC,GAAG,GAAG,EAAE,CAAC;IAC7B,mBAAmB,CAAC,YAAY,GAAG,EAAE,CAAC;IACtC,OAAO,mBAAmB,CAAC,OAAO,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,MAAM,YAAY,GAAG,mBAAmB,CAAC,YAAY,CAAC;IACtD,mBAAmB,CAAC,YAAY,GAAG,EAAE,CAAC;IACtC,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
1
|
+
{"version":3,"file":"commit-context.js","sourceRoot":"","sources":["../../src/core/commit-context.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAQ1D,MAAM,CAAC,MAAM,mBAAmB,GAAwB;IACtD,GAAG,EAAE,EAAE;IACP,YAAY,EAAE,EAAE;CACjB,CAAC;AAEF,MAAM,UAAU,wBAAwB;IACtC,mBAAmB,CAAC,GAAG,GAAG,EAAE,CAAC;IAC7B,mBAAmB,CAAC,YAAY,GAAG,EAAE,CAAC;IACtC,OAAO,mBAAmB,CAAC,OAAO,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,MAAM,YAAY,GAAG,mBAAmB,CAAC,YAAY,CAAC;IACtD,mBAAmB,CAAC,YAAY,GAAG,EAAE,CAAC;IACtC,OAAO,YAAY,CAAC;AACtB,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\nexport interface GlobalCommitContext<Ops = unknown[]> {\n ops: Ops;\n flushOptions: FlushOptions;\n flowIds?: number[];\n}\n\nexport const globalCommitContext: GlobalCommitContext = {\n ops: [],\n flushOptions: {},\n};\n\nexport function resetGlobalCommitContext(): void {\n globalCommitContext.ops = [];\n globalCommitContext.flushOptions = {};\n delete globalCommitContext.flowIds;\n}\n\nexport function takeGlobalFlushOptions(): FlushOptions {\n const flushOptions = globalCommitContext.flushOptions;\n globalCommitContext.flushOptions = {};\n return flushOptions;\n}\n"]}
|
|
@@ -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,CAAC,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC7G,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"}
|
|
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,CAAC,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC7G,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 /*, useInstance */ } from '../hooks/react.js';\nexport { __runInJS, createRef, useRef };\n\n/**\n * @internal\n */\nexport default {\n Component,\n PureComponent,\n createContext,\n createRef,\n lazy,\n useState,\n useReducer,\n useRef,\n useEffect,\n useMemo,\n useCallback,\n __runInJS,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lynxComponent.js","sourceRoot":"","sources":["../../../src/core/compat/lynxComponent.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAQnC,MAAM,UAAU,qBAAqB,CACnC,WAA0E,EAC1E,YAAuB;IAEvB,MAAM,cAAc,GAAG,YAAoC,CAAC;IAC5D,MAAM,CAAC,GAAG,cAAc,CAAC,IAAI,CAAC;IAC9B,IACE,OAAO,CAAC,KAAK,UAAU;WACpB,CAAC,CAAC,KAAK,yBAAyB;eAC7B,CAA6B,CAAC,SAAS,YAAY,yBAAyB,CAAC,EACnF,CAAC;QACD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,WAAW,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,SAAS;YACT,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,wBAAwB,CAAC,EAAE,CAAC;gBACpD,OAAO,WAAW,CAAC,YAAY,EAAE,uBAAuB,CAAC,cAAc,CAAC,CAAC,CAAC;YAC5E,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,OAAO,yBAA0B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BAAsB;IACtB,qBAAqB;CACtB,CAAC,CAAC;AAEH,SAAS,uBAAuB,CAAC,YAAkC;IACjE,MAAM,UAAU,GAA4B,EAAE,CAAC;IAC/C,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC5C,sGAAsG;QACtG,wDAAwD;QACxD,IACE,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC;eAC5B,CAAC,KAAK,IAAI;eACV,CAAC,KAAK,WAAW;eACjB,CAAC,KAAK,SAAS;eACf,CAAC,KAAK,UAAU;eAChB,CAAC,KAAK,wBAAwB;eAC9B,CAAC,kEAAkE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;eAC5E,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EACjC,CAAC;YACD,UAAU,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACtC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,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 { Component } from 'preact';\nimport type { ReactNode } from 'react';\n\ninterface CompatComponentVNode {\n type: unknown;\n props: Record<string, unknown>;\n}\n\nexport function wrapWithLynxComponent(\n jsxSnapshot: (c: ReactNode, spread?: Record<string, unknown>) => ReactNode,\n jsxComponent: ReactNode,\n): ReactNode {\n const componentVNode = jsxComponent as CompatComponentVNode;\n const C = componentVNode.type;\n if (\n typeof C === 'function'\n && (C === ComponentFromReactRuntime\n || (C as { prototype?: unknown }).prototype instanceof ComponentFromReactRuntime)\n ) {\n if (jsxSnapshot.length === 1) {\n return jsxSnapshot(jsxComponent);\n } else {\n // spread\n if (!componentVNode.props['removeComponentElement']) {\n return jsxSnapshot(jsxComponent, takeComponentAttributes(componentVNode));\n }\n }\n }\n return jsxComponent;\n}\n\nexport class ComponentFromReactRuntime extends Component {\n /* v8 ignore next 3 -- marker component, never rendered directly. */\n render(): null {\n return null;\n }\n}\n\nconst __COMPONENT_ATTRIBUTES__ = /* @__PURE__ */ new Set([\n 'name',\n 'style',\n 'class',\n 'flatten',\n 'clip-radius',\n 'overlap',\n 'user-interaction-enabled',\n 'native-interaction-enabled',\n 'block-native-event',\n 'enableLayoutOnly',\n 'cssAlignWithLegacyW3C',\n 'intersection-observers',\n 'trigger-global-event',\n 'exposure-scene',\n 'exposure-id',\n 'exposure-screen-margin-top',\n 'exposure-screen-margin-bottom',\n 'exposure-screen-margin-left',\n 'exposure-screen-margin-right',\n 'focusable',\n 'focus-index',\n 'accessibility-label',\n 'accessibility-element',\n 'accessibility-traits',\n 'enable-new-animator',\n]);\n\nfunction takeComponentAttributes(jsxComponent: CompatComponentVNode): Record<string, unknown> {\n const attributes: Record<string, unknown> = {};\n Object.keys(jsxComponent.props).forEach((k) => {\n // let re1 = Regex::new(r\"^(global-bind|bind|catch|capture-bind|capture-catch)([A-Za-z]+)$\").unwrap();\n // let re2 = Regex::new(r\"^data-([A-Za-z]+)$\").unwrap();\n if (\n __COMPONENT_ATTRIBUTES__.has(k)\n || k === 'id'\n || k === 'className'\n || k === 'dataSet'\n || k === 'data-set'\n || k === 'removeComponentElement'\n || (/^(global-bind|bind|catch|capture-bind|capture-catch)([A-Za-z]+)$/.exec(k))\n || (/^data-([A-Za-z]+)$/.exec(k))\n ) {\n attributes[k] = jsxComponent.props[k];\n delete jsxComponent.props[k];\n }\n });\n\n return attributes;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/core/component.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,oBAAoB;AAEpB,OAAO,EAAE,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AC;IACpC,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,CAAC,mBAAmB,CAAC,IAAI,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC;IACjG,WAAW,CAAC,SAAS,CAAC,mBAAmB,CAAC,GAAG,WAAW,CAAC;IACzD,WAAW,CAAC,SAAS,CAAC,QAAQ,GAAG,UAAS,KAAU,EAAE,QAAa;QACjE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QACxC,aAAa;QACb,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,CAAC;QACrD,IAAI,UAAU,EAAE,CAAC;YACf,mBAAmB,CAAC,YAAY,CAAC,kBAAkB,GAAG,UAAU,CAAC;YACjE,gBAAgB,CAAC,uBAAuB,EAAE,UAAU,CAAC,CAAC;YACtD,IAAI,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;QACzC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,sBAAsB,EAAE,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\n/* eslint-disable */\n\nimport { Component } from 'preact';\n\nimport { globalCommitContext } from './commit-context.js';\nimport { PerfSpecificKey, markTimingLegacy } from './performance.js';\nimport { NEXT_STATE } from '../shared/render-constants.js';\n\ninterface ReactAppInstance {\n GlobalEventEmitter: unknown;\n registerModule(name: string, module: object): void;\n getJSModule<Module = unknown>(name: string): Module;\n}\n\ninterface LegacyNativeApp {\n nativeModuleProxy: {\n LynxUIMethodModule: unknown;\n };\n}\n\ninterface LegacyReactComponent {\n getNodeRef(this: unknown, selector: string, single?: boolean): unknown;\n getNodeRefFromRoot(this: unknown, selector: string): unknown;\n}\n\nconst OriginalSetStateKey = '__reactLynxOriginalSetState';\n\nfunction reportRefDeprecationError(fnName: string, newFnName: string) {\n if (__DEV__ && !__DISABLE_CREATE_SELECTOR_QUERY_INCOMPATIBLE_WARNING__) {\n lynx.reportError(\n new Error(\n `${fnName} is deprecated and has different behavior in ReactLynx 3.0, please use ref or ${newFnName} instead.`,\n ),\n );\n }\n}\n\nfunction getReactAppInstance(): ReactAppInstance {\n return lynx.getApp() as unknown as ReactAppInstance;\n}\n\nfunction getLegacyNativeApp(): LegacyNativeApp {\n return (lynx.getApp() as any)._nativeApp;\n}\n\nfunction getLegacyReactComponent(): LegacyReactComponent {\n return (lynx.getApp() as any)._reactLynx.ReactComponent.prototype;\n}\n\nfunction createLegacyComponentReceiver(\n reactAppInstance: ReactAppInstance,\n nativeApp: LegacyNativeApp,\n): unknown {\n return {\n _type: '',\n _nativeApp: nativeApp,\n _uiModule: nativeApp.nativeModuleProxy.LynxUIMethodModule,\n _reactAppInstance: reactAppInstance,\n };\n}\n\nfunction installComponentCompat(): void {\n if (!__JS__) {\n return;\n }\n\n const __Component = Component as any;\n const reactAppInstance = getReactAppInstance();\n\n __Component.prototype._reactAppInstance = reactAppInstance;\n\n __Component.prototype.getNodeRef = function(a: string, b?: boolean) {\n reportRefDeprecationError('getNodeRef', 'lynx.createSelectorQuery');\n\n return getLegacyReactComponent().getNodeRef.call(\n createLegacyComponentReceiver(\n getReactAppInstance(),\n getLegacyNativeApp(),\n ),\n a,\n b,\n );\n };\n\n __Component.prototype.getNodeRefFromRoot = function(a: string) {\n reportRefDeprecationError('getNodeRefFromRoot', 'lynx.createSelectorQuery');\n\n return getLegacyReactComponent().getNodeRefFromRoot.call(\n createLegacyComponentReceiver(\n getReactAppInstance(),\n getLegacyNativeApp(),\n ),\n a,\n );\n };\n\n __Component.prototype.registerModule = function(\n name: string,\n module: object,\n ): void {\n this._reactAppInstance.registerModule(name, module);\n };\n\n __Component.prototype.getJSModule = function<Module = unknown>(\n name: string,\n ): Module {\n return this._reactAppInstance.getJSModule(name);\n };\n\n __Component.prototype.addGlobalEventListener = function(\n eventName: string,\n callback: (...args: unknown[]) => void,\n context?: object,\n ): void {\n return this._reactAppInstance.getJSModule('GlobalEventEmitter').addListener(\n eventName,\n callback,\n context,\n );\n };\n\n __Component.prototype.getElementById = function(id: string) {\n reportRefDeprecationError('getElementById', 'lynx.getElementById');\n return lynx.getElementById(id);\n };\n\n __Component.prototype.GlobalEventEmitter = reactAppInstance.GlobalEventEmitter;\n\n __Component.prototype.createSelectorQuery = function() {\n reportRefDeprecationError('createSelectorQuery on component instance', 'lynx.createSelectorQuery');\n return lynx.createSelectorQuery();\n };\n\n const oldSetState = __Component.prototype[OriginalSetStateKey] ?? __Component.prototype.setState;\n __Component.prototype[OriginalSetStateKey] = oldSetState;\n __Component.prototype.setState = function(state: any, callback: any): void {\n oldSetState.call(this, state, callback);\n // @ts-ignore\n const timingFlag = this[NEXT_STATE][PerfSpecificKey];\n if (timingFlag) {\n globalCommitContext.flushOptions.__lynx_timing_flag = timingFlag;\n markTimingLegacy('updateSetStateTrigger', timingFlag);\n this[NEXT_STATE][PerfSpecificKey] = '';\n }\n };\n}\n\nexport { installComponentCompat };\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","sourceRoot":"","sources":["../../src/core/entry-reload.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AACxE,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;AACtE,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AACzE,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAEjE,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,IAA0C,CAAC;AAE9D,SAAS,oBAAoB;IAC3B,OAAO,OAAO,qCAAqC,KAAK,WAAW;WAC9D,qCAAqC;WACrC,IAAI,EAAE,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU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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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forceRootRender.js","sourceRoot":"","sources":["../../src/core/forceRootRender.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAQlG,MAAM,UAAU,sBAAsB,CACpC,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAA0B;IAE9D,4EAA4E;IAC5E,iEAAiE;IACjE,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,CAAU,CAAC;QACvD,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;YAC/B,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACxB,YAAY,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,6DAA6D;IAC7D,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACrC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,KAAY,EAAE,QAAe,EAAE,EAAE;QACvD,qBAAqB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CAAC,KAAK,CAAC,CAAC;IACrC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,KAAY,EAAE,QAAe,EAAE,EAAE;QACvD,qBAAqB;QACrB,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC3B,CAAC;QACD,oBAAoB;QAEpB,MAAM,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC9B,IAAI,CAAC,EAAE,CAAC;YACN,CAAC,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,iCAAiC;YACjC,wCAAwC;QAC1C,CAAC;IACH,CAAC,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,EAAE,CAAC;IACX,CAAC;YAAS,CAAC;QACT,aAAa,CAAC,KAAK,CAAC,GAAG,OAAkD,CAAC;IAC5E,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.\nimport { options as preactOptions } from 'preact';\nimport type { VNode } from 'preact';\n\nimport { BITS, COMPONENT, COMPONENT_FORCE, DIFF2, ORIGINAL } from '../shared/render-constants.js';\n\nexport interface ForceRootRenderOptions {\n getRootVNode: () => unknown;\n setRootVNode: (vnode: VNode) => void;\n render: () => void;\n}\n\nexport function runWithForceRootRender(\n { getRootVNode, setRootVNode, render }: ForceRootRenderOptions,\n): void {\n // Preact can skip root render if `_original` is unchanged; bumping it keeps\n // backend force renders aligned with Preact's own rerender path.\n const rootVNode = getRootVNode();\n if (rootVNode) {\n const newVNode = Object.assign({}, rootVNode) as VNode;\n if (newVNode[ORIGINAL] != null) {\n newVNode[ORIGINAL] += 1;\n setRootVNode(newVNode);\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff = preactOptions[DIFF2];\n preactOptions[DIFF2] = (vnode: VNode, oldVNode: VNode) => {\n /* v8 ignore start */\n if (oldDiff) {\n oldDiff(vnode, oldVNode);\n }\n /* v8 ignore stop */\n\n const c = oldVNode[COMPONENT];\n if (c) {\n c[BITS] |= COMPONENT_FORCE;\n } else {\n // mount phase of a new Component\n // `isNew` is true, no need to set FORCE\n }\n };\n\n try {\n render();\n } finally {\n preactOptions[DIFF2] = oldDiff as (vnode: VNode, oldVNode: VNode) => void;\n }\n}\n"]}
|