@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,169 @@
|
|
|
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 { useLayoutEffect } from 'preact/hooks';
|
|
5
|
+
import { expect, it, vi } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { createBackgroundFunctionHandle } from '../../../src/core/background-function/handle.js';
|
|
8
|
+
import {
|
|
9
|
+
resetBackgroundFunctionRuntime,
|
|
10
|
+
runOnBackground,
|
|
11
|
+
} from '../../../src/core/background-function/run-on-background.js';
|
|
12
|
+
import { resetFunctionCallReturnListener } from '../../../src/core/thread-function-call/return-value.js';
|
|
13
|
+
import { root } from '../../../src/lynx-api.js';
|
|
14
|
+
import { __root } from '../../../src/root.js';
|
|
15
|
+
import { setupPage } from '../../../src/snapshot/index.js';
|
|
16
|
+
import { destroyBackground } from '../../../src/snapshot/lifecycle/destroy.js';
|
|
17
|
+
import { globalCommitTaskMap } from '../../../src/snapshot/lifecycle/patch/commit.js';
|
|
18
|
+
import { onPostWorkletCtx } from '../../../src/snapshot/worklet/ctx.js';
|
|
19
|
+
import { clearConfigCacheForTesting } from '../../../src/snapshot/worklet/functionality.js';
|
|
20
|
+
import { registerWorklet } from '../../../src/worklet-runtime/bindings/index.js';
|
|
21
|
+
import { WorkletEvents } from '../../../src/worklet-runtime/bindings/events.js';
|
|
22
|
+
import { initWorklet } from '../../../src/worklet-runtime/workletRuntime.js';
|
|
23
|
+
import { globalEnvManager } from '../utils/envManager.js';
|
|
24
|
+
import { elementTree } from '../utils/nativeMethod.js';
|
|
25
|
+
|
|
26
|
+
it('retires old and unmount background functions across ordinary reload and hydrates working replacements', async () => {
|
|
27
|
+
const oldCall = vi.fn(() => 'old-page');
|
|
28
|
+
const cleanupCall = vi.fn(() => 'unmounted-page');
|
|
29
|
+
const newCall = vi.fn(() => 'new-page');
|
|
30
|
+
const oldResult = vi.fn();
|
|
31
|
+
const oldRequestResult = vi.fn();
|
|
32
|
+
const newResult = vi.fn(value => value);
|
|
33
|
+
let generation = 0;
|
|
34
|
+
let cleanupCtx;
|
|
35
|
+
const cleanup = vi.fn(() => {
|
|
36
|
+
cleanupCtx = onPostWorkletCtx({
|
|
37
|
+
_wkltId: 'cleanup',
|
|
38
|
+
_jsFn: { callback: createBackgroundFunctionHandle(cleanupCall) },
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
function App() {
|
|
42
|
+
useLayoutEffect(() => cleanup, []);
|
|
43
|
+
const ctx = {
|
|
44
|
+
_wkltId: 'call-background',
|
|
45
|
+
_jsFn: {
|
|
46
|
+
callback: __MAIN_THREAD__
|
|
47
|
+
? { _isFirstScreen: true }
|
|
48
|
+
: createBackgroundFunctionHandle(generation === 0 ? oldCall : newCall),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
return <view main-thread:bindtap={ctx} />;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function hydratePage() {
|
|
55
|
+
globalEnvManager.switchToBackground();
|
|
56
|
+
lynx.getNativeApp().callLepusMethod.mockClear();
|
|
57
|
+
lynx.getApp().OnLifecycleEvent(...__OnLifecycleEvent.mock.lastCall);
|
|
58
|
+
const [method, patch, complete] = lynx.getNativeApp().callLepusMethod.mock.lastCall;
|
|
59
|
+
expect(patch.patchOptions.isHydration).toBe(true);
|
|
60
|
+
globalEnvManager.switchToMainThread();
|
|
61
|
+
globalThis[method](patch);
|
|
62
|
+
globalEnvManager.switchToBackground();
|
|
63
|
+
complete();
|
|
64
|
+
globalEnvManager.switchToMainThread();
|
|
65
|
+
return __root.__element_root.children[0].props.event['bindEvent:tap'].value;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const workletGlobals = {
|
|
69
|
+
lynxWorkletImpl: globalThis.lynxWorkletImpl,
|
|
70
|
+
runWorklet: globalThis.runWorklet,
|
|
71
|
+
registerWorklet: globalThis.registerWorklet,
|
|
72
|
+
registerWorkletInternal: globalThis.registerWorkletInternal,
|
|
73
|
+
};
|
|
74
|
+
const sdkVersion = SystemInfo.lynxSdkVersion;
|
|
75
|
+
globalEnvManager.resetEnv();
|
|
76
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
77
|
+
clearConfigCacheForTesting();
|
|
78
|
+
try {
|
|
79
|
+
initWorklet();
|
|
80
|
+
registerWorklet('main-thread', 'call-background', function(value) {
|
|
81
|
+
return runOnBackground(this._jsFn.callback)(value);
|
|
82
|
+
});
|
|
83
|
+
setupPage(__CreatePage('0', 0));
|
|
84
|
+
__root.__jsx = <App />;
|
|
85
|
+
renderPage({});
|
|
86
|
+
globalEnvManager.switchToBackground();
|
|
87
|
+
root.render(<App />);
|
|
88
|
+
const oldCtx = hydratePage();
|
|
89
|
+
const context = lynx.getCoreContext();
|
|
90
|
+
const jsContext = lynx.getJSContext();
|
|
91
|
+
// Hold a real old return and request at the transport boundary. Replay the
|
|
92
|
+
// original envelopes after reload; do not manufacture their version/IDs.
|
|
93
|
+
context.dispatchEvent.mockImplementationOnce(() => {});
|
|
94
|
+
void runWorklet(oldCtx, ['before']).then(oldResult);
|
|
95
|
+
const oldReturn = context.dispatchEvent.mock.lastCall[0];
|
|
96
|
+
expect(oldReturn.type).toBe(WorkletEvents.FunctionCallRet);
|
|
97
|
+
expect(oldCall).toHaveBeenCalledExactlyOnceWith('before');
|
|
98
|
+
jsContext.dispatchEvent.mockImplementationOnce(() => {});
|
|
99
|
+
void runWorklet(oldCtx, ['delayed-request']).then(oldRequestResult);
|
|
100
|
+
const oldRequest = jsContext.dispatchEvent.mock.lastCall[0];
|
|
101
|
+
expect(oldRequest.type).toBe(WorkletEvents.runOnBackground);
|
|
102
|
+
|
|
103
|
+
globalEnvManager.switchToBackground();
|
|
104
|
+
const oldListeners = context.addEventListener.mock.calls.filter(([type]) =>
|
|
105
|
+
type === WorkletEvents.runOnBackground || type === WorkletEvents.releaseBackgroundWorkletCtx
|
|
106
|
+
);
|
|
107
|
+
expect(oldListeners).toHaveLength(2);
|
|
108
|
+
context.removeEventListener.mockClear();
|
|
109
|
+
generation = 1;
|
|
110
|
+
lynx.getApp().onAppReload({});
|
|
111
|
+
expect(cleanup).toHaveBeenCalledOnce();
|
|
112
|
+
// The test harness shares resolver state across threads: finish MTS reload
|
|
113
|
+
// before dispatching new calls, then apply the actual hydration patch.
|
|
114
|
+
globalEnvManager.switchToMainThread();
|
|
115
|
+
updatePage({}, { reloadTemplate: true });
|
|
116
|
+
const newCtx = hydratePage();
|
|
117
|
+
context.dispatchEvent.mockImplementationOnce(() => {});
|
|
118
|
+
const result = runWorklet(newCtx, ['after']).then(newResult);
|
|
119
|
+
const newReturn = context.dispatchEvent.mock.lastCall[0];
|
|
120
|
+
expect(JSON.parse(newReturn.data).resolveId).toBe(JSON.parse(oldReturn.data).resolveId);
|
|
121
|
+
expect(newCall).toHaveBeenCalledExactlyOnceWith('after');
|
|
122
|
+
jsContext.dispatchEvent(oldRequest);
|
|
123
|
+
globalEnvManager.switchToBackground();
|
|
124
|
+
context.dispatchEvent(oldReturn);
|
|
125
|
+
await Promise.resolve();
|
|
126
|
+
expect(newResult).not.toHaveBeenCalled();
|
|
127
|
+
expect(oldResult).not.toHaveBeenCalled();
|
|
128
|
+
expect(oldRequestResult).not.toHaveBeenCalled();
|
|
129
|
+
context.dispatchEvent(newReturn);
|
|
130
|
+
await expect(result).resolves.toBe('new-page');
|
|
131
|
+
|
|
132
|
+
globalEnvManager.switchToMainThread();
|
|
133
|
+
await expect(runWorklet(oldCtx, ['retired'])).rejects.toThrow('runOnBackground: JS function not found');
|
|
134
|
+
// A thrown native listener leaves this harness on the receiving thread.
|
|
135
|
+
globalEnvManager.switchToMainThread();
|
|
136
|
+
await expect(
|
|
137
|
+
runOnBackground({
|
|
138
|
+
_jsFnId: cleanupCtx._jsFn.callback._jsFnId,
|
|
139
|
+
_execId: cleanupCtx._execId,
|
|
140
|
+
})(),
|
|
141
|
+
).rejects.toThrow('runOnBackground: JS function not found');
|
|
142
|
+
expect.soft(oldCall).toHaveBeenCalledOnce();
|
|
143
|
+
expect.soft(cleanupCall).not.toHaveBeenCalled();
|
|
144
|
+
for (const [type, listener] of oldListeners) {
|
|
145
|
+
expect.soft(context.removeEventListener).toHaveBeenCalledWith(type, listener);
|
|
146
|
+
}
|
|
147
|
+
globalEnvManager.switchToMainThread();
|
|
148
|
+
// Releasing retired contexts must not remove a replacement page's context.
|
|
149
|
+
lynx.getJSContext().dispatchEvent({
|
|
150
|
+
type: WorkletEvents.releaseBackgroundWorkletCtx,
|
|
151
|
+
data: [oldCtx._execId, cleanupCtx._execId],
|
|
152
|
+
});
|
|
153
|
+
await expect(runWorklet(newCtx, ['after-release'])).resolves.toBe('new-page');
|
|
154
|
+
expect(newCall).toHaveBeenCalledTimes(2);
|
|
155
|
+
} finally {
|
|
156
|
+
cleanup.mockImplementation(() => {});
|
|
157
|
+
globalEnvManager.switchToBackground();
|
|
158
|
+
destroyBackground();
|
|
159
|
+
resetBackgroundFunctionRuntime();
|
|
160
|
+
resetFunctionCallReturnListener();
|
|
161
|
+
globalCommitTaskMap.clear();
|
|
162
|
+
globalEnvManager.resetEnv();
|
|
163
|
+
elementTree.clear();
|
|
164
|
+
Object.assign(globalThis, workletGlobals);
|
|
165
|
+
SystemInfo.lynxSdkVersion = sdkVersion;
|
|
166
|
+
clearConfigCacheForTesting();
|
|
167
|
+
vi.restoreAllMocks();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
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, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { createElement } from '../../../lepus/index.js';
|
|
7
|
+
import { runOnBackground } from '../../../src/core/background-function/run-on-background.js';
|
|
8
|
+
import { getReloadVersion } from '../../../src/core/reload-version.js';
|
|
9
|
+
import { resetFunctionCallReturnListener } from '../../../src/core/thread-function-call/return-value.js';
|
|
10
|
+
import { __root } from '../../../src/root.js';
|
|
11
|
+
import { setupPage } from '../../../src/snapshot/index.js';
|
|
12
|
+
import { initRunOnBackgroundDelay } from '../../../src/worklet-runtime/delayRunOnBackground.js';
|
|
13
|
+
import { globalEnvManager } from '../utils/envManager.js';
|
|
14
|
+
import { elementTree } from '../utils/nativeMethod.js';
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
globalEnvManager.resetEnv();
|
|
18
|
+
setupPage(__CreatePage('0', 0));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
vi.restoreAllMocks();
|
|
23
|
+
globalEnvManager.resetEnv();
|
|
24
|
+
elementTree.clear();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('clears old delayed background calls before rendering and preserves new calls', () => {
|
|
28
|
+
const previousImpl = globalThis.lynxWorkletImpl;
|
|
29
|
+
const previousSdkVersion = SystemInfo.lynxSdkVersion;
|
|
30
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
31
|
+
const delay = initRunOnBackgroundDelay();
|
|
32
|
+
globalThis.lynxWorkletImpl = { ...previousImpl, _runOnBackgroundDelayImpl: delay };
|
|
33
|
+
const dispatch = vi.spyOn(lynx.getJSContext(), 'dispatchEvent').mockImplementation(() => {});
|
|
34
|
+
try {
|
|
35
|
+
__root.__jsx = createElement(() => {
|
|
36
|
+
void runOnBackground(Object.assign(() => {}, { _isFirstScreen: true }))();
|
|
37
|
+
return null;
|
|
38
|
+
});
|
|
39
|
+
renderPage({});
|
|
40
|
+
expect(delay.delayedBackgroundFunctionArray).toHaveLength(1);
|
|
41
|
+
const oldTask = delay.delayedBackgroundFunctionArray[0];
|
|
42
|
+
const oldCallback = vi.spyOn(oldTask, 'task');
|
|
43
|
+
|
|
44
|
+
updatePage({}, { reloadTemplate: true });
|
|
45
|
+
|
|
46
|
+
expect(delay.delayedBackgroundFunctionArray).toHaveLength(1);
|
|
47
|
+
expect(delay.delayedBackgroundFunctionArray[0]).not.toBe(oldTask);
|
|
48
|
+
delay.delayedBackgroundFunctionArray[0].jsFnHandle = { _jsFnId: 7, _execId: 9 };
|
|
49
|
+
delay.runDelayedBackgroundFunctions();
|
|
50
|
+
expect(oldCallback).not.toHaveBeenCalled();
|
|
51
|
+
expect(dispatch).toHaveBeenCalledOnce();
|
|
52
|
+
expect(JSON.parse(dispatch.mock.calls[0][0].data)).toMatchObject({
|
|
53
|
+
obj: { _jsFnId: 7, _execId: 9 },
|
|
54
|
+
reloadVersion: getReloadVersion(),
|
|
55
|
+
});
|
|
56
|
+
expect(delay.delayedBackgroundFunctionArray).toHaveLength(0);
|
|
57
|
+
} finally {
|
|
58
|
+
delay.clearDelayedBackgroundFunctions();
|
|
59
|
+
resetFunctionCallReturnListener();
|
|
60
|
+
globalThis.lynxWorkletImpl = previousImpl;
|
|
61
|
+
SystemInfo.lynxSdkVersion = previousSdkVersion;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
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 { createElement } from 'preact';
|
|
5
|
+
import { useLayoutEffect } from 'preact/hooks';
|
|
6
|
+
import { expect, it, vi } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
delayedRunOnMainThreadData,
|
|
10
|
+
takeDelayedRunOnMainThreadData,
|
|
11
|
+
} from '../../../src/core/thread-function-call/main-thread.js';
|
|
12
|
+
import { resetFunctionCallReturnListener } from '../../../src/core/thread-function-call/return-value.js';
|
|
13
|
+
import { root } from '../../../src/lynx-api.js';
|
|
14
|
+
import { __root } from '../../../src/root.js';
|
|
15
|
+
import { destroyBackground } from '../../../src/snapshot/lifecycle/destroy.js';
|
|
16
|
+
import { globalCommitTaskMap } from '../../../src/snapshot/lifecycle/patch/commit.js';
|
|
17
|
+
import { reloadBackground } from '../../../src/snapshot/lifecycle/reload.js';
|
|
18
|
+
import { setupPage } from '../../../src/snapshot/index.js';
|
|
19
|
+
import { runOnMainThread } from '../../../src/snapshot/worklet/call/runOnMainThread.js';
|
|
20
|
+
import { registerWorklet } from '../../../src/worklet-runtime/bindings/index.js';
|
|
21
|
+
import { initWorklet } from '../../../src/worklet-runtime/workletRuntime.js';
|
|
22
|
+
import { globalEnvManager } from '../utils/envManager.js';
|
|
23
|
+
import { elementTree } from '../utils/nativeMethod.js';
|
|
24
|
+
|
|
25
|
+
it('drops pre-hydration and unmount calls before a reload reuses their return IDs', async () => {
|
|
26
|
+
const oldResult = vi.fn();
|
|
27
|
+
const cleanupResult = vi.fn();
|
|
28
|
+
const cleanup = vi.fn(() => {
|
|
29
|
+
void runOnMainThread({ _wkltId: 'unmount-call' })().then(cleanupResult);
|
|
30
|
+
expect(delayedRunOnMainThreadData.map(data => data.resolveId)).toEqual([1, 2]);
|
|
31
|
+
});
|
|
32
|
+
function App() {
|
|
33
|
+
useLayoutEffect(() => cleanup, []);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const oldCall = vi.fn(() => 'old-page');
|
|
38
|
+
const unmountCall = vi.fn(() => 'old-page');
|
|
39
|
+
const newCall = vi.fn(() => 'new-page');
|
|
40
|
+
const workletGlobals = {
|
|
41
|
+
lynxWorkletImpl: globalThis.lynxWorkletImpl,
|
|
42
|
+
runWorklet: globalThis.runWorklet,
|
|
43
|
+
registerWorklet: globalThis.registerWorklet,
|
|
44
|
+
registerWorkletInternal: globalThis.registerWorkletInternal,
|
|
45
|
+
};
|
|
46
|
+
const sdkVersion = SystemInfo.lynxSdkVersion;
|
|
47
|
+
globalEnvManager.resetEnv();
|
|
48
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
49
|
+
try {
|
|
50
|
+
initWorklet();
|
|
51
|
+
registerWorklet('main-thread', 'old-call', oldCall);
|
|
52
|
+
registerWorklet('main-thread', 'unmount-call', unmountCall);
|
|
53
|
+
registerWorklet('main-thread', 'new-call', newCall);
|
|
54
|
+
setupPage(__CreatePage('0', 0));
|
|
55
|
+
__root.__jsx = null;
|
|
56
|
+
renderPage({});
|
|
57
|
+
globalEnvManager.switchToBackground();
|
|
58
|
+
root.render(createElement(App));
|
|
59
|
+
void runOnMainThread({ _wkltId: 'old-call' })().then(oldResult);
|
|
60
|
+
expect(delayedRunOnMainThreadData[0]?.resolveId).toBe(1);
|
|
61
|
+
|
|
62
|
+
reloadBackground({});
|
|
63
|
+
expect(cleanup).toHaveBeenCalledOnce();
|
|
64
|
+
// Both threads share resolver state in this harness. Complete MTS reload
|
|
65
|
+
// before creating the replacement BTS call, then deliver its hydration.
|
|
66
|
+
globalEnvManager.switchToMainThread();
|
|
67
|
+
updatePage({}, { reloadTemplate: true });
|
|
68
|
+
globalEnvManager.switchToBackground();
|
|
69
|
+
const result = runOnMainThread({ _wkltId: 'new-call' })();
|
|
70
|
+
expect(delayedRunOnMainThreadData.at(-1)?.resolveId).toBe(1);
|
|
71
|
+
|
|
72
|
+
lynx.getNativeApp().callLepusMethod.mockClear();
|
|
73
|
+
lynx.getApp().OnLifecycleEvent(...__OnLifecycleEvent.mock.lastCall);
|
|
74
|
+
const [method, patch, complete] = lynx.getNativeApp().callLepusMethod.mock.lastCall;
|
|
75
|
+
expect(patch.patchOptions.isHydration).toBe(true);
|
|
76
|
+
expect(JSON.parse(patch.data).delayedRunOnMainThreadData).toEqual([
|
|
77
|
+
{ worklet: expect.objectContaining({ _wkltId: 'new-call' }), params: [], resolveId: 1 },
|
|
78
|
+
]);
|
|
79
|
+
globalEnvManager.switchToMainThread();
|
|
80
|
+
globalThis[method](patch);
|
|
81
|
+
globalEnvManager.switchToBackground();
|
|
82
|
+
complete();
|
|
83
|
+
|
|
84
|
+
await expect(result).resolves.toBe('new-page');
|
|
85
|
+
expect(newCall).toHaveBeenCalledExactlyOnceWith();
|
|
86
|
+
expect(oldCall).not.toHaveBeenCalled();
|
|
87
|
+
expect(unmountCall).not.toHaveBeenCalled();
|
|
88
|
+
expect(oldResult).not.toHaveBeenCalled();
|
|
89
|
+
expect(cleanupResult).not.toHaveBeenCalled();
|
|
90
|
+
} finally {
|
|
91
|
+
cleanup.mockImplementation(() => {});
|
|
92
|
+
globalEnvManager.switchToBackground();
|
|
93
|
+
destroyBackground();
|
|
94
|
+
takeDelayedRunOnMainThreadData();
|
|
95
|
+
resetFunctionCallReturnListener();
|
|
96
|
+
globalCommitTaskMap.clear();
|
|
97
|
+
globalEnvManager.resetEnv();
|
|
98
|
+
elementTree.clear();
|
|
99
|
+
Object.assign(globalThis, workletGlobals);
|
|
100
|
+
SystemInfo.lynxSdkVersion = sdkVersion;
|
|
101
|
+
vi.restoreAllMocks();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
@@ -5,11 +5,19 @@ import { useEffect, useLayoutEffect, useState } from '../../src/index';
|
|
|
5
5
|
import { globalEnvManager } from './utils/envManager';
|
|
6
6
|
import { waitSchedule } from './utils/nativeMethod';
|
|
7
7
|
import { globalCommitTaskMap, replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
__globalSnapshotPatch,
|
|
10
|
+
deinitGlobalSnapshotPatch,
|
|
11
|
+
initGlobalSnapshotPatch,
|
|
12
|
+
} from '../../src/snapshot/lifecycle/patch/snapshotPatch';
|
|
9
13
|
import { LifecycleConstant } from '../../src/snapshot/lifecycle/constant';
|
|
10
14
|
import { CATCH_ERROR } from '../../src/shared/render-constants';
|
|
11
15
|
import { __root } from '../../src/root';
|
|
12
16
|
import { setupPage, backgroundSnapshotInstanceManager } from '../../src/snapshot';
|
|
17
|
+
import { onFunctionCall, resetFunctionCallReturnListener } from '../../src/core/thread-function-call/return-value.js';
|
|
18
|
+
import { getReloadVersion } from '../../src/core/reload-version.js';
|
|
19
|
+
import { reloadBackground } from '../../src/snapshot/lifecycle/reload.js';
|
|
20
|
+
import { WorkletEvents } from '../../src/worklet-runtime/bindings/events.js';
|
|
13
21
|
|
|
14
22
|
beforeAll(() => {
|
|
15
23
|
setupPage(__CreatePage('0', 0));
|
|
@@ -673,3 +681,55 @@ describe('componentDidUpdate', () => {
|
|
|
673
681
|
expect(callback).nthCalledWith(2, 2);
|
|
674
682
|
});
|
|
675
683
|
});
|
|
684
|
+
|
|
685
|
+
it.each(['page close', 'reload'])('cleans Snapshot patches and return listeners on %s', (boundary) => {
|
|
686
|
+
globalEnvManager.switchToBackground();
|
|
687
|
+
const context = lynx.getCoreContext();
|
|
688
|
+
const addListener = vi.spyOn(context, 'addEventListener').mockClear();
|
|
689
|
+
const removeListener = vi.spyOn(context, 'removeEventListener').mockClear();
|
|
690
|
+
const oldResolve = vi.fn();
|
|
691
|
+
let patchDuringUnmount = null;
|
|
692
|
+
const unmount = vi.fn(() => {
|
|
693
|
+
patchDuringUnmount = __globalSnapshotPatch;
|
|
694
|
+
// Cleanup can itself create a pending cross-thread call.
|
|
695
|
+
onFunctionCall(oldResolve);
|
|
696
|
+
});
|
|
697
|
+
class Comp extends Component {
|
|
698
|
+
componentWillUnmount() {
|
|
699
|
+
unmount();
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
render() {
|
|
703
|
+
return null;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
try {
|
|
708
|
+
__root.__jsx = <Comp />;
|
|
709
|
+
render(__root.__jsx, __root);
|
|
710
|
+
initGlobalSnapshotPatch();
|
|
711
|
+
__globalSnapshotPatch.push('pending patch');
|
|
712
|
+
onFunctionCall(oldResolve);
|
|
713
|
+
|
|
714
|
+
if (boundary === 'page close') lynx.getApp().callDestroyLifetimeFun();
|
|
715
|
+
else reloadBackground({});
|
|
716
|
+
|
|
717
|
+
expect(unmount).toHaveBeenCalledOnce();
|
|
718
|
+
expect.soft(patchDuringUnmount).toBeUndefined();
|
|
719
|
+
expect.soft(__globalSnapshotPatch).toBeUndefined();
|
|
720
|
+
for (const [type, listener] of addListener.mock.calls) {
|
|
721
|
+
if (type === WorkletEvents.FunctionCallRet) {
|
|
722
|
+
expect.soft(removeListener).toHaveBeenCalledWith(type, listener);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const newResolve = vi.fn();
|
|
727
|
+
const resolveId = onFunctionCall(newResolve);
|
|
728
|
+
const listener = addListener.mock.lastCall[1];
|
|
729
|
+
listener({ data: JSON.stringify({ resolveId, returnValue: 'new result', reloadVersion: getReloadVersion() }) });
|
|
730
|
+
expect(newResolve).toHaveBeenCalledWith('new result');
|
|
731
|
+
expect(oldResolve).not.toHaveBeenCalled();
|
|
732
|
+
} finally {
|
|
733
|
+
resetFunctionCallReturnListener();
|
|
734
|
+
}
|
|
735
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { options, render } from 'preact';
|
|
6
|
+
import { createElement } from 'preact/compat';
|
|
7
|
+
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { lazy, useEffect, useRef, useState } from '../../../src/index.js';
|
|
10
|
+
import { makeSyncThen } from '../../../src/core/lynx/lazy-bundle.js';
|
|
11
|
+
import { __root } from '../../../src/root.js';
|
|
12
|
+
import { globalEnvManager } from '../utils/envManager.js';
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
vi.restoreAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('synchronous lazy imports with cached Promise.resolve results', () => {
|
|
19
|
+
test.each([undefined, null, true, false, 0, ''])(
|
|
20
|
+
'keeps the shared promise for %j asynchronous',
|
|
21
|
+
async (value) => {
|
|
22
|
+
const resolve = Promise.resolve.bind(Promise);
|
|
23
|
+
const shared = resolve(value);
|
|
24
|
+
const originalThen = shared.then;
|
|
25
|
+
// The Lynx Promise polyfill reuses fulfilled promises for these values.
|
|
26
|
+
vi.spyOn(Promise, 'resolve').mockImplementation(result => result === value ? shared : resolve(result));
|
|
27
|
+
|
|
28
|
+
const promise = makeSyncThen('exports').call(resolve('exports'), () => value);
|
|
29
|
+
let lazyCallbackCalled = false;
|
|
30
|
+
promise.then(result => {
|
|
31
|
+
expect(result).toBe(value);
|
|
32
|
+
lazyCallbackCalled = true;
|
|
33
|
+
});
|
|
34
|
+
expect(lazyCallbackCalled).toBe(true);
|
|
35
|
+
expect(shared.then).toBe(originalThen);
|
|
36
|
+
|
|
37
|
+
let ordinaryCallbackCalled = false;
|
|
38
|
+
Promise.resolve(value).then(() => {
|
|
39
|
+
ordinaryCallbackCalled = true;
|
|
40
|
+
});
|
|
41
|
+
expect(ordinaryCallbackCalled).toBe(false);
|
|
42
|
+
await resolve();
|
|
43
|
+
expect(ordinaryCallbackCalled).toBe(true);
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
test('a cached lazy child mount effect can update its parent without re-entering', async () => {
|
|
48
|
+
globalEnvManager.resetEnv();
|
|
49
|
+
globalEnvManager.switchToBackground();
|
|
50
|
+
const previousDebounce = options.debounceRendering;
|
|
51
|
+
const previousRaf = options.requestAnimationFrame;
|
|
52
|
+
const resolve = Promise.resolve.bind(Promise);
|
|
53
|
+
const sharedUndefined = resolve();
|
|
54
|
+
vi.spyOn(Promise, 'resolve').mockImplementation(value => value === undefined ? sharedUndefined : resolve(value));
|
|
55
|
+
|
|
56
|
+
// This is Preact's fallback scheduler in Lynx runtimes without the global
|
|
57
|
+
// queueMicrotask API. Its Promise.resolve must remain asynchronous.
|
|
58
|
+
options.debounceRendering = callback => Promise.resolve().then(callback);
|
|
59
|
+
let flushEffects;
|
|
60
|
+
options.requestAnimationFrame = callback => {
|
|
61
|
+
flushEffects = callback;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const calls = [];
|
|
65
|
+
let parentValue;
|
|
66
|
+
function Leaf({ notify }) {
|
|
67
|
+
const count = useRef(0);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
count.current++;
|
|
70
|
+
calls.push(['effect', count.current]);
|
|
71
|
+
notify();
|
|
72
|
+
return () => calls.push(['cleanup', count.current]);
|
|
73
|
+
}, []);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const exports = { default: Leaf };
|
|
77
|
+
const cached = resolve(exports);
|
|
78
|
+
cached.then = makeSyncThen(exports);
|
|
79
|
+
const Remote = lazy(() => cached);
|
|
80
|
+
function App() {
|
|
81
|
+
const [value, setValue] = useState(0);
|
|
82
|
+
parentValue = value;
|
|
83
|
+
return createElement(Remote, { notify: () => setValue(v => v + 1) });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
render(createElement(App), __root);
|
|
88
|
+
flushEffects();
|
|
89
|
+
expect(calls).toEqual([['effect', 1]]);
|
|
90
|
+
expect(parentValue).toBe(0);
|
|
91
|
+
await resolve();
|
|
92
|
+
expect(parentValue).toBe(1);
|
|
93
|
+
expect(calls).toEqual([['effect', 1]]);
|
|
94
|
+
|
|
95
|
+
render(null, __root);
|
|
96
|
+
flushEffects();
|
|
97
|
+
expect(calls).toEqual([['effect', 1], ['cleanup', 1]]);
|
|
98
|
+
} finally {
|
|
99
|
+
render(null, __root);
|
|
100
|
+
flushEffects?.();
|
|
101
|
+
options.debounceRendering = previousDebounce;
|
|
102
|
+
options.requestAnimationFrame = previousRaf;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -5,7 +5,7 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi }
|
|
|
5
5
|
import { globalEnvManager } from './utils/envManager';
|
|
6
6
|
import { elementTree, options } from './utils/nativeMethod';
|
|
7
7
|
import { __page as __internalPage } from '../../src/internal';
|
|
8
|
-
import {
|
|
8
|
+
import { firstScreenSync } from '../../src/snapshot/lifecycle/event/firstScreenSync';
|
|
9
9
|
import { __root } from '../../src/root';
|
|
10
10
|
import { clearPage } from '../../src/snapshot';
|
|
11
11
|
|
|
@@ -467,7 +467,7 @@ describe('ssr', () => {
|
|
|
467
467
|
|
|
468
468
|
ssrHydrate(info);
|
|
469
469
|
expect(__internalPage).toBe(__page);
|
|
470
|
-
expect(
|
|
470
|
+
expect(firstScreenSync.eventIdSwap).toEqual({});
|
|
471
471
|
{
|
|
472
472
|
const listRef = elementTree.getElementById('ssr-list');
|
|
473
473
|
expect(elementTree.triggerComponentAtIndex(listRef, 0)).toEqual(uiSign1);
|
|
@@ -40,7 +40,7 @@ describe('runOnBackground', () => {
|
|
|
40
40
|
[
|
|
41
41
|
[
|
|
42
42
|
{
|
|
43
|
-
"data": "{"obj":{"_jsFnId":233,"_execId":244},"params":[1,["args"]],"resolveId":1}",
|
|
43
|
+
"data": "{"obj":{"_jsFnId":233,"_execId":244},"params":[1,["args"]],"resolveId":1,"reloadVersion":0}",
|
|
44
44
|
"type": "Lynx.Worklet.runOnBackground",
|
|
45
45
|
},
|
|
46
46
|
],
|
|
@@ -69,7 +69,7 @@ describe('runOnBackground', () => {
|
|
|
69
69
|
[
|
|
70
70
|
[
|
|
71
71
|
{
|
|
72
|
-
"data": "{"obj":{"_jsFnId":7,"_execId":8},"params":[1,["args"]],"resolveId":1}",
|
|
72
|
+
"data": "{"obj":{"_jsFnId":7,"_execId":8},"params":[1,["args"]],"resolveId":1,"reloadVersion":0}",
|
|
73
73
|
"type": "Lynx.Worklet.runOnBackground",
|
|
74
74
|
},
|
|
75
75
|
],
|
|
@@ -111,14 +111,9 @@ describe('runOnBackground', () => {
|
|
|
111
111
|
|
|
112
112
|
expect(() => {
|
|
113
113
|
runJSFunction({
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
_execId: id,
|
|
118
|
-
},
|
|
119
|
-
params: [],
|
|
120
|
-
resolveId: 1,
|
|
121
|
-
}),
|
|
114
|
+
obj: { _jsFnId: 234, _execId: id },
|
|
115
|
+
params: [],
|
|
116
|
+
resolveId: 1,
|
|
122
117
|
});
|
|
123
118
|
}).toThrowError('runOnBackground: JS function not found');
|
|
124
119
|
});
|
|
@@ -229,6 +224,6 @@ describe('runJSFunction', () => {
|
|
|
229
224
|
data: [id],
|
|
230
225
|
});
|
|
231
226
|
|
|
232
|
-
expect(trigger).toThrow(
|
|
227
|
+
expect(trigger).toThrow(`runOnBackground: JS function not found: {"_jsFnId":233,"_execId":${id}}`);
|
|
233
228
|
});
|
|
234
229
|
});
|
|
@@ -90,7 +90,7 @@ describe('runOnMainThread', () => {
|
|
|
90
90
|
[
|
|
91
91
|
[
|
|
92
92
|
{
|
|
93
|
-
"data": "{"worklet":{"_wkltId":"835d:450ef:2"},"params":[1,["args"]],"resolveId":1}",
|
|
93
|
+
"data": "{"worklet":{"_wkltId":"835d:450ef:2"},"params":[1,["args"]],"resolveId":1,"reloadVersion":0}",
|
|
94
94
|
"type": "Lynx.Worklet.runWorkletCtx",
|
|
95
95
|
},
|
|
96
96
|
],
|
|
@@ -16,7 +16,10 @@ import { MainThreadRef, isMainThreadRef, useMainThreadRef } from '../../../src/c
|
|
|
16
16
|
import { isMainThreadFunction } from '../../../src/core/main-thread-function';
|
|
17
17
|
import { takeMainThreadRefInitValuePatch } from '../../../src/core/main-thread-ref-init-value';
|
|
18
18
|
import { globalEnvManager } from '../utils/envManager';
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
injectUpdateMTRefInitValue,
|
|
21
|
+
sendMTRefInitValueToMainThread,
|
|
22
|
+
} from '../../../src/snapshot/worklet/ref/updateInitValue';
|
|
20
23
|
|
|
21
24
|
const Comp = () => {
|
|
22
25
|
const ref = useMainThreadRef(233);
|
|
@@ -51,6 +54,7 @@ beforeEach(() => {
|
|
|
51
54
|
});
|
|
52
55
|
|
|
53
56
|
afterEach(() => {
|
|
57
|
+
globalThis.__ALOG__ = true;
|
|
54
58
|
destroyWorklet();
|
|
55
59
|
vi.clearAllMocks();
|
|
56
60
|
});
|
|
@@ -151,6 +155,13 @@ describe('WorkletRef in js', () => {
|
|
|
151
155
|
expect(globalThis.lynxWorkletImpl._refImpl.updateWorkletRefInitValueChanges).toBeCalledTimes(1);
|
|
152
156
|
globalThis[rLynxChange[1][0]](rLynxChange[1][1]);
|
|
153
157
|
expect(globalThis.lynxWorkletImpl._refImpl.updateWorkletRefInitValueChanges).toBeCalledTimes(1);
|
|
158
|
+
const logs = console.alog.mock.calls.map(([message]) => message).filter(message =>
|
|
159
|
+
message.includes('MTRefInitValue')
|
|
160
|
+
);
|
|
161
|
+
expect(logs).toEqual([
|
|
162
|
+
'[ReactLynxDebug] Snapshot BTS -> MTS sendMTRefInitValue:\n[[1,233]]',
|
|
163
|
+
'[ReactLynxDebug] Snapshot MTS updateMTRefInitValue:\n[[1,233]]',
|
|
164
|
+
]);
|
|
154
165
|
}
|
|
155
166
|
});
|
|
156
167
|
|
|
@@ -176,6 +187,18 @@ describe('WorkletRef in js', () => {
|
|
|
176
187
|
);
|
|
177
188
|
});
|
|
178
189
|
|
|
190
|
+
it.each([false, undefined])('should initialize refs without alog when the flag is %s', (alog) => {
|
|
191
|
+
globalThis.__ALOG__ = alog;
|
|
192
|
+
globalEnvManager.switchToBackground();
|
|
193
|
+
new MainThreadRef(233);
|
|
194
|
+
sendMTRefInitValueToMainThread();
|
|
195
|
+
const [name, data] = lynx.getNativeApp().callLepusMethod.mock.calls.at(-1);
|
|
196
|
+
globalEnvManager.switchToMainThread();
|
|
197
|
+
globalThis[name](data);
|
|
198
|
+
expect(globalThis.lynxWorkletImpl._refImpl.updateWorkletRefInitValueChanges).toHaveBeenCalledWith([[1, 233]]);
|
|
199
|
+
expect(console.alog.mock.calls.some(([message]) => message.includes('MTRefInitValue'))).toBe(false);
|
|
200
|
+
});
|
|
201
|
+
|
|
179
202
|
it('should not send init value to the main thread when native capabilities not fulfilled', () => {
|
|
180
203
|
SystemInfo.lynxSdkVersion = '2.13';
|
|
181
204
|
const Comp = () => {
|