@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/docs/macros.md
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Built-in macros
|
|
3
|
+
group: Documents
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Built-in Macros
|
|
7
|
+
|
|
8
|
+
The `@lynx-js/react` package processes built-in macro definitions such as `__BACKGROUND__` and `__MAIN_THREAD__`. During compilation, code blocks with `false` conditions are automatically removed.
|
|
9
|
+
|
|
10
|
+
## `__BACKGROUND__`
|
|
11
|
+
|
|
12
|
+
- Type: `boolean`
|
|
13
|
+
- Purpose: Controls code execution in background thread environment. Used to determine which code segments should be preserved in background thread code after compilation.
|
|
14
|
+
|
|
15
|
+
### Usage Examples
|
|
16
|
+
|
|
17
|
+
#### In Function Components
|
|
18
|
+
|
|
19
|
+
Here's an example using the `App` component:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { noop } from 'lodash-es';
|
|
23
|
+
import { useEffect } from '@lynx-js/react';
|
|
24
|
+
|
|
25
|
+
function App() {
|
|
26
|
+
const showToast = __BACKGROUND__
|
|
27
|
+
? () => {
|
|
28
|
+
bridge.call('showToast', {
|
|
29
|
+
message: t('toast'),
|
|
30
|
+
icon: 'success',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
: noop;
|
|
34
|
+
|
|
35
|
+
useEffect(showToast, []);
|
|
36
|
+
return <view />;
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
After compilation, this code is transformed into:
|
|
41
|
+
|
|
42
|
+
- Background thread code (`background.js` in the compilation intermediate directory):
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
function App() {
|
|
46
|
+
const showToast = () => {
|
|
47
|
+
bridge.call('showToast', {
|
|
48
|
+
message: t('toast'),
|
|
49
|
+
icon: 'success',
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
useEffect(showToast, []);
|
|
53
|
+
return createSnapshotInstance(__snapshot_5ab440, null, []);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- Main thread code (`main-thread.js` in the compilation intermediate directory):
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
function App() {
|
|
61
|
+
const showToast = noop_default;
|
|
62
|
+
|
|
63
|
+
useEffect();
|
|
64
|
+
return createSnapshotInstance(__snapshot_5ab440, null, []);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### In Class Components
|
|
69
|
+
|
|
70
|
+
Here's an example using the `Conversations` component:
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { AppLoggerFactory } from '../utils/appLoggerFactory';
|
|
74
|
+
|
|
75
|
+
class Conversations extends Component<Props, State> {
|
|
76
|
+
appLogger: AppLogger;
|
|
77
|
+
|
|
78
|
+
constructor(props: Props) {
|
|
79
|
+
super(props);
|
|
80
|
+
this.state = {
|
|
81
|
+
showConversationItemAction: false,
|
|
82
|
+
loading: true,
|
|
83
|
+
};
|
|
84
|
+
if (__BACKGROUND__) {
|
|
85
|
+
this.appLogger = AppLoggerFactory();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
After compilation, this code is transformed into:
|
|
92
|
+
|
|
93
|
+
- Background thread code (`background.js` in the compilation intermediate directory):
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
class Conversations extends Component<Props, State> {
|
|
97
|
+
appLogger: AppLogger;
|
|
98
|
+
|
|
99
|
+
constructor(props: Props) {
|
|
100
|
+
super(props);
|
|
101
|
+
this.state = {
|
|
102
|
+
showConversationItemAction: false,
|
|
103
|
+
loading: true,
|
|
104
|
+
};
|
|
105
|
+
this.appLogger = AppLoggerFactory();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
- Main thread code (`main-thread.js` in the compilation intermediate directory):
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
class Conversations extends Component<Props, State> {
|
|
114
|
+
appLogger: AppLogger;
|
|
115
|
+
|
|
116
|
+
constructor(props: Props) {
|
|
117
|
+
super(props);
|
|
118
|
+
this.state = {
|
|
119
|
+
showConversationItemAction: false,
|
|
120
|
+
loading: true,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## `__MAIN_THREAD__`
|
|
127
|
+
|
|
128
|
+
- Type: `boolean`
|
|
129
|
+
- Purpose: Controls code execution in main thread environment. Used to determine which code segments should be preserved in main thread code during compilation.
|
|
130
|
+
|
|
131
|
+
### Usage Examples
|
|
132
|
+
|
|
133
|
+
#### In Function Components
|
|
134
|
+
|
|
135
|
+
Here's an example using the `App` component:
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
import { noop } from 'lodash-es';
|
|
139
|
+
import { useEffect } from '@lynx-js/react';
|
|
140
|
+
|
|
141
|
+
function App() {
|
|
142
|
+
const showToast = !__MAIN_THREAD__
|
|
143
|
+
? () => {
|
|
144
|
+
bridge.call('showToast', {
|
|
145
|
+
message: t('toast'),
|
|
146
|
+
icon: 'success',
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
: noop;
|
|
150
|
+
|
|
151
|
+
useEffect(showToast, []);
|
|
152
|
+
return <view />;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
After compilation, this code is transformed into:
|
|
157
|
+
|
|
158
|
+
- Background thread code (`background.js` in the compilation intermediate directory):
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
function App() {
|
|
162
|
+
const showToast = () => {
|
|
163
|
+
bridge.call('showToast', {
|
|
164
|
+
message: t('toast'),
|
|
165
|
+
icon: 'success',
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
useEffect(showToast, []);
|
|
169
|
+
return createSnapshotInstance(__snapshot_5ab440, null, []);
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
- Main thread code (`main-thread.js` in the compilation intermediate directory):
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
function App() {
|
|
177
|
+
const showToast = noop_default;
|
|
178
|
+
|
|
179
|
+
useEffect();
|
|
180
|
+
return createSnapshotInstance(__snapshot_5ab440, null, []);
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### In Class Components
|
|
185
|
+
|
|
186
|
+
Here's an example using the `Conversations` component:
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { AppLoggerFactory } from '../utils/appLoggerFactory';
|
|
190
|
+
|
|
191
|
+
class Conversations extends Component<Props, State> {
|
|
192
|
+
appLogger: AppLogger;
|
|
193
|
+
|
|
194
|
+
constructor(props: Props) {
|
|
195
|
+
super(props);
|
|
196
|
+
this.state = {
|
|
197
|
+
showConversationItemAction: false,
|
|
198
|
+
loading: true,
|
|
199
|
+
};
|
|
200
|
+
if (!__MAIN_THREAD__) {
|
|
201
|
+
this.appLogger = AppLoggerFactory();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
After compilation, this code is transformed into:
|
|
208
|
+
|
|
209
|
+
- Background thread code (`background.js` in the compilation intermediate directory):
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
class Conversations extends Component<Props, State> {
|
|
213
|
+
appLogger: AppLogger;
|
|
214
|
+
|
|
215
|
+
constructor(props: Props) {
|
|
216
|
+
super(props);
|
|
217
|
+
this.state = {
|
|
218
|
+
showConversationItemAction: false,
|
|
219
|
+
loading: true,
|
|
220
|
+
};
|
|
221
|
+
this.appLogger = AppLoggerFactory();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
- Main thread code (`main-thread.js` in the compilation intermediate directory):
|
|
227
|
+
|
|
228
|
+
```tsx
|
|
229
|
+
class Conversations extends Component<Props, State> {
|
|
230
|
+
appLogger: AppLogger;
|
|
231
|
+
|
|
232
|
+
constructor(props: Props) {
|
|
233
|
+
super(props);
|
|
234
|
+
this.state = {
|
|
235
|
+
showConversationItemAction: false,
|
|
236
|
+
loading: true,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## `__JS__`
|
|
243
|
+
|
|
244
|
+
- Type: `boolean`
|
|
245
|
+
- Purpose: Alias of [`__BACKGROUND__`](#__background__).
|
|
246
|
+
|
|
247
|
+
:::warning Deprecated
|
|
248
|
+
Use `__BACKGROUND__` instead.
|
|
249
|
+
:::
|
|
250
|
+
|
|
251
|
+
## `__LEPUS__`
|
|
252
|
+
|
|
253
|
+
- Type: `boolean`
|
|
254
|
+
- Purpose: Alias of [`__MAIN_THREAD__`](#__main_thread__).
|
|
255
|
+
|
|
256
|
+
:::warning Deprecated
|
|
257
|
+
Use `__MAIN_THREAD__` instead.
|
|
258
|
+
:::
|
|
259
|
+
|
|
260
|
+
## `__DEV__`
|
|
261
|
+
|
|
262
|
+
- Type: `boolean`
|
|
263
|
+
- Purpose: `true` in development builds, `false` in production. Use it to guard development-only code — prop validation, invariant checks, friendlier error messages — so none of it reaches production.
|
|
264
|
+
|
|
265
|
+
```tsx
|
|
266
|
+
if (__DEV__) {
|
|
267
|
+
// Stripped from production builds.
|
|
268
|
+
console.log('debug only');
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## `__PROFILE__`
|
|
273
|
+
|
|
274
|
+
- Type: `boolean`
|
|
275
|
+
- Purpose: `true` when the build carries profiling instrumentation. It is on by default in development and off in production. See [Performance Profiling](https://lynxjs.org/react/performance/profiling.mdx) for the traces it produces, and [Runtime Profiling](https://lynxjs.org/rspeedy/runtime-profiling.md) for how to turn it on for a production build.
|
|
276
|
+
|
|
277
|
+
## `__REACT_DEVTOOL__`
|
|
278
|
+
|
|
279
|
+
- Type: `boolean | undefined`
|
|
280
|
+
- Purpose: `true` when the runtime hooks that [Preact DevTools](https://lynxjs.org/guide/devtool/panels/preact-devtools-panel.mdx) depends on are compiled in. Enabled by default in development; in production it can be enabled with the `REACT_DEVTOOL=true` environment variable.
|
|
281
|
+
|
|
282
|
+
## `__LAZY_BUNDLE_FETCHER__`
|
|
283
|
+
|
|
284
|
+
- Type: `'FetchBundle' | 'QueryComponent'`
|
|
285
|
+
- Purpose: Which lazy bundle fetcher the build is wired up to. `'FetchBundle'` enables the `lynx.fetchBundle`-based path (and `import(..., { with: { mode } })` mode hints); `'QueryComponent'` is the legacy `lynx.QueryComponent` path. How the value is selected, the `REACT_LAZY_BUNDLE_FETCHER` override and the version scope are documented in [Lazy bundle loaders](https://lynxjs.org/react/code-splitting.md#lazy-bundle-loaders).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.128.0",
|
|
4
4
|
"description": "ReactLynx is a framework for developing Lynx applications with familiar React.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -103,13 +103,9 @@
|
|
|
103
103
|
"default": "./transform/main.js"
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
|
-
"./worklet-runtime": {
|
|
106
|
+
"./worklet-runtime/init": {
|
|
107
107
|
"types": "./runtime/lib/worklet-runtime/index.d.ts",
|
|
108
|
-
"default": "./runtime/worklet-runtime/
|
|
109
|
-
},
|
|
110
|
-
"./worklet-dev-runtime": {
|
|
111
|
-
"types": "./runtime/lib/worklet-runtime/index.d.ts",
|
|
112
|
-
"default": "./runtime/worklet-runtime/dev.js"
|
|
108
|
+
"default": "./runtime/lib/worklet-runtime/index.js"
|
|
113
109
|
},
|
|
114
110
|
"./worklet-runtime/bindings": {
|
|
115
111
|
"types": "./runtime/lib/worklet-runtime/bindings/index.d.ts",
|
|
@@ -196,10 +192,7 @@
|
|
|
196
192
|
"runtime-components": [
|
|
197
193
|
"./components/lib/index.d.ts"
|
|
198
194
|
],
|
|
199
|
-
"worklet-runtime": [
|
|
200
|
-
"./runtime/lib/worklet-runtime/index.d.ts"
|
|
201
|
-
],
|
|
202
|
-
"worklet-dev-runtime": [
|
|
195
|
+
"worklet-runtime/init": [
|
|
203
196
|
"./runtime/lib/worklet-runtime/index.d.ts"
|
|
204
197
|
],
|
|
205
198
|
"worklet-runtime/bindings": [
|
|
@@ -218,6 +211,7 @@
|
|
|
218
211
|
"types",
|
|
219
212
|
"docs",
|
|
220
213
|
"testing-library",
|
|
214
|
+
"!**/node_modules/**",
|
|
221
215
|
"CHANGELOG.md",
|
|
222
216
|
"internal.js",
|
|
223
217
|
"README.md",
|
|
@@ -228,7 +222,7 @@
|
|
|
228
222
|
},
|
|
229
223
|
"devDependencies": {
|
|
230
224
|
"@lynx-js/types": "4.1.0",
|
|
231
|
-
"@microsoft/api-extractor": "7.59.
|
|
225
|
+
"@microsoft/api-extractor": "7.59.4",
|
|
232
226
|
"@types/react": "^19.2.18"
|
|
233
227
|
},
|
|
234
228
|
"peerDependencies": {
|
|
@@ -241,7 +235,6 @@
|
|
|
241
235
|
}
|
|
242
236
|
},
|
|
243
237
|
"scripts": {
|
|
244
|
-
"api-extractor": "api-extractor run --verbose"
|
|
245
|
-
"build": "rslib"
|
|
238
|
+
"api-extractor": "api-extractor run --verbose"
|
|
246
239
|
}
|
|
247
240
|
}
|
package/refresh/dist/index.js
CHANGED
|
@@ -29,6 +29,23 @@ options.debounceRendering = (process)=>{
|
|
|
29
29
|
const vnodesForComponent = new WeakMap();
|
|
30
30
|
const mappedVNodes = new WeakMap();
|
|
31
31
|
const lastSeen = new Map();
|
|
32
|
+
const lastSeenByInstance = new WeakMap();
|
|
33
|
+
const setLastSeen = (vnode)=>{
|
|
34
|
+
const component = vnode.__c;
|
|
35
|
+
if (component) {
|
|
36
|
+
if (lastSeenByInstance.has(component)) lastSeen.delete(lastSeenByInstance.get(component));
|
|
37
|
+
lastSeenByInstance.set(component, vnode.__v);
|
|
38
|
+
}
|
|
39
|
+
lastSeen.set(vnode.__v, vnode);
|
|
40
|
+
};
|
|
41
|
+
const clearLastSeen = (vnode)=>{
|
|
42
|
+
lastSeen.delete(vnode.__v);
|
|
43
|
+
const component = vnode.__c;
|
|
44
|
+
if (component && lastSeenByInstance.has(component)) {
|
|
45
|
+
lastSeen.delete(lastSeenByInstance.get(component));
|
|
46
|
+
lastSeenByInstance.delete(component);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
32
49
|
const getMappedVnode = (type)=>{
|
|
33
50
|
if (mappedVNodes.has(type)) return getMappedVnode(mappedVNodes.get(type));
|
|
34
51
|
return type;
|
|
@@ -65,7 +82,7 @@ const oldDiffed = options.diffed;
|
|
|
65
82
|
options.diffed = (vnode)=>{
|
|
66
83
|
if (vnode && 'function' == typeof vnode.type) {
|
|
67
84
|
const vnodes = vnodesForComponent.get(vnode.type);
|
|
68
|
-
|
|
85
|
+
setLastSeen(vnode);
|
|
69
86
|
if (vnodes) {
|
|
70
87
|
const matchingDom = vnodes.filter((p)=>p.__c === vnode.__c);
|
|
71
88
|
if (matchingDom.length > 1) {
|
|
@@ -79,11 +96,14 @@ options.diffed = (vnode)=>{
|
|
|
79
96
|
const oldUnmount = options.unmount;
|
|
80
97
|
options.unmount = (vnode)=>{
|
|
81
98
|
const type = (vnode || {}).type;
|
|
82
|
-
if ('function' == typeof type
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
99
|
+
if ('function' == typeof type) {
|
|
100
|
+
clearLastSeen(vnode);
|
|
101
|
+
if (vnodesForComponent.has(type)) {
|
|
102
|
+
const vnodes = vnodesForComponent.get(type);
|
|
103
|
+
if (vnodes) {
|
|
104
|
+
const index = vnodes.indexOf(vnode);
|
|
105
|
+
if (-1 !== index) vnodes.splice(index, 1);
|
|
106
|
+
}
|
|
87
107
|
}
|
|
88
108
|
}
|
|
89
109
|
if (oldUnmount) oldUnmount(vnode);
|
package/refresh/package.json
CHANGED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { defineMainThreadObjectType } from '../../src/core/main-thread-object.js';
|
|
4
|
+
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
vi.stubGlobal('__DEV__', true);
|
|
7
|
+
vi.stubGlobal('__JS__', true);
|
|
8
|
+
vi.stubGlobal('__LEPUS__', false);
|
|
9
|
+
vi.stubGlobal('lynxWorkletImpl', {
|
|
10
|
+
_refImpl: { registerMainThreadObjectType: vi.fn() },
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
vi.unstubAllGlobals();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('core/main-thread-object definition', () => {
|
|
19
|
+
it('registers a type during main-thread module evaluation without rendering its hook', () => {
|
|
20
|
+
const create = value => ({ value });
|
|
21
|
+
const register = globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType;
|
|
22
|
+
|
|
23
|
+
vi.stubGlobal('__JS__', false);
|
|
24
|
+
vi.stubGlobal('__LEPUS__', true);
|
|
25
|
+
const type = defineMainThreadObjectType({
|
|
26
|
+
type: '@test/lazy-module-value',
|
|
27
|
+
create,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
expect(register).toHaveBeenCalledWith(
|
|
31
|
+
'@test/lazy-module-value',
|
|
32
|
+
create,
|
|
33
|
+
);
|
|
34
|
+
expect(type).not.toHaveProperty('create');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it.each([true, false])('validates and freezes object type definitions (__JS__=%s)', (isJS) => {
|
|
38
|
+
vi.stubGlobal('__JS__', isJS);
|
|
39
|
+
vi.stubGlobal('__LEPUS__', !isJS);
|
|
40
|
+
expect(() =>
|
|
41
|
+
defineMainThreadObjectType({
|
|
42
|
+
type: '',
|
|
43
|
+
create: value => ({ value }),
|
|
44
|
+
})
|
|
45
|
+
).toThrow('MainThreadObject type must be a non-empty string.');
|
|
46
|
+
expect(() =>
|
|
47
|
+
defineMainThreadObjectType({
|
|
48
|
+
type: 'main-thread',
|
|
49
|
+
create: value => ({ value }),
|
|
50
|
+
})
|
|
51
|
+
).toThrow(
|
|
52
|
+
'MainThreadObject type "main-thread" is reserved for MainThreadRef.',
|
|
53
|
+
);
|
|
54
|
+
expect(() =>
|
|
55
|
+
defineMainThreadObjectType({
|
|
56
|
+
type: '@test/missing-create',
|
|
57
|
+
})
|
|
58
|
+
).toThrow(
|
|
59
|
+
'MainThreadObject type "@test/missing-create" must provide a create Main Thread Function.',
|
|
60
|
+
);
|
|
61
|
+
expect(() =>
|
|
62
|
+
defineMainThreadObjectType({
|
|
63
|
+
type: '@test/capturing-create',
|
|
64
|
+
create: {
|
|
65
|
+
_wkltId: 'capturing-create',
|
|
66
|
+
_c: { mutableValue: 1 },
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
).toThrow(
|
|
70
|
+
'MainThreadObject create function for "@test/capturing-create" must not capture values. Import dependencies from a shared-runtime module instead.',
|
|
71
|
+
);
|
|
72
|
+
expect(() =>
|
|
73
|
+
defineMainThreadObjectType({
|
|
74
|
+
type: '@test/js-function-capture',
|
|
75
|
+
create: {
|
|
76
|
+
_wkltId: 'js-function-capture',
|
|
77
|
+
_jsFn: { callback: { _jsFnId: 1 } },
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
).toThrow(
|
|
81
|
+
'MainThreadObject create function for "@test/js-function-capture" must not capture values. Import dependencies from a shared-runtime module instead.',
|
|
82
|
+
);
|
|
83
|
+
expect(() =>
|
|
84
|
+
defineMainThreadObjectType({
|
|
85
|
+
type: '@test/this-capture',
|
|
86
|
+
create: {
|
|
87
|
+
_wkltId: 'this-capture',
|
|
88
|
+
helper: { stop() {} },
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
).toThrow(
|
|
92
|
+
'MainThreadObject create function for "@test/this-capture" must not capture values. Import dependencies from a shared-runtime module instead.',
|
|
93
|
+
);
|
|
94
|
+
const hiddenCapture = { _wkltId: 'hidden-capture' };
|
|
95
|
+
Object.defineProperty(hiddenCapture, 'helper', { value: 1 });
|
|
96
|
+
expect(() =>
|
|
97
|
+
defineMainThreadObjectType({
|
|
98
|
+
type: '@test/hidden-capture',
|
|
99
|
+
create: hiddenCapture,
|
|
100
|
+
})
|
|
101
|
+
).toThrow(
|
|
102
|
+
'MainThreadObject create function for "@test/hidden-capture" must not capture values. Import dependencies from a shared-runtime module instead.',
|
|
103
|
+
);
|
|
104
|
+
const symbolCapture = {
|
|
105
|
+
_wkltId: 'symbol-capture',
|
|
106
|
+
[Symbol('helper')]: 1,
|
|
107
|
+
};
|
|
108
|
+
expect(() =>
|
|
109
|
+
defineMainThreadObjectType({
|
|
110
|
+
type: '@test/symbol-capture',
|
|
111
|
+
create: symbolCapture,
|
|
112
|
+
})
|
|
113
|
+
).toThrow(
|
|
114
|
+
'MainThreadObject create function for "@test/symbol-capture" must not capture values. Import dependencies from a shared-runtime module instead.',
|
|
115
|
+
);
|
|
116
|
+
const accessorClosure = {
|
|
117
|
+
_wkltId: 'accessor-closure',
|
|
118
|
+
get _c() {
|
|
119
|
+
return {};
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
expect(() =>
|
|
123
|
+
defineMainThreadObjectType({
|
|
124
|
+
type: '@test/accessor-closure',
|
|
125
|
+
create: accessorClosure,
|
|
126
|
+
})
|
|
127
|
+
).toThrow(
|
|
128
|
+
'MainThreadObject create function for "@test/accessor-closure" must not capture values. Import dependencies from a shared-runtime module instead.',
|
|
129
|
+
);
|
|
130
|
+
const type = defineMainThreadObjectType({
|
|
131
|
+
type: '@test/frozen',
|
|
132
|
+
create: value => ({ value }),
|
|
133
|
+
});
|
|
134
|
+
expect(Object.isFrozen(type)).toBe(true);
|
|
135
|
+
|
|
136
|
+
vi.stubGlobal('__DEV__', false);
|
|
137
|
+
const ownKeys = vi.fn(Reflect.ownKeys);
|
|
138
|
+
const create = new Proxy({
|
|
139
|
+
_wkltId: 'production-create',
|
|
140
|
+
_c: { mutableValue: 1 },
|
|
141
|
+
}, { ownKeys });
|
|
142
|
+
const productionType = defineMainThreadObjectType({
|
|
143
|
+
type: '@test/production',
|
|
144
|
+
create,
|
|
145
|
+
});
|
|
146
|
+
expect(productionType.type).toBe('@test/production');
|
|
147
|
+
expect(ownKeys).not.toHaveBeenCalled();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runOnMainThread } from '@lynx-js/react';
|
|
1
|
+
import { defineMainThreadObjectType, runOnMainThread, useMainThreadObject } from '@lynx-js/react';
|
|
2
2
|
|
|
3
3
|
interface AppProps {
|
|
4
4
|
label?: string;
|
|
@@ -7,9 +7,23 @@ interface AppProps {
|
|
|
7
7
|
|
|
8
8
|
export let lastRenderPromise: Promise<string> | undefined;
|
|
9
9
|
|
|
10
|
+
const config = { prefix: 'main' };
|
|
11
|
+
|
|
12
|
+
const formatterType = defineMainThreadObjectType({
|
|
13
|
+
type: 'element-template-formatter',
|
|
14
|
+
create: (prefix: string) => {
|
|
15
|
+
'main thread';
|
|
16
|
+
return {
|
|
17
|
+
format(value: string) {
|
|
18
|
+
return `${prefix}:${value}`;
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
10
24
|
const echoOnMainThread = (value: string): string => {
|
|
11
25
|
'main thread';
|
|
12
|
-
return
|
|
26
|
+
return `${config.prefix}:${value}`;
|
|
13
27
|
};
|
|
14
28
|
|
|
15
29
|
export function callMainDirect(label = 'manual'): Promise<string> {
|
|
@@ -17,8 +31,17 @@ export function callMainDirect(label = 'manual'): Promise<string> {
|
|
|
17
31
|
}
|
|
18
32
|
|
|
19
33
|
export function App({ label = 'first', source = 'render' }: AppProps) {
|
|
34
|
+
const formatter = useMainThreadObject(formatterType, config.prefix);
|
|
35
|
+
const formatOnMainThread = (value: string): string => {
|
|
36
|
+
'main thread';
|
|
37
|
+
// Capture the handle itself so this runtime fixture does not require
|
|
38
|
+
// the separate compiler feature for narrowed member captures.
|
|
39
|
+
const target = formatter;
|
|
40
|
+
return target.format(value);
|
|
41
|
+
};
|
|
42
|
+
|
|
20
43
|
if (__BACKGROUND__) {
|
|
21
|
-
lastRenderPromise = runOnMainThread(
|
|
44
|
+
lastRenderPromise = runOnMainThread(formatOnMainThread)(`${source}:${label}`);
|
|
22
45
|
}
|
|
23
46
|
return <view id={label} />;
|
|
24
47
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { defineMainThreadObjectType, useMainThreadObject } from '@lynx-js/react/element-template';
|
|
4
|
+
|
|
5
|
+
describe('element-template MainThreadObject entry', () => {
|
|
6
|
+
it('exposes MainThreadObject APIs from the public ET alias', () => {
|
|
7
|
+
expect(defineMainThreadObjectType).toBeTypeOf('function');
|
|
8
|
+
expect(useMainThreadObject).toBeTypeOf('function');
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -19,9 +19,12 @@ describe('legacy internal guardrail', () => {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it('keeps the ET main-thread event loader surface minimal', () => {
|
|
22
|
-
expect(ElementTemplateInternal
|
|
22
|
+
expect('loadWorkletRuntime' in ElementTemplateInternal).toBe(false);
|
|
23
23
|
expect('loadWorkletRuntime' in ElementTemplateRuntime).toBe(false);
|
|
24
24
|
|
|
25
|
+
expect(ElementTemplateInternal.captureMainThreadObject({ value: 1 })).toBeUndefined();
|
|
26
|
+
expect('captureMainThreadObject' in ElementTemplateRuntime).toBe(false);
|
|
27
|
+
|
|
25
28
|
expect(ElementTemplateInternal.registerWorkletOnBackground).toBeTypeOf('function');
|
|
26
29
|
expect(() => ElementTemplateInternal.registerWorkletOnBackground('main-thread', 'hash', () => {})).not.toThrow();
|
|
27
30
|
expect('registerWorkletOnBackground' in ElementTemplateRuntime).toBe(false);
|