@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
|
@@ -5,6 +5,7 @@ import { BackgroundElementTemplateInstance } from '../../../../../src/element-te
|
|
|
5
5
|
import { backgroundElementTemplateInstanceManager } from '../../../../../src/element-template/background/manager.js';
|
|
6
6
|
import { root } from '../../../../../src/element-template/index.js';
|
|
7
7
|
import { resetElementTemplatePatchListener } from '../../../../../src/element-template/native/patch-listener.js';
|
|
8
|
+
import { resetElementTemplateRefInitValueListener } from '../../../../../src/element-template/main-thread-ref-init-value.js';
|
|
8
9
|
import { __root, setRoot } from '../../../../../src/element-template/runtime/page/root-instance.js';
|
|
9
10
|
import { serializeBackgroundTree } from '../../../test-utils/debug/serializer.js';
|
|
10
11
|
|
|
@@ -25,6 +26,7 @@ function setup(): void {
|
|
|
25
26
|
|
|
26
27
|
function teardown(): void {
|
|
27
28
|
resetElementTemplatePatchListener();
|
|
29
|
+
resetElementTemplateRefInitValueListener();
|
|
28
30
|
resetElementTemplateHydrationListener();
|
|
29
31
|
vi.unstubAllGlobals();
|
|
30
32
|
(globalThis as { __LYNX_REPORT_ERROR_CALLS?: Error[] }).__LYNX_REPORT_ERROR_CALLS = [];
|
|
@@ -19,7 +19,7 @@ describe('legacy internal guardrail', () => {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it('keeps the ET main-thread event loader surface minimal', () => {
|
|
22
|
-
expect(ElementTemplateInternal
|
|
22
|
+
expect('loadWorkletRuntime' in ElementTemplateInternal).toBe(false);
|
|
23
23
|
expect('loadWorkletRuntime' in ElementTemplateRuntime).toBe(false);
|
|
24
24
|
|
|
25
25
|
expect(ElementTemplateInternal.captureMainThreadObject({ value: 1 })).toBeUndefined();
|
|
@@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
3
3
|
import { ElementTemplateEnvManager } from '../test-utils/debug/envManager.js';
|
|
4
4
|
|
|
5
5
|
const envManager = new ElementTemplateEnvManager();
|
|
6
|
+
const installElementTemplateRefInitValueListener = vi.fn();
|
|
6
7
|
|
|
7
8
|
describe('element-template native index wiring', () => {
|
|
8
9
|
const originalNodeEnv = process.env['NODE_ENV'];
|
|
@@ -10,6 +11,10 @@ describe('element-template native index wiring', () => {
|
|
|
10
11
|
beforeEach(() => {
|
|
11
12
|
vi.resetModules();
|
|
12
13
|
vi.clearAllMocks();
|
|
14
|
+
vi.doMock('../../../src/element-template/main-thread-ref-init-value.js', async (importOriginal) => ({
|
|
15
|
+
...await importOriginal<typeof import('../../../src/element-template/main-thread-ref-init-value.js')>(),
|
|
16
|
+
installElementTemplateRefInitValueListener,
|
|
17
|
+
}));
|
|
13
18
|
globalThis.__ALOG_ELEMENT_API__ = undefined;
|
|
14
19
|
});
|
|
15
20
|
|
|
@@ -17,6 +22,7 @@ describe('element-template native index wiring', () => {
|
|
|
17
22
|
process.env['NODE_ENV'] = originalNodeEnv;
|
|
18
23
|
globalThis.__ALOG_ELEMENT_API__ = undefined;
|
|
19
24
|
vi.resetModules();
|
|
25
|
+
vi.doUnmock('../../../src/element-template/main-thread-ref-init-value.js');
|
|
20
26
|
vi.doUnmock('../../../src/element-template/native/main-thread-api.js');
|
|
21
27
|
vi.doUnmock('../../../src/element-template/native/patch-listener.js');
|
|
22
28
|
vi.doUnmock('../../../src/element-template/native/mts-destroy.js');
|
|
@@ -98,6 +104,7 @@ describe('element-template native index wiring', () => {
|
|
|
98
104
|
|
|
99
105
|
expect(initElementTemplatePAPICallAlog).toHaveBeenCalledTimes(1);
|
|
100
106
|
expect(injectCalledByNative).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(installElementTemplateRefInitValueListener).toHaveBeenCalledTimes(1);
|
|
101
108
|
expect(installElementTemplatePatchListener).toHaveBeenCalledTimes(1);
|
|
102
109
|
expect(installOnMtsDestruction).toHaveBeenCalledTimes(1);
|
|
103
110
|
expect(initProfileHook).toHaveBeenCalledTimes(1);
|
|
@@ -218,6 +225,7 @@ describe('element-template native index wiring', () => {
|
|
|
218
225
|
);
|
|
219
226
|
|
|
220
227
|
expect(injectCalledByNative).not.toHaveBeenCalled();
|
|
228
|
+
expect(installElementTemplateRefInitValueListener).not.toHaveBeenCalled();
|
|
221
229
|
expect(installElementTemplatePatchListener).not.toHaveBeenCalled();
|
|
222
230
|
expect(installOnMtsDestruction).not.toHaveBeenCalled();
|
|
223
231
|
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { MainThreadRef, clearMainThreadRefLastIdForTesting } from '../../../src/core/main-thread-ref.js';
|
|
4
|
+
import { takeMainThreadRefInitValuePatch } from '../../../src/core/main-thread-ref-init-value.js';
|
|
5
|
+
import { clearMtsConfigCacheForTesting } from '../../../src/core/mts-capability.js';
|
|
6
|
+
import { increaseReloadVersion } from '../../../src/core/reload-version.js';
|
|
7
|
+
import {
|
|
8
|
+
installElementTemplateRefInitValueListener,
|
|
9
|
+
resetElementTemplateRefInitValueListener,
|
|
10
|
+
sendMTRefInitValueToMainThread,
|
|
11
|
+
} from '../../../src/element-template/main-thread-ref-init-value.js';
|
|
12
|
+
import {
|
|
13
|
+
installElementTemplatePatchListener,
|
|
14
|
+
resetElementTemplatePatchListener,
|
|
15
|
+
} from '../../../src/element-template/native/patch-listener.js';
|
|
16
|
+
import { destroyElementTemplateMainThreadRuntime } from '../../../src/element-template/native/mts-destroy.js';
|
|
17
|
+
import { ElementTemplateLifecycleConstant } from '../../../src/element-template/protocol/lifecycle-constant.js';
|
|
18
|
+
import { getFromWorkletRefMap, initWorkletRef } from '../../../src/worklet-runtime/workletRef.js';
|
|
19
|
+
import { ElementTemplateEnvManager } from '../test-utils/debug/envManager.js';
|
|
20
|
+
|
|
21
|
+
describe('ElementTemplate ref initialization event', () => {
|
|
22
|
+
const env = new ElementTemplateEnvManager();
|
|
23
|
+
let previousImpl: typeof globalThis.lynxWorkletImpl;
|
|
24
|
+
let previousSdkVersion: string;
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
env.resetEnv('background');
|
|
28
|
+
previousSdkVersion = SystemInfo.lynxSdkVersion;
|
|
29
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
30
|
+
clearMtsConfigCacheForTesting();
|
|
31
|
+
clearMainThreadRefLastIdForTesting();
|
|
32
|
+
takeMainThreadRefInitValuePatch();
|
|
33
|
+
previousImpl = globalThis.lynxWorkletImpl;
|
|
34
|
+
globalThis.lynxWorkletImpl = { ...previousImpl, _refImpl: initWorkletRef() };
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
env.switchToMainThread();
|
|
39
|
+
resetElementTemplateRefInitValueListener();
|
|
40
|
+
globalThis.lynxWorkletImpl = previousImpl;
|
|
41
|
+
SystemInfo.lynxSdkVersion = previousSdkVersion;
|
|
42
|
+
clearMtsConfigCacheForTesting();
|
|
43
|
+
takeMainThreadRefInitValuePatch();
|
|
44
|
+
vi.unstubAllGlobals();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it.each([true, false, undefined])('initializes a retained ref after reload (alog: %s)', (alog) => {
|
|
48
|
+
vi.stubGlobal('__ALOG__', alog);
|
|
49
|
+
const log = vi.spyOn(console, 'alog');
|
|
50
|
+
env.switchToMainThread();
|
|
51
|
+
installElementTemplateRefInitValueListener();
|
|
52
|
+
env.switchToBackground();
|
|
53
|
+
const ref = new MainThreadRef(233);
|
|
54
|
+
const handle = JSON.parse(JSON.stringify(ref));
|
|
55
|
+
sendMTRefInitValueToMainThread();
|
|
56
|
+
// Advance after BTS sent the event, before MTS receives it.
|
|
57
|
+
increaseReloadVersion();
|
|
58
|
+
env.switchToMainThread();
|
|
59
|
+
expect(getFromWorkletRefMap(handle)).toMatchObject({ current: 233 });
|
|
60
|
+
if (alog) {
|
|
61
|
+
expect(log).toHaveBeenCalledWith('[ReactLynxDebug] ElementTemplate BTS -> MTS sendMTRefInitValue:\n[[1,233]]');
|
|
62
|
+
expect(log).toHaveBeenCalledWith('[ReactLynxDebug] ElementTemplate MTS updateMTRefInitValue:\n[[1,233]]');
|
|
63
|
+
} else {
|
|
64
|
+
expect(log.mock.calls.some(([message]) => String(message).includes('MTRefInitValue'))).toBe(false);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('does not send an empty queue or resend initialization', () => {
|
|
69
|
+
const dispatch = vi.spyOn(lynx.getCoreContext(), 'dispatchEvent');
|
|
70
|
+
sendMTRefInitValueToMainThread();
|
|
71
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
72
|
+
new MainThreadRef('once');
|
|
73
|
+
sendMTRefInitValueToMainThread();
|
|
74
|
+
sendMTRefInitValueToMainThread();
|
|
75
|
+
expect(dispatch).toHaveBeenCalledExactlyOnceWith({
|
|
76
|
+
type: ElementTemplateLifecycleConstant.updateMTRefInitValue,
|
|
77
|
+
data: JSON.stringify([[1, 'once']]),
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('keeps its receiver when the UI listener resets and removes it on destruction', () => {
|
|
82
|
+
env.switchToMainThread();
|
|
83
|
+
const apply = vi.spyOn(globalThis.lynxWorkletImpl._refImpl, 'updateWorkletRefInitValueChanges');
|
|
84
|
+
installElementTemplateRefInitValueListener();
|
|
85
|
+
installElementTemplateRefInitValueListener();
|
|
86
|
+
installElementTemplatePatchListener();
|
|
87
|
+
resetElementTemplatePatchListener();
|
|
88
|
+
env.switchToBackground();
|
|
89
|
+
new MainThreadRef('first');
|
|
90
|
+
sendMTRefInitValueToMainThread();
|
|
91
|
+
env.switchToMainThread();
|
|
92
|
+
expect(apply).toHaveBeenCalledOnce();
|
|
93
|
+
destroyElementTemplateMainThreadRuntime();
|
|
94
|
+
env.switchToBackground();
|
|
95
|
+
new MainThreadRef('after-destroy');
|
|
96
|
+
sendMTRefInitValueToMainThread();
|
|
97
|
+
env.switchToMainThread();
|
|
98
|
+
expect(apply).toHaveBeenCalledOnce();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
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, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
registerBackgroundFunctionCtx,
|
|
8
|
+
runOnBackground,
|
|
9
|
+
} from '../../../src/core/background-function/run-on-background.js';
|
|
10
|
+
import { destroyElementTemplateBackgroundRuntime } from '../../../src/element-template/background/destroy.js';
|
|
11
|
+
import { getReloadVersion } from '../../../src/core/reload-version.js';
|
|
12
|
+
import { WorkletEvents } from '../../../src/worklet-runtime/bindings/events.js';
|
|
13
|
+
import { reloadMainThread } from '../../../src/element-template/native/reload-main-thread.js';
|
|
14
|
+
import { createElementTemplatePage, setupPage } from '../../../src/element-template/runtime/page/page.js';
|
|
15
|
+
import {
|
|
16
|
+
__etAttrPlanMap,
|
|
17
|
+
adaptMTRefAttrSlot,
|
|
18
|
+
clearEtAttrPlanMap,
|
|
19
|
+
} from '../../../src/element-template/runtime/template/attr-slot-plan.js';
|
|
20
|
+
import {
|
|
21
|
+
initializeMainThreadDynamicAttrSlots,
|
|
22
|
+
attachMainThreadDynamicAttrRefsForSubtree,
|
|
23
|
+
} from '../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
|
|
24
|
+
import { reloadBackground } from '../../../src/element-template/native/reload-background.js';
|
|
25
|
+
import { resetElementTemplateMainThreadBackgroundFunctionRuntime } from '../../../src/element-template/runtime/template/main-thread-background-function.js';
|
|
26
|
+
import { ElementTemplateEnvManager } from '../test-utils/debug/envManager.js';
|
|
27
|
+
|
|
28
|
+
// ET ordinary reload retains the entry, but clears its background function table.
|
|
29
|
+
// Queue a real MTS request, reload before BTS delivery, then deliver the request.
|
|
30
|
+
describe('ElementTemplate dual-thread communication delivery across ordinary reload', () => {
|
|
31
|
+
const env = new ElementTemplateEnvManager();
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
env.switchToMainThread(() => resetElementTemplateMainThreadBackgroundFunctionRuntime());
|
|
34
|
+
env.switchToBackground(() => destroyElementTemplateBackgroundRuntime());
|
|
35
|
+
clearEtAttrPlanMap();
|
|
36
|
+
vi.unstubAllGlobals();
|
|
37
|
+
});
|
|
38
|
+
it('stamps calls from old main-thread ref cleanup with the old version', () => {
|
|
39
|
+
env.resetEnv('main');
|
|
40
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
41
|
+
const page = createElementTemplatePage();
|
|
42
|
+
setupPage(page);
|
|
43
|
+
const oldVersion = getReloadVersion();
|
|
44
|
+
const dispatch = vi.spyOn(lynx.getJSContext(), 'dispatchEvent');
|
|
45
|
+
const cleanup = vi.fn(() => {
|
|
46
|
+
void runOnBackground(Object.assign(() => {}, { _execId: 2, _jsFnId: 1 }))();
|
|
47
|
+
});
|
|
48
|
+
vi.stubGlobal('runWorklet', vi.fn(() => cleanup));
|
|
49
|
+
__etAttrPlanMap._reload_dual_thread = [0, adaptMTRefAttrSlot];
|
|
50
|
+
initializeMainThreadDynamicAttrSlots(-1, '_reload_dual_thread', [
|
|
51
|
+
{ type: 'main-thread-ref', value: { _wkltId: 'ref-cleanup' } },
|
|
52
|
+
]);
|
|
53
|
+
attachMainThreadDynamicAttrRefsForSubtree([{ uid: -1, ref: page }]);
|
|
54
|
+
|
|
55
|
+
reloadMainThread({}, { reloadTemplate: true });
|
|
56
|
+
|
|
57
|
+
expect(cleanup).toHaveBeenCalledOnce();
|
|
58
|
+
const request = dispatch.mock.calls.find(([event]) => event.type === WorkletEvents.runOnBackground)![0];
|
|
59
|
+
expect(JSON.parse(request.data as string).reloadVersion).toBe(oldVersion);
|
|
60
|
+
expect(getReloadVersion()).toBe(oldVersion + 1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it.each([1, 2])('drops a stale request from %i retired contexts before looking up a function', async (ctxCount) => {
|
|
64
|
+
env.resetEnv('background');
|
|
65
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
66
|
+
const oldFn = vi.fn();
|
|
67
|
+
let oldCtx;
|
|
68
|
+
for (let i = 0; i < ctxCount; i++) {
|
|
69
|
+
oldCtx = { _wkltId: 'ctx', _c: { fn: { _jsFnId: 1, _fn: oldFn } }, _execId: 0 };
|
|
70
|
+
registerBackgroundFunctionCtx(oldCtx);
|
|
71
|
+
}
|
|
72
|
+
const oldId = oldCtx!._execId;
|
|
73
|
+
env.switchToMainThread();
|
|
74
|
+
void runOnBackground(Object.assign(() => {}, { _execId: oldId, _jsFnId: 1 }))();
|
|
75
|
+
|
|
76
|
+
// The harness shares core modules across threads. Retire MTS resolvers first,
|
|
77
|
+
// as its ordinary reload does, before exercising the real BTS reload below.
|
|
78
|
+
resetElementTemplateMainThreadBackgroundFunctionRuntime();
|
|
79
|
+
|
|
80
|
+
const freshFn = vi.fn(() => 'fresh');
|
|
81
|
+
const freshCtx = { _wkltId: 'ctx', _c: { fn: { _jsFnId: 1, _fn: freshFn } }, _execId: 0 };
|
|
82
|
+
expect(() =>
|
|
83
|
+
env.switchToBackground(() => {
|
|
84
|
+
reloadBackground({});
|
|
85
|
+
registerBackgroundFunctionCtx(freshCtx);
|
|
86
|
+
})
|
|
87
|
+
).not.toThrow();
|
|
88
|
+
expect(freshCtx._execId).toBeGreaterThan(oldId);
|
|
89
|
+
// A stale request must be dropped before looking up its retired context.
|
|
90
|
+
expect(freshFn).not.toHaveBeenCalled();
|
|
91
|
+
expect(oldFn).not.toHaveBeenCalled();
|
|
92
|
+
|
|
93
|
+
env.switchToMainThread();
|
|
94
|
+
lynx.getJSContext().dispatchEvent({ type: WorkletEvents.releaseBackgroundWorkletCtx, data: [oldId] });
|
|
95
|
+
const result = runOnBackground(Object.assign(() => {}, { _execId: freshCtx._execId, _jsFnId: 1 }))();
|
|
96
|
+
env.switchToBackground();
|
|
97
|
+
env.switchToMainThread();
|
|
98
|
+
await expect(result).resolves.toBe('fresh');
|
|
99
|
+
expect(freshFn).toHaveBeenCalledOnce();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -7,7 +7,8 @@ import { installElementTemplateHydrationListener } from '../../../src/element-te
|
|
|
7
7
|
import { BackgroundPageRootInstance } from '../../../src/element-template/background/instance.js';
|
|
8
8
|
import { profileEnd, profileStart } from '../../../src/element-template/debug/profile.js';
|
|
9
9
|
import { reloadBackground } from '../../../src/element-template/native/reload-background.js';
|
|
10
|
-
import {
|
|
10
|
+
import { onMtsDestruction } from '../../../src/element-template/native/mts-destroy.js';
|
|
11
|
+
import { completeMainThreadReload, reloadMainThread } from '../../../src/element-template/native/reload-main-thread.js';
|
|
11
12
|
import { resetEventStateForRuntime } from '../../../src/element-template/prop-adapters/event.js';
|
|
12
13
|
import { destroyAllElementTemplateListStates } from '../../../src/element-template/runtime/list/list.js';
|
|
13
14
|
import { setupPage } from '../../../src/element-template/runtime/page/page.js';
|
|
@@ -110,6 +111,10 @@ vi.mock('../../../src/element-template/background/instance.js', () => {
|
|
|
110
111
|
};
|
|
111
112
|
});
|
|
112
113
|
|
|
114
|
+
vi.mock('../../../src/element-template/native/mts-destroy.js', () => ({
|
|
115
|
+
onMtsDestruction: vi.fn(),
|
|
116
|
+
}));
|
|
117
|
+
|
|
113
118
|
vi.mock('../../../src/element-template/debug/profile.js', () => ({
|
|
114
119
|
profileEnd: vi.fn(),
|
|
115
120
|
profileStart: vi.fn(),
|
|
@@ -295,6 +300,50 @@ describe('ElementTemplate reloadMainThread', () => {
|
|
|
295
300
|
}
|
|
296
301
|
});
|
|
297
302
|
|
|
303
|
+
it('evaluates the entry again and lets it render into the retained page', () => {
|
|
304
|
+
vi.mocked(mockRender).mockReturnValue({ pageAttributes: null, rootRefs: [], rootSubtreeHandles: [] });
|
|
305
|
+
const supportsReEvalKey = Symbol.for('__LYNX_ENTRY_SUPPORTS_RE_EVAL__');
|
|
306
|
+
const reloaderKey = Symbol.for('__LYNX_MAIN_THREAD_ENTRY_RELOADER__');
|
|
307
|
+
const completerKey = Symbol.for('__LYNX_MAIN_THREAD_RELOAD_COMPLETER__');
|
|
308
|
+
const host = lynx as unknown as Record<symbol, unknown>;
|
|
309
|
+
vi.stubGlobal('__EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__', true);
|
|
310
|
+
const page = mockedState.page;
|
|
311
|
+
const newJsx = { type: 'NewApp' };
|
|
312
|
+
const events: string[] = [];
|
|
313
|
+
lynx.__initData = { kept: 'yes', count: 1 };
|
|
314
|
+
vi.mocked(onMtsDestruction).mockImplementation(() => events.push('retire'));
|
|
315
|
+
vi.mocked(increaseReloadVersion).mockImplementationOnce(() => {
|
|
316
|
+
events.push('advance-version');
|
|
317
|
+
return 2;
|
|
318
|
+
});
|
|
319
|
+
host[supportsReEvalKey] = true;
|
|
320
|
+
host[reloaderKey] = () => {
|
|
321
|
+
events.push('evaluate');
|
|
322
|
+
// What evaluating the entry does: reset init data, install its completer, render into a fresh root.
|
|
323
|
+
lynx.__initData = {};
|
|
324
|
+
host[completerKey] = completeMainThreadReload;
|
|
325
|
+
setRoot({ __jsx: newJsx });
|
|
326
|
+
};
|
|
327
|
+
const options = { reloadTemplate: true };
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
reloadMainThread({ count: 2 }, options);
|
|
331
|
+
} finally {
|
|
332
|
+
delete host[supportsReEvalKey];
|
|
333
|
+
delete host[reloaderKey];
|
|
334
|
+
delete host[completerKey];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
expect(events).toEqual(['retire', 'advance-version', 'evaluate']);
|
|
338
|
+
expect(increaseReloadVersion).toHaveBeenCalledOnce();
|
|
339
|
+
expect(lynx.__initData).toEqual({ kept: 'yes', count: 2 });
|
|
340
|
+
expect(setupPage).toHaveBeenLastCalledWith(page);
|
|
341
|
+
expect(mockRender).toHaveBeenCalledWith(newJsx, undefined);
|
|
342
|
+
expect(__FlushElementTree).toHaveBeenLastCalledWith(undefined, options);
|
|
343
|
+
// The retained page is not rebuilt by the previous entry.
|
|
344
|
+
expect(elementTemplateRegistry.clear).not.toHaveBeenCalled();
|
|
345
|
+
});
|
|
346
|
+
|
|
298
347
|
it('rebuilds when the physical page has no root slot', () => {
|
|
299
348
|
mockedState.root = { __jsx: null };
|
|
300
349
|
vi.mocked(mockRender).mockReturnValue({
|
|
@@ -222,64 +222,121 @@ describe('ElementTemplate commit hook', () => {
|
|
|
222
222
|
expect(takeDelayedRunOnMainThreadData()).toEqual([]);
|
|
223
223
|
});
|
|
224
224
|
|
|
225
|
-
it('dispatches
|
|
226
|
-
markElementTemplateHydrated();
|
|
225
|
+
it.each([false, true])('dispatches ref initialization separately (hydrated: %s)', (hydrated) => {
|
|
226
|
+
if (hydrated) markElementTemplateHydrated();
|
|
227
|
+
const dispatch = vi.spyOn(lynx.getCoreContext(), 'dispatchEvent');
|
|
227
228
|
new MainThreadRef('commit-init');
|
|
228
229
|
|
|
229
230
|
options.__c?.({} as unknown as object, []);
|
|
230
231
|
|
|
232
|
+
expect(dispatch).toHaveBeenCalledExactlyOnceWith({
|
|
233
|
+
type: ElementTemplateLifecycleConstant.updateMTRefInitValue,
|
|
234
|
+
data: JSON.stringify([[1, 'commit-init']]),
|
|
235
|
+
});
|
|
236
|
+
expect(takeMainThreadRefInitValuePatch()).toEqual([]);
|
|
231
237
|
envManager.switchToMainThread();
|
|
232
|
-
expect(updateEvents).toEqual([
|
|
233
|
-
{
|
|
234
|
-
ops: [],
|
|
235
|
-
flushOptions: { emptyPatch: true },
|
|
236
|
-
flowIds: undefined,
|
|
237
|
-
reloadVersion: getReloadVersion(),
|
|
238
|
-
mainThreadRefInitValuePatch: [[1, 'commit-init']],
|
|
239
|
-
},
|
|
240
|
-
]);
|
|
238
|
+
expect(updateEvents).toEqual([]);
|
|
241
239
|
envManager.switchToBackground();
|
|
242
|
-
expect(takeMainThreadRefInitValuePatch()).toEqual([]);
|
|
243
240
|
});
|
|
244
241
|
|
|
245
|
-
it('
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
242
|
+
it.each(['update', 'ref', 'circular-ref', 'dispatch'])(
|
|
243
|
+
'cleans commit state when %s fails and allows the next commit',
|
|
244
|
+
(failure) => {
|
|
245
|
+
vi.useFakeTimers();
|
|
246
|
+
globalThis.__ALOG__ = false;
|
|
247
|
+
const serializeError = new Error('update serialization failed');
|
|
248
|
+
const dispatch = vi.spyOn(lynx.getCoreContext(), 'dispatchEvent');
|
|
249
|
+
const throwingValue = {
|
|
250
|
+
toJSON() {
|
|
251
|
+
throw serializeError;
|
|
252
|
+
},
|
|
253
|
+
} as unknown as string;
|
|
254
|
+
const circularValue: { self?: unknown } = {};
|
|
255
|
+
circularValue.self = circularValue;
|
|
256
|
+
new MainThreadRef(
|
|
257
|
+
failure === 'ref' ? throwingValue : failure === 'circular-ref' ? circularValue : 'survives-ui-serialization',
|
|
258
|
+
);
|
|
259
|
+
if (failure === 'dispatch') {
|
|
260
|
+
dispatch.mockImplementationOnce(() => {
|
|
261
|
+
throw serializeError;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
const ref = vi.fn();
|
|
265
|
+
const removedRoot = new BackgroundElementTemplateInstance('removed');
|
|
266
|
+
const removeEventListener = vi.spyOn(lynx.getCoreContext(), 'removeEventListener');
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
markElementTemplateHydrated();
|
|
270
|
+
queueRefAttrUpdate(null, ref, { instanceId: -2 }, 0);
|
|
271
|
+
markRemovedSubtreeForPostDispatchTeardown(removedRoot);
|
|
272
|
+
globalCommitContext.ops = createRawTextOps(1, failure === 'update' ? throwingValue : 'failed');
|
|
273
|
+
enqueueDelayedRunOnMainThreadData({
|
|
274
|
+
worklet: { _wkltId: 'failed-serialize-main-thread-function' },
|
|
275
|
+
params: [],
|
|
276
|
+
resolveId: onFunctionCall(vi.fn()),
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
expect(() => options.__c?.({} as unknown as object, [])).toThrow(
|
|
280
|
+
failure === 'circular-ref' ? TypeError : serializeError,
|
|
281
|
+
);
|
|
282
|
+
if (failure === 'update' || failure === 'dispatch') {
|
|
283
|
+
expect(dispatch).toHaveBeenCalledExactlyOnceWith({
|
|
284
|
+
type: ElementTemplateLifecycleConstant.updateMTRefInitValue,
|
|
285
|
+
data: JSON.stringify([[1, 'survives-ui-serialization']]),
|
|
286
|
+
});
|
|
287
|
+
} else {
|
|
288
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
289
|
+
}
|
|
290
|
+
expect(takeMainThreadRefInitValuePatch()).toEqual([]);
|
|
291
|
+
expect(takeDelayedRunOnMainThreadData()).toEqual([]);
|
|
292
|
+
expect(removeEventListener).toHaveBeenCalledWith(WorkletEvents.FunctionCallRet, expect.any(Function));
|
|
293
|
+
expect(globalCommitContext.ops).toEqual([]);
|
|
294
|
+
expect([...globalCommitContext.nonPayload.removedSubtreesAwaitingTeardown]).toEqual([]);
|
|
295
|
+
|
|
296
|
+
dispatch.mockClear();
|
|
297
|
+
new MainThreadRef('next-ref');
|
|
298
|
+
globalCommitContext.ops = createRawTextOps(2, 'next-commit');
|
|
299
|
+
options.__c?.({} as unknown as object, []);
|
|
300
|
+
expect(ref).not.toHaveBeenCalled();
|
|
301
|
+
expect(dispatch.mock.calls.map(([event]) => event.type)).toEqual([
|
|
302
|
+
ElementTemplateLifecycleConstant.updateMTRefInitValue,
|
|
303
|
+
ElementTemplateLifecycleConstant.update,
|
|
304
|
+
]);
|
|
305
|
+
expect(dispatch.mock.calls[0]![0].data).toBe(JSON.stringify([[2, 'next-ref']]));
|
|
306
|
+
expect(parseElementTemplateUpdateEventPayload(dispatch.mock.calls[1]![0].data)).toMatchObject({
|
|
307
|
+
ops: createRawTextOps(2, 'next-commit'),
|
|
308
|
+
});
|
|
309
|
+
expect(parseElementTemplateUpdateEventPayload(dispatch.mock.calls[1]![0].data).delayedRunOnMainThreadData)
|
|
310
|
+
.toBeUndefined();
|
|
311
|
+
|
|
312
|
+
vi.advanceTimersByTime(10000);
|
|
313
|
+
expect(backgroundElementTemplateInstanceManager.get(removedRoot.instanceId)).toBeUndefined();
|
|
314
|
+
} finally {
|
|
315
|
+
vi.useRealTimers();
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
it('cleans a failed ref initialization commit before hydration', () => {
|
|
321
|
+
const circularValue: { self?: unknown } = {};
|
|
322
|
+
circularValue.self = circularValue;
|
|
323
|
+
new MainThreadRef(circularValue);
|
|
254
324
|
const ref = vi.fn();
|
|
255
|
-
|
|
325
|
+
queueRefAttrUpdate(null, ref, { instanceId: -2 }, 0);
|
|
326
|
+
globalCommitContext.ops = createRawTextOps(1, 'failed');
|
|
327
|
+
enqueueDelayedRunOnMainThreadData({
|
|
328
|
+
worklet: { _wkltId: 'failed-ref-init' },
|
|
329
|
+
params: [],
|
|
330
|
+
resolveId: onFunctionCall(vi.fn()),
|
|
331
|
+
});
|
|
256
332
|
const removeEventListener = vi.spyOn(lynx.getCoreContext(), 'removeEventListener');
|
|
257
333
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
worklet: { _wkltId: 'failed-serialize-main-thread-function' },
|
|
265
|
-
params: [],
|
|
266
|
-
resolveId: onFunctionCall(vi.fn()),
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
expect(() => options.__c?.({} as unknown as object, [])).toThrow(serializeError);
|
|
270
|
-
expect(takeDelayedRunOnMainThreadData()).toEqual([]);
|
|
271
|
-
expect(removeEventListener).toHaveBeenCalledWith(WorkletEvents.FunctionCallRet, expect.any(Function));
|
|
272
|
-
expect(globalCommitContext.ops).toEqual([]);
|
|
273
|
-
expect([...globalCommitContext.nonPayload.removedSubtreesAwaitingTeardown]).toEqual([]);
|
|
274
|
-
|
|
275
|
-
options.__c?.({} as unknown as object, []);
|
|
276
|
-
expect(ref).not.toHaveBeenCalled();
|
|
277
|
-
|
|
278
|
-
vi.advanceTimersByTime(10000);
|
|
279
|
-
expect(backgroundElementTemplateInstanceManager.get(removedRoot.instanceId)).toBeUndefined();
|
|
280
|
-
} finally {
|
|
281
|
-
vi.useRealTimers();
|
|
282
|
-
}
|
|
334
|
+
expect(() => options.__c?.({} as unknown as object, [])).toThrow(TypeError);
|
|
335
|
+
expect(globalCommitContext.ops).toEqual([]);
|
|
336
|
+
expect(takeDelayedRunOnMainThreadData()).toEqual([]);
|
|
337
|
+
expect(removeEventListener).toHaveBeenCalledWith(WorkletEvents.FunctionCallRet, expect.any(Function));
|
|
338
|
+
options.__c?.({} as unknown as object, []);
|
|
339
|
+
expect(ref).not.toHaveBeenCalled();
|
|
283
340
|
});
|
|
284
341
|
|
|
285
342
|
it('dispatches triggerDataUpdated when useInitData observes a data change', () => {
|
package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx
CHANGED
|
@@ -208,35 +208,33 @@ function installMockWorkletRuntime(hydrateCtx = vi.fn()): {
|
|
|
208
208
|
hydrateCtx: ReturnType<typeof vi.fn>;
|
|
209
209
|
loadLepusChunk: ReturnType<typeof vi.fn>;
|
|
210
210
|
} {
|
|
211
|
-
const loadLepusChunk = vi.fn()
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return true;
|
|
239
|
-
});
|
|
211
|
+
const loadLepusChunk = vi.fn();
|
|
212
|
+
globalThis.lynxWorkletImpl = {
|
|
213
|
+
_workletMap: {},
|
|
214
|
+
_eventDelayImpl: {
|
|
215
|
+
clearDelayedWorklets: vi.fn(),
|
|
216
|
+
runDelayedWorklet: vi.fn(),
|
|
217
|
+
},
|
|
218
|
+
_refImpl: {
|
|
219
|
+
_firstScreenWorkletRefMap: new Map(),
|
|
220
|
+
_workletRefMap: {},
|
|
221
|
+
clearFirstScreenWorkletRefMap: vi.fn(),
|
|
222
|
+
updateWorkletRef: vi.fn(),
|
|
223
|
+
updateWorkletRefInitValueChanges: vi.fn(),
|
|
224
|
+
},
|
|
225
|
+
_runOnBackgroundDelayImpl: {
|
|
226
|
+
delayRunOnBackground: vi.fn(),
|
|
227
|
+
runDelayedBackgroundFunctions: vi.fn(),
|
|
228
|
+
},
|
|
229
|
+
_hydrateCtx: hydrateCtx,
|
|
230
|
+
_eomImpl: {
|
|
231
|
+
setShouldFlush: vi.fn(),
|
|
232
|
+
},
|
|
233
|
+
_runRunOnMainThreadTask: vi.fn(),
|
|
234
|
+
};
|
|
235
|
+
globalThis.registerWorkletInternal = (_type, id, worklet) => {
|
|
236
|
+
globalThis.lynxWorkletImpl._workletMap[id] = worklet;
|
|
237
|
+
};
|
|
240
238
|
vi.stubGlobal('__LoadLepusChunk', loadLepusChunk);
|
|
241
239
|
return { hydrateCtx, loadLepusChunk };
|
|
242
240
|
}
|
|
@@ -244,10 +242,8 @@ function installMockWorkletRuntime(hydrateCtx = vi.fn()): {
|
|
|
244
242
|
function installRealWorkletRuntime(): {
|
|
245
243
|
loadLepusChunk: ReturnType<typeof vi.fn>;
|
|
246
244
|
} {
|
|
247
|
-
const loadLepusChunk = vi.fn()
|
|
248
|
-
|
|
249
|
-
return true;
|
|
250
|
-
});
|
|
245
|
+
const loadLepusChunk = vi.fn();
|
|
246
|
+
initWorklet();
|
|
251
247
|
vi.stubGlobal('__LoadLepusChunk', loadLepusChunk);
|
|
252
248
|
return { loadLepusChunk };
|
|
253
249
|
}
|
|
@@ -429,8 +425,10 @@ describe('Compiled direct event background updates', () => {
|
|
|
429
425
|
enableWorkletTransform: true,
|
|
430
426
|
target: 'LEPUS',
|
|
431
427
|
});
|
|
432
|
-
expect(mainArtifact.code).toContain(
|
|
433
|
-
|
|
428
|
+
expect(mainArtifact.code).toContain(
|
|
429
|
+
'import { registerWorklet as __registerWorklet } from "@lynx-js/react/worklet-runtime/init"',
|
|
430
|
+
);
|
|
431
|
+
expect(mainArtifact.code).not.toContain('loadWorkletRuntime');
|
|
434
432
|
expect(mainArtifact.code).toContain('adaptMTEventAttrSlot');
|
|
435
433
|
expect(mainArtifact.code).not.toContain('registerWorkletOnBackground');
|
|
436
434
|
expect(mainArtifact.code).not.toContain('transformToWorklet');
|
|
@@ -439,10 +437,7 @@ describe('Compiled direct event background updates', () => {
|
|
|
439
437
|
const { loadLepusChunk } = installMockWorkletRuntime(hydrateCtx);
|
|
440
438
|
|
|
441
439
|
const { backgroundModule, mainModule } = await loadCompiledMainThreadDirectEventFixture();
|
|
442
|
-
expect(loadLepusChunk).
|
|
443
|
-
dynamicComponentEntry: '__Card__',
|
|
444
|
-
chunkType: 0,
|
|
445
|
-
});
|
|
440
|
+
expect(loadLepusChunk).not.toHaveBeenCalled();
|
|
446
441
|
expect(Object.keys(globalThis.lynxWorkletImpl._workletMap)).toHaveLength(1);
|
|
447
442
|
|
|
448
443
|
const host = renderCompiledFixtureOnBackground(backgroundModule, envManager, { label: 'first' });
|
|
@@ -511,20 +506,16 @@ describe('Compiled direct event background updates', () => {
|
|
|
511
506
|
enableWorkletTransform: true,
|
|
512
507
|
target: 'JS',
|
|
513
508
|
});
|
|
514
|
-
expect(mainArtifact.code).toContain(
|
|
515
|
-
|
|
509
|
+
expect(mainArtifact.code).toContain(
|
|
510
|
+
'import { registerWorklet as __registerWorklet } from "@lynx-js/react/worklet-runtime/init"',
|
|
511
|
+
);
|
|
512
|
+
expect(mainArtifact.code).not.toContain('loadWorkletRuntime');
|
|
516
513
|
expect(mainArtifact.code).toContain('runOnBackground');
|
|
517
514
|
expect(backgroundArtifact.code).toContain('transformToWorklet');
|
|
518
515
|
|
|
519
516
|
const { loadLepusChunk } = installRealWorkletRuntime();
|
|
520
517
|
const { backgroundModule, mainModule } = await loadCompiledMainThreadRunOnBackgroundEventFixture();
|
|
521
|
-
|
|
522
|
-
// sentinel via the webpack banner, so the compiled main thread forwards it
|
|
523
|
-
// to the worklet runtime loader (matching production for the main card).
|
|
524
|
-
expect(loadLepusChunk).toHaveBeenCalledWith('worklet-runtime', {
|
|
525
|
-
dynamicComponentEntry: '__Card__',
|
|
526
|
-
chunkType: 0,
|
|
527
|
-
});
|
|
518
|
+
expect(loadLepusChunk).not.toHaveBeenCalled();
|
|
528
519
|
const onReport = vi.fn((label: string) => `reported:${label}`);
|
|
529
520
|
const host = renderCompiledFixtureOnBackground(backgroundModule, envManager, { label: 'first', onReport });
|
|
530
521
|
renderCompiledFixtureOnMainThread(mainModule, envManager, { label: 'first', onReport });
|