@lynx-js/react 0.128.0 → 0.129.1
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 +34 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/entry-re-eval.test.ts +161 -0
- package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
- package/runtime/__test__/core/reload-scoped-dual-thread-communication.test.ts +129 -0
- package/runtime/__test__/core/thread-function-call.test.ts +1 -0
- package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +2 -0
- package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
- package/runtime/__test__/element-template/native/index.test.ts +8 -0
- package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
- package/runtime/__test__/element-template/native/main-thread-ref-init-value.test.ts +100 -0
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +83 -0
- package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +104 -0
- package/runtime/__test__/element-template/native/reload.test.ts +79 -1
- package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +104 -47
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +7 -1
- package/runtime/__test__/element-template/runtime/background/re-eval-reload.test.ts +69 -0
- package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
- package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +31 -5
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +214 -10
- package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +2 -0
- package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
- package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +121 -26
- package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +89 -2
- package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +5 -0
- package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
- package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
- package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
- package/runtime/__test__/shared/component-stack.test.ts +211 -0
- package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
- package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
- package/runtime/__test__/snapshot/lifecycle/re-eval-reload.test.jsx +114 -0
- package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +169 -0
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +63 -0
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-main-thread.test.jsx +103 -0
- package/runtime/__test__/snapshot/lifecycle.test.jsx +61 -1
- package/runtime/__test__/snapshot/lynx/lazy-effect-scheduling.test.jsx +105 -0
- package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
- package/runtime/__test__/snapshot/preact.test.jsx +0 -3
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
- package/runtime/__test__/snapshot/ssr.test.jsx +2 -2
- package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +6 -11
- package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +1 -1
- package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +24 -1
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +27 -1
- package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +46 -0
- package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +3 -3
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
- package/runtime/lazy/element-template-internal.js +0 -1
- package/runtime/lazy/internal.js +1 -1
- package/runtime/lazy/jsx-dev-runtime.js +1 -1
- package/runtime/lazy/jsx-runtime.js +1 -1
- package/runtime/lazy/legacy-react-runtime.js +1 -1
- package/runtime/lazy/react-lepus.js +1 -1
- package/runtime/lazy/react.js +1 -1
- package/runtime/lib/core/background-function/exec-map.d.ts +2 -0
- package/runtime/lib/core/background-function/exec-map.js +7 -0
- package/runtime/lib/core/background-function/exec-map.js.map +1 -1
- package/runtime/lib/core/background-function/run-on-background.js +15 -16
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
- package/runtime/lib/core/capture-main-thread-object.js +2 -1
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
- package/runtime/lib/core/card-lifetime.d.ts +5 -0
- package/runtime/lib/core/card-lifetime.js +17 -0
- package/runtime/lib/core/card-lifetime.js.map +1 -0
- package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
- package/runtime/lib/core/entry-reload.d.ts +7 -0
- package/runtime/lib/core/entry-reload.js +49 -0
- package/runtime/lib/core/entry-reload.js.map +1 -0
- package/runtime/lib/core/lynx/lazy-bundle.js +5 -2
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
- package/runtime/lib/core/lynx-data-processors.js +3 -0
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/core/main-thread-ref-id.js +4 -4
- package/runtime/lib/core/main-thread-ref-id.js.map +1 -1
- package/runtime/lib/core/reload-scoped-event.d.ts +5 -0
- package/runtime/lib/core/reload-scoped-event.js +26 -0
- package/runtime/lib/core/reload-scoped-event.js.map +1 -0
- package/runtime/lib/core/reload-version.js +4 -3
- package/runtime/lib/core/reload-version.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.d.ts +2 -0
- package/runtime/lib/core/runtime-destroy.js +10 -1
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/core/thread-function-call/main-thread.js +5 -4
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- package/runtime/lib/core/thread-function-call/return-value.js +6 -5
- package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
- package/runtime/lib/document.js +0 -5
- package/runtime/lib/document.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js +24 -22
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js +2 -6
- package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
- package/runtime/lib/element-template/client/root.d.ts +1 -1
- package/runtime/lib/element-template/client/root.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +2 -2
- 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 +0 -13
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.js.map +1 -1
- package/runtime/lib/element-template/main-thread-ref-init-value.d.ts +3 -0
- package/runtime/lib/element-template/main-thread-ref-init-value.js +38 -0
- package/runtime/lib/element-template/main-thread-ref-init-value.js.map +1 -0
- package/runtime/lib/element-template/native/flush.d.ts +1 -0
- package/runtime/lib/element-template/native/flush.js +9 -0
- package/runtime/lib/element-template/native/flush.js.map +1 -0
- package/runtime/lib/element-template/native/index.js +2 -0
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/native/main-thread-api.js +3 -7
- package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js +10 -2
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +58 -54
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.d.ts +1 -1
- package/runtime/lib/element-template/native/reload-background.js +12 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.d.ts +6 -0
- package/runtime/lib/element-template/native/reload-main-thread.js +20 -3
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.d.ts +2 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.js +1 -0
- package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +0 -2
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
- package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js +4 -0
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -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.d.ts +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +41 -21
- 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-ref-ctx.d.ts +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.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 +2 -125
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/shared/component-stack.d.ts +0 -4
- package/runtime/lib/shared/component-stack.js +21 -5
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/shared/index-map.d.ts +4 -1
- package/runtime/lib/shared/index-map.js +5 -2
- package/runtime/lib/shared/index-map.js.map +1 -1
- package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
- package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
- package/runtime/lib/snapshot/lifecycle/destroy.js +6 -0
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.d.ts +6 -2
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js +21 -18
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.d.ts +9 -2
- package/runtime/lib/snapshot/lifecycle/reload.js +29 -8
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/list/list.js +3 -2
- package/runtime/lib/snapshot/list/list.js.map +1 -1
- package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
- package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +14 -11
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
- package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/list.js +2 -1
- package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.d.ts +4 -2
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js +11 -11
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +1 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +6 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ctx.d.ts +1 -1
- package/runtime/lib/snapshot/worklet/ctx.js +6 -1
- package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js +6 -0
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js +3 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +8 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/listeners.js +2 -2
- package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.js +3 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -1
- package/runtime/lib/worklet-runtime/runOnMainThread.js +4 -3
- package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/background-function/exec-map.ts +9 -0
- package/runtime/src/core/background-function/run-on-background.ts +14 -16
- package/runtime/src/core/capture-main-thread-object.ts +2 -1
- package/runtime/src/core/card-lifetime.ts +18 -0
- package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
- package/runtime/src/core/entry-reload.ts +63 -0
- package/runtime/src/core/lynx/lazy-bundle.ts +5 -2
- package/runtime/src/core/lynx-data-processors.ts +124 -1
- package/runtime/src/core/main-thread-ref-id.ts +5 -4
- package/runtime/src/core/reload-scoped-event.ts +35 -0
- package/runtime/src/core/reload-version.ts +5 -3
- package/runtime/src/core/runtime-destroy.ts +12 -1
- package/runtime/src/core/thread-function-call/main-thread.ts +4 -4
- package/runtime/src/core/thread-function-call/return-value.ts +6 -5
- package/runtime/src/document.ts +0 -6
- package/runtime/src/element-template/background/commit-hook.ts +32 -23
- package/runtime/src/element-template/background/hydration-listener.ts +2 -6
- package/runtime/src/element-template/client/root.ts +1 -3
- package/runtime/src/element-template/index.ts +2 -2
- package/runtime/src/element-template/internal.ts +0 -20
- package/runtime/src/element-template/lynx/env.ts +1 -1
- package/runtime/src/element-template/main-thread-ref-init-value.ts +44 -0
- package/runtime/src/element-template/native/flush.ts +10 -0
- package/runtime/src/element-template/native/index.ts +2 -0
- package/runtime/src/element-template/native/main-thread-api.ts +3 -6
- package/runtime/src/element-template/native/mts-destroy.ts +10 -2
- package/runtime/src/element-template/native/patch-listener.ts +62 -62
- package/runtime/src/element-template/native/reload-background.ts +13 -1
- package/runtime/src/element-template/native/reload-main-thread.ts +32 -3
- package/runtime/src/element-template/protocol/lifecycle-constant.ts +1 -0
- package/runtime/src/element-template/protocol/types.ts +0 -15
- package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
- package/runtime/src/element-template/runtime/patch.ts +5 -0
- package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
- package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +51 -21
- package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +2 -2
- package/runtime/src/element-template/types.d.ts +6 -0
- package/runtime/src/internal.ts +1 -1
- package/runtime/src/lynx-api.ts +2 -124
- package/runtime/src/shared/component-stack.ts +22 -5
- package/runtime/src/shared/index-map.ts +3 -2
- package/runtime/src/snapshot/lifecycle/destroy.ts +7 -0
- package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +26 -19
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
- package/runtime/src/snapshot/lifecycle/reload.ts +47 -11
- package/runtime/src/snapshot/list/list.ts +9 -2
- package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
- package/runtime/src/snapshot/lynx/calledByNative.ts +14 -13
- package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
- package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
- package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
- package/runtime/src/snapshot/snapshot/list.ts +5 -1
- package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +19 -12
- package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +10 -1
- package/runtime/src/snapshot/worklet/ctx.ts +10 -1
- package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +6 -0
- package/runtime/src/worklet-runtime/README.md +33 -0
- package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
- package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
- package/runtime/src/worklet-runtime/delayRunOnBackground.ts +3 -1
- package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +8 -1
- package/runtime/src/worklet-runtime/listeners.ts +4 -7
- package/runtime/src/worklet-runtime/mainThreadObject.ts +2 -1
- package/runtime/src/worklet-runtime/runOnMainThread.ts +4 -3
- package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
- package/runtime/types/types.d.ts +3 -1
- package/runtime/vitest.config.ts +0 -2
- package/testing-library/.turbo/turbo-build.log +7 -7
- package/testing-library/src/__tests__/act.test.jsx +0 -7
- package/testing-library/src/__tests__/alog.test.jsx +12 -54
- package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
- package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
- package/testing-library/src/__tests__/worklet.test.jsx +59 -5
- package/transform/.turbo/turbo-build$colon$wasm.log +63 -136
- package/transform/__test__/defines.spec.js +137 -0
- package/transform/__test__/object-methods.spec.js +79 -0
- package/transform/crates/swc_plugin_worklet/definition_imports.rs +97 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +56 -48
- package/transform/crates/swc_plugin_worklet/lib.rs +400 -595
- package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +6 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +9 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +12 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +1 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +1 -1
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +3 -1
- package/transform/package.json +0 -1
- package/transform/src/lib.rs +173 -12
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +105 -32
- package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +193 -194
- package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
- package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
- package/runtime/lib/snapshot/worklet/hmr.js +0 -28
- package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
- package/runtime/src/snapshot/worklet/hmr.ts +0 -34
- /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
- /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { createElement } from 'preact';
|
|
5
|
+
import { useLayoutEffect } from 'preact/hooks';
|
|
6
|
+
import { expect, it, vi } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
delayedRunOnMainThreadData,
|
|
10
|
+
takeDelayedRunOnMainThreadData,
|
|
11
|
+
} from '../../../src/core/thread-function-call/main-thread.js';
|
|
12
|
+
import { resetFunctionCallReturnListener } from '../../../src/core/thread-function-call/return-value.js';
|
|
13
|
+
import { root } from '../../../src/lynx-api.js';
|
|
14
|
+
import { __root } from '../../../src/root.js';
|
|
15
|
+
import { destroyBackground } from '../../../src/snapshot/lifecycle/destroy.js';
|
|
16
|
+
import { globalCommitTaskMap } from '../../../src/snapshot/lifecycle/patch/commit.js';
|
|
17
|
+
import { reloadBackground } from '../../../src/snapshot/lifecycle/reload.js';
|
|
18
|
+
import { setupPage } from '../../../src/snapshot/index.js';
|
|
19
|
+
import { runOnMainThread } from '../../../src/snapshot/worklet/call/runOnMainThread.js';
|
|
20
|
+
import { registerWorklet } from '../../../src/worklet-runtime/bindings/index.js';
|
|
21
|
+
import { initWorklet } from '../../../src/worklet-runtime/workletRuntime.js';
|
|
22
|
+
import { globalEnvManager } from '../utils/envManager.js';
|
|
23
|
+
import { elementTree } from '../utils/nativeMethod.js';
|
|
24
|
+
|
|
25
|
+
it('drops pre-hydration and unmount calls before a reload reuses their return IDs', async () => {
|
|
26
|
+
const oldResult = vi.fn();
|
|
27
|
+
const cleanupResult = vi.fn();
|
|
28
|
+
const cleanup = vi.fn(() => {
|
|
29
|
+
void runOnMainThread({ _wkltId: 'unmount-call' })().then(cleanupResult);
|
|
30
|
+
expect(delayedRunOnMainThreadData.map(data => data.resolveId)).toEqual([1, 2]);
|
|
31
|
+
});
|
|
32
|
+
function App() {
|
|
33
|
+
useLayoutEffect(() => cleanup, []);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const oldCall = vi.fn(() => 'old-page');
|
|
38
|
+
const unmountCall = vi.fn(() => 'old-page');
|
|
39
|
+
const newCall = vi.fn(() => 'new-page');
|
|
40
|
+
const workletGlobals = {
|
|
41
|
+
lynxWorkletImpl: globalThis.lynxWorkletImpl,
|
|
42
|
+
runWorklet: globalThis.runWorklet,
|
|
43
|
+
registerWorklet: globalThis.registerWorklet,
|
|
44
|
+
registerWorkletInternal: globalThis.registerWorkletInternal,
|
|
45
|
+
};
|
|
46
|
+
const sdkVersion = SystemInfo.lynxSdkVersion;
|
|
47
|
+
globalEnvManager.resetEnv();
|
|
48
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
49
|
+
try {
|
|
50
|
+
initWorklet();
|
|
51
|
+
registerWorklet('main-thread', 'old-call', oldCall);
|
|
52
|
+
registerWorklet('main-thread', 'unmount-call', unmountCall);
|
|
53
|
+
registerWorklet('main-thread', 'new-call', newCall);
|
|
54
|
+
setupPage(__CreatePage('0', 0));
|
|
55
|
+
__root.__jsx = null;
|
|
56
|
+
renderPage({});
|
|
57
|
+
globalEnvManager.switchToBackground();
|
|
58
|
+
root.render(createElement(App));
|
|
59
|
+
void runOnMainThread({ _wkltId: 'old-call' })().then(oldResult);
|
|
60
|
+
expect(delayedRunOnMainThreadData[0]?.resolveId).toBe(1);
|
|
61
|
+
|
|
62
|
+
reloadBackground({});
|
|
63
|
+
expect(cleanup).toHaveBeenCalledOnce();
|
|
64
|
+
// Both threads share resolver state in this harness. Complete MTS reload
|
|
65
|
+
// before creating the replacement BTS call, then deliver its hydration.
|
|
66
|
+
globalEnvManager.switchToMainThread();
|
|
67
|
+
updatePage({}, { reloadTemplate: true });
|
|
68
|
+
globalEnvManager.switchToBackground();
|
|
69
|
+
const result = runOnMainThread({ _wkltId: 'new-call' })();
|
|
70
|
+
expect(delayedRunOnMainThreadData.at(-1)?.resolveId).toBe(1);
|
|
71
|
+
|
|
72
|
+
lynx.getNativeApp().callLepusMethod.mockClear();
|
|
73
|
+
lynx.getApp().OnLifecycleEvent(...__OnLifecycleEvent.mock.lastCall);
|
|
74
|
+
const [method, patch, complete] = lynx.getNativeApp().callLepusMethod.mock.lastCall;
|
|
75
|
+
expect(patch.patchOptions.isHydration).toBe(true);
|
|
76
|
+
expect(JSON.parse(patch.data).delayedRunOnMainThreadData).toEqual([
|
|
77
|
+
{ worklet: expect.objectContaining({ _wkltId: 'new-call' }), params: [], resolveId: 1 },
|
|
78
|
+
]);
|
|
79
|
+
globalEnvManager.switchToMainThread();
|
|
80
|
+
globalThis[method](patch);
|
|
81
|
+
globalEnvManager.switchToBackground();
|
|
82
|
+
complete();
|
|
83
|
+
|
|
84
|
+
await expect(result).resolves.toBe('new-page');
|
|
85
|
+
expect(newCall).toHaveBeenCalledExactlyOnceWith();
|
|
86
|
+
expect(oldCall).not.toHaveBeenCalled();
|
|
87
|
+
expect(unmountCall).not.toHaveBeenCalled();
|
|
88
|
+
expect(oldResult).not.toHaveBeenCalled();
|
|
89
|
+
expect(cleanupResult).not.toHaveBeenCalled();
|
|
90
|
+
} finally {
|
|
91
|
+
cleanup.mockImplementation(() => {});
|
|
92
|
+
globalEnvManager.switchToBackground();
|
|
93
|
+
destroyBackground();
|
|
94
|
+
takeDelayedRunOnMainThreadData();
|
|
95
|
+
resetFunctionCallReturnListener();
|
|
96
|
+
globalCommitTaskMap.clear();
|
|
97
|
+
globalEnvManager.resetEnv();
|
|
98
|
+
elementTree.clear();
|
|
99
|
+
Object.assign(globalThis, workletGlobals);
|
|
100
|
+
SystemInfo.lynxSdkVersion = sdkVersion;
|
|
101
|
+
vi.restoreAllMocks();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
@@ -5,11 +5,19 @@ import { useEffect, useLayoutEffect, useState } from '../../src/index';
|
|
|
5
5
|
import { globalEnvManager } from './utils/envManager';
|
|
6
6
|
import { waitSchedule } from './utils/nativeMethod';
|
|
7
7
|
import { globalCommitTaskMap, replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
__globalSnapshotPatch,
|
|
10
|
+
deinitGlobalSnapshotPatch,
|
|
11
|
+
initGlobalSnapshotPatch,
|
|
12
|
+
} from '../../src/snapshot/lifecycle/patch/snapshotPatch';
|
|
9
13
|
import { LifecycleConstant } from '../../src/snapshot/lifecycle/constant';
|
|
10
14
|
import { CATCH_ERROR } from '../../src/shared/render-constants';
|
|
11
15
|
import { __root } from '../../src/root';
|
|
12
16
|
import { setupPage, backgroundSnapshotInstanceManager } from '../../src/snapshot';
|
|
17
|
+
import { onFunctionCall, resetFunctionCallReturnListener } from '../../src/core/thread-function-call/return-value.js';
|
|
18
|
+
import { getReloadVersion } from '../../src/core/reload-version.js';
|
|
19
|
+
import { reloadBackground } from '../../src/snapshot/lifecycle/reload.js';
|
|
20
|
+
import { WorkletEvents } from '../../src/worklet-runtime/bindings/events.js';
|
|
13
21
|
|
|
14
22
|
beforeAll(() => {
|
|
15
23
|
setupPage(__CreatePage('0', 0));
|
|
@@ -673,3 +681,55 @@ describe('componentDidUpdate', () => {
|
|
|
673
681
|
expect(callback).nthCalledWith(2, 2);
|
|
674
682
|
});
|
|
675
683
|
});
|
|
684
|
+
|
|
685
|
+
it.each(['page close', 'reload'])('cleans Snapshot patches and return listeners on %s', (boundary) => {
|
|
686
|
+
globalEnvManager.switchToBackground();
|
|
687
|
+
const context = lynx.getCoreContext();
|
|
688
|
+
const addListener = vi.spyOn(context, 'addEventListener').mockClear();
|
|
689
|
+
const removeListener = vi.spyOn(context, 'removeEventListener').mockClear();
|
|
690
|
+
const oldResolve = vi.fn();
|
|
691
|
+
let patchDuringUnmount = null;
|
|
692
|
+
const unmount = vi.fn(() => {
|
|
693
|
+
patchDuringUnmount = __globalSnapshotPatch;
|
|
694
|
+
// Cleanup can itself create a pending cross-thread call.
|
|
695
|
+
onFunctionCall(oldResolve);
|
|
696
|
+
});
|
|
697
|
+
class Comp extends Component {
|
|
698
|
+
componentWillUnmount() {
|
|
699
|
+
unmount();
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
render() {
|
|
703
|
+
return null;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
try {
|
|
708
|
+
__root.__jsx = <Comp />;
|
|
709
|
+
render(__root.__jsx, __root);
|
|
710
|
+
initGlobalSnapshotPatch();
|
|
711
|
+
__globalSnapshotPatch.push('pending patch');
|
|
712
|
+
onFunctionCall(oldResolve);
|
|
713
|
+
|
|
714
|
+
if (boundary === 'page close') lynx.getApp().callDestroyLifetimeFun();
|
|
715
|
+
else reloadBackground({});
|
|
716
|
+
|
|
717
|
+
expect(unmount).toHaveBeenCalledOnce();
|
|
718
|
+
expect.soft(patchDuringUnmount).toBeUndefined();
|
|
719
|
+
expect.soft(__globalSnapshotPatch).toBeUndefined();
|
|
720
|
+
for (const [type, listener] of addListener.mock.calls) {
|
|
721
|
+
if (type === WorkletEvents.FunctionCallRet) {
|
|
722
|
+
expect.soft(removeListener).toHaveBeenCalledWith(type, listener);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const newResolve = vi.fn();
|
|
727
|
+
const resolveId = onFunctionCall(newResolve);
|
|
728
|
+
const listener = addListener.mock.lastCall[1];
|
|
729
|
+
listener({ data: JSON.stringify({ resolveId, returnValue: 'new result', reloadVersion: getReloadVersion() }) });
|
|
730
|
+
expect(newResolve).toHaveBeenCalledWith('new result');
|
|
731
|
+
expect(oldResolve).not.toHaveBeenCalled();
|
|
732
|
+
} finally {
|
|
733
|
+
resetFunctionCallReturnListener();
|
|
734
|
+
}
|
|
735
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { options, render } from 'preact';
|
|
6
|
+
import { createElement } from 'preact/compat';
|
|
7
|
+
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { lazy, useEffect, useRef, useState } from '../../../src/index.js';
|
|
10
|
+
import { makeSyncThen } from '../../../src/core/lynx/lazy-bundle.js';
|
|
11
|
+
import { __root } from '../../../src/root.js';
|
|
12
|
+
import { globalEnvManager } from '../utils/envManager.js';
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
vi.restoreAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('synchronous lazy imports with cached Promise.resolve results', () => {
|
|
19
|
+
test.each([undefined, null, true, false, 0, ''])(
|
|
20
|
+
'keeps the shared promise for %j asynchronous',
|
|
21
|
+
async (value) => {
|
|
22
|
+
const resolve = Promise.resolve.bind(Promise);
|
|
23
|
+
const shared = resolve(value);
|
|
24
|
+
const originalThen = shared.then;
|
|
25
|
+
// The Lynx Promise polyfill reuses fulfilled promises for these values.
|
|
26
|
+
vi.spyOn(Promise, 'resolve').mockImplementation(result => result === value ? shared : resolve(result));
|
|
27
|
+
|
|
28
|
+
const promise = makeSyncThen('exports').call(resolve('exports'), () => value);
|
|
29
|
+
let lazyCallbackCalled = false;
|
|
30
|
+
promise.then(result => {
|
|
31
|
+
expect(result).toBe(value);
|
|
32
|
+
lazyCallbackCalled = true;
|
|
33
|
+
});
|
|
34
|
+
expect(lazyCallbackCalled).toBe(true);
|
|
35
|
+
expect(shared.then).toBe(originalThen);
|
|
36
|
+
|
|
37
|
+
let ordinaryCallbackCalled = false;
|
|
38
|
+
Promise.resolve(value).then(() => {
|
|
39
|
+
ordinaryCallbackCalled = true;
|
|
40
|
+
});
|
|
41
|
+
expect(ordinaryCallbackCalled).toBe(false);
|
|
42
|
+
await resolve();
|
|
43
|
+
expect(ordinaryCallbackCalled).toBe(true);
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
test('a cached lazy child mount effect can update its parent without re-entering', async () => {
|
|
48
|
+
globalEnvManager.resetEnv();
|
|
49
|
+
globalEnvManager.switchToBackground();
|
|
50
|
+
const previousDebounce = options.debounceRendering;
|
|
51
|
+
const previousRaf = options.requestAnimationFrame;
|
|
52
|
+
const resolve = Promise.resolve.bind(Promise);
|
|
53
|
+
const sharedUndefined = resolve();
|
|
54
|
+
vi.spyOn(Promise, 'resolve').mockImplementation(value => value === undefined ? sharedUndefined : resolve(value));
|
|
55
|
+
|
|
56
|
+
// This is Preact's fallback scheduler in Lynx runtimes without the global
|
|
57
|
+
// queueMicrotask API. Its Promise.resolve must remain asynchronous.
|
|
58
|
+
options.debounceRendering = callback => Promise.resolve().then(callback);
|
|
59
|
+
let flushEffects;
|
|
60
|
+
options.requestAnimationFrame = callback => {
|
|
61
|
+
flushEffects = callback;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const calls = [];
|
|
65
|
+
let parentValue;
|
|
66
|
+
function Leaf({ notify }) {
|
|
67
|
+
const count = useRef(0);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
count.current++;
|
|
70
|
+
calls.push(['effect', count.current]);
|
|
71
|
+
notify();
|
|
72
|
+
return () => calls.push(['cleanup', count.current]);
|
|
73
|
+
}, []);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const exports = { default: Leaf };
|
|
77
|
+
const cached = resolve(exports);
|
|
78
|
+
cached.then = makeSyncThen(exports);
|
|
79
|
+
const Remote = lazy(() => cached);
|
|
80
|
+
function App() {
|
|
81
|
+
const [value, setValue] = useState(0);
|
|
82
|
+
parentValue = value;
|
|
83
|
+
return createElement(Remote, { notify: () => setValue(v => v + 1) });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
render(createElement(App), __root);
|
|
88
|
+
flushEffects();
|
|
89
|
+
expect(calls).toEqual([['effect', 1]]);
|
|
90
|
+
expect(parentValue).toBe(0);
|
|
91
|
+
await resolve();
|
|
92
|
+
expect(parentValue).toBe(1);
|
|
93
|
+
expect(calls).toEqual([['effect', 1]]);
|
|
94
|
+
|
|
95
|
+
render(null, __root);
|
|
96
|
+
flushEffects();
|
|
97
|
+
expect(calls).toEqual([['effect', 1], ['cleanup', 1]]);
|
|
98
|
+
} finally {
|
|
99
|
+
render(null, __root);
|
|
100
|
+
flushEffects?.();
|
|
101
|
+
options.debounceRendering = previousDebounce;
|
|
102
|
+
options.requestAnimationFrame = previousRaf;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -9,6 +9,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite
|
|
|
9
9
|
import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit';
|
|
10
10
|
import { injectUpdateMainThread } from '../../../src/snapshot/lifecycle/patch/updateMainThread';
|
|
11
11
|
import { installComponentCompat } from '../../../src/core/component';
|
|
12
|
+
import { globalPipelineOptions } from '../../../src/core/performance';
|
|
12
13
|
import { initTimingAPI } from '../../../src/snapshot/lynx/performance';
|
|
13
14
|
import { __root } from '../../../src/root';
|
|
14
15
|
import { setupPage } from '../../../src/snapshot';
|
|
@@ -128,6 +129,7 @@ describe('setState timing api', () => {
|
|
|
128
129
|
|
|
129
130
|
globalEnvManager.switchToMainThread();
|
|
130
131
|
rLynxChange(mtCallbacks[0][1]);
|
|
132
|
+
expect(globalPipelineOptions).toBeUndefined();
|
|
131
133
|
expect(__root.__element_root).toMatchInlineSnapshot(`
|
|
132
134
|
<page
|
|
133
135
|
cssId="default-entry-from-native:0"
|
|
@@ -210,6 +212,7 @@ describe('attribute timing api', () => {
|
|
|
210
212
|
|
|
211
213
|
globalEnvManager.switchToMainThread();
|
|
212
214
|
rLynxChange(mtCallbacks[0][1]);
|
|
215
|
+
expect(globalPipelineOptions).toBeUndefined();
|
|
213
216
|
expect(__root.__element_root).toMatchInlineSnapshot(`
|
|
214
217
|
<page
|
|
215
218
|
cssId="default-entry-from-native:0"
|
|
@@ -93,9 +93,6 @@ function collectSnapshotPatchOps(patch) {
|
|
|
93
93
|
case SnapshotOperation.DEV_ONLY_AddSnapshot:
|
|
94
94
|
i += 2;
|
|
95
95
|
break;
|
|
96
|
-
case SnapshotOperation.DEV_ONLY_RegisterWorklet:
|
|
97
|
-
i += 2;
|
|
98
|
-
break;
|
|
99
96
|
case SnapshotOperation.DEV_ONLY_SetSnapshotEntryName:
|
|
100
97
|
i += 2;
|
|
101
98
|
break;
|
|
@@ -5,7 +5,6 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite
|
|
|
5
5
|
|
|
6
6
|
import { globalEnvManager } from './utils/envManager';
|
|
7
7
|
import { elementTree } from './utils/nativeMethod';
|
|
8
|
-
import { registerWorkletOnBackground } from '../../src/internal';
|
|
9
8
|
import { addCtxNotFoundEventListener } from '../../src/snapshot/lifecycle/patch/error';
|
|
10
9
|
import {
|
|
11
10
|
SnapshotOperation,
|
|
@@ -1637,38 +1636,6 @@ describe('DEV_ONLY_addSnapshot', () => {
|
|
|
1637
1636
|
});
|
|
1638
1637
|
});
|
|
1639
1638
|
|
|
1640
|
-
describe.skip('DEV_ONLY_RegisterWorklet', () => {
|
|
1641
|
-
beforeEach(() => {
|
|
1642
|
-
initGlobalSnapshotPatch();
|
|
1643
|
-
});
|
|
1644
|
-
|
|
1645
|
-
it('basic', () => {
|
|
1646
|
-
registerWorkletOnBackground('main-thread', 'hash-1', () => 'fn-1');
|
|
1647
|
-
globalThis.registerWorklet = vi.fn();
|
|
1648
|
-
|
|
1649
|
-
const patch = takeGlobalSnapshotPatch();
|
|
1650
|
-
|
|
1651
|
-
expect(patch).toMatchInlineSnapshot(`
|
|
1652
|
-
[
|
|
1653
|
-
101,
|
|
1654
|
-
"hash-1",
|
|
1655
|
-
"() => "fn-1"",
|
|
1656
|
-
]
|
|
1657
|
-
`);
|
|
1658
|
-
|
|
1659
|
-
// Apply patches in main thread
|
|
1660
|
-
snapshotPatchApply(patch, 42, false);
|
|
1661
|
-
|
|
1662
|
-
expect(globalThis.registerWorklet).toBeCalledTimes(1);
|
|
1663
|
-
expect(globalThis.registerWorklet.mock.calls[0][0]).toMatch('main-thread');
|
|
1664
|
-
expect(globalThis.registerWorklet.mock.calls[0][1]).toMatch('hash-1');
|
|
1665
|
-
expect(globalThis.registerWorklet.mock.calls[0][2]()).toMatch('fn-1');
|
|
1666
|
-
|
|
1667
|
-
registerWorkletOnBackground('main-thread', 'hash-1', () => 'fn-1');
|
|
1668
|
-
expect(globalThis.registerWorklet).toBeCalledTimes(1);
|
|
1669
|
-
});
|
|
1670
|
-
});
|
|
1671
|
-
|
|
1672
1639
|
describe('list', () => {
|
|
1673
1640
|
beforeEach(() => {
|
|
1674
1641
|
initGlobalSnapshotPatch();
|
|
@@ -5,7 +5,7 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi }
|
|
|
5
5
|
import { globalEnvManager } from './utils/envManager';
|
|
6
6
|
import { elementTree, options } from './utils/nativeMethod';
|
|
7
7
|
import { __page as __internalPage } from '../../src/internal';
|
|
8
|
-
import {
|
|
8
|
+
import { firstScreenSync } from '../../src/snapshot/lifecycle/event/firstScreenSync';
|
|
9
9
|
import { __root } from '../../src/root';
|
|
10
10
|
import { clearPage } from '../../src/snapshot';
|
|
11
11
|
|
|
@@ -467,7 +467,7 @@ describe('ssr', () => {
|
|
|
467
467
|
|
|
468
468
|
ssrHydrate(info);
|
|
469
469
|
expect(__internalPage).toBe(__page);
|
|
470
|
-
expect(
|
|
470
|
+
expect(firstScreenSync.eventIdSwap).toEqual({});
|
|
471
471
|
{
|
|
472
472
|
const listRef = elementTree.getElementById('ssr-list');
|
|
473
473
|
expect(elementTree.triggerComponentAtIndex(listRef, 0)).toEqual(uiSign1);
|
|
@@ -40,7 +40,7 @@ describe('runOnBackground', () => {
|
|
|
40
40
|
[
|
|
41
41
|
[
|
|
42
42
|
{
|
|
43
|
-
"data": "{"obj":{"_jsFnId":233,"_execId":244},"params":[1,["args"]],"resolveId":1}",
|
|
43
|
+
"data": "{"obj":{"_jsFnId":233,"_execId":244},"params":[1,["args"]],"resolveId":1,"reloadVersion":0}",
|
|
44
44
|
"type": "Lynx.Worklet.runOnBackground",
|
|
45
45
|
},
|
|
46
46
|
],
|
|
@@ -69,7 +69,7 @@ describe('runOnBackground', () => {
|
|
|
69
69
|
[
|
|
70
70
|
[
|
|
71
71
|
{
|
|
72
|
-
"data": "{"obj":{"_jsFnId":7,"_execId":8},"params":[1,["args"]],"resolveId":1}",
|
|
72
|
+
"data": "{"obj":{"_jsFnId":7,"_execId":8},"params":[1,["args"]],"resolveId":1,"reloadVersion":0}",
|
|
73
73
|
"type": "Lynx.Worklet.runOnBackground",
|
|
74
74
|
},
|
|
75
75
|
],
|
|
@@ -111,14 +111,9 @@ describe('runOnBackground', () => {
|
|
|
111
111
|
|
|
112
112
|
expect(() => {
|
|
113
113
|
runJSFunction({
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
_execId: id,
|
|
118
|
-
},
|
|
119
|
-
params: [],
|
|
120
|
-
resolveId: 1,
|
|
121
|
-
}),
|
|
114
|
+
obj: { _jsFnId: 234, _execId: id },
|
|
115
|
+
params: [],
|
|
116
|
+
resolveId: 1,
|
|
122
117
|
});
|
|
123
118
|
}).toThrowError('runOnBackground: JS function not found');
|
|
124
119
|
});
|
|
@@ -229,6 +224,6 @@ describe('runJSFunction', () => {
|
|
|
229
224
|
data: [id],
|
|
230
225
|
});
|
|
231
226
|
|
|
232
|
-
expect(trigger).toThrow(
|
|
227
|
+
expect(trigger).toThrow(`runOnBackground: JS function not found: {"_jsFnId":233,"_execId":${id}}`);
|
|
233
228
|
});
|
|
234
229
|
});
|
|
@@ -90,7 +90,7 @@ describe('runOnMainThread', () => {
|
|
|
90
90
|
[
|
|
91
91
|
[
|
|
92
92
|
{
|
|
93
|
-
"data": "{"worklet":{"_wkltId":"835d:450ef:2"},"params":[1,["args"]],"resolveId":1}",
|
|
93
|
+
"data": "{"worklet":{"_wkltId":"835d:450ef:2"},"params":[1,["args"]],"resolveId":1,"reloadVersion":0}",
|
|
94
94
|
"type": "Lynx.Worklet.runWorkletCtx",
|
|
95
95
|
},
|
|
96
96
|
],
|
|
@@ -16,7 +16,10 @@ import { MainThreadRef, isMainThreadRef, useMainThreadRef } from '../../../src/c
|
|
|
16
16
|
import { isMainThreadFunction } from '../../../src/core/main-thread-function';
|
|
17
17
|
import { takeMainThreadRefInitValuePatch } from '../../../src/core/main-thread-ref-init-value';
|
|
18
18
|
import { globalEnvManager } from '../utils/envManager';
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
injectUpdateMTRefInitValue,
|
|
21
|
+
sendMTRefInitValueToMainThread,
|
|
22
|
+
} from '../../../src/snapshot/worklet/ref/updateInitValue';
|
|
20
23
|
|
|
21
24
|
const Comp = () => {
|
|
22
25
|
const ref = useMainThreadRef(233);
|
|
@@ -51,6 +54,7 @@ beforeEach(() => {
|
|
|
51
54
|
});
|
|
52
55
|
|
|
53
56
|
afterEach(() => {
|
|
57
|
+
globalThis.__ALOG__ = true;
|
|
54
58
|
destroyWorklet();
|
|
55
59
|
vi.clearAllMocks();
|
|
56
60
|
});
|
|
@@ -151,6 +155,13 @@ describe('WorkletRef in js', () => {
|
|
|
151
155
|
expect(globalThis.lynxWorkletImpl._refImpl.updateWorkletRefInitValueChanges).toBeCalledTimes(1);
|
|
152
156
|
globalThis[rLynxChange[1][0]](rLynxChange[1][1]);
|
|
153
157
|
expect(globalThis.lynxWorkletImpl._refImpl.updateWorkletRefInitValueChanges).toBeCalledTimes(1);
|
|
158
|
+
const logs = console.alog.mock.calls.map(([message]) => message).filter(message =>
|
|
159
|
+
message.includes('MTRefInitValue')
|
|
160
|
+
);
|
|
161
|
+
expect(logs).toEqual([
|
|
162
|
+
'[ReactLynxDebug] Snapshot BTS -> MTS sendMTRefInitValue:\n[[1,233]]',
|
|
163
|
+
'[ReactLynxDebug] Snapshot MTS updateMTRefInitValue:\n[[1,233]]',
|
|
164
|
+
]);
|
|
154
165
|
}
|
|
155
166
|
});
|
|
156
167
|
|
|
@@ -176,6 +187,18 @@ describe('WorkletRef in js', () => {
|
|
|
176
187
|
);
|
|
177
188
|
});
|
|
178
189
|
|
|
190
|
+
it.each([false, undefined])('should initialize refs without alog when the flag is %s', (alog) => {
|
|
191
|
+
globalThis.__ALOG__ = alog;
|
|
192
|
+
globalEnvManager.switchToBackground();
|
|
193
|
+
new MainThreadRef(233);
|
|
194
|
+
sendMTRefInitValueToMainThread();
|
|
195
|
+
const [name, data] = lynx.getNativeApp().callLepusMethod.mock.calls.at(-1);
|
|
196
|
+
globalEnvManager.switchToMainThread();
|
|
197
|
+
globalThis[name](data);
|
|
198
|
+
expect(globalThis.lynxWorkletImpl._refImpl.updateWorkletRefInitValueChanges).toHaveBeenCalledWith([[1, 233]]);
|
|
199
|
+
expect(console.alog.mock.calls.some(([message]) => message.includes('MTRefInitValue'))).toBe(false);
|
|
200
|
+
});
|
|
201
|
+
|
|
179
202
|
it('should not send init value to the main thread when native capabilities not fulfilled', () => {
|
|
180
203
|
SystemInfo.lynxSdkVersion = '2.13';
|
|
181
204
|
const Comp = () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
import { beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
|
|
6
6
|
import { JsFunctionLifecycleManager } from '../../src/worklet-runtime/jsFunctionLifecycle';
|
|
7
7
|
|
|
@@ -86,4 +86,30 @@ describe('jsFunctionLifecycle', () => {
|
|
|
86
86
|
}
|
|
87
87
|
`);
|
|
88
88
|
});
|
|
89
|
+
it('leaves failed registrations retryable', () => {
|
|
90
|
+
const manager = new JsFunctionLifecycleManager();
|
|
91
|
+
const target = {};
|
|
92
|
+
const error = new TypeError('target must be an object');
|
|
93
|
+
const register = vi.spyOn(manager.registry, 'register').mockImplementationOnce(() => {
|
|
94
|
+
throw error;
|
|
95
|
+
});
|
|
96
|
+
expect(() => manager.addRef(3, target)).toThrow(error);
|
|
97
|
+
expect(manager.execIdRefCount.size).toBe(0);
|
|
98
|
+
expect(manager.retainedObjects.has(target)).toBe(false);
|
|
99
|
+
manager.addRef(3, target);
|
|
100
|
+
expect(register).toHaveBeenCalledTimes(2);
|
|
101
|
+
expect(manager.execIdRefCount.get(3)).toBe(1);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('does not release a new runtime execution when retired finalizers run', () => {
|
|
105
|
+
const previous = new JsFunctionLifecycleManager();
|
|
106
|
+
previous.addRef(3, {});
|
|
107
|
+
previous.removeRef(3);
|
|
108
|
+
previous.dispose();
|
|
109
|
+
const current = new JsFunctionLifecycleManager();
|
|
110
|
+
current.addRef(3, {});
|
|
111
|
+
previous.fire();
|
|
112
|
+
expect(events).toEqual([]);
|
|
113
|
+
expect(current.execIdRefCount.get(3)).toBe(1);
|
|
114
|
+
});
|
|
89
115
|
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
describe('worklet-runtime legacy fallback', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
vi.resetModules();
|
|
9
|
+
vi.stubGlobal('__LoadLepusChunk', undefined);
|
|
10
|
+
vi.stubGlobal('lynxWorkletImpl', undefined);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
vi.unstubAllGlobals();
|
|
15
|
+
vi.resetModules();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('exports the compatibility helper without initializing the worklet runtime', async () => {
|
|
19
|
+
const reactInternal = await import('@lynx-js/react/internal');
|
|
20
|
+
const bindings = await import('@lynx-js/react/worklet-runtime/bindings');
|
|
21
|
+
|
|
22
|
+
expect(reactInternal.loadWorkletRuntime).toBeTypeOf('function');
|
|
23
|
+
expect(reactInternal.loadWorkletRuntime).toBe(bindings.loadWorkletRuntime);
|
|
24
|
+
expect(globalThis.lynxWorkletImpl).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('returns false when the legacy chunk loader is unavailable', async () => {
|
|
28
|
+
const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
|
|
29
|
+
|
|
30
|
+
expect(loadWorkletRuntime('__Card__')).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('reuses the in-memory runtime without loading the legacy chunk', async () => {
|
|
34
|
+
const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
|
|
35
|
+
const runtime = { _workletMap: {} };
|
|
36
|
+
const loader = vi.fn();
|
|
37
|
+
vi.stubGlobal('lynxWorkletImpl', runtime);
|
|
38
|
+
vi.stubGlobal('__LoadLepusChunk', loader);
|
|
39
|
+
|
|
40
|
+
expect(loadWorkletRuntime('__Card__')).toBe(true);
|
|
41
|
+
expect(globalThis.lynxWorkletImpl).toBe(runtime);
|
|
42
|
+
expect(loader).not.toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it.each([true, false])('returns the legacy chunk loader result (%s)', async (result) => {
|
|
46
|
+
const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
|
|
47
|
+
const loader = vi.fn(() => result);
|
|
48
|
+
vi.stubGlobal('__LoadLepusChunk', loader);
|
|
49
|
+
|
|
50
|
+
expect(loadWorkletRuntime('__Card__')).toBe(result);
|
|
51
|
+
expect(loader).toHaveBeenCalledExactlyOnceWith('worklet-runtime', {
|
|
52
|
+
dynamicComponentEntry: '__Card__',
|
|
53
|
+
chunkType: 0,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('supports callers without a dynamic component entry', async () => {
|
|
58
|
+
const { loadWorkletRuntime } = await import('@lynx-js/react/internal');
|
|
59
|
+
const loader = vi.fn(() => true);
|
|
60
|
+
vi.stubGlobal('__LoadLepusChunk', loader);
|
|
61
|
+
|
|
62
|
+
expect(loadWorkletRuntime()).toBe(true);
|
|
63
|
+
expect(loader).toHaveBeenCalledExactlyOnceWith('worklet-runtime', {
|
|
64
|
+
dynamicComponentEntry: undefined,
|
|
65
|
+
chunkType: 0,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -152,6 +152,52 @@ describe('MainThreadObject registry and realization', () => {
|
|
|
152
152
|
}).not.toThrow();
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
+
it('keeps the resolved factory when the same create is registered again', () => {
|
|
156
|
+
const create = vi.fn(value => ({ value }));
|
|
157
|
+
const createDescriptor = { _wkltId: 'create-repeat' };
|
|
158
|
+
globalThis.registerWorklet('main-thread', 'create-repeat', create);
|
|
159
|
+
const lookupFactory = vi.fn(() => create);
|
|
160
|
+
Object.defineProperty(lynxWorkletImpl._workletMap, 'create-repeat', { get: lookupFactory });
|
|
161
|
+
|
|
162
|
+
const register = () =>
|
|
163
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType('@test/repeat', createDescriptor);
|
|
164
|
+
register();
|
|
165
|
+
updateWorkletRefInitValueChanges([[81, 'first', '@test/repeat']]);
|
|
166
|
+
// `useMainThreadObject` registers the type again on its first use.
|
|
167
|
+
register();
|
|
168
|
+
updateWorkletRefInitValueChanges([[82, 'second', '@test/repeat']]);
|
|
169
|
+
|
|
170
|
+
expect(lookupFactory).toHaveBeenCalledOnce();
|
|
171
|
+
removeValueFromWorkletRefMap(81);
|
|
172
|
+
removeValueFromWorkletRefMap(82);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('uses the factory of the latest evaluation of the defining module', () => {
|
|
176
|
+
// Each evaluation of the module creates its own descriptor and its own
|
|
177
|
+
// module state; the worklet ID and source stay the same.
|
|
178
|
+
const evaluateModule = (generation) => {
|
|
179
|
+
globalThis.registerWorklet('main-thread', 'create-generation', value => ({ value, generation }));
|
|
180
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
181
|
+
'@test/generation',
|
|
182
|
+
{ _wkltId: 'create-generation' },
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
evaluateModule('old');
|
|
187
|
+
updateWorkletRefInitValueChanges([[91, 'a', '@test/generation']]);
|
|
188
|
+
const oldObject = getFromWorkletRefMap({ _wvid: 91 });
|
|
189
|
+
expect(oldObject).toMatchObject({ generation: 'old' });
|
|
190
|
+
|
|
191
|
+
evaluateModule('new');
|
|
192
|
+
updateWorkletRefInitValueChanges([[92, 'b', '@test/generation']]);
|
|
193
|
+
expect(getFromWorkletRefMap({ _wvid: 92 })).toMatchObject({ generation: 'new' });
|
|
194
|
+
// Objects that already exist keep their identity.
|
|
195
|
+
expect(getFromWorkletRefMap({ _wvid: 91 })).toBe(oldObject);
|
|
196
|
+
|
|
197
|
+
removeValueFromWorkletRefMap(91);
|
|
198
|
+
removeValueFromWorkletRefMap(92);
|
|
199
|
+
});
|
|
200
|
+
|
|
155
201
|
it('rejects factories that do not create objects', () => {
|
|
156
202
|
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
157
203
|
'@test/invalid',
|