@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
package/runtime/src/lynx.ts
CHANGED
|
@@ -69,7 +69,7 @@ if (typeof __ALOG_ELEMENT_API__ !== 'undefined' && __ALOG_ELEMENT_API__) {
|
|
|
69
69
|
initElementPAPICallAlog();
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
function initBackgroundRuntime(): void {
|
|
73
73
|
// Trick Preact and TypeScript to accept our custom document adapter.
|
|
74
74
|
options.document = document as unknown as Document;
|
|
75
75
|
options.requestAnimationFrame = lynxQueueMicrotask;
|
|
@@ -90,4 +90,8 @@ if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
94
|
+
initBackgroundRuntime();
|
|
95
|
+
}
|
|
96
|
+
|
|
93
97
|
setupLynxEnv();
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
|
|
5
5
|
import { backgroundSnapshotInstanceManager } from '../../snapshot/backgroundSnapshot.js';
|
|
6
|
-
import { snapshotManager } from '../../snapshot/definition.js';
|
|
7
6
|
|
|
8
7
|
export const ctxNotFoundType = 'Lynx.Error.CtxNotFound';
|
|
9
8
|
|
|
@@ -11,39 +10,57 @@ const errorMsg = 'snapshotPatchApply failed: ctx not found';
|
|
|
11
10
|
|
|
12
11
|
let ctxNotFoundEventListener: ((e: RuntimeProxy.Event) => void) | null = null;
|
|
13
12
|
|
|
13
|
+
export interface CtxNotFoundOptions {
|
|
14
|
+
operation: string;
|
|
15
|
+
commitId: number;
|
|
16
|
+
isHydration: boolean;
|
|
17
|
+
parent?: number;
|
|
18
|
+
child?: number;
|
|
19
|
+
/** Missing main-thread contexts: 1 for parent, 2 for child, 3 for both. */
|
|
20
|
+
missingNode?: 1 | 2 | 3;
|
|
21
|
+
}
|
|
22
|
+
|
|
14
23
|
export interface CtxNotFoundData {
|
|
15
24
|
id: number;
|
|
25
|
+
options: CtxNotFoundOptions;
|
|
16
26
|
}
|
|
17
27
|
|
|
18
|
-
export function sendCtxNotFoundEventToBackground(id: number): void {
|
|
19
|
-
/* v8 ignore next 3 */
|
|
28
|
+
export function sendCtxNotFoundEventToBackground(id: number, options: CtxNotFoundOptions): void {
|
|
20
29
|
if (!lynx.getJSContext) {
|
|
21
30
|
throw new Error(errorMsg);
|
|
22
31
|
}
|
|
23
32
|
lynx.getJSContext().dispatchEvent({
|
|
24
33
|
type: ctxNotFoundType,
|
|
25
|
-
data: {
|
|
26
|
-
id,
|
|
27
|
-
} as CtxNotFoundData,
|
|
34
|
+
data: { id, options },
|
|
28
35
|
});
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
export function reportCtxNotFound(data: CtxNotFoundData): void {
|
|
32
|
-
const id = data
|
|
39
|
+
const { id, options } = data;
|
|
33
40
|
const instance = backgroundSnapshotInstanceManager.values.get(id);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const snapshotType = instance?.__snapshot_def ? instance.type ?? 'null' : 'null';
|
|
42
|
+
const { operation, commitId, isHydration, child, missingNode } = options;
|
|
43
|
+
const parent = options.parent ?? instance?.parentNode?.__id;
|
|
44
|
+
let parentInfo = 'parent: null';
|
|
45
|
+
if (parent !== undefined) {
|
|
46
|
+
const parentInstance = backgroundSnapshotInstanceManager.values.get(parent);
|
|
47
|
+
const parentType = parentInstance?.__snapshot_def ? parentInstance.type ?? 'null' : 'null';
|
|
48
|
+
const missingInfo = missingNode === undefined
|
|
49
|
+
? ''
|
|
50
|
+
: `, missing: ${missingNode === 1 || missingNode === 3}`;
|
|
51
|
+
parentInfo = `parent: { id: ${parent}, snapshot type: '${parentType}'${missingInfo} }`;
|
|
44
52
|
}
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
let ctxInfo = parentInfo;
|
|
54
|
+
if (child !== undefined) {
|
|
55
|
+
const childInstance = backgroundSnapshotInstanceManager.values.get(child);
|
|
56
|
+
const childType = childInstance?.__snapshot_def ? childInstance.type ?? 'null' : 'null';
|
|
57
|
+
const missingInfo = missingNode === undefined
|
|
58
|
+
? ''
|
|
59
|
+
: `, missing: ${missingNode === 2 || missingNode === 3}`;
|
|
60
|
+
ctxInfo = `${parentInfo}, child: { id: ${child}, snapshot type: '${childType}'${missingInfo} }`;
|
|
61
|
+
}
|
|
62
|
+
let message =
|
|
63
|
+
`${errorMsg}, snapshot type: '${snapshotType}', ${ctxInfo}, operation: '${operation}', commitId: ${commitId}, isHydration: ${isHydration}`;
|
|
47
64
|
if (__DEV__) {
|
|
48
65
|
message += '. You can set environment variable `REACT_ALOG=true` and restart your dev server for troubleshooting.';
|
|
49
66
|
}
|
|
@@ -24,7 +24,7 @@ import { SnapshotInstance, snapshotCreatorMap, snapshotInstanceManager } from '.
|
|
|
24
24
|
* This is the counterpart to the patch generation in the background thread.
|
|
25
25
|
* Each operation in the patch is processed sequentially to update the DOM.
|
|
26
26
|
*/
|
|
27
|
-
export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
27
|
+
export function snapshotPatchApply(snapshotPatch: SnapshotPatch, commitId: number, isHydration: boolean): void {
|
|
28
28
|
const length = snapshotPatch.length;
|
|
29
29
|
for (let i = 0; i < length; ++i) {
|
|
30
30
|
switch (snapshotPatch[i]) {
|
|
@@ -43,7 +43,14 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
43
43
|
const child = snapshotInstanceManager.values.get(childId);
|
|
44
44
|
const existingNode = snapshotInstanceManager.values.get(beforeId!);
|
|
45
45
|
if (!parent || !child) {
|
|
46
|
-
sendCtxNotFoundEventToBackground(parent ? childId : parentId
|
|
46
|
+
sendCtxNotFoundEventToBackground(parent ? childId : parentId, {
|
|
47
|
+
operation: 'InsertBefore',
|
|
48
|
+
commitId,
|
|
49
|
+
isHydration,
|
|
50
|
+
parent: parentId,
|
|
51
|
+
child: childId,
|
|
52
|
+
missingNode: parent ? 2 : (child ? 1 : 3),
|
|
53
|
+
});
|
|
47
54
|
} else {
|
|
48
55
|
child.__slotIndex = __slotIndex;
|
|
49
56
|
parent.insertBefore(child, existingNode);
|
|
@@ -56,7 +63,14 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
56
63
|
const parent = snapshotInstanceManager.values.get(parentId);
|
|
57
64
|
const child = snapshotInstanceManager.values.get(childId);
|
|
58
65
|
if (!parent || !child) {
|
|
59
|
-
sendCtxNotFoundEventToBackground(parent ? childId : parentId
|
|
66
|
+
sendCtxNotFoundEventToBackground(parent ? childId : parentId, {
|
|
67
|
+
operation: 'RemoveChild',
|
|
68
|
+
commitId,
|
|
69
|
+
isHydration,
|
|
70
|
+
parent: parentId,
|
|
71
|
+
child: childId,
|
|
72
|
+
missingNode: parent ? 2 : (child ? 1 : 3),
|
|
73
|
+
});
|
|
60
74
|
} else {
|
|
61
75
|
parent.removeChild(child);
|
|
62
76
|
}
|
|
@@ -70,7 +84,11 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
70
84
|
if (child) {
|
|
71
85
|
applyNodesRefInsertBefore(identifier, child, beforeId);
|
|
72
86
|
} else {
|
|
73
|
-
sendCtxNotFoundEventToBackground(childId
|
|
87
|
+
sendCtxNotFoundEventToBackground(childId, {
|
|
88
|
+
operation: 'nodesRefInsertBefore',
|
|
89
|
+
commitId,
|
|
90
|
+
isHydration,
|
|
91
|
+
});
|
|
74
92
|
}
|
|
75
93
|
break;
|
|
76
94
|
}
|
|
@@ -81,7 +99,11 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
81
99
|
if (child) {
|
|
82
100
|
applyNodesRefRemoveChild(identifier, child);
|
|
83
101
|
} else {
|
|
84
|
-
sendCtxNotFoundEventToBackground(childId
|
|
102
|
+
sendCtxNotFoundEventToBackground(childId, {
|
|
103
|
+
operation: 'nodesRefRemoveChild',
|
|
104
|
+
commitId,
|
|
105
|
+
isHydration,
|
|
106
|
+
});
|
|
85
107
|
}
|
|
86
108
|
break;
|
|
87
109
|
}
|
|
@@ -93,7 +115,7 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
93
115
|
if (si) {
|
|
94
116
|
si.setAttribute(dynamicPartIndex, value);
|
|
95
117
|
} else {
|
|
96
|
-
sendCtxNotFoundEventToBackground(id);
|
|
118
|
+
sendCtxNotFoundEventToBackground(id, { operation: 'SetAttribute', commitId, isHydration });
|
|
97
119
|
}
|
|
98
120
|
break;
|
|
99
121
|
}
|
|
@@ -104,7 +126,7 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
104
126
|
if (si) {
|
|
105
127
|
si.setAttribute('values', values);
|
|
106
128
|
} else {
|
|
107
|
-
sendCtxNotFoundEventToBackground(id);
|
|
129
|
+
sendCtxNotFoundEventToBackground(id, { operation: 'SetAttributes', commitId, isHydration });
|
|
108
130
|
}
|
|
109
131
|
break;
|
|
110
132
|
}
|
|
@@ -66,10 +66,10 @@ function updateMainThread(
|
|
|
66
66
|
setMainThreadHydrating(true);
|
|
67
67
|
}
|
|
68
68
|
try {
|
|
69
|
-
for (const { snapshotPatch } of patchList) {
|
|
69
|
+
for (const { snapshotPatch, id } of patchList) {
|
|
70
70
|
__pendingListUpdates.clearAttachedLists();
|
|
71
71
|
if (snapshotPatch) {
|
|
72
|
-
snapshotPatchApply(snapshotPatch);
|
|
72
|
+
snapshotPatchApply(snapshotPatch, id, patchOptions.isHydration === true);
|
|
73
73
|
}
|
|
74
74
|
__pendingListUpdates.flush();
|
|
75
75
|
// console.debug('********** Lepus updatePatch:');
|
|
@@ -9,6 +9,8 @@ import { Children as PreactChildren } from 'preact/compat';
|
|
|
9
9
|
* Type of ReactLynx children utilities.
|
|
10
10
|
*
|
|
11
11
|
* @public
|
|
12
|
+
*
|
|
13
|
+
* @group Types
|
|
12
14
|
*/
|
|
13
15
|
export type ReactLynxChildren = Omit<typeof PreactChildren, 'map' | 'forEach' | 'toArray'> & {
|
|
14
16
|
map<T extends ComponentChild, R>(
|
|
@@ -15,6 +15,8 @@ import { getCloneSnapshotInfo, getCloneSnapshotType, isCompiledSnapshot } from '
|
|
|
15
15
|
* The call signature of ReactLynx `createElement`.
|
|
16
16
|
*
|
|
17
17
|
* @public
|
|
18
|
+
*
|
|
19
|
+
* @group Types
|
|
18
20
|
*/
|
|
19
21
|
export interface CreateElement {
|
|
20
22
|
/** Creates an element for a Lynx intrinsic element. */
|
|
@@ -35,6 +37,8 @@ export interface CreateElement {
|
|
|
35
37
|
* The call signature of ReactLynx `cloneElement`.
|
|
36
38
|
*
|
|
37
39
|
* @public
|
|
40
|
+
*
|
|
41
|
+
* @group Types
|
|
38
42
|
*/
|
|
39
43
|
export interface CloneElement {
|
|
40
44
|
/** Clones an element with optional replacement props and children. */
|
|
@@ -109,6 +113,8 @@ function pickChildrenProps(
|
|
|
109
113
|
*
|
|
110
114
|
* @function
|
|
111
115
|
* @public
|
|
116
|
+
*
|
|
117
|
+
* @group Functions
|
|
112
118
|
*/
|
|
113
119
|
export const createElement =
|
|
114
120
|
(function(type: CreateElementParams[0], props: CreateElementParams[1], ...rest: CreateElementParams[2][]) {
|
|
@@ -146,6 +152,8 @@ export const createElement =
|
|
|
146
152
|
*
|
|
147
153
|
* @function
|
|
148
154
|
* @public
|
|
155
|
+
*
|
|
156
|
+
* @group Functions
|
|
149
157
|
*/
|
|
150
158
|
export const cloneElement =
|
|
151
159
|
(function(vnode: CloneElementParams[0], props: CloneElementParams[1], ...rest: CloneElementParams[2][]) {
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
|
|
5
5
|
import { updateWorkletRefInitValueChanges } from '@lynx-js/react/worklet-runtime/bindings';
|
|
6
|
+
import type { MainThreadRefInitValuePatch } from '@lynx-js/react/worklet-runtime/bindings';
|
|
6
7
|
|
|
7
8
|
import { takeMainThreadRefInitValuePatch } from '../../../core/main-thread-ref-init-value.js';
|
|
8
|
-
import type { MainThreadRefInitValuePatch } from '../../../core/main-thread-ref-init-value.js';
|
|
9
9
|
import { LifecycleConstant } from '../../lifecycle/constant.js';
|
|
10
10
|
|
|
11
11
|
function updateMTRefInitValue({ data }: { data: string }): void {
|
|
@@ -2,7 +2,7 @@
|
|
|
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
|
|
|
5
|
-
import type { ClosureValueType, JsFnHandle, Worklet, WorkletRefImpl } from './types.js';
|
|
5
|
+
import type { ClosureValueType, JsFnHandle, MainThreadRefInitValuePatch, Worklet, WorkletRefImpl } from './types.js';
|
|
6
6
|
import type { Element } from '../api/element.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -30,12 +30,26 @@ function updateWorkletRef(workletRef: WorkletRefImpl<Element>, element: ElementN
|
|
|
30
30
|
*
|
|
31
31
|
* @param patch - An array containing the index and new value of the worklet value.
|
|
32
32
|
*/
|
|
33
|
-
function updateWorkletRefInitValueChanges(
|
|
33
|
+
function updateWorkletRefInitValueChanges(
|
|
34
|
+
patch?: MainThreadRefInitValuePatch,
|
|
35
|
+
): void {
|
|
34
36
|
if (patch) {
|
|
35
37
|
globalThis.lynxWorkletImpl?._refImpl.updateWorkletRefInitValueChanges(patch);
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Register a definition for an opaque main-thread object type.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
function registerMainThreadObjectType(
|
|
47
|
+
type: string,
|
|
48
|
+
create: ((initialValue: unknown) => object) | Worklet,
|
|
49
|
+
): void {
|
|
50
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(type, create);
|
|
51
|
+
}
|
|
52
|
+
|
|
39
53
|
/**
|
|
40
54
|
* Releases the temporary negative-ID MainThreadRefs after hydration handoff.
|
|
41
55
|
*/
|
|
@@ -84,6 +98,7 @@ export {
|
|
|
84
98
|
updateWorkletRef,
|
|
85
99
|
updateWorkletRefInitValueChanges,
|
|
86
100
|
clearFirstScreenMainThreadRefs,
|
|
101
|
+
registerMainThreadObjectType,
|
|
87
102
|
registerWorklet,
|
|
88
103
|
delayRunOnBackground,
|
|
89
104
|
setEomShouldFlushElementTree,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
export { loadWorkletRuntime } from './loadRuntime.js';
|
|
5
4
|
|
|
6
5
|
export * from './bindings.js';
|
|
7
6
|
|
|
@@ -11,7 +11,7 @@ export type WorkletRefId = number;
|
|
|
11
11
|
export interface WorkletRefImpl<T> {
|
|
12
12
|
_wvid: WorkletRefId;
|
|
13
13
|
_initValue: T;
|
|
14
|
-
_type
|
|
14
|
+
_type?: string;
|
|
15
15
|
_lifecycleObserver?: unknown;
|
|
16
16
|
current?: T;
|
|
17
17
|
}
|
|
@@ -23,22 +23,18 @@ export interface WorkletRef<T> {
|
|
|
23
23
|
[key: string]: unknown;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
interface ClosureValueType_ extends Record<string, ClosureValueType> {}
|
|
27
|
-
|
|
28
26
|
export type ClosureValueType =
|
|
29
27
|
| null
|
|
30
28
|
| undefined
|
|
31
29
|
| string
|
|
32
30
|
| boolean
|
|
33
31
|
| number
|
|
34
|
-
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
| ClosureValueType_
|
|
41
|
-
| ClosureValueType[];
|
|
32
|
+
| object;
|
|
33
|
+
|
|
34
|
+
export type MainThreadRefInitValuePatch = (
|
|
35
|
+
| [id: number, value: unknown]
|
|
36
|
+
| [id: number, value: unknown, type: string]
|
|
37
|
+
)[];
|
|
42
38
|
|
|
43
39
|
export interface Worklet {
|
|
44
40
|
_wkltId: string;
|
|
@@ -2,8 +2,16 @@
|
|
|
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
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
ClosureValueType,
|
|
7
|
+
JsFnHandle,
|
|
8
|
+
Worklet,
|
|
9
|
+
WorkletRef,
|
|
10
|
+
WorkletRefId,
|
|
11
|
+
WorkletRefImpl,
|
|
12
|
+
} from './bindings/index.js';
|
|
6
13
|
import { profile } from './utils/profile.js';
|
|
14
|
+
import { hydrateWorkletValue, isHydratedWorkletValue } from './workletRef.js';
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* Hydrates a Worklet context with data from a first-screen Worklet context.
|
|
@@ -37,7 +45,13 @@ function hydrateCtxImpl(
|
|
|
37
45
|
return;
|
|
38
46
|
}
|
|
39
47
|
|
|
40
|
-
//
|
|
48
|
+
// Typed handles (including `_type: 'main-thread'` mutable cells) hydrate
|
|
49
|
+
// atomically without walking their initialization payload. Untyped legacy
|
|
50
|
+
// refs continue through the existing `_wvid` path below.
|
|
51
|
+
if (isTypedWorkletRefDescriptor(ctxObj)) {
|
|
52
|
+
hydrateWorkletValueHandle(ctxObj, firstScreenCtxObj);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
41
55
|
for (const key in ctx) {
|
|
42
56
|
if (key === '_wvid') {
|
|
43
57
|
hydrateMainThreadRef(
|
|
@@ -59,23 +73,42 @@ function hydrateCtxImpl(
|
|
|
59
73
|
}
|
|
60
74
|
}
|
|
61
75
|
|
|
76
|
+
function isTypedWorkletRefDescriptor(
|
|
77
|
+
value: object,
|
|
78
|
+
): value is WorkletRefImpl<unknown> {
|
|
79
|
+
const descriptor = value as Partial<WorkletRefImpl<unknown>>;
|
|
80
|
+
return typeof descriptor._wvid === 'number'
|
|
81
|
+
&& typeof descriptor._type === 'string';
|
|
82
|
+
}
|
|
83
|
+
|
|
62
84
|
/**
|
|
63
85
|
* Hydrates a WorkletRef on the main thread.
|
|
64
|
-
* This
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @param refId The ID of the WorkletRef to hydrate.
|
|
68
|
-
* @param value The new value for the WorkletRef.
|
|
86
|
+
* This maps the positive-ID background handle to the target realized during
|
|
87
|
+
* first-screen rendering, while leaving an unused first-screen handle alone.
|
|
69
88
|
*/
|
|
70
89
|
function hydrateMainThreadRef(
|
|
71
90
|
refId: WorkletRefId,
|
|
72
91
|
value: WorkletRefImpl<unknown>,
|
|
73
|
-
) {
|
|
92
|
+
): void {
|
|
74
93
|
if ('_initValue' in value) {
|
|
75
|
-
// The ref has not been accessed yet.
|
|
76
94
|
return;
|
|
77
95
|
}
|
|
78
|
-
lynxWorkletImpl!._refImpl._workletRefMap[refId] = value
|
|
96
|
+
lynxWorkletImpl!._refImpl._workletRefMap[refId] = value as WorkletRef<unknown>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Hydrates a typed worklet handle on the main thread.
|
|
101
|
+
* The target is the object or mutable cell realized from the matching first-screen handle.
|
|
102
|
+
*/
|
|
103
|
+
function hydrateWorkletValueHandle(
|
|
104
|
+
handle: WorkletRefImpl<unknown>,
|
|
105
|
+
value: ClosureValueType,
|
|
106
|
+
): void {
|
|
107
|
+
if (!isHydratedWorkletValue(value)) {
|
|
108
|
+
// The handle was not accessed during first-screen rendering.
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
hydrateWorkletValue(handle, value);
|
|
79
112
|
}
|
|
80
113
|
|
|
81
114
|
/**
|
|
@@ -10,3 +10,10 @@ if (globalThis.lynxWorkletImpl === undefined) {
|
|
|
10
10
|
initApiEnv();
|
|
11
11
|
initEventListeners();
|
|
12
12
|
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Registers compiler-generated main-thread functions with the initialized host runtime.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export const registerWorklet = globalThis.registerWorkletInternal;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import type { Worklet, WorkletRefImpl } from './bindings/types.js';
|
|
5
|
+
|
|
6
|
+
type MainThreadObjectFactory = (initialValue: unknown) => object;
|
|
7
|
+
interface MainThreadObjectDefinition {
|
|
8
|
+
create: MainThreadObjectFactory | Worklet;
|
|
9
|
+
resolvedCreate?: MainThreadObjectFactory;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const mainThreadObjectDefinitions = new Map<string, MainThreadObjectDefinition>();
|
|
13
|
+
// The brand belongs to the target, not an individual handle. Other handles or
|
|
14
|
+
// captured contexts may still own the target after one ref-map entry is removed.
|
|
15
|
+
let realizedMainThreadObjectTypes = new WeakMap<object, string>();
|
|
16
|
+
|
|
17
|
+
function registerMainThreadObjectType(
|
|
18
|
+
type: string,
|
|
19
|
+
create: MainThreadObjectFactory | Worklet,
|
|
20
|
+
): void {
|
|
21
|
+
if (type === 'main-thread') {
|
|
22
|
+
throw new Error(
|
|
23
|
+
'MainThreadObject type "main-thread" is reserved for MainThreadRef.',
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
const registered = mainThreadObjectDefinitions.get(type);
|
|
27
|
+
if (registered) {
|
|
28
|
+
if (
|
|
29
|
+
getFactoryRegistrationIdentity(registered.create)
|
|
30
|
+
!== getFactoryRegistrationIdentity(create)
|
|
31
|
+
) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Conflicting MainThreadObject registration for type "${type}". A type key must always use the same create function.`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
mainThreadObjectDefinitions.set(type, { create });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getFactoryRegistrationIdentity(
|
|
42
|
+
factory: MainThreadObjectFactory | Worklet,
|
|
43
|
+
): string {
|
|
44
|
+
if (typeof factory === 'function') {
|
|
45
|
+
return Function.prototype.toString.call(factory);
|
|
46
|
+
}
|
|
47
|
+
return `worklet:${factory._wkltId}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function resolveFactoryFunction(
|
|
51
|
+
factory: MainThreadObjectFactory | Worklet,
|
|
52
|
+
): MainThreadObjectFactory {
|
|
53
|
+
if (typeof factory === 'function') {
|
|
54
|
+
return factory;
|
|
55
|
+
}
|
|
56
|
+
if (!('_wkltId' in factory) || '_lepusWorkletHash' in factory) {
|
|
57
|
+
throw new Error('Cannot resolve an invalid Main Thread Function.');
|
|
58
|
+
}
|
|
59
|
+
// Factories are capture-free, so they need neither context traversal nor binding.
|
|
60
|
+
// Resolve on first use: the compiler registers worklets after module evaluation.
|
|
61
|
+
return lynxWorkletImpl._workletMap[factory._wkltId] as MainThreadObjectFactory;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getMainThreadObjectFactory(
|
|
65
|
+
definition: MainThreadObjectDefinition,
|
|
66
|
+
): MainThreadObjectFactory {
|
|
67
|
+
return definition.resolvedCreate ??= resolveFactoryFunction(definition.create);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function createMainThreadObject(refImpl: WorkletRefImpl<unknown>): object {
|
|
71
|
+
const type = refImpl._type!;
|
|
72
|
+
const definition = mainThreadObjectDefinitions.get(type);
|
|
73
|
+
if (!definition) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`MainThreadObject type is not registered: "${type}". Define the type in a module evaluated on the main thread before initializing its handle.`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const value = getMainThreadObjectFactory(definition)(refImpl._initValue);
|
|
80
|
+
if (typeof value !== 'object' || value === null) {
|
|
81
|
+
throw new Error(`MainThreadObject type "${type}" created a non-object value.`);
|
|
82
|
+
}
|
|
83
|
+
realizedMainThreadObjectTypes.set(value, type);
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function isRealizedMainThreadObject(value: object): boolean {
|
|
88
|
+
return realizedMainThreadObjectTypes.has(value);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function assertCompatibleMainThreadObject(
|
|
92
|
+
handle: WorkletRefImpl<unknown>,
|
|
93
|
+
value: object,
|
|
94
|
+
operation: 'hydration' | 'initialization patch',
|
|
95
|
+
): void {
|
|
96
|
+
const actualType = realizedMainThreadObjectTypes.get(value);
|
|
97
|
+
const expectedType = handle._type!;
|
|
98
|
+
if (actualType !== expectedType) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`MainThreadObject type mismatch during ${operation} for handle ${handle._wvid}: background handle expects type "${expectedType}", but the main-thread target is type "${actualType}".`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function initMainThreadObjects(): void {
|
|
106
|
+
mainThreadObjectDefinitions.clear();
|
|
107
|
+
realizedMainThreadObjectTypes = new WeakMap();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export {
|
|
111
|
+
type MainThreadObjectFactory,
|
|
112
|
+
initMainThreadObjects,
|
|
113
|
+
registerMainThreadObjectType,
|
|
114
|
+
createMainThreadObject,
|
|
115
|
+
assertCompatibleMainThreadObject,
|
|
116
|
+
isRealizedMainThreadObject,
|
|
117
|
+
};
|