@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
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
|
|
5
|
+
import {
|
|
6
|
+
installElementTemplateRefInitValueListener,
|
|
7
|
+
resetElementTemplateRefInitValueListener,
|
|
8
|
+
} from '../../../../src/element-template/main-thread-ref-init-value.js';
|
|
5
9
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
10
|
|
|
11
|
+
import { JsFunctionLifecycleManager } from '../../../../src/worklet-runtime/jsFunctionLifecycle.js';
|
|
7
12
|
import { getReloadVersion, increaseReloadVersion } from '../../../../src/core/reload-version.js';
|
|
8
13
|
import type { BackgroundElementTemplateInstance } from '../../../../src/element-template/background/instance.js';
|
|
9
14
|
import { root } from '../../../../src/element-template/index.js';
|
|
@@ -37,6 +42,7 @@ import {
|
|
|
37
42
|
} from '../../../../src/element-template/runtime/list/list.js';
|
|
38
43
|
import {
|
|
39
44
|
attachMainThreadDynamicAttrRefsForSubtree,
|
|
45
|
+
applyPendingMainThreadRefAttachments,
|
|
40
46
|
clearMainThreadDynamicAttrState,
|
|
41
47
|
detachMainThreadDynamicAttrRefsForSubtree,
|
|
42
48
|
getMainThreadDynamicAttrState,
|
|
@@ -109,6 +115,7 @@ function createMaterializedListForFrontendTest(nativeId: number): FiberElement {
|
|
|
109
115
|
|
|
110
116
|
const MT_EVENT_TEMPLATE = '_et_mt_event';
|
|
111
117
|
const MT_REF_TEMPLATE = '_et_mt_ref';
|
|
118
|
+
const REF_TARGET = { id: 'materialized-ref-node' } as unknown as ElementRef;
|
|
112
119
|
|
|
113
120
|
function registerMTEventSlotsForTemplate(templateType: string, ...slotIndexes: number[]): void {
|
|
114
121
|
__etAttrPlanMap[templateType] = slotIndexes.flatMap(slotIndex => [
|
|
@@ -154,6 +161,8 @@ function seedMTRefState(
|
|
|
154
161
|
attributeSlots[attrSlotIndex] = { type: 'main-thread-ref', value };
|
|
155
162
|
initializeMainThreadDynamicAttrSlots(handleId, MT_REF_TEMPLATE, attributeSlots);
|
|
156
163
|
attachMainThreadDynamicAttrRefsForSubtree([{ uid: handleId, ref: nativeRef }]);
|
|
164
|
+
vi.mocked(__GetElementByAttrSlot).mockReturnValue(REF_TARGET);
|
|
165
|
+
applyPendingMainThreadRefAttachments();
|
|
157
166
|
}
|
|
158
167
|
|
|
159
168
|
function installWorkletRefRuntime(): {
|
|
@@ -335,6 +344,43 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
335
344
|
expect(mockFlushElementTree.mock.calls.length).toBeGreaterThan(0);
|
|
336
345
|
});
|
|
337
346
|
|
|
347
|
+
it.each([false, true])('tracks setter input before Native and commits only on success (throws=%s)', (throws) => {
|
|
348
|
+
const previous = globalThis.lynxWorkletImpl;
|
|
349
|
+
const manager = new JsFunctionLifecycleManager();
|
|
350
|
+
const hydrate = vi.fn();
|
|
351
|
+
globalThis.lynxWorkletImpl = { ...previous, _jsFunctionLifecycleManager: manager, _hydrateCtx: hydrate };
|
|
352
|
+
const oldCtx = { _wkltId: 'tap', _execId: 30 };
|
|
353
|
+
const nextCtx = { _wkltId: 'tap', _execId: 31 };
|
|
354
|
+
elementTemplateRegistry.set(101, {} as ElementTemplateHandle);
|
|
355
|
+
seedMTEventState(101, 0, oldCtx);
|
|
356
|
+
const retain = vi.spyOn(manager, 'addRef');
|
|
357
|
+
const error = new Error('setter failed');
|
|
358
|
+
mockSetElementTemplateAttributeSlot.mockImplementationOnce((_native, _slot, value) => {
|
|
359
|
+
expect(value.value).toBe(nextCtx);
|
|
360
|
+
expect(retain).toHaveBeenCalledExactlyOnceWith(31, nextCtx);
|
|
361
|
+
expect(getMainThreadDynamicAttrState(101, 0)?.nativeHeldValue).toBe(oldCtx);
|
|
362
|
+
if (throws) throw error;
|
|
363
|
+
});
|
|
364
|
+
try {
|
|
365
|
+
const apply = () =>
|
|
366
|
+
applyElementTemplateUpdateCommands([
|
|
367
|
+
ElementTemplateUpdateOps.setMainThreadEvent,
|
|
368
|
+
101,
|
|
369
|
+
0,
|
|
370
|
+
{ type: 'worklet', value: nextCtx },
|
|
371
|
+
], true);
|
|
372
|
+
if (throws) expect(apply).toThrow(error);
|
|
373
|
+
else apply();
|
|
374
|
+
expect(getMainThreadDynamicAttrState(101, 0)?.nativeHeldValue).toBe(throws ? oldCtx : nextCtx);
|
|
375
|
+
expect(retain).toHaveBeenCalledExactlyOnceWith(31, nextCtx);
|
|
376
|
+
if (throws) expect(hydrate).not.toHaveBeenCalled();
|
|
377
|
+
else expect(hydrate).toHaveBeenCalledExactlyOnceWith(nextCtx, oldCtx);
|
|
378
|
+
} finally {
|
|
379
|
+
manager.dispose();
|
|
380
|
+
globalThis.lynxWorkletImpl = previous;
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
|
|
338
384
|
it('records MTEvent state after setMainThreadEvent PAPI succeeds', () => {
|
|
339
385
|
const targetId = 101;
|
|
340
386
|
const nativeRef = {};
|
|
@@ -602,7 +648,11 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
602
648
|
]);
|
|
603
649
|
|
|
604
650
|
expect(mockInsertElementTemplateNodeIntoSlot).toHaveBeenCalledWith(parentRef, 0, nativeRef, null);
|
|
605
|
-
expect(updateWorkletRef).
|
|
651
|
+
expect(updateWorkletRef).not.toHaveBeenCalled();
|
|
652
|
+
applyPendingMainThreadRefAttachments();
|
|
653
|
+
const target = vi.mocked(__GetElementByAttrSlot).mock.results.at(-1)!.value;
|
|
654
|
+
expect(target).not.toBe(nativeRef);
|
|
655
|
+
expect(updateWorkletRef).toHaveBeenCalledWith(ref, target);
|
|
606
656
|
expect(getMainThreadDynamicAttrState(handleId, 0)).toEqual({
|
|
607
657
|
kind: 'mt-ref',
|
|
608
658
|
value: ref,
|
|
@@ -757,19 +807,19 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
757
807
|
|
|
758
808
|
expect(mockSetElementTemplateAttributeSlot).not.toHaveBeenCalled();
|
|
759
809
|
expect(oldCleanup).toHaveBeenCalledTimes(1);
|
|
760
|
-
const mountedCallback = runWorklet.mock.calls[0]?.[0] as typeof nextCallback
|
|
761
|
-
_unmount?: () => void;
|
|
762
|
-
};
|
|
810
|
+
const mountedCallback = runWorklet.mock.calls[0]?.[0] as typeof nextCallback;
|
|
763
811
|
expect(mountedCallback).toEqual(expect.objectContaining({
|
|
764
812
|
_wkltId: 'next-ref-callback',
|
|
765
813
|
}));
|
|
766
|
-
expect(runWorklet.mock.calls[0]?.[1]).toEqual([{ elementRefptr:
|
|
767
|
-
expect(mountedCallback
|
|
814
|
+
expect(runWorklet.mock.calls[0]?.[1]).toEqual([{ elementRefptr: REF_TARGET }]);
|
|
815
|
+
expect(mountedCallback).toHaveProperty('_unmount', nextCleanup);
|
|
768
816
|
expect(nextCallback).not.toHaveProperty('_unmount');
|
|
769
817
|
expect(getMainThreadDynamicAttrState(targetId, 0)).toEqual({
|
|
770
818
|
kind: 'mt-ref',
|
|
771
819
|
value: mountedCallback,
|
|
772
820
|
});
|
|
821
|
+
applyElementTemplateUpdateCommands([ElementTemplateUpdateOps.setMainThreadRef, targetId, 0, null]);
|
|
822
|
+
expect(nextCleanup).toHaveBeenCalledOnce();
|
|
773
823
|
} finally {
|
|
774
824
|
globalThis.runWorklet = previousRunWorklet;
|
|
775
825
|
}
|
|
@@ -804,10 +854,11 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
804
854
|
{ type: 'main-thread-ref', value: nextCallback },
|
|
805
855
|
], true);
|
|
806
856
|
|
|
857
|
+
applyPendingMainThreadRefAttachments();
|
|
807
858
|
expect(hydrateCtx).toHaveBeenCalledWith(nextCallback, oldCallback);
|
|
808
859
|
expect(runDelayedWorklet).not.toHaveBeenCalled();
|
|
809
860
|
expect(oldCleanup).toHaveBeenCalledTimes(1);
|
|
810
|
-
expect(globalThis.runWorklet).toHaveBeenCalledWith(nextCallback, [{ elementRefptr:
|
|
861
|
+
expect(globalThis.runWorklet).toHaveBeenCalledWith(nextCallback, [{ elementRefptr: REF_TARGET }]);
|
|
811
862
|
} finally {
|
|
812
863
|
globalThis.runWorklet = previousRunWorklet;
|
|
813
864
|
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
@@ -841,6 +892,7 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
841
892
|
{ type: 'main-thread-ref', value: nextCallback },
|
|
842
893
|
], true);
|
|
843
894
|
|
|
895
|
+
applyPendingMainThreadRefAttachments();
|
|
844
896
|
expect(hydrateCtx).toHaveBeenCalledWith(nextCallback, oldCallback);
|
|
845
897
|
expect(globalThis.runWorklet).not.toHaveBeenCalled();
|
|
846
898
|
expect(getMainThreadDynamicAttrState(targetId, 0)).toEqual({
|
|
@@ -1388,6 +1440,55 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1388
1440
|
}
|
|
1389
1441
|
});
|
|
1390
1442
|
|
|
1443
|
+
it('cleans hydration handoff and propagates a ref callback error without running later work', () => {
|
|
1444
|
+
const handle = { id: 'throwing-ref-template' } as unknown as ElementTemplateHandle;
|
|
1445
|
+
const target = { id: 'inner-node' } as unknown as ElementRef;
|
|
1446
|
+
const callback = { _wkltId: 'throwing-ref' };
|
|
1447
|
+
const callbackError = new Error('ref callback failed');
|
|
1448
|
+
const runDelayedBackgroundFunctions = vi.fn();
|
|
1449
|
+
const clearFirstScreenWorkletRefMap = vi.fn();
|
|
1450
|
+
const runRunOnMainThreadTask = vi.fn();
|
|
1451
|
+
const previousWorkletImpl = globalThis.lynxWorkletImpl;
|
|
1452
|
+
const previousRunWorklet = globalThis.runWorklet;
|
|
1453
|
+
globalThis.lynxWorkletImpl = {
|
|
1454
|
+
...previousWorkletImpl,
|
|
1455
|
+
_refImpl: { ...createMainThreadRefImplMock(), clearFirstScreenWorkletRefMap },
|
|
1456
|
+
_runOnBackgroundDelayImpl: { runDelayedBackgroundFunctions },
|
|
1457
|
+
_runRunOnMainThreadTask: runRunOnMainThreadTask,
|
|
1458
|
+
};
|
|
1459
|
+
globalThis.runWorklet = vi.fn(() => {
|
|
1460
|
+
throw callbackError;
|
|
1461
|
+
});
|
|
1462
|
+
try {
|
|
1463
|
+
registerMTRefSlots(0);
|
|
1464
|
+
initializeMainThreadDynamicAttrSlots(193, MT_REF_TEMPLATE, [{ type: 'main-thread-ref', value: callback }]);
|
|
1465
|
+
attachMainThreadDynamicAttrRefsForSubtree([{ uid: 193, ref: handle }]);
|
|
1466
|
+
vi.mocked(__GetElementByAttrSlot).mockReturnValue(target);
|
|
1467
|
+
envManager.switchToMainThread();
|
|
1468
|
+
installElementTemplatePatchListener();
|
|
1469
|
+
mockFlushElementTree.mockClear();
|
|
1470
|
+
expect(() => {
|
|
1471
|
+
envManager.switchToBackground();
|
|
1472
|
+
dispatchElementTemplateUpdate({
|
|
1473
|
+
ops: [],
|
|
1474
|
+
isHydration: true,
|
|
1475
|
+
flushOptions: {},
|
|
1476
|
+
delayedRunOnMainThreadData: [{ worklet: { _wkltId: 'should-not-run' }, params: [], resolveId: 33 }],
|
|
1477
|
+
});
|
|
1478
|
+
envManager.switchToMainThread();
|
|
1479
|
+
}).toThrow(callbackError);
|
|
1480
|
+
expect(globalThis.runWorklet).toHaveBeenCalledWith(callback, [{ elementRefptr: target }]);
|
|
1481
|
+
expect(runDelayedBackgroundFunctions).toHaveBeenCalledTimes(1);
|
|
1482
|
+
expect(clearFirstScreenWorkletRefMap).toHaveBeenCalledTimes(1);
|
|
1483
|
+
expect(runRunOnMainThreadTask).not.toHaveBeenCalled();
|
|
1484
|
+
expect(mockFlushElementTree).not.toHaveBeenCalled();
|
|
1485
|
+
} finally {
|
|
1486
|
+
globalThis.runWorklet = previousRunWorklet;
|
|
1487
|
+
clearMainThreadDynamicAttrState();
|
|
1488
|
+
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1491
|
+
|
|
1391
1492
|
it('continues delayed lifecycle when patch apply reports a missing target', () => {
|
|
1392
1493
|
const runDelayedBackgroundFunctions = vi.fn();
|
|
1393
1494
|
const runRunOnMainThreadTask = vi.fn();
|
|
@@ -1439,7 +1540,100 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1439
1540
|
}
|
|
1440
1541
|
});
|
|
1441
1542
|
|
|
1442
|
-
it('
|
|
1543
|
+
it('delivers pending targets before hydration handoff and delayed tasks, then flushes their writes', () => {
|
|
1544
|
+
const callOrder: string[] = [];
|
|
1545
|
+
const handle = { id: 'pending-template' } as unknown as ElementTemplateHandle;
|
|
1546
|
+
const target = { id: 'inner-node' } as unknown as ElementRef;
|
|
1547
|
+
const ref = { _wvid: 91 };
|
|
1548
|
+
const worklet = { _wkltId: 'uses-hydrated-ref' };
|
|
1549
|
+
const updateWorkletRef = vi.fn(() => callOrder.push('attach'));
|
|
1550
|
+
const clearFirstScreenWorkletRefMap = vi.fn(() => callOrder.push('clear-first-screen'));
|
|
1551
|
+
const runDelayedBackgroundFunctions = vi.fn(() => callOrder.push('background-handoff'));
|
|
1552
|
+
const runRunOnMainThreadTask = vi.fn(() => {
|
|
1553
|
+
expect(updateWorkletRef).toHaveBeenCalledWith(ref, target);
|
|
1554
|
+
callOrder.push('task');
|
|
1555
|
+
});
|
|
1556
|
+
const previousWorkletImpl = globalThis.lynxWorkletImpl;
|
|
1557
|
+
globalThis.lynxWorkletImpl = {
|
|
1558
|
+
...previousWorkletImpl,
|
|
1559
|
+
_refImpl: { updateWorkletRef, clearFirstScreenWorkletRefMap },
|
|
1560
|
+
_runOnBackgroundDelayImpl: { runDelayedBackgroundFunctions },
|
|
1561
|
+
_eomImpl: { setShouldFlush: vi.fn() },
|
|
1562
|
+
_runRunOnMainThreadTask: runRunOnMainThreadTask,
|
|
1563
|
+
};
|
|
1564
|
+
try {
|
|
1565
|
+
registerMTRefSlots(0);
|
|
1566
|
+
initializeMainThreadDynamicAttrSlots(191, MT_REF_TEMPLATE, [{ type: 'main-thread-ref', value: ref }]);
|
|
1567
|
+
attachMainThreadDynamicAttrRefsForSubtree([{ uid: 191, ref: handle }]);
|
|
1568
|
+
vi.mocked(__GetElementByAttrSlot).mockReturnValue(target);
|
|
1569
|
+
mockFlushElementTree.mockImplementationOnce(() => callOrder.push('initial-flush'));
|
|
1570
|
+
envManager.switchToMainThread();
|
|
1571
|
+
installElementTemplatePatchListener();
|
|
1572
|
+
envManager.switchToBackground();
|
|
1573
|
+
dispatchElementTemplateUpdate({
|
|
1574
|
+
ops: [],
|
|
1575
|
+
isHydration: true,
|
|
1576
|
+
flushOptions: { emptyPatch: true },
|
|
1577
|
+
delayedRunOnMainThreadData: [{ worklet, params: [], resolveId: 31 }],
|
|
1578
|
+
});
|
|
1579
|
+
envManager.switchToMainThread();
|
|
1580
|
+
expect(callOrder).toEqual(['attach', 'background-handoff', 'clear-first-screen', 'task', 'initial-flush']);
|
|
1581
|
+
expect(runRunOnMainThreadTask).toHaveBeenCalledWith(worklet, [], 31);
|
|
1582
|
+
expect(mockFlushElementTree).toHaveBeenCalledOnce();
|
|
1583
|
+
expect(mockFlushElementTree.mock.calls[0]![1]).toEqual({ emptyPatch: true });
|
|
1584
|
+
} finally {
|
|
1585
|
+
clearMainThreadDynamicAttrState();
|
|
1586
|
+
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
|
|
1590
|
+
it('delivers refs synchronously before a later delayed-task payload', () => {
|
|
1591
|
+
const handleId = 192;
|
|
1592
|
+
const handle = { id: 'pending-template' } as unknown as ElementTemplateHandle;
|
|
1593
|
+
const target = { id: 'inner-node' } as unknown as ElementRef;
|
|
1594
|
+
const ref = { _wvid: 92 };
|
|
1595
|
+
const worklet = { _wkltId: 'later-payload-uses-ref' };
|
|
1596
|
+
const updateWorkletRef = vi.fn();
|
|
1597
|
+
const runRunOnMainThreadTask = vi.fn(() => expect(updateWorkletRef).toHaveBeenCalledWith(ref, target));
|
|
1598
|
+
const previousWorkletImpl = globalThis.lynxWorkletImpl;
|
|
1599
|
+
globalThis.lynxWorkletImpl = {
|
|
1600
|
+
...previousWorkletImpl,
|
|
1601
|
+
_refImpl: { updateWorkletRef },
|
|
1602
|
+
_eomImpl: { setShouldFlush: vi.fn() },
|
|
1603
|
+
_runRunOnMainThreadTask: runRunOnMainThreadTask,
|
|
1604
|
+
};
|
|
1605
|
+
try {
|
|
1606
|
+
elementTemplateRegistry.set(handleId, handle);
|
|
1607
|
+
registerMTRefSlots(0);
|
|
1608
|
+
attachMainThreadDynamicAttrRefsForSubtree([{ uid: handleId, ref: handle }]);
|
|
1609
|
+
vi.mocked(__GetElementByAttrSlot).mockReturnValue(target);
|
|
1610
|
+
envManager.switchToMainThread();
|
|
1611
|
+
installElementTemplatePatchListener();
|
|
1612
|
+
envManager.switchToBackground();
|
|
1613
|
+
dispatchElementTemplateUpdate({
|
|
1614
|
+
ops: [ElementTemplateUpdateOps.setMainThreadRef, handleId, 0, { type: 'main-thread-ref', value: ref }],
|
|
1615
|
+
flushOptions: {},
|
|
1616
|
+
});
|
|
1617
|
+
envManager.switchToMainThread();
|
|
1618
|
+
expect(updateWorkletRef).toHaveBeenCalledWith(ref, target);
|
|
1619
|
+
envManager.switchToBackground();
|
|
1620
|
+
dispatchElementTemplateUpdate({
|
|
1621
|
+
ops: [],
|
|
1622
|
+
flushOptions: { emptyPatch: true },
|
|
1623
|
+
delayedRunOnMainThreadData: [{ worklet, params: [], resolveId: 32 }],
|
|
1624
|
+
});
|
|
1625
|
+
envManager.switchToMainThread();
|
|
1626
|
+
expect(runRunOnMainThreadTask).toHaveBeenCalledWith(worklet, [], 32);
|
|
1627
|
+
expect(__GetElementByAttrSlot).toHaveBeenCalledOnce();
|
|
1628
|
+
expect(updateWorkletRef).toHaveBeenCalledOnce();
|
|
1629
|
+
expect(mockFlushElementTree.mock.calls).toEqual([[undefined, {}], [undefined, { emptyPatch: true }]]);
|
|
1630
|
+
} finally {
|
|
1631
|
+
clearMainThreadDynamicAttrState();
|
|
1632
|
+
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
1633
|
+
}
|
|
1634
|
+
});
|
|
1635
|
+
|
|
1636
|
+
it('applies independent ref initialization before delayed main-thread tasks', () => {
|
|
1443
1637
|
const callOrder: string[] = [];
|
|
1444
1638
|
const updateWorkletRefInitValueChanges = vi.fn(() => {
|
|
1445
1639
|
callOrder.push('init-patch');
|
|
@@ -1461,12 +1655,17 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1461
1655
|
|
|
1462
1656
|
try {
|
|
1463
1657
|
envManager.switchToMainThread();
|
|
1658
|
+
installElementTemplateRefInitValueListener();
|
|
1464
1659
|
installElementTemplatePatchListener();
|
|
1465
1660
|
mockFlushElementTree.mockImplementationOnce(() => {
|
|
1466
1661
|
callOrder.push('flushElementTree');
|
|
1467
1662
|
});
|
|
1468
1663
|
|
|
1469
1664
|
envManager.switchToBackground();
|
|
1665
|
+
lynx.getCoreContext().dispatchEvent({
|
|
1666
|
+
type: ElementTemplateLifecycleConstant.updateMTRefInitValue,
|
|
1667
|
+
data: JSON.stringify([[1, 'same-payload-init']]),
|
|
1668
|
+
});
|
|
1470
1669
|
dispatchElementTemplateUpdate({
|
|
1471
1670
|
ops: [],
|
|
1472
1671
|
flushOptions: {},
|
|
@@ -1477,7 +1676,6 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1477
1676
|
resolveId: 10,
|
|
1478
1677
|
},
|
|
1479
1678
|
],
|
|
1480
|
-
mainThreadRefInitValuePatch: [[1, 'same-payload-init']],
|
|
1481
1679
|
});
|
|
1482
1680
|
envManager.switchToMainThread();
|
|
1483
1681
|
|
|
@@ -1489,6 +1687,7 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1489
1687
|
'flushElementTree',
|
|
1490
1688
|
]);
|
|
1491
1689
|
} finally {
|
|
1690
|
+
resetElementTemplateRefInitValueListener();
|
|
1492
1691
|
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
1493
1692
|
}
|
|
1494
1693
|
});
|
|
@@ -1512,10 +1711,15 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1512
1711
|
try {
|
|
1513
1712
|
increaseReloadVersion();
|
|
1514
1713
|
envManager.switchToMainThread();
|
|
1714
|
+
installElementTemplateRefInitValueListener();
|
|
1515
1715
|
installElementTemplatePatchListener();
|
|
1516
1716
|
mockFlushElementTree.mockClear();
|
|
1517
1717
|
|
|
1518
1718
|
envManager.switchToBackground();
|
|
1719
|
+
lynx.getCoreContext().dispatchEvent({
|
|
1720
|
+
type: ElementTemplateLifecycleConstant.updateMTRefInitValue,
|
|
1721
|
+
data: JSON.stringify([[1, 'stale-init']]),
|
|
1722
|
+
});
|
|
1519
1723
|
dispatchElementTemplateUpdate({
|
|
1520
1724
|
ops: [],
|
|
1521
1725
|
flushOptions: {},
|
|
@@ -1527,7 +1731,6 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1527
1731
|
resolveId: 10,
|
|
1528
1732
|
},
|
|
1529
1733
|
],
|
|
1530
|
-
mainThreadRefInitValuePatch: [[1, 'stale-init']],
|
|
1531
1734
|
});
|
|
1532
1735
|
envManager.switchToMainThread();
|
|
1533
1736
|
|
|
@@ -1535,6 +1738,7 @@ describe('ElementTemplate patch stream (apply)', () => {
|
|
|
1535
1738
|
expect(runRunOnMainThreadTask).not.toHaveBeenCalled();
|
|
1536
1739
|
expect(mockFlushElementTree).not.toHaveBeenCalled();
|
|
1537
1740
|
} finally {
|
|
1741
|
+
resetElementTemplateRefInitValueListener();
|
|
1538
1742
|
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
1539
1743
|
}
|
|
1540
1744
|
});
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
installElementTemplatePatchListener,
|
|
5
5
|
resetElementTemplatePatchListener,
|
|
6
6
|
} from '../../../../src/element-template/native/patch-listener.js';
|
|
7
|
-
import { setPipeline } from '../../../../src/core/performance.js';
|
|
7
|
+
import { globalPipelineOptions, setPipeline } from '../../../../src/core/performance.js';
|
|
8
8
|
import { ElementTemplateUpdateOps } from '../../../../src/element-template/protocol/opcodes.js';
|
|
9
9
|
import { ElementTemplateLifecycleConstant } from '../../../../src/element-template/protocol/lifecycle-constant.js';
|
|
10
10
|
import {
|
|
@@ -105,6 +105,7 @@ describe('ElementTemplate update timing (main thread patch)', () => {
|
|
|
105
105
|
['pipelineID', 'patchChangesEnd'],
|
|
106
106
|
['pipelineID', 'mtsRenderEnd'],
|
|
107
107
|
]);
|
|
108
|
+
expect(globalPipelineOptions).toBeUndefined();
|
|
108
109
|
});
|
|
109
110
|
|
|
110
111
|
it('handles updates without pipeline options', () => {
|
|
@@ -154,6 +155,7 @@ describe('ElementTemplate update timing (main thread patch)', () => {
|
|
|
154
155
|
['pipelineID', 'parseChangesEnd'],
|
|
155
156
|
['pipelineID', 'mtsRenderEnd'],
|
|
156
157
|
]);
|
|
158
|
+
expect(globalPipelineOptions).toBeUndefined();
|
|
157
159
|
});
|
|
158
160
|
|
|
159
161
|
it('marks parse timing for empty update envelopes with pipeline options', () => {
|
|
@@ -179,6 +181,7 @@ describe('ElementTemplate update timing (main thread patch)', () => {
|
|
|
179
181
|
['pipelineID', 'parseChangesEnd'],
|
|
180
182
|
['pipelineID', 'mtsRenderEnd'],
|
|
181
183
|
]);
|
|
184
|
+
expect(globalPipelineOptions).toBeUndefined();
|
|
182
185
|
});
|
|
183
186
|
|
|
184
187
|
it('accepts update payloads from the current reload version', () => {
|
|
@@ -61,7 +61,10 @@ beforeEach(() => {
|
|
|
61
61
|
compiledTemplate: {
|
|
62
62
|
kind: 'element',
|
|
63
63
|
type: 'view',
|
|
64
|
-
attributesArray: [
|
|
64
|
+
attributesArray: [
|
|
65
|
+
{ kind: 'slot', key: 'id', attrSlotIndex: 0 },
|
|
66
|
+
{ kind: 'slot', key: 'main-thread:ref', attrSlotIndex: 1 },
|
|
67
|
+
],
|
|
65
68
|
},
|
|
66
69
|
},
|
|
67
70
|
]);
|
|
@@ -46,7 +46,10 @@ beforeEach(() => {
|
|
|
46
46
|
compiledTemplate: {
|
|
47
47
|
kind: 'element',
|
|
48
48
|
type: 'view',
|
|
49
|
-
attributesArray: [
|
|
49
|
+
attributesArray: [
|
|
50
|
+
{ kind: 'slot', key: 'id', attrSlotIndex: 0 },
|
|
51
|
+
{ kind: 'slot', key: 'main-thread:ref', attrSlotIndex: 1 },
|
|
52
|
+
],
|
|
50
53
|
},
|
|
51
54
|
},
|
|
52
55
|
]);
|
|
@@ -15,9 +15,11 @@ import {
|
|
|
15
15
|
clearEtAttrPlanMap,
|
|
16
16
|
} from '../../../../src/element-template/runtime/template/attr-slot-plan.js';
|
|
17
17
|
import {
|
|
18
|
+
applyPendingMainThreadRefAttachments,
|
|
18
19
|
clearMainThreadDynamicAttrState,
|
|
19
20
|
getMainThreadDynamicAttrState,
|
|
20
21
|
initializeMainThreadDynamicAttrSlots,
|
|
22
|
+
updateMainThreadRefAttrSlot,
|
|
21
23
|
} from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
|
|
22
24
|
import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
|
|
23
25
|
|
|
@@ -50,6 +52,7 @@ describe('renderMainThread', () => {
|
|
|
50
52
|
vi.stubGlobal('__InsertNodeToElementTemplate', vi.fn());
|
|
51
53
|
vi.stubGlobal('__SetAttributeOfElementTemplate', vi.fn());
|
|
52
54
|
vi.stubGlobal('__SerializeElementTemplate', vi.fn());
|
|
55
|
+
vi.stubGlobal('__FlushElementTree', vi.fn());
|
|
53
56
|
elementTemplateRegistry.clear();
|
|
54
57
|
destroyAllElementTemplateListStates();
|
|
55
58
|
clearMainThreadDynamicAttrState();
|
|
@@ -281,6 +284,8 @@ describe('renderMainThread', () => {
|
|
|
281
284
|
|
|
282
285
|
it('attaches root MTRef state only after page insertion succeeds', () => {
|
|
283
286
|
const rootRef = { type: 'root-ref' } as unknown as ElementTemplateHandle;
|
|
287
|
+
const target = { type: 'actual-element' } as unknown as ElementRef;
|
|
288
|
+
vi.mocked(__GetElementByAttrSlot).mockReturnValue(target);
|
|
284
289
|
const ref = { _wvid: 80 };
|
|
285
290
|
const updateWorkletRef = vi.fn();
|
|
286
291
|
const previousWorkletImpl = globalThis.lynxWorkletImpl;
|
|
@@ -312,7 +317,12 @@ describe('renderMainThread', () => {
|
|
|
312
317
|
try {
|
|
313
318
|
renderMainThread();
|
|
314
319
|
|
|
315
|
-
expect(updateWorkletRef).toHaveBeenCalledWith(ref,
|
|
320
|
+
expect(updateWorkletRef).toHaveBeenCalledWith(ref, target);
|
|
321
|
+
expect(__FlushElementTree).not.toHaveBeenCalled();
|
|
322
|
+
expect(updateWorkletRef.mock.invocationCallOrder[0]).toBeLessThan(
|
|
323
|
+
vi.mocked(__SerializeElementTemplate).mock.invocationCallOrder[0]!,
|
|
324
|
+
);
|
|
325
|
+
expect(updateWorkletRef.mock.invocationCallOrder[0]).toBeLessThan(dispatchEvent.mock.invocationCallOrder[0]!);
|
|
316
326
|
expect(vi.mocked(__InsertNodeToElementTemplate).mock.invocationCallOrder[0]).toBeLessThan(
|
|
317
327
|
updateWorkletRef.mock.invocationCallOrder[0]!,
|
|
318
328
|
);
|
|
@@ -325,6 +335,96 @@ describe('renderMainThread', () => {
|
|
|
325
335
|
}
|
|
326
336
|
});
|
|
327
337
|
|
|
338
|
+
it('delivers first-screen callback effects before a synchronous hydrate roundtrip', () => {
|
|
339
|
+
const rootRef = {} as ElementTemplateHandle;
|
|
340
|
+
const target = {} as ElementRef;
|
|
341
|
+
const first = { _wkltId: 'ref-callback', initialized: false, delayIndices: [] as number[] };
|
|
342
|
+
const hydrated = { _wkltId: 'ref-callback' };
|
|
343
|
+
const events: string[] = [];
|
|
344
|
+
const previousRunWorklet = globalThis.runWorklet;
|
|
345
|
+
const previousWorkletImpl = globalThis.lynxWorkletImpl;
|
|
346
|
+
globalThis.runWorklet = vi.fn().mockImplementationOnce(() => {
|
|
347
|
+
events.push('first attach');
|
|
348
|
+
first.initialized = true;
|
|
349
|
+
first.delayIndices.push(0);
|
|
350
|
+
return () => events.push('first cleanup');
|
|
351
|
+
}).mockImplementation(() => {
|
|
352
|
+
events.push('hydrated attach');
|
|
353
|
+
});
|
|
354
|
+
globalThis.lynxWorkletImpl = {
|
|
355
|
+
...previousWorkletImpl,
|
|
356
|
+
_hydrateCtx: vi.fn((_next, previous) => {
|
|
357
|
+
expect(previous).toBe(first);
|
|
358
|
+
expect(first.initialized).toBe(true);
|
|
359
|
+
expect(first.delayIndices).toEqual([0]);
|
|
360
|
+
events.push('hydrate context');
|
|
361
|
+
}),
|
|
362
|
+
} as typeof globalThis.lynxWorkletImpl;
|
|
363
|
+
__etAttrPlanMap._et_ref = [0, adaptMTRefAttrSlot];
|
|
364
|
+
initializeMainThreadDynamicAttrSlots(-1, '_et_ref', [{ type: 'main-thread-ref', value: first }]);
|
|
365
|
+
vi.mocked(mockRender).mockReturnValue({
|
|
366
|
+
pageAttributes: null,
|
|
367
|
+
rootRefs: [rootRef],
|
|
368
|
+
rootSubtreeHandles: [[{ uid: -1, ref: rootRef }]],
|
|
369
|
+
});
|
|
370
|
+
vi.mocked(__GetElementByAttrSlot).mockReturnValue(target);
|
|
371
|
+
vi.mocked(__SerializeElementTemplate).mockImplementation(() => {
|
|
372
|
+
events.push('serialize');
|
|
373
|
+
return {} as ReturnType<typeof __SerializeElementTemplate>;
|
|
374
|
+
});
|
|
375
|
+
dispatchEvent.mockImplementation(() => {
|
|
376
|
+
events.push('dispatch hydrate');
|
|
377
|
+
updateMainThreadRefAttrSlot(-1, 0, { type: 'main-thread-ref', value: hydrated }, rootRef, true);
|
|
378
|
+
applyPendingMainThreadRefAttachments();
|
|
379
|
+
});
|
|
380
|
+
try {
|
|
381
|
+
renderMainThread();
|
|
382
|
+
expect(events).toEqual([
|
|
383
|
+
'first attach',
|
|
384
|
+
'serialize',
|
|
385
|
+
'dispatch hydrate',
|
|
386
|
+
'first cleanup',
|
|
387
|
+
'hydrate context',
|
|
388
|
+
'hydrated attach',
|
|
389
|
+
]);
|
|
390
|
+
clearMainThreadDynamicAttrState();
|
|
391
|
+
} finally {
|
|
392
|
+
globalThis.runWorklet = previousRunWorklet;
|
|
393
|
+
globalThis.lynxWorkletImpl = previousWorkletImpl;
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it.each(['missing target', 'callback throws'])(
|
|
398
|
+
'does not serialize or dispatch hydration when first-screen %s',
|
|
399
|
+
failure => {
|
|
400
|
+
const rootRef = {} as ElementTemplateHandle;
|
|
401
|
+
const previousRunWorklet = globalThis.runWorklet;
|
|
402
|
+
globalThis.runWorklet = vi.fn(() => {
|
|
403
|
+
throw new Error('ref callback failed');
|
|
404
|
+
});
|
|
405
|
+
__etAttrPlanMap._et_ref = [0, adaptMTRefAttrSlot];
|
|
406
|
+
initializeMainThreadDynamicAttrSlots(-1, '_et_ref', [{
|
|
407
|
+
type: 'main-thread-ref',
|
|
408
|
+
value: { _wkltId: 'failed-ref' },
|
|
409
|
+
}]);
|
|
410
|
+
vi.mocked(mockRender).mockReturnValue({
|
|
411
|
+
pageAttributes: null,
|
|
412
|
+
rootRefs: [rootRef],
|
|
413
|
+
rootSubtreeHandles: [[{ uid: -1, ref: rootRef }]],
|
|
414
|
+
});
|
|
415
|
+
vi.mocked(__GetElementByAttrSlot).mockReturnValue(failure === 'missing target' ? null : {} as ElementRef);
|
|
416
|
+
try {
|
|
417
|
+
expect(() => renderMainThread()).toThrow(
|
|
418
|
+
failure === 'missing target' ? 'could not be materialized' : 'ref callback failed',
|
|
419
|
+
);
|
|
420
|
+
expect(__SerializeElementTemplate).not.toHaveBeenCalled();
|
|
421
|
+
expect(dispatchEvent).not.toHaveBeenCalled();
|
|
422
|
+
} finally {
|
|
423
|
+
globalThis.runWorklet = previousRunWorklet;
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
);
|
|
427
|
+
|
|
328
428
|
it('keeps root MTRef state blocked when page insertion throws', () => {
|
|
329
429
|
const rootRef = { type: 'root-ref' } as unknown as ElementTemplateHandle;
|
|
330
430
|
const ref = { _wvid: 81 };
|
|
@@ -22,6 +22,7 @@ import { applyElementTemplateUpdateCommands } from '../../../../src/element-temp
|
|
|
22
22
|
import { ElementTemplateUpdateOps } from '../../../../src/element-template/protocol/opcodes.js';
|
|
23
23
|
import { renderToElementTemplate } from '../../../../src/element-template/runtime/render/render-direct.js';
|
|
24
24
|
import { resetElementTemplatePatchListener } from '../../../../src/element-template/native/patch-listener.js';
|
|
25
|
+
import { resetElementTemplateRefInitValueListener } from '../../../../src/element-template/main-thread-ref-init-value.js';
|
|
25
26
|
import { resetTemplateId } from '../../../../src/element-template/runtime/template/handle.js';
|
|
26
27
|
import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
|
|
27
28
|
import type {
|
|
@@ -181,6 +182,7 @@ async function compileAndRender(
|
|
|
181
182
|
};
|
|
182
183
|
} finally {
|
|
183
184
|
resetElementTemplatePatchListener();
|
|
185
|
+
resetElementTemplateRefInitValueListener();
|
|
184
186
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
185
187
|
}
|
|
186
188
|
}
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
clearMainThreadDynamicAttrState,
|
|
24
24
|
getMainThreadDynamicAttrState,
|
|
25
25
|
} from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
|
|
26
|
+
import { JsFunctionLifecycleManager } from '../../../../src/worklet-runtime/jsFunctionLifecycle.js';
|
|
26
27
|
import { resetTemplateId } from '../../../../src/element-template/runtime/template/handle.js';
|
|
27
28
|
|
|
28
29
|
describe('ElementTemplateHandle', () => {
|
|
@@ -102,6 +103,37 @@ describe('ElementTemplateHandle', () => {
|
|
|
102
103
|
});
|
|
103
104
|
});
|
|
104
105
|
|
|
106
|
+
it.each(['success', 'null', 'throw'])(
|
|
107
|
+
'prepares and tracks create input before Native %s without advancing failed state',
|
|
108
|
+
(outcome) => {
|
|
109
|
+
const previous = globalThis.lynxWorkletImpl;
|
|
110
|
+
const manager = new JsFunctionLifecycleManager();
|
|
111
|
+
globalThis.lynxWorkletImpl = { ...previous, _jsFunctionLifecycleManager: manager };
|
|
112
|
+
const ctx = { _wkltId: 'tap', _execId: 21 };
|
|
113
|
+
const retain = vi.spyOn(manager, 'addRef');
|
|
114
|
+
const error = new Error('create failed');
|
|
115
|
+
__etAttrPlanMap['__Card__:_et_test'] = [0, adaptMTEventAttrSlot];
|
|
116
|
+
mockCreateCompiledElementTemplate.mockImplementationOnce((_key, _url, slots) => {
|
|
117
|
+
expect(slots[0].value).toBe(ctx);
|
|
118
|
+
expect(retain).toHaveBeenCalledExactlyOnceWith(21, ctx);
|
|
119
|
+
expect(getMainThreadDynamicAttrState(-1, 0)).toBeUndefined();
|
|
120
|
+
if (outcome === 'throw') throw error;
|
|
121
|
+
return outcome === 'null' ? null : mockCreatedNativeRef;
|
|
122
|
+
});
|
|
123
|
+
try {
|
|
124
|
+
const create = () =>
|
|
125
|
+
createElementTemplateWithReservedHandle(-1, '_et_test', null, [{ type: 'worklet', value: ctx }], null);
|
|
126
|
+
if (outcome === 'throw') expect(create).toThrow(error);
|
|
127
|
+
else expect(create()).toBe(outcome === 'null' ? null : mockCreatedNativeRef);
|
|
128
|
+
expect(retain).toHaveBeenCalledExactlyOnceWith(21, ctx);
|
|
129
|
+
expect(getMainThreadDynamicAttrState(-1, 0)?.nativeHeldValue).toBe(outcome === 'success' ? ctx : undefined);
|
|
130
|
+
} finally {
|
|
131
|
+
manager.dispose();
|
|
132
|
+
globalThis.lynxWorkletImpl = previous;
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
|
|
105
137
|
it('records dynamic-entry main-thread dynamic attr state with the full template identity', () => {
|
|
106
138
|
const id = reserveElementTemplateId();
|
|
107
139
|
const ctx = { _wkltId: 'tap' };
|