@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
|
@@ -3,8 +3,11 @@
|
|
|
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 { clearDelayedRunOnBackgroundFunctions } from '../../src/worklet-runtime/bindings/observers';
|
|
6
7
|
import { initWorklet } from '../../src/worklet-runtime/workletRuntime';
|
|
7
8
|
|
|
9
|
+
const originalLynx = globalThis.lynx;
|
|
10
|
+
|
|
8
11
|
beforeEach(() => {
|
|
9
12
|
globalThis.SystemInfo = {
|
|
10
13
|
lynxSdkVersion: '2.16',
|
|
@@ -13,6 +16,9 @@ beforeEach(() => {
|
|
|
13
16
|
});
|
|
14
17
|
|
|
15
18
|
afterEach(() => {
|
|
19
|
+
vi.restoreAllMocks();
|
|
20
|
+
globalThis.lynx = originalLynx;
|
|
21
|
+
globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.dispose();
|
|
16
22
|
delete globalThis.lynxWorkletImpl;
|
|
17
23
|
});
|
|
18
24
|
|
|
@@ -130,6 +136,8 @@ describe('runOnBackground', () => {
|
|
|
130
136
|
{
|
|
131
137
|
"jsFnHandle": {
|
|
132
138
|
"_execId": 8,
|
|
139
|
+
"_hydratedEpoch": 0,
|
|
140
|
+
"_isFirstScreen": false,
|
|
133
141
|
"_jsFnId": 1,
|
|
134
142
|
},
|
|
135
143
|
"task": [MockFunction spy],
|
|
@@ -185,4 +193,184 @@ describe('runOnBackground', () => {
|
|
|
185
193
|
});
|
|
186
194
|
expect(task).not.toHaveBeenCalled();
|
|
187
195
|
});
|
|
196
|
+
|
|
197
|
+
it('transitions queued first-screen handles for subsequent calls and retains ownership until collected', async () => {
|
|
198
|
+
const releasedExecIds = [];
|
|
199
|
+
globalThis.lynx = {
|
|
200
|
+
getJSContext: () => ({
|
|
201
|
+
dispatchEvent: (event) => {
|
|
202
|
+
if (event.type === 'Lynx.Worklet.releaseBackgroundWorkletCtx') {
|
|
203
|
+
releasedExecIds.push(...event.data);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
}),
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const registered = [];
|
|
210
|
+
vi.spyOn(globalThis, 'FinalizationRegistry').mockImplementation(function(cleanup) {
|
|
211
|
+
return {
|
|
212
|
+
register(target, heldValue) {
|
|
213
|
+
registered.push({ target, heldValue, cleanup, finalized: false });
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
initWorklet();
|
|
218
|
+
|
|
219
|
+
function finalizeExcept(liveTargets) {
|
|
220
|
+
const live = new Set(liveTargets);
|
|
221
|
+
for (const entry of registered) {
|
|
222
|
+
if (!entry.finalized && !live.has(entry.target)) {
|
|
223
|
+
entry.finalized = true;
|
|
224
|
+
entry.cleanup(entry.heldValue);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Mode A (queued before hydration) & Mode B (first called after hydration) on the same retained closure
|
|
230
|
+
let tick;
|
|
231
|
+
globalThis.registerWorklet('main-thread', 'timer-ref', function(element) {
|
|
232
|
+
if (!element || this._c.started.current) return;
|
|
233
|
+
this._c.started.current = true;
|
|
234
|
+
const { onQueued, onPostHydrate } = this._jsFn;
|
|
235
|
+
tick = (mode, value) => {
|
|
236
|
+
const handle = mode === 'queued' ? onQueued : onPostHydrate;
|
|
237
|
+
if (handle._isFirstScreen) {
|
|
238
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground(
|
|
239
|
+
handle,
|
|
240
|
+
(fnId, execId) => dispatched.push({ mode, value, fnId, execId }),
|
|
241
|
+
);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
dispatched.push({ mode, value, fnId: handle._jsFnId, execId: handle._execId });
|
|
245
|
+
};
|
|
246
|
+
tick('queued', 1);
|
|
247
|
+
tick('queued', 2);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const dispatched = [];
|
|
251
|
+
let activeSlot = {
|
|
252
|
+
_wkltId: 'timer-ref',
|
|
253
|
+
_c: { started: { _wvid: -1, _initValue: false, _type: 'main-thread' } },
|
|
254
|
+
_jsFn: {
|
|
255
|
+
onQueued: { _isFirstScreen: true },
|
|
256
|
+
onPostHydrate: { _isFirstScreen: true },
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
const retainedQueuedHandle = activeSlot._jsFn.onQueued;
|
|
260
|
+
const retainedPostHandle = activeSlot._jsFn.onPostHydrate;
|
|
261
|
+
globalThis.runWorklet(activeSlot, [{ elementRefptr: {} }]);
|
|
262
|
+
expect(dispatched).toEqual([]);
|
|
263
|
+
expect(retainedQueuedHandle._delayIndices).toEqual([0, 1]);
|
|
264
|
+
|
|
265
|
+
// Hydrate with execId = 10
|
|
266
|
+
globalThis.lynxWorkletImpl._refImpl.updateWorkletRefInitValueChanges([[1, false, 'main-thread']]);
|
|
267
|
+
const hydratedSlot = {
|
|
268
|
+
_wkltId: 'timer-ref',
|
|
269
|
+
_execId: 10,
|
|
270
|
+
_c: { started: { _wvid: 1, _type: 'main-thread' } },
|
|
271
|
+
_jsFn: { onQueued: { _jsFnId: 1 }, onPostHydrate: { _jsFnId: 2 } },
|
|
272
|
+
};
|
|
273
|
+
globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.addRef(10, hydratedSlot);
|
|
274
|
+
globalThis.lynxWorkletImpl._hydrateCtx(hydratedSlot, activeSlot);
|
|
275
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.runDelayedBackgroundFunctions();
|
|
276
|
+
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(0);
|
|
277
|
+
activeSlot = hydratedSlot;
|
|
278
|
+
globalThis.runWorklet(activeSlot, [{ elementRefptr: {} }]);
|
|
279
|
+
|
|
280
|
+
expect(dispatched).toEqual([
|
|
281
|
+
{ mode: 'queued', value: 1, fnId: 1, execId: 10 },
|
|
282
|
+
{ mode: 'queued', value: 2, fnId: 1, execId: 10 },
|
|
283
|
+
]);
|
|
284
|
+
expect(retainedQueuedHandle).not.toHaveProperty('_delayIndices');
|
|
285
|
+
expect(retainedQueuedHandle).toMatchObject({ _isFirstScreen: false, _hydratedEpoch: 0, _jsFnId: 1, _execId: 10 });
|
|
286
|
+
expect(retainedPostHandle).toMatchObject({ _isFirstScreen: false, _hydratedEpoch: 0, _jsFnId: 2, _execId: 10 });
|
|
287
|
+
|
|
288
|
+
// Rerender replaces slot with execId = 11, then MTS GC collects hydratedSlot while `tick` stays alive
|
|
289
|
+
const rerenderSlot = {
|
|
290
|
+
_wkltId: 'timer-ref',
|
|
291
|
+
_execId: 11,
|
|
292
|
+
_c: { started: { _wvid: 1, _type: 'main-thread' } },
|
|
293
|
+
_jsFn: { onQueued: { _jsFnId: 3 }, onPostHydrate: { _jsFnId: 4 } },
|
|
294
|
+
};
|
|
295
|
+
globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.addRef(11, rerenderSlot);
|
|
296
|
+
activeSlot = rerenderSlot;
|
|
297
|
+
globalThis.runWorklet(activeSlot, [{ elementRefptr: {} }]);
|
|
298
|
+
|
|
299
|
+
finalizeExcept([activeSlot, retainedQueuedHandle, retainedPostHandle]);
|
|
300
|
+
await Promise.resolve();
|
|
301
|
+
expect(releasedExecIds).toEqual([]);
|
|
302
|
+
|
|
303
|
+
// Post-hydration calls on both handles dispatch directly without re-entering delay queue
|
|
304
|
+
tick('queued', 3);
|
|
305
|
+
tick('post', 4);
|
|
306
|
+
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(0);
|
|
307
|
+
expect(dispatched.slice(2)).toEqual([
|
|
308
|
+
{ mode: 'queued', value: 3, fnId: 1, execId: 10 },
|
|
309
|
+
{ mode: 'post', value: 4, fnId: 2, execId: 10 },
|
|
310
|
+
]);
|
|
311
|
+
|
|
312
|
+
// Cancel timer and unmount slot: both execId 10 and 11 must now be released
|
|
313
|
+
tick = undefined;
|
|
314
|
+
activeSlot = undefined;
|
|
315
|
+
finalizeExcept([]);
|
|
316
|
+
await Promise.resolve();
|
|
317
|
+
expect(releasedExecIds.sort((a, b) => a - b)).toEqual([10, 11]);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('binds a shared first-screen handle once per epoch, rebinds on reload, and ignores orphaned delays', () => {
|
|
321
|
+
const sharedHandle = { _isFirstScreen: true };
|
|
322
|
+
const nonFirstScreenHandle = { _jsFnId: 9, _execId: 4 };
|
|
323
|
+
const sharedFirstScreen = {
|
|
324
|
+
_wkltId: 'shared',
|
|
325
|
+
_jsFn: { cb: sharedHandle, existing: nonFirstScreenHandle },
|
|
326
|
+
};
|
|
327
|
+
const slotA = { _wkltId: 'shared', _execId: 21, _jsFn: { cb: { _jsFnId: 5 }, existing: { _jsFnId: 9 } } };
|
|
328
|
+
const slotB = { _wkltId: 'shared', _execId: 22, _jsFn: { cb: { _jsFnId: 5 } } };
|
|
329
|
+
|
|
330
|
+
globalThis.lynxWorkletImpl._hydrateCtx(slotA, sharedFirstScreen);
|
|
331
|
+
globalThis.lynxWorkletImpl._hydrateCtx(slotB, sharedFirstScreen);
|
|
332
|
+
|
|
333
|
+
expect(sharedHandle).toMatchObject({ _isFirstScreen: false, _hydratedEpoch: 0, _jsFnId: 5, _execId: 21 });
|
|
334
|
+
expect(nonFirstScreenHandle).toEqual({ _jsFnId: 9, _execId: 4 });
|
|
335
|
+
expect(slotB._jsFn.cb._execId).toBe(22);
|
|
336
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(21)).toBe(1);
|
|
337
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(22)).toBeUndefined();
|
|
338
|
+
|
|
339
|
+
// Once hydration finishes, an orphaned unhydrated first-screen handle does not grow the delay queue
|
|
340
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.runDelayedBackgroundFunctions();
|
|
341
|
+
const orphan = { _isFirstScreen: true };
|
|
342
|
+
const orphanTask = vi.fn();
|
|
343
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground(orphan, orphanTask);
|
|
344
|
+
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(0);
|
|
345
|
+
expect(orphan).not.toHaveProperty('_delayIndices');
|
|
346
|
+
|
|
347
|
+
// Reload recreates the lifecycle manager, clears stale _delayIndices, advances epoch, and rebinds handles
|
|
348
|
+
const epoch0Manager = globalThis.lynxWorkletImpl._jsFunctionLifecycleManager;
|
|
349
|
+
clearDelayedRunOnBackgroundFunctions();
|
|
350
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager).not.toBe(epoch0Manager);
|
|
351
|
+
const staleTask = vi.fn();
|
|
352
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground(sharedHandle, staleTask);
|
|
353
|
+
expect(sharedHandle._delayIndices).toEqual([0]);
|
|
354
|
+
|
|
355
|
+
// Aborting pre-hydration via another reload must clear sharedHandle._delayIndices so it cannot overwrite index 0
|
|
356
|
+
clearDelayedRunOnBackgroundFunctions();
|
|
357
|
+
expect(sharedHandle).not.toHaveProperty('_delayIndices');
|
|
358
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground(orphan, orphanTask);
|
|
359
|
+
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(1);
|
|
360
|
+
|
|
361
|
+
const epoch2Slot = {
|
|
362
|
+
_wkltId: 'shared',
|
|
363
|
+
_execId: 30,
|
|
364
|
+
_jsFn: { cb: { _jsFnId: 6 }, orphan: { _jsFnId: 7 } },
|
|
365
|
+
};
|
|
366
|
+
globalThis.lynxWorkletImpl._hydrateCtx(epoch2Slot, {
|
|
367
|
+
_wkltId: 'shared',
|
|
368
|
+
_jsFn: { cb: sharedHandle, orphan },
|
|
369
|
+
});
|
|
370
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.runDelayedBackgroundFunctions();
|
|
371
|
+
expect(staleTask).not.toHaveBeenCalled();
|
|
372
|
+
expect(orphanTask).toHaveBeenCalledExactlyOnceWith(7, 30);
|
|
373
|
+
expect(sharedHandle).toMatchObject({ _isFirstScreen: false, _hydratedEpoch: 2, _jsFnId: 6, _execId: 30 });
|
|
374
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(30)).toBe(2);
|
|
375
|
+
});
|
|
188
376
|
});
|
|
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
getFromWorkletRefMap,
|
|
8
|
+
initWorkletRef,
|
|
8
9
|
isHydratedWorkletValue,
|
|
9
10
|
removeValueFromWorkletRefMap,
|
|
10
11
|
updateWorkletRefInitValueChanges,
|
|
@@ -685,4 +686,19 @@ describe('WorkletRef', () => {
|
|
|
685
686
|
'background-thread-init-2',
|
|
686
687
|
);
|
|
687
688
|
});
|
|
689
|
+
|
|
690
|
+
it('keeps ref maps isolated per RefImpl instance', () => {
|
|
691
|
+
const first = initWorkletRef();
|
|
692
|
+
const second = initWorkletRef();
|
|
693
|
+
|
|
694
|
+
first.updateWorkletRefInitValueChanges([[1, 'first-value']]);
|
|
695
|
+
second.updateWorkletRefInitValueChanges([[1, 'second-value']]);
|
|
696
|
+
first.updateWorkletRef({ _wvid: -1 }, 'first-element');
|
|
697
|
+
second.clearFirstScreenWorkletRefMap();
|
|
698
|
+
|
|
699
|
+
expect(first._workletRefMap[1].current).toBe('first-value');
|
|
700
|
+
expect(second._workletRefMap[1].current).toBe('second-value');
|
|
701
|
+
expect(first._firstScreenWorkletRefMap[-1].current.element).toBe('first-element');
|
|
702
|
+
expect(second._firstScreenWorkletRefMap).toEqual({});
|
|
703
|
+
});
|
|
688
704
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
|
|
6
6
|
import { Element } from '../../src/worklet-runtime/api/element';
|
|
7
7
|
import { initApiEnv } from '../../src/worklet-runtime/api/lynxApi';
|
|
@@ -14,6 +14,11 @@ import {
|
|
|
14
14
|
} from '../../src/worklet-runtime/workletRef';
|
|
15
15
|
import { initWorklet } from '../../src/worklet-runtime/workletRuntime';
|
|
16
16
|
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.dispose();
|
|
19
|
+
delete globalThis.lynxWorkletImpl;
|
|
20
|
+
});
|
|
21
|
+
|
|
17
22
|
describe('Worklet', () => {
|
|
18
23
|
const consoleMock = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
|
19
24
|
|
|
@@ -21,6 +26,7 @@ describe('Worklet', () => {
|
|
|
21
26
|
globalThis.SystemInfo = {
|
|
22
27
|
lynxSdkVersion: '2.16',
|
|
23
28
|
};
|
|
29
|
+
globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager?.dispose();
|
|
24
30
|
delete globalThis.lynxWorkletImpl;
|
|
25
31
|
globalThis.lynx = {
|
|
26
32
|
requestAnimationFrame: vi.fn(),
|
|
@@ -808,3 +814,49 @@ it('requestAnimationFrame should throw error before 2.16 2', async () => {
|
|
|
808
814
|
globalThis.runWorklet(worklet, [1]);
|
|
809
815
|
expect(fn).toBeCalled();
|
|
810
816
|
});
|
|
817
|
+
|
|
818
|
+
it('preserves an already-bound handle execId and skips unbound handles without a root execId', () => {
|
|
819
|
+
globalThis.SystemInfo = { lynxSdkVersion: '2.16' };
|
|
820
|
+
initWorklet();
|
|
821
|
+
globalThis.registerWorklet('main-thread', 'capture-handles', function() {
|
|
822
|
+
return this._jsFn;
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
const prebound = { _jsFnId: 1, _execId: 4 };
|
|
826
|
+
globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.addRef(4, prebound);
|
|
827
|
+
const unbound = { _jsFnId: 2 };
|
|
828
|
+
|
|
829
|
+
// Root without `_execId` preserves `prebound._execId` and leaves `unbound` uncounted.
|
|
830
|
+
const withoutExec = { _wkltId: 'capture-handles', _jsFn: { prebound, unbound } };
|
|
831
|
+
globalThis.runWorklet(withoutExec, []);
|
|
832
|
+
expect(prebound._execId).toBe(4);
|
|
833
|
+
expect(unbound._execId).toBeUndefined();
|
|
834
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(4)).toBe(1);
|
|
835
|
+
|
|
836
|
+
// Another root with `_execId = 9` still does not overwrite `prebound._execId`.
|
|
837
|
+
const withOtherExec = { _wkltId: 'capture-handles', _execId: 9, _jsFn: { prebound } };
|
|
838
|
+
globalThis.runWorklet(withOtherExec, []);
|
|
839
|
+
expect(prebound._execId).toBe(4);
|
|
840
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(4)).toBe(1);
|
|
841
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(9)).toBeUndefined();
|
|
842
|
+
|
|
843
|
+
// A hydrated handle from an older reload epoch must not register its retired `_execId` before re-hydration.
|
|
844
|
+
const staleEpochHandle = { _jsFnId: 3, _execId: 7, _isFirstScreen: false, _hydratedEpoch: 0 };
|
|
845
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.clearDelayedBackgroundFunctions();
|
|
846
|
+
globalThis.runWorklet({ _wkltId: 'capture-handles', _jsFn: { staleEpochHandle } }, []);
|
|
847
|
+
expect(globalThis.lynxWorkletImpl._jsFunctionLifecycleManager.execIdRefCount.get(7)).toBeUndefined();
|
|
848
|
+
|
|
849
|
+
// Short-circuit checks: a prebound handle without `_hydratedEpoch` must neither read root `_execId`
|
|
850
|
+
// nor dereference `_runOnBackgroundDelayImpl.epoch`.
|
|
851
|
+
globalThis.registerWorklet('main-thread', 'capture-arg-handle', function(cb) {
|
|
852
|
+
return cb._execId;
|
|
853
|
+
});
|
|
854
|
+
const args = [{ _jsFnId: 4, _execId: 12 }];
|
|
855
|
+
Object.defineProperty(args, '_execId', {
|
|
856
|
+
get() {
|
|
857
|
+
throw new Error('root _execId should not be read for prebound handle');
|
|
858
|
+
},
|
|
859
|
+
});
|
|
860
|
+
delete globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl;
|
|
861
|
+
expect(globalThis.runWorklet({ _wkltId: 'capture-arg-handle' }, args)).toBe(12);
|
|
862
|
+
});
|
package/runtime/lazy/internal.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-name.js","sourceRoot":"","sources":["../../src/core/attribute-name.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,4BAA4B,GAAG,kEAAkE,CAAC;AACxG,MAAM,wBAAwB,GAAG,6EAA6E,CAAC;AAE/G,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,OAAO,4BAA4B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,GAAW;IAClD,OAAO,wBAAwB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,yBAAyB,CAAC,IAAY;IAC7C,IACE,IAAI,CAAC,MAAM,IAAI,CAAC;WACb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aAAM,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;YACjC,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;IAC9C,CAAC;IAED,+DAA+D;IAC/D,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nconst lynxEventAttributeNameRegExp = /^(?:global-bind|bind|catch|capture-bind|capture-catch)[A-Za-z]+$/;\nconst namespacedEventKeyRegExp = /^[A-Za-z-]+:(?:global-bind|bind|catch|capture-bind|capture-catch)[A-Za-z]+$/;\n\nexport function isEventPropKey(key: string): boolean {\n return lynxEventAttributeNameRegExp.test(key);\n}\n\nexport function isNamespacedEventPropKey(key: string): boolean {\n return namespacedEventKeyRegExp.test(key);\n}\n\nfunction isReactEventAttributeName(name: string): boolean {\n if (\n name.length <= 2\n || !name.startsWith('on')\n ) {\n return false;\n }\n\n let code = name.charCodeAt(2);\n if (code < 65 || code > 90) {\n return false;\n }\n for (let index = 3; index < name.length; index++) {\n code = name.charCodeAt(index);\n if (\n (code < 65 || code > 90)\n && (code < 97 || code > 122)\n ) {\n return false;\n }\n }\n return true;\n}\n\nfunction toDashCase(name: string): string {\n let index = 0;\n for (; index < name.length; index++) {\n const code = name.charCodeAt(index);\n if (code >= 65 && code <= 90) {\n break;\n }\n }\n\n if (index === name.length) {\n return name;\n }\n\n let transformed = name.slice(0, index);\n for (; index < name.length; index++) {\n const code = name.charCodeAt(index);\n if (code >= 65 && code <= 90) {\n if (index !== 0) {\n transformed += '-';\n }\n transformed += name[index]!.toLowerCase();\n } else {\n transformed += name[index];\n }\n }\n return transformed;\n}\n\nexport function transformAttrName(name: string): string {\n const config = lynx.__runtime_configs__?.transformBuiltinAttributeNames;\n\n // A disabled config keeps every name unchanged.\n if (!config) {\n return name;\n }\n\n // An object config applies rules in `rename > preserve > mode` order.\n if (config !== true) {\n if (\n config.rename\n && Object.prototype.hasOwnProperty.call(config.rename, name)\n ) {\n return config.rename[name]!;\n }\n if (\n config.preserve?.includes(name)\n || config.mode === 'mapping-only'\n ) {\n return name;\n }\n }\n\n // Enabled configs keep native Lynx event names unchanged.\n if (isEventPropKey(name) || isNamespacedEventPropKey(name)) {\n return name;\n }\n\n // `true` and the default dash-case mode apply React-style event mappings.\n if (isReactEventAttributeName(name)) {\n if (name === 'onClick') {\n return 'bindtap';\n } else if (name === 'onCatchTap') {\n return 'catchtap';\n }\n return `bind${name.slice(2).toLowerCase()}`;\n }\n\n // Remaining names use dash-case when the transform is enabled.\n return toDashCase(name);\n}\n"]}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { BackgroundFunctionExecMap } from './exec-map.js';
|
|
5
|
-
import { isSdkVersionGt } from '../../
|
|
6
|
-
import { delayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';
|
|
5
|
+
import { isSdkVersionGt } from '../../shared/version.js';
|
|
6
|
+
import { delayRunOnBackground, shouldDelayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';
|
|
7
7
|
import { WorkletEvents } from '../../worklet-runtime/bindings/events.js';
|
|
8
8
|
import { addReloadScopedEventListener, dispatchReloadScopedEvent } from '../reload-scoped-event.js';
|
|
9
9
|
import { isRuntimeDestroyed, registerDestroyTask } from '../runtime-destroy.js';
|
|
@@ -108,18 +108,18 @@ export function runOnBackground(f) {
|
|
|
108
108
|
return new Promise((resolve) => {
|
|
109
109
|
if (isRuntimeDestroyed())
|
|
110
110
|
return;
|
|
111
|
-
|
|
112
|
-
if (obj._isFirstScreen) {
|
|
111
|
+
if (shouldDelayRunOnBackground(obj)) {
|
|
113
112
|
delayRunOnBackground(obj, (fnId, execId) => {
|
|
114
|
-
dispatchRunBackgroundFunctionEvent(fnId, params, execId,
|
|
113
|
+
dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolve);
|
|
115
114
|
});
|
|
116
115
|
return;
|
|
117
116
|
}
|
|
118
|
-
dispatchRunBackgroundFunctionEvent(obj._jsFnId, params, obj._execId,
|
|
117
|
+
dispatchRunBackgroundFunctionEvent(obj._jsFnId, params, obj._execId, resolve);
|
|
119
118
|
});
|
|
120
119
|
};
|
|
121
120
|
}
|
|
122
|
-
function dispatchRunBackgroundFunctionEvent(fnId, params, execId,
|
|
121
|
+
function dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolve) {
|
|
122
|
+
const resolveId = onFunctionCall(resolve);
|
|
123
123
|
dispatchReloadScopedEvent(lynx.getJSContext(), {
|
|
124
124
|
type: WorkletEvents.runOnBackground,
|
|
125
125
|
data: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-on-background.js","sourceRoot":"","sources":["../../../src/core/background-function/run-on-background.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"run-on-background.js","sourceRoot":"","sources":["../../../src/core/background-function/run-on-background.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAC9G,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAGzE,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACpG,OAAO,EAAE,kBAA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nC,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,EAAE,GAAG,MAA0B,EAAc,EAAE;QACzD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,IAAI,kBAAkB,EAAE;gBAAE,OAAO;YAEjC,IAAI,0BAA0B,CAAC,GAAG,CAAC,EAAE,CAAC;gBACpC,oBAAoB,CAAC,GAAG,EAAE,CAAC,IAAY,EAAE,MAAc,EAAE,EAAE;oBACzD,kCAAkC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;gBACpE,CAAC,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YAED,kCAAkC,CAAC,GAAG,CAAC,OAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,OAAQ,EAAE,OAAO,CAAC,CAAC;QAClF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,kCAAkC,CACzC,IAAY,EACZ,MAA0B,EAC1B,MAAc,EACd,OAA6B;IAE7B,MAAM,SAAS,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IAC1C,yBAAyB,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE;QAC7C,IAAI,EAAE,aAAa,CAAC,eAAe;QACnC,IAAI,EAAE;YACJ,GAAG,EAAE;gBACH,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,MAAM;aAChB;YACD,MAAM;YACN,SAAS;SACa;KACzB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { BackgroundFunctionExecMap } from './exec-map.js';\nimport { isSdkVersionGt } from '../../shared/version.js';\nimport { delayRunOnBackground, shouldDelayRunOnBackground } from '../../worklet-runtime/bindings/bindings.js';\nimport { WorkletEvents } from '../../worklet-runtime/bindings/events.js';\nimport type { RunWorkletCtxRetData } from '../../worklet-runtime/bindings/events.js';\nimport type { ClosureValueType, JsFnHandle, Worklet } from '../../worklet-runtime/bindings/types.js';\nimport { addReloadScopedEventListener, dispatchReloadScopedEvent } from '../reload-scoped-event.js';\nimport { isRuntimeDestroyed, registerDestroyTask } from '../runtime-destroy.js';\nimport { onFunctionCall } from '../thread-function-call/return-value.js';\n\n/**\n * @internal\n */\ninterface RunOnBackgroundData {\n obj: JsFnHandle;\n params: unknown[];\n resolveId: number;\n}\n\nlet execIdMap: BackgroundFunctionExecMap | undefined;\nlet cleanupBackgroundFunctionRuntime: (() => void) | undefined;\nlet unregisterBackgroundFunctionCleanup: (() => void) | undefined;\n\nfunction initBackgroundFunctionRuntime(): void {\n 'background only';\n if (cleanupBackgroundFunctionRuntime) {\n return;\n }\n\n execIdMap ??= new BackgroundFunctionExecMap();\n const context = lynx.getCoreContext();\n const removeListener = addReloadScopedEventListener(context, WorkletEvents.runOnBackground, runBackgroundFunction);\n context.addEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n\n cleanupBackgroundFunctionRuntime = () => {\n removeListener();\n context.removeEventListener(WorkletEvents.releaseBackgroundWorkletCtx, releaseBackgroundFunctionCtx);\n execIdMap!.clear();\n cleanupBackgroundFunctionRuntime = undefined;\n };\n}\n\n/**\n * @internal\n */\nexport function runBackgroundFunction(data: RunOnBackgroundData): void {\n 'background only';\n const obj = execIdMap!.findJsFnHandle(data.obj._execId!, data.obj._jsFnId!);\n const f = obj?._fn;\n if (!f) {\n throw new Error('runOnBackground: JS function not found: ' + JSON.stringify(data.obj));\n }\n const returnValue = f(...data.params);\n dispatchReloadScopedEvent(lynx.getCoreContext(), {\n type: WorkletEvents.FunctionCallRet,\n data: { resolveId: data.resolveId, returnValue } satisfies RunWorkletCtxRetData,\n });\n}\n\nfunction releaseBackgroundFunctionCtx(event: RuntimeProxy.Event): void {\n 'background only';\n for (const id of event.data) {\n execIdMap!.remove(id as number);\n }\n}\n\n/**\n * @internal\n */\nexport function registerBackgroundFunctionCtx(ctx: Worklet): void {\n 'background only';\n initBackgroundFunctionRuntime();\n ensureBackgroundFunctionCleanup();\n execIdMap!.add(ctx);\n}\n\nfunction ensureBackgroundFunctionCleanup(): void {\n if (unregisterBackgroundFunctionCleanup) {\n return;\n }\n unregisterBackgroundFunctionCleanup = registerDestroyTask(() => {\n resetBackgroundFunctionRuntime();\n });\n}\n\nexport function resetBackgroundFunctionRuntime(): void {\n cleanupBackgroundFunctionRuntime?.();\n unregisterBackgroundFunctionCleanup?.();\n unregisterBackgroundFunctionCleanup = undefined;\n}\n\n/**\n * `runOnBackground` allows triggering js functions on the background thread asynchronously.\n * @param f - The js function to be called.\n * @returns A function. Calling which with the arguments to be passed to the js function to trigger it on the background thread. This function returns a promise that resolves to the return value of the js function.\n * @public\n *\n * @example\n *\n * ```ts\n * import { runOnBackground } from '@lynx-js/react';\n *\n * async function someMainthreadFunction() {\n * 'main thread';\n * const fn = runOnBackground(() => {\n * return 'hello';\n * });\n * const result = await fn();\n * }\n * ```\n *\n * @group Functions\n */\nexport function runOnBackground<R, Fn extends (...args: any[]) => R>(\n f: Fn,\n): (...args: Parameters<Fn>) => Promise<R> {\n if (!isSdkVersionGt(2, 15)) {\n throw new Error('runOnBackground requires Lynx sdk version 2.16.');\n }\n if (__JS__) {\n throw new Error('runOnBackground can only be used on the main thread.');\n }\n const obj = f as any as JsFnHandle;\n if (obj._error) {\n throw new Error(obj._error);\n }\n return async (...params: ClosureValueType[]): Promise<R> => {\n return new Promise((resolve) => {\n if (isRuntimeDestroyed()) return;\n\n if (shouldDelayRunOnBackground(obj)) {\n delayRunOnBackground(obj, (fnId: number, execId: number) => {\n dispatchRunBackgroundFunctionEvent(fnId, params, execId, resolve);\n });\n return;\n }\n\n dispatchRunBackgroundFunctionEvent(obj._jsFnId!, params, obj._execId!, resolve);\n });\n };\n}\n\nfunction dispatchRunBackgroundFunctionEvent(\n fnId: number,\n params: ClosureValueType[],\n execId: number,\n resolve: (value: any) => void,\n): void {\n const resolveId = onFunctionCall(resolve);\n dispatchReloadScopedEvent(lynx.getJSContext(), {\n type: WorkletEvents.runOnBackground,\n data: {\n obj: {\n _jsFnId: fnId,\n _execId: execId,\n },\n params,\n resolveId,\n } as RunOnBackgroundData,\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright 2024 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 { Suspense, createElement, lazy } from 'preact/compat';
|
|
5
|
+
import { useMemo } from '../hooks/react.js';
|
|
6
|
+
import { loadLazyBundle } from '../lynx/lazy-bundle.js';
|
|
7
|
+
/**
|
|
8
|
+
* @internal Compatibility for the compiler lowering of <component is=? />.
|
|
9
|
+
*/
|
|
10
|
+
export function __ComponentIsPolyfill({ is, ...props }) {
|
|
11
|
+
const DynamicComponent = useMemo(
|
|
12
|
+
// Lazy bundles expose React types but run on the host's Preact renderer.
|
|
13
|
+
() => lazy(() => loadLazyBundle(is)), [is]);
|
|
14
|
+
if (typeof is !== 'string') {
|
|
15
|
+
lynx.reportError(new Error('You must provide a string to props `is` when using syntax `<component is=? />`.'));
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return createElement(Suspense, { key: is, fallback: null }, createElement(DynamicComponent, props));
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=componentIs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"componentIs.js","sourceRoot":"","sources":["../../../src/core/compat/componentIs.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,EAAE,EAAE,EAAE,GAAG,KAAK,EAAkB;IACpE,MAAM,gBAAgB,GAAG,OAAO;IAC9B,yEAAyE;IACzE,GAAG,EAAE,CACH,IAAI,CAAyC,GAAG,EAAE,CAChD,cAAc,CAAC,EAAE,CAAiE,CACnF,EACH,CAAC,EAAE,CAAC,CACL,CAAC;IACF,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;QAC3B,IAAI,CAAC,WAAW,CACd,IAAI,KAAK,CACP,iFAAiF,CAClF,CACF,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,aAAa,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,aAAa,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC,CAAC;AACtG,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { ComponentType } from 'preact';\nimport { Suspense, createElement, lazy } from 'preact/compat';\n\nimport { useMemo } from '../hooks/react.js';\nimport { loadLazyBundle } from '../lynx/lazy-bundle.js';\n\n/**\n * @internal Compatibility for the compiler lowering of <component is=? />.\n */\nexport function __ComponentIsPolyfill({ is, ...props }: { is: string }) {\n const DynamicComponent = useMemo(\n // Lazy bundles expose React types but run on the host's Preact renderer.\n () =>\n lazy<ComponentType<Record<string, unknown>>>(() =>\n loadLazyBundle(is) as Promise<{ default: ComponentType<Record<string, unknown>> }>\n ),\n [is],\n );\n if (typeof is !== 'string') {\n lynx.reportError(\n new Error(\n 'You must provide a string to props `is` when using syntax `<component is=? />`.',\n ),\n );\n return null;\n }\n return createElement(Suspense, { key: is, fallback: null }, createElement(DynamicComponent, props));\n}\n"]}
|
|
@@ -26,7 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
26
26
|
SOFTWARE.
|
|
27
27
|
*/
|
|
28
28
|
import { Fragment, options } from 'preact';
|
|
29
|
-
import { DIFF, DIFFED, RENDER, ROOT } from '
|
|
29
|
+
import { DIFF, DIFFED, RENDER, ROOT } from '../shared/render-constants.js';
|
|
30
30
|
/**
|
|
31
31
|
* Get human readable name of the component/dom node
|
|
32
32
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-stack.js","sourceRoot":"","sources":["../../src/core/component-stack.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAG3C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAW3E;;GAEG;AACH,SAAS,mBAAmB,CAAC,KAAmB;IAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,UAAU,CAAC;IACpB,CAAC;SAAM,IAAI,OAAO,KAAK,CAAC,IAAI,IAAI,UAAU,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;IACnD,CAAC;SAAM,IAAI,OAAO,KAAK,CAAC,IAAI,IAAI,QAAQ,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,WAAW,GAAmB,EAAE,CAAC;AAEvC;;;;;;;;;;;;;;;;;GAiBG;A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MAAsD,EAAE,UAAU,EAAE,CAAC;YACzE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;YACvB,UAAU,GAAG,EAAE,CAAC;QAClB,CAAC;QACD,IAAI,OAAO;YAAE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC,CAAC;IAEF,OAAO,CAAC,KAAK,GAAG,CAAC,KAAmB,EAAE,EAAE;QACtC,gFAAgF;QAChF,4EAA4E;QAC5E,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/B,KAAK,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACnF,CAAC;QACD,IAAI,QAAQ;YAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,EAAE;QACxB,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QAED,IAAI,SAAS;YAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2025 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * @license\nThe MIT License (MIT)\n\nCopyright (c) 2015-present Jason Miller\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n */\n\nimport { Fragment, options } from 'preact';\nimport type { VNode } from 'preact';\n\nimport { DIFF, DIFFED, RENDER, ROOT } from '../shared/render-constants.js';\n\ninterface PatchedVNode extends VNode {\n _owner?: PatchedVNode | null;\n\n __source?: {\n fileName: string;\n lineNumber: number;\n };\n}\n\n/**\n * Get human readable name of the component/dom node\n */\nfunction getVNodeDisplayName(vnode: PatchedVNode): string {\n if (vnode.type === Fragment) {\n return 'Fragment';\n } else if (typeof vnode.type == 'function') {\n return vnode.type.displayName ?? vnode.type.name;\n } else if (typeof vnode.type == 'string') {\n return vnode.type;\n }\n\n return '#text';\n}\n\n/**\n * Used to keep track of the currently rendered `vnode` and print it\n * in debug messages.\n */\nconst renderStack: PatchedVNode[] = [];\n\n/**\n * Keep track of the current owners. An owner describes a component\n * which was responsible to render a specific `vnode`. This exclude\n * children that are passed via `props.children`, because they belong\n * to the parent owner.\n *\n * ```jsx\n * const Foo = props => <div>{props.children}</div> // div's owner is Foo\n * const Bar = props => {\n * return (\n * <Foo><span /></Foo> // Foo's owner is Bar, span's owner is Bar\n * )\n * }\n * ```\n *\n * Note: A `vnode` may be hoisted to the root scope due to compiler\n * optimization. In these cases the `_owner` will be different.\n */\nlet ownerStack: PatchedVNode[] = [];\nlet didInstallComponentStack = false;\n\n/**\n * Get the currently rendered `vnode`\n */\nexport function getCurrentVNode(): PatchedVNode | null {\n return renderStack.length > 0 ? renderStack[renderStack.length - 1]! : null;\n}\n\n/**\n * Check if a `vnode` is a possible owner.\n */\nfunction isPossibleOwner(vnode: PatchedVNode) {\n return typeof vnode.type == 'function' && vnode.type != Fragment;\n}\n\n/**\n * Return the component stack that was captured up to this point.\n */\nexport function getOwnerStack(vnode: PatchedVNode): string {\n const stack = [vnode];\n let next = vnode;\n while (next._owner != null) {\n stack.push(next._owner);\n next = next._owner;\n }\n\n return stack.reduce((acc, owner) => {\n acc += ` in ${getVNodeDisplayName(owner)}`;\n\n const source = owner.__source;\n if (source) {\n acc += ` (at ${source.fileName}:${source.lineNumber})`;\n }\n\n return (acc += '\\n');\n }, '');\n}\n\n/**\n * Setup code to capture the component trace while rendering. Note that\n * we cannot simply traverse `vnode._parent` upwards, because we have some\n * debug messages for `this.setState` where the `vnode` is `undefined`.\n */\nexport function setupComponentStack(): void {\n renderStack.length = 0;\n ownerStack = [];\n if (didInstallComponentStack) {\n return;\n }\n didInstallComponentStack = true;\n\n /* eslint-disable @typescript-eslint/unbound-method */\n const oldDiff = options[DIFF];\n const oldDiffed = options[DIFFED];\n const oldRoot = options[ROOT];\n const oldVNode = options.vnode;\n const oldRender = options[RENDER];\n /* eslint-enable @typescript-eslint/unbound-method */\n\n options[DIFFED] = vnode => {\n if (isPossibleOwner(vnode)) {\n const ownerIndex = ownerStack.lastIndexOf(vnode);\n if (ownerIndex !== -1) {\n ownerStack.length = ownerIndex;\n }\n const renderIndex = renderStack.lastIndexOf(vnode);\n if (renderIndex !== -1) {\n renderStack.length = renderIndex;\n }\n }\n if (oldDiffed) oldDiffed(vnode);\n };\n\n options[DIFF] = vnode => {\n if (isPossibleOwner(vnode)) {\n renderStack.push(vnode);\n }\n if (oldDiff) oldDiff(vnode);\n };\n\n options[ROOT] = (vnode, parent) => {\n if (!(parent as { parentNode?: unknown } | null | undefined)?.parentNode) {\n renderStack.length = 0;\n ownerStack = [];\n }\n if (oldRoot) oldRoot(vnode, parent);\n };\n\n options.vnode = (vnode: PatchedVNode) => {\n // Scheduled component updates clone the vnode before entering its render scope.\n // Preserve the original owner when Preact invokes this hook for that clone.\n if (vnode._owner === undefined) {\n vnode._owner = ownerStack.length > 0 ? ownerStack[ownerStack.length - 1]! : null;\n }\n if (oldVNode) oldVNode(vnode);\n };\n\n options[RENDER] = vnode => {\n if (isPossibleOwner(vnode)) {\n ownerStack.push(vnode);\n }\n\n if (oldRender) oldRender(vnode);\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isDirectOrDeepEqual(a: unknown, b: unknown): boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright 2024 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 { getCurrentVNode, getOwnerStack } from './component-stack.js';
|
|
5
|
+
export function isDirectOrDeepEqual(a, b) {
|
|
6
|
+
if (a === b) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
if (typeof a == 'object' && a !== null && typeof b == 'object' && b !== null
|
|
11
|
+
&& JSON.stringify(a) === JSON.stringify(b)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (__DEV__ && /circular|cyclic/i.test(error.message)) {
|
|
17
|
+
// JavaScript engines give this different errors name and messages:
|
|
18
|
+
// PrimJS: "circular reference"
|
|
19
|
+
// JavaScriptCore: "JSON.stringify cannot serialize cyclic structures"
|
|
20
|
+
// V8: "Converting circular structure to JSON"
|
|
21
|
+
const vnode = getCurrentVNode();
|
|
22
|
+
if (vnode) {
|
|
23
|
+
const stack = getOwnerStack(vnode);
|
|
24
|
+
error.message += `\n\n${stack}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=deep-equal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-equal.js","sourceRoot":"","sources":["../../src/core/deep-equal.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEtE,MAAM,UAAU,mBAAmB,CAAC,CAAU,EAAE,CAAU;IACxD,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC;QACH,IACE,OAAO,CAAC,IAAI,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,QAAQ,IAAI,CAAC,KAAK,IAAI;eACrE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAC1C,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAE,KAAe,CAAC,OAAO,CAAC,EAAE,CAAC;YACjE,mEAAmE;YACnE,+BAA+B;YAC/B,sEAAsE;YACtE,8CAA8C;YAC9C,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;YAChC,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;gBAClC,KAAe,CAAC,OAAO,IAAI,OAAO,KAAK,EAAE,CAAC;YAC7C,CAAC;QACH,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { getCurrentVNode, getOwnerStack } from './component-stack.js';\n\nexport function isDirectOrDeepEqual(a: unknown, b: unknown): boolean {\n if (a === b) {\n return true;\n }\n try {\n if (\n typeof a == 'object' && a !== null && typeof b == 'object' && b !== null\n && JSON.stringify(a) === JSON.stringify(b)\n ) {\n return true;\n }\n } catch (error) {\n if (__DEV__ && /circular|cyclic/i.test((error as Error).message)) {\n // JavaScript engines give this different errors name and messages:\n // PrimJS: \"circular reference\"\n // JavaScriptCore: \"JSON.stringify cannot serialize cyclic structures\"\n // V8: \"Converting circular structure to JSON\"\n const vnode = getCurrentVNode();\n if (vnode) {\n const stack = getOwnerStack(vnode);\n (error as Error).message += `\\n\\n${stack}`;\n }\n }\n throw error;\n }\n return false;\n}\n"]}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { options } from 'preact';
|
|
11
11
|
import { CHILDREN, COMPONENT, DIFF, DIFFED, HOOK, HOOKS, LIST, MASK, PARENT, PENDING_EFFECTS, RENDER, ROOT, VALUE, VNODE, } from '../../shared/render-constants.js';
|
|
12
|
-
import { noop } from '../../utils.js';
|
|
12
|
+
import { noop } from '../../shared/utils.js';
|
|
13
13
|
let currentIndex;
|
|
14
14
|
let currentComponent;
|
|
15
15
|
let currentHook;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mainThreadImpl.js","sourceRoot":"","sources":["../../../src/core/hooks/mainThreadImpl.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAUjC,OAAO,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,eAAe,EACf,MAAM,EACN,IAAI,EACJ,KAAK,EACL,KAAK,GACN,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,IAAI,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QACH,MAAM,IAAI,GAAG,IAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACnD,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAW,CAAC;AAChC,CAAC;AAED,mBAAmB;AACnB,MAAM,SAAS,GAAG,IAA4B,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAkC,CAAC;AAC3D,MAAM,mBAAmB,GAAG,IAAsC,CAAC;AAEnE,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,UAAU,EACV,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,UAAU,EACV,MAAM,EACN,QAAQ,GACT,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements hooks in the main thread.\n * This module is modified from preact/hooks\n *\n * internal-preact/hooks/dist/hooks.mjs\n */\n\nimport { options } from 'preact';\nimport type { Component, ErrorInfo, PreactContext } from 'preact';\nimport type {\n Dispatch,\n useEffect as useEffectType,\n useErrorBoundary as useErrorBoundaryType,\n useImperativeHandle as useImperativeHandleType,\n useLayoutEffect as useLayoutEffectType,\n} from 'preact/hooks';\n\nimport {\n CHILDREN,\n COMPONENT,\n DIFF,\n DIFFED,\n HOOK,\n HOOKS,\n LIST,\n MASK,\n PARENT,\n PENDING_EFFECTS,\n RENDER,\n ROOT,\n VALUE,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { noop } from '../../utils.js';\n\nlet currentIndex: number;\nlet currentComponent: Component | null | undefined;\nlet currentHook: number;\nlet hooksInstalled = false;\nlet oldBeforeDiff: ((vnode: any) => void) | undefined;\nlet oldBeforeRender: ((vnode: any) => void) | undefined;\nlet oldAfterDiff: ((vnode: any) => void) | undefined;\nlet oldRoot: ((vnode: any, parentDom: any) => void) | undefined;\n\nfunction installMainThreadHooks(): void {\n if (hooksInstalled) {\n return;\n }\n hooksInstalled = true;\n /* eslint-disable @typescript-eslint/unbound-method */\n oldBeforeDiff = options[DIFF];\n oldBeforeRender = options[RENDER];\n oldAfterDiff = options[DIFFED];\n oldRoot = options[ROOT];\n /* eslint-enable @typescript-eslint/unbound-method */\n\n options[DIFF] = function(vnode) {\n currentComponent = null;\n if (oldBeforeDiff) oldBeforeDiff(vnode);\n };\n\n /* v8 ignore start */\n options[ROOT] = function(vnode, parentDom) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (vnode && parentDom[CHILDREN] && parentDom[CHILDREN][MASK]) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n vnode[MASK] = parentDom[CHILDREN][MASK] as [number, number];\n }\n if (oldRoot) oldRoot(vnode, parentDom);\n };\n /* v8 ignore stop */\n\n options[RENDER] = function(vnode) {\n if (oldBeforeRender) oldBeforeRender(vnode);\n currentComponent = vnode[COMPONENT];\n currentIndex = 0;\n };\n\n options[DIFFED] = function(vnode) {\n if (oldAfterDiff) oldAfterDiff(vnode);\n currentComponent = null;\n };\n}\n\nfunction getHookState(index: number, type: number) {\n if (options[HOOK]) {\n options[HOOK](currentComponent!, index, currentHook || type);\n }\n currentHook = 0;\n const hooks = currentComponent![HOOKS] ?? (currentComponent![HOOKS] = {\n [LIST]: [],\n [PENDING_EFFECTS]: [],\n });\n if (index >= hooks[LIST]!.length) {\n hooks[LIST]!.push({});\n }\n return hooks[LIST]![index];\n}\n\nfunction invokeOrReturn(arg: unknown, f: (...args: unknown[]) => unknown) {\n return typeof f == 'function' ? f(arg) : f;\n}\n\nfunction useState<S>(initialState: S | (() => S)) {\n currentHook = 1;\n return useReducer(noop, initialState) as [S, Dispatch<unknown>];\n}\n\nfunction useReducer<S, A>(\n _reducer: (prevState: S, action: A) => S,\n initialState: S | (() => S),\n init?: (initialState: S) => S,\n) {\n const hookState = getHookState(currentIndex++, 2)!;\n if (!hookState[COMPONENT]) {\n hookState[VALUE] = [\n /* v8 ignore start */\n init ? init(initialState as S) : invokeOrReturn(undefined, initialState as (() => S)),\n /* v8 ignore stop */\n function(_action: A) {\n if (__DEV__) {\n console.error('Cannot update state in main thread!');\n }\n },\n ];\n hookState[COMPONENT] = currentComponent;\n }\n return hookState[VALUE] as [S, Dispatch<A>];\n}\n\nfunction useRef<T>(initialValue?: T): { current: T | undefined } {\n currentHook = 5;\n return useMemo(function() {\n return {\n current: initialValue,\n };\n }, []);\n}\n\n// used for first screen and need not to cache value by args\nfunction useMemo<T>(factory: () => T, _args: ReadonlyArray<unknown>): T {\n const state = getHookState(currentIndex++, 7)!;\n state[VALUE] = factory();\n return state[VALUE] as T;\n}\n\nfunction useCallback<T>(callback: T, args: ReadonlyArray<unknown>): T {\n currentHook = 8;\n return useMemo(function() {\n return callback;\n }, args);\n}\n\nfunction useContext<T>(context: PreactContext<T>): T {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const provider = currentComponent!.context[context.__c] as {\n props: {\n value: T;\n };\n };\n const state = getHookState(currentIndex++, 9)!;\n state['c'] = context;\n /* v8 ignore start */\n if (!provider) return context.__;\n /* v8 ignore stop */\n state[VALUE] = true;\n return provider.props.value;\n}\n\nfunction useDebugValue<T>(value: T, formatter?: (value: T) => string | number): void {\n if (options.useDebugValue) {\n /* v8 ignore start */\n options.useDebugValue(formatter ? formatter(value) : value as string | number);\n /* v8 ignore stop */\n }\n}\n\nfunction useErrorBoundary(cb: (error: any, errorInfo: ErrorInfo) => Promise<void> | void) {\n const state = getHookState(currentIndex++, 10)!;\n state[VALUE] = cb;\n return [undefined, noop] as ReturnType<typeof useErrorBoundaryType>;\n}\n\nfunction useId(): string {\n const state = getHookState(currentIndex++, 11)!;\n if (!state[VALUE]) {\n // Grab either the root node or the nearest async boundary node.\n let root = currentComponent![VNODE];\n while (root !== null && !root![MASK] && root![PARENT] !== null) {\n root = root![PARENT];\n }\n /**\n * init mask to [0, 0]\n * mask[0] will not change\n * mask[1] will auto increase\n */\n const mask = root![MASK] ?? (root![MASK] = [0, 0]);\n state[VALUE] = 'P' + mask[0] + '-' + mask[1]++;\n }\n return state[VALUE] as string;\n}\n\n// background hooks\nconst useEffect = noop as typeof useEffectType;\nconst useLayoutEffect = noop as typeof useLayoutEffectType;\nconst useImperativeHandle = noop as typeof useImperativeHandleType;\n\nexport {\n installMainThreadHooks,\n useCallback,\n useContext,\n useDebugValue,\n useEffect,\n useErrorBoundary,\n useId,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"mainThreadImpl.js","sourceRoot":"","sources":["../../../src/core/hooks/mainThreadImpl.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAUjC,OAAO,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,eAAe,EACf,MAAM,EACN,IAAI,EACJ,KAAK,EACL,KAAK,GACN,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,IAAI,YAAoB,CAAC;AACzB,IAAI,gBAA8C,CAAC;AACnD,IAAI,WAAmB,CAAC;AACxB,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,aAAiD,CAAC;AACtD,IAAI,eAAmD,CAAC;AACxD,IAAI,YAAgD,CAAC;AACrD,IAAI,OAA2D,CAAC;AAEhE,SAAS,sBAAsB;IAC7B,IAAI,cAAc,EAAE,C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CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAW,CAAC;AAChC,CAAC;AAED,mBAAmB;AACnB,MAAM,SAAS,GAAG,IAA4B,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAkC,CAAC;AAC3D,MAAM,mBAAmB,GAAG,IAAsC,CAAC;AAEnE,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,UAAU,EACV,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,UAAU,EACV,MAAM,EACN,QAAQ,GACT,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n/**\n * Implements hooks in the main thread.\n * This module is modified from preact/hooks\n *\n * internal-preact/hooks/dist/hooks.mjs\n */\n\nimport { options } from 'preact';\nimport type { Component, ErrorInfo, PreactContext } from 'preact';\nimport type {\n Dispatch,\n useEffect as useEffectType,\n useErrorBoundary as useErrorBoundaryType,\n useImperativeHandle as useImperativeHandleType,\n useLayoutEffect as useLayoutEffectType,\n} from 'preact/hooks';\n\nimport {\n CHILDREN,\n COMPONENT,\n DIFF,\n DIFFED,\n HOOK,\n HOOKS,\n LIST,\n MASK,\n PARENT,\n PENDING_EFFECTS,\n RENDER,\n ROOT,\n VALUE,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { noop } from '../../shared/utils.js';\n\nlet currentIndex: number;\nlet currentComponent: Component | null | undefined;\nlet currentHook: number;\nlet hooksInstalled = false;\nlet oldBeforeDiff: ((vnode: any) => void) | undefined;\nlet oldBeforeRender: ((vnode: any) => void) | undefined;\nlet oldAfterDiff: ((vnode: any) => void) | undefined;\nlet oldRoot: ((vnode: any, parentDom: any) => void) | undefined;\n\nfunction installMainThreadHooks(): void {\n if (hooksInstalled) {\n return;\n }\n hooksInstalled = true;\n /* eslint-disable @typescript-eslint/unbound-method */\n oldBeforeDiff = options[DIFF];\n oldBeforeRender = options[RENDER];\n oldAfterDiff = options[DIFFED];\n oldRoot = options[ROOT];\n /* eslint-enable @typescript-eslint/unbound-method */\n\n options[DIFF] = function(vnode) {\n currentComponent = null;\n if (oldBeforeDiff) oldBeforeDiff(vnode);\n };\n\n /* v8 ignore start */\n options[ROOT] = function(vnode, parentDom) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (vnode && parentDom[CHILDREN] && parentDom[CHILDREN][MASK]) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n vnode[MASK] = parentDom[CHILDREN][MASK] as [number, number];\n }\n if (oldRoot) oldRoot(vnode, parentDom);\n };\n /* v8 ignore stop */\n\n options[RENDER] = function(vnode) {\n if (oldBeforeRender) oldBeforeRender(vnode);\n currentComponent = vnode[COMPONENT];\n currentIndex = 0;\n };\n\n options[DIFFED] = function(vnode) {\n if (oldAfterDiff) oldAfterDiff(vnode);\n currentComponent = null;\n };\n}\n\nfunction getHookState(index: number, type: number) {\n if (options[HOOK]) {\n options[HOOK](currentComponent!, index, currentHook || type);\n }\n currentHook = 0;\n const hooks = currentComponent![HOOKS] ?? (currentComponent![HOOKS] = {\n [LIST]: [],\n [PENDING_EFFECTS]: [],\n });\n if (index >= hooks[LIST]!.length) {\n hooks[LIST]!.push({});\n }\n return hooks[LIST]![index];\n}\n\nfunction invokeOrReturn(arg: unknown, f: (...args: unknown[]) => unknown) {\n return typeof f == 'function' ? f(arg) : f;\n}\n\nfunction useState<S>(initialState: S | (() => S)) {\n currentHook = 1;\n return useReducer(noop, initialState) as [S, Dispatch<unknown>];\n}\n\nfunction useReducer<S, A>(\n _reducer: (prevState: S, action: A) => S,\n initialState: S | (() => S),\n init?: (initialState: S) => S,\n) {\n const hookState = getHookState(currentIndex++, 2)!;\n if (!hookState[COMPONENT]) {\n hookState[VALUE] = [\n /* v8 ignore start */\n init ? init(initialState as S) : invokeOrReturn(undefined, initialState as (() => S)),\n /* v8 ignore stop */\n function(_action: A) {\n if (__DEV__) {\n console.error('Cannot update state in main thread!');\n }\n },\n ];\n hookState[COMPONENT] = currentComponent;\n }\n return hookState[VALUE] as [S, Dispatch<A>];\n}\n\nfunction useRef<T>(initialValue?: T): { current: T | undefined } {\n currentHook = 5;\n return useMemo(function() {\n return {\n current: initialValue,\n };\n }, []);\n}\n\n// used for first screen and need not to cache value by args\nfunction useMemo<T>(factory: () => T, _args: ReadonlyArray<unknown>): T {\n const state = getHookState(currentIndex++, 7)!;\n state[VALUE] = factory();\n return state[VALUE] as T;\n}\n\nfunction useCallback<T>(callback: T, args: ReadonlyArray<unknown>): T {\n currentHook = 8;\n return useMemo(function() {\n return callback;\n }, args);\n}\n\nfunction useContext<T>(context: PreactContext<T>): T {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const provider = currentComponent!.context[context.__c] as {\n props: {\n value: T;\n };\n };\n const state = getHookState(currentIndex++, 9)!;\n state['c'] = context;\n /* v8 ignore start */\n if (!provider) return context.__;\n /* v8 ignore stop */\n state[VALUE] = true;\n return provider.props.value;\n}\n\nfunction useDebugValue<T>(value: T, formatter?: (value: T) => string | number): void {\n if (options.useDebugValue) {\n /* v8 ignore start */\n options.useDebugValue(formatter ? formatter(value) : value as string | number);\n /* v8 ignore stop */\n }\n}\n\nfunction useErrorBoundary(cb: (error: any, errorInfo: ErrorInfo) => Promise<void> | void) {\n const state = getHookState(currentIndex++, 10)!;\n state[VALUE] = cb;\n return [undefined, noop] as ReturnType<typeof useErrorBoundaryType>;\n}\n\nfunction useId(): string {\n const state = getHookState(currentIndex++, 11)!;\n if (!state[VALUE]) {\n // Grab either the root node or the nearest async boundary node.\n let root = currentComponent![VNODE];\n while (root !== null && !root![MASK] && root![PARENT] !== null) {\n root = root![PARENT];\n }\n /**\n * init mask to [0, 0]\n * mask[0] will not change\n * mask[1] will auto increase\n */\n const mask = root![MASK] ?? (root![MASK] = [0, 0]);\n state[VALUE] = 'P' + mask[0] + '-' + mask[1]++;\n }\n return state[VALUE] as string;\n}\n\n// background hooks\nconst useEffect = noop as typeof useEffectType;\nconst useLayoutEffect = noop as typeof useLayoutEffectType;\nconst useImperativeHandle = noop as typeof useImperativeHandleType;\n\nexport {\n installMainThreadHooks,\n useCallback,\n useContext,\n useDebugValue,\n useEffect,\n useErrorBoundary,\n useId,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setupSharedLynxEnv(): void;
|