@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
|
@@ -2,24 +2,44 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { Element } from './api/element.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
MainThreadRefInitValuePatch,
|
|
7
|
+
Worklet,
|
|
8
|
+
WorkletRef,
|
|
9
|
+
WorkletRefId,
|
|
10
|
+
WorkletRefImpl,
|
|
11
|
+
} from './bindings/types.js';
|
|
12
|
+
import {
|
|
13
|
+
assertCompatibleMainThreadObject,
|
|
14
|
+
createMainThreadObject,
|
|
15
|
+
initMainThreadObjects,
|
|
16
|
+
isRealizedMainThreadObject,
|
|
17
|
+
registerMainThreadObjectType,
|
|
18
|
+
} from './mainThreadObject.js';
|
|
19
|
+
import type { MainThreadObjectFactory } from './mainThreadObject.js';
|
|
6
20
|
import { mainThreadFlushLoopMark } from './utils/mainThreadFlushLoopGuard.js';
|
|
7
21
|
import { profile } from './utils/profile.js';
|
|
8
22
|
|
|
9
23
|
interface RefImpl {
|
|
10
|
-
_workletRefMap: Record<WorkletRefId,
|
|
11
|
-
_firstScreenWorkletRefMap: Record<WorkletRefId,
|
|
24
|
+
_workletRefMap: Record<WorkletRefId, object>;
|
|
25
|
+
_firstScreenWorkletRefMap: Record<WorkletRefId, object>;
|
|
12
26
|
updateWorkletRef(
|
|
13
27
|
refImpl: WorkletRefImpl<Element | null>,
|
|
14
28
|
element: ElementNode | null,
|
|
15
29
|
): void;
|
|
16
|
-
updateWorkletRefInitValueChanges(
|
|
30
|
+
updateWorkletRefInitValueChanges(
|
|
31
|
+
patch: MainThreadRefInitValuePatch,
|
|
32
|
+
): void;
|
|
33
|
+
registerMainThreadObjectType(
|
|
34
|
+
type: string,
|
|
35
|
+
create: MainThreadObjectFactory | Worklet,
|
|
36
|
+
): void;
|
|
17
37
|
clearFirstScreenWorkletRefMap(): void;
|
|
18
38
|
}
|
|
19
39
|
|
|
20
40
|
let impl: RefImpl | undefined;
|
|
21
|
-
|
|
22
41
|
function initWorkletRef(): RefImpl {
|
|
42
|
+
initMainThreadObjects();
|
|
23
43
|
return (impl = {
|
|
24
44
|
_workletRefMap: {},
|
|
25
45
|
/**
|
|
@@ -31,6 +51,7 @@ function initWorkletRef(): RefImpl {
|
|
|
31
51
|
_firstScreenWorkletRefMap: {},
|
|
32
52
|
updateWorkletRef,
|
|
33
53
|
updateWorkletRefInitValueChanges,
|
|
54
|
+
registerMainThreadObjectType,
|
|
34
55
|
clearFirstScreenWorkletRefMap,
|
|
35
56
|
});
|
|
36
57
|
}
|
|
@@ -39,15 +60,64 @@ const createWorkletRef = <T>(
|
|
|
39
60
|
id: WorkletRefId,
|
|
40
61
|
value: T,
|
|
41
62
|
): WorkletRef<T> => {
|
|
42
|
-
|
|
63
|
+
const ref = {
|
|
43
64
|
current: value,
|
|
44
65
|
_wvid: id,
|
|
45
66
|
};
|
|
67
|
+
return ref;
|
|
46
68
|
};
|
|
47
69
|
|
|
48
|
-
|
|
49
|
-
refImpl
|
|
50
|
-
|
|
70
|
+
function createWorkletValue(refImpl: WorkletRefImpl<unknown>): object {
|
|
71
|
+
return !refImpl._type || refImpl._type === 'main-thread'
|
|
72
|
+
? createWorkletRef(refImpl._wvid, refImpl._initValue)
|
|
73
|
+
: createMainThreadObject(refImpl);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function isMutableCell(value: unknown): value is WorkletRef<unknown> {
|
|
77
|
+
return typeof value === 'object' && value !== null
|
|
78
|
+
&& typeof (value as Partial<WorkletRef<unknown>>)._wvid === 'number'
|
|
79
|
+
&& Object.prototype.hasOwnProperty.call(value, 'current');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function isHydratedWorkletValue(value: unknown): value is object {
|
|
83
|
+
return typeof value === 'object' && value !== null
|
|
84
|
+
&& (isRealizedMainThreadObject(value) || isMutableCell(value));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function assertCompatibleWorkletValue(
|
|
88
|
+
handle: WorkletRefImpl<unknown>,
|
|
89
|
+
value: object,
|
|
90
|
+
operation: 'hydration' | 'initialization patch',
|
|
91
|
+
): void {
|
|
92
|
+
let actualKind: 'typed-object' | 'mutable-cell' | undefined;
|
|
93
|
+
if (isRealizedMainThreadObject(value)) {
|
|
94
|
+
actualKind = 'typed-object';
|
|
95
|
+
} else if (isMutableCell(value)) {
|
|
96
|
+
actualKind = 'mutable-cell';
|
|
97
|
+
}
|
|
98
|
+
if (!actualKind) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`Cannot apply MainThreadObject ${operation} for handle ${handle._wvid}: the existing target has no worklet-value metadata.`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const expectedType = handle._type;
|
|
105
|
+
const expectedKind = !expectedType || expectedType === 'main-thread'
|
|
106
|
+
? 'mutable-cell'
|
|
107
|
+
: 'typed-object';
|
|
108
|
+
if (actualKind !== expectedKind) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`Worklet value kind mismatch during ${operation} for handle ${handle._wvid}: background handle expects ${expectedKind}, but the main-thread target is ${actualKind}.`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
if (actualKind === 'typed-object') {
|
|
114
|
+
assertCompatibleMainThreadObject(handle, value, operation);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const getFromWorkletRefMap = (
|
|
119
|
+
refImpl: WorkletRefImpl<unknown>,
|
|
120
|
+
): object | undefined => {
|
|
51
121
|
const id = refImpl._wvid;
|
|
52
122
|
/* v8 ignore next 3 */
|
|
53
123
|
if (__DEV__) {
|
|
@@ -59,12 +129,9 @@ const getFromWorkletRefMap = <T>(
|
|
|
59
129
|
// Might be called in two scenarios:
|
|
60
130
|
// 1. In MTS events
|
|
61
131
|
// 2. In `main-thread:ref`
|
|
62
|
-
value = impl!._firstScreenWorkletRefMap[id]
|
|
63
|
-
if (!value) {
|
|
64
|
-
value = impl!._firstScreenWorkletRefMap[id] = createWorkletRef(id, refImpl._initValue);
|
|
65
|
-
}
|
|
132
|
+
value = impl!._firstScreenWorkletRefMap[id] ??= createWorkletValue(refImpl);
|
|
66
133
|
} else {
|
|
67
|
-
value = impl!._workletRefMap[id]
|
|
134
|
+
value = impl!._workletRefMap[id];
|
|
68
135
|
}
|
|
69
136
|
|
|
70
137
|
/* v8 ignore next 3 */
|
|
@@ -78,6 +145,14 @@ function removeValueFromWorkletRefMap(id: WorkletRefId): void {
|
|
|
78
145
|
delete impl!._workletRefMap[id];
|
|
79
146
|
}
|
|
80
147
|
|
|
148
|
+
function hydrateWorkletValue(
|
|
149
|
+
handle: WorkletRefImpl<unknown>,
|
|
150
|
+
value: object,
|
|
151
|
+
): void {
|
|
152
|
+
assertCompatibleWorkletValue(handle, value, 'hydration');
|
|
153
|
+
impl!._workletRefMap[handle._wvid] = value;
|
|
154
|
+
}
|
|
155
|
+
|
|
81
156
|
/**
|
|
82
157
|
* Create an element instance of the given element node, then set the worklet value to it.
|
|
83
158
|
* This is called in `snapshotContextUpdateWorkletRef`.
|
|
@@ -88,20 +163,44 @@ function updateWorkletRef(
|
|
|
88
163
|
handle: WorkletRefImpl<Element | null>,
|
|
89
164
|
element: ElementNode | null,
|
|
90
165
|
): void {
|
|
91
|
-
getFromWorkletRefMap(handle).current = element
|
|
166
|
+
(getFromWorkletRefMap(handle) as WorkletRef<Element | null>).current = element
|
|
92
167
|
? new Element(element)
|
|
93
168
|
: null;
|
|
94
169
|
}
|
|
95
170
|
|
|
96
171
|
function updateWorkletRefInitValueChanges(
|
|
97
|
-
patch:
|
|
172
|
+
patch: MainThreadRefInitValuePatch,
|
|
98
173
|
): void {
|
|
99
174
|
profile('updateWorkletRefInitValueChanges', () => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
175
|
+
let firstError: unknown;
|
|
176
|
+
let hasError = false;
|
|
177
|
+
patch.forEach(([id, value, type]) => {
|
|
178
|
+
try {
|
|
179
|
+
const handle = {
|
|
180
|
+
_wvid: id,
|
|
181
|
+
_initValue: value,
|
|
182
|
+
_type: type,
|
|
183
|
+
} as WorkletRefImpl<unknown>;
|
|
184
|
+
const existing = impl!._workletRefMap[id];
|
|
185
|
+
if (existing) {
|
|
186
|
+
assertCompatibleWorkletValue(
|
|
187
|
+
handle,
|
|
188
|
+
existing,
|
|
189
|
+
'initialization patch',
|
|
190
|
+
);
|
|
191
|
+
} else {
|
|
192
|
+
impl!._workletRefMap[id] = createWorkletValue(handle);
|
|
193
|
+
}
|
|
194
|
+
} catch (error) {
|
|
195
|
+
if (!hasError) {
|
|
196
|
+
firstError = error;
|
|
197
|
+
hasError = true;
|
|
198
|
+
}
|
|
103
199
|
}
|
|
104
200
|
});
|
|
201
|
+
if (hasError) {
|
|
202
|
+
throw firstError;
|
|
203
|
+
}
|
|
105
204
|
});
|
|
106
205
|
}
|
|
107
206
|
|
|
@@ -115,5 +214,7 @@ export {
|
|
|
115
214
|
initWorkletRef,
|
|
116
215
|
getFromWorkletRefMap,
|
|
117
216
|
removeValueFromWorkletRefMap,
|
|
217
|
+
hydrateWorkletValue,
|
|
218
|
+
isHydratedWorkletValue,
|
|
118
219
|
updateWorkletRefInitValueChanges,
|
|
119
220
|
};
|
|
@@ -10,6 +10,7 @@ import { initEomImpl } from './eomImpl.js';
|
|
|
10
10
|
import { addEventMethodsIfNeeded } from './eventPropagation.js';
|
|
11
11
|
import { hydrateCtx } from './hydrate.js';
|
|
12
12
|
import { JsFunctionLifecycleManager, isRunOnBackgroundEnabled } from './jsFunctionLifecycle.js';
|
|
13
|
+
import { isRealizedMainThreadObject } from './mainThreadObject.js';
|
|
13
14
|
import { runRunOnMainThreadTask } from './runOnMainThread.js';
|
|
14
15
|
import { mainThreadFlushLoopMark } from './utils/mainThreadFlushLoopGuard.js';
|
|
15
16
|
import { profile } from './utils/profile.js';
|
|
@@ -129,8 +130,7 @@ function transformWorklet(
|
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
const worklet = { main: ctx };
|
|
133
|
-
transformWorkletInner(worklet, 0, ctx);
|
|
133
|
+
const worklet = transformWorkletInner({ main: ctx }, 0, ctx) as { main: ClosureValueType };
|
|
134
134
|
|
|
135
135
|
if (isWorklet) {
|
|
136
136
|
workletCache.set(ctx, worklet.main);
|
|
@@ -143,16 +143,16 @@ const transformWorkletInner = (
|
|
|
143
143
|
value: ClosureValueType,
|
|
144
144
|
depth: number,
|
|
145
145
|
ctx: unknown,
|
|
146
|
-
) => {
|
|
146
|
+
): ClosureValueType => {
|
|
147
147
|
const limit = 1000;
|
|
148
148
|
if (++depth >= limit) {
|
|
149
149
|
throw new Error('Depth of value exceeds limit of ' + limit + '.');
|
|
150
150
|
}
|
|
151
151
|
/* v8 ignore next 3 */
|
|
152
152
|
if (typeof value !== 'object' || value === null) {
|
|
153
|
-
return;
|
|
153
|
+
return value;
|
|
154
154
|
}
|
|
155
|
-
|
|
155
|
+
let obj = value as Record<string, ClosureValueType>;
|
|
156
156
|
|
|
157
157
|
for (const key in obj) {
|
|
158
158
|
const subObj: ClosureValueType = obj[key];
|
|
@@ -160,14 +160,26 @@ const transformWorkletInner = (
|
|
|
160
160
|
continue;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
// A MainThreadObject initialization payload is user data. Resolve the
|
|
164
|
+
// typed descriptor before walking it so payload properties that resemble
|
|
165
|
+
// worklet metadata remain untouched. Legacy MainThreadRef descriptors retain
|
|
166
|
+
// the existing recursive path.
|
|
167
|
+
if (isRealizedMainThreadObject(subObj)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (isMainThreadObjectDescriptor(subObj)) {
|
|
171
|
+
obj = replaceCapturedProperty(obj, value, key, getFromWorkletRefMap(subObj));
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
|
|
163
175
|
if (/** isEventTarget */ 'elementRefptr' in subObj) {
|
|
164
|
-
obj[key] = new Element(subObj
|
|
176
|
+
obj[key] = new Element(subObj.elementRefptr as ElementNode);
|
|
165
177
|
continue;
|
|
166
178
|
} else if (subObj instanceof Element) {
|
|
167
179
|
continue;
|
|
168
180
|
}
|
|
169
181
|
|
|
170
|
-
transformWorkletInner(subObj, depth, ctx)
|
|
182
|
+
const transformedSubObj = transformWorkletInner(subObj, depth, ctx) as Record<string, ClosureValueType>;
|
|
171
183
|
|
|
172
184
|
const isWorkletRef = '_wvid' in (subObj as object);
|
|
173
185
|
if (isWorkletRef) {
|
|
@@ -179,21 +191,29 @@ const transformWorkletInner = (
|
|
|
179
191
|
const isWorklet = '_wkltId' in subObj;
|
|
180
192
|
if (isWorklet) {
|
|
181
193
|
const isRootWorklet = subObj === ctx;
|
|
182
|
-
const boundCtx = { ...
|
|
194
|
+
const boundCtx = { ...transformedSubObj };
|
|
183
195
|
// Keep the original context collectible. PrimJS traces WeakMap values even
|
|
184
196
|
// when their keys are otherwise unreachable, so the cached function must not point back to its key.
|
|
185
|
-
|
|
197
|
+
const boundWorklet: ((...args: unknown[]) => unknown) & { boundCtx?: object } = lynxWorkletImpl
|
|
198
|
+
._workletMap[(subObj as Worklet)._wkltId]!
|
|
186
199
|
.bind(boundCtx);
|
|
200
|
+
if (transformedSubObj !== subObj && obj === value && obj !== ctx) obj = copyAccessorCapture(obj);
|
|
201
|
+
obj = replaceCapturedProperty(obj, value, key, boundWorklet);
|
|
187
202
|
if (!isRootWorklet) {
|
|
188
203
|
// Hydration needs the same context that the function already owns through bind().
|
|
189
204
|
// The original nested context can disappear after its parent replaces it with this function.
|
|
190
|
-
|
|
205
|
+
boundWorklet.boundCtx = boundCtx;
|
|
191
206
|
}
|
|
192
207
|
continue;
|
|
193
208
|
}
|
|
209
|
+
if (transformedSubObj !== subObj) {
|
|
210
|
+
// The root context is runtime-owned: hydration must see its captured copy.
|
|
211
|
+
if (obj === value && obj !== ctx) obj = copyAccessorCapture(obj);
|
|
212
|
+
obj = replaceCapturedProperty(obj, value, key, transformedSubObj);
|
|
213
|
+
}
|
|
194
214
|
const isJsFn = '_jsFnId' in subObj;
|
|
195
215
|
if (isJsFn) {
|
|
196
|
-
subObj['_execId'] = (ctx as Worklet)._execId;
|
|
216
|
+
(subObj as Record<string, ClosureValueType>)['_execId'] = (ctx as Worklet)._execId;
|
|
197
217
|
lynxWorkletImpl._jsFunctionLifecycleManager?.addRef(
|
|
198
218
|
(ctx as Worklet)._execId!,
|
|
199
219
|
subObj,
|
|
@@ -201,6 +221,58 @@ const transformWorkletInner = (
|
|
|
201
221
|
continue;
|
|
202
222
|
}
|
|
203
223
|
}
|
|
224
|
+
return obj;
|
|
204
225
|
};
|
|
205
226
|
|
|
227
|
+
function replaceCapturedProperty(
|
|
228
|
+
obj: Record<string, ClosureValueType>,
|
|
229
|
+
source: object,
|
|
230
|
+
key: string,
|
|
231
|
+
value: ClosureValueType,
|
|
232
|
+
): Record<string, ClosureValueType> {
|
|
233
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
234
|
+
if (descriptor?.get) {
|
|
235
|
+
// Getters can refresh handles or method receivers. Materialize the captured
|
|
236
|
+
// value without consuming the source getter or invoking its setter.
|
|
237
|
+
const capturedDescriptor = {
|
|
238
|
+
value,
|
|
239
|
+
writable: true,
|
|
240
|
+
enumerable: descriptor.enumerable!,
|
|
241
|
+
configurable: descriptor.configurable!,
|
|
242
|
+
};
|
|
243
|
+
if (obj === source || !descriptor.configurable) {
|
|
244
|
+
// Replace before defining the copy, including non-configurable getters.
|
|
245
|
+
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
|
246
|
+
descriptors[key] = capturedDescriptor;
|
|
247
|
+
return copyAccessorCapture(obj, descriptors);
|
|
248
|
+
}
|
|
249
|
+
Object.defineProperty(obj, key, capturedDescriptor);
|
|
250
|
+
} else {
|
|
251
|
+
obj[key] = value;
|
|
252
|
+
}
|
|
253
|
+
return obj;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function copyAccessorCapture(
|
|
257
|
+
obj: Record<string, ClosureValueType>,
|
|
258
|
+
descriptors: PropertyDescriptorMap = Object.getOwnPropertyDescriptors(obj),
|
|
259
|
+
): Record<string, ClosureValueType> {
|
|
260
|
+
// Copy descriptors without evaluating getters a second time. Array ancestors
|
|
261
|
+
// retain their array identity when a nested accessor requires a captured copy.
|
|
262
|
+
return Object.defineProperties(
|
|
263
|
+
Array.isArray(obj)
|
|
264
|
+
? []
|
|
265
|
+
: Object.create(Object.getPrototypeOf(obj) as object | null) as Record<string, ClosureValueType>,
|
|
266
|
+
descriptors,
|
|
267
|
+
) as Record<string, ClosureValueType>;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function isMainThreadObjectDescriptor(
|
|
271
|
+
value: object,
|
|
272
|
+
): value is WorkletRefImpl<unknown> {
|
|
273
|
+
const descriptor = value as Partial<WorkletRefImpl<unknown>>;
|
|
274
|
+
return typeof descriptor._wvid === 'number'
|
|
275
|
+
&& typeof descriptor._type === 'string'
|
|
276
|
+
&& descriptor._type !== 'main-thread';
|
|
277
|
+
}
|
|
206
278
|
export { initWorklet };
|
package/runtime/tsconfig.json
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
"composite": true,
|
|
5
5
|
"types": ["node"],
|
|
6
6
|
"outDir": "./lib",
|
|
7
|
+
// Published maps must retain their sources because runtime/src is not shipped.
|
|
8
|
+
"inlineSources": true,
|
|
7
9
|
// Keep incremental metadata under lib so clearing generated outputs also
|
|
8
10
|
// invalidates the runtime build cache for worklet-runtime artifacts.
|
|
9
11
|
"tsBuildInfoFile": "./lib/tsconfig.tsbuildinfo",
|
package/runtime/vitest.config.ts
CHANGED
|
@@ -75,6 +75,10 @@ export default defineConfig({
|
|
|
75
75
|
},
|
|
76
76
|
{ find: /^preact\/jsx-runtime$/, replacement: path.join(internalPreactRoot, 'jsx-runtime/dist/jsxRuntime.mjs') },
|
|
77
77
|
{ find: '@lynx-js/react/compat', replacement: path.resolve(__dirname, './compat/index.js') },
|
|
78
|
+
{
|
|
79
|
+
find: '@lynx-js/react/worklet-runtime/init',
|
|
80
|
+
replacement: path.resolve(__dirname, './src/worklet-runtime/index.ts'),
|
|
81
|
+
},
|
|
78
82
|
{
|
|
79
83
|
find: '@lynx-js/react/worklet-runtime/bindings',
|
|
80
84
|
replacement: path.resolve(__dirname, './src/worklet-runtime/bindings/index.ts'),
|
|
@@ -4,24 +4,24 @@ Rslib v1.0.2
|
|
|
4
4
|
info build started...
|
|
5
5
|
start generating declaration files... (esm0)
|
|
6
6
|
start generating declaration files... (esm2)
|
|
7
|
-
ready built in 0.
|
|
8
|
-
ready built in 0.
|
|
9
|
-
ready built in
|
|
10
|
-
info declaration files prepared with tsgo in 1.
|
|
11
|
-
ready declaration files bundled successfully: dist/index.d.ts in
|
|
12
|
-
ready declaration files generated in
|
|
7
|
+
ready built in 0.68s (esm2)
|
|
8
|
+
ready built in 0.80s (esm1)
|
|
9
|
+
ready built in 1.18s (esm0)
|
|
10
|
+
info declaration files prepared with tsgo in 1.61 s (esm2)
|
|
11
|
+
ready declaration files bundled successfully: dist/index.d.ts in 3.30 s (esm2)
|
|
12
|
+
ready declaration files generated in 7.27 s (esm0)
|
|
13
13
|
|
|
14
14
|
File (esm0) Size
|
|
15
15
|
dist/rslib-runtime-0.js 1.6 kB
|
|
16
|
-
dist/rstest-config.js 3.2 kB
|
|
17
16
|
dist/@rstest/adapter-rsbuild~0.js 3.7 kB
|
|
18
|
-
dist/
|
|
19
|
-
dist/
|
|
17
|
+
dist/rstest-config.js 3.8 kB
|
|
18
|
+
dist/plugins/index.js 12.6 kB
|
|
19
|
+
dist/env/index.js 26.1 kB
|
|
20
20
|
dist/pure.js 539.1 kB
|
|
21
21
|
|
|
22
|
-
Total: 586.
|
|
22
|
+
Total: 586.8 kB
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
11 files generated in dist, total: 8.9 kB (esm1)
|
|
25
25
|
|
|
26
26
|
File (esm2) Size
|
|
27
27
|
dist/type-entry/index.js 0.01 kB
|
|
@@ -464,26 +464,16 @@ function createPolyfills() {
|
|
|
464
464
|
mainThreadContexts.JsContext.dispatchEvent = ({ type, data })=>deliverEvent(backgroundThreadContexts.CoreContext, 'background', type, data, 'CoreContext');
|
|
465
465
|
backgroundThreadContexts.CoreContext.dispatchEvent = ({ type, data })=>deliverEvent(mainThreadContexts.JsContext, 'main', type, data, 'JSContext');
|
|
466
466
|
backgroundThreadContexts.JsContext.dispatchEvent = ({ type, data })=>deliverEvent(backgroundThreadContexts.JsContext, 'background', type, data, 'JSContext');
|
|
467
|
-
function __LoadLepusChunk(chunkName, _options) {
|
|
468
|
-
const isBackground = !__MAIN_THREAD__;
|
|
469
|
-
globalThis.lynxTestingEnv.switchToMainThread();
|
|
470
|
-
let ans;
|
|
471
|
-
if ('worklet-runtime' === chunkName) ans = globalThis.onInitWorkletRuntime?.();
|
|
472
|
-
else throw new Error(`__LoadLepusChunk: Unknown chunk name: ${chunkName}`);
|
|
473
|
-
if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
474
|
-
return ans;
|
|
475
|
-
}
|
|
476
467
|
return {
|
|
477
468
|
app,
|
|
478
469
|
performance,
|
|
479
470
|
mainThreadContexts,
|
|
480
|
-
backgroundThreadContexts
|
|
481
|
-
__LoadLepusChunk
|
|
471
|
+
backgroundThreadContexts
|
|
482
472
|
};
|
|
483
473
|
}
|
|
484
474
|
function injectMainThreadGlobals(target, polyfills) {
|
|
485
475
|
__injectElementApi(target);
|
|
486
|
-
const { performance, mainThreadContexts
|
|
476
|
+
const { performance, mainThreadContexts } = polyfills || {};
|
|
487
477
|
if (void 0 === target) target = globalThis;
|
|
488
478
|
target.__DEV__ = true;
|
|
489
479
|
target.__PROFILE__ = true;
|
|
@@ -531,7 +521,6 @@ function injectMainThreadGlobals(target, polyfills) {
|
|
|
531
521
|
target.console.profile = console.profile = ()=>{};
|
|
532
522
|
target.console.profileEnd = console.profileEnd = ()=>{};
|
|
533
523
|
target.console.alog = console.alog = ()=>{};
|
|
534
|
-
target.__LoadLepusChunk = __LoadLepusChunk;
|
|
535
524
|
globalThis.onInjectMainThreadGlobals?.(target);
|
|
536
525
|
}
|
|
537
526
|
const IGNORE_LIST_GLOBALS = [
|
|
@@ -565,7 +554,7 @@ class NodesRef {
|
|
|
565
554
|
}
|
|
566
555
|
}
|
|
567
556
|
function injectBackgroundThreadGlobals(target, polyfills) {
|
|
568
|
-
const { app, performance, backgroundThreadContexts
|
|
557
|
+
const { app, performance, backgroundThreadContexts } = polyfills || {};
|
|
569
558
|
if (void 0 === target) target = globalThis;
|
|
570
559
|
target.__DEV__ = true;
|
|
571
560
|
target.__PROFILE__ = true;
|
|
@@ -630,7 +619,6 @@ function injectBackgroundThreadGlobals(target, polyfills) {
|
|
|
630
619
|
runtimeType: 'quickjs',
|
|
631
620
|
lynxSdkVersion: '3.0'
|
|
632
621
|
};
|
|
633
|
-
target.__LoadLepusChunk = __LoadLepusChunk;
|
|
634
622
|
globalThis.onInjectBackgroundThreadGlobals?.(target);
|
|
635
623
|
}
|
|
636
624
|
class LynxTestingEnv {
|