@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,211 @@
|
|
|
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 type { VNode } from 'preact';
|
|
6
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { DIFF, DIFFED, RENDER, ROOT } from '../../src/shared/render-constants.js';
|
|
9
|
+
|
|
10
|
+
describe('shared/component-stack', () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
vi.resetModules();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('is idempotent and clears leaked renderStack entries on next root render or re-setup', async () => {
|
|
16
|
+
const { options } = await import('preact');
|
|
17
|
+
delete options[DIFF];
|
|
18
|
+
delete options[DIFFED];
|
|
19
|
+
delete options[ROOT];
|
|
20
|
+
delete options.vnode;
|
|
21
|
+
delete options[RENDER];
|
|
22
|
+
|
|
23
|
+
const { getCurrentVNode, setupComponentStack } = await import('../../src/shared/component-stack.js');
|
|
24
|
+
setupComponentStack();
|
|
25
|
+
|
|
26
|
+
const installedDiff = options[DIFF];
|
|
27
|
+
const installedDiffed = options[DIFFED];
|
|
28
|
+
const installedRoot = options[ROOT];
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
30
|
+
const installedVNode = options.vnode;
|
|
31
|
+
const installedRender = options[RENDER];
|
|
32
|
+
|
|
33
|
+
function ThrowingChild() {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const throwingVNode = { type: ThrowingChild, props: {} } as unknown as VNode;
|
|
38
|
+
options[ROOT]?.(throwingVNode, {} as never);
|
|
39
|
+
options[DIFF]?.(throwingVNode);
|
|
40
|
+
options[RENDER]?.(throwingVNode);
|
|
41
|
+
// Simulate a component throwing during render before DIFFED runs.
|
|
42
|
+
expect(getCurrentVNode()).toBe(throwingVNode);
|
|
43
|
+
|
|
44
|
+
// Next root render must clear renderStack as well as ownerStack.
|
|
45
|
+
const nextRootVNode = { type: 'view', props: {} } as unknown as VNode;
|
|
46
|
+
options[ROOT]?.(nextRootVNode, {} as never);
|
|
47
|
+
expect(getCurrentVNode()).toBeNull();
|
|
48
|
+
|
|
49
|
+
// Repeated setupComponentStack() must not double-wrap hooks and must reset stacks.
|
|
50
|
+
options[DIFF]?.(throwingVNode);
|
|
51
|
+
expect(getCurrentVNode()).toBe(throwingVNode);
|
|
52
|
+
setupComponentStack();
|
|
53
|
+
expect(getCurrentVNode()).toBeNull();
|
|
54
|
+
expect(options[DIFF]).toBe(installedDiff);
|
|
55
|
+
expect(options[DIFFED]).toBe(installedDiffed);
|
|
56
|
+
expect(options[ROOT]).toBe(installedRoot);
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
58
|
+
expect(options.vnode).toBe(installedVNode);
|
|
59
|
+
expect(options[RENDER]).toBe(installedRender);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('chains existing Preact option hooks and formats owner stacks across vnode types', async () => {
|
|
63
|
+
const { Fragment, options } = await import('preact');
|
|
64
|
+
const oldDiff = vi.fn();
|
|
65
|
+
const oldDiffed = vi.fn();
|
|
66
|
+
const oldRoot = vi.fn();
|
|
67
|
+
const oldVNode = vi.fn();
|
|
68
|
+
const oldRender = vi.fn();
|
|
69
|
+
|
|
70
|
+
options[DIFF] = oldDiff;
|
|
71
|
+
options[DIFFED] = oldDiffed;
|
|
72
|
+
options[ROOT] = oldRoot;
|
|
73
|
+
options.vnode = oldVNode;
|
|
74
|
+
options[RENDER] = oldRender;
|
|
75
|
+
|
|
76
|
+
const { getCurrentVNode, getOwnerStack, setupComponentStack } = await import(
|
|
77
|
+
'../../src/shared/component-stack.js'
|
|
78
|
+
);
|
|
79
|
+
setupComponentStack();
|
|
80
|
+
|
|
81
|
+
function Outer() {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
function NamedInner() {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
NamedInner.displayName = 'CustomInner';
|
|
88
|
+
|
|
89
|
+
const rootVNode = { type: Outer, props: {}, __source: { fileName: 'App.tsx', lineNumber: 10 } } as unknown as VNode;
|
|
90
|
+
options.vnode?.(rootVNode);
|
|
91
|
+
options[ROOT]?.(rootVNode, {} as never);
|
|
92
|
+
options[DIFF]?.(rootVNode);
|
|
93
|
+
options[RENDER]?.(rootVNode);
|
|
94
|
+
expect(getCurrentVNode()).toBe(rootVNode);
|
|
95
|
+
|
|
96
|
+
const innerVNode = { type: NamedInner, props: {} } as unknown as VNode;
|
|
97
|
+
options.vnode?.(innerVNode);
|
|
98
|
+
// Cloning a vnode with an existing _owner must preserve that _owner.
|
|
99
|
+
const preOwnedVNode = { type: 'view', props: {}, _owner: rootVNode } as unknown as VNode;
|
|
100
|
+
options.vnode?.(preOwnedVNode);
|
|
101
|
+
expect((preOwnedVNode as unknown as { _owner: unknown })._owner).toBe(rootVNode);
|
|
102
|
+
|
|
103
|
+
options[DIFF]?.(innerVNode);
|
|
104
|
+
options[RENDER]?.(innerVNode);
|
|
105
|
+
expect(getCurrentVNode()).toBe(innerVNode);
|
|
106
|
+
|
|
107
|
+
const fragmentVNode = { type: Fragment, props: {} } as unknown as VNode;
|
|
108
|
+
options.vnode?.(fragmentVNode);
|
|
109
|
+
options[DIFF]?.(fragmentVNode);
|
|
110
|
+
options[RENDER]?.(fragmentVNode);
|
|
111
|
+
options[DIFFED]?.(fragmentVNode);
|
|
112
|
+
expect(getCurrentVNode()).toBe(innerVNode);
|
|
113
|
+
|
|
114
|
+
// Nested portal root render (parent with parentNode) must preserve outer stacks,
|
|
115
|
+
// including when an inner portal component throws and unwinds to an outer boundary.
|
|
116
|
+
const portalContextVNode = { type: Outer, props: {} } as unknown as VNode;
|
|
117
|
+
const throwingPortalChildVNode = { type: NamedInner, props: {} } as unknown as VNode;
|
|
118
|
+
options.vnode?.(portalContextVNode);
|
|
119
|
+
options[ROOT]?.(portalContextVNode, { parentNode: {} } as never);
|
|
120
|
+
expect(getCurrentVNode()).toBe(innerVNode);
|
|
121
|
+
options[DIFF]?.(portalContextVNode);
|
|
122
|
+
options[RENDER]?.(portalContextVNode);
|
|
123
|
+
options[DIFF]?.(throwingPortalChildVNode);
|
|
124
|
+
options[RENDER]?.(throwingPortalChildVNode);
|
|
125
|
+
expect(getCurrentVNode()).toBe(throwingPortalChildVNode);
|
|
126
|
+
// Simulate throwingPortalChildVNode and portalContextVNode skipping DIFFED
|
|
127
|
+
// when an outer boundary catches the error and finishes DIFFED on innerVNode.
|
|
128
|
+
options[DIFFED]?.(innerVNode);
|
|
129
|
+
expect(getCurrentVNode()).toBe(rootVNode);
|
|
130
|
+
|
|
131
|
+
// Component bailout (DIFF + DIFFED without RENDER) must not pop parent owner.
|
|
132
|
+
const bailoutVNode = { type: NamedInner, props: {} } as unknown as VNode;
|
|
133
|
+
options[DIFF]?.(bailoutVNode);
|
|
134
|
+
expect(getCurrentVNode()).toBe(bailoutVNode);
|
|
135
|
+
options[DIFFED]?.(bailoutVNode);
|
|
136
|
+
expect(getCurrentVNode()).toBe(rootVNode);
|
|
137
|
+
|
|
138
|
+
// Guard against DIFFED on a component vnode that was never pushed to renderStack.
|
|
139
|
+
const unpushedVNode = { type: NamedInner, props: {} } as unknown as VNode;
|
|
140
|
+
options[DIFFED]?.(unpushedVNode);
|
|
141
|
+
expect(getCurrentVNode()).toBe(rootVNode);
|
|
142
|
+
|
|
143
|
+
const postPortalChildVNode = { type: 'view', props: {} } as unknown as VNode;
|
|
144
|
+
options.vnode?.(postPortalChildVNode);
|
|
145
|
+
expect((postPortalChildVNode as unknown as { _owner: unknown })._owner).toBe(rootVNode);
|
|
146
|
+
|
|
147
|
+
const hostVNode = { type: 'view', props: {}, _owner: fragmentVNode } as unknown as VNode;
|
|
148
|
+
const textVNode = { type: null, props: {}, _owner: hostVNode } as unknown as VNode;
|
|
149
|
+
|
|
150
|
+
expect(getOwnerStack(textVNode)).toBe(
|
|
151
|
+
' in #text\n'
|
|
152
|
+
+ ' in view\n'
|
|
153
|
+
+ ' in Fragment\n'
|
|
154
|
+
+ ' in CustomInner\n'
|
|
155
|
+
+ ' in Outer (at App.tsx:10)\n',
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
options[DIFFED]?.(rootVNode);
|
|
159
|
+
expect(getCurrentVNode()).toBeNull();
|
|
160
|
+
|
|
161
|
+
expect(oldRoot).toHaveBeenCalledTimes(2);
|
|
162
|
+
expect(oldDiff).toHaveBeenCalledTimes(6);
|
|
163
|
+
expect(oldRender).toHaveBeenCalledTimes(5);
|
|
164
|
+
expect(oldDiffed).toHaveBeenCalledTimes(5);
|
|
165
|
+
expect(oldVNode).toHaveBeenCalledTimes(6);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('unwinds renderStack and ownerStack when a Portal child throws into an outer ErrorBoundary', async () => {
|
|
169
|
+
const { Component, createElement, render } = await import('preact');
|
|
170
|
+
const { createPortal } = await import('../../src/snapshot/lynx/portals.js');
|
|
171
|
+
const { getCurrentVNode, setupComponentStack } = await import(
|
|
172
|
+
'../../src/shared/component-stack.js'
|
|
173
|
+
);
|
|
174
|
+
setupComponentStack();
|
|
175
|
+
|
|
176
|
+
class Boundary extends Component<{ children?: unknown }, { failed: boolean }> {
|
|
177
|
+
override state = { failed: false };
|
|
178
|
+
static override getDerivedStateFromError() {
|
|
179
|
+
return { failed: true };
|
|
180
|
+
}
|
|
181
|
+
override render() {
|
|
182
|
+
return this.state.failed ? null : this.props.children;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function Boom(): null {
|
|
187
|
+
throw new Error('portal boom');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const fakeTarget = {
|
|
191
|
+
_nodeSelectToken: { type: 0, identifier: '#host', rootUniqueId: 0 },
|
|
192
|
+
} as never;
|
|
193
|
+
|
|
194
|
+
function App() {
|
|
195
|
+
return createElement(Boundary, null, createPortal(createElement(Boom, null), fakeTarget));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const rootContainer = {
|
|
199
|
+
nodeType: 1,
|
|
200
|
+
childNodes: [],
|
|
201
|
+
insertBefore() {},
|
|
202
|
+
removeChild() {},
|
|
203
|
+
} as never;
|
|
204
|
+
|
|
205
|
+
render(createElement(App, null), rootContainer);
|
|
206
|
+
|
|
207
|
+
expect(getCurrentVNode()).toBeNull();
|
|
208
|
+
const afterRenderVNode = createElement('view', null) as unknown as { _owner?: unknown };
|
|
209
|
+
expect(afterRenderVNode._owner).toBeNull();
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -33,9 +33,6 @@ describe('formatPatch', () => {
|
|
|
33
33
|
SnapshotOperation.DEV_ONLY_AddSnapshot,
|
|
34
34
|
'unique-1',
|
|
35
35
|
'snapshotCreator-val',
|
|
36
|
-
SnapshotOperation.DEV_ONLY_RegisterWorklet,
|
|
37
|
-
'hash-1',
|
|
38
|
-
'() => {}',
|
|
39
36
|
];
|
|
40
37
|
const formatted = prettyFormatSnapshotPatch(snapshotPatch);
|
|
41
38
|
expect(formatted).toEqual([
|
|
@@ -60,11 +57,6 @@ describe('formatPatch', () => {
|
|
|
60
57
|
uniqID: 'unique-1',
|
|
61
58
|
snapshotCreator: 'snapshotCreator-val',
|
|
62
59
|
},
|
|
63
|
-
{
|
|
64
|
-
op: 'DEV_ONLY_RegisterWorklet',
|
|
65
|
-
hash: 'hash-1',
|
|
66
|
-
fnStr: '() => {}',
|
|
67
|
-
},
|
|
68
60
|
]);
|
|
69
61
|
});
|
|
70
62
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { prepareGestureForCommit } from '../../../src/snapshot/gesture/
|
|
3
|
+
import { prepareGestureForCommit } from '../../../src/snapshot/gesture/processGestureBackground';
|
|
4
4
|
import { clearConfigCacheForTesting } from '../../../src/snapshot/worklet/functionality';
|
|
5
5
|
|
|
6
6
|
describe('prepareGestureForCommit', () => {
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*
|
|
2
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
3
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
4
|
+
// LICENSE file in the root directory of this source tree.
|
|
5
|
+
*/
|
|
6
|
+
import { render } from 'preact';
|
|
7
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { registerDestroyTask } from '../../../src/core/runtime-destroy';
|
|
10
|
+
import { __root, setRoot } from '../../../src/root';
|
|
11
|
+
import { completeMainThreadReload } from '../../../src/snapshot/lifecycle/reload';
|
|
12
|
+
import { SnapshotInstance } from '../../../src/snapshot/snapshot/snapshot';
|
|
13
|
+
import { globalEnvManager } from '../utils/envManager';
|
|
14
|
+
import { elementTree } from '../utils/nativeMethod';
|
|
15
|
+
|
|
16
|
+
const supportsReEvalKey = Symbol.for('__LYNX_ENTRY_SUPPORTS_RE_EVAL__');
|
|
17
|
+
const reloaderKey = Symbol.for('__LYNX_MAIN_THREAD_ENTRY_RELOADER__');
|
|
18
|
+
const completerKey = Symbol.for('__LYNX_MAIN_THREAD_RELOAD_COMPLETER__');
|
|
19
|
+
|
|
20
|
+
function App({ label = 'app' }) {
|
|
21
|
+
return (
|
|
22
|
+
<view>
|
|
23
|
+
<text>{label}</text>
|
|
24
|
+
</view>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('re-evaluating the main-thread entry on reload', () => {
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
globalEnvManager.resetEnv();
|
|
31
|
+
vi.stubGlobal('__EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__', true);
|
|
32
|
+
globalEnvManager.switchToMainThread();
|
|
33
|
+
lynx[supportsReEvalKey] = true;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
delete lynx[supportsReEvalKey];
|
|
38
|
+
delete lynx[reloaderKey];
|
|
39
|
+
delete lynx[completerKey];
|
|
40
|
+
vi.restoreAllMocks();
|
|
41
|
+
vi.unstubAllGlobals();
|
|
42
|
+
globalEnvManager.resetEnv();
|
|
43
|
+
elementTree.clear();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('retires the entry, evaluates it again and lets it hydrate the existing tree', () => {
|
|
47
|
+
__root.__jsx = <App label='old' />;
|
|
48
|
+
renderPage({ kept: 'yes', count: 1 });
|
|
49
|
+
const page = __root.__element_root;
|
|
50
|
+
const events = [];
|
|
51
|
+
registerDestroyTask(() => events.push('retire'));
|
|
52
|
+
lynx[reloaderKey] = () => {
|
|
53
|
+
events.push('evaluate');
|
|
54
|
+
// What evaluating the entry does: reset init data, install its completer, render into a fresh root.
|
|
55
|
+
lynx.__initData = {};
|
|
56
|
+
lynx[completerKey] = completeMainThreadReload;
|
|
57
|
+
setRoot(new SnapshotInstance('root'));
|
|
58
|
+
__root.__jsx = <App label='new' />;
|
|
59
|
+
};
|
|
60
|
+
const createText = vi.spyOn(globalThis, '__CreateText');
|
|
61
|
+
|
|
62
|
+
updatePage({ count: 2 }, { reloadTemplate: true });
|
|
63
|
+
|
|
64
|
+
expect(events).toEqual(['retire', 'evaluate']);
|
|
65
|
+
expect(lynx.__initData).toEqual({ kept: 'yes', count: 2 });
|
|
66
|
+
expect(__root.__element_root).toBe(page);
|
|
67
|
+
expect(createText).not.toHaveBeenCalled();
|
|
68
|
+
expect(JSON.stringify(page)).toContain('new');
|
|
69
|
+
expect(JSON.stringify(page)).not.toContain('old');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('re-evaluating the background entry on reload', () => {
|
|
74
|
+
let reloadCard;
|
|
75
|
+
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
globalEnvManager.resetEnv();
|
|
78
|
+
vi.stubGlobal('__EXPERIMENTAL_RE_EVAL_JS_ON_RELOAD__', true);
|
|
79
|
+
globalEnvManager.switchToBackground();
|
|
80
|
+
lynx[supportsReEvalKey] = true;
|
|
81
|
+
reloadCard = vi.fn();
|
|
82
|
+
lynx.getApp().reloadCard = reloadCard;
|
|
83
|
+
lynx.__globalProps = {};
|
|
84
|
+
__root.__jsx = <App />;
|
|
85
|
+
render(<App />, __root);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
afterEach(() => {
|
|
89
|
+
delete lynx[supportsReEvalKey];
|
|
90
|
+
delete lynx.getApp().reloadCard;
|
|
91
|
+
vi.unstubAllGlobals();
|
|
92
|
+
globalEnvManager.resetEnv();
|
|
93
|
+
elementTree.clear();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('retires the entry, then asks the client to evaluate it with the merged data', () => {
|
|
97
|
+
lynx.__initData = { kept: 'yes', count: 1 };
|
|
98
|
+
const destroy = vi.spyOn(lynx.getApp(), 'callDestroyLifetimeFun');
|
|
99
|
+
|
|
100
|
+
lynx.getApp().onAppReload({ count: 2 }, { source: 'test' });
|
|
101
|
+
|
|
102
|
+
expect(reloadCard).toHaveBeenCalledWith({ kept: 'yes', count: 2 }, { source: 'test' });
|
|
103
|
+
expect(destroy.mock.invocationCallOrder[0]).toBeLessThan(reloadCard.mock.invocationCallOrder[0]);
|
|
104
|
+
expect(__root.childNodes).toEqual([]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('does not render the old tree again from a globalProps update queued before the reload', async () => {
|
|
108
|
+
lynx.getApp().updateGlobalProps({ theme: 'dark' });
|
|
109
|
+
lynx.getApp().onAppReload({});
|
|
110
|
+
await Promise.resolve();
|
|
111
|
+
|
|
112
|
+
expect(__root.childNodes).toEqual([]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
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 { useLayoutEffect } from 'preact/hooks';
|
|
5
|
+
import { expect, it, vi } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { createBackgroundFunctionHandle } from '../../../src/core/background-function/handle.js';
|
|
8
|
+
import {
|
|
9
|
+
resetBackgroundFunctionRuntime,
|
|
10
|
+
runOnBackground,
|
|
11
|
+
} from '../../../src/core/background-function/run-on-background.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 { setupPage } from '../../../src/snapshot/index.js';
|
|
16
|
+
import { destroyBackground } from '../../../src/snapshot/lifecycle/destroy.js';
|
|
17
|
+
import { globalCommitTaskMap } from '../../../src/snapshot/lifecycle/patch/commit.js';
|
|
18
|
+
import { onPostWorkletCtx } from '../../../src/snapshot/worklet/ctx.js';
|
|
19
|
+
import { clearConfigCacheForTesting } from '../../../src/snapshot/worklet/functionality.js';
|
|
20
|
+
import { registerWorklet } from '../../../src/worklet-runtime/bindings/index.js';
|
|
21
|
+
import { WorkletEvents } from '../../../src/worklet-runtime/bindings/events.js';
|
|
22
|
+
import { initWorklet } from '../../../src/worklet-runtime/workletRuntime.js';
|
|
23
|
+
import { globalEnvManager } from '../utils/envManager.js';
|
|
24
|
+
import { elementTree } from '../utils/nativeMethod.js';
|
|
25
|
+
|
|
26
|
+
it('retires old and unmount background functions across ordinary reload and hydrates working replacements', async () => {
|
|
27
|
+
const oldCall = vi.fn(() => 'old-page');
|
|
28
|
+
const cleanupCall = vi.fn(() => 'unmounted-page');
|
|
29
|
+
const newCall = vi.fn(() => 'new-page');
|
|
30
|
+
const oldResult = vi.fn();
|
|
31
|
+
const oldRequestResult = vi.fn();
|
|
32
|
+
const newResult = vi.fn(value => value);
|
|
33
|
+
let generation = 0;
|
|
34
|
+
let cleanupCtx;
|
|
35
|
+
const cleanup = vi.fn(() => {
|
|
36
|
+
cleanupCtx = onPostWorkletCtx({
|
|
37
|
+
_wkltId: 'cleanup',
|
|
38
|
+
_jsFn: { callback: createBackgroundFunctionHandle(cleanupCall) },
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
function App() {
|
|
42
|
+
useLayoutEffect(() => cleanup, []);
|
|
43
|
+
const ctx = {
|
|
44
|
+
_wkltId: 'call-background',
|
|
45
|
+
_jsFn: {
|
|
46
|
+
callback: __MAIN_THREAD__
|
|
47
|
+
? { _isFirstScreen: true }
|
|
48
|
+
: createBackgroundFunctionHandle(generation === 0 ? oldCall : newCall),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
return <view main-thread:bindtap={ctx} />;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function hydratePage() {
|
|
55
|
+
globalEnvManager.switchToBackground();
|
|
56
|
+
lynx.getNativeApp().callLepusMethod.mockClear();
|
|
57
|
+
lynx.getApp().OnLifecycleEvent(...__OnLifecycleEvent.mock.lastCall);
|
|
58
|
+
const [method, patch, complete] = lynx.getNativeApp().callLepusMethod.mock.lastCall;
|
|
59
|
+
expect(patch.patchOptions.isHydration).toBe(true);
|
|
60
|
+
globalEnvManager.switchToMainThread();
|
|
61
|
+
globalThis[method](patch);
|
|
62
|
+
globalEnvManager.switchToBackground();
|
|
63
|
+
complete();
|
|
64
|
+
globalEnvManager.switchToMainThread();
|
|
65
|
+
return __root.__element_root.children[0].props.event['bindEvent:tap'].value;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const workletGlobals = {
|
|
69
|
+
lynxWorkletImpl: globalThis.lynxWorkletImpl,
|
|
70
|
+
runWorklet: globalThis.runWorklet,
|
|
71
|
+
registerWorklet: globalThis.registerWorklet,
|
|
72
|
+
registerWorkletInternal: globalThis.registerWorkletInternal,
|
|
73
|
+
};
|
|
74
|
+
const sdkVersion = SystemInfo.lynxSdkVersion;
|
|
75
|
+
globalEnvManager.resetEnv();
|
|
76
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
77
|
+
clearConfigCacheForTesting();
|
|
78
|
+
try {
|
|
79
|
+
initWorklet();
|
|
80
|
+
registerWorklet('main-thread', 'call-background', function(value) {
|
|
81
|
+
return runOnBackground(this._jsFn.callback)(value);
|
|
82
|
+
});
|
|
83
|
+
setupPage(__CreatePage('0', 0));
|
|
84
|
+
__root.__jsx = <App />;
|
|
85
|
+
renderPage({});
|
|
86
|
+
globalEnvManager.switchToBackground();
|
|
87
|
+
root.render(<App />);
|
|
88
|
+
const oldCtx = hydratePage();
|
|
89
|
+
const context = lynx.getCoreContext();
|
|
90
|
+
const jsContext = lynx.getJSContext();
|
|
91
|
+
// Hold a real old return and request at the transport boundary. Replay the
|
|
92
|
+
// original envelopes after reload; do not manufacture their version/IDs.
|
|
93
|
+
context.dispatchEvent.mockImplementationOnce(() => {});
|
|
94
|
+
void runWorklet(oldCtx, ['before']).then(oldResult);
|
|
95
|
+
const oldReturn = context.dispatchEvent.mock.lastCall[0];
|
|
96
|
+
expect(oldReturn.type).toBe(WorkletEvents.FunctionCallRet);
|
|
97
|
+
expect(oldCall).toHaveBeenCalledExactlyOnceWith('before');
|
|
98
|
+
jsContext.dispatchEvent.mockImplementationOnce(() => {});
|
|
99
|
+
void runWorklet(oldCtx, ['delayed-request']).then(oldRequestResult);
|
|
100
|
+
const oldRequest = jsContext.dispatchEvent.mock.lastCall[0];
|
|
101
|
+
expect(oldRequest.type).toBe(WorkletEvents.runOnBackground);
|
|
102
|
+
|
|
103
|
+
globalEnvManager.switchToBackground();
|
|
104
|
+
const oldListeners = context.addEventListener.mock.calls.filter(([type]) =>
|
|
105
|
+
type === WorkletEvents.runOnBackground || type === WorkletEvents.releaseBackgroundWorkletCtx
|
|
106
|
+
);
|
|
107
|
+
expect(oldListeners).toHaveLength(2);
|
|
108
|
+
context.removeEventListener.mockClear();
|
|
109
|
+
generation = 1;
|
|
110
|
+
lynx.getApp().onAppReload({});
|
|
111
|
+
expect(cleanup).toHaveBeenCalledOnce();
|
|
112
|
+
// The test harness shares resolver state across threads: finish MTS reload
|
|
113
|
+
// before dispatching new calls, then apply the actual hydration patch.
|
|
114
|
+
globalEnvManager.switchToMainThread();
|
|
115
|
+
updatePage({}, { reloadTemplate: true });
|
|
116
|
+
const newCtx = hydratePage();
|
|
117
|
+
context.dispatchEvent.mockImplementationOnce(() => {});
|
|
118
|
+
const result = runWorklet(newCtx, ['after']).then(newResult);
|
|
119
|
+
const newReturn = context.dispatchEvent.mock.lastCall[0];
|
|
120
|
+
expect(JSON.parse(newReturn.data).resolveId).toBe(JSON.parse(oldReturn.data).resolveId);
|
|
121
|
+
expect(newCall).toHaveBeenCalledExactlyOnceWith('after');
|
|
122
|
+
jsContext.dispatchEvent(oldRequest);
|
|
123
|
+
globalEnvManager.switchToBackground();
|
|
124
|
+
context.dispatchEvent(oldReturn);
|
|
125
|
+
await Promise.resolve();
|
|
126
|
+
expect(newResult).not.toHaveBeenCalled();
|
|
127
|
+
expect(oldResult).not.toHaveBeenCalled();
|
|
128
|
+
expect(oldRequestResult).not.toHaveBeenCalled();
|
|
129
|
+
context.dispatchEvent(newReturn);
|
|
130
|
+
await expect(result).resolves.toBe('new-page');
|
|
131
|
+
|
|
132
|
+
globalEnvManager.switchToMainThread();
|
|
133
|
+
await expect(runWorklet(oldCtx, ['retired'])).rejects.toThrow('runOnBackground: JS function not found');
|
|
134
|
+
// A thrown native listener leaves this harness on the receiving thread.
|
|
135
|
+
globalEnvManager.switchToMainThread();
|
|
136
|
+
await expect(
|
|
137
|
+
runOnBackground({
|
|
138
|
+
_jsFnId: cleanupCtx._jsFn.callback._jsFnId,
|
|
139
|
+
_execId: cleanupCtx._execId,
|
|
140
|
+
})(),
|
|
141
|
+
).rejects.toThrow('runOnBackground: JS function not found');
|
|
142
|
+
expect.soft(oldCall).toHaveBeenCalledOnce();
|
|
143
|
+
expect.soft(cleanupCall).not.toHaveBeenCalled();
|
|
144
|
+
for (const [type, listener] of oldListeners) {
|
|
145
|
+
expect.soft(context.removeEventListener).toHaveBeenCalledWith(type, listener);
|
|
146
|
+
}
|
|
147
|
+
globalEnvManager.switchToMainThread();
|
|
148
|
+
// Releasing retired contexts must not remove a replacement page's context.
|
|
149
|
+
lynx.getJSContext().dispatchEvent({
|
|
150
|
+
type: WorkletEvents.releaseBackgroundWorkletCtx,
|
|
151
|
+
data: [oldCtx._execId, cleanupCtx._execId],
|
|
152
|
+
});
|
|
153
|
+
await expect(runWorklet(newCtx, ['after-release'])).resolves.toBe('new-page');
|
|
154
|
+
expect(newCall).toHaveBeenCalledTimes(2);
|
|
155
|
+
} finally {
|
|
156
|
+
cleanup.mockImplementation(() => {});
|
|
157
|
+
globalEnvManager.switchToBackground();
|
|
158
|
+
destroyBackground();
|
|
159
|
+
resetBackgroundFunctionRuntime();
|
|
160
|
+
resetFunctionCallReturnListener();
|
|
161
|
+
globalCommitTaskMap.clear();
|
|
162
|
+
globalEnvManager.resetEnv();
|
|
163
|
+
elementTree.clear();
|
|
164
|
+
Object.assign(globalThis, workletGlobals);
|
|
165
|
+
SystemInfo.lynxSdkVersion = sdkVersion;
|
|
166
|
+
clearConfigCacheForTesting();
|
|
167
|
+
vi.restoreAllMocks();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
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, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { createElement } from '../../../lepus/index.js';
|
|
7
|
+
import { runOnBackground } from '../../../src/core/background-function/run-on-background.js';
|
|
8
|
+
import { getReloadVersion } from '../../../src/core/reload-version.js';
|
|
9
|
+
import { resetFunctionCallReturnListener } from '../../../src/core/thread-function-call/return-value.js';
|
|
10
|
+
import { __root } from '../../../src/root.js';
|
|
11
|
+
import { setupPage } from '../../../src/snapshot/index.js';
|
|
12
|
+
import { initRunOnBackgroundDelay } from '../../../src/worklet-runtime/delayRunOnBackground.js';
|
|
13
|
+
import { globalEnvManager } from '../utils/envManager.js';
|
|
14
|
+
import { elementTree } from '../utils/nativeMethod.js';
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
globalEnvManager.resetEnv();
|
|
18
|
+
setupPage(__CreatePage('0', 0));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
vi.restoreAllMocks();
|
|
23
|
+
globalEnvManager.resetEnv();
|
|
24
|
+
elementTree.clear();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('clears old delayed background calls before rendering and preserves new calls', () => {
|
|
28
|
+
const previousImpl = globalThis.lynxWorkletImpl;
|
|
29
|
+
const previousSdkVersion = SystemInfo.lynxSdkVersion;
|
|
30
|
+
SystemInfo.lynxSdkVersion = '4.0';
|
|
31
|
+
const delay = initRunOnBackgroundDelay();
|
|
32
|
+
globalThis.lynxWorkletImpl = { ...previousImpl, _runOnBackgroundDelayImpl: delay };
|
|
33
|
+
const dispatch = vi.spyOn(lynx.getJSContext(), 'dispatchEvent').mockImplementation(() => {});
|
|
34
|
+
try {
|
|
35
|
+
__root.__jsx = createElement(() => {
|
|
36
|
+
void runOnBackground(Object.assign(() => {}, { _isFirstScreen: true }))();
|
|
37
|
+
return null;
|
|
38
|
+
});
|
|
39
|
+
renderPage({});
|
|
40
|
+
expect(delay.delayedBackgroundFunctionArray).toHaveLength(1);
|
|
41
|
+
const oldTask = delay.delayedBackgroundFunctionArray[0];
|
|
42
|
+
const oldCallback = vi.spyOn(oldTask, 'task');
|
|
43
|
+
|
|
44
|
+
updatePage({}, { reloadTemplate: true });
|
|
45
|
+
|
|
46
|
+
expect(delay.delayedBackgroundFunctionArray).toHaveLength(1);
|
|
47
|
+
expect(delay.delayedBackgroundFunctionArray[0]).not.toBe(oldTask);
|
|
48
|
+
delay.delayedBackgroundFunctionArray[0].jsFnHandle = { _jsFnId: 7, _execId: 9 };
|
|
49
|
+
delay.runDelayedBackgroundFunctions();
|
|
50
|
+
expect(oldCallback).not.toHaveBeenCalled();
|
|
51
|
+
expect(dispatch).toHaveBeenCalledOnce();
|
|
52
|
+
expect(JSON.parse(dispatch.mock.calls[0][0].data)).toMatchObject({
|
|
53
|
+
obj: { _jsFnId: 7, _execId: 9 },
|
|
54
|
+
reloadVersion: getReloadVersion(),
|
|
55
|
+
});
|
|
56
|
+
expect(delay.delayedBackgroundFunctionArray).toHaveLength(0);
|
|
57
|
+
} finally {
|
|
58
|
+
delay.clearDelayedBackgroundFunctions();
|
|
59
|
+
resetFunctionCallReturnListener();
|
|
60
|
+
globalThis.lynxWorkletImpl = previousImpl;
|
|
61
|
+
SystemInfo.lynxSdkVersion = previousSdkVersion;
|
|
62
|
+
}
|
|
63
|
+
});
|