@lynx-js/react 0.129.2 → 0.129.4
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 +24 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -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/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/lynx/performance.test.ts +1 -0
- package/runtime/__test__/element-template/native/callDestroyLifetimeFun.test.ts +1 -0
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +10 -15
- package/runtime/__test__/element-template/native/reload.test.ts +4 -7
- 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/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 +3 -4
- 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 +32 -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 +1 -0
- package/runtime/__test__/guardrails/snapshot-containment.test.ts +98 -77
- package/runtime/__test__/snapshot/compat/export.test.jsx +8 -2
- package/runtime/__test__/snapshot/debug/passive-update-depth.test.jsx +549 -0
- 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 +1 -1
- package/runtime/__test__/snapshot/lifecycle/transfer.mts.test.jsx +194 -0
- package/runtime/__test__/snapshot/lifecycle/transfer.test.jsx +210 -0
- package/runtime/__test__/snapshot/list.test.jsx +109 -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 +5 -0
- package/runtime/__test__/snapshot/utils/globals.js +1 -0
- package/runtime/__test__/worklet-runtime/delayWorkletEvent.test.js +22 -11
- package/runtime/__test__/worklet-runtime/hydrate.test.js +1 -0
- package/runtime/__test__/worklet-runtime/initEntry.test.js +12 -0
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +24 -16
- 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/compat/index.d.ts +17 -1
- package/runtime/compat/index.js +3 -2
- package/runtime/lazy/compat.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/{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-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.js +1 -1
- 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-hook.js +1 -1
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/destroy.js +1 -1
- package/runtime/lib/element-template/background/destroy.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +173 -85
- package/runtime/lib/element-template/background/hydrate.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/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/native/index.js +2 -2
- package/runtime/lib/element-template/native/index.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 +0 -4
- 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 +42 -119
- 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 +2 -2
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +1 -6
- 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 +1 -0
- 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/shared/version.js +15 -0
- 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 +1 -1
- 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 +1 -1
- 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/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 +15 -0
- package/runtime/lib/snapshot/transfer.js +343 -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/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 +2 -4
- package/runtime/lib/worklet-runtime/delayWorkletEvent.js +42 -44
- 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/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/{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/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 +1 -1
- package/runtime/src/element-template/background/attr-slots.ts +2 -2
- package/runtime/src/element-template/background/commit-hook.ts +1 -1
- package/runtime/src/element-template/background/destroy.ts +1 -1
- package/runtime/src/element-template/background/hydrate.ts +229 -119
- package/runtime/src/element-template/background/instance.ts +82 -82
- 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/native/index.ts +2 -2
- package/runtime/src/element-template/native/patch-listener.ts +6 -7
- package/runtime/src/element-template/native/reload-main-thread.ts +0 -4
- 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 +59 -163
- 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 +3 -2
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +1 -6
- 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 +2 -0
- 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/shared/version.ts +16 -0
- package/runtime/src/snapshot/alog/render.ts +1 -1
- package/runtime/src/snapshot/debug/profileHooks.ts +1 -1
- 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 +1 -1
- package/runtime/src/snapshot/list/list.ts +12 -3
- 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 +379 -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/observers.ts +9 -1
- package/runtime/src/worklet-runtime/bindings/types.ts +1 -0
- package/runtime/src/worklet-runtime/delayWorkletEvent.ts +49 -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/workletRef.ts +63 -62
- package/runtime/src/worklet-runtime/workletRuntime.ts +10 -10
- package/testing-library/.turbo/turbo-build.log +10 -10
- 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__/list.test.jsx +52 -0
- package/testing-library/src/__tests__/worklet.test.jsx +81 -0
- 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 +88 -201
- 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 +0 -19
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +129 -156
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +282 -149
- 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/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/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/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 +0 -10
- package/runtime/lib/worklet-runtime/utils/version.js.map +0 -1
- package/runtime/src/snapshot/alog/index.ts +0 -8
- package/runtime/src/utils.ts +0 -134
- package/runtime/src/worklet-runtime/delayRunOnBackground.ts +0 -53
- package/runtime/src/worklet-runtime/utils/version.ts +0 -11
- /package/runtime/__test__/element-template/fixtures/background/hydrate/{coverage.raw-text-key-branches → children.reconciles-raw-text-slots}/output.txt +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/src/{shared → core}/attribute-name.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lynx-api.js","sourceRoot":"","sources":["../src/lynx-api.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,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;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAiD,eAAe,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;AAIvH,MAAM,YAAY,GAAG,eAAe,CAAC,iBAAiB,CAAc;IAClE,aAAa;IACb,QAAQ;IACR,aAAa;IACb,0BAA0B;CAC3B,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,oDAAoD;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAA6C,eAAe,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;AAErH;;;;;;;;GAQG;AACH,oDAAoD;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAA0B,eAAe,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;AAElG;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB,eAAe,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;AAEpF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAoD,eAAe,CAAC,YAAY;KAC/G,UAAU,EAAE,CAAC;AAGhB,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAwI/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,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.\nimport { render } from 'preact';\nimport { createContext, createElement } from 'preact/compat';\nimport { useState } from 'preact/hooks';\nimport type { Consumer, FC, ReactNode } from 'react';\n\nimport { createGlobalProps } from './core/globalProps.js';\nimport type { GlobalProps } from './core/globalProps.js';\nimport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nimport { factory, withInitDataInState } from './core/initData.js';\nimport type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw } from './core/lynx-data-processors.js';\nimport { __root } from './root.js';\nimport { profileEnd, profileStart } from './shared/profile.js';\nimport { LifecycleConstant } from './snapshot/lifecycle/constant.js';\nimport { onFirstScreenSyncReady } from './snapshot/lifecycle/event/firstScreenSync.js';\nimport { flushDelayedLifecycleEvents } from './snapshot/lynx/tt.js';\n\n/**\n * The default root exported by `@lynx-js/react` for you to render a JSX\n * @public\n *\n * @group Types\n */\nexport interface Root {\n /**\n * Use this API to pass in your JSX to render\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * ```tsx\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * if (__MAIN_THREAD__) {\n * root.render(\n * <DataProvider data={DEFAULT_DATA}>\n * <App/>\n * </DataProvider>\n * );\n * } else if (__BACKGROUND__) {\n * fetchData().then((data) => {\n * root.render(\n * <DataProvider data={data}>\n * <App/>\n * </DataProvider>\n * ); // You can render later after your data is ready\n * })\n * }\n * ```\n *\n * @public\n */\n render: (jsx: ReactNode) => void;\n /**\n * {@inheritDoc Lynx.registerDataProcessors}\n * @deprecated use {@link Lynx.registerDataProcessors | lynx.registerDataProcessors} instead\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition) => void;\n}\n\n/**\n * The default and only root of ReactLynx for you to render JSX\n * @example\n * ```ts\n * import { root } from \"@lynx-js/react\"\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport const root: Root = {\n render: (jsx: ReactNode): void => {\n /* v8 ignore next 2 */\n if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n __root.__jsx = jsx;\n } else {\n __root.__jsx = jsx;\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::renderBackground');\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(jsx, __root as any);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'jsReady') {\n // `jsReady` is a special case of the `manual` first-screen sync: the\n // framework marks ready automatically once the background is ready.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n } else {\n // `immediately` or `manual`: the first screen is synced without waiting\n // for the background, so the `firstScreen` message might have been\n // reached when `root.render()` is called asynchronously.\n flushDelayedLifecycleEvents();\n }\n }\n },\n /* v8 ignore next 3 */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition): void => {\n lynx.registerDataProcessors(dataProcessorDefinition);\n },\n};\n\n/**\n * Mark the first screen as ready to sync when `firstScreenSyncTiming` is `'manual'`.\n *\n * The main thread holds the UI control until this is called, so the handover timing to\n * the background thread (for hydration) is fully controlled by the user. It can be called\n * from both threads (a background-thread call is forwarded to the main thread), is a no-op\n * unless `firstScreenSyncTiming` is `'manual'`, and has no further effect once called.\n *\n * @example\n *\n * ```ts\n * import { markFirstScreenSyncReady } from \"@lynx-js/react\"\n *\n * markFirstScreenSyncReady();\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport function markFirstScreenSyncReady(): void {\n if (__FIRST_SCREEN_SYNC_TIMING__ !== 'manual') {\n return;\n }\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // The sync happens on the main thread, forward the mark to it.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n return;\n }\n onFirstScreenSyncReady();\n}\n\nconst _InitData = /* @__PURE__ */ factory<InitData>(\n {\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n },\n '__initData',\n 'onDataChanged',\n);\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `initData`,\n * you must wrap your JSX inside it\n * @group Components\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <InitDataConsumer children={(initData) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <InitDataProvider>\n * <App/>\n * </InitDataProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _InitData.Provider();\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `initData`.\n * This should be used with {@link InitDataProvider}\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataConsumer: Consumer<InitData> = /* @__PURE__ */ _InitData.Consumer();\n/**\n * A React Hooks for you to get `initData`.\n * If `initData` is changed, a re-render will be triggered automatically.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const initData = useInitData();\n *\n * initData.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitData: () => InitData = /* @__PURE__ */ _InitData.use();\n/**\n * A React Hooks for you to get notified when `initData` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useInitDataChanged((data) => {\n * data.someProperty // can use it\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitDataChanged: (callback: (data: InitData) => void) => void = /* @__PURE__ */ _InitData.useChanged();\n\nexport type { GlobalProps } from './core/globalProps.js';\n\nconst _GlobalProps = /* @__PURE__ */ createGlobalProps<GlobalProps>({\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n});\n\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`; in the default `'reactive'` mode it renders its children directly\n * and updates come from a full re-render.\n * @group Components\n *\n * @example\n *\n * With `globalPropsMode: 'event'`:\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <GlobalPropsConsumer children={(globalProps) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <GlobalPropsProvider>\n * <App/>\n * </GlobalPropsProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _GlobalProps.Provider();\n\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`, together with {@link GlobalPropsProvider}; in the default `'reactive'` mode\n * it calls `children` with `lynx.__globalProps` directly and updates come from a full re-render.\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsConsumer: Consumer<GlobalProps> = /* @__PURE__ */ _GlobalProps.Consumer();\n\n/**\n * A React Hooks for you to get `lynx.__globalProps`.\n * With `globalPropsMode: 'event'`, the component re-renders when `lynx.__globalProps` changes;\n * in the default `'reactive'` mode, updates arrive through a full re-render.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const globalProps = useGlobalProps();\n *\n * globalProps.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalProps: () => GlobalProps = /* @__PURE__ */ _GlobalProps.use();\n\n/**\n * A React Hooks for you to get notified when `__globalProps` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useGlobalPropsChanged((data) => {\n * lynx.__globalProps.someProperty // can use lynx.__globalProps\n * data.someProperty // can use data\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalPropsChanged: (callback: (data: GlobalProps) => void) => void = /* @__PURE__ */ _GlobalProps\n .useChanged();\n\nexport type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw };\nexport { withInitDataInState };\n\n/**\n * APIs under `lynx` global variable that added by ReactLynx.\n *\n * @example\n *\n * ```ts\n * lynx.registerDataProcessors(...);\n * lynx.querySelector(...);\n * lynx.querySelectorAll(...);\n * ```\n *\n * @public\n *\n * @group Types\n */\nexport interface Lynx {\n /**\n * An alias of `lynx.getJSModule(\"GlobalEventEmitter\").trigger(eventName, params)` only in Lepus\n *\n * @public\n */\n triggerGlobalEventFromLepus: (eventName: string, params: any) => void;\n\n /**\n * Register DataProcessors. You MUST call this before `root.render()`.\n *\n * @example\n *\n * You MUST call `lynx.registerDataProcessors` before calling `root.render()`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * // You MUST call this before `root.render()`\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {...} // default DataProcessor\n * dataProcessors: {\n * getScreenMetricsOverride: () => {...} // named DataProcessor\n * }\n * })\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * If you have a class component with `static defaultDataProcessor`\n * or `static dataProcessors`, you can use it to register DataProcessors.\n *\n * ```ts\n * import { root, Component } from \"@lynx-js/react\"\n *\n * class App extends Component {\n * static defaultDataProcessor() {\n * ...\n * }\n *\n * static dataProcessors = {\n * getScreenMetricsOverride() {\n * ...\n * }\n * }\n * }\n *\n * lynx.registerDataProcessors(App); // You can pass `App` because it has the required shape\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * interface ExistingInterface {\n * somePropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitDataRaw extends ExistingInterface {\n * someAnotherCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: (initDataRaw) => {\n * initDataRaw.somePropertyFromExistingInterface // will be typed\n * }\n * })\n *\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { useInitData } from \"@lynx-js/react\"\n *\n * interface AnotherExistingInterface {\n * someAnotherPropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitData extends AnotherExistingInterface {\n * someCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {\n * return {\n * someCustomProperty: 'value', // will be typed\n * someAnotherPropertyFromExistingInterface: 1, // will be typed\n * }\n * }\n * })\n *\n * function App() {\n * const initData = useInitData();\n *\n * initData.someCustomProperty // will be typed\n * initData.someAnotherPropertyFromExistingInterface // will be typed\n * }\n *\n * ```\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void;\n}\n\nexport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nexport { runOnBackground } from './core/background-function/run-on-background.js';\nexport { runOnMainThread } from './snapshot/worklet/call/runOnMainThread.js';\nexport { MainThreadRef, useMainThreadRef } from './core/main-thread-ref.js';\nexport { defineMainThreadObjectType, useMainThreadObject } from './core/main-thread-object.js';\nexport type {\n MainThreadObjectHandle,\n MainThreadObjectType,\n MainThreadObjectTypeDefinition,\n} from './core/main-thread-object.js';\n"]}
|
|
1
|
+
{"version":3,"file":"lynx-api.js","sourceRoot":"","sources":["../src/lynx-api.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AACxF,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EA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CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,oDAAoD;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAA6C,eAAe,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;AAErH;;;;;;;;GAQG;AACH,oDAAoD;AACpD,MAAM,CAAC,MAAM,mBAAmB,GAA0B,eAAe,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;AAElG;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB,eAAe,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;AAEpF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAoD,eAAe,CAAC,YAAY;KAC/G,UAAU,EAAE,CAAC;AAGhB,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAwI/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,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.\nimport { render } from 'preact';\nimport { createContext, createElement } from 'preact/compat';\nimport { useState } from 'preact/hooks';\nimport type { Consumer, FC, ReactNode } from 'react';\n\nimport { createGlobalProps } from './core/globalProps.js';\nimport type { GlobalProps } from './core/globalProps.js';\nimport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nimport { factory, withInitDataInState } from './core/initData.js';\nimport type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw } from './core/lynx-data-processors.js';\nimport { __root, transferMode, warnRootRenderOnTransferPage } from './root.js';\nimport { profileEnd, profileStart } from './shared/profile.js';\nimport { LifecycleConstant } from './snapshot/lifecycle/constant.js';\nimport { onFirstScreenSyncReady } from './snapshot/lifecycle/event/firstScreenSync.js';\nimport { flushDelayedLifecycleEvents } from './snapshot/lynx/tt.js';\n\n/**\n * The default root exported by `@lynx-js/react` for you to render a JSX\n * @public\n *\n * @group Types\n */\nexport interface Root {\n /**\n * Use this API to pass in your JSX to render\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * ```tsx\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * if (__MAIN_THREAD__) {\n * root.render(\n * <DataProvider data={DEFAULT_DATA}>\n * <App/>\n * </DataProvider>\n * );\n * } else if (__BACKGROUND__) {\n * fetchData().then((data) => {\n * root.render(\n * <DataProvider data={data}>\n * <App/>\n * </DataProvider>\n * ); // You can render later after your data is ready\n * })\n * }\n * ```\n *\n * @public\n */\n render: (jsx: ReactNode) => void;\n /**\n * {@inheritDoc Lynx.registerDataProcessors}\n * @deprecated use {@link Lynx.registerDataProcessors | lynx.registerDataProcessors} instead\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition) => void;\n}\n\n/**\n * The default and only root of ReactLynx for you to render JSX\n * @example\n * ```ts\n * import { root } from \"@lynx-js/react\"\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport const root: Root = {\n render: (jsx: ReactNode): void => {\n // Transfer pages render only registered components; the page root stays empty.\n if (transferMode) {\n warnRootRenderOnTransferPage();\n return;\n }\n /* v8 ignore next 2 */\n if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n __root.__jsx = jsx;\n } else {\n __root.__jsx = jsx;\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::renderBackground');\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(jsx, __root as any);\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n if (__FIRST_SCREEN_SYNC_TIMING__ === 'jsReady') {\n // `jsReady` is a special case of the `manual` first-screen sync: the\n // framework marks ready automatically once the background is ready.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n } else {\n // `immediately` or `manual`: the first screen is synced without waiting\n // for the background, so the `firstScreen` message might have been\n // reached when `root.render()` is called asynchronously.\n flushDelayedLifecycleEvents();\n }\n }\n },\n /* v8 ignore next 3 */\n registerDataProcessors: (dataProcessorDefinition: DataProcessorDefinition): void => {\n lynx.registerDataProcessors(dataProcessorDefinition);\n },\n};\n\n/**\n * Mark the first screen as ready to sync when `firstScreenSyncTiming` is `'manual'`.\n *\n * The main thread holds the UI control until this is called, so the handover timing to\n * the background thread (for hydration) is fully controlled by the user. It can be called\n * from both threads (a background-thread call is forwarded to the main thread), is a no-op\n * unless `firstScreenSyncTiming` is `'manual'`, and has no further effect once called.\n *\n * @example\n *\n * ```ts\n * import { markFirstScreenSyncReady } from \"@lynx-js/react\"\n *\n * markFirstScreenSyncReady();\n * ```\n *\n * @public\n *\n * @group Functions\n */\nexport function markFirstScreenSyncReady(): void {\n if (__FIRST_SCREEN_SYNC_TIMING__ !== 'manual') {\n return;\n }\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // The sync happens on the main thread, forward the mark to it.\n lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});\n return;\n }\n onFirstScreenSyncReady();\n}\n\nconst _InitData = /* @__PURE__ */ factory<InitData>(\n {\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n },\n '__initData',\n 'onDataChanged',\n);\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `initData`,\n * you must wrap your JSX inside it\n * @group Components\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <InitDataConsumer children={(initData) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <InitDataProvider>\n * <App/>\n * </InitDataProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _InitData.Provider();\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `initData`.\n * This should be used with {@link InitDataProvider}\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const InitDataConsumer: Consumer<InitData> = /* @__PURE__ */ _InitData.Consumer();\n/**\n * A React Hooks for you to get `initData`.\n * If `initData` is changed, a re-render will be triggered automatically.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const initData = useInitData();\n *\n * initData.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitData: () => InitData = /* @__PURE__ */ _InitData.use();\n/**\n * A React Hooks for you to get notified when `initData` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useInitDataChanged((data) => {\n * data.someProperty // can use it\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useInitDataChanged: (callback: (data: InitData) => void) => void = /* @__PURE__ */ _InitData.useChanged();\n\nexport type { GlobalProps } from './core/globalProps.js';\n\nconst _GlobalProps = /* @__PURE__ */ createGlobalProps<GlobalProps>({\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n});\n\n/**\n * The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`; in the default `'reactive'` mode it renders its children directly\n * and updates come from a full re-render.\n * @group Components\n *\n * @example\n *\n * With `globalPropsMode: 'event'`:\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * return (\n * <GlobalPropsConsumer children={(globalProps) => <view>...</view>}/>\n * )\n * }\n *\n * root.render(\n * <GlobalPropsProvider>\n * <App/>\n * </GlobalPropsProvider>\n * );\n *\n * ```\n *\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _GlobalProps.Provider();\n\n/**\n * The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `lynx.__globalProps`.\n * Only needed with `globalPropsMode: 'event'`, together with {@link GlobalPropsProvider}; in the default `'reactive'` mode\n * it calls `children` with `lynx.__globalProps` directly and updates come from a full re-render.\n * @group Components\n * @public\n *\n * @function\n */\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsConsumer: Consumer<GlobalProps> = /* @__PURE__ */ _GlobalProps.Consumer();\n\n/**\n * A React Hooks for you to get `lynx.__globalProps`.\n * With `globalPropsMode: 'event'`, the component re-renders when `lynx.__globalProps` changes;\n * in the default `'reactive'` mode, updates arrive through a full re-render.\n *\n * @example\n *\n * ```ts\n * function App() {\n * const globalProps = useGlobalProps();\n *\n * globalProps.someProperty // use it\n * }\n * ```\n *\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalProps: () => GlobalProps = /* @__PURE__ */ _GlobalProps.use();\n\n/**\n * A React Hooks for you to get notified when `__globalProps` changed.\n *\n * @example\n * ```ts\n * function App() {\n * useGlobalPropsChanged((data) => {\n * lynx.__globalProps.someProperty // can use lynx.__globalProps\n * data.someProperty // can use data\n * })\n * }\n * ```\n * @function\n * @public\n *\n * @group Hooks\n */\nexport const useGlobalPropsChanged: (callback: (data: GlobalProps) => void) => void = /* @__PURE__ */ _GlobalProps\n .useChanged();\n\nexport type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw };\nexport { withInitDataInState };\n\n/**\n * APIs under `lynx` global variable that added by ReactLynx.\n *\n * @example\n *\n * ```ts\n * lynx.registerDataProcessors(...);\n * lynx.querySelector(...);\n * lynx.querySelectorAll(...);\n * ```\n *\n * @public\n *\n * @group Types\n */\nexport interface Lynx {\n /**\n * An alias of `lynx.getJSModule(\"GlobalEventEmitter\").trigger(eventName, params)` only in Lepus\n *\n * @public\n */\n triggerGlobalEventFromLepus: (eventName: string, params: any) => void;\n\n /**\n * Register DataProcessors. You MUST call this before `root.render()`.\n *\n * @example\n *\n * You MUST call `lynx.registerDataProcessors` before calling `root.render()`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * // You MUST call this before `root.render()`\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {...} // default DataProcessor\n * dataProcessors: {\n * getScreenMetricsOverride: () => {...} // named DataProcessor\n * }\n * })\n *\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * If you have a class component with `static defaultDataProcessor`\n * or `static dataProcessors`, you can use it to register DataProcessors.\n *\n * ```ts\n * import { root, Component } from \"@lynx-js/react\"\n *\n * class App extends Component {\n * static defaultDataProcessor() {\n * ...\n * }\n *\n * static dataProcessors = {\n * getScreenMetricsOverride() {\n * ...\n * }\n * }\n * }\n *\n * lynx.registerDataProcessors(App); // You can pass `App` because it has the required shape\n * root.render(<App/>);\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * interface ExistingInterface {\n * somePropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitDataRaw extends ExistingInterface {\n * someAnotherCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: (initDataRaw) => {\n * initDataRaw.somePropertyFromExistingInterface // will be typed\n * }\n * })\n *\n * ```\n *\n * @example\n *\n * For developers who want fully typed `defaultDataProcessor`,\n * they can achieve it by extends interface `InitDataRaw` and `InitData`.\n *\n * ```ts\n * import { useInitData } from \"@lynx-js/react\"\n *\n * interface AnotherExistingInterface {\n * someAnotherPropertyFromExistingInterface: number\n * }\n *\n * declare module '@lynx-js/react' {\n * interface InitData extends AnotherExistingInterface {\n * someCustomProperty: string\n * }\n * }\n *\n * lynx.registerDataProcessors({\n * defaultDataProcessor: () => {\n * return {\n * someCustomProperty: 'value', // will be typed\n * someAnotherPropertyFromExistingInterface: 1, // will be typed\n * }\n * }\n * })\n *\n * function App() {\n * const initData = useInitData();\n *\n * initData.someCustomProperty // will be typed\n * initData.someAnotherPropertyFromExistingInterface // will be typed\n * }\n *\n * ```\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void;\n}\n\nexport { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListener.js';\nexport { runOnBackground } from './core/background-function/run-on-background.js';\nexport { runOnMainThread } from './snapshot/worklet/call/runOnMainThread.js';\nexport { MainThreadRef, useMainThreadRef } from './core/main-thread-ref.js';\nexport { defineMainThreadObjectType, useMainThreadObject } from './core/main-thread-object.js';\nexport type {\n MainThreadObjectHandle,\n MainThreadObjectType,\n MainThreadObjectTypeDefinition,\n} from './core/main-thread-object.js';\n"]}
|
package/runtime/lib/lynx.js
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
import { options } from 'preact';
|
|
5
5
|
// to make sure preact's hooks to register earlier than ours
|
|
6
6
|
import './core/hooks/react.js';
|
|
7
|
+
import { setupComponentStack } from './core/component-stack.js';
|
|
7
8
|
import { document, setupBackgroundDocument } from './document.js';
|
|
8
|
-
import {
|
|
9
|
+
import { lynxQueueMicrotask } from './shared/microtask.js';
|
|
9
10
|
import { isProfiling } from './shared/profile.js';
|
|
10
11
|
import { initElementPAPICallAlog } from './snapshot/alog/elementPAPICall.js';
|
|
11
|
-
import {
|
|
12
|
+
import { initRenderAlog } from './snapshot/alog/render.js';
|
|
12
13
|
import { initProfileHook } from './snapshot/debug/profileHooks.js';
|
|
13
14
|
import { setupVNodeSourceHook } from './snapshot/debug/vnodeSource.js';
|
|
14
15
|
import { replaceCommitHook } from './snapshot/lifecycle/patch/commit.js';
|
|
@@ -21,7 +22,6 @@ import { initTimingAPI } from './snapshot/lynx/performance.js';
|
|
|
21
22
|
import { injectPrepareLazyBundleMTS } from './snapshot/lynx/prepareLazyBundleMTS.js';
|
|
22
23
|
import { injectTt } from './snapshot/lynx/tt.js';
|
|
23
24
|
import { injectUpdateMTRefInitValue } from './snapshot/worklet/ref/updateInitValue.js';
|
|
24
|
-
import { lynxQueueMicrotask } from './utils.js';
|
|
25
25
|
export { runWithForce } from './snapshot/lynx/runWithForce.js';
|
|
26
26
|
// @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature
|
|
27
27
|
if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__ && typeof globalThis.processEvalResult === 'undefined') {
|
|
@@ -54,7 +54,7 @@ if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__ && typeof __PROFIL
|
|
|
54
54
|
}
|
|
55
55
|
if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
|
|
56
56
|
// We are logging both main-thread and background.
|
|
57
|
-
|
|
57
|
+
initRenderAlog();
|
|
58
58
|
}
|
|
59
59
|
if (typeof __ALOG_ELEMENT_API__ !== 'undefined' && __ALOG_ELEMENT_API__) {
|
|
60
60
|
initElementPAPICallAlog();
|
package/runtime/lib/lynx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lynx.js","sourceRoot":"","sources":["../src/lynx.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,4DAA4D;AAC5D,OAAO,uBAAuB,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"lynx.js","sourceRoot":"","sources":["../src/lynx.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DA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CAAC;IAE9B,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,MAAM,EAAE,CAAC,CAAA,CAAC;SACrC,CAAC;QACJ,iBAAiB,EAAE,CAAC;QACpB,aAAa,EAAE,CAAC;QAChB,IAAI,OAAO,IAAI,WAAW,EAAE,CAAC;YAC3B,oBAAoB,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,WAAW,EAAE,CAAC;YAChB,eAAe,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC;AAED,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,cAAc,EAAE,CAAC;IAC5D,qBAAqB,EAAE,CAAC;AAC1B,CAAC;AAED,YAAY,EAAE,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.\nimport { options } from 'preact';\n// to make sure preact's hooks to register earlier than ours\nimport './core/hooks/react.js';\n\nimport { setupComponentStack } from './core/component-stack.js';\nimport { document, setupBackgroundDocument } from './document.js';\nimport { lynxQueueMicrotask } from './shared/microtask.js';\nimport { isProfiling } from './shared/profile.js';\nimport { initElementPAPICallAlog } from './snapshot/alog/elementPAPICall.js';\nimport { initRenderAlog } from './snapshot/alog/render.js';\nimport { initProfileHook } from './snapshot/debug/profileHooks.js';\nimport { setupVNodeSourceHook } from './snapshot/debug/vnodeSource.js';\nimport { replaceCommitHook } from './snapshot/lifecycle/patch/commit.js';\nimport { addCtxNotFoundEventListener } from './snapshot/lifecycle/patch/error.js';\nimport { injectUpdateMainThread } from './snapshot/lifecycle/patch/updateMainThread.js';\nimport { injectCalledByNative } from './snapshot/lynx/calledByNative.js';\nimport { setupLynxEnv } from './snapshot/lynx/env.js';\nimport { injectLepusMethods } from './snapshot/lynx/injectLepusMethods.js';\nimport { initTimingAPI } from './snapshot/lynx/performance.js';\nimport { injectPrepareLazyBundleMTS } from './snapshot/lynx/prepareLazyBundleMTS.js';\nimport { injectTt } from './snapshot/lynx/tt.js';\nimport { injectUpdateMTRefInitValue } from './snapshot/worklet/ref/updateInitValue.js';\n\nexport { runWithForce } from './snapshot/lynx/runWithForce.js';\n\n// @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__ && typeof globalThis.processEvalResult === 'undefined') {\n // @ts-expect-error Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature\n globalThis.processEvalResult = <T>(result: ((schema: string) => T) | undefined, schema: string) => {\n return result?.(schema);\n };\n}\n\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n injectCalledByNative();\n injectUpdateMainThread();\n injectUpdateMTRefInitValue();\n if (\n typeof __LAZY_BUNDLE_FETCHER__ !== 'undefined'\n && __LAZY_BUNDLE_FETCHER__ === 'FetchBundle'\n ) {\n injectPrepareLazyBundleMTS();\n }\n // `injectLepusMethods` exposes the snapshot <-> element mapping that preact\n // devtools relies on, so it must also run when devtools is enabled in\n // production via `REACT_DEVTOOL=true`.\n if (__DEV__ || (typeof __REACT_DEVTOOL__ !== 'undefined' && __REACT_DEVTOOL__)) {\n injectLepusMethods();\n }\n}\n\nif (__DEV__) {\n setupComponentStack();\n}\n\n// We are profiling both main-thread and background.\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__ && typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n initProfileHook();\n}\n\nif (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n // We are logging both main-thread and background.\n initRenderAlog();\n}\nif (typeof __ALOG_ELEMENT_API__ !== 'undefined' && __ALOG_ELEMENT_API__) {\n initElementPAPICallAlog();\n}\n\nfunction initBackgroundRuntime(): void {\n // Trick Preact and TypeScript to accept our custom document adapter.\n options.document = document as unknown as Document;\n options.requestAnimationFrame = lynxQueueMicrotask;\n setupBackgroundDocument();\n injectTt();\n addCtxNotFoundEventListener();\n\n if (process.env['NODE_ENV'] === 'test') {}\n else {\n replaceCommitHook();\n initTimingAPI();\n if (__DEV__ && isProfiling) {\n setupVNodeSourceHook();\n }\n if (isProfiling) {\n initProfileHook();\n }\n }\n}\n\nif (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n initBackgroundRuntime();\n}\n\nsetupLynxEnv();\n"]}
|
package/runtime/lib/root.d.ts
CHANGED
|
@@ -15,4 +15,8 @@ declare let __root: (SnapshotInstance | BackgroundSnapshotInstance) & {
|
|
|
15
15
|
nodeType?: Element['nodeType'];
|
|
16
16
|
};
|
|
17
17
|
declare function setRoot(root: typeof __root): void;
|
|
18
|
-
|
|
18
|
+
/** Set once a page renders transfer components; `root.render` is then ignored. */
|
|
19
|
+
declare let transferMode: boolean;
|
|
20
|
+
declare function enableTransferMode(): void;
|
|
21
|
+
declare function warnRootRenderOnTransferPage(): void;
|
|
22
|
+
export { __root, enableTransferMode, setRoot, transferMode, warnRootRenderOnTransferPage };
|
package/runtime/lib/root.js
CHANGED
|
@@ -21,5 +21,16 @@ if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {
|
|
|
21
21
|
else if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
22
22
|
setRoot(new BackgroundSnapshotInstance('root'));
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
/** Set once a page renders transfer components; `root.render` is then ignored. */
|
|
25
|
+
let transferMode = false;
|
|
26
|
+
function enableTransferMode() {
|
|
27
|
+
transferMode = true;
|
|
28
|
+
}
|
|
29
|
+
function warnRootRenderOnTransferPage() {
|
|
30
|
+
if (__DEV__) {
|
|
31
|
+
console.warn('[ReactLynx] `root.render` is ignored on transfer pages. '
|
|
32
|
+
+ 'Render components through `TransferRegistry.registerComponent` instead of mixing both.');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export { __root, enableTransferMode, setRoot, transferMode, warnRootRenderOnTransferPage };
|
|
25
36
|
//# sourceMappingURL=root.js.map
|
package/runtime/lib/root.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.js","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE;;;GAGG;AACH,IAAI,MAUH,CAAC;AAEF,SAAS,OAAO,CAAC,IAAmB;IAClC,MAAM,GAAG,IAAI,CAAC;IAEd,kDAAkD;IAClD,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACtB,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,IAAI,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EAAE,CAAC;IAC9D,OAAO,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;AACxC,CAAC;KAAM,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,cAAc,EAAE,CAAC;IACnE,OAAO,CAAC,IAAI,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,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.\nimport { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js';\nimport { SnapshotInstance } from './snapshot/snapshot/snapshot.js';\n\n/**\n * The internal ReactLynx's root.\n * {@link @lynx-js/react!Root | root}.\n */\nlet __root: (SnapshotInstance | BackgroundSnapshotInstance) & {\n __jsx?: React.ReactNode;\n __opcodes?: any[];\n\n /**\n * Returns the type of node.\n *\n * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/nodeType)\n */\n nodeType?: Element['nodeType'];\n};\n\nfunction setRoot(root: typeof __root): void {\n __root = root;\n\n // A fake ELEMENT_NODE to make preact/debug happy.\n if (__DEV__ && __root) {\n __root.nodeType = 1;\n }\n}\n\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n setRoot(new SnapshotInstance('root'));\n} else if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n setRoot(new BackgroundSnapshotInstance('root'));\n}\n\nexport { __root, setRoot };\n"]}
|
|
1
|
+
{"version":3,"file":"root.js","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE;;;GAGG;AACH,IAAI,MAUH,CAAC;AAEF,SAAS,OAAO,CAAC,IAAmB;IAClC,MAAM,GAAG,IAAI,CAAC;IAEd,kDAAkD;IAClD,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACtB,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,IAAI,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EAAE,CAAC;IAC9D,OAAO,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;AACxC,CAAC;KAAM,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,cAAc,EAAE,CAAC;IACnE,OAAO,CAAC,IAAI,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,kFAAkF;AAClF,IAAI,YAAY,GAAG,KAAK,CAAC;AAEzB,SAAS,kBAAkB;IACzB,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC;AAED,SAAS,4BAA4B;IACnC,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CACV,0DAA0D;cACtD,wFAAwF,CAC7F,CAAC;IACJ,CAAC;AACH,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,4BAA4B,EAAE,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.\nimport { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js';\nimport { SnapshotInstance } from './snapshot/snapshot/snapshot.js';\n\n/**\n * The internal ReactLynx's root.\n * {@link @lynx-js/react!Root | root}.\n */\nlet __root: (SnapshotInstance | BackgroundSnapshotInstance) & {\n __jsx?: React.ReactNode;\n __opcodes?: any[];\n\n /**\n * Returns the type of node.\n *\n * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/nodeType)\n */\n nodeType?: Element['nodeType'];\n};\n\nfunction setRoot(root: typeof __root): void {\n __root = root;\n\n // A fake ELEMENT_NODE to make preact/debug happy.\n if (__DEV__ && __root) {\n __root.nodeType = 1;\n }\n}\n\nif (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n setRoot(new SnapshotInstance('root'));\n} else if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n setRoot(new BackgroundSnapshotInstance('root'));\n}\n\n/** Set once a page renders transfer components; `root.render` is then ignored. */\nlet transferMode = false;\n\nfunction enableTransferMode(): void {\n transferMode = true;\n}\n\nfunction warnRootRenderOnTransferPage(): void {\n if (__DEV__) {\n console.warn(\n '[ReactLynx] `root.render` is ignored on transfer pages. '\n + 'Render components through `TransferRegistry.registerComponent` instead of mixing both.',\n );\n }\n}\n\nexport { __root, enableTransferMode, setRoot, transferMode, warnRootRenderOnTransferPage };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const lynxQueueMicrotask: typeof lynx.queueMicrotask;
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
export const lynxQueueMicrotask = /* @__PURE__ */ (() => {
|
|
5
|
+
if (lynx.queueMicrotask) {
|
|
6
|
+
return (fn) => lynx.queueMicrotask(fn);
|
|
7
|
+
}
|
|
8
|
+
else if (typeof globalThis.Promise === 'function') {
|
|
9
|
+
const resolved = globalThis.Promise.resolve();
|
|
10
|
+
/* v8 ignore start */
|
|
11
|
+
return (fn) => {
|
|
12
|
+
// Schedule as a microtask, and surface exceptions like queueMicrotask would.
|
|
13
|
+
resolved.then(fn).catch((err) => {
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
throw err;
|
|
16
|
+
}, 0);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// Fallback to macrotask when microtasks aren't available.
|
|
22
|
+
return (fn) => {
|
|
23
|
+
setTimeout(fn, 0);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/* v8 ignore stop */
|
|
27
|
+
})();
|
|
28
|
+
//# sourceMappingURL=microtask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"microtask.js","sourceRoot":"","sources":["../../src/shared/microtask.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,CAAC,MAAM,kBAAkB,GAA+B,eAAe,CAAC,CAAC,GAAG,EAAE;IAClF,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;QACxB,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;SAAM,IAAI,OAAO,UAAU,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QACpD,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC9C,qBAAqB;QACrB,OAAO,CAAC,EAAE,EAAE,EAAE;YACZ,6EAA6E;YAC7E,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC9B,UAAU,CAAC,GAAG,EAAE;oBACd,MAAM,GAAG,CAAC;gBACZ,CAAC,EAAE,CAAC,CAAC,CAAC;YACR,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,0DAA0D;QAC1D,OAAO,CAAC,EAAE,EAAE,EAAE;YACZ,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QACpB,CAAC,CAAC;IACJ,CAAC;IACD,oBAAoB;AACtB,CAAC,CAAC,EAAE,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\nexport const lynxQueueMicrotask: typeof lynx.queueMicrotask = /* @__PURE__ */ (() => {\n if (lynx.queueMicrotask) {\n return (fn) => lynx.queueMicrotask(fn);\n } else if (typeof globalThis.Promise === 'function') {\n const resolved = globalThis.Promise.resolve();\n /* v8 ignore start */\n return (fn) => {\n // Schedule as a microtask, and surface exceptions like queueMicrotask would.\n resolved.then(fn).catch((err) => {\n setTimeout(() => {\n throw err;\n }, 0);\n });\n };\n } else {\n // Fallback to macrotask when microtasks aren't available.\n return (fn) => {\n setTimeout(fn, 0);\n };\n }\n /* v8 ignore stop */\n})();\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const noop: (...args: unknown[]) => unknown;
|
|
2
|
+
export declare function isEmptyObject(obj?: object): obj is Record<string, never>;
|
|
3
|
+
export declare function maybePromise<T>(value: unknown): value is Promise<T>;
|
|
4
|
+
export declare function getDisplayName(type: {
|
|
5
|
+
displayName?: string | undefined;
|
|
6
|
+
name: string;
|
|
7
|
+
}): string;
|
|
8
|
+
export declare function hook<T, K extends keyof T>(object: T, key: K, fn: Required<T>[K] extends (...args: infer P) => infer Q ? ((old?: T[K], ...args: P) => Q) : never): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
/* v8 ignore start */
|
|
5
|
+
export const noop = () => { };
|
|
6
|
+
/* v8 ignore stop */
|
|
7
|
+
export function isEmptyObject(obj) {
|
|
8
|
+
for (const _ in obj)
|
|
9
|
+
return false;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
export function maybePromise(value) {
|
|
13
|
+
return (typeof value === 'object'
|
|
14
|
+
&& value !== null
|
|
15
|
+
// @ts-expect-error the check is safe
|
|
16
|
+
&& typeof value.then === 'function');
|
|
17
|
+
}
|
|
18
|
+
export function getDisplayName(type) {
|
|
19
|
+
return type.displayName ?? type.name;
|
|
20
|
+
}
|
|
21
|
+
export function hook(object, key, fn) {
|
|
22
|
+
const oldFn = object[key];
|
|
23
|
+
object[key] = function (...args) {
|
|
24
|
+
return fn.call(this, oldFn, ...args);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/shared/utils.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,qBAAqB;AACrB,MAAM,CAAC,MAAM,IAAI,GAAoC,GAAG,EAAE,GAAE,CAAC,CAAC;AAC9D,oBAAoB;AAEpB,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,KAAK,MAAM,CAAC,IAAI,GAAG;QAAE,OAAO,KAAK,CAAC;IAClC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,YAAY,CAAI,KAAc;IAC5C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;WACtB,KAAK,KAAK,IAAI;QACjB,qCAAqC;WAClC,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CACpC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAwD;IACrF,OAAO,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,IAAI,CAClB,MAAS,EACT,GAAM,EACN,EACS;IAET,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,CAAC,GAAG,UAAkB,GAAG,IAAe;QAChD,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;IACvC,CAAS,CAAC;AACZ,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\n/* v8 ignore start */\nexport const noop: (...args: unknown[]) => unknown = () => {};\n/* v8 ignore stop */\n\nexport function isEmptyObject(obj?: object): obj is Record<string, never> {\n for (const _ in obj) return false;\n return true;\n}\n\nexport function maybePromise<T>(value: unknown): value is Promise<T> {\n return (\n typeof value === 'object'\n && value !== null\n // @ts-expect-error the check is safe\n && typeof value.then === 'function'\n );\n}\n\nexport function getDisplayName(type: { displayName?: string | undefined; name: string }): string {\n return type.displayName ?? type.name;\n}\n\nexport function hook<T, K extends keyof T>(\n object: T,\n key: K,\n fn: Required<T>[K] extends (...args: infer P) => infer Q ? ((old?: T[K], ...args: P) => Q)\n : never,\n): void {\n const oldFn = object[key];\n object[key] = function(this: T, ...args: unknown[]) {\n return fn.call(this, oldFn, ...args);\n } as T[K];\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
export function isSdkVersionGt(major, minor) {
|
|
5
|
+
// Worklet initialization can run before ReactLynx installs the global alias.
|
|
6
|
+
const lynxSdkVersion = globalThis.SystemInfo?.lynxSdkVersion
|
|
7
|
+
?? lynx.SystemInfo?.lynxSdkVersion
|
|
8
|
+
?? '1.0';
|
|
9
|
+
const version = lynxSdkVersion.split('.');
|
|
10
|
+
return Number(version[0]) > major || (Number(version[0]) == major && Number(version[1]) > minor);
|
|
11
|
+
}
|
|
12
|
+
export function isRunOnBackgroundEnabled() {
|
|
13
|
+
return isSdkVersionGt(2, 15);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,KAAa;IACzD,6EAA6E;IAC7E,MAAM,cAAc,GAAI,UAA+D,CAAC,UAAU,EAAE,cAAc;WAC5G,IAAmD,CAAC,UAAU,EAAE,cAAc;WAC/E,KAAK,CAAC;IACX,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;AACnG,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/B,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\nexport function isSdkVersionGt(major: number, minor: number): boolean {\n // Worklet initialization can run before ReactLynx installs the global alias.\n const lynxSdkVersion = (globalThis as typeof globalThis & { SystemInfo?: ISystemInfo }).SystemInfo?.lynxSdkVersion\n ?? (lynx as typeof lynx & { SystemInfo?: ISystemInfo }).SystemInfo?.lynxSdkVersion\n ?? '1.0';\n const version = lynxSdkVersion.split('.');\n return Number(version[0]) > major || (Number(version[0]) == major && Number(version[1]) > minor);\n}\n\nexport function isRunOnBackgroundEnabled(): boolean {\n return isSdkVersionGt(2, 15);\n}\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { options } from 'preact';
|
|
5
5
|
import { DIFFED, DOM } from '../../shared/render-constants.js';
|
|
6
|
-
import { getDisplayName } from '../../utils.js';
|
|
6
|
+
import { getDisplayName } from '../../shared/utils.js';
|
|
7
7
|
export function initRenderAlog() {
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
9
9
|
const oldAfterDiff = options[DIFFED];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/snapshot/alog/render.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/snapshot/alog/render.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD,MAAM,UAAU,cAAc;IAC5B,6DAA6D;IAC7D,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,OAAO,CAAC,MAAM,CAAC,GAAG,UAAS,KAA0C;QACnE,8BAA8B;QAC9B,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACrC,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,kBAAkB,CAAC;YACvE,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,IAAsB,CAAC,CAAC;YACjE,qCAAqC;YACrC,IAAI,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe,EAAE,CAAC;gBAC9D,OAAO,CAAC,IAAI,EAAE,CACZ,IAAI,UAAU,4BAA4B,WAAW,EAAE,CACxD,CAAC;YACJ,CAAC;iBAAM,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,cAAc,EAAE,CAAC;gBACnE,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;gBACvB,OAAO,CAAC,IAAI,EAAE,CACZ,IAAI,UAAU,4BAA4B,WAAW,aAAa,GAAG,EAAE,IAAI,WAAW,GAAG,EAAE,IAAI,EAAE,CAClG,CAAC;YACJ,CAAC;QACH,CAAC;QACD,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC,CAAC;AACJ,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.\nimport { options } from 'preact';\nimport type { ComponentClass, VNode } from 'preact';\n\nimport { DIFFED, DOM } from '../../shared/render-constants.js';\nimport { getDisplayName } from '../../shared/utils.js';\nimport type { SnapshotInstance } from '../snapshot/snapshot.js';\n\nexport function initRenderAlog(): void {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldAfterDiff = options[DIFFED];\n options[DIFFED] = function(vnode: VNode & { [DOM]: SnapshotInstance }) {\n // Only log on component vnode\n if (typeof vnode.type === 'function') {\n const threadName = __MAIN_THREAD__ ? 'MainThread' : 'BackgroundThread';\n const displayName = getDisplayName(vnode.type as ComponentClass);\n // log the component render into Alog\n if (typeof __MAIN_THREAD__ !== 'undefined' && __MAIN_THREAD__) {\n console.alog?.(\n `[${threadName} Component Render] name: ${displayName}`,\n );\n } else if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const dom = vnode[DOM];\n console.alog?.(\n `[${threadName} Component Render] name: ${displayName}, uniqID: ${dom?.type}, __id: ${dom?.__id}`,\n );\n }\n }\n oldAfterDiff?.(vnode);\n };\n}\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { Component, options } from 'preact';
|
|
5
5
|
import { BITS, COMMIT, COMPONENT, COMPONENT_DIRTY, DIFF, DIFF2, DIFFED, HOOKS, LIST, NEXT_STATE, NEXT_VALUE, RENDER, VALUE, VNODE, } from '../../shared/render-constants.js';
|
|
6
|
-
import { getDisplayName } from '../../utils.js';
|
|
6
|
+
import { getDisplayName } from '../../shared/utils.js';
|
|
7
7
|
import { globalPatchOptions } from '../lifecycle/patch/commit.js';
|
|
8
8
|
import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';
|
|
9
9
|
const format = (val) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profileHooks.js","sourceRoot":"","sources":["../../../src/snapshot/debug/profileHooks.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAK5C,OAAO,EACL,IAAI,EACJ,MAAM,EACN,SAAS,EACT,eAAe,EACf,IAAI,EACJ,KAAK,EACL,MAAM,EACN,KAAK,EACL,IAAI,EACJ,UAAU,EACV,UAAU,EACV,MAAM,EACN,KAAK,EACL,KAAK,GACN,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,g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AY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;QAI5C,6DAA6D;QAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAmB,EAAE,EAAE;YACtC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,qBAAqB,EAAE,CAAC;gBAC9D,KAAK,CAAC,YAAY,CAAC,GAAG,qBAAqB,CAAC,MAAM,CAAC;YACrD,CAAC;YACD,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC,CAAC;QAEF,6DAA6D;QAC7D,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QACvC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,KAAmB,EAAE,EAAE;YACxC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACrC,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;gBACxC,OAAO,KAAK,CAAC,YAAY,CAAC,CAAC;gBAC3B,IAAI,qBAAqB,IAAI,WAAW,KAAK,qBAAqB,CAAC,MAAM,EAAE,CAAC;oBAC1E,2CAA2C;oBAC3C,WAAW,CAAC,8BAA8B,EAAE;wBAC1C,IAAI,EAAE;4BACJ,aAAa,EAAE,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,IAAsB,CAAC;yBAC9E;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC;AACH,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.\nimport { Component, options } from 'preact';\nimport type { ComponentClass, ComponentType, VNode } from 'preact';\n\nimport type { TraceOption } from '@lynx-js/types';\n\nimport {\n BITS,\n COMMIT,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DIFF2,\n DIFFED,\n HOOKS,\n LIST,\n NEXT_STATE,\n NEXT_VALUE,\n RENDER,\n VALUE,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { getDisplayName } from '../../utils.js';\nimport { globalPatchOptions } from '../lifecycle/patch/commit.js';\nimport { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';\n\nconst format = (val: unknown) => {\n if (typeof val === 'function') {\n return val.toString();\n }\n return val;\n};\n\nfunction safeJsonStringify(val: unknown) {\n const seen = new WeakSet<object>();\n\n return JSON.stringify(val, function(_key, value: unknown) {\n if (typeof value === 'object' && value !== null) {\n if (seen.has(value)) {\n return '[Unserializable: Circular]';\n }\n seen.add(value);\n }\n\n return value;\n });\n}\n\nfunction buildSetStateProfileMarkArgs(\n type: string | ComponentType | undefined,\n currentState: unknown,\n nextState: unknown,\n): Record<string, string> {\n const EMPTY_OBJ = {};\n\n const currentStateObj = (currentState ?? EMPTY_OBJ) as Record<string, unknown>;\n const nextStateObj = (nextState ?? EMPTY_OBJ) as Record<string, unknown>;\n\n return {\n componentName: (type && typeof type === 'function')\n ? getDisplayName(type as ComponentClass)\n : 'Unknown',\n 'current state keys': JSON.stringify(Object.keys(currentStateObj)),\n 'next state keys': JSON.stringify(Object.keys(nextStateObj)),\n 'changed (shallow diff) state keys': JSON.stringify(\n // the setState is in assign manner, we assume nextState is a superset of currentState\n Object.keys(nextStateObj).filter(\n key => currentStateObj[key] !== nextStateObj[key],\n ),\n ),\n currentValue: safeJsonStringify(format(currentState)),\n nextValue: safeJsonStringify(format(nextState)),\n };\n}\n\nexport function initProfileHook(): void {\n // early-exit if required profiling APIs are unavailable\n let p;\n /* v8 ignore start */\n if (\n !(p = lynx.performance)\n || typeof p.profileStart !== 'function'\n || typeof p.profileEnd !== 'function'\n || typeof p.profileMark !== 'function'\n || typeof p.profileFlowId !== 'function'\n ) {\n return;\n }\n /* v8 ignore stop */\n\n const profileStart = p.profileStart.bind(p);\n const profileEnd = p.profileEnd.bind(p);\n const profileMark = p.profileMark.bind(p);\n const profileFlowId = p.profileFlowId.bind(p);\n\n // for each setState call, we will add a profiling trace and\n // attach a flowId to the component instance.\n // This allows us to trace the flow of its diffing, committing and patching.\n {\n const sFlowID = Symbol('FLOW_ID');\n type PatchedComponent = Component & { [sFlowID]?: number };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldSetState = Component.prototype.setState;\n Component.prototype.setState = function(this: PatchedComponent & { [NEXT_STATE]: unknown }, state, callback) {\n oldSetState?.call(this, state, callback);\n\n if (this[BITS] & COMPONENT_DIRTY) {\n const type = this[VNODE]!.type;\n const isClassComponent = typeof type === 'function' && ('prototype' in type)\n && ('render' in type.prototype);\n\n if (isClassComponent) {\n profileMark('ReactLynx::setState', {\n flowId: this[sFlowID] ??= profileFlowId(),\n args: buildSetStateProfileMarkArgs(\n type,\n this.state,\n this[NEXT_STATE],\n ),\n });\n }\n }\n };\n }\n\n // These hot callbacks have fixed signatures; avoid collecting and spreading\n // an argument array for every host and component visited.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff2 = options[DIFF2];\n options[DIFF2] = (vnode, oldVNode) => {\n // We only add profiling trace for Component\n if (typeof vnode.type === 'function') {\n const profileOptions: TraceOption = {};\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const c: PatchedComponent = oldVNode[COMPONENT]!;\n if (c) {\n const flowId = c[sFlowID];\n delete c[sFlowID];\n if (flowId) {\n globalPatchOptions.flowIds ??= [];\n globalPatchOptions.flowIds.push(flowId);\n profileOptions.flowId = flowId;\n }\n }\n }\n\n profileStart(\n `ReactLynx::diff::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`,\n profileOptions,\n );\n }\n oldDiff2?.(vnode, oldVNode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiffed = options[DIFFED];\n options[DIFFED] = vnode => {\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const hooks = vnode[COMPONENT]?.[HOOKS];\n const hookList = hooks?.[LIST];\n\n if (Array.isArray(hookList)) {\n hookList.forEach((hookState, hookIdx: number) => {\n hookState['internalNextValue'] = hookState[NEXT_VALUE];\n // define a setter for __N to track the next value of the hook\n Object.defineProperty(hookState, NEXT_VALUE, {\n get: () => hookState['internalNextValue'],\n set: (value) => {\n if (Array.isArray(value)) {\n // hookState[VALUE] is [state, dispatch]\n const currentValueTuple = hookState[VALUE] as unknown[];\n const currentValue = currentValueTuple[0];\n const [nextValue] = value as unknown[];\n\n const component = hookState[COMPONENT] as PatchedComponent | undefined;\n if (!component) {\n hookState['internalNextValue'] = value;\n return;\n }\n\n const type = component[VNODE]!.type;\n const flowId = component[sFlowID] ??= profileFlowId();\n\n profileMark('ReactLynx::hooks::setState', {\n flowId,\n args: {\n hookIdx: String(hookIdx),\n ...buildSetStateProfileMarkArgs(\n type,\n currentValue,\n nextValue,\n ),\n },\n });\n }\n hookState['internalNextValue'] = value;\n },\n configurable: true,\n });\n });\n }\n }\n\n if (typeof vnode.type === 'function') {\n profileEnd(); // for options[DIFF2]\n }\n oldDiffed?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldCommit = options[COMMIT];\n options[COMMIT] = (vnode, commitQueue) => {\n profileStart('ReactLynx::commit', {\n ...globalPatchOptions.flowIds\n ? {\n flowId: globalPatchOptions.flowIds[0],\n flowIds: globalPatchOptions.flowIds,\n }\n : {},\n });\n oldCommit?.(vnode, commitQueue);\n profileEnd();\n };\n }\n }\n\n // Profile the user-provided `render`.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldRender = options[RENDER];\n options[RENDER] = (vnode: VNode) => {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalRender = vnode[COMPONENT]!.render;\n vnode[COMPONENT]!.render = function render(this, props, state, context) {\n profileStart(`ReactLynx::render::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`);\n try {\n return originalRender.call(this, props, state, context);\n } finally {\n profileEnd();\n vnode[COMPONENT]!.render = originalRender;\n }\n };\n oldRender?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const sPatchLength = Symbol('PATCH_LENGTH');\n\n type PatchedVNode = VNode & { [sPatchLength]?: number };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff = options[DIFF];\n options[DIFF] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function' && __globalSnapshotPatch) {\n vnode[sPatchLength] = __globalSnapshotPatch.length;\n }\n oldDiff?.(vnode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldPatchDiffed = options[DIFFED];\n options[DIFFED] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function') {\n const patchLength = vnode[sPatchLength];\n delete vnode[sPatchLength];\n if (__globalSnapshotPatch && patchLength === __globalSnapshotPatch.length) {\n // \"NoPatch\" is a conventional name in Lynx\n profileMark('ReactLynx::diffFinishNoPatch', {\n args: {\n componentName: /* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass),\n },\n });\n }\n }\n oldPatchDiffed?.(vnode);\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profileHooks.js","sourceRoot":"","sources":["../../../src/snapshot/debug/profileHooks.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAK5C,OAAO,EACL,IAAI,EACJ,MAAM,EACN,SAAS,EACT,eAAe,EACf,IAAI,EACJ,KAAK,EACL,MAAM,EACN,KAAK,EACL,IAAI,EACJ,UAAU,EACV,UAAU,EACV,MAAM,EACN,KAAK,EACL,KAAK,GACN,MAAM,kCAAkC,CAAC;AAC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,cAAc,EAAE,CAAC;QAC5D,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;QAI5C,6DAA6D;QAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAmB,EAAE,EAAE;YACtC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,qBAAqB,EAAE,CAAC;gBAC9D,KAAK,CAAC,YAAY,CAAC,GAAG,qBAAqB,CAAC,MAAM,CAAC;YACrD,CAAC;YACD,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC,CAAC;QAEF,6DAA6D;QAC7D,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QACvC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,KAAmB,EAAE,EAAE;YACxC,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACrC,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;gBACxC,OAAO,KAAK,CAAC,YAAY,CAAC,CAAC;gBAC3B,IAAI,qBAAqB,IAAI,WAAW,KAAK,qBAAqB,CAAC,MAAM,EAAE,CAAC;oBAC1E,2CAA2C;oBAC3C,WAAW,CAAC,8BAA8B,EAAE;wBAC1C,IAAI,EAAE;4BACJ,aAAa,EAAE,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,IAAsB,CAAC;yBAC9E;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC;AACH,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.\nimport { Component, options } from 'preact';\nimport type { ComponentClass, ComponentType, VNode } from 'preact';\n\nimport type { TraceOption } from '@lynx-js/types';\n\nimport {\n BITS,\n COMMIT,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DIFF2,\n DIFFED,\n HOOKS,\n LIST,\n NEXT_STATE,\n NEXT_VALUE,\n RENDER,\n VALUE,\n VNODE,\n} from '../../shared/render-constants.js';\nimport { getDisplayName } from '../../shared/utils.js';\nimport { globalPatchOptions } from '../lifecycle/patch/commit.js';\nimport { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';\n\nconst format = (val: unknown) => {\n if (typeof val === 'function') {\n return val.toString();\n }\n return val;\n};\n\nfunction safeJsonStringify(val: unknown) {\n const seen = new WeakSet<object>();\n\n return JSON.stringify(val, function(_key, value: unknown) {\n if (typeof value === 'object' && value !== null) {\n if (seen.has(value)) {\n return '[Unserializable: Circular]';\n }\n seen.add(value);\n }\n\n return value;\n });\n}\n\nfunction buildSetStateProfileMarkArgs(\n type: string | ComponentType | undefined,\n currentState: unknown,\n nextState: unknown,\n): Record<string, string> {\n const EMPTY_OBJ = {};\n\n const currentStateObj = (currentState ?? EMPTY_OBJ) as Record<string, unknown>;\n const nextStateObj = (nextState ?? EMPTY_OBJ) as Record<string, unknown>;\n\n return {\n componentName: (type && typeof type === 'function')\n ? getDisplayName(type as ComponentClass)\n : 'Unknown',\n 'current state keys': JSON.stringify(Object.keys(currentStateObj)),\n 'next state keys': JSON.stringify(Object.keys(nextStateObj)),\n 'changed (shallow diff) state keys': JSON.stringify(\n // the setState is in assign manner, we assume nextState is a superset of currentState\n Object.keys(nextStateObj).filter(\n key => currentStateObj[key] !== nextStateObj[key],\n ),\n ),\n currentValue: safeJsonStringify(format(currentState)),\n nextValue: safeJsonStringify(format(nextState)),\n };\n}\n\nexport function initProfileHook(): void {\n // early-exit if required profiling APIs are unavailable\n let p;\n /* v8 ignore start */\n if (\n !(p = lynx.performance)\n || typeof p.profileStart !== 'function'\n || typeof p.profileEnd !== 'function'\n || typeof p.profileMark !== 'function'\n || typeof p.profileFlowId !== 'function'\n ) {\n return;\n }\n /* v8 ignore stop */\n\n const profileStart = p.profileStart.bind(p);\n const profileEnd = p.profileEnd.bind(p);\n const profileMark = p.profileMark.bind(p);\n const profileFlowId = p.profileFlowId.bind(p);\n\n // for each setState call, we will add a profiling trace and\n // attach a flowId to the component instance.\n // This allows us to trace the flow of its diffing, committing and patching.\n {\n const sFlowID = Symbol('FLOW_ID');\n type PatchedComponent = Component & { [sFlowID]?: number };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldSetState = Component.prototype.setState;\n Component.prototype.setState = function(this: PatchedComponent & { [NEXT_STATE]: unknown }, state, callback) {\n oldSetState?.call(this, state, callback);\n\n if (this[BITS] & COMPONENT_DIRTY) {\n const type = this[VNODE]!.type;\n const isClassComponent = typeof type === 'function' && ('prototype' in type)\n && ('render' in type.prototype);\n\n if (isClassComponent) {\n profileMark('ReactLynx::setState', {\n flowId: this[sFlowID] ??= profileFlowId(),\n args: buildSetStateProfileMarkArgs(\n type,\n this.state,\n this[NEXT_STATE],\n ),\n });\n }\n }\n };\n }\n\n // These hot callbacks have fixed signatures; avoid collecting and spreading\n // an argument array for every host and component visited.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff2 = options[DIFF2];\n options[DIFF2] = (vnode, oldVNode) => {\n // We only add profiling trace for Component\n if (typeof vnode.type === 'function') {\n const profileOptions: TraceOption = {};\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const c: PatchedComponent = oldVNode[COMPONENT]!;\n if (c) {\n const flowId = c[sFlowID];\n delete c[sFlowID];\n if (flowId) {\n globalPatchOptions.flowIds ??= [];\n globalPatchOptions.flowIds.push(flowId);\n profileOptions.flowId = flowId;\n }\n }\n }\n\n profileStart(\n `ReactLynx::diff::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`,\n profileOptions,\n );\n }\n oldDiff2?.(vnode, oldVNode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiffed = options[DIFFED];\n options[DIFFED] = vnode => {\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const hooks = vnode[COMPONENT]?.[HOOKS];\n const hookList = hooks?.[LIST];\n\n if (Array.isArray(hookList)) {\n hookList.forEach((hookState, hookIdx: number) => {\n hookState['internalNextValue'] = hookState[NEXT_VALUE];\n // define a setter for __N to track the next value of the hook\n Object.defineProperty(hookState, NEXT_VALUE, {\n get: () => hookState['internalNextValue'],\n set: (value) => {\n if (Array.isArray(value)) {\n // hookState[VALUE] is [state, dispatch]\n const currentValueTuple = hookState[VALUE] as unknown[];\n const currentValue = currentValueTuple[0];\n const [nextValue] = value as unknown[];\n\n const component = hookState[COMPONENT] as PatchedComponent | undefined;\n if (!component) {\n hookState['internalNextValue'] = value;\n return;\n }\n\n const type = component[VNODE]!.type;\n const flowId = component[sFlowID] ??= profileFlowId();\n\n profileMark('ReactLynx::hooks::setState', {\n flowId,\n args: {\n hookIdx: String(hookIdx),\n ...buildSetStateProfileMarkArgs(\n type,\n currentValue,\n nextValue,\n ),\n },\n });\n }\n hookState['internalNextValue'] = value;\n },\n configurable: true,\n });\n });\n }\n }\n\n if (typeof vnode.type === 'function') {\n profileEnd(); // for options[DIFF2]\n }\n oldDiffed?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldCommit = options[COMMIT];\n options[COMMIT] = (vnode, commitQueue) => {\n profileStart('ReactLynx::commit', {\n ...globalPatchOptions.flowIds\n ? {\n flowId: globalPatchOptions.flowIds[0],\n flowIds: globalPatchOptions.flowIds,\n }\n : {},\n });\n oldCommit?.(vnode, commitQueue);\n profileEnd();\n };\n }\n }\n\n // Profile the user-provided `render`.\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldRender = options[RENDER];\n options[RENDER] = (vnode: VNode) => {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalRender = vnode[COMPONENT]!.render;\n vnode[COMPONENT]!.render = function render(this, props, state, context) {\n profileStart(`ReactLynx::render::${/* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass)}`);\n try {\n return originalRender.call(this, props, state, context);\n } finally {\n profileEnd();\n vnode[COMPONENT]!.render = originalRender;\n }\n };\n oldRender?.(vnode);\n };\n\n if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {\n const sPatchLength = Symbol('PATCH_LENGTH');\n\n type PatchedVNode = VNode & { [sPatchLength]?: number };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldDiff = options[DIFF];\n options[DIFF] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function' && __globalSnapshotPatch) {\n vnode[sPatchLength] = __globalSnapshotPatch.length;\n }\n oldDiff?.(vnode);\n };\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const oldPatchDiffed = options[DIFFED];\n options[DIFFED] = (vnode: PatchedVNode) => {\n if (typeof vnode.type === 'function') {\n const patchLength = vnode[sPatchLength];\n delete vnode[sPatchLength];\n if (__globalSnapshotPatch && patchLength === __globalSnapshotPatch.length) {\n // \"NoPatch\" is a conventional name in Lynx\n profileMark('ReactLynx::diffFinishNoPatch', {\n args: {\n componentName: /* #__INLINE__ */ getDisplayName(vnode.type as ComponentClass),\n },\n });\n }\n }\n oldPatchDiffed?.(vnode);\n };\n }\n}\n"]}
|
|
@@ -2,14 +2,14 @@
|
|
|
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 { render } from 'preact';
|
|
5
|
-
import { __root } from '../../root.js';
|
|
6
5
|
import { delayedEvents } from './event/delayEvents.js';
|
|
7
6
|
import { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';
|
|
8
7
|
import { globalCommitTaskMap } from './patch/commit.js';
|
|
9
8
|
import { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';
|
|
10
9
|
import { delayedUiOps } from './ref/delay.js';
|
|
10
|
+
import { withSyncEffectFlush } from '../../core/sync-effect-flush.js';
|
|
11
|
+
import { __root } from '../../root.js';
|
|
11
12
|
import { profileEnd, profileStart } from '../../shared/profile.js';
|
|
12
|
-
import { withSyncEffectFlush } from '../../utils.js';
|
|
13
13
|
import { resetSnapshotMainThreadFunctionRuntime } from '../worklet/call/runOnMainThread.js';
|
|
14
14
|
import { resetSnapshotBackgroundFunctionRuntime } from '../worklet/ctx.js';
|
|
15
15
|
function destroyBackground() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,sCAAsC,EAAE,MAAM,oCAAoC,CAAC;AAC5F,OAAO,EAAE,sCAAsC,EAAE,MAAM,mBAAmB,CAAC;AAE3E,SAAS,iBAAiB;IACxB,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;QACtD,YAAY,CAAC,8BAA8B,CAAC,CAAC;IAC/C,CAAC;IAED,yBAAyB,EAAE,CAAC;IAE5B,IAAI,CAAC;QACH,mBAAmB,CAAC,GAAG,EAAE;YACvB,iEAAiE;YACjE,MAAM,CAAC,IAAI,EAAE,MAAa,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACjC,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,mBAAmB,CAAC,KAAK,EAAE,CAAC;QAC5B,qEAAqE;QACrE,0DAA0D;QAC1D,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;QAClC,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;QACxB,sCAAsC,EAAE,CAAC;QACzC,sCAAsC,EAAE,CAAC;QACzC,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC;AACH,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,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.\nimport { render } from 'preact';\n\nimport { delayedEvents } from './event/delayEvents.js';\nimport { delayedLifecycleEvents } from './event/delayLifecycleEvents.js';\nimport { globalCommitTaskMap } from './patch/commit.js';\nimport { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';\nimport { delayedUiOps } from './ref/delay.js';\nimport { withSyncEffectFlush } from '../../core/sync-effect-flush.js';\nimport { __root } from '../../root.js';\nimport { profileEnd, profileStart } from '../../shared/profile.js';\nimport { resetSnapshotMainThreadFunctionRuntime } from '../worklet/call/runOnMainThread.js';\nimport { resetSnapshotBackgroundFunctionRuntime } from '../worklet/ctx.js';\n\nfunction destroyBackground(): void {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('ReactLynx::destroyBackground');\n }\n\n deinitGlobalSnapshotPatch();\n\n try {\n withSyncEffectFlush(() => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n render(null, __root as any);\n });\n\n globalCommitTaskMap.forEach(task => {\n task();\n });\n } finally {\n globalCommitTaskMap.clear();\n // Clear delayed events which should not be executed after destroyed.\n // This is important when the page is performing a reload.\n delayedLifecycleEvents.length = 0;\n if (delayedEvents) {\n delayedEvents.length = 0;\n }\n delayedUiOps.length = 0;\n resetSnapshotBackgroundFunctionRuntime();\n resetSnapshotMainThreadFunctionRuntime();\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n }\n}\n\nexport { destroyBackground };\n"]}
|
|
@@ -2,8 +2,9 @@
|
|
|
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 { options } from 'preact';
|
|
5
|
+
import { lynxQueueMicrotask } from '../../shared/microtask.js';
|
|
5
6
|
import { RENDER_COMPONENT, ROOT } from '../../shared/render-constants.js';
|
|
6
|
-
import { hook
|
|
7
|
+
import { hook } from '../../shared/utils.js';
|
|
7
8
|
export const isRendering = /* @__PURE__ */ { value: false };
|
|
8
9
|
const setIsRendering = () => {
|
|
9
10
|
isRendering.value = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isRendering.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/isRendering.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"isRendering.js","sourceRoot":"","sources":["../../../src/snapshot/lifecycle/isRendering.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAE5D,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,WAAW,CAAC,KAAK,GAAG,IAAI,CAAC;IACzB,sFAAsF;IACtF,kBAAkB,CAAC,GAAG,EAAE;QACtB,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAsB,GAAuC,EAAE,GAAG,IAAO,EAAE,EAAE;IAChG,oBAAoB;IACpB,IAAI,GAAG;QAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IACtB,cAAc,EAAE,CAAC;AACnB,CAAC,CAAC;AAEF,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC;AAC9C,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,CAAC,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\nimport { options } from 'preact';\n\nimport { lynxQueueMicrotask } from '../../shared/microtask.js';\nimport { RENDER_COMPONENT, ROOT } from '../../shared/render-constants.js';\nimport { hook } from '../../shared/utils.js';\n\nexport const isRendering = /* @__PURE__ */ { value: false };\n\nconst setIsRendering = () => {\n isRendering.value = true;\n // Make sure `isRendering` is set to false even if an error is thrown during rendering\n lynxQueueMicrotask(() => {\n isRendering.value = false;\n });\n};\n\nconst onRenderHook = <T extends unknown[]>(old: ((...args: T) => void) | undefined, ...args: T) => {\n /* v8 ignore next */\n if (old) old(...args);\n setIsRendering();\n};\n\nhook(options, RENDER_COMPONENT, onRenderHook);\nhook(options, ROOT, onRenderHook);\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { VNode } from 'preact';
|
|
1
2
|
import type { RunWorkletCtxData } from '@lynx-js/react/worklet-runtime/bindings';
|
|
2
3
|
import { globalBackgroundSnapshotInstancesToRemove } from './globalState.js';
|
|
3
4
|
import type { SnapshotPatch } from './snapshotPatch.js';
|
|
@@ -31,11 +32,15 @@ interface PatchOptions {
|
|
|
31
32
|
*/
|
|
32
33
|
export type GlobalPatchOptions = Omit<PatchOptions, 'reloadVersion'>;
|
|
33
34
|
export declare let globalPatchOptions: GlobalPatchOptions;
|
|
35
|
+
/**
|
|
36
|
+
* Delivers a collected commit and calls `finish` once it has been applied.
|
|
37
|
+
*/
|
|
38
|
+
type CommitTransport = (vnode: VNode, patchList: PatchList, patchOptions: GlobalPatchOptions, finish: () => void) => void;
|
|
34
39
|
/**
|
|
35
40
|
* Replaces Preact's default commit hook with our custom implementation.
|
|
36
|
-
* Calling it again
|
|
41
|
+
* Calling it again only replaces the transport until {@link removeCommitHookForTesting} is called.
|
|
37
42
|
*/
|
|
38
|
-
declare function replaceCommitHook(): void;
|
|
43
|
+
declare function replaceCommitHook(transport?: CommitTransport): void;
|
|
39
44
|
/**
|
|
40
45
|
* Restores the commit option replaced by {@link replaceCommitHook} so tests
|
|
41
46
|
* can clean up the global Preact `options` object. Assumes the matching
|
|
@@ -25,7 +25,7 @@ import { getReloadVersion } from '../../../core/reload-version.js';
|
|
|
25
25
|
import { delayedRunOnMainThreadData, takeDelayedRunOnMainThreadData, } from '../../../core/thread-function-call/main-thread.js';
|
|
26
26
|
import { profileEnd, profileStart } from '../../../shared/profile.js';
|
|
27
27
|
import { COMMIT } from '../../../shared/render-constants.js';
|
|
28
|
-
import { hook, isEmptyObject } from '../../../utils.js';
|
|
28
|
+
import { hook, isEmptyObject } from '../../../shared/utils.js';
|
|
29
29
|
import { LifecycleConstant } from '../../lifecycle/constant.js';
|
|
30
30
|
import { backgroundSnapshotInstanceManager } from '../../snapshot/backgroundSnapshot.js';
|
|
31
31
|
import { applyQueuedRefs } from '../../snapshot/ref.js';
|
|
@@ -39,13 +39,19 @@ function takeGlobalPatchOptions() {
|
|
|
39
39
|
globalPatchOptions = {};
|
|
40
40
|
return res;
|
|
41
41
|
}
|
|
42
|
+
const nativeTransport = (_vnode, patchList, patchOptions, finish) => {
|
|
43
|
+
// Send the update to the native layer
|
|
44
|
+
lynx.getNativeApp().callLepusMethod(LifecycleConstant.patchUpdate, commitPatchUpdate(patchList, patchOptions), finish);
|
|
45
|
+
};
|
|
42
46
|
let commitHookInstalled = false;
|
|
43
47
|
let previousCommit;
|
|
48
|
+
let commitTransport = nativeTransport;
|
|
44
49
|
/**
|
|
45
50
|
* Replaces Preact's default commit hook with our custom implementation.
|
|
46
|
-
* Calling it again
|
|
51
|
+
* Calling it again only replaces the transport until {@link removeCommitHookForTesting} is called.
|
|
47
52
|
*/
|
|
48
|
-
function replaceCommitHook() {
|
|
53
|
+
function replaceCommitHook(transport = nativeTransport) {
|
|
54
|
+
commitTransport = transport;
|
|
49
55
|
if (commitHookInstalled) {
|
|
50
56
|
return;
|
|
51
57
|
}
|
|
@@ -107,9 +113,7 @@ function replaceCommitHook() {
|
|
|
107
113
|
if (delayedRunOnMainThreadData.length) {
|
|
108
114
|
patchList.delayedRunOnMainThreadData = takeDelayedRunOnMainThreadData();
|
|
109
115
|
}
|
|
110
|
-
|
|
111
|
-
// Send the update to the native layer
|
|
112
|
-
lynx.getNativeApp().callLepusMethod(LifecycleConstant.patchUpdate, obj, () => {
|
|
116
|
+
commitTransport(vnode, patchList, patchOptions, () => {
|
|
113
117
|
const commitTask = globalCommitTaskMap.get(commitTaskId);
|
|
114
118
|
if (commitTask) {
|
|
115
119
|
commitTask();
|
|
@@ -132,6 +136,7 @@ function removeCommitHookForTesting() {
|
|
|
132
136
|
return;
|
|
133
137
|
}
|
|
134
138
|
commitHookInstalled = false;
|
|
139
|
+
commitTransport = nativeTransport;
|
|
135
140
|
if (previousCommit) {
|
|
136
141
|
options[COMMIT] = previousCommit;
|
|
137
142
|
previousCommit = undefined;
|