@lynx-js/react 0.129.3 → 0.129.5
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 +38 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -2
- package/refresh/.turbo/turbo-build.log +3 -3
- package/refresh/dist/index.js +113 -20
- package/refresh/rslib.config.ts +13 -3
- package/refresh/src/index.ts +100 -0
- package/refresh/src/self.ts +38 -0
- package/runtime/__test__/{snapshot → core}/attribute-name.test.ts +1 -1
- package/runtime/__test__/core/background-function.test.ts +37 -0
- package/runtime/__test__/{shared → core}/component-stack.test.ts +4 -4
- package/runtime/__test__/core/lynx/env.test.ts +146 -0
- package/runtime/__test__/core/ref.test.ts +218 -1
- package/runtime/__test__/core/sync-effect-flush.test.ts +58 -0
- package/runtime/__test__/element-template/debug/alog.test.ts +20 -12
- package/runtime/__test__/element-template/fixtures/background/hydrate/_shared.tsx +15 -34
- package/runtime/__test__/element-template/fixtures/background/hydrate/children.creates-missing-nodes-recursively/output.txt +2 -0
- package/runtime/__test__/element-template/fixtures/background/hydrate/children.iterates-existing-slots/output.txt +1 -0
- package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-attrs-element/output.txt +6 -1
- package/runtime/__test__/element-template/fixtures/background/hydrate/children.missing-slot-record-on-main/output.txt +1 -0
- package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.move-before-child → children.reconciles-raw-text-slots}/case.tsx +1 -1
- package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text/output.txt +1 -0
- package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.emit-create-raw-text-non-text/output.txt +1 -0
- package/runtime/__test__/element-template/fixtures/background/hydrate/root-key-mismatch-reconciles/output.txt +1 -0
- package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.creates-and-inserts-new/output.txt +1 -0
- package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.inserts-before-existing-sibling/output.txt +1 -0
- package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.mixed-operations/output.txt +1 -0
- package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -0
- package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/complex-trees.deeply-nested-dynamic-content/output.txt +1 -0
- package/runtime/__test__/element-template/fixtures/background/instance/ops/emits-bundle-url-in-create-template/output.txt +1 -0
- package/runtime/__test__/element-template/fixtures/list/mts/index.tsx +185 -0
- package/runtime/__test__/element-template/fixtures/page/render-page/native-log.txt +1 -0
- package/runtime/__test__/element-template/fixtures/patch/detaches-node-when-moving-between-slots/case.tsx +2 -0
- package/runtime/__test__/element-template/fixtures/patch-compiled/applies-insert-before-with-reference/ops.txt +1 -0
- package/runtime/__test__/element-template/fixtures/patch-compiled/apply-hydration-ops/ops.txt +1 -0
- package/runtime/__test__/element-template/fixtures/render/child-siblings/papi.txt +10 -5
- package/runtime/__test__/element-template/fixtures/render/component/papi.txt +6 -3
- package/runtime/__test__/element-template/fixtures/render/component-slot-content/papi.txt +6 -3
- package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/papi.txt +2 -1
- package/runtime/__test__/element-template/fixtures/render/direct-native/appends-root-text-via-append-element/native-log.txt +1 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/native-log.txt +2 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-template-children-in-the-same-slot/native-log.txt +3 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +3 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/native-log.txt +3 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/native-log.txt +3 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/native-log.txt +1 -0
- package/runtime/__test__/element-template/fixtures/render/mapped-view-children/papi.txt +14 -7
- package/runtime/__test__/element-template/fixtures/render/mixed-children/papi.txt +8 -4
- package/runtime/__test__/element-template/fixtures/render/multiple-text/papi.txt +38 -19
- package/runtime/__test__/element-template/fixtures/render/nested-templates/papi.txt +6 -3
- package/runtime/__test__/element-template/fixtures/render/react-example/papi.txt +6 -3
- package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/papi.txt +6 -3
- package/runtime/__test__/element-template/fixtures/render/template-dedupe/papi.txt +10 -5
- package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +47 -4
- package/runtime/__test__/element-template/lynx/performance.test.ts +1 -0
- package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +1 -0
- package/runtime/__test__/element-template/native/index.test.ts +9 -9
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +65 -17
- package/runtime/__test__/element-template/native/reload.test.ts +19 -12
- package/runtime/__test__/element-template/runtime/background/adapter/background-adapter.et.test.tsx +0 -32
- package/runtime/__test__/element-template/runtime/background/commit-context.test.ts +0 -14
- package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +10 -0
- package/runtime/__test__/element-template/runtime/background/event/compiled-fixtures.test.tsx +22 -0
- package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +197 -252
- package/runtime/__test__/element-template/runtime/background/instance.test.ts +277 -126
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +1 -1
- package/runtime/__test__/element-template/runtime/background/passive-update-depth.test.tsx +496 -0
- package/runtime/__test__/element-template/runtime/background/render/preact.test.tsx +16 -22
- package/runtime/__test__/element-template/runtime/background/root-render.test.tsx +5 -3
- package/runtime/__test__/element-template/runtime/background/suspense.test.tsx +2 -0
- package/runtime/__test__/element-template/runtime/background/update/compiled-fixtures.test.tsx +1 -0
- package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +1 -0
- package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +4 -5
- package/runtime/__test__/element-template/runtime/list/list-mts-compiled.test.ts +525 -0
- package/runtime/__test__/element-template/runtime/page/compiled-fixtures.test.tsx +2 -0
- package/runtime/__test__/element-template/runtime/page/root-instance.test.ts +2 -14
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +425 -1032
- package/runtime/__test__/element-template/runtime/patch/patch-listener-alog.test.ts +1 -0
- package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +1 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/event.test.ts +0 -20
- package/runtime/__test__/element-template/runtime/prop-adapters/gesture.test.ts +2 -1
- package/runtime/__test__/element-template/runtime/prop-adapters/hydrate.test.ts +1 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/ref.test.ts +65 -0
- package/runtime/__test__/element-template/runtime/prop-adapters/spread-mts-compiled.test.ts +12 -4
- package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +2 -5
- package/runtime/__test__/element-template/runtime/render/render-direct-native.test.tsx +56 -121
- package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +18 -17
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +5 -4
- package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -0
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +1 -60
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +65 -89
- package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +8 -6
- package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +34 -6
- package/runtime/__test__/element-template/test-utils/debug/updateRunner.test.tsx +20 -12
- package/runtime/__test__/element-template/test-utils/debug/updateRunner.ts +2 -28
- package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.test.ts +14 -5
- package/runtime/__test__/element-template/test-utils/mock/mockNativePapi/templateTree.ts +1 -57
- package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +29 -13
- package/runtime/__test__/element-template/vitest.config.ts +2 -1
- package/runtime/__test__/guardrails/snapshot-containment.test.ts +98 -77
- package/runtime/__test__/snapshot/debug/passive-update-depth.test.jsx +549 -0
- package/runtime/__test__/snapshot/debug/profile.test.jsx +147 -26
- package/runtime/__test__/snapshot/debug/react-hooks-profile.test.jsx +3 -3
- package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +138 -1
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +55 -1
- package/runtime/__test__/snapshot/lifecycle/transfer.mts.test.jsx +286 -0
- package/runtime/__test__/snapshot/lifecycle/transfer.test.jsx +415 -0
- package/runtime/__test__/snapshot/list.test.jsx +109 -0
- package/runtime/__test__/snapshot/lynx/suspense.test.jsx +48 -0
- package/runtime/__test__/snapshot/lynxQueueMicrotask.test.jsx +2 -2
- package/runtime/__test__/snapshot/ref.test.jsx +124 -1
- package/runtime/__test__/snapshot/utils/envManager.ts +7 -0
- package/runtime/__test__/snapshot/utils/globals.js +1 -0
- package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +43 -11
- package/runtime/__test__/worklet-runtime/hydrate.test.js +1 -0
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +24 -16
- package/runtime/__test__/worklet-runtime/lifecycle.test.js +297 -0
- package/runtime/__test__/worklet-runtime/profile.test.js +12 -6
- package/runtime/__test__/worklet-runtime/runOnBackground.test.js +188 -0
- package/runtime/__test__/worklet-runtime/workletRef.test.js +16 -0
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +53 -1
- package/runtime/lazy/element-template-internal.js +1 -0
- package/runtime/lazy/internal.js +1 -0
- package/runtime/lib/core/attribute-name.js.map +1 -0
- package/runtime/lib/core/background-function/run-on-background.js +7 -7
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
- package/runtime/lib/core/compat/componentIs.d.ts +1 -0
- package/runtime/lib/core/compat/componentIs.js +20 -0
- package/runtime/lib/core/compat/componentIs.js.map +1 -0
- package/runtime/lib/{shared → core}/component-stack.js +1 -1
- package/runtime/lib/core/component-stack.js.map +1 -0
- package/runtime/lib/core/deep-equal.d.ts +1 -0
- package/runtime/lib/core/deep-equal.js +31 -0
- package/runtime/lib/core/deep-equal.js.map +1 -0
- package/runtime/lib/core/hooks/mainThreadImpl.js +1 -1
- package/runtime/lib/core/hooks/mainThreadImpl.js.map +1 -1
- package/runtime/lib/core/lynx/env.d.ts +1 -0
- package/runtime/lib/{element-template → core}/lynx/env.js +3 -2
- package/runtime/lib/core/lynx/env.js.map +1 -0
- package/runtime/lib/core/lynx-page-data.js +1 -1
- package/runtime/lib/core/lynx-page-data.js.map +1 -1
- package/runtime/lib/core/mts-capability.js +1 -1
- package/runtime/lib/core/mts-capability.js.map +1 -1
- package/runtime/lib/core/performance.js +2 -1
- package/runtime/lib/core/performance.js.map +1 -1
- package/runtime/lib/core/ref.d.ts +1 -2
- package/runtime/lib/core/ref.js +60 -9
- package/runtime/lib/core/ref.js.map +1 -1
- package/runtime/lib/core/sync-effect-flush.d.ts +9 -0
- package/runtime/lib/core/sync-effect-flush.js +31 -0
- package/runtime/lib/core/sync-effect-flush.js.map +1 -0
- package/runtime/lib/core/thread-function-call/main-thread.d.ts +1 -0
- package/runtime/lib/core/thread-function-call/main-thread.js +5 -2
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- package/runtime/lib/element-template/background/attr-slots.d.ts +1 -0
- package/runtime/lib/element-template/background/attr-slots.js.map +1 -1
- package/runtime/lib/element-template/background/commit-event.d.ts +6 -0
- package/runtime/lib/element-template/background/commit-event.js +36 -0
- package/runtime/lib/element-template/background/commit-event.js.map +1 -0
- package/runtime/lib/element-template/background/commit-hook.js +4 -24
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js +2 -2
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +174 -87
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js +5 -25
- package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
- package/runtime/lib/element-template/background/instance.d.ts +7 -10
- package/runtime/lib/element-template/background/instance.js +65 -58
- package/runtime/lib/element-template/background/instance.js.map +1 -1
- package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.js +4 -4
- package/runtime/lib/element-template/background/main-thread-function.js.map +1 -0
- package/runtime/lib/element-template/background/render-scope.js +2 -1
- package/runtime/lib/element-template/background/render-scope.js.map +1 -1
- package/runtime/lib/element-template/debug/alog.d.ts +1 -10
- package/runtime/lib/element-template/debug/alog.js +1 -16
- package/runtime/lib/element-template/debug/alog.js.map +1 -1
- package/runtime/lib/element-template/debug/profile.js +1 -1
- package/runtime/lib/element-template/debug/profile.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +1 -1
- package/runtime/lib/element-template/index.js +1 -1
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.js +3 -0
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/native/index.js +4 -4
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.d.ts +2 -1
- package/runtime/lib/element-template/native/mts-destroy.js +15 -4
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +4 -8
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js +2 -6
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/ref.d.ts +2 -1
- package/runtime/lib/element-template/prop-adapters/ref.js +4 -4
- package/runtime/lib/element-template/prop-adapters/ref.js.map +1 -1
- package/runtime/lib/element-template/prop-adapters/spread.js +1 -1
- package/runtime/lib/element-template/prop-adapters/spread.js.map +1 -1
- package/runtime/lib/element-template/protocol/opcodes.d.ts +0 -2
- package/runtime/lib/element-template/protocol/opcodes.js +0 -2
- package/runtime/lib/element-template/protocol/opcodes.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +8 -30
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/runtime/list/list.d.ts +14 -54
- package/runtime/lib/element-template/runtime/list/list.js +82 -546
- package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
- package/runtime/lib/element-template/runtime/list/platform-info.d.ts +2 -0
- package/runtime/lib/element-template/runtime/list/platform-info.js +26 -0
- package/runtime/lib/element-template/runtime/list/platform-info.js.map +1 -0
- package/runtime/lib/element-template/runtime/patch.js +44 -128
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +1 -1
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js +24 -21
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.d.ts +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js +3 -6
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-direct.js +21 -20
- package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +0 -13
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js +8 -0
- package/runtime/lib/element-template/runtime/template/attr-slot-plan.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.d.ts +3 -3
- package/runtime/lib/element-template/runtime/template/handle.js +3 -3
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.d.ts +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -8
- 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 +2 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +44 -28
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/typed-attributes.d.ts +2 -0
- package/runtime/lib/element-template/runtime/template/typed-attributes.js +8 -1
- package/runtime/lib/element-template/runtime/template/typed-attributes.js.map +1 -1
- package/runtime/lib/internal.d.ts +1 -0
- package/runtime/lib/internal.js +5 -10
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.js +6 -1
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +4 -4
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/root.d.ts +5 -1
- package/runtime/lib/root.js +12 -1
- package/runtime/lib/root.js.map +1 -1
- package/runtime/lib/shared/microtask.d.ts +1 -0
- package/runtime/lib/shared/microtask.js +28 -0
- package/runtime/lib/shared/microtask.js.map +1 -0
- package/runtime/lib/shared/utils.d.ts +8 -0
- package/runtime/lib/shared/utils.js +27 -0
- package/runtime/lib/shared/utils.js.map +1 -0
- package/runtime/lib/{worklet-runtime/utils → shared}/version.d.ts +1 -0
- package/runtime/lib/{worklet-runtime/utils → shared}/version.js +4 -2
- package/runtime/lib/shared/version.js.map +1 -0
- package/runtime/lib/snapshot/alog/render.js +1 -1
- package/runtime/lib/snapshot/alog/render.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js +28 -63
- package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/destroy.js +2 -2
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/isRendering.js +2 -1
- package/runtime/lib/snapshot/lifecycle/isRendering.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/commit.d.ts +7 -2
- package/runtime/lib/snapshot/lifecycle/patch/commit.js +11 -6
- package/runtime/lib/snapshot/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.d.ts +5 -0
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.d.ts +1 -1
- package/runtime/lib/snapshot/lifecycle/ref/delay.js +2 -2
- package/runtime/lib/snapshot/lifecycle/ref/delay.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.js +3 -3
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/list/list.js +12 -3
- package/runtime/lib/snapshot/list/list.js.map +1 -1
- package/runtime/lib/snapshot/lynx/env.js +2 -32
- package/runtime/lib/snapshot/lynx/env.js.map +1 -1
- package/runtime/lib/snapshot/lynx/tt.d.ts +3 -1
- package/runtime/lib/snapshot/lynx/tt.js +7 -3
- package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.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/platformInfo.js +1 -1
- package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/ref.d.ts +1 -0
- package/runtime/lib/snapshot/snapshot/ref.js +2 -2
- package/runtime/lib/snapshot/snapshot/ref.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshot.js +1 -1
- package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/spread.js +3 -2
- package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
- package/runtime/lib/snapshot/transfer.d.ts +21 -0
- package/runtime/lib/snapshot/transfer.js +486 -0
- package/runtime/lib/snapshot/transfer.js.map +1 -0
- package/runtime/lib/snapshot/worklet/functionality.js +1 -1
- package/runtime/lib/snapshot/worklet/functionality.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/api/element.js +1 -1
- package/runtime/lib/worklet-runtime/api/element.js.map +1 -1
- package/runtime/lib/worklet-runtime/api/lynxApi.js +1 -1
- package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -2
- package/runtime/lib/worklet-runtime/bindings/bindings.js +11 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/lifecycle.d.ts +19 -0
- package/runtime/lib/worklet-runtime/bindings/lifecycle.js +49 -0
- package/runtime/lib/worklet-runtime/bindings/lifecycle.js.map +1 -0
- package/runtime/lib/worklet-runtime/bindings/observers.js +9 -1
- package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/types.d.ts +1 -0
- package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
- package/runtime/lib/worklet-runtime/delayWorkletEvent.d.ts +3 -5
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js +49 -43
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -1
- package/runtime/lib/worklet-runtime/global.d.ts +1 -2
- package/runtime/lib/worklet-runtime/global.js.map +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js +2 -32
- package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
- package/runtime/lib/worklet-runtime/run-on-background/index.d.ts +28 -0
- package/runtime/lib/worklet-runtime/run-on-background/index.js +103 -0
- package/runtime/lib/worklet-runtime/run-on-background/index.js.map +1 -0
- package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.d.ts → run-on-background/lifecycle.d.ts} +2 -2
- package/runtime/lib/worklet-runtime/{jsFunctionLifecycle.js → run-on-background/lifecycle.js} +12 -9
- package/runtime/lib/worklet-runtime/run-on-background/lifecycle.js.map +1 -0
- package/runtime/lib/worklet-runtime/utils/profile.js +1 -3
- package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRef.js +51 -54
- package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +5 -6
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/src/core/background-function/run-on-background.ts +7 -7
- package/runtime/src/core/compat/componentIs.ts +32 -0
- package/runtime/src/{shared → core}/component-stack.ts +1 -1
- package/runtime/src/core/deep-equal.ts +33 -0
- package/runtime/src/core/hooks/mainThreadImpl.ts +1 -1
- package/runtime/src/{element-template → core}/lynx/env.ts +6 -4
- package/runtime/src/core/lynx-page-data.ts +1 -1
- package/runtime/src/core/mts-capability.ts +1 -1
- package/runtime/src/core/performance.ts +2 -1
- package/runtime/src/core/ref.ts +92 -15
- package/runtime/src/core/sync-effect-flush.ts +30 -0
- package/runtime/src/core/thread-function-call/main-thread.ts +6 -2
- package/runtime/src/element-template/background/attr-slots.ts +2 -2
- package/runtime/src/element-template/background/commit-event.ts +52 -0
- package/runtime/src/element-template/background/commit-hook.ts +5 -32
- package/runtime/src/element-template/background/destroy.ts +2 -2
- package/runtime/src/element-template/background/hydrate.ts +234 -122
- package/runtime/src/element-template/background/hydration-listener.ts +7 -32
- package/runtime/src/element-template/background/instance.ts +82 -82
- package/runtime/src/element-template/{runtime/template → background}/main-thread-function.ts +4 -7
- package/runtime/src/element-template/background/render-scope.ts +2 -1
- package/runtime/src/element-template/debug/alog.ts +2 -30
- package/runtime/src/element-template/debug/profile.ts +1 -1
- package/runtime/src/element-template/index.ts +1 -1
- package/runtime/src/element-template/internal.ts +4 -0
- package/runtime/src/element-template/native/index.ts +4 -4
- package/runtime/src/element-template/native/mts-destroy.ts +21 -4
- package/runtime/src/element-template/native/patch-listener.ts +6 -7
- package/runtime/src/element-template/native/reload-main-thread.ts +2 -6
- package/runtime/src/element-template/prop-adapters/ref.ts +12 -5
- package/runtime/src/element-template/prop-adapters/spread.ts +1 -1
- package/runtime/src/element-template/protocol/opcodes.ts +0 -2
- package/runtime/src/element-template/protocol/types.ts +10 -38
- package/runtime/src/element-template/runtime/list/list.ts +115 -744
- package/runtime/src/element-template/runtime/list/platform-info.ts +31 -0
- package/runtime/src/element-template/runtime/patch.ts +78 -197
- package/runtime/src/element-template/runtime/render/create-rendered-host.ts +27 -31
- package/runtime/src/element-template/runtime/render/render-components.ts +2 -5
- package/runtime/src/element-template/runtime/render/render-direct.ts +19 -18
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +0 -14
- package/runtime/src/element-template/runtime/template/attr-slot-plan.ts +9 -0
- package/runtime/src/element-template/runtime/template/handle.ts +5 -2
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +9 -8
- package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +44 -30
- package/runtime/src/element-template/runtime/template/typed-attributes.ts +17 -1
- package/runtime/src/element-template/types.d.ts +6 -22
- package/runtime/src/internal.ts +6 -13
- package/runtime/src/lynx-api.ts +6 -1
- package/runtime/src/lynx.ts +4 -4
- package/runtime/src/root.ts +17 -1
- package/runtime/src/shared/microtask.ts +26 -0
- package/runtime/src/shared/utils.ts +37 -0
- package/runtime/src/{worklet-runtime/utils → shared}/version.ts +6 -4
- package/runtime/src/snapshot/alog/render.ts +1 -1
- package/runtime/src/snapshot/debug/profileHooks.ts +31 -92
- package/runtime/src/snapshot/lifecycle/destroy.ts +2 -2
- package/runtime/src/snapshot/lifecycle/isRendering.ts +2 -1
- package/runtime/src/snapshot/lifecycle/patch/commit.ts +28 -7
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +1 -1
- package/runtime/src/snapshot/lifecycle/ref/delay.ts +5 -2
- package/runtime/src/snapshot/lifecycle/reload.ts +3 -4
- package/runtime/src/snapshot/list/list.ts +12 -3
- package/runtime/src/snapshot/lynx/env.ts +3 -43
- package/runtime/src/snapshot/lynx/tt.ts +8 -3
- package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +1 -1
- package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
- package/runtime/src/snapshot/snapshot/platformInfo.ts +1 -1
- package/runtime/src/snapshot/snapshot/ref.ts +7 -4
- package/runtime/src/snapshot/snapshot/snapshot.ts +1 -1
- package/runtime/src/snapshot/snapshot/spread.ts +3 -2
- package/runtime/src/snapshot/transfer.ts +535 -0
- package/runtime/src/snapshot/worklet/functionality.ts +1 -1
- package/runtime/src/worklet-runtime/api/element.ts +1 -1
- package/runtime/src/worklet-runtime/api/lynxApi.ts +1 -1
- package/runtime/src/worklet-runtime/bindings/bindings.ts +12 -0
- package/runtime/src/worklet-runtime/bindings/lifecycle.ts +51 -0
- package/runtime/src/worklet-runtime/bindings/observers.ts +9 -1
- package/runtime/src/worklet-runtime/bindings/types.ts +1 -0
- package/runtime/src/worklet-runtime/delayWorkletEvent.ts +57 -54
- package/runtime/src/worklet-runtime/global.ts +1 -2
- package/runtime/src/worklet-runtime/hydrate.ts +2 -35
- package/runtime/src/worklet-runtime/run-on-background/index.ts +145 -0
- package/runtime/src/worklet-runtime/{jsFunctionLifecycle.ts → run-on-background/lifecycle.ts} +11 -9
- package/runtime/src/worklet-runtime/utils/profile.ts +1 -3
- package/runtime/src/worklet-runtime/workletRef.ts +63 -62
- package/runtime/src/worklet-runtime/workletRuntime.ts +10 -10
- package/runtime/types/internal-preact.d.ts +2 -0
- package/runtime/vitest.config.ts +0 -1
- package/testing-library/.turbo/turbo-build.log +11 -11
- package/testing-library/dist/pure.js +7 -4
- package/testing-library/dist/setupFiles/common/runtime-setup.js +3 -1
- package/testing-library/dist/setupFiles/inner/rstest.js +1 -1
- package/testing-library/dist/setupFiles/inner/vitest.js +1 -1
- package/testing-library/src/__tests__/events.test.jsx +1 -1
- package/testing-library/src/__tests__/list.test.jsx +52 -0
- package/testing-library/src/__tests__/worklet.test.jsx +81 -0
- package/testing-library/src/fire-event.ts +1 -1
- package/testing-library/src/pure.jsx +5 -2
- package/testing-library/src/setupFiles/common/runtime-setup.js +2 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +45 -44
- package/transform/__test__/fixture.spec.js +1 -1
- package/transform/cjs/browser.cjs +11 -0
- package/transform/crates/swc_plugin_compat/lib.rs +20 -2
- package/transform/crates/swc_plugin_compat/napi.rs +7 -0
- package/transform/crates/swc_plugin_dynamic_import/lib.rs +15 -4
- package/transform/crates/swc_plugin_element_template/attr_name.rs +0 -3
- package/transform/crates/swc_plugin_element_template/extractor.rs +0 -8
- package/transform/crates/swc_plugin_element_template/lib.rs +12 -1
- package/transform/crates/swc_plugin_element_template/tests/element_template.rs +19 -45
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +35 -19
- package/transform/crates/swc_plugin_worklet/lib.rs +11 -7
- package/transform/dist/wasm.cjs +1 -1
- package/transform/rspack-napi/lib/index.js +1 -4
- package/transform/rspack-napi/lib/index.js.map +1 -1
- package/transform/rspack-napi/src/index.ts +1 -4
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/src/lib.rs +394 -27
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +415 -107
- package/transform/swc-plugin-reactlynx/src/lib.rs +99 -22
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +29 -339
- package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
- package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.move-before-child/output.txt +0 -10
- package/runtime/__test__/element-template/fixtures/background/hydrate/coverage.raw-text-key-branches/case.tsx +0 -5
- package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/case.ts +0 -11
- package/runtime/__test__/element-template/fixtures/background/instance/ops/supports-silent-insert-before/output.txt +0 -1
- package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/case.ts +0 -23
- package/runtime/__test__/element-template/fixtures/background/instance/ops/treats-nullish-attrs-as-empty-object/output.txt +0 -6
- package/runtime/__test__/element-template/lynx/env.test.ts +0 -242
- package/runtime/__test__/element-template/runtime/page/authored-page.test.ts +0 -35
- package/runtime/__test__/element-template/runtime/patch/update-fixture-helper.test.tsx +0 -40
- package/runtime/__test__/snapshot/lynx-data-processors.test.ts +0 -3
- package/runtime/lib/element-template/lynx/env.d.ts +0 -1
- package/runtime/lib/element-template/lynx/env.js.map +0 -1
- package/runtime/lib/element-template/runtime/template/main-thread-function.js.map +0 -1
- package/runtime/lib/shared/attribute-name.js.map +0 -1
- package/runtime/lib/shared/component-stack.js.map +0 -1
- package/runtime/lib/snapshot/alog/index.d.ts +0 -1
- package/runtime/lib/snapshot/alog/index.js +0 -8
- package/runtime/lib/snapshot/alog/index.js.map +0 -1
- package/runtime/lib/snapshot/compat/componentIs.d.ts +0 -4
- package/runtime/lib/snapshot/compat/componentIs.js +0 -20
- package/runtime/lib/snapshot/compat/componentIs.js.map +0 -1
- package/runtime/lib/utils.d.ts +0 -19
- package/runtime/lib/utils.js +0 -119
- package/runtime/lib/utils.js.map +0 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.d.ts +0 -13
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js +0 -29
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +0 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +0 -1
- package/runtime/lib/worklet-runtime/utils/version.js.map +0 -1
- package/runtime/src/snapshot/alog/index.ts +0 -8
- package/runtime/src/snapshot/compat/componentIs.ts +0 -30
- package/runtime/src/utils.ts +0 -134
- package/runtime/src/worklet-runtime/delayRunOnBackground.ts +0 -53
- /package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.raw-text-key-branches → children.reconciles-raw-text-slots}/output.txt +0 -0
- /package/runtime/__test__/element-template/runtime/{template → background}/main-thread-function.test.ts +0 -0
- /package/runtime/lib/{shared → core}/attribute-name.d.ts +0 -0
- /package/runtime/lib/{shared → core}/attribute-name.js +0 -0
- /package/runtime/lib/{shared → core}/component-stack.d.ts +0 -0
- /package/runtime/lib/element-template/{runtime/template → background}/main-thread-function.d.ts +0 -0
- /package/runtime/src/{shared → core}/attribute-name.ts +0 -0
|
@@ -8,8 +8,9 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite
|
|
|
8
8
|
|
|
9
9
|
import { RefProxy, runDelayedUiOps, shouldDelayUiOps } from '../../src/snapshot/lifecycle/ref/delay';
|
|
10
10
|
import { destroyBackground } from '../../src/snapshot/lifecycle/destroy';
|
|
11
|
+
import { reloadBackground } from '../../src/snapshot/lifecycle/reload';
|
|
11
12
|
|
|
12
|
-
import { Component, createRef, useState } from '../../src/index';
|
|
13
|
+
import { Component, createPortal, createRef, useState } from '../../src/index';
|
|
13
14
|
import { clearCommitTaskId, replaceCommitHook } from '../../src/snapshot/lifecycle/patch/commit';
|
|
14
15
|
import { injectUpdateMainThread } from '../../src/snapshot/lifecycle/patch/updateMainThread';
|
|
15
16
|
import { __pendingListUpdates } from '../../src/snapshot/list/pendingListUpdates';
|
|
@@ -1661,6 +1662,7 @@ describe('ui operations', () => {
|
|
|
1661
1662
|
"invoke",
|
|
1662
1663
|
[
|
|
1663
1664
|
{
|
|
1665
|
+
"fail": [Function],
|
|
1664
1666
|
"method": "boundingClientRect",
|
|
1665
1667
|
},
|
|
1666
1668
|
],
|
|
@@ -1904,6 +1906,7 @@ describe('ui operations', () => {
|
|
|
1904
1906
|
"invoke",
|
|
1905
1907
|
[
|
|
1906
1908
|
{
|
|
1909
|
+
"fail": [Function],
|
|
1907
1910
|
"method": "boundingClientRect",
|
|
1908
1911
|
},
|
|
1909
1912
|
],
|
|
@@ -1970,6 +1973,7 @@ describe('ui operations', () => {
|
|
|
1970
1973
|
"invoke",
|
|
1971
1974
|
[
|
|
1972
1975
|
{
|
|
1976
|
+
"fail": [Function],
|
|
1973
1977
|
"method": "boundingClientRect",
|
|
1974
1978
|
},
|
|
1975
1979
|
],
|
|
@@ -2396,3 +2400,122 @@ describe('runDelayedUiOps helper', () => {
|
|
|
2396
2400
|
expect(invoke).not.toHaveBeenCalled();
|
|
2397
2401
|
});
|
|
2398
2402
|
});
|
|
2403
|
+
|
|
2404
|
+
describe('Snapshot ref selector error diagnostics', () => {
|
|
2405
|
+
it('enriches lookup failures on invoke while passing fields/path through and warning when fail is omitted in __DEV__', () => {
|
|
2406
|
+
const invokeQueue = [];
|
|
2407
|
+
const fieldsQueue = [];
|
|
2408
|
+
const pathQueue = [];
|
|
2409
|
+
const originalDev = globalThis.__DEV__;
|
|
2410
|
+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
2411
|
+
const reportErrorSpy = vi.spyOn(lynx, 'reportError').mockImplementation(() => {});
|
|
2412
|
+
|
|
2413
|
+
vi.spyOn(lynx, 'createSelectorQuery').mockImplementation(() => ({
|
|
2414
|
+
select(selector) {
|
|
2415
|
+
return {
|
|
2416
|
+
invoke(options) {
|
|
2417
|
+
return {
|
|
2418
|
+
exec() {
|
|
2419
|
+
invokeQueue.push({ selector, options });
|
|
2420
|
+
},
|
|
2421
|
+
};
|
|
2422
|
+
},
|
|
2423
|
+
fields(fields, cb) {
|
|
2424
|
+
return {
|
|
2425
|
+
exec() {
|
|
2426
|
+
fieldsQueue.push({ selector, fields, cb });
|
|
2427
|
+
},
|
|
2428
|
+
};
|
|
2429
|
+
},
|
|
2430
|
+
path(cb) {
|
|
2431
|
+
return {
|
|
2432
|
+
exec() {
|
|
2433
|
+
pathQueue.push({ selector, cb });
|
|
2434
|
+
},
|
|
2435
|
+
};
|
|
2436
|
+
},
|
|
2437
|
+
};
|
|
2438
|
+
},
|
|
2439
|
+
}));
|
|
2440
|
+
|
|
2441
|
+
const dispatchInvoke = (proxy, method, res) => {
|
|
2442
|
+
const fail = vi.fn();
|
|
2443
|
+
proxy.invoke({ method, fail }).exec();
|
|
2444
|
+
const req = invokeQueue.shift();
|
|
2445
|
+
req.options.fail(
|
|
2446
|
+
res === undefined
|
|
2447
|
+
? { code: 2, data: `no node found for selector '${req.selector}'` }
|
|
2448
|
+
: res,
|
|
2449
|
+
);
|
|
2450
|
+
return fail.mock.calls[0][0];
|
|
2451
|
+
};
|
|
2452
|
+
|
|
2453
|
+
try {
|
|
2454
|
+
globalThis.__DEV__ = false;
|
|
2455
|
+
|
|
2456
|
+
const boxRef = createRef();
|
|
2457
|
+
function App() {
|
|
2458
|
+
return (
|
|
2459
|
+
<view>
|
|
2460
|
+
<view ref={boxRef} />
|
|
2461
|
+
</view>
|
|
2462
|
+
);
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
__root.__jsx = <App />;
|
|
2466
|
+
renderPage();
|
|
2467
|
+
globalEnvManager.switchToBackground();
|
|
2468
|
+
render(<App />, __root);
|
|
2469
|
+
lynx.getApp().OnLifecycleEvent(...globalThis.__OnLifecycleEvent.mock.calls[0]);
|
|
2470
|
+
globalThis.__OnLifecycleEvent.mockClear();
|
|
2471
|
+
|
|
2472
|
+
const activeBoxNode = boxRef.current;
|
|
2473
|
+
|
|
2474
|
+
expect(dispatchInvoke(activeBoxNode, 'boundingClientRect').data).toMatch(
|
|
2475
|
+
/^no node found for selector '\[react-ref--?\d+-0\]' \[ReactLynx ref: invoke\(boundingClientRect\), __snapshot_[^\]]+\]$/,
|
|
2476
|
+
);
|
|
2477
|
+
const methodNotFound = { code: 3, data: 'method not found' };
|
|
2478
|
+
expect(dispatchInvoke(activeBoxNode, 'boundingClientRect', methodNotFound)).toBe(methodNotFound);
|
|
2479
|
+
expect(dispatchInvoke(activeBoxNode, 'boundingClientRect', null)).toBeNull();
|
|
2480
|
+
|
|
2481
|
+
// Omitted fail in production passes options through untouched; fields & path callbacks pass through untouched
|
|
2482
|
+
const rawOptions = { method: 'boundingClientRect' };
|
|
2483
|
+
activeBoxNode.invoke(rawOptions).exec();
|
|
2484
|
+
expect(invokeQueue.shift().options).toBe(rawOptions);
|
|
2485
|
+
|
|
2486
|
+
const fieldsCb = vi.fn();
|
|
2487
|
+
activeBoxNode.fields({ id: true }, fieldsCb).exec();
|
|
2488
|
+
expect(fieldsQueue.shift().cb).toBe(fieldsCb);
|
|
2489
|
+
|
|
2490
|
+
const pathCb = vi.fn();
|
|
2491
|
+
activeBoxNode.path(pathCb).exec();
|
|
2492
|
+
expect(pathQueue.shift().cb).toBe(pathCb);
|
|
2493
|
+
|
|
2494
|
+
globalThis.__DEV__ = true;
|
|
2495
|
+
expect(dispatchInvoke(activeBoxNode, 'focus').data).toContain('ReactLynx ref exec() call stack');
|
|
2496
|
+
|
|
2497
|
+
activeBoxNode.invoke({ method: 'boundingClientRect' }).exec();
|
|
2498
|
+
const omittedReq = invokeQueue.shift();
|
|
2499
|
+
omittedReq.options.fail({
|
|
2500
|
+
code: 2,
|
|
2501
|
+
data: `no node found for selector '${omittedReq.selector}'`,
|
|
2502
|
+
});
|
|
2503
|
+
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
2504
|
+
expect(warnSpy.mock.calls[0][0]).toMatch(
|
|
2505
|
+
/\[ReactLynx ref: invoke\(boundingClientRect\), __snapshot_[^\]]+\]/,
|
|
2506
|
+
);
|
|
2507
|
+
expect(warnSpy.mock.calls[0][0]).toContain('ReactLynx ref exec() call stack');
|
|
2508
|
+
expect(reportErrorSpy).toHaveBeenCalledTimes(1);
|
|
2509
|
+
expect(reportErrorSpy.mock.calls[0][0].name).toBe('INVOKE_ERROR');
|
|
2510
|
+
globalThis.__DEV__ = false;
|
|
2511
|
+
|
|
2512
|
+
expect(dispatchInvoke(new RefProxy([999999, 1]), 'focus').data).toBe(
|
|
2513
|
+
`no node found for selector '[react-ref-999999-1]' [ReactLynx ref: invoke(focus)]`,
|
|
2514
|
+
);
|
|
2515
|
+
} finally {
|
|
2516
|
+
warnSpy.mockRestore();
|
|
2517
|
+
reportErrorSpy.mockRestore();
|
|
2518
|
+
globalThis.__DEV__ = originalDev;
|
|
2519
|
+
}
|
|
2520
|
+
});
|
|
2521
|
+
});
|
|
@@ -100,6 +100,13 @@ export class EnvManager {
|
|
|
100
100
|
// `renderPage` no longer resets the first-screen state (it is initialized once
|
|
101
101
|
// at module load), so reset it here for test isolation across tests.
|
|
102
102
|
resetFirstScreenSyncState();
|
|
103
|
+
const workletImpl = this.target.lynxWorkletImpl;
|
|
104
|
+
if (workletImpl?._jsFunctionLifecycleManager?.recreate) {
|
|
105
|
+
workletImpl._jsFunctionLifecycleManager = workletImpl._jsFunctionLifecycleManager.recreate();
|
|
106
|
+
}
|
|
107
|
+
workletImpl?._runOnBackgroundDelayImpl?.clearDelayedBackgroundFunctions?.();
|
|
108
|
+
workletImpl?._refImpl?.clearFirstScreenWorkletRefMap?.();
|
|
109
|
+
workletImpl?._eventDelayImpl?.clearDelayedWorklets?.(true);
|
|
103
110
|
getJSModule('GlobalEventEmitter')?.clear();
|
|
104
111
|
this.switchToBackground();
|
|
105
112
|
this.switchToMainThread();
|
|
@@ -211,6 +211,7 @@ afterEach((context) => {
|
|
|
211
211
|
'preact/debug',
|
|
212
212
|
'should remove event listener when throw in cleanup',
|
|
213
213
|
'should not throw if error - instead it will render an empty page',
|
|
214
|
+
'rolls back a creation whose first frame throws',
|
|
214
215
|
];
|
|
215
216
|
if (skippedTasks.some(task => context.task.name.includes(task))) {
|
|
216
217
|
return;
|
|
@@ -3,11 +3,7 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
clearDelayedWorklets,
|
|
8
|
-
delayExecUntilJsReady,
|
|
9
|
-
runDelayedWorklet,
|
|
10
|
-
} from '../../src/worklet-runtime/delayWorkletEvent';
|
|
6
|
+
import { initEventDelay } from '../../src/worklet-runtime/delayWorkletEvent';
|
|
11
7
|
import { updateWorkletRefInitValueChanges } from '../../src/worklet-runtime/workletRef';
|
|
12
8
|
import { initWorklet } from '../../src/worklet-runtime/workletRuntime';
|
|
13
9
|
|
|
@@ -42,11 +38,11 @@ describe('DelayWorkletEvent', () => {
|
|
|
42
38
|
elementRefptr: 'element2',
|
|
43
39
|
},
|
|
44
40
|
};
|
|
45
|
-
delayExecUntilJsReady('1', [event, 1]);
|
|
41
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.delayExecUntilJsReady('1', [event, 1]);
|
|
46
42
|
globalThis.runWorklet({
|
|
47
43
|
_lepusWorkletHash: '1',
|
|
48
44
|
}, [event, 2]);
|
|
49
|
-
delayExecUntilJsReady('1', [event2, 3]);
|
|
45
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.delayExecUntilJsReady('1', [event2, 3]);
|
|
50
46
|
|
|
51
47
|
let worklet = {
|
|
52
48
|
_c: {
|
|
@@ -58,7 +54,7 @@ describe('DelayWorkletEvent', () => {
|
|
|
58
54
|
};
|
|
59
55
|
|
|
60
56
|
updateWorkletRefInitValueChanges([[178, 333]]);
|
|
61
|
-
runDelayedWorklet(worklet, 'element');
|
|
57
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.runDelayedWorklet(worklet, 'element');
|
|
62
58
|
vi.runAllTimers();
|
|
63
59
|
expect(fn).toBeCalledTimes(2);
|
|
64
60
|
expect(fn).toHaveBeenNthCalledWith(1, expect.anything(), 1);
|
|
@@ -74,16 +70,52 @@ describe('DelayWorkletEvent', () => {
|
|
|
74
70
|
elementRefptr: 'element',
|
|
75
71
|
},
|
|
76
72
|
};
|
|
77
|
-
delayExecUntilJsReady('1', [event]);
|
|
73
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.delayExecUntilJsReady('1', [event]);
|
|
78
74
|
|
|
79
|
-
clearDelayedWorklets();
|
|
75
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.clearDelayedWorklets();
|
|
80
76
|
|
|
81
77
|
let worklet = {
|
|
82
78
|
_wkltId: '1',
|
|
83
79
|
};
|
|
84
80
|
|
|
85
|
-
runDelayedWorklet(worklet, 'element');
|
|
81
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.runDelayedWorklet(worklet, 'element');
|
|
86
82
|
vi.runAllTimers();
|
|
87
83
|
expect(fn).not.toBeCalled();
|
|
88
84
|
});
|
|
85
|
+
|
|
86
|
+
it('keeps state isolated per EventDelayImpl instance', () => {
|
|
87
|
+
const fn = vi.fn();
|
|
88
|
+
globalThis.registerWorklet('main-thread', '1', fn);
|
|
89
|
+
const first = initEventDelay();
|
|
90
|
+
const second = initEventDelay();
|
|
91
|
+
const event = { currentTarget: { elementRefptr: 'element' } };
|
|
92
|
+
|
|
93
|
+
first.delayExecUntilJsReady('1', [event, 'first']);
|
|
94
|
+
second.clearDelayedWorklets();
|
|
95
|
+
|
|
96
|
+
first.runDelayedWorklet({ _wkltId: '1' }, 'element');
|
|
97
|
+
vi.runAllTimers();
|
|
98
|
+
expect(fn).toHaveBeenCalledExactlyOnceWith(expect.anything(), 'first');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('replays scheduled events across normal hydration clear, but cancels them on reload/dispose clear', () => {
|
|
102
|
+
const fn = vi.fn();
|
|
103
|
+
globalThis.registerWorklet('main-thread', '1', fn);
|
|
104
|
+
const makeEvent = () => ({ currentTarget: { elementRefptr: 'element' } });
|
|
105
|
+
|
|
106
|
+
// Normal hydration finishes synchronously after scheduling replay: timer must still run.
|
|
107
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.delayExecUntilJsReady('1', [makeEvent(), 'hydrated']);
|
|
108
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.runDelayedWorklet({ _wkltId: '1' }, 'element');
|
|
109
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.clearDelayedWorklets();
|
|
110
|
+
vi.runAllTimers();
|
|
111
|
+
expect(fn).toHaveBeenCalledExactlyOnceWith(expect.anything(), 'hydrated');
|
|
112
|
+
|
|
113
|
+
// Reload/dispose invalidates already-scheduled replays so old callbacks never run.
|
|
114
|
+
fn.mockClear();
|
|
115
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.delayExecUntilJsReady('1', [makeEvent(), 'stale']);
|
|
116
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.runDelayedWorklet({ _wkltId: '1' }, 'element');
|
|
117
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.clearDelayedWorklets(true);
|
|
118
|
+
vi.runAllTimers();
|
|
119
|
+
expect(fn).not.toHaveBeenCalled();
|
|
120
|
+
});
|
|
89
121
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
|
|
6
|
-
import { JsFunctionLifecycleManager } from '../../src/worklet-runtime/
|
|
6
|
+
import { JsFunctionLifecycleManager } from '../../src/worklet-runtime/run-on-background/lifecycle';
|
|
7
7
|
|
|
8
8
|
let events = [];
|
|
9
9
|
beforeEach(() => {
|
|
@@ -21,12 +21,7 @@ describe('jsFunctionLifecycle', () => {
|
|
|
21
21
|
const manager = new JsFunctionLifecycleManager();
|
|
22
22
|
manager.addRef(3, {});
|
|
23
23
|
manager.fire();
|
|
24
|
-
expect(events[
|
|
25
|
-
{
|
|
26
|
-
"data": [],
|
|
27
|
-
"type": "Lynx.Worklet.releaseBackgroundWorkletCtx",
|
|
28
|
-
}
|
|
29
|
-
`);
|
|
24
|
+
expect(events).toEqual([]);
|
|
30
25
|
});
|
|
31
26
|
|
|
32
27
|
it('should add and remove', () => {
|
|
@@ -50,14 +45,8 @@ describe('jsFunctionLifecycle', () => {
|
|
|
50
45
|
manager.addRef(3, {});
|
|
51
46
|
manager.removeRef(3);
|
|
52
47
|
manager.fire();
|
|
53
|
-
expect(events[
|
|
54
|
-
{
|
|
55
|
-
"data": [],
|
|
56
|
-
"type": "Lynx.Worklet.releaseBackgroundWorkletCtx",
|
|
57
|
-
}
|
|
58
|
-
`);
|
|
48
|
+
expect(events).toEqual([]);
|
|
59
49
|
|
|
60
|
-
events = [];
|
|
61
50
|
manager.removeRef(3);
|
|
62
51
|
manager.fire();
|
|
63
52
|
expect(events[0]).toMatchInlineSnapshot(`
|
|
@@ -105,11 +94,30 @@ describe('jsFunctionLifecycle', () => {
|
|
|
105
94
|
const previous = new JsFunctionLifecycleManager();
|
|
106
95
|
previous.addRef(3, {});
|
|
107
96
|
previous.removeRef(3);
|
|
108
|
-
previous.
|
|
109
|
-
const current = new JsFunctionLifecycleManager();
|
|
97
|
+
const current = previous.recreate();
|
|
110
98
|
current.addRef(3, {});
|
|
111
99
|
previous.fire();
|
|
112
100
|
expect(events).toEqual([]);
|
|
113
101
|
expect(current.execIdRefCount.get(3)).toBe(1);
|
|
114
102
|
});
|
|
103
|
+
|
|
104
|
+
it('cancels pending release when addRef re-retains an execId before fire()', async () => {
|
|
105
|
+
const manager = new JsFunctionLifecycleManager();
|
|
106
|
+
manager.addRef(3, {});
|
|
107
|
+
manager.removeRef(3);
|
|
108
|
+
manager.addRef(3, {});
|
|
109
|
+
|
|
110
|
+
await Promise.resolve();
|
|
111
|
+
expect(events).toEqual([]);
|
|
112
|
+
expect(manager.execIdRefCount.get(3)).toBe(1);
|
|
113
|
+
|
|
114
|
+
manager.removeRef(3);
|
|
115
|
+
await Promise.resolve();
|
|
116
|
+
expect(events).toEqual([
|
|
117
|
+
{
|
|
118
|
+
data: [3],
|
|
119
|
+
type: 'Lynx.Worklet.releaseBackgroundWorkletCtx',
|
|
120
|
+
},
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
115
123
|
});
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { WorkletEvents } from '../../src/worklet-runtime/bindings/events.js';
|
|
7
|
+
import { disposeWorkletRuntime, resetWorkletRuntimeForReload } from '../../src/worklet-runtime/bindings/lifecycle.js';
|
|
8
|
+
import { onHydrationFinished } from '../../src/worklet-runtime/bindings/observers.js';
|
|
9
|
+
import {
|
|
10
|
+
getFromWorkletRefMap,
|
|
11
|
+
isHydratedWorkletValue,
|
|
12
|
+
updateWorkletRefInitValueChanges,
|
|
13
|
+
} from '../../src/worklet-runtime/workletRef.js';
|
|
14
|
+
import { initWorklet } from '../../src/worklet-runtime/workletRuntime.js';
|
|
15
|
+
|
|
16
|
+
describe('worklet-runtime lifecycle contract', () => {
|
|
17
|
+
let originalLynx;
|
|
18
|
+
let originalSystemInfo;
|
|
19
|
+
let originalSetTimeout;
|
|
20
|
+
let originalSetInterval;
|
|
21
|
+
let originalClearTimeout;
|
|
22
|
+
let originalClearInterval;
|
|
23
|
+
let originalRequestAnimationFrame;
|
|
24
|
+
let originalCancelAnimationFrame;
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
originalLynx = globalThis.lynx;
|
|
28
|
+
originalSystemInfo = globalThis.SystemInfo;
|
|
29
|
+
originalSetTimeout = globalThis.setTimeout;
|
|
30
|
+
originalSetInterval = globalThis.setInterval;
|
|
31
|
+
originalClearTimeout = globalThis.clearTimeout;
|
|
32
|
+
originalClearInterval = globalThis.clearInterval;
|
|
33
|
+
originalRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
34
|
+
originalCancelAnimationFrame = globalThis.cancelAnimationFrame;
|
|
35
|
+
|
|
36
|
+
globalThis.SystemInfo = { lynxSdkVersion: '2.16' };
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
vi.restoreAllMocks();
|
|
41
|
+
globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.dispose?.();
|
|
42
|
+
delete globalThis.lynxWorkletImpl;
|
|
43
|
+
delete globalThis.registerWorklet;
|
|
44
|
+
delete globalThis.registerWorkletInternal;
|
|
45
|
+
delete globalThis.runWorklet;
|
|
46
|
+
globalThis.lynx = originalLynx;
|
|
47
|
+
globalThis.SystemInfo = originalSystemInfo;
|
|
48
|
+
globalThis.setTimeout = originalSetTimeout;
|
|
49
|
+
globalThis.setInterval = originalSetInterval;
|
|
50
|
+
globalThis.clearTimeout = originalClearTimeout;
|
|
51
|
+
globalThis.clearInterval = originalClearInterval;
|
|
52
|
+
globalThis.requestAnimationFrame = originalRequestAnimationFrame;
|
|
53
|
+
globalThis.cancelAnimationFrame = originalCancelAnimationFrame;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('no-ops cleanly when lynxWorkletImpl is not initialized', () => {
|
|
57
|
+
delete globalThis.lynxWorkletImpl;
|
|
58
|
+
|
|
59
|
+
expect(() => resetWorkletRuntimeForReload()).not.toThrow();
|
|
60
|
+
expect(() => disposeWorkletRuntime()).not.toThrow();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('handles partial runtime mocks safely for reload and dispose', () => {
|
|
64
|
+
globalThis.lynxWorkletImpl = {};
|
|
65
|
+
expect(() => resetWorkletRuntimeForReload()).not.toThrow();
|
|
66
|
+
expect(() => disposeWorkletRuntime()).not.toThrow();
|
|
67
|
+
expect('_jsFunctionLifecycleManager' in globalThis.lynxWorkletImpl).toBe(false);
|
|
68
|
+
|
|
69
|
+
globalThis.lynxWorkletImpl = {
|
|
70
|
+
_jsFunctionLifecycleManager: { addRef: vi.fn() },
|
|
71
|
+
};
|
|
72
|
+
expect(() => resetWorkletRuntimeForReload()).not.toThrow();
|
|
73
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager).toBeDefined();
|
|
74
|
+
|
|
75
|
+
expect(() => disposeWorkletRuntime()).not.toThrow();
|
|
76
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager).toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('resets aborted first-screen state on reload while preserving VM registrations and positive refs', () => {
|
|
80
|
+
const dispatchEvent = vi.fn();
|
|
81
|
+
globalThis.lynx = {
|
|
82
|
+
...originalLynx,
|
|
83
|
+
getJSContext: () => ({ dispatchEvent }),
|
|
84
|
+
};
|
|
85
|
+
initWorklet();
|
|
86
|
+
|
|
87
|
+
const lazyWorklet = vi.fn(() => 'from-lazy');
|
|
88
|
+
globalThis.registerWorklet('main-thread', 'lazy-worklet', lazyWorklet);
|
|
89
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
90
|
+
'@test/lazy-object',
|
|
91
|
+
value => ({ value }),
|
|
92
|
+
);
|
|
93
|
+
updateWorkletRefInitValueChanges([[1, 'live-positive', '@test/lazy-object']]);
|
|
94
|
+
const positiveObj = getFromWorkletRefMap({ _wvid: 1 });
|
|
95
|
+
const firstScreenRef = getFromWorkletRefMap({ _wvid: -1, _initValue: 'aborted-first-screen' });
|
|
96
|
+
const delayedTask = vi.fn();
|
|
97
|
+
const firstScreenHandle = { _isFirstScreen: true };
|
|
98
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground(firstScreenHandle, delayedTask);
|
|
99
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.delayExecUntilJsReady('legacy-event', [{ currentTarget: {} }]);
|
|
100
|
+
|
|
101
|
+
const previousManager = globalThis.lynxWorkletImpl._jsFunctionLifecycleManager;
|
|
102
|
+
previousManager.addRef(5, {});
|
|
103
|
+
|
|
104
|
+
resetWorkletRuntimeForReload();
|
|
105
|
+
|
|
106
|
+
const nextManager = globalThis.lynxWorkletImpl._jsFunctionLifecycleManager;
|
|
107
|
+
expect(nextManager).toBeDefined();
|
|
108
|
+
expect(nextManager).not.toBe(previousManager);
|
|
109
|
+
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.epoch).toBe(1);
|
|
110
|
+
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(0);
|
|
111
|
+
expect(firstScreenHandle).not.toHaveProperty('_delayIndices');
|
|
112
|
+
expect(globalThis.lynxWorkletImpl._refImpl._firstScreenWorkletRefMap).toEqual({});
|
|
113
|
+
expect(globalThis.lynxWorkletImpl._eventDelayImpl._delayedWorkletParamsMap.size).toBe(0);
|
|
114
|
+
|
|
115
|
+
// VM-scoped registrations and positive-ID refs survive reload.
|
|
116
|
+
expect(globalThis.runWorklet({ _wkltId: 'lazy-worklet' }, [])).toBe('from-lazy');
|
|
117
|
+
expect(getFromWorkletRefMap({ _wvid: 1 })).toBe(positiveObj);
|
|
118
|
+
expect(isHydratedWorkletValue(positiveObj)).toBe(true);
|
|
119
|
+
// Re-allocating negative ID -1 produces a fresh ref instead of returning the aborted one.
|
|
120
|
+
const nextFirstScreenRef = getFromWorkletRefMap({ _wvid: -1, _initValue: 'reloaded-first-screen' });
|
|
121
|
+
expect(nextFirstScreenRef).not.toBe(firstScreenRef);
|
|
122
|
+
expect(nextFirstScreenRef.current).toBe('reloaded-first-screen');
|
|
123
|
+
|
|
124
|
+
// Retired manager finalizers cannot release reused execId 5 on the new page.
|
|
125
|
+
nextManager.addRef(5, {});
|
|
126
|
+
previousManager.removeRef(5);
|
|
127
|
+
previousManager.fire();
|
|
128
|
+
expect(dispatchEvent).not.toHaveBeenCalled();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('disposes lifecycle manager without allocating a replacement on terminal teardown', () => {
|
|
132
|
+
const dispatchEvent = vi.fn();
|
|
133
|
+
globalThis.lynx = {
|
|
134
|
+
...originalLynx,
|
|
135
|
+
getJSContext: () => ({ dispatchEvent }),
|
|
136
|
+
};
|
|
137
|
+
initWorklet();
|
|
138
|
+
|
|
139
|
+
const previousManager = globalThis.lynxWorkletImpl._jsFunctionLifecycleManager;
|
|
140
|
+
previousManager.addRef(7, {});
|
|
141
|
+
getFromWorkletRefMap({ _wvid: -1, _initValue: 'first-screen' });
|
|
142
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground({ _isFirstScreen: true }, vi.fn());
|
|
143
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.delayExecUntilJsReady('legacy-event', [{}]);
|
|
144
|
+
|
|
145
|
+
disposeWorkletRuntime();
|
|
146
|
+
|
|
147
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager).toBeUndefined();
|
|
148
|
+
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(0);
|
|
149
|
+
expect(globalThis.lynxWorkletImpl._refImpl._firstScreenWorkletRefMap).toEqual({});
|
|
150
|
+
expect(globalThis.lynxWorkletImpl._eventDelayImpl._delayedWorkletParamsMap.size).toBe(0);
|
|
151
|
+
|
|
152
|
+
previousManager.removeRef(7);
|
|
153
|
+
previousManager.fire();
|
|
154
|
+
expect(dispatchEvent).not.toHaveBeenCalled();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('invalidates scheduled legacy worklet replays on reload and dispose without breaking hydration replay', () => {
|
|
158
|
+
vi.useFakeTimers();
|
|
159
|
+
try {
|
|
160
|
+
initWorklet();
|
|
161
|
+
const handler = vi.fn();
|
|
162
|
+
globalThis.registerWorklet('main-thread', 'legacy-tap', handler);
|
|
163
|
+
const element = {};
|
|
164
|
+
const worklet = { _wkltId: 'legacy-tap' };
|
|
165
|
+
const makeEvent = () => ({ currentTarget: { elementRefptr: element } });
|
|
166
|
+
|
|
167
|
+
// Normal hydration finish clears unmatched entries but preserves scheduled replay.
|
|
168
|
+
globalThis.runWorklet({ _lepusWorkletHash: 'legacy-tap' }, [makeEvent(), 'hydrated']);
|
|
169
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.runDelayedWorklet(worklet, element);
|
|
170
|
+
onHydrationFinished();
|
|
171
|
+
vi.runAllTimers();
|
|
172
|
+
expect(handler).toHaveBeenCalledExactlyOnceWith(expect.anything(), 'hydrated');
|
|
173
|
+
|
|
174
|
+
// Reload invalidates already-scheduled replay.
|
|
175
|
+
handler.mockClear();
|
|
176
|
+
globalThis.runWorklet({ _lepusWorkletHash: 'legacy-tap' }, [makeEvent(), 'stale-reload']);
|
|
177
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.runDelayedWorklet(worklet, element);
|
|
178
|
+
expect(vi.getTimerCount()).toBe(1);
|
|
179
|
+
resetWorkletRuntimeForReload();
|
|
180
|
+
vi.runAllTimers();
|
|
181
|
+
expect(handler).not.toHaveBeenCalled();
|
|
182
|
+
|
|
183
|
+
// Terminal dispose invalidates already-scheduled replay.
|
|
184
|
+
globalThis.runWorklet({ _lepusWorkletHash: 'legacy-tap' }, [makeEvent(), 'stale-dispose']);
|
|
185
|
+
globalThis.lynxWorkletImpl._eventDelayImpl.runDelayedWorklet(worklet, element);
|
|
186
|
+
expect(vi.getTimerCount()).toBe(1);
|
|
187
|
+
disposeWorkletRuntime();
|
|
188
|
+
vi.runAllTimers();
|
|
189
|
+
expect(handler).not.toHaveBeenCalled();
|
|
190
|
+
} finally {
|
|
191
|
+
vi.useRealTimers();
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('preserves lazy registrations, allows factory refresh, and avoids duplicate listeners across entry re-evaluations', async () => {
|
|
196
|
+
const listeners = new Map();
|
|
197
|
+
const jsContext = {
|
|
198
|
+
addEventListener: vi.fn((type, fn) => {
|
|
199
|
+
if (!listeners.has(type)) listeners.set(type, []);
|
|
200
|
+
listeners.get(type).push(fn);
|
|
201
|
+
}),
|
|
202
|
+
dispatchEvent: vi.fn(),
|
|
203
|
+
};
|
|
204
|
+
globalThis.lynx = {
|
|
205
|
+
...originalLynx,
|
|
206
|
+
getJSContext: () => jsContext,
|
|
207
|
+
setTimeout: originalSetTimeout,
|
|
208
|
+
setInterval: originalSetInterval,
|
|
209
|
+
clearTimeout: originalClearTimeout,
|
|
210
|
+
clearInterval: originalClearInterval,
|
|
211
|
+
requestAnimationFrame: originalRequestAnimationFrame,
|
|
212
|
+
cancelAnimationFrame: originalCancelAnimationFrame,
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
vi.resetModules();
|
|
216
|
+
const initialEntry = await import('@lynx-js/react/worklet-runtime/init');
|
|
217
|
+
expect(listeners.get(WorkletEvents.runWorkletCtx)).toHaveLength(1);
|
|
218
|
+
expect(listeners.get(WorkletEvents.releaseWorkletRef)).toHaveLength(1);
|
|
219
|
+
|
|
220
|
+
// Simulate a lazy bundle registering a worklet and MainThreadObject type once.
|
|
221
|
+
const lazyWorklet = vi.fn(() => 'lazy-ok');
|
|
222
|
+
initialEntry.registerWorklet('main-thread', 'lazy-bundle-fn', lazyWorklet);
|
|
223
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
224
|
+
'@test/lazy-type',
|
|
225
|
+
value => ({ source: 'lazy', value }),
|
|
226
|
+
);
|
|
227
|
+
// Simulate a main-entry module registering a MainThreadObject type bound to module-local state.
|
|
228
|
+
const makeEntryFactory = (epoch) => value => ({ epoch, value });
|
|
229
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
230
|
+
'@test/entry-type',
|
|
231
|
+
makeEntryFactory(1),
|
|
232
|
+
);
|
|
233
|
+
updateWorkletRefInitValueChanges([[1, 'before', '@test/entry-type']]);
|
|
234
|
+
const realizedBefore = getFromWorkletRefMap({ _wvid: 1 });
|
|
235
|
+
expect(realizedBefore).toEqual({ epoch: 1, value: 'before' });
|
|
236
|
+
|
|
237
|
+
// Perform two consecutive reload + entry re-evaluation cycles.
|
|
238
|
+
for (const nextEpoch of [2, 3]) {
|
|
239
|
+
const retiredManager = globalThis.lynxWorkletImpl._jsFunctionLifecycleManager;
|
|
240
|
+
retiredManager.addRef(1, {});
|
|
241
|
+
resetWorkletRuntimeForReload();
|
|
242
|
+
|
|
243
|
+
vi.resetModules();
|
|
244
|
+
const reEvaluatedEntry = await import('@lynx-js/react/worklet-runtime/init');
|
|
245
|
+
expect(reEvaluatedEntry.registerWorklet).toBe(globalThis.registerWorkletInternal);
|
|
246
|
+
|
|
247
|
+
// Re-evaluated main-entry module refreshes its factory with identical source identity.
|
|
248
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
249
|
+
'@test/entry-type',
|
|
250
|
+
makeEntryFactory(nextEpoch),
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
// Listeners must not be duplicated on repeated entry re-evaluations, and delivery still works.
|
|
254
|
+
expect(listeners.get(WorkletEvents.runWorkletCtx)).toHaveLength(1);
|
|
255
|
+
expect(listeners.get(WorkletEvents.releaseWorkletRef)).toHaveLength(1);
|
|
256
|
+
lazyWorklet.mockClear();
|
|
257
|
+
listeners.get(WorkletEvents.runWorkletCtx)[0]({
|
|
258
|
+
data: JSON.stringify({
|
|
259
|
+
worklet: { _wkltId: 'lazy-bundle-fn' },
|
|
260
|
+
params: [],
|
|
261
|
+
resolveId: nextEpoch,
|
|
262
|
+
}),
|
|
263
|
+
});
|
|
264
|
+
expect(lazyWorklet).toHaveBeenCalledOnce();
|
|
265
|
+
|
|
266
|
+
// Lifecycle manager was recreated cleanly and retired finalizers are inert.
|
|
267
|
+
jsContext.dispatchEvent.mockClear();
|
|
268
|
+
const activeManager = globalThis.lynxWorkletImpl._jsFunctionLifecycleManager;
|
|
269
|
+
expect(activeManager).toBeDefined();
|
|
270
|
+
expect(activeManager).not.toBe(retiredManager);
|
|
271
|
+
retiredManager.removeRef(1);
|
|
272
|
+
retiredManager.fire();
|
|
273
|
+
expect(jsContext.dispatchEvent).not.toHaveBeenCalled();
|
|
274
|
+
|
|
275
|
+
// Cached lazy bundle registrations & existing object brands still work.
|
|
276
|
+
expect(globalThis.runWorklet({ _wkltId: 'lazy-bundle-fn' }, [])).toBe('lazy-ok');
|
|
277
|
+
updateWorkletRefInitValueChanges([
|
|
278
|
+
[nextEpoch * 10, `lazy-${nextEpoch}`, '@test/lazy-type'],
|
|
279
|
+
[nextEpoch * 10 + 1, `entry-${nextEpoch}`, '@test/entry-type'],
|
|
280
|
+
]);
|
|
281
|
+
expect(getFromWorkletRefMap({ _wvid: nextEpoch * 10 })).toEqual({
|
|
282
|
+
source: 'lazy',
|
|
283
|
+
value: `lazy-${nextEpoch}`,
|
|
284
|
+
});
|
|
285
|
+
expect(getFromWorkletRefMap({ _wvid: nextEpoch * 10 + 1 })).toEqual({
|
|
286
|
+
epoch: nextEpoch,
|
|
287
|
+
value: `entry-${nextEpoch}`,
|
|
288
|
+
});
|
|
289
|
+
// Existing realized object keeps its brand across entry re-evaluations.
|
|
290
|
+
expect(() => updateWorkletRefInitValueChanges([[1, 'mismatch', 'main-thread']])).toThrow(
|
|
291
|
+
'Worklet value kind mismatch',
|
|
292
|
+
);
|
|
293
|
+
updateWorkletRefInitValueChanges([[1, 'same', '@test/entry-type']]);
|
|
294
|
+
expect(getFromWorkletRefMap({ _wvid: 1 })).toBe(realizedBefore);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
@@ -10,18 +10,24 @@ describe('profile', () => {
|
|
|
10
10
|
const originalProfileEnd = console.profileEnd;
|
|
11
11
|
|
|
12
12
|
afterEach(() => {
|
|
13
|
+
vi.unstubAllGlobals();
|
|
13
14
|
console.profile = originalProfile;
|
|
14
15
|
console.profileEnd = originalProfileEnd;
|
|
15
16
|
});
|
|
16
17
|
|
|
17
|
-
it('
|
|
18
|
-
|
|
18
|
+
it.each([true, false])('respects __PROFILE__=%s independently of __DEV__', (enabled) => {
|
|
19
|
+
vi.stubGlobal('__PROFILE__', enabled);
|
|
20
|
+
vi.stubGlobal('__DEV__', !enabled);
|
|
19
21
|
console.profile = vi.fn();
|
|
20
22
|
console.profileEnd = vi.fn();
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
expect(profile('x', () => 123)).toBe(123);
|
|
25
|
+
if (enabled) {
|
|
26
|
+
expect(console.profile).toHaveBeenCalledWith('x');
|
|
27
|
+
expect(console.profileEnd).toHaveBeenCalledTimes(1);
|
|
28
|
+
} else {
|
|
29
|
+
expect(console.profile).not.toHaveBeenCalled();
|
|
30
|
+
expect(console.profileEnd).not.toHaveBeenCalled();
|
|
31
|
+
}
|
|
26
32
|
});
|
|
27
33
|
});
|