@lynx-js/react 0.126.2 → 0.128.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 +36 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/docs/directives.md +90 -0
- package/docs/global-events.md +50 -0
- package/docs/import-attributes.md +43 -0
- package/docs/macros.md +285 -0
- package/package.json +7 -14
- package/refresh/.turbo/turbo-build.log +2 -2
- package/refresh/dist/index.js +26 -6
- package/refresh/package.json +1 -1
- package/runtime/__test__/core/main-thread-object.test.js +149 -0
- package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +26 -3
- package/runtime/__test__/element-template/imports/main-thread-object-api.test.ts +10 -0
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +4 -1
- 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 +11 -9
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -3
- 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/ctxNotFound.test.ts +271 -0
- package/runtime/__test__/snapshot/event.test.jsx +7 -7
- package/runtime/__test__/snapshot/lazy.test.js +73 -1
- package/runtime/__test__/snapshot/lynx/portals.test.jsx +75 -37
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +59 -47
- package/runtime/__test__/snapshot/spread.test.jsx +10 -10
- package/runtime/__test__/snapshot/worklet/main-thread-object.test.jsx +306 -0
- package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +1 -0
- package/runtime/__test__/worklet-runtime/initEntry.test.js +109 -0
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +182 -0
- package/runtime/__test__/worklet-runtime/object-methods.test.js +59 -0
- package/runtime/__test__/worklet-runtime/workletRef.test.js +362 -2
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +246 -1
- package/runtime/lazy/compat.js +2 -0
- package/runtime/lazy/element-template-internal.js +1 -1
- package/runtime/lazy/element-template.js +2 -0
- package/runtime/lazy/internal.js +2 -1
- package/runtime/lazy/react.js +2 -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.d.ts +16 -0
- package/runtime/lib/core/background-function/run-on-background.js +16 -0
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
- package/runtime/lib/core/capture-main-thread-object.d.ts +1 -0
- package/runtime/lib/core/capture-main-thread-object.js +16 -0
- package/runtime/lib/core/capture-main-thread-object.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/forceRootRender.js.map +1 -1
- package/runtime/lib/core/globalProps.d.ts +2 -0
- 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.d.ts +4 -0
- package/runtime/lib/core/hooks/react.js +4 -0
- package/runtime/lib/core/hooks/react.js.map +1 -1
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.d.ts +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
- package/runtime/lib/core/initData.d.ts +2 -0
- package/runtime/lib/core/initData.js +2 -0
- 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.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.d.ts +3 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js +17 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -0
- package/runtime/lib/core/main-thread-object.d.ts +77 -0
- package/runtime/lib/core/main-thread-object.js +258 -0
- package/runtime/lib/core/main-thread-object.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-id.d.ts +1 -0
- package/runtime/lib/core/main-thread-ref-id.js +14 -0
- package/runtime/lib/core/main-thread-ref-id.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-init-value.d.ts +1 -1
- package/runtime/lib/core/main-thread-ref-init-value.js +4 -2
- package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
- package/runtime/lib/core/main-thread-ref.d.ts +4 -0
- package/runtime/lib/core/main-thread-ref.js +5 -8
- 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-version.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- 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.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.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.d.ts +2 -0
- package/runtime/lib/element-template/index.js +1 -0
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +1 -1
- package/runtime/lib/element-template/internal.js +1 -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/native/callDestroyLifetimeFun.js.map +1 -1
- 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.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- 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.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 +1 -1
- 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 +1 -1
- package/runtime/lib/internal.js +1 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +34 -0
- package/runtime/lib/lynx-api.js +21 -0
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +4 -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.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.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.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.d.ts +11 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.js +24 -16
- 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.d.ts +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +29 -7
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +2 -2
- 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.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/render.js.map +1 -1
- 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.map +1 -1
- package/runtime/lib/snapshot/lynx/children.d.ts +2 -0
- package/runtime/lib/snapshot/lynx/children.js.map +1 -1
- package/runtime/lib/snapshot/lynx/element.d.ts +8 -0
- package/runtime/lib/snapshot/lynx/element.js +4 -0
- 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.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.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 +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -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.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.d.ts +3 -3
- package/runtime/lib/worklet-runtime/bindings/bindings.js +9 -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.d.ts +3 -6
- package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -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 +26 -7
- 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.map +1 -1
- package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.d.ts +8 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js +67 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -0
- 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.d.ts +11 -7
- package/runtime/lib/worklet-runtime/workletRef.js +72 -9
- package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +68 -9
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/background-function/run-on-background.ts +16 -0
- package/runtime/src/core/capture-main-thread-object.ts +17 -0
- package/runtime/src/core/globalProps.ts +2 -0
- package/runtime/src/core/hooks/react.ts +4 -0
- package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +2 -0
- package/runtime/src/core/initData.ts +2 -0
- package/runtime/src/core/main-thread-object-handle-registry.ts +25 -0
- package/runtime/src/core/main-thread-object.ts +380 -0
- package/runtime/src/core/main-thread-ref-id.ts +16 -0
- package/runtime/src/core/main-thread-ref-init-value.ts +12 -4
- package/runtime/src/core/main-thread-ref.ts +7 -8
- package/runtime/src/element-template/background/commit-hook.ts +1 -1
- package/runtime/src/element-template/index.ts +6 -0
- package/runtime/src/element-template/internal.ts +2 -1
- package/runtime/src/element-template/protocol/types.ts +1 -1
- package/runtime/src/internal.ts +1 -1
- package/runtime/src/lynx-api.ts +38 -0
- package/runtime/src/lynx.ts +5 -1
- package/runtime/src/snapshot/lifecycle/patch/error.ts +36 -19
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +29 -7
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +2 -2
- package/runtime/src/snapshot/lynx/children.ts +2 -0
- package/runtime/src/snapshot/lynx/element.ts +8 -0
- package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +2 -0
- package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +1 -1
- package/runtime/src/worklet-runtime/bindings/bindings.ts +17 -2
- package/runtime/src/worklet-runtime/bindings/index.ts +0 -1
- package/runtime/src/worklet-runtime/bindings/types.ts +7 -11
- package/runtime/src/worklet-runtime/hydrate.ts +43 -10
- package/runtime/src/worklet-runtime/index.ts +7 -0
- package/runtime/src/worklet-runtime/mainThreadObject.ts +117 -0
- package/runtime/src/worklet-runtime/workletRef.ts +120 -19
- package/runtime/src/worklet-runtime/workletRuntime.ts +83 -11
- package/runtime/tsconfig.json +2 -0
- package/runtime/vitest.config.ts +4 -0
- package/testing-library/.turbo/turbo-build.log +11 -11
- package/testing-library/dist/env/index.js +3 -15
- package/testing-library/dist/index.d.ts +165 -2
- 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/package.json +2 -1
- package/testing-library/rstest.config.ts +3 -0
- package/testing-library/src/__tests__/lynx.test.jsx +1 -1
- package/testing-library/src/__tests__/rstest-config.test.js +34 -1
- package/testing-library/src/__tests__/worklet.test.jsx +87 -33
- 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/testing-library/tsconfig.docs.json +9 -0
- package/testing-library/typedoc.json +22 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +135 -73
- package/transform/__test__/defines.spec.js +80 -12
- package/transform/__test__/fixture.spec.js +231 -71
- package/transform/__test__/object-methods.spec.js +82 -0
- package/transform/crates/swc_plugin_worklet/decl_collect.rs +10 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +14 -0
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +228 -13
- package/transform/crates/swc_plugin_worklet/lib.rs +599 -150
- package/transform/crates/swc_plugin_worklet/napi.rs +10 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +8 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +12 -7
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_js.js +27 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +43 -0
- 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_js.js +16 -14
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +18 -18
- 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_js.js +7 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +9 -9
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +22 -0
- 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 +14 -0
- 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_js.js +42 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +58 -0
- 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.js +3 -1
- 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 +5 -5
- 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_js.js +9 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +14 -0
- 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 +25 -1
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/src/lib.rs +193 -23
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +63 -467
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +340 -28
- package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
- package/transform/vitest.config.ts +5 -1
- package/types/react.docs.d.ts +130 -11
- 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 -638
- package/runtime/worklet-runtime/main.js +0 -1
- package/testing-library/node_modules/.bin/rsbuild +0 -68
- package/testing-library/node_modules/.bin/rspeedy +0 -68
- package/testing-library/node_modules/.bin/rstest +0 -68
- 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
- package/transform/node_modules/.bin/esbuild +0 -59
- package/transform/node_modules/.bin/napi +0 -68
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { act } from 'preact/test-utils';
|
|
2
2
|
import { ARIARole } from 'aria-query';
|
|
3
|
-
import { OptionsReceived } from 'pretty-format';
|
|
4
|
-
import * as prettyFormat from 'pretty-format';
|
|
5
3
|
|
|
6
4
|
export { act }
|
|
7
5
|
|
|
@@ -284,6 +282,37 @@ export declare interface ByRoleOptions {
|
|
|
284
282
|
*/
|
|
285
283
|
export declare function cleanup(): void;
|
|
286
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
287
|
+
*
|
|
288
|
+
* This source code is licensed under the MIT license found in the
|
|
289
|
+
* LICENSE file in the root directory of this source tree.
|
|
290
|
+
*/
|
|
291
|
+
declare type Colors = {
|
|
292
|
+
comment: {
|
|
293
|
+
close: string;
|
|
294
|
+
open: string;
|
|
295
|
+
};
|
|
296
|
+
content: {
|
|
297
|
+
close: string;
|
|
298
|
+
open: string;
|
|
299
|
+
};
|
|
300
|
+
prop: {
|
|
301
|
+
close: string;
|
|
302
|
+
open: string;
|
|
303
|
+
};
|
|
304
|
+
tag: {
|
|
305
|
+
close: string;
|
|
306
|
+
open: string;
|
|
307
|
+
};
|
|
308
|
+
value: {
|
|
309
|
+
close: string;
|
|
310
|
+
open: string;
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
declare type CompareKeys = ((a: string, b: string) => number) | undefined;
|
|
315
|
+
|
|
287
316
|
export declare function computeHeadingLevel(element: Element): number | undefined
|
|
288
317
|
|
|
289
318
|
export declare interface Config {
|
|
@@ -307,6 +336,22 @@ export declare interface Config {
|
|
|
307
336
|
getElementError: (message: string | null, container: Element) => Error
|
|
308
337
|
}
|
|
309
338
|
|
|
339
|
+
declare type Config_2 = {
|
|
340
|
+
callToJSON: boolean;
|
|
341
|
+
compareKeys: CompareKeys;
|
|
342
|
+
colors: Colors;
|
|
343
|
+
escapeRegex: boolean;
|
|
344
|
+
escapeString: boolean;
|
|
345
|
+
indent: string;
|
|
346
|
+
maxDepth: number;
|
|
347
|
+
min: boolean;
|
|
348
|
+
plugins: Plugins;
|
|
349
|
+
printBasicPrototype: boolean;
|
|
350
|
+
printFunctionName: boolean;
|
|
351
|
+
spacingInner: string;
|
|
352
|
+
spacingOuter: string;
|
|
353
|
+
};
|
|
354
|
+
|
|
310
355
|
export declare interface ConfigFn {
|
|
311
356
|
(existingConfig: Config): Partial<Config>
|
|
312
357
|
}
|
|
@@ -329,6 +374,8 @@ export declare type CreateObject = {
|
|
|
329
374
|
) => Event
|
|
330
375
|
}
|
|
331
376
|
|
|
377
|
+
declare const DEFAULT_OPTIONS: Options;
|
|
378
|
+
|
|
332
379
|
export declare interface DefaultNormalizerOptions {
|
|
333
380
|
trim?: boolean
|
|
334
381
|
collapseWhitespace?: boolean
|
|
@@ -618,6 +665,13 @@ declare type FireObject_2 = {
|
|
|
618
665
|
) => boolean
|
|
619
666
|
}
|
|
620
667
|
|
|
668
|
+
/**
|
|
669
|
+
* Returns a presentation string of your `val` object
|
|
670
|
+
* @param val any potential JavaScript object
|
|
671
|
+
* @param options Custom settings
|
|
672
|
+
*/
|
|
673
|
+
declare function format(val: unknown, options?: OptionsReceived): string;
|
|
674
|
+
|
|
621
675
|
export declare type GetAllBy<Arguments extends any[]> = QueryMethod<
|
|
622
676
|
Arguments,
|
|
623
677
|
HTMLElement[]
|
|
@@ -741,6 +795,8 @@ variant?: Variant,
|
|
|
741
795
|
method?: Method,
|
|
742
796
|
): Suggestion | undefined
|
|
743
797
|
|
|
798
|
+
declare type Indent = (arg0: string) => string;
|
|
799
|
+
|
|
744
800
|
/**
|
|
745
801
|
* @public
|
|
746
802
|
*/
|
|
@@ -1021,17 +1077,64 @@ export declare type Method =
|
|
|
1021
1077
|
| 'Title'
|
|
1022
1078
|
| 'title'
|
|
1023
1079
|
|
|
1080
|
+
declare type NewPlugin = {
|
|
1081
|
+
serialize: (val: any, config: Config_2, indentation: string, depth: number, refs: Refs, printer: Printer) => string;
|
|
1082
|
+
test: Test;
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1024
1085
|
export declare type NormalizerFn = (text: string) => string
|
|
1025
1086
|
|
|
1026
1087
|
export declare interface NormalizerOptions extends DefaultNormalizerOptions {
|
|
1027
1088
|
normalizer?: NormalizerFn
|
|
1028
1089
|
}
|
|
1029
1090
|
|
|
1091
|
+
declare type OldPlugin = {
|
|
1092
|
+
print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
|
|
1093
|
+
test: Test;
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
declare type Options = {
|
|
1097
|
+
callToJSON: boolean;
|
|
1098
|
+
compareKeys: CompareKeys;
|
|
1099
|
+
escapeRegex: boolean;
|
|
1100
|
+
escapeString: boolean;
|
|
1101
|
+
highlight: boolean;
|
|
1102
|
+
indent: number;
|
|
1103
|
+
maxDepth: number;
|
|
1104
|
+
min: boolean;
|
|
1105
|
+
plugins: Plugins;
|
|
1106
|
+
printBasicPrototype: boolean;
|
|
1107
|
+
printFunctionName: boolean;
|
|
1108
|
+
theme: Theme;
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
declare type OptionsReceived = PrettyFormatOptions;
|
|
1112
|
+
|
|
1030
1113
|
/**
|
|
1031
1114
|
* @public
|
|
1032
1115
|
*/
|
|
1033
1116
|
declare type PickUnderscoreKeys<T> = Pick<T, FilterUnderscoreKeys<T>>;
|
|
1034
1117
|
|
|
1118
|
+
declare type Plugin_2 = NewPlugin | OldPlugin;
|
|
1119
|
+
|
|
1120
|
+
declare type PluginOptions = {
|
|
1121
|
+
edgeSpacing: string;
|
|
1122
|
+
min: boolean;
|
|
1123
|
+
spacing: string;
|
|
1124
|
+
};
|
|
1125
|
+
|
|
1126
|
+
declare type Plugins = Array<Plugin_2>;
|
|
1127
|
+
|
|
1128
|
+
declare const plugins: {
|
|
1129
|
+
AsymmetricMatcher: NewPlugin;
|
|
1130
|
+
ConvertAnsi: NewPlugin;
|
|
1131
|
+
DOMCollection: NewPlugin;
|
|
1132
|
+
DOMElement: NewPlugin;
|
|
1133
|
+
Immutable: NewPlugin;
|
|
1134
|
+
ReactElement: NewPlugin;
|
|
1135
|
+
ReactTestComponent: NewPlugin;
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1035
1138
|
export declare function prettyDOM(
|
|
1036
1139
|
dom?: Element | HTMLDocument,
|
|
1037
1140
|
maxLength?: number,
|
|
@@ -1046,8 +1149,48 @@ export declare interface PrettyDOMOptions extends prettyFormat.OptionsReceived {
|
|
|
1046
1149
|
filterNode?: (node: Node) => boolean
|
|
1047
1150
|
}
|
|
1048
1151
|
|
|
1152
|
+
declare namespace prettyFormat {
|
|
1153
|
+
export {
|
|
1154
|
+
format,
|
|
1155
|
+
Colors,
|
|
1156
|
+
CompareKeys,
|
|
1157
|
+
Config_2 as Config,
|
|
1158
|
+
Options,
|
|
1159
|
+
OptionsReceived,
|
|
1160
|
+
OldPlugin,
|
|
1161
|
+
NewPlugin,
|
|
1162
|
+
Plugin_2 as Plugin,
|
|
1163
|
+
Plugins,
|
|
1164
|
+
PrettyFormatOptions,
|
|
1165
|
+
Printer,
|
|
1166
|
+
Refs,
|
|
1167
|
+
Theme,
|
|
1168
|
+
DEFAULT_OPTIONS,
|
|
1169
|
+
plugins,
|
|
1170
|
+
format as default
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1049
1173
|
export { prettyFormat }
|
|
1050
1174
|
|
|
1175
|
+
declare interface PrettyFormatOptions {
|
|
1176
|
+
callToJSON?: boolean;
|
|
1177
|
+
compareKeys?: CompareKeys;
|
|
1178
|
+
escapeRegex?: boolean;
|
|
1179
|
+
escapeString?: boolean;
|
|
1180
|
+
highlight?: boolean;
|
|
1181
|
+
indent?: number;
|
|
1182
|
+
maxDepth?: number;
|
|
1183
|
+
min?: boolean;
|
|
1184
|
+
plugins?: Plugins;
|
|
1185
|
+
printBasicPrototype?: boolean;
|
|
1186
|
+
printFunctionName?: boolean;
|
|
1187
|
+
theme?: ThemeReceived;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
declare type Print = (arg0: unknown) => string;
|
|
1191
|
+
|
|
1192
|
+
declare type Printer = (val: unknown, config: Config_2, indentation: string, depth: number, refs: Refs, hasCalledToJSON?: boolean) => string;
|
|
1193
|
+
|
|
1051
1194
|
export declare interface Queries {
|
|
1052
1195
|
[T: string]: Query
|
|
1053
1196
|
}
|
|
@@ -1267,6 +1410,8 @@ export declare interface QueryOptions {
|
|
|
1267
1410
|
[key: string]: RegExp | boolean
|
|
1268
1411
|
}
|
|
1269
1412
|
|
|
1413
|
+
declare type Refs = Array<unknown>;
|
|
1414
|
+
|
|
1270
1415
|
/**
|
|
1271
1416
|
* Render into the page. It should be used with cleanup.
|
|
1272
1417
|
*
|
|
@@ -1531,6 +1676,24 @@ export declare interface Suggestion {
|
|
|
1531
1676
|
toString(): string
|
|
1532
1677
|
}
|
|
1533
1678
|
|
|
1679
|
+
declare type Test = (arg0: any) => boolean;
|
|
1680
|
+
|
|
1681
|
+
declare type Theme = {
|
|
1682
|
+
comment: string;
|
|
1683
|
+
content: string;
|
|
1684
|
+
prop: string;
|
|
1685
|
+
tag: string;
|
|
1686
|
+
value: string;
|
|
1687
|
+
};
|
|
1688
|
+
|
|
1689
|
+
declare type ThemeReceived = {
|
|
1690
|
+
comment?: string;
|
|
1691
|
+
content?: string;
|
|
1692
|
+
prop?: string;
|
|
1693
|
+
tag?: string;
|
|
1694
|
+
value?: string;
|
|
1695
|
+
};
|
|
1696
|
+
|
|
1534
1697
|
export declare type Variant =
|
|
1535
1698
|
| 'find'
|
|
1536
1699
|
| 'findAll'
|
|
@@ -23,6 +23,15 @@ function testingLibraryPlugin(options) {
|
|
|
23
23
|
const runtimeOSSAlias = generateAlias(runtimeOSSPkgName, runtimeOSSDir, runtimeDir);
|
|
24
24
|
let runtimeAlias = [];
|
|
25
25
|
if (runtimePkgName !== runtimeOSSPkgName) runtimeAlias = generateAlias(runtimePkgName, runtimeDir, vitest_dirname);
|
|
26
|
+
const workletRuntimeInitAliases = [
|
|
27
|
+
...new Set([
|
|
28
|
+
runtimeOSSPkgName,
|
|
29
|
+
runtimePkgName
|
|
30
|
+
])
|
|
31
|
+
].map((pkgName)=>({
|
|
32
|
+
find: new RegExp('^' + pkgName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '/worklet-runtime/init$'),
|
|
33
|
+
replacement: vitest_require.resolve('../setupFiles/common/worklet-runtime-init.js')
|
|
34
|
+
}));
|
|
26
35
|
const preactAlias = generateAlias('preact', preactDir, runtimeOSSDir);
|
|
27
36
|
preactAlias.forEach((alias)=>{
|
|
28
37
|
alias.replacement = alias.replacement.replace(/\.js$/, '.mjs');
|
|
@@ -230,6 +239,7 @@ function testingLibraryPlugin(options) {
|
|
|
230
239
|
vitest_require.resolve('../setupFiles/vitest')
|
|
231
240
|
],
|
|
232
241
|
alias: [
|
|
242
|
+
...workletRuntimeInitAliases,
|
|
233
243
|
...runtimeOSSAlias,
|
|
234
244
|
...runtimeAlias,
|
|
235
245
|
...preactAlias,
|
|
@@ -5,6 +5,20 @@ const rstest_config_require = createRequire(import.meta.url);
|
|
|
5
5
|
function createDefaultRstestConfig() {
|
|
6
6
|
return {
|
|
7
7
|
testEnvironment: 'jsdom',
|
|
8
|
+
plugins: [
|
|
9
|
+
{
|
|
10
|
+
name: 'lynx:testing-runtime-init',
|
|
11
|
+
pre: [
|
|
12
|
+
'lynx:react',
|
|
13
|
+
'lynx:react-alias'
|
|
14
|
+
],
|
|
15
|
+
setup (api) {
|
|
16
|
+
api.modifyBundlerChain((chain)=>{
|
|
17
|
+
chain.resolve.alias.set('@lynx-js/react/worklet-runtime/init$', rstest_config_require.resolve('./setupFiles/common/worklet-runtime-init.js'));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
],
|
|
8
22
|
setupFiles: [
|
|
9
23
|
rstest_config_require.resolve('./setupFiles/rstest')
|
|
10
24
|
],
|
|
@@ -75,6 +89,7 @@ function withLynxConfig(options) {
|
|
|
75
89
|
...defaultConfig,
|
|
76
90
|
plugins: [
|
|
77
91
|
...rstestConfig.plugins || [],
|
|
92
|
+
...defaultConfig.plugins || [],
|
|
78
93
|
{
|
|
79
94
|
name: 'lynx-adapter:remove-useless-plugins',
|
|
80
95
|
remove: [
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const isBackground = !__MAIN_THREAD__;
|
|
2
|
+
globalThis.lynxTestingEnv.switchToMainThread();
|
|
3
|
+
try {
|
|
4
|
+
if (void 0 === globalThis.lynxWorkletImpl) globalThis.onInitWorkletRuntime();
|
|
5
|
+
} finally{
|
|
6
|
+
if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
7
|
+
}
|
|
8
|
+
function registerWorklet(type, id, worklet) {
|
|
9
|
+
globalThis.registerWorkletInternal(type, id, worklet);
|
|
10
|
+
}
|
|
11
|
+
export { registerWorklet };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
1
2
|
import { defineConfig } from '@rstest/core';
|
|
2
3
|
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';
|
|
3
4
|
import { withDefaultConfig } from './src/rstest-config.ts';
|
|
4
5
|
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
|
|
5
8
|
export default defineConfig({
|
|
6
9
|
extends: withDefaultConfig({
|
|
7
10
|
modifyRstestConfig(config) {
|
|
@@ -53,7 +53,7 @@ describe('lynx global API', () => {
|
|
|
53
53
|
const reportErrorCalls = lynxTestingEnv.backgroundThread.lynx.reportError.mock.calls;
|
|
54
54
|
|
|
55
55
|
expect(() => render(<view />)).toThrowErrorMatchingInlineSnapshot(
|
|
56
|
-
`[Error: snapshotPatchApply failed: ctx not found, snapshot type: 'null'. You can set environment variable \`REACT_ALOG=true\` and restart your dev server for troubleshooting.]`,
|
|
56
|
+
`[Error: snapshotPatchApply failed: ctx not found, snapshot type: 'null', parent: { id: 10000000000, snapshot type: 'null', missing: true }, child: { id: 10000000000, snapshot type: 'null', missing: true }, operation: 'InsertBefore', commitId: 2, isHydration: true. You can set environment variable \`REACT_ALOG=true\` and restart your dev server for troubleshooting.]`,
|
|
57
57
|
);
|
|
58
58
|
|
|
59
59
|
const snapshotPatch = JSON.parse(callLepusMethodCalls[0][1]['data']).patchList[0].snapshotPatch;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { createRsbuild } from '@rsbuild/core';
|
|
1
4
|
import { describe, expect, it } from 'vitest';
|
|
2
5
|
|
|
3
|
-
import { isRspeedyProject } from '../rstest-config.js';
|
|
6
|
+
import { isRspeedyProject, withDefaultConfig } from '../rstest-config.js';
|
|
4
7
|
|
|
5
8
|
const hasLynxConfig = (path) => path.endsWith('lynx.config.ts');
|
|
6
9
|
const hasNothing = () => false;
|
|
@@ -29,3 +32,33 @@ describe('isRspeedyProject', () => {
|
|
|
29
32
|
expect(isRspeedyProject(undefined, hasNothing)).toBe(false);
|
|
30
33
|
});
|
|
31
34
|
});
|
|
35
|
+
|
|
36
|
+
describe('testing runtime init ordering', () => {
|
|
37
|
+
it.each(['lynx:react', 'lynx:react-alias'])(
|
|
38
|
+
'preserves the testing init alias when defaults precede %s',
|
|
39
|
+
async (name) => {
|
|
40
|
+
const defaults = await withDefaultConfig()({});
|
|
41
|
+
const rsbuild = await createRsbuild({
|
|
42
|
+
rsbuildConfig: {
|
|
43
|
+
plugins: [
|
|
44
|
+
...defaults.plugins,
|
|
45
|
+
{
|
|
46
|
+
name,
|
|
47
|
+
setup(api) {
|
|
48
|
+
api.modifyBundlerChain(chain => {
|
|
49
|
+
chain.resolve.alias.set(
|
|
50
|
+
'@lynx-js/react/worklet-runtime/init$',
|
|
51
|
+
'/production-runtime.js',
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const [config] = await rsbuild.initConfigs();
|
|
60
|
+
expect(config.resolve.alias['@lynx-js/react/worklet-runtime/init$'])
|
|
61
|
+
.toContain(join('setupFiles', 'common', 'worklet-runtime-init.js'));
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
});
|
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
import { describe, expect, vi } from 'vitest';
|
|
2
2
|
import { fireEvent, render, waitSchedule } from '..';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
Component,
|
|
5
|
+
defineMainThreadObjectType,
|
|
6
|
+
runOnBackground,
|
|
7
|
+
runOnMainThread,
|
|
8
|
+
useMainThreadObject,
|
|
9
|
+
useMainThreadRef,
|
|
10
|
+
} from '@lynx-js/react';
|
|
11
|
+
|
|
12
|
+
const guardedClassCaptureType = defineMainThreadObjectType({
|
|
13
|
+
type: '@test/guarded-class-capture',
|
|
14
|
+
create: initialValue => ({
|
|
15
|
+
get: () => initialValue,
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
|
|
4
19
|
describe('worklet', () => {
|
|
20
|
+
it('resolves the registration owner when a MIXED module imports the init entry on BTS', async () => {
|
|
21
|
+
expect(__MAIN_THREAD__).toBe(false);
|
|
22
|
+
const { registerWorklet } = await import('@lynx-js/react/worklet-runtime/init');
|
|
23
|
+
expect(__MAIN_THREAD__).toBe(false);
|
|
24
|
+
|
|
25
|
+
const owner = vi.spyOn(globalThis, 'registerWorkletInternal');
|
|
26
|
+
const worklet = vi.fn(() => 42);
|
|
27
|
+
try {
|
|
28
|
+
registerWorklet('main-thread', 'mixed-init-entry', worklet);
|
|
29
|
+
expect(owner).toHaveBeenCalledWith('main-thread', 'mixed-init-entry', worklet);
|
|
30
|
+
expect(globalThis.lynxWorkletImpl._workletMap['mixed-init-entry']).toBe(worklet);
|
|
31
|
+
} finally {
|
|
32
|
+
owner.mockRestore();
|
|
33
|
+
delete globalThis.lynxWorkletImpl._workletMap['mixed-init-entry'];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
5
37
|
it('main-thread script should work', async () => {
|
|
6
38
|
const cb = vi.fn();
|
|
7
39
|
const Comp = () => {
|
|
@@ -47,9 +79,8 @@ describe('worklet', () => {
|
|
|
47
79
|
`);
|
|
48
80
|
});
|
|
49
81
|
it('main-thread script should not throw when enable background thread', async () => {
|
|
50
|
-
vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
51
|
-
|
|
52
|
-
expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
|
|
82
|
+
const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
83
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
|
|
53
84
|
|
|
54
85
|
globalThis.cb = vi.fn();
|
|
55
86
|
const mainThreadFn = () => {
|
|
@@ -72,7 +103,7 @@ describe('worklet', () => {
|
|
|
72
103
|
enableBackgroundThread: true,
|
|
73
104
|
});
|
|
74
105
|
|
|
75
|
-
expect(
|
|
106
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`
|
|
76
107
|
[
|
|
77
108
|
[
|
|
78
109
|
"rLynxChange",
|
|
@@ -115,9 +146,8 @@ describe('worklet', () => {
|
|
|
115
146
|
vi.resetAllMocks();
|
|
116
147
|
});
|
|
117
148
|
it('main-thread script should not update MTS function when enable background', async () => {
|
|
118
|
-
vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
119
|
-
|
|
120
|
-
expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
|
|
149
|
+
const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
150
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
|
|
121
151
|
|
|
122
152
|
globalThis.cb = vi.fn();
|
|
123
153
|
const mainThreadFn = (e) => {
|
|
@@ -154,7 +184,7 @@ describe('worklet', () => {
|
|
|
154
184
|
enableBackgroundThread: true,
|
|
155
185
|
});
|
|
156
186
|
|
|
157
|
-
expect(
|
|
187
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`
|
|
158
188
|
[
|
|
159
189
|
[
|
|
160
190
|
"rLynxChange",
|
|
@@ -205,9 +235,8 @@ describe('worklet', () => {
|
|
|
205
235
|
});
|
|
206
236
|
|
|
207
237
|
it('main thread script props', () => {
|
|
208
|
-
vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
209
|
-
|
|
210
|
-
expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
|
|
238
|
+
const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
239
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
|
|
211
240
|
|
|
212
241
|
globalThis.cb = vi.fn();
|
|
213
242
|
const mainThreadFn = (e) => {
|
|
@@ -244,7 +273,7 @@ describe('worklet', () => {
|
|
|
244
273
|
</page>
|
|
245
274
|
`);
|
|
246
275
|
|
|
247
|
-
expect(
|
|
276
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`
|
|
248
277
|
[
|
|
249
278
|
[
|
|
250
279
|
"rLynxChange",
|
|
@@ -280,9 +309,8 @@ describe('worklet', () => {
|
|
|
280
309
|
});
|
|
281
310
|
|
|
282
311
|
it('runOnMainThread works', async () => {
|
|
283
|
-
vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
284
|
-
|
|
285
|
-
expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
|
|
312
|
+
const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
313
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
|
|
286
314
|
const Comp = () => {
|
|
287
315
|
return (
|
|
288
316
|
<view
|
|
@@ -311,9 +339,8 @@ describe('worklet', () => {
|
|
|
311
339
|
});
|
|
312
340
|
|
|
313
341
|
it('runOnBackground works', async () => {
|
|
314
|
-
vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
315
|
-
|
|
316
|
-
expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
|
|
342
|
+
const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
343
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
|
|
317
344
|
|
|
318
345
|
const cb = vi.fn();
|
|
319
346
|
globalThis.receiveRunOnBackgroundResp = vi.fn();
|
|
@@ -338,7 +365,7 @@ describe('worklet', () => {
|
|
|
338
365
|
enableMainThread: true,
|
|
339
366
|
enableBackgroundThread: true,
|
|
340
367
|
});
|
|
341
|
-
expect(
|
|
368
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`
|
|
342
369
|
[
|
|
343
370
|
[
|
|
344
371
|
"rLynxChange",
|
|
@@ -393,9 +420,8 @@ describe('worklet', () => {
|
|
|
393
420
|
});
|
|
394
421
|
|
|
395
422
|
it('worklet ref should work', async () => {
|
|
396
|
-
vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
397
|
-
|
|
398
|
-
expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
|
|
423
|
+
const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
424
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
|
|
399
425
|
globalThis.cb = vi.fn();
|
|
400
426
|
const Comp = () => {
|
|
401
427
|
const ref = useMainThreadRef(null);
|
|
@@ -436,7 +462,7 @@ describe('worklet', () => {
|
|
|
436
462
|
</view>
|
|
437
463
|
</page>
|
|
438
464
|
`);
|
|
439
|
-
expect(
|
|
465
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`
|
|
440
466
|
[
|
|
441
467
|
[
|
|
442
468
|
"rLynxChangeRefInitValue",
|
|
@@ -478,9 +504,8 @@ describe('worklet', () => {
|
|
|
478
504
|
});
|
|
479
505
|
|
|
480
506
|
it('nest runOnMainThread->runOnBackground works', async () => {
|
|
481
|
-
vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
482
|
-
|
|
483
|
-
expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
|
|
507
|
+
const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
508
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
|
|
484
509
|
const Comp = () => {
|
|
485
510
|
return (
|
|
486
511
|
<view
|
|
@@ -553,9 +578,8 @@ describe('worklet', () => {
|
|
|
553
578
|
});
|
|
554
579
|
|
|
555
580
|
it('multiple main-thread worklets should work together when background thread is enabled', () => {
|
|
556
|
-
vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
557
|
-
|
|
558
|
-
expect(callLepusMethodCalls).toMatchInlineSnapshot(`[]`);
|
|
581
|
+
const callLepusMethod = vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
|
|
582
|
+
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
|
|
559
583
|
|
|
560
584
|
globalThis.firstCb = vi.fn();
|
|
561
585
|
globalThis.secondCb = vi.fn();
|
|
@@ -588,10 +612,10 @@ describe('worklet', () => {
|
|
|
588
612
|
enableBackgroundThread: true,
|
|
589
613
|
});
|
|
590
614
|
|
|
591
|
-
expect(
|
|
592
|
-
expect(
|
|
615
|
+
expect(callLepusMethod.mock.calls).toHaveLength(1);
|
|
616
|
+
expect(callLepusMethod.mock.calls[0][0]).toBe('rLynxChange');
|
|
593
617
|
|
|
594
|
-
const patchData = JSON.parse(
|
|
618
|
+
const patchData = JSON.parse(callLepusMethod.mock.calls[0][1].data);
|
|
595
619
|
const workletIds = patchData.patchList
|
|
596
620
|
.flatMap(item => Array.isArray(item.snapshotPatch) ? item.snapshotPatch : [])
|
|
597
621
|
.filter(item => typeof item === 'object' && item !== null && '_wkltId' in item)
|
|
@@ -615,4 +639,34 @@ describe('worklet', () => {
|
|
|
615
639
|
expect(globalThis.secondCb).toBeCalledWith('second-key');
|
|
616
640
|
vi.resetAllMocks();
|
|
617
641
|
});
|
|
642
|
+
|
|
643
|
+
it('preserves a guarded main-thread object captured from a class field', () => {
|
|
644
|
+
globalThis.classCaptureCb = vi.fn();
|
|
645
|
+
|
|
646
|
+
class ClassCapture extends Component {
|
|
647
|
+
value = this.props.value;
|
|
648
|
+
|
|
649
|
+
onTap() {
|
|
650
|
+
'main thread';
|
|
651
|
+
globalThis.classCaptureCb(this.value.get());
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
render() {
|
|
655
|
+
return <view main-thread:bindtap={this.onTap} />;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const Comp = () => {
|
|
660
|
+
const value = useMainThreadObject(guardedClassCaptureType, 42);
|
|
661
|
+
return <ClassCapture value={value} />;
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
const { container } = render(<Comp />, {
|
|
665
|
+
enableMainThread: true,
|
|
666
|
+
enableBackgroundThread: true,
|
|
667
|
+
});
|
|
668
|
+
fireEvent.tap(container.firstChild);
|
|
669
|
+
|
|
670
|
+
expect(globalThis.classCaptureCb).toHaveBeenCalledWith(42);
|
|
671
|
+
});
|
|
618
672
|
});
|
|
@@ -67,6 +67,10 @@ export function testingLibraryPlugin(
|
|
|
67
67
|
if (runtimePkgName !== runtimeOSSPkgName) {
|
|
68
68
|
runtimeAlias = generateAlias(runtimePkgName, runtimeDir, __dirname);
|
|
69
69
|
}
|
|
70
|
+
const workletRuntimeInitAliases = [...new Set([runtimeOSSPkgName, runtimePkgName])].map(pkgName => ({
|
|
71
|
+
find: new RegExp('^' + pkgName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '/worklet-runtime/init$'),
|
|
72
|
+
replacement: require.resolve('../setupFiles/common/worklet-runtime-init.js'),
|
|
73
|
+
}));
|
|
70
74
|
const preactAlias = generateAlias('preact', preactDir, runtimeOSSDir);
|
|
71
75
|
preactAlias.forEach((alias) => {
|
|
72
76
|
alias.replacement = alias.replacement.replace(/\.js$/, '.mjs');
|
|
@@ -314,7 +318,7 @@ export function testingLibraryPlugin(
|
|
|
314
318
|
setupFiles: [
|
|
315
319
|
require.resolve('../setupFiles/vitest'),
|
|
316
320
|
],
|
|
317
|
-
alias: [...runtimeOSSAlias, ...runtimeAlias, ...preactAlias, ...reactAlias],
|
|
321
|
+
alias: [...workletRuntimeInitAliases, ...runtimeOSSAlias, ...runtimeAlias, ...preactAlias, ...reactAlias],
|
|
318
322
|
// Force any module that touches `preact` (or its forks like
|
|
319
323
|
// `@lynx-js/internal-preact`, `@lynx-js/react-signals`) through Vite's
|
|
320
324
|
// transform pipeline so the aliases above can redirect every
|
|
@@ -2,7 +2,7 @@ import type { ExtendConfig, ExtendConfigFn } from '@rstest/core';
|
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import type { RsbuildConfig } from '@rsbuild/core';
|
|
5
|
+
import type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core';
|
|
6
6
|
|
|
7
7
|
export interface LynxConfigOptions {
|
|
8
8
|
/**
|
|
@@ -43,6 +43,21 @@ const require = createRequire(import.meta.url);
|
|
|
43
43
|
function createDefaultRstestConfig(): ExtendConfig {
|
|
44
44
|
return {
|
|
45
45
|
testEnvironment: 'jsdom',
|
|
46
|
+
plugins: [
|
|
47
|
+
{
|
|
48
|
+
name: 'lynx:testing-runtime-init',
|
|
49
|
+
// Integrations can embed the alias plugin inside a React wrapper.
|
|
50
|
+
pre: ['lynx:react', 'lynx:react-alias'],
|
|
51
|
+
setup(api) {
|
|
52
|
+
api.modifyBundlerChain(chain => {
|
|
53
|
+
chain.resolve.alias.set(
|
|
54
|
+
'@lynx-js/react/worklet-runtime/init$',
|
|
55
|
+
require.resolve('./setupFiles/common/worklet-runtime-init.js'),
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
} satisfies RsbuildPlugin,
|
|
60
|
+
],
|
|
46
61
|
setupFiles: [require.resolve('./setupFiles/rstest')],
|
|
47
62
|
globals: true,
|
|
48
63
|
};
|
|
@@ -153,6 +168,7 @@ export function withLynxConfig(
|
|
|
153
168
|
...defaultConfig,
|
|
154
169
|
plugins: [
|
|
155
170
|
...(rstestConfig.plugins || []),
|
|
171
|
+
...(defaultConfig.plugins || []),
|
|
156
172
|
{
|
|
157
173
|
name: 'lynx-adapter:remove-useless-plugins',
|
|
158
174
|
// `lynx:rsbuild:target` builds for Lynx, but the tests run in jsdom
|