@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
|
@@ -0,0 +1,415 @@
|
|
|
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
|
+
// Background side of the transfer protocol. The first `registerComponent` fixes
|
|
5
|
+
// the thread, so the main thread side lives in `transfer.mts.test.jsx`.
|
|
6
|
+
import { options, render } from 'preact';
|
|
7
|
+
import { useEffect, useLayoutEffect } from 'preact/hooks';
|
|
8
|
+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
resetBackgroundFunctionRuntime,
|
|
12
|
+
runBackgroundFunction,
|
|
13
|
+
} from '../../../src/core/background-function/run-on-background';
|
|
14
|
+
import { runOnMainThread, root, useState } from '../../../src/index';
|
|
15
|
+
import { resetFunctionCallReturnListener } from '../../../src/core/thread-function-call/return-value';
|
|
16
|
+
import { TransferRegistry } from '../../../src/internal';
|
|
17
|
+
import { __root } from '../../../src/root';
|
|
18
|
+
import {
|
|
19
|
+
BackgroundSnapshotInstance,
|
|
20
|
+
backgroundSnapshotInstanceManager,
|
|
21
|
+
} from '../../../src/snapshot/snapshot/backgroundSnapshot';
|
|
22
|
+
import { WorkletEvents } from '../../../src/worklet-runtime/bindings/events';
|
|
23
|
+
import { globalEnvManager } from '../utils/envManager';
|
|
24
|
+
import { waitSchedule } from '../utils/nativeMethod';
|
|
25
|
+
|
|
26
|
+
function makeBus() {
|
|
27
|
+
const listeners = {};
|
|
28
|
+
const sent = [];
|
|
29
|
+
return {
|
|
30
|
+
sent,
|
|
31
|
+
of: type => sent.filter(event => event.type === type).map(event => event.data),
|
|
32
|
+
count: () => Object.values(listeners).flat().length,
|
|
33
|
+
addEventListener(type, listener) {
|
|
34
|
+
(listeners[type] ??= []).push(listener);
|
|
35
|
+
},
|
|
36
|
+
removeEventListener(type, listener) {
|
|
37
|
+
listeners[type] = listeners[type]?.filter(l => l !== listener);
|
|
38
|
+
},
|
|
39
|
+
dispatchEvent(event) {
|
|
40
|
+
sent.push({ type: event.type, data: JSON.parse(event.data) });
|
|
41
|
+
},
|
|
42
|
+
fire(type, data) {
|
|
43
|
+
listeners[type]?.forEach(listener => listener({ data: JSON.stringify(data) }));
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const link = makeBus();
|
|
49
|
+
const native = makeBus();
|
|
50
|
+
const reportError = vi.fn();
|
|
51
|
+
|
|
52
|
+
let setCount;
|
|
53
|
+
let taps = 0;
|
|
54
|
+
function Bubble(props) {
|
|
55
|
+
const [count, setCountState] = useState(0);
|
|
56
|
+
setCount = setCountState;
|
|
57
|
+
return (
|
|
58
|
+
<view bindtap={() => taps++}>
|
|
59
|
+
<text>{`${props.text}:${count}`}</text>
|
|
60
|
+
</view>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function Page() {
|
|
64
|
+
return <view />;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Serializes the newest transfer root the way the main thread first frame would. */
|
|
68
|
+
function firstFrame(rootId) {
|
|
69
|
+
const roots = [...backgroundSnapshotInstanceManager.values.values()].filter(si => si.type === 'root');
|
|
70
|
+
const toJSON = si => ({
|
|
71
|
+
id: si.__id,
|
|
72
|
+
type: si.type,
|
|
73
|
+
values: si.__values,
|
|
74
|
+
children: si.childNodes.length ? si.childNodes.map(toJSON) : undefined,
|
|
75
|
+
});
|
|
76
|
+
const transferRoot = rootId === undefined
|
|
77
|
+
? roots.reduce((a, b) => (a.__id > b.__id ? a : b))
|
|
78
|
+
: roots.find(root => root.__id === rootId);
|
|
79
|
+
return JSON.stringify(toJSON(transferRoot));
|
|
80
|
+
}
|
|
81
|
+
function commits(transferId) {
|
|
82
|
+
return link.of('__TransferCommit').filter(packet => packet.transferId === transferId);
|
|
83
|
+
}
|
|
84
|
+
function ack(transferId, seq, status = 'applied', version = 0) {
|
|
85
|
+
link.fire('__TransferCommitResult', { transferId, version, seq, status });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
beforeAll(() => {
|
|
89
|
+
globalEnvManager.resetEnv();
|
|
90
|
+
globalEnvManager.switchToBackground();
|
|
91
|
+
vi.stubGlobal('lynx', {
|
|
92
|
+
...lynx,
|
|
93
|
+
getCoreContext: () => link,
|
|
94
|
+
getJSContext: () => link,
|
|
95
|
+
getNative: () => native,
|
|
96
|
+
reportError,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
afterAll(() => {
|
|
101
|
+
vi.unstubAllGlobals();
|
|
102
|
+
globalEnvManager.resetEnv();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('transfer (background thread)', () => {
|
|
106
|
+
it('keeps the page root empty once a component is registered', () => {
|
|
107
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
108
|
+
root.render(<Page />);
|
|
109
|
+
expect(__root.childNodes).toHaveLength(1);
|
|
110
|
+
|
|
111
|
+
TransferRegistry.registerComponent('Bubble', () => Bubble);
|
|
112
|
+
expect(__root.__jsx).toBeUndefined();
|
|
113
|
+
expect(__root.childNodes).toHaveLength(0);
|
|
114
|
+
|
|
115
|
+
root.render(<Page />);
|
|
116
|
+
expect(__root.__jsx).toBeUndefined();
|
|
117
|
+
expect(__root.childNodes).toHaveLength(0);
|
|
118
|
+
// Both the earlier and the later `root.render` are reported in development.
|
|
119
|
+
expect(warn).toHaveBeenCalledTimes(2);
|
|
120
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('`root.render` is ignored on transfer pages'));
|
|
121
|
+
warn.mockRestore();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('hydrates a created component and sends one commit at a time', async () => {
|
|
125
|
+
link.fire('__CreateTransfer', { transferId: '1', componentName: 'Bubble', initialProps: { text: 'a' } });
|
|
126
|
+
expect(commits('1')).toHaveLength(0);
|
|
127
|
+
|
|
128
|
+
link.fire('__TransferFirstFrame', { transferId: '1', snapshot: firstFrame() });
|
|
129
|
+
expect(commits('1')).toMatchObject([{ seq: 1, kind: 'hydrate', patchOptions: { isHydration: true } }]);
|
|
130
|
+
|
|
131
|
+
setCount(1);
|
|
132
|
+
await waitSchedule();
|
|
133
|
+
// Queued until the hydration commit is applied.
|
|
134
|
+
expect(commits('1')).toHaveLength(1);
|
|
135
|
+
ack('1', 1);
|
|
136
|
+
expect(commits('1')[1]).toMatchObject({ seq: 2, kind: 'update' });
|
|
137
|
+
expect(JSON.stringify(commits('1')[1].patchList)).toContain('a:1');
|
|
138
|
+
|
|
139
|
+
// Like a template reload, a reload remounts the component and waits for a new first frame.
|
|
140
|
+
link.fire('__ReloadTransfer', { transferId: '1', props: { text: 'b' } });
|
|
141
|
+
ack('1', 2);
|
|
142
|
+
expect(commits('1')).toHaveLength(2);
|
|
143
|
+
const frame = firstFrame();
|
|
144
|
+
expect(frame).toContain('b:0');
|
|
145
|
+
link.fire('__TransferFirstFrame', { transferId: '1', snapshot: frame });
|
|
146
|
+
expect(commits('1')[2]).toMatchObject({ version: 1, seq: 1, kind: 'hydrate' });
|
|
147
|
+
ack('1', 1, 'applied', 1);
|
|
148
|
+
|
|
149
|
+
// Events dispatch directly to the hydrated handlers.
|
|
150
|
+
const view = [...backgroundSnapshotInstanceManager.values.values()].find(si =>
|
|
151
|
+
typeof si.__values?.[0] === 'function'
|
|
152
|
+
);
|
|
153
|
+
lynx.getApp().publishEvent(`${view.__id}:0:`, { type: 'tap' });
|
|
154
|
+
expect(taps).toBe(1);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('drops commits before hydration and disposes in both directions', async () => {
|
|
158
|
+
link.fire('__CreateTransfer', { transferId: '2', componentName: 'Bubble', initialProps: { text: 'c' } });
|
|
159
|
+
setCount(5);
|
|
160
|
+
await waitSchedule();
|
|
161
|
+
expect(commits('2')).toHaveLength(0);
|
|
162
|
+
|
|
163
|
+
link.fire('__TransferFirstFrame', { transferId: '2', snapshot: firstFrame() });
|
|
164
|
+
expect(commits('2')).toMatchObject([{ seq: 1, kind: 'hydrate' }]);
|
|
165
|
+
ack('2', 1, 'failed');
|
|
166
|
+
expect(link.of('__TransferDisposed')).toEqual([{ transferId: '2' }]);
|
|
167
|
+
|
|
168
|
+
// Disposed by the main thread: torn down without echoing back.
|
|
169
|
+
link.fire('__DestroyTransfer', { transferId: '1' });
|
|
170
|
+
expect(link.of('__TransferDisposed')).toHaveLength(1);
|
|
171
|
+
link.fire('__ReloadTransfer', { transferId: '1', props: { text: 'd' } });
|
|
172
|
+
expect(commits('1')).toHaveLength(3);
|
|
173
|
+
|
|
174
|
+
link.fire('__CreateTransfer', { transferId: '3', componentName: 'Missing', initialProps: {} });
|
|
175
|
+
expect(reportError).toHaveBeenCalledWith(new Error('Unknown transfer component: Missing'));
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('ignores early, duplicate and stale messages', async () => {
|
|
179
|
+
// An empty first frame hydrates by inserting the rendered children.
|
|
180
|
+
const emptyFrame = id => JSON.stringify({ id, type: 'root' });
|
|
181
|
+
link.fire('__TransferFirstFrame', { transferId: '4', snapshot: emptyFrame(-100) });
|
|
182
|
+
expect(commits('4')).toHaveLength(0);
|
|
183
|
+
link.fire('__CreateTransfer', { transferId: '4', componentName: 'Bubble', initialProps: { text: 'e' } });
|
|
184
|
+
expect(commits('4')).toMatchObject([{ seq: 1, kind: 'hydrate' }]);
|
|
185
|
+
|
|
186
|
+
link.fire('__TransferFirstFrame', { transferId: '4', snapshot: emptyFrame(-100) });
|
|
187
|
+
link.fire('__CreateTransfer', { transferId: '4', componentName: 'Bubble', initialProps: {} });
|
|
188
|
+
ack('4', 7);
|
|
189
|
+
ack('404', 1);
|
|
190
|
+
setCount(1);
|
|
191
|
+
await waitSchedule();
|
|
192
|
+
expect(commits('4')).toHaveLength(1);
|
|
193
|
+
|
|
194
|
+
// A reload releases the in-flight and queued commits; their results no longer match.
|
|
195
|
+
link.fire('__ReloadTransfer', { transferId: '4', props: { text: 'f' } });
|
|
196
|
+
ack('4', 1);
|
|
197
|
+
link.fire('__TransferFirstFrame', { transferId: '4', snapshot: emptyFrame(-102) });
|
|
198
|
+
expect(commits('4')).toMatchObject([{ version: 0, seq: 1 }, { version: 1, seq: 1, kind: 'hydrate' }]);
|
|
199
|
+
setCount(2);
|
|
200
|
+
await waitSchedule();
|
|
201
|
+
expect(commits('4')).toHaveLength(2);
|
|
202
|
+
|
|
203
|
+
// Disposal releases the in-flight and queued commits; later messages are ignored.
|
|
204
|
+
link.fire('__DestroyTransfer', { transferId: '4' });
|
|
205
|
+
link.fire('__DestroyTransfer', { transferId: '4' });
|
|
206
|
+
ack('4', 1);
|
|
207
|
+
link.fire('__TransferFirstFrame', { transferId: '4', snapshot: emptyFrame(-101) });
|
|
208
|
+
link.fire('__CreateTransfer', { transferId: '4', componentName: 'Bubble', initialProps: {} });
|
|
209
|
+
expect(commits('4')).toHaveLength(2);
|
|
210
|
+
|
|
211
|
+
render(<Page />, new BackgroundSnapshotInstance('root'));
|
|
212
|
+
expect(reportError).toHaveBeenCalledWith(new Error('Commit rendered outside a transfer instance'));
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('keeps pre-hydration render and effect worklets with their instance across reuse', async () => {
|
|
216
|
+
const sdkVersion = SystemInfo.lynxSdkVersion;
|
|
217
|
+
SystemInfo.lynxSdkVersion = '4.3';
|
|
218
|
+
const completed = [];
|
|
219
|
+
const callback = vi.fn();
|
|
220
|
+
const staleCleanup = vi.fn();
|
|
221
|
+
const initialize = { _wkltId: 'initialize', _jsFn: { callback: { _fn: callback, _jsFnId: 1 } } };
|
|
222
|
+
const call = (label) => void runOnMainThread(initialize)(label).then(() => completed.push(label));
|
|
223
|
+
const runCallback = execId =>
|
|
224
|
+
runBackgroundFunction({ obj: { _execId: execId, _jsFnId: 1 }, params: [], resolveId: 0 });
|
|
225
|
+
let updateA;
|
|
226
|
+
let updateB;
|
|
227
|
+
let flushEffects;
|
|
228
|
+
const requestAnimationFrame = options.requestAnimationFrame;
|
|
229
|
+
function Card({ name }) {
|
|
230
|
+
const [count, setCount] = useState(0);
|
|
231
|
+
if (name === 'a') updateA = setCount;
|
|
232
|
+
if (name === 'b') updateB = setCount;
|
|
233
|
+
call(`${name}:render:${count}`);
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
if (name === 'a' && count === 1) {
|
|
236
|
+
call('a:effect');
|
|
237
|
+
return () => call('a:effect-cleanup');
|
|
238
|
+
}
|
|
239
|
+
if (name === 'a' && count === 2) {
|
|
240
|
+
return () => {
|
|
241
|
+
staleCleanup();
|
|
242
|
+
call('a:stale-effect-cleanup');
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}, [count]);
|
|
246
|
+
useLayoutEffect(() => {
|
|
247
|
+
call(`${name}:layout`);
|
|
248
|
+
if (name !== 'a') return;
|
|
249
|
+
setCount(1);
|
|
250
|
+
return () => call('a:cleanup');
|
|
251
|
+
}, []);
|
|
252
|
+
return <text>{`${name}:${count}`}</text>;
|
|
253
|
+
}
|
|
254
|
+
const calls = (id, index) => commits(id)[index].patchList.delayedRunOnMainThreadData;
|
|
255
|
+
const worklets = (id, index) => calls(id, index).map(({ params }) => params[0]);
|
|
256
|
+
const returnFrom = (id, index) => {
|
|
257
|
+
for (const { resolveId } of calls(id, index)) {
|
|
258
|
+
link.fire(WorkletEvents.FunctionCallRet, { resolveId });
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
TransferRegistry.registerComponent('Worklets', () => Card);
|
|
262
|
+
try {
|
|
263
|
+
options.requestAnimationFrame = flush => {
|
|
264
|
+
flushEffects = flush;
|
|
265
|
+
};
|
|
266
|
+
const listenersBeforeFirstFrame = link.count();
|
|
267
|
+
link.fire('__CreateTransfer', { transferId: 'work-a', componentName: 'Worklets', initialProps: { name: 'a' } });
|
|
268
|
+
await waitSchedule();
|
|
269
|
+
const frameA = firstFrame();
|
|
270
|
+
link.fire('__CreateTransfer', { transferId: 'work-b', componentName: 'Worklets', initialProps: { name: 'b' } });
|
|
271
|
+
await waitSchedule();
|
|
272
|
+
expect(commits('work-a')).toHaveLength(0);
|
|
273
|
+
expect(commits('work-b')).toHaveLength(0);
|
|
274
|
+
expect(link.count()).toBe(listenersBeforeFirstFrame);
|
|
275
|
+
link.fire('__TransferFirstFrame', { transferId: 'work-b', snapshot: firstFrame() });
|
|
276
|
+
expect(worklets('work-b', 0)).toEqual(['b:render:0', 'b:layout']);
|
|
277
|
+
ack('work-b', 1);
|
|
278
|
+
updateB(1);
|
|
279
|
+
await waitSchedule();
|
|
280
|
+
expect(worklets('work-b', 1)).toEqual(['b:render:1']);
|
|
281
|
+
returnFrom('work-b', 1);
|
|
282
|
+
ack('work-b', 2);
|
|
283
|
+
flushEffects();
|
|
284
|
+
expect(link.of(WorkletEvents.runWorkletCtx)).not.toContainEqual(
|
|
285
|
+
expect.objectContaining({ params: ['a:effect'] }),
|
|
286
|
+
);
|
|
287
|
+
updateA(2);
|
|
288
|
+
await waitSchedule();
|
|
289
|
+
flushEffects();
|
|
290
|
+
expect(link.of(WorkletEvents.runWorkletCtx)).not.toContainEqual(
|
|
291
|
+
expect.objectContaining({ params: ['a:effect-cleanup'] }),
|
|
292
|
+
);
|
|
293
|
+
link.fire('__TransferFirstFrame', { transferId: 'work-a', snapshot: frameA });
|
|
294
|
+
expect(worklets('work-a', 0)).toEqual([
|
|
295
|
+
'a:render:0',
|
|
296
|
+
'a:layout',
|
|
297
|
+
'a:render:1',
|
|
298
|
+
'a:effect',
|
|
299
|
+
'a:render:2',
|
|
300
|
+
'a:effect-cleanup',
|
|
301
|
+
]);
|
|
302
|
+
expect(new Set(calls('work-a', 0).map(({ worklet }) => worklet._execId)).size).toBe(6);
|
|
303
|
+
const lastExecId = calls('work-a', 0).at(-1).worklet._execId;
|
|
304
|
+
ack('work-a', 1);
|
|
305
|
+
link.fire('__ReloadTransfer', { transferId: 'work-a', props: { name: 'reused' } });
|
|
306
|
+
runCallback(calls('work-a', 0)[0].worklet._execId);
|
|
307
|
+
expect(callback).toHaveBeenCalledOnce();
|
|
308
|
+
await waitSchedule();
|
|
309
|
+
flushEffects();
|
|
310
|
+
expect(staleCleanup).toHaveBeenCalledOnce();
|
|
311
|
+
expect(link.of(WorkletEvents.runWorkletCtx)).not.toContainEqual(
|
|
312
|
+
expect.objectContaining({ params: ['a:stale-effect-cleanup'] }),
|
|
313
|
+
);
|
|
314
|
+
const replacementFrame = firstFrame(JSON.parse(frameA).id);
|
|
315
|
+
expect(replacementFrame).toContain('reused:0');
|
|
316
|
+
link.fire('__TransferFirstFrame', { transferId: 'work-a', snapshot: replacementFrame });
|
|
317
|
+
expect(commits('work-a')[1]).toMatchObject({ version: 1, seq: 1, kind: 'hydrate' });
|
|
318
|
+
expect(worklets('work-a', 1)).toEqual(['reused:render:0', 'reused:layout']);
|
|
319
|
+
expect(calls('work-a', 1)[0].worklet._execId).toBe(lastExecId + 1);
|
|
320
|
+
returnFrom('work-a', 0);
|
|
321
|
+
returnFrom('work-b', 0);
|
|
322
|
+
await waitSchedule();
|
|
323
|
+
expect(completed).toEqual(['b:render:1', 'b:render:0', 'b:layout']);
|
|
324
|
+
link.fire(WorkletEvents.FunctionCallRet, { resolveId: calls('work-a', 1)[0].resolveId });
|
|
325
|
+
ack('work-a', 1, 'failed', 1);
|
|
326
|
+
returnFrom('work-a', 1);
|
|
327
|
+
await waitSchedule();
|
|
328
|
+
expect(completed).toEqual(['b:render:1', 'b:render:0', 'b:layout', 'reused:render:0']);
|
|
329
|
+
|
|
330
|
+
const lastSentExecId = calls('work-a', 1).at(-1).worklet._execId;
|
|
331
|
+
link.fire('__CreateTransfer', { transferId: 'work-c', componentName: 'Worklets', initialProps: { name: 'c' } });
|
|
332
|
+
link.fire('__DestroyTransfer', { transferId: 'work-c' });
|
|
333
|
+
expect(commits('work-c')).toHaveLength(0);
|
|
334
|
+
|
|
335
|
+
call('outside-render');
|
|
336
|
+
expect(link.of(WorkletEvents.runWorkletCtx).at(-1)).toMatchObject({
|
|
337
|
+
params: ['outside-render'],
|
|
338
|
+
worklet: { _execId: lastSentExecId + 1 },
|
|
339
|
+
});
|
|
340
|
+
} finally {
|
|
341
|
+
link.fire('__DestroyTransfer', { transferId: 'work-a' });
|
|
342
|
+
link.fire('__DestroyTransfer', { transferId: 'work-b' });
|
|
343
|
+
flushEffects?.();
|
|
344
|
+
options.requestAnimationFrame = requestAnimationFrame;
|
|
345
|
+
resetFunctionCallReturnListener();
|
|
346
|
+
resetBackgroundFunctionRuntime();
|
|
347
|
+
SystemInfo.lynxSdkVersion = sdkVersion;
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('updates props in place and keeps state, while a reload resets it', async () => {
|
|
352
|
+
let mounts = 0;
|
|
353
|
+
let setN;
|
|
354
|
+
function Streamed(props) {
|
|
355
|
+
const [mounted, setMounted] = useState(false);
|
|
356
|
+
const [n, setNState] = useState(0);
|
|
357
|
+
setN = setNState;
|
|
358
|
+
useEffect(() => {
|
|
359
|
+
mounts++;
|
|
360
|
+
setMounted(true);
|
|
361
|
+
}, []);
|
|
362
|
+
return mounted ? <text>{`${props.text}:${n}`}</text> : null;
|
|
363
|
+
}
|
|
364
|
+
TransferRegistry.registerComponent('Streamed', () => Streamed);
|
|
365
|
+
link.fire('__CreateTransfer', { transferId: 's', componentName: 'Streamed', initialProps: { text: 'a' } });
|
|
366
|
+
link.fire('__TransferFirstFrame', { transferId: 's', snapshot: firstFrame() });
|
|
367
|
+
ack('s', 1);
|
|
368
|
+
await waitSchedule();
|
|
369
|
+
expect(mounts).toBe(1);
|
|
370
|
+
expect(JSON.stringify(commits('s')[1].patchList)).toContain('a:0');
|
|
371
|
+
ack('s', 2);
|
|
372
|
+
|
|
373
|
+
// An update re-renders the mounted component with new props and keeps its state.
|
|
374
|
+
link.fire('__UpdateTransfer', { transferId: 's', props: { text: 'b' } });
|
|
375
|
+
expect(commits('s')[2]).toMatchObject({ version: 0, seq: 3, kind: 'update' });
|
|
376
|
+
expect(JSON.stringify(commits('s')[2].patchList)).toContain('b:0');
|
|
377
|
+
ack('s', 3);
|
|
378
|
+
// Later commits still belong to the instance.
|
|
379
|
+
const errors = reportError.mock.calls.length;
|
|
380
|
+
setN(1);
|
|
381
|
+
await waitSchedule();
|
|
382
|
+
expect(reportError.mock.calls.length).toBe(errors);
|
|
383
|
+
expect(JSON.stringify(commits('s')[3].patchList)).toContain('b:1');
|
|
384
|
+
ack('s', 4);
|
|
385
|
+
expect(mounts).toBe(1);
|
|
386
|
+
|
|
387
|
+
// A reload remounts it and resets its state; updates before the new first frame are kept.
|
|
388
|
+
link.fire('__ReloadTransfer', { transferId: 's', props: { text: 'c' } });
|
|
389
|
+
link.fire('__UpdateTransfer', { transferId: 's', props: { text: 'd' } });
|
|
390
|
+
expect(commits('s')).toHaveLength(4);
|
|
391
|
+
link.fire('__TransferFirstFrame', { transferId: 's', snapshot: firstFrame() });
|
|
392
|
+
expect(commits('s')[4]).toMatchObject({ version: 1, seq: 1, kind: 'hydrate' });
|
|
393
|
+
ack('s', 1, 'applied', 1);
|
|
394
|
+
await waitSchedule();
|
|
395
|
+
expect(mounts).toBe(2);
|
|
396
|
+
setN(5);
|
|
397
|
+
await waitSchedule();
|
|
398
|
+
expect(JSON.stringify(commits('s').at(-1).patchList)).toContain('d:5');
|
|
399
|
+
link.fire('__DestroyTransfer', { transferId: 's' });
|
|
400
|
+
|
|
401
|
+
// Updates for destroyed or unknown instances render nothing.
|
|
402
|
+
const sent = commits('s').length;
|
|
403
|
+
link.fire('__UpdateTransfer', { transferId: 's', props: { text: 'e' } });
|
|
404
|
+
link.fire('__UpdateTransfer', { transferId: 'missing', props: {} });
|
|
405
|
+
await waitSchedule();
|
|
406
|
+
expect(commits('s')).toHaveLength(sent);
|
|
407
|
+
expect(mounts).toBe(2);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it('removes its listeners when the lifetime is destroyed', () => {
|
|
411
|
+
native.fire('__DestroyLifetime', {});
|
|
412
|
+
expect(link.count()).toBe(0);
|
|
413
|
+
expect(native.count()).toBe(0);
|
|
414
|
+
});
|
|
415
|
+
});
|
|
@@ -4917,6 +4917,115 @@ describe('destroy list after element transfer', () => {
|
|
|
4917
4917
|
});
|
|
4918
4918
|
});
|
|
4919
4919
|
|
|
4920
|
+
describe('nested list element ownership after outer row reuse', () => {
|
|
4921
|
+
function createRows() {
|
|
4922
|
+
const listSnapshot = __SNAPSHOT__(<list>{HOLE}</list>);
|
|
4923
|
+
const rowSnapshot = __SNAPSHOT__(<list-item item-key={HOLE} reuse-identifier='row'>{HOLE}</list-item>);
|
|
4924
|
+
const cellSnapshot = __SNAPSHOT__(
|
|
4925
|
+
<list-item item-key={HOLE}>
|
|
4926
|
+
<raw-text text={HOLE} />
|
|
4927
|
+
</list-item>,
|
|
4928
|
+
);
|
|
4929
|
+
const outer = new SnapshotInstance(listSnapshot);
|
|
4930
|
+
const rows = [0, 1].map((index) => {
|
|
4931
|
+
const row = new SnapshotInstance(rowSnapshot);
|
|
4932
|
+
row.setAttribute(0, { 'item-key': `row-${index}` });
|
|
4933
|
+
const inner = new SnapshotInstance(listSnapshot);
|
|
4934
|
+
const cell = new SnapshotInstance(cellSnapshot);
|
|
4935
|
+
cell.setAttribute(0, { 'item-key': `cell-${index}` });
|
|
4936
|
+
cell.setAttribute(1, `cell-${index}`);
|
|
4937
|
+
inner.insertBefore(cell);
|
|
4938
|
+
row.insertBefore(inner);
|
|
4939
|
+
outer.insertBefore(row);
|
|
4940
|
+
return { inner, cell };
|
|
4941
|
+
});
|
|
4942
|
+
outer.ensureElements();
|
|
4943
|
+
return { outerList: outer.__element_root, row0: rows[0], row1: rows[1] };
|
|
4944
|
+
}
|
|
4945
|
+
|
|
4946
|
+
const show = (list, index) => elementTree.triggerComponentAtIndex(list, index);
|
|
4947
|
+
const recycle = (list, sign) => elementTree.triggerEnqueueComponent(list, sign);
|
|
4948
|
+
const text = (element) => __GetAttributeByName(element.children[0], 'text');
|
|
4949
|
+
|
|
4950
|
+
it('redirects the old recycle-pool entry to the copy that keeps the old element', () => {
|
|
4951
|
+
const { outerList, row0, row1 } = createRows();
|
|
4952
|
+
const cell0Instance = row0.cell;
|
|
4953
|
+
const oldRowSign = show(outerList, 0);
|
|
4954
|
+
const oldInnerList = row0.inner.__element_root;
|
|
4955
|
+
const oldCellSign = show(oldInnerList, 0);
|
|
4956
|
+
const oldCellElement = cell0Instance.__element_root;
|
|
4957
|
+
expect(text(oldCellElement)).toBe('cell-0');
|
|
4958
|
+
|
|
4959
|
+
recycle(outerList, oldRowSign);
|
|
4960
|
+
expect(show(outerList, 1)).toBe(oldRowSign);
|
|
4961
|
+
expect(row1.inner.__element_root).toBe(oldInnerList);
|
|
4962
|
+
recycle(oldInnerList, oldCellSign);
|
|
4963
|
+
const oldCellPool = gRecycleMap[__GetElementUniqueID(oldInnerList)].get(cell0Instance.type);
|
|
4964
|
+
expect(oldCellPool.get(oldCellSign)).toBe(cell0Instance);
|
|
4965
|
+
expect(cell0Instance.__element_root).toBe(oldCellElement);
|
|
4966
|
+
|
|
4967
|
+
expect(show(outerList, 0)).not.toBe(oldRowSign);
|
|
4968
|
+
expect(row0.inner.__element_root).not.toBe(oldInnerList);
|
|
4969
|
+
const newCellSign = show(row0.inner.__element_root, 0);
|
|
4970
|
+
const newCellElement = cell0Instance.__element_root;
|
|
4971
|
+
expect(newCellSign).toBe(__GetElementUniqueID(newCellElement));
|
|
4972
|
+
expect(newCellSign).not.toBe(oldCellSign);
|
|
4973
|
+
expect(newCellElement).not.toBe(oldCellElement);
|
|
4974
|
+
expect(text(newCellElement)).toBe('cell-0');
|
|
4975
|
+
|
|
4976
|
+
const recycledCellInstance = oldCellPool.get(oldCellSign);
|
|
4977
|
+
expect(
|
|
4978
|
+
recycledCellInstance === cell0Instance,
|
|
4979
|
+
'the old recycle-pool entry must stop pointing at the logical cell that now owns a new element',
|
|
4980
|
+
).toBe(false);
|
|
4981
|
+
expect(recycledCellInstance.__element_root).toBe(oldCellElement);
|
|
4982
|
+
expect(cell0Instance.__element_root).toBe(newCellElement);
|
|
4983
|
+
|
|
4984
|
+
expect(show(oldInnerList, 0)).toBe(oldCellSign);
|
|
4985
|
+
expect(row1.cell.__element_root).toBe(oldCellElement);
|
|
4986
|
+
expect(text(oldCellElement)).toBe('cell-1');
|
|
4987
|
+
expect(cell0Instance.__element_root).toBe(newCellElement);
|
|
4988
|
+
expect(text(newCellElement)).toBe('cell-0');
|
|
4989
|
+
});
|
|
4990
|
+
|
|
4991
|
+
it('uses the redirected sign-map entry when the old cell is enqueued after element transfer', () => {
|
|
4992
|
+
const { outerList, row0, row1 } = createRows();
|
|
4993
|
+
const cell0Instance = row0.cell;
|
|
4994
|
+
const oldRowSign = show(outerList, 0);
|
|
4995
|
+
const oldInnerList = row0.inner.__element_root;
|
|
4996
|
+
const oldCellSign = show(oldInnerList, 0);
|
|
4997
|
+
const oldCellElement = cell0Instance.__element_root;
|
|
4998
|
+
const oldSignMap = gSignMap[__GetElementUniqueID(oldInnerList)];
|
|
4999
|
+
expect(oldSignMap.get(oldCellSign)).toBe(cell0Instance);
|
|
5000
|
+
|
|
5001
|
+
recycle(outerList, oldRowSign);
|
|
5002
|
+
expect(show(outerList, 1)).toBe(oldRowSign);
|
|
5003
|
+
expect(row1.inner.__element_root).toBe(oldInnerList);
|
|
5004
|
+
expect(show(outerList, 0)).not.toBe(oldRowSign);
|
|
5005
|
+
const newCellSign = show(row0.inner.__element_root, 0);
|
|
5006
|
+
const newCellElement = cell0Instance.__element_root;
|
|
5007
|
+
expect(newCellSign).toBe(__GetElementUniqueID(newCellElement));
|
|
5008
|
+
expect(newCellSign).not.toBe(oldCellSign);
|
|
5009
|
+
|
|
5010
|
+
const transferredCellInstance = oldSignMap.get(oldCellSign);
|
|
5011
|
+
expect(
|
|
5012
|
+
transferredCellInstance === cell0Instance,
|
|
5013
|
+
'a delayed enqueue must find the copy holding the old element in the old sign map',
|
|
5014
|
+
).toBe(false);
|
|
5015
|
+
expect(transferredCellInstance.__element_root).toBe(oldCellElement);
|
|
5016
|
+
expect(cell0Instance.__element_root).toBe(newCellElement);
|
|
5017
|
+
|
|
5018
|
+
recycle(oldInnerList, oldCellSign);
|
|
5019
|
+
const recycledInstances = [...gRecycleMap[__GetElementUniqueID(oldInnerList)].values()]
|
|
5020
|
+
.flatMap(pool => [...pool.values()]);
|
|
5021
|
+
expect(recycledInstances).toContain(transferredCellInstance);
|
|
5022
|
+
expect(recycledInstances).not.toContain(cell0Instance);
|
|
5023
|
+
expect(transferredCellInstance.__element_root).toBe(oldCellElement);
|
|
5024
|
+
expect(cell0Instance.__element_root).toBe(newCellElement);
|
|
5025
|
+
expect(text(newCellElement)).toBe('cell-0');
|
|
5026
|
+
});
|
|
5027
|
+
});
|
|
5028
|
+
|
|
4920
5029
|
describe('list worklet ref lifecycle', () => {
|
|
4921
5030
|
it('unrefs worklet refs when a list child is logically removed', () => {
|
|
4922
5031
|
const listSnapshot = __SNAPSHOT__(<list>{HOLE}</list>);
|
|
@@ -10,6 +10,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vite
|
|
|
10
10
|
import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit';
|
|
11
11
|
import { injectUpdateMainThread } from '../../../src/snapshot/lifecycle/patch/updateMainThread';
|
|
12
12
|
import { installComponentCompat } from '../../../src/core/component';
|
|
13
|
+
import { __ComponentIsPolyfill } from '../../../src/internal';
|
|
13
14
|
import { __root } from '../../../src/root';
|
|
14
15
|
import {
|
|
15
16
|
setupPage,
|
|
@@ -39,10 +40,57 @@ afterEach(() => {
|
|
|
39
40
|
vi.runAllTimers();
|
|
40
41
|
vi.useRealTimers();
|
|
41
42
|
vi.restoreAllMocks();
|
|
43
|
+
vi.unstubAllGlobals();
|
|
42
44
|
elementTree.clear();
|
|
43
45
|
});
|
|
44
46
|
|
|
45
47
|
describe('suspense', () => {
|
|
48
|
+
it('renders an empty component and reports an invalid legacy component URL', () => {
|
|
49
|
+
const reportError = vi.spyOn(lynx, 'reportError').mockImplementation(() => {});
|
|
50
|
+
__root.__jsx = createElement(__ComponentIsPolyfill, { is: null });
|
|
51
|
+
renderPage();
|
|
52
|
+
expect(reportError).toHaveBeenCalledWith(expect.objectContaining({
|
|
53
|
+
message: expect.stringContaining('You must provide a string'),
|
|
54
|
+
}));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('loads a legacy component asynchronously and remounts it when its URL changes', async () => {
|
|
58
|
+
globalEnvManager.switchToBackground();
|
|
59
|
+
const query = vi.fn();
|
|
60
|
+
const mount = vi.fn();
|
|
61
|
+
const renderChild = vi.fn();
|
|
62
|
+
function Child({ label }) {
|
|
63
|
+
useState(() => mount(label));
|
|
64
|
+
renderChild(label);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const app = lynx.getApp();
|
|
68
|
+
vi.stubGlobal('lynx', {
|
|
69
|
+
...lynx,
|
|
70
|
+
QueryComponent: query,
|
|
71
|
+
getApp: () => ({ ...app, getDynamicComponentExports: () => ({ default: Child }) }),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
render(createElement(__ComponentIsPolyfill, { is: 'one', label: 'first' }), __root);
|
|
75
|
+
expect(query).toHaveBeenCalledWith('one', expect.any(Function));
|
|
76
|
+
expect(renderChild).not.toHaveBeenCalled();
|
|
77
|
+
query.mock.calls[0][1]({ code: 0, detail: { schema: 'one' } });
|
|
78
|
+
await vi.runAllTimersAsync();
|
|
79
|
+
expect(renderChild).toHaveBeenLastCalledWith('first');
|
|
80
|
+
|
|
81
|
+
render(createElement(__ComponentIsPolyfill, { is: 'one', label: 'updated' }), __root);
|
|
82
|
+
expect(query).toHaveBeenCalledTimes(1);
|
|
83
|
+
expect(mount.mock.calls).toEqual([['first']]);
|
|
84
|
+
expect(renderChild).toHaveBeenLastCalledWith('updated');
|
|
85
|
+
|
|
86
|
+
render(createElement(__ComponentIsPolyfill, { is: 'two', label: 'second' }), __root);
|
|
87
|
+
expect(query).toHaveBeenLastCalledWith('two', expect.any(Function));
|
|
88
|
+
query.mock.calls[1][1]({ code: 0, detail: { schema: 'two' } });
|
|
89
|
+
await vi.runAllTimersAsync();
|
|
90
|
+
expect(mount.mock.calls).toEqual([['first'], ['second']]);
|
|
91
|
+
expect(renderChild).toHaveBeenLastCalledWith('second');
|
|
92
|
+
});
|
|
93
|
+
|
|
46
94
|
/**
|
|
47
95
|
* Tests the basic functionality of the `Suspense` component.
|
|
48
96
|
*
|
|
@@ -13,7 +13,7 @@ describe('lynxQueueMicrotask', () => {
|
|
|
13
13
|
const mockFn = vi.fn();
|
|
14
14
|
vi.stubGlobal('lynx', { queueMicrotask: vi.fn(fn => Promise.resolve().then(fn)) });
|
|
15
15
|
|
|
16
|
-
const { lynxQueueMicrotask } = await import('../../src/
|
|
16
|
+
const { lynxQueueMicrotask } = await import('../../src/shared/microtask');
|
|
17
17
|
lynxQueueMicrotask(mockFn);
|
|
18
18
|
|
|
19
19
|
expect(lynx.queueMicrotask).toHaveBeenCalled();
|
|
@@ -27,7 +27,7 @@ describe('lynxQueueMicrotask', () => {
|
|
|
27
27
|
const mockFn = vi.fn();
|
|
28
28
|
vi.stubGlobal('lynx', {});
|
|
29
29
|
|
|
30
|
-
const { lynxQueueMicrotask } = await import('../../src/
|
|
30
|
+
const { lynxQueueMicrotask } = await import('../../src/shared/microtask');
|
|
31
31
|
lynxQueueMicrotask(mockFn);
|
|
32
32
|
|
|
33
33
|
expect(mockFn).not.toHaveBeenCalled();
|