@lynx-js/react 0.129.3 → 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 +16 -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/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/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/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/{worklet-runtime/utils → shared}/version.js +4 -2
- package/runtime/lib/shared/version.js.map +1 -0
- package/runtime/lib/snapshot/alog/render.js +1 -1
- package/runtime/lib/snapshot/alog/render.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js +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/{worklet-runtime/utils → shared}/version.ts +6 -4
- 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 +64 -64
- 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 +85 -85
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +213 -192
- 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.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/__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,13 +1,14 @@
|
|
|
1
1
|
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { MAIN_BUNDLE_URL_SENTINEL,
|
|
5
|
-
import { composeElementTemplateListAttributes, createElementTemplateListState, markElementTemplateListDestroyed,
|
|
4
|
+
import { MAIN_BUNDLE_URL_SENTINEL, parseElementTemplateType } from '../../protocol/template-type.js';
|
|
5
|
+
import { composeElementTemplateListAttributes, createElementTemplateListState, markElementTemplateListDestroyed, registerElementTemplateListState, } from '../list/list.js';
|
|
6
|
+
import { filterListItemPlatformInfoFromSpread } from '../list/platform-info.js';
|
|
6
7
|
import { __etAttrPlanMap, hasMainThreadRefAttrSlot } from '../template/attr-slot-plan.js';
|
|
7
8
|
import { createElementTemplateWithReservedHandle, createTypedElementTemplateWithReservedHandle, destroyElementTemplateId, getNextElementTemplateId, } from '../template/handle.js';
|
|
8
|
-
import {
|
|
9
|
+
import { initializeMainThreadDynamicAttrSlots } from '../template/main-thread-dynamic-attr-state.js';
|
|
10
|
+
import { prepareTypedListAttributes } from '../template/typed-attributes.js';
|
|
9
11
|
const TYPED_LIST_HOST_TYPE = 'list';
|
|
10
|
-
const EMPTY_LIST_ITEM_UIDS = [];
|
|
11
12
|
export function discardRenderedHostsSince(checkpoint) {
|
|
12
13
|
const end = getNextElementTemplateId();
|
|
13
14
|
// Synchronous first-screen creation allocates consecutive negative IDs.
|
|
@@ -17,14 +18,20 @@ export function discardRenderedHostsSince(checkpoint) {
|
|
|
17
18
|
destroyElementTemplateId(uid);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
export function createRenderedHost(handleId, type, attributes, childSlots,
|
|
21
|
+
export function createRenderedHost(handleId, type, attributes, childSlots, materializationHandles, listItemPlatformInfo, host, listItemSubtreeHandleIds) {
|
|
21
22
|
if (type === TYPED_LIST_HOST_TYPE) {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const preparedTypedAttributes = prepareTypedListAttributes(handleId, attributes);
|
|
24
|
+
const listState = createElementTemplateListState(listItemSubtreeHandleIds);
|
|
25
|
+
const attrsWithCallbacks = composeElementTemplateListAttributes(preparedTypedAttributes, listState);
|
|
26
|
+
const elementRef = createTypedElementTemplateWithReservedHandle(handleId, TYPED_LIST_HOST_TYPE, attrsWithCallbacks, childSlots ?? null, {});
|
|
27
|
+
if (elementRef) {
|
|
28
|
+
initializeMainThreadDynamicAttrSlots(handleId, TYPED_LIST_HOST_TYPE, [preparedTypedAttributes]);
|
|
29
|
+
registerElementTemplateListState(handleId, listState, elementRef);
|
|
30
|
+
materializationHandles.push({
|
|
31
|
+
uid: handleId,
|
|
32
|
+
ref: elementRef,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
28
35
|
return elementRef;
|
|
29
36
|
}
|
|
30
37
|
const plain = host?.plain === true;
|
|
@@ -44,22 +51,18 @@ export function createRenderedHost(handleId, type, attributes, childSlots, listI
|
|
|
44
51
|
const templateKey = identity.templateKey;
|
|
45
52
|
const bundleUrl = identity.bundleUrl === MAIN_BUNDLE_URL_SENTINEL ? null : identity.bundleUrl;
|
|
46
53
|
const hasMainThreadRef = !plain && /* #__NOINLINE__ */ hasMainThreadRefAttrSlot(type);
|
|
47
|
-
const elementRef = createElementTemplateWithReservedHandle(handleId, templateKey, bundleUrl, preparedAttributeSlots, childSlots ?? null, !plain
|
|
54
|
+
const elementRef = createElementTemplateWithReservedHandle(handleId, templateKey, bundleUrl, preparedAttributeSlots, childSlots ?? null, !plain,
|
|
55
|
+
// Pass List item platform info through native ET options during initial
|
|
56
|
+
// rendering.
|
|
57
|
+
listItemPlatformInfo === undefined
|
|
58
|
+
? undefined
|
|
59
|
+
: { __listItemPlatformInfo: filterListItemPlatformInfoFromSpread(listItemPlatformInfo) });
|
|
48
60
|
if (hasMainThreadRef) {
|
|
49
61
|
materializationHandles.push({
|
|
50
62
|
uid: handleId,
|
|
51
63
|
ref: elementRef,
|
|
52
64
|
});
|
|
53
65
|
}
|
|
54
|
-
if (listItemPlatformInfo !== undefined) {
|
|
55
|
-
registerElementTemplateListItem(handleId, elementRef, {
|
|
56
|
-
// The native list identifies items by the same identity the template
|
|
57
|
-
// was registered under (sentinel stripped for the main card), so the
|
|
58
|
-
// update path (`resolveTypedListItem`) stays consistent with it.
|
|
59
|
-
templateKey: elementTemplateIdentityKey(templateKey, bundleUrl),
|
|
60
|
-
platformInfo: listItemPlatformInfo,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
66
|
return elementRef;
|
|
64
67
|
}
|
|
65
68
|
//# sourceMappingURL=create-rendered-host.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-rendered-host.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/create-rendered-host.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,
|
|
1
|
+
{"version":3,"file":"create-rendered-host.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/create-rendered-host.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAG1D,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAErG,OAAO,EACL,oCAAoC,EACpC,8BAA8B,EAC9B,gCAAgC,EAChC,gCAAgC,GACjC,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,oCAAoC,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE1F,OAAO,EACL,uCAAuC,EACvC,4CAA4C,EAC5C,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oCAAoC,EAAE,MAAM,+CAA+C,CAAC;AAErG,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAE7E,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAIpC,MAAM,UAAU,yBAAyB,CAAC,UAAkB;IAC1D,MAAM,GAAG,GAAG,wBAAwB,EAAE,CAAC;IACvC,wEAAwE;IACxE,2EAA2E;IAC3E,KAAK,IAAI,GAAG,GAAG,UAAU,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC;QAC5C,gCAAgC,CAAC,GAAG,CAAC,CAAC;QACtC,wBAAwB,CAA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License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport type { ElementTemplateHost } from './host.js';\nimport { MAIN_BUNDLE_URL_SENTINEL, parseElementTemplateType } from '../../protocol/template-type.js';\nimport type { RuntimeTypedElementAttributes, SerializableValue } from '../../protocol/types.js';\nimport {\n composeElementTemplateListAttributes,\n createElementTemplateListState,\n markElementTemplateListDestroyed,\n registerElementTemplateListState,\n} from '../list/list.js';\nimport type { ETListItemPlatformInfo } from '../list/list.js';\nimport { filterListItemPlatformInfoFromSpread } from '../list/platform-info.js';\nimport { __etAttrPlanMap, hasMainThreadRefAttrSlot } from '../template/attr-slot-plan.js';\nimport type { EtAttrAdapter } from '../template/attr-slot-plan.js';\nimport {\n createElementTemplateWithReservedHandle,\n createTypedElementTemplateWithReservedHandle,\n destroyElementTemplateId,\n getNextElementTemplateId,\n} from '../template/handle.js';\nimport { initializeMainThreadDynamicAttrSlots } from '../template/main-thread-dynamic-attr-state.js';\nimport type { MainThreadDynamicAttrSubtreeHandle } from '../template/main-thread-dynamic-attr-state.js';\nimport { prepareTypedListAttributes } from '../template/typed-attributes.js';\n\nconst TYPED_LIST_HOST_TYPE = 'list';\n\nexport type RenderAttributes = SerializableValue[] | RuntimeTypedElementAttributes | undefined;\n\nexport function discardRenderedHostsSince(checkpoint: number): void {\n const end = getNextElementTemplateId();\n // Synchronous first-screen creation allocates consecutive negative IDs.\n // Release abandoned native refs and side tables without reusing those IDs.\n for (let uid = checkpoint; uid > end; uid--) {\n markElementTemplateListDestroyed(uid);\n destroyElementTemplateId(uid);\n }\n}\n\nexport function createRenderedHost(\n handleId: number,\n type: string,\n attributes: RenderAttributes,\n childSlots: ElementTemplateHandle[][] | undefined,\n materializationHandles: MainThreadDynamicAttrSubtreeHandle[],\n listItemPlatformInfo: ETListItemPlatformInfo | undefined,\n host?: ElementTemplateHost,\n listItemSubtreeHandleIds?: Map<number, readonly number[]>,\n): ElementTemplateHandle {\n if (type === TYPED_LIST_HOST_TYPE) {\n const preparedTypedAttributes = prepareTypedListAttributes(\n handleId,\n attributes as RuntimeTypedElementAttributes | undefined,\n );\n const listState = createElementTemplateListState(listItemSubtreeHandleIds);\n const attrsWithCallbacks = composeElementTemplateListAttributes(preparedTypedAttributes, listState);\n const elementRef = createTypedElementTemplateWithReservedHandle(\n handleId,\n TYPED_LIST_HOST_TYPE,\n attrsWithCallbacks,\n childSlots ?? null,\n {},\n );\n if (elementRef) {\n initializeMainThreadDynamicAttrSlots(\n handleId,\n TYPED_LIST_HOST_TYPE,\n [preparedTypedAttributes],\n );\n registerElementTemplateListState(handleId, listState, elementRef);\n materializationHandles.push({\n uid: handleId,\n ref: elementRef,\n });\n }\n return elementRef;\n }\n\n const plain = host?.plain === true;\n const attrPlan = plain ? undefined : __etAttrPlanMap[type];\n const attributeSlots = attributes as SerializableValue[] | undefined;\n let preparedAttributeSlots = attributeSlots ?? null;\n if (attrPlan !== undefined) {\n preparedAttributeSlots = attributeSlots?.slice() ?? [];\n for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {\n const attrSlotIndex = attrPlan[planIndex] as number;\n const adapter = attrPlan[planIndex + 1] as EtAttrAdapter;\n preparedAttributeSlots[attrSlotIndex] = adapter(\n handleId,\n attrSlotIndex,\n preparedAttributeSlots[attrSlotIndex],\n );\n }\n }\n // Compact hosts carry bundle identity captured when their template is defined.\n const identity = host ?? parseElementTemplateType(type);\n const templateKey = identity.templateKey;\n const bundleUrl = identity.bundleUrl === MAIN_BUNDLE_URL_SENTINEL ? null : identity.bundleUrl;\n const hasMainThreadRef = !plain && /* #__NOINLINE__ */ hasMainThreadRefAttrSlot(type);\n const elementRef = createElementTemplateWithReservedHandle(\n handleId,\n templateKey,\n bundleUrl,\n preparedAttributeSlots,\n childSlots ?? null,\n !plain,\n // Pass List item platform info through native ET options during initial\n // rendering.\n listItemPlatformInfo === undefined\n ? undefined\n : { __listItemPlatformInfo: filterListItemPlatformInfoFromSpread(listItemPlatformInfo) },\n );\n if (hasMainThreadRef) {\n materializationHandles.push({\n uid: handleId,\n ref: elementRef,\n });\n }\n return elementRef;\n}\n"]}
|
|
@@ -3,4 +3,4 @@ export declare let beforeDiff2: ((vnode: unknown, context: Record<string, unknow
|
|
|
3
3
|
export declare function renderWithHooks(vnode: unknown, context: unknown, output: unknown[], renderVNode: Function, result: unknown): unknown[];
|
|
4
4
|
export declare const EMPTY_OBJ: Record<string, unknown>;
|
|
5
5
|
export declare function cleanupVNode(vnode: unknown): void;
|
|
6
|
-
export declare function renderComponentVNode(vnode: unknown, type: unknown, props: unknown, context: unknown, output: unknown[], renderVNode: Function, result: unknown, parentType?: string, subtreeHandles?: unknown[]
|
|
6
|
+
export declare function renderComponentVNode(vnode: unknown, type: unknown, props: unknown, context: unknown, output: unknown[], renderVNode: Function, result: unknown, parentType?: string, subtreeHandles?: unknown[]): void;
|
|
@@ -94,7 +94,7 @@ export function cleanupVNode(vnode) {
|
|
|
94
94
|
if (unmountHook)
|
|
95
95
|
unmountHook(vnode);
|
|
96
96
|
}
|
|
97
|
-
export function renderComponentVNode(vnode, type, props, context, output, renderVNode, result, parentType, subtreeHandles
|
|
97
|
+
export function renderComponentVNode(vnode, type, props, context, output, renderVNode, result, parentType, subtreeHandles) {
|
|
98
98
|
let cctx = context;
|
|
99
99
|
let rendered;
|
|
100
100
|
let component;
|
|
@@ -150,14 +150,13 @@ export function renderComponentVNode(vnode, type, props, context, output, render
|
|
|
150
150
|
? {
|
|
151
151
|
rootSubtreeHandlesLength: result.rootSubtreeHandles.length,
|
|
152
152
|
subtreeHandlesLength: subtreeHandles?.length,
|
|
153
|
-
listItemUidsLength: listItemUids?.length,
|
|
154
153
|
nextId: getNextElementTemplateId(),
|
|
155
154
|
pageAttributes: result.pageAttributes,
|
|
156
155
|
isInsideAuthoredPage: result.isInsideAuthoredPage,
|
|
157
156
|
}
|
|
158
157
|
: undefined;
|
|
159
158
|
try {
|
|
160
|
-
renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles
|
|
159
|
+
renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles);
|
|
161
160
|
}
|
|
162
161
|
catch (e) {
|
|
163
162
|
if (checkpoint && e && typeof e === 'object' && e.then) {
|
|
@@ -167,13 +166,11 @@ export function renderComponentVNode(vnode, type, props, context, output, render
|
|
|
167
166
|
result.rootSubtreeHandles.length = checkpoint.rootSubtreeHandlesLength;
|
|
168
167
|
if (subtreeHandles)
|
|
169
168
|
subtreeHandles.length = checkpoint.subtreeHandlesLength;
|
|
170
|
-
if (listItemUids)
|
|
171
|
-
listItemUids.length = checkpoint.listItemUidsLength;
|
|
172
169
|
discardRenderedHostsSince(checkpoint.nextId);
|
|
173
170
|
result.pageAttributes = checkpoint.pageAttributes;
|
|
174
171
|
if (__DEV__)
|
|
175
172
|
result.isInsideAuthoredPage = checkpoint.isInsideAuthoredPage;
|
|
176
|
-
renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles
|
|
173
|
+
renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles);
|
|
177
174
|
}
|
|
178
175
|
else {
|
|
179
176
|
throw e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-components.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/render-components.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;GAIG;AAEH,cAAc;AAEd,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,SAAS,EACT,eAAe,EACf,IAAI,EACJ,KAAK,EACL,MAAM,EACN,cAAc,EACd,UAAU,EACV,MAAM,EACN,MAAM,EACN,YAAY,EACZ,KAAK,GACN,MAAM,qCAAqC,CAAC;AAE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GAAG,UAAU,CAAC,oBAAoB,CAAC;YAC5E,IAAI,YAAY;gBAAE,YAAY,CAAC,MAAM,GAAG,UAAU,CAAC,kBAAkB,CAAC;YACtE,yBAAyB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAC7C,MAAM,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;YAClD,IAAI,OAAO;gBAAE,MAAM,CAAC,oBAAoB,GAAG,UAAU,CAAC,oBAAoB,CAAC;YAC3E,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;QAClG,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,yDAAyD;AACzD,SAAS,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO;IACrC,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAC1C,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/**\n * Synchronous component traversal for Element Template rendering.\n * This module is modified from preact-render-to-string@6.0.3 to generate\n * host output instead of HTML strings for Lynx.\n */\n\n// @ts-nocheck\n\nimport { Fragment, h, options } from 'preact';\n\nimport { discardRenderedHostsSince } from './create-rendered-host.js';\nimport { getNextElementTemplateId } from '../template/handle.js';\n\nimport {\n BITS,\n CHILDREN,\n COMMIT,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DIFF2,\n DIFFED,\n GLOBAL_CONTEXT,\n NEXT_STATE,\n PARENT,\n RENDER,\n SKIP_EFFECTS,\n VNODE,\n} from '../../../shared/render-constants.js';\n\n/** @typedef {import('preact').VNode} VNode */\n\nconst EMPTY_ARR = [];\nconst assign = /* @__PURE__ */ Object.assign;\n\n// Global state for the current render pass\nexport let beforeDiff: ((vnode: unknown) => void) | undefined;\nexport let beforeDiff2: ((vnode: unknown, context: Record<string, unknown>) => void) | undefined;\nlet afterDiff, renderHook, unmountHook;\n\nexport function renderWithHooks(\n vnode: unknown,\n context: unknown,\n output: unknown[],\n renderVNode: Function,\n result: unknown,\n): unknown[] {\n // Performance optimization: main-thread rendering is synchronous and we\n // therefore don't execute any effects. To do that we pass an empty\n // array to `options._commit` (`__c`). But we can go one step further\n // and avoid a lot of dirty checks and allocations by setting\n // `options._skipEffects` (`__s`) too.\n const previousSkipEffects = options[SKIP_EFFECTS];\n options[SKIP_EFFECTS] = true;\n\n // store options hooks once before each synchronous render call\n beforeDiff = options[DIFF];\n beforeDiff2 = options[DIFF2];\n afterDiff = options[DIFFED];\n renderHook = options[RENDER];\n unmountHook = options.unmount;\n\n const parent = h(Fragment, null);\n parent[CHILDREN] = [vnode];\n\n try {\n renderVNode(\n vnode,\n context || EMPTY_OBJ,\n parent,\n output,\n result,\n );\n } finally {\n // options._commit, we don't schedule any effects in this library right now,\n // so we can pass an empty queue to this hook.\n if (options[COMMIT]) options[COMMIT](vnode, EMPTY_ARR);\n options[SKIP_EFFECTS] = previousSkipEffects;\n EMPTY_ARR.length = 0;\n }\n\n return output;\n}\n\n// Installed as setState/forceUpdate for function components\n/* v8 ignore start */\nfunction markAsDirty() {\n this[BITS] |= COMPONENT_DIRTY;\n}\n/* v8 ignore stop */\n\nexport const EMPTY_OBJ: Record<string, unknown> = {};\n\n/**\n * @param {VNode} vnode\n * @param {Record<string, unknown>} context\n */\nfunction renderClassComponent(vnode, context, globalContext) {\n const type = /** @type {import(\"preact\").ComponentClass<typeof vnode.props>} */ (vnode.type);\n\n let c;\n if (vnode[COMPONENT]) {\n c = vnode[COMPONENT];\n c.state = c[NEXT_STATE];\n } else {\n c = new type(vnode.props, context);\n }\n\n vnode[COMPONENT] = c;\n c[VNODE] = vnode;\n\n c.props = vnode.props;\n c.context = context;\n c[GLOBAL_CONTEXT] = globalContext;\n // turn off stateful re-rendering:\n c[BITS] |= COMPONENT_DIRTY;\n\n if (c.state == null) c.state = EMPTY_OBJ;\n\n if (c[NEXT_STATE] == null) {\n c[NEXT_STATE] = c.state;\n }\n\n if (type.getDerivedStateFromProps) {\n c.state = assign(\n {},\n c.state,\n type.getDerivedStateFromProps(c.props, c.state),\n );\n }\n\n if (renderHook) renderHook(vnode);\n\n return c.render(c.props, c.state, context);\n}\n\nexport function cleanupVNode(vnode: unknown): void {\n if (afterDiff) afterDiff(vnode);\n vnode[PARENT] = undefined;\n if (unmountHook) unmountHook(vnode);\n}\n\nexport function renderComponentVNode(\n vnode: unknown,\n type: unknown,\n props: unknown,\n context: unknown,\n output: unknown[],\n renderVNode: Function,\n result: unknown,\n parentType?: string,\n subtreeHandles?: unknown[],\n listItemUids?: number[],\n): void {\n let cctx = context;\n let rendered;\n let component;\n const outputLength = output.length;\n\n if (type === Fragment) {\n rendered = props.children;\n } else {\n const contextType = type.contextType;\n if (contextType != null) {\n const provider = context[contextType.__c];\n cctx = provider ? provider.props.value : contextType.__;\n }\n\n if (type.prototype && typeof type.prototype.render === 'function') {\n rendered = /**#__NOINLINE__**/ renderClassComponent(vnode, cctx, context);\n component = vnode[COMPONENT];\n } else {\n component = {\n __v: vnode,\n props,\n context: cctx,\n [GLOBAL_CONTEXT]: context,\n // silently drop state updates\n setState: markAsDirty,\n forceUpdate: markAsDirty,\n __g: COMPONENT_DIRTY,\n // hooks\n __h: [],\n };\n vnode[COMPONENT] = component;\n component.constructor = type;\n component.render = doRender;\n\n let count = 0;\n while (component[BITS] & COMPONENT_DIRTY && count++ < 25) {\n component[BITS] &= ~COMPONENT_DIRTY;\n\n if (renderHook) renderHook(vnode);\n\n rendered = component.render(props, component.state, cctx);\n }\n component[BITS] |= COMPONENT_DIRTY;\n }\n\n if (component.getChildContext != null) {\n context = assign({}, context, component.getChildContext());\n }\n }\n\n const isTopLevelFragment = rendered != null && rendered.type === Fragment\n && rendered.key == null;\n rendered = isTopLevelFragment ? rendered.props.children : rendered;\n\n // A Suspense boundary owns the IDs allocated while rendering its children,\n // as well as the entries added to the enclosing commit collectors.\n const checkpoint = component && component.__c\n ? {\n rootSubtreeHandlesLength: result.rootSubtreeHandles.length,\n subtreeHandlesLength: subtreeHandles?.length,\n listItemUidsLength: listItemUids?.length,\n nextId: getNextElementTemplateId(),\n pageAttributes: result.pageAttributes,\n isInsideAuthoredPage: result.isInsideAuthoredPage,\n }\n : undefined;\n\n try {\n renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles, listItemUids);\n } catch (e) {\n if (\n checkpoint && e && typeof e === 'object' && e.then\n ) {\n component.setState({ /* _suspended */ __a: true });\n\n rendered = renderClassComponent(vnode, context, context);\n\n output.length = outputLength;\n result.rootSubtreeHandles.length = checkpoint.rootSubtreeHandlesLength;\n if (subtreeHandles) subtreeHandles.length = checkpoint.subtreeHandlesLength;\n if (listItemUids) listItemUids.length = checkpoint.listItemUidsLength;\n discardRenderedHostsSince(checkpoint.nextId);\n result.pageAttributes = checkpoint.pageAttributes;\n if (__DEV__) result.isInsideAuthoredPage = checkpoint.isInsideAuthoredPage;\n renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles, listItemUids);\n } else {\n throw e;\n }\n } finally {\n cleanupVNode(vnode);\n }\n}\n\n/** The `.render()` method for a PFC backing instance. */\nfunction doRender(props, state, context) {\n return this.constructor(props, context);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"render-components.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/render-components.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;;GAIG;AAEH,cAAc;AAEd,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,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AC,CAAC;YAEzD,MAAM,CAAC,MAAM,GAAG,YAAY,CAAC;YAC7B,MAAM,CAAC,kBAAkB,CAAC,MAAM,GAAG,UAAU,CAAC,wBAAwB,CAAC;YACvE,IAAI,cAAc;gBAAE,cAAc,CAAC,MAAM,GAAG,UAAU,CAAC,oBAAoB,CAAC;YAC5E,yBAAyB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAC7C,MAAM,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;YAClD,IAAI,OAAO;gBAAE,MAAM,CAAC,oBAAoB,GAAG,UAAU,CAAC,oBAAoB,CAAC;YAC3E,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;QACpF,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,yDAAyD;AACzD,SAAS,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO;IACrC,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAC1C,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/**\n * Synchronous component traversal for Element Template rendering.\n * This module is modified from preact-render-to-string@6.0.3 to generate\n * host output instead of HTML strings for Lynx.\n */\n\n// @ts-nocheck\n\nimport { Fragment, h, options } from 'preact';\n\nimport { discardRenderedHostsSince } from './create-rendered-host.js';\nimport { getNextElementTemplateId } from '../template/handle.js';\n\nimport {\n BITS,\n CHILDREN,\n COMMIT,\n COMPONENT,\n COMPONENT_DIRTY,\n DIFF,\n DIFF2,\n DIFFED,\n GLOBAL_CONTEXT,\n NEXT_STATE,\n PARENT,\n RENDER,\n SKIP_EFFECTS,\n VNODE,\n} from '../../../shared/render-constants.js';\n\n/** @typedef {import('preact').VNode} VNode */\n\nconst EMPTY_ARR = [];\nconst assign = /* @__PURE__ */ Object.assign;\n\n// Global state for the current render pass\nexport let beforeDiff: ((vnode: unknown) => void) | undefined;\nexport let beforeDiff2: ((vnode: unknown, context: Record<string, unknown>) => void) | undefined;\nlet afterDiff, renderHook, unmountHook;\n\nexport function renderWithHooks(\n vnode: unknown,\n context: unknown,\n output: unknown[],\n renderVNode: Function,\n result: unknown,\n): unknown[] {\n // Performance optimization: main-thread rendering is synchronous and we\n // therefore don't execute any effects. To do that we pass an empty\n // array to `options._commit` (`__c`). But we can go one step further\n // and avoid a lot of dirty checks and allocations by setting\n // `options._skipEffects` (`__s`) too.\n const previousSkipEffects = options[SKIP_EFFECTS];\n options[SKIP_EFFECTS] = true;\n\n // store options hooks once before each synchronous render call\n beforeDiff = options[DIFF];\n beforeDiff2 = options[DIFF2];\n afterDiff = options[DIFFED];\n renderHook = options[RENDER];\n unmountHook = options.unmount;\n\n const parent = h(Fragment, null);\n parent[CHILDREN] = [vnode];\n\n try {\n renderVNode(\n vnode,\n context || EMPTY_OBJ,\n parent,\n output,\n result,\n );\n } finally {\n // options._commit, we don't schedule any effects in this library right now,\n // so we can pass an empty queue to this hook.\n if (options[COMMIT]) options[COMMIT](vnode, EMPTY_ARR);\n options[SKIP_EFFECTS] = previousSkipEffects;\n EMPTY_ARR.length = 0;\n }\n\n return output;\n}\n\n// Installed as setState/forceUpdate for function components\n/* v8 ignore start */\nfunction markAsDirty() {\n this[BITS] |= COMPONENT_DIRTY;\n}\n/* v8 ignore stop */\n\nexport const EMPTY_OBJ: Record<string, unknown> = {};\n\n/**\n * @param {VNode} vnode\n * @param {Record<string, unknown>} context\n */\nfunction renderClassComponent(vnode, context, globalContext) {\n const type = /** @type {import(\"preact\").ComponentClass<typeof vnode.props>} */ (vnode.type);\n\n let c;\n if (vnode[COMPONENT]) {\n c = vnode[COMPONENT];\n c.state = c[NEXT_STATE];\n } else {\n c = new type(vnode.props, context);\n }\n\n vnode[COMPONENT] = c;\n c[VNODE] = vnode;\n\n c.props = vnode.props;\n c.context = context;\n c[GLOBAL_CONTEXT] = globalContext;\n // turn off stateful re-rendering:\n c[BITS] |= COMPONENT_DIRTY;\n\n if (c.state == null) c.state = EMPTY_OBJ;\n\n if (c[NEXT_STATE] == null) {\n c[NEXT_STATE] = c.state;\n }\n\n if (type.getDerivedStateFromProps) {\n c.state = assign(\n {},\n c.state,\n type.getDerivedStateFromProps(c.props, c.state),\n );\n }\n\n if (renderHook) renderHook(vnode);\n\n return c.render(c.props, c.state, context);\n}\n\nexport function cleanupVNode(vnode: unknown): void {\n if (afterDiff) afterDiff(vnode);\n vnode[PARENT] = undefined;\n if (unmountHook) unmountHook(vnode);\n}\n\nexport function renderComponentVNode(\n vnode: unknown,\n type: unknown,\n props: unknown,\n context: unknown,\n output: unknown[],\n renderVNode: Function,\n result: unknown,\n parentType?: string,\n subtreeHandles?: unknown[],\n): void {\n let cctx = context;\n let rendered;\n let component;\n const outputLength = output.length;\n\n if (type === Fragment) {\n rendered = props.children;\n } else {\n const contextType = type.contextType;\n if (contextType != null) {\n const provider = context[contextType.__c];\n cctx = provider ? provider.props.value : contextType.__;\n }\n\n if (type.prototype && typeof type.prototype.render === 'function') {\n rendered = /**#__NOINLINE__**/ renderClassComponent(vnode, cctx, context);\n component = vnode[COMPONENT];\n } else {\n component = {\n __v: vnode,\n props,\n context: cctx,\n [GLOBAL_CONTEXT]: context,\n // silently drop state updates\n setState: markAsDirty,\n forceUpdate: markAsDirty,\n __g: COMPONENT_DIRTY,\n // hooks\n __h: [],\n };\n vnode[COMPONENT] = component;\n component.constructor = type;\n component.render = doRender;\n\n let count = 0;\n while (component[BITS] & COMPONENT_DIRTY && count++ < 25) {\n component[BITS] &= ~COMPONENT_DIRTY;\n\n if (renderHook) renderHook(vnode);\n\n rendered = component.render(props, component.state, cctx);\n }\n component[BITS] |= COMPONENT_DIRTY;\n }\n\n if (component.getChildContext != null) {\n context = assign({}, context, component.getChildContext());\n }\n }\n\n const isTopLevelFragment = rendered != null && rendered.type === Fragment\n && rendered.key == null;\n rendered = isTopLevelFragment ? rendered.props.children : rendered;\n\n // A Suspense boundary owns the IDs allocated while rendering its children,\n // as well as the entries added to the enclosing commit collectors.\n const checkpoint = component && component.__c\n ? {\n rootSubtreeHandlesLength: result.rootSubtreeHandles.length,\n subtreeHandlesLength: subtreeHandles?.length,\n nextId: getNextElementTemplateId(),\n pageAttributes: result.pageAttributes,\n isInsideAuthoredPage: result.isInsideAuthoredPage,\n }\n : undefined;\n\n try {\n renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles);\n } catch (e) {\n if (\n checkpoint && e && typeof e === 'object' && e.then\n ) {\n component.setState({ /* _suspended */ __a: true });\n\n rendered = renderClassComponent(vnode, context, context);\n\n output.length = outputLength;\n result.rootSubtreeHandles.length = checkpoint.rootSubtreeHandlesLength;\n if (subtreeHandles) subtreeHandles.length = checkpoint.subtreeHandlesLength;\n discardRenderedHostsSince(checkpoint.nextId);\n result.pageAttributes = checkpoint.pageAttributes;\n if (__DEV__) result.isInsideAuthoredPage = checkpoint.isInsideAuthoredPage;\n renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles);\n } else {\n throw e;\n }\n } finally {\n cleanupVNode(vnode);\n }\n}\n\n/** The `.render()` method for a PFC backing instance. */\nfunction doRender(props, state, context) {\n return this.constructor(props, context);\n}\n"]}
|
|
@@ -5,7 +5,6 @@ import { createRenderedHost, discardRenderedHostsSince } from './create-rendered
|
|
|
5
5
|
import { EMPTY_OBJ, beforeDiff, beforeDiff2, cleanupVNode, renderComponentVNode, renderWithHooks, } from './render-components.js';
|
|
6
6
|
import { CHILDREN, PARENT } from '../../../shared/render-constants.js';
|
|
7
7
|
import { ELEMENT_TEMPLATE_PAGE_HANDLE_ID } from '../../protocol/page.js';
|
|
8
|
-
import { clearPendingElementTemplateListItems } from '../list/list.js';
|
|
9
8
|
import { __ElementTemplatePage } from '../page/authored-page.js';
|
|
10
9
|
import { createElementTemplateWithReservedHandle, getNextElementTemplateId, reserveElementTemplateId, } from '../template/handle.js';
|
|
11
10
|
import { prepareTypedElementAttributes } from '../template/typed-attributes.js';
|
|
@@ -27,11 +26,6 @@ export function renderToElementTemplate(vnode, context) {
|
|
|
27
26
|
discardRenderedHostsSince(checkpoint);
|
|
28
27
|
throw error;
|
|
29
28
|
}
|
|
30
|
-
finally {
|
|
31
|
-
// Completed lists consume their item records. Anything left belongs to
|
|
32
|
-
// abandoned content, including children discarded by Suspense.
|
|
33
|
-
clearPendingElementTemplateListItems();
|
|
34
|
-
}
|
|
35
29
|
result.pageAttributes ??= null;
|
|
36
30
|
return result;
|
|
37
31
|
}
|
|
@@ -41,7 +35,7 @@ function validateRoot(result, parentType) {
|
|
|
41
35
|
throw new Error('Element Template authored <page /> must wrap all materialized roots.');
|
|
42
36
|
}
|
|
43
37
|
}
|
|
44
|
-
function renderHost(vnode, context, output, result, parentType, parentSubtreeHandles
|
|
38
|
+
function renderHost(vnode, context, output, result, parentType, parentSubtreeHandles) {
|
|
45
39
|
const type = vnode.type;
|
|
46
40
|
const props = vnode.templateKey === undefined ? vnode.props : vnode;
|
|
47
41
|
const isList = type === 'list';
|
|
@@ -60,8 +54,9 @@ function renderHost(vnode, context, output, result, parentType, parentSubtreeHan
|
|
|
60
54
|
// child arrays and the root/list-item ref collector survive this call.
|
|
61
55
|
const subtreeHandles = parentType === undefined || parentType === 'list' ? [] : parentSubtreeHandles;
|
|
62
56
|
let childSlots;
|
|
63
|
-
let
|
|
57
|
+
let listItemSubtreeHandleIds;
|
|
64
58
|
if (isList) {
|
|
59
|
+
const previousListItemSubtreeHandleIds = result.currentListItemSubtreeHandleIds;
|
|
65
60
|
try {
|
|
66
61
|
if (__DEV__) {
|
|
67
62
|
for (const name in props) {
|
|
@@ -74,11 +69,13 @@ function renderHost(vnode, context, output, result, parentType, parentSubtreeHan
|
|
|
74
69
|
if (children != null && children !== true && children !== false) {
|
|
75
70
|
const refs = [];
|
|
76
71
|
childSlots = [refs];
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
listItemSubtreeHandleIds = new Map();
|
|
73
|
+
result.currentListItemSubtreeHandleIds = listItemSubtreeHandleIds;
|
|
74
|
+
renderDirect(children, context, vnode, refs, result, type, subtreeHandles);
|
|
79
75
|
}
|
|
80
76
|
}
|
|
81
77
|
finally {
|
|
78
|
+
result.currentListItemSubtreeHandleIds = previousListItemSubtreeHandleIds;
|
|
82
79
|
cleanupVNode(vnode);
|
|
83
80
|
}
|
|
84
81
|
}
|
|
@@ -103,7 +100,7 @@ function renderHost(vnode, context, output, result, parentType, parentSubtreeHan
|
|
|
103
100
|
if (children == null || children === true || children === false)
|
|
104
101
|
continue;
|
|
105
102
|
const refs = (childSlots ??= [])[slotId] = [];
|
|
106
|
-
renderDirect(children, context, vnode, refs, result, type, subtreeHandles
|
|
103
|
+
renderDirect(children, context, vnode, refs, result, type, subtreeHandles);
|
|
107
104
|
}
|
|
108
105
|
}
|
|
109
106
|
cleanupVNode(vnode);
|
|
@@ -117,16 +114,20 @@ function renderHost(vnode, context, output, result, parentType, parentSubtreeHan
|
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
const uid = reserveElementTemplateId();
|
|
120
|
-
const ref = /* #__NOINLINE__ */ createRenderedHost(uid, type, attributes, childSlots,
|
|
117
|
+
const ref = /* #__NOINLINE__ */ createRenderedHost(uid, type, attributes, childSlots, subtreeHandles, listItemPlatformInfo, vnode.templateKey === undefined ? undefined : vnode, listItemSubtreeHandleIds);
|
|
121
118
|
output.push(ref);
|
|
122
|
-
if (parentType ===
|
|
123
|
-
|
|
119
|
+
if (!isList && parentType === 'list' && subtreeHandles.length > 0) {
|
|
120
|
+
const itemHandleIds = [];
|
|
121
|
+
for (let index = 0; index < subtreeHandles.length; index += 1) {
|
|
122
|
+
itemHandleIds.push(subtreeHandles[index].uid);
|
|
123
|
+
}
|
|
124
|
+
result.currentListItemSubtreeHandleIds.set(uid, itemHandleIds);
|
|
124
125
|
}
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
if (parentType === undefined) {
|
|
127
|
+
result.rootSubtreeHandles.push(subtreeHandles);
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
|
-
function renderDirect(value, context, parent, output, result, parentType, subtreeHandles
|
|
130
|
+
function renderDirect(value, context, parent, output, result, parentType, subtreeHandles) {
|
|
130
131
|
if (value == null || value === true || value === false || value === '')
|
|
131
132
|
return;
|
|
132
133
|
if (typeof value !== 'object') {
|
|
@@ -149,7 +150,7 @@ function renderDirect(value, context, parent, output, result, parentType, subtre
|
|
|
149
150
|
const child = value[index];
|
|
150
151
|
if (child == null || typeof child === 'boolean')
|
|
151
152
|
continue;
|
|
152
|
-
renderDirect(child, context, parent, output, result, parentType, subtreeHandles
|
|
153
|
+
renderDirect(child, context, parent, output, result, parentType, subtreeHandles);
|
|
153
154
|
}
|
|
154
155
|
return;
|
|
155
156
|
}
|
|
@@ -177,13 +178,13 @@ function renderDirect(value, context, parent, output, result, parentType, subtre
|
|
|
177
178
|
}
|
|
178
179
|
result.pageAttributes = prepareTypedElementAttributes(ELEMENT_TEMPLATE_PAGE_HANDLE_ID, props['attributes']);
|
|
179
180
|
}
|
|
180
|
-
/* #__NOINLINE__ */ renderComponentVNode(vnode, type, props, context, output, renderDirect, result, parentType, subtreeHandles
|
|
181
|
+
/* #__NOINLINE__ */ renderComponentVNode(vnode, type, props, context, output, renderDirect, result, parentType, subtreeHandles);
|
|
181
182
|
if (__DEV__ && type === __ElementTemplatePage)
|
|
182
183
|
result.isInsideAuthoredPage = false;
|
|
183
184
|
return;
|
|
184
185
|
}
|
|
185
186
|
if (typeof type === 'string') {
|
|
186
|
-
/* #__NOINLINE__ */ renderHost(vnode, context, output, result, parentType, subtreeHandles
|
|
187
|
+
/* #__NOINLINE__ */ renderHost(vnode, context, output, result, parentType, subtreeHandles);
|
|
187
188
|
return;
|
|
188
189
|
}
|
|
189
190
|
if (__DEV__) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-direct.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/render-direct.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAG1F,OAAO,EACL,SAAS,EACT,UAAU,EACV,WAAW,EACX,YAAY,EACZ,oBAAoB,EACpB,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAEzE,OAAO,EAAE,oCAAoC,EAAE,MAAM,iBAAiB,CAAC;AAEvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,uCAAuC,EACvC,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAuBhF,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC;AAE9C,MAAM,UAAU,uBAAuB,CAAC,KAAc,EAAE,OAA8B;IACpF,MAAM,UAAU,GAAG,wBAAwB,EAAE,CAAC;IAC9C,MAAM,MAAM,GAAsB;QAChC,cAAc,EAAE,SAAS;QACzB,QAAQ,EAAE,EAAE;QACZ,kBAAkB,EAAE,EAAE;KACvB,CAAC;IACF,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,CAAC,oBAAoB,GAAG,KAAK,CAAC;IACtC,CAAC;IACD,IAAI,CAAC;QACH,mBAAmB,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAC7F,CAAC;IAAC,OAAO,KAA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ed 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 { createRenderedHost, discardRenderedHostsSince } from './create-rendered-host.js';\nimport type { RenderAttributes } from './create-rendered-host.js';\nimport type { ElementTemplateHost } from './host.js';\nimport {\n EMPTY_OBJ,\n beforeDiff,\n beforeDiff2,\n cleanupVNode,\n renderComponentVNode,\n renderWithHooks,\n} from './render-components.js';\nimport { CHILDREN, PARENT } from '../../../shared/render-constants.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID } from '../../protocol/page.js';\nimport type { RuntimeTypedElementAttributes, TypedElementAttributesCommand } from '../../protocol/types.js';\nimport { clearPendingElementTemplateListItems } from '../list/list.js';\nimport type { ETListItemPlatformInfo } from '../list/list.js';\nimport { __ElementTemplatePage } from '../page/authored-page.js';\nimport {\n createElementTemplateWithReservedHandle,\n getNextElementTemplateId,\n reserveElementTemplateId,\n} from '../template/handle.js';\nimport type { MainThreadDynamicAttrSubtreeHandle } from '../template/main-thread-dynamic-attr-state.js';\nimport { prepareTypedElementAttributes } from '../template/typed-attributes.js';\n\nexport interface MainThreadCreateResult {\n pageAttributes: TypedElementAttributesCommand | null;\n rootRefs: ElementTemplateHandle[];\n rootSubtreeHandles: MainThreadDynamicAttrSubtreeHandle[][];\n}\n\ninterface DirectRenderState extends Omit<MainThreadCreateResult, 'pageAttributes'> {\n pageAttributes: TypedElementAttributesCommand | null | undefined;\n isInsideAuthoredPage?: boolean;\n}\n\ninterface RenderVNode {\n type: unknown;\n props: Record<string, unknown>;\n templateKey?: string;\n [PARENT]?: RenderVNode | undefined;\n [CHILDREN]?: unknown[];\n}\n\ntype RenderContext = Record<string, unknown>;\n\nconst isArray = /* @__PURE__ */ Array.isArray;\n\nexport function renderToElementTemplate(vnode: unknown, context?: RenderContext | null): MainThreadCreateResult {\n const checkpoint = getNextElementTemplateId();\n const result: DirectRenderState = {\n pageAttributes: undefined,\n rootRefs: [],\n rootSubtreeHandles: [],\n };\n if (__DEV__) {\n result.isInsideAuthoredPage = false;\n }\n try {\n /* #__NOINLINE__ */ renderWithHooks(vnode, context, result.rootRefs, renderDirect, result);\n } catch (error) {\n discardRenderedHostsSince(checkpoint);\n throw error;\n } finally {\n // Completed lists consume their item records. Anything left belongs to\n // abandoned content, including children discarded by Suspense.\n clearPendingElementTemplateListItems();\n }\n result.pageAttributes ??= null;\n return result as MainThreadCreateResult;\n}\n\nfunction validateRoot(result: DirectRenderState, parentType: string | undefined): void {\n if (\n parentType === undefined && result.pageAttributes !== undefined\n && !result.isInsideAuthoredPage\n ) {\n throw new Error('Element Template authored <page /> must wrap all materialized roots.');\n }\n}\n\nfunction renderHost(\n vnode: RenderVNode,\n context: RenderContext,\n output: ElementTemplateHandle[],\n result: DirectRenderState,\n parentType: string | undefined,\n parentSubtreeHandles: MainThreadDynamicAttrSubtreeHandle[] | undefined,\n parentListItemUids: number[] | undefined,\n): void {\n const type = vnode.type as string;\n const props = vnode.templateKey === undefined ? vnode.props : vnode as unknown as Record<string, unknown>;\n const isList = type === 'list';\n const attributes = (isList ? props['attributes'] : props['attributeSlots']) as RenderAttributes;\n const listItemPlatformInfo = props['__listItemPlatformInfo'] as ETListItemPlatformInfo | undefined;\n let deferredListItemMarker = false;\n if (__DEV__) {\n deferredListItemMarker = props['isReady'] !== undefined;\n validateRoot(result, parentType);\n }\n if (!isList && !(type.startsWith('_et_') || type.includes(':_et_'))) {\n cleanupVNode(vnode);\n throw new Error(`Element Template main-thread renderer received an uncompiled host vnode: ${type}`);\n }\n\n // Recursive locals retain the inputs until children finish. Only native\n // child arrays and the root/list-item ref collector survive this call.\n const subtreeHandles = parentType === undefined || parentType === 'list' ? [] : parentSubtreeHandles!;\n let childSlots: ElementTemplateHandle[][] | undefined;\n let listItemUids: number[] | undefined;\n if (isList) {\n try {\n if (__DEV__) {\n for (const name in props) {\n if (name.startsWith('$') && name !== '$0') {\n throw new Error('Element Template typed list only supports logical slot $0.');\n }\n }\n }\n const children = props['$0'];\n if (children != null && children !== true && children !== false) {\n const refs: ElementTemplateHandle[] = [];\n childSlots = [refs];\n listItemUids = [];\n renderDirect(children, context, vnode, refs, result, type, subtreeHandles, listItemUids);\n }\n } finally {\n cleanupVNode(vnode);\n }\n } else {\n // Ordered inputs belong to the caller. Named inputs are collected into a\n // renderer-owned array that can also hold the resulting native refs.\n let childrenBySlot = props['slotChildren'] as unknown[] | undefined;\n if (vnode.templateKey === undefined && childrenBySlot === undefined) {\n for (const name in props) {\n if (name.startsWith('$')) {\n const children = props[name];\n if (children == null || children === true || children === false) continue;\n (childrenBySlot ??= [])[+name.slice(1)] = children;\n }\n }\n childSlots = childrenBySlot as ElementTemplateHandle[][] | undefined;\n }\n if (childrenBySlot !== undefined) {\n for (let slotId = 0; slotId < childrenBySlot.length; slotId++) {\n const children = childrenBySlot[slotId];\n if (children == null || children === true || children === false) continue;\n const refs = (childSlots ??= [])[slotId] = [];\n renderDirect(children, context, vnode, refs, result, type, subtreeHandles, undefined);\n }\n }\n cleanupVNode(vnode);\n }\n\n if (__DEV__ && !isList && parentType === 'list') {\n if (deferredListItemMarker) {\n throw new Error('Element Template typed list does not support deferred list items.');\n }\n if (listItemPlatformInfo === undefined) {\n throw new Error('Element Template typed list received a non-list-item root in logical slot $0.');\n }\n }\n const uid = reserveElementTemplateId();\n const ref = /* #__NOINLINE__ */ createRenderedHost(\n uid,\n type,\n attributes,\n childSlots,\n listItemUids,\n subtreeHandles,\n listItemPlatformInfo,\n vnode.templateKey === undefined ? undefined : vnode as unknown as ElementTemplateHost,\n );\n output.push(ref);\n if (parentType === undefined) {\n result.rootSubtreeHandles.push(isList ? [] : subtreeHandles);\n } else if (parentListItemUids !== undefined) {\n parentListItemUids.push(uid);\n }\n}\n\nfunction renderDirect(\n value: unknown,\n context: RenderContext,\n parent: RenderVNode,\n output: ElementTemplateHandle[],\n result: DirectRenderState,\n parentType?: string,\n subtreeHandles?: MainThreadDynamicAttrSubtreeHandle[],\n listItemUids?: number[],\n): void {\n if (value == null || value === true || value === false || value === '') return;\n\n if (typeof value !== 'object') {\n if (typeof value === 'function') return;\n if (__DEV__) {\n validateRoot(result, parentType);\n if (parentType === 'list') {\n throw new Error('Element Template typed list received text logical child.');\n }\n }\n output.push(createElementTemplateWithReservedHandle(\n reserveElementTemplateId(),\n '_et_builtin_raw_text',\n null,\n [(value as string | number) + ''],\n [],\n ));\n if (parentType === undefined) result.rootSubtreeHandles.push([]);\n return;\n }\n\n if (isArray(value)) {\n parent[CHILDREN] = value;\n for (let index = 0; index < value.length; index++) {\n const child: unknown = value[index];\n if (child == null || typeof child === 'boolean') continue;\n renderDirect(child, context, parent, output, result, parentType, subtreeHandles, listItemUids);\n }\n return;\n }\n\n const vnode = value as RenderVNode;\n vnode[PARENT] = parent;\n if (beforeDiff) beforeDiff(vnode);\n if (beforeDiff2) beforeDiff2(vnode, EMPTY_OBJ);\n const type = vnode.type;\n const props = vnode.props;\n if (typeof type === 'function') {\n if (type === __ElementTemplatePage) {\n if (__DEV__) {\n if (parentType !== undefined) {\n throw new Error('Element Template authored <page /> must be the outermost element.');\n }\n if (result.pageAttributes !== undefined) {\n throw new Error('Element Template does not support multiple authored <page /> elements.');\n }\n if (result.rootRefs.length !== 0) {\n throw new Error('Element Template authored <page /> must wrap all materialized roots.');\n }\n result.isInsideAuthoredPage = true;\n }\n result.pageAttributes = prepareTypedElementAttributes(\n ELEMENT_TEMPLATE_PAGE_HANDLE_ID,\n props['attributes'] as RuntimeTypedElementAttributes | undefined,\n );\n }\n /* #__NOINLINE__ */ renderComponentVNode(\n vnode,\n type,\n props,\n context,\n output,\n renderDirect,\n result,\n parentType,\n subtreeHandles,\n listItemUids,\n );\n if (__DEV__ && type === __ElementTemplatePage) result.isInsideAuthoredPage = false;\n return;\n }\n if (typeof type === 'string') {\n /* #__NOINLINE__ */ renderHost(vnode, context, output, result, parentType, subtreeHandles, listItemUids);\n return;\n }\n if (__DEV__) {\n cleanupVNode(vnode);\n throw new Error('Element Template main-thread renderer received an invalid vnode.');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"render-direct.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/render-direct.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAG1F,OAAO,EACL,SAAS,EACT,UAAU,EACV,WAAW,EACX,YAAY,EACZ,oBAAoB,EACpB,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAGzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,uCAAuC,EACvC,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAwBhF,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC;AAE9C,MAAM,UAAU,uBAAuB,CAAC,KAAc,EAAE,OAA8B;IACpF,MAAM,UAAU,GAAG,wBAAwB,EAAE,CAAC;IAC9C,MAAM,MAAM,GAAsB;QAChC,cAAc,EAAE,SAAS;QACzB,QAAQ,EAAE,EAAE;QACZ,kBAAkB,EAAE,EAAE;KACvB,CAAC;IACF,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,CAAC,oBAAoB,GAAG,KAAK,CAAC;IACtC,CAAC;IACD,IAAI,CAAC;QACH,mBAAmB,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAC7F,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,yBAAyB,CAAC,UAAU,CAAC,CAAC;QACtC,MAAM,KAAK,CAAC;IACd,CAAC;IAC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AO,EAAE,CAAC;QACZ,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IACtF,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.\n\nimport { createRenderedHost, discardRenderedHostsSince } from './create-rendered-host.js';\nimport type { RenderAttributes } from './create-rendered-host.js';\nimport type { ElementTemplateHost } from './host.js';\nimport {\n EMPTY_OBJ,\n beforeDiff,\n beforeDiff2,\n cleanupVNode,\n renderComponentVNode,\n renderWithHooks,\n} from './render-components.js';\nimport { CHILDREN, PARENT } from '../../../shared/render-constants.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID } from '../../protocol/page.js';\nimport type { RuntimeTypedElementAttributes, TypedElementAttributesCommand } from '../../protocol/types.js';\nimport type { ETListItemPlatformInfo } from '../list/list.js';\nimport { __ElementTemplatePage } from '../page/authored-page.js';\nimport {\n createElementTemplateWithReservedHandle,\n getNextElementTemplateId,\n reserveElementTemplateId,\n} from '../template/handle.js';\nimport type { MainThreadDynamicAttrSubtreeHandle } from '../template/main-thread-dynamic-attr-state.js';\nimport { prepareTypedElementAttributes } from '../template/typed-attributes.js';\n\nexport interface MainThreadCreateResult {\n pageAttributes: TypedElementAttributesCommand | null;\n rootRefs: ElementTemplateHandle[];\n rootSubtreeHandles: MainThreadDynamicAttrSubtreeHandle[][];\n}\n\ninterface DirectRenderState extends Omit<MainThreadCreateResult, 'pageAttributes'> {\n pageAttributes: TypedElementAttributesCommand | null | undefined;\n currentListItemSubtreeHandleIds?: Map<number, readonly number[]> | undefined;\n isInsideAuthoredPage?: boolean;\n}\n\ninterface RenderVNode {\n type: unknown;\n props: Record<string, unknown>;\n templateKey?: string;\n [PARENT]?: RenderVNode | undefined;\n [CHILDREN]?: unknown[];\n}\n\ntype RenderContext = Record<string, unknown>;\n\nconst isArray = /* @__PURE__ */ Array.isArray;\n\nexport function renderToElementTemplate(vnode: unknown, context?: RenderContext | null): MainThreadCreateResult {\n const checkpoint = getNextElementTemplateId();\n const result: DirectRenderState = {\n pageAttributes: undefined,\n rootRefs: [],\n rootSubtreeHandles: [],\n };\n if (__DEV__) {\n result.isInsideAuthoredPage = false;\n }\n try {\n /* #__NOINLINE__ */ renderWithHooks(vnode, context, result.rootRefs, renderDirect, result);\n } catch (error) {\n discardRenderedHostsSince(checkpoint);\n throw error;\n }\n result.pageAttributes ??= null;\n return result as MainThreadCreateResult;\n}\n\nfunction validateRoot(result: DirectRenderState, parentType: string | undefined): void {\n if (\n parentType === undefined && result.pageAttributes !== undefined\n && !result.isInsideAuthoredPage\n ) {\n throw new Error('Element Template authored <page /> must wrap all materialized roots.');\n }\n}\n\nfunction renderHost(\n vnode: RenderVNode,\n context: RenderContext,\n output: ElementTemplateHandle[],\n result: DirectRenderState,\n parentType: string | undefined,\n parentSubtreeHandles: MainThreadDynamicAttrSubtreeHandle[] | undefined,\n): void {\n const type = vnode.type as string;\n const props = vnode.templateKey === undefined ? vnode.props : vnode as unknown as Record<string, unknown>;\n const isList = type === 'list';\n const attributes = (isList ? props['attributes'] : props['attributeSlots']) as RenderAttributes;\n const listItemPlatformInfo = props['__listItemPlatformInfo'] as ETListItemPlatformInfo | undefined;\n let deferredListItemMarker = false;\n if (__DEV__) {\n deferredListItemMarker = props['isReady'] !== undefined;\n validateRoot(result, parentType);\n }\n if (!isList && !(type.startsWith('_et_') || type.includes(':_et_'))) {\n cleanupVNode(vnode);\n throw new Error(`Element Template main-thread renderer received an uncompiled host vnode: ${type}`);\n }\n\n // Recursive locals retain the inputs until children finish. Only native\n // child arrays and the root/list-item ref collector survive this call.\n const subtreeHandles = parentType === undefined || parentType === 'list' ? [] : parentSubtreeHandles!;\n let childSlots: ElementTemplateHandle[][] | undefined;\n let listItemSubtreeHandleIds: Map<number, readonly number[]> | undefined;\n if (isList) {\n const previousListItemSubtreeHandleIds = result.currentListItemSubtreeHandleIds;\n try {\n if (__DEV__) {\n for (const name in props) {\n if (name.startsWith('$') && name !== '$0') {\n throw new Error('Element Template typed list only supports logical slot $0.');\n }\n }\n }\n const children = props['$0'];\n if (children != null && children !== true && children !== false) {\n const refs: ElementTemplateHandle[] = [];\n childSlots = [refs];\n listItemSubtreeHandleIds = new Map();\n result.currentListItemSubtreeHandleIds = listItemSubtreeHandleIds;\n renderDirect(children, context, vnode, refs, result, type, subtreeHandles);\n }\n } finally {\n result.currentListItemSubtreeHandleIds = previousListItemSubtreeHandleIds;\n cleanupVNode(vnode);\n }\n } else {\n // Ordered inputs belong to the caller. Named inputs are collected into a\n // renderer-owned array that can also hold the resulting native refs.\n let childrenBySlot = props['slotChildren'] as unknown[] | undefined;\n if (vnode.templateKey === undefined && childrenBySlot === undefined) {\n for (const name in props) {\n if (name.startsWith('$')) {\n const children = props[name];\n if (children == null || children === true || children === false) continue;\n (childrenBySlot ??= [])[+name.slice(1)] = children;\n }\n }\n childSlots = childrenBySlot as ElementTemplateHandle[][] | undefined;\n }\n if (childrenBySlot !== undefined) {\n for (let slotId = 0; slotId < childrenBySlot.length; slotId++) {\n const children = childrenBySlot[slotId];\n if (children == null || children === true || children === false) continue;\n const refs = (childSlots ??= [])[slotId] = [];\n renderDirect(children, context, vnode, refs, result, type, subtreeHandles);\n }\n }\n cleanupVNode(vnode);\n }\n\n if (__DEV__ && !isList && parentType === 'list') {\n if (deferredListItemMarker) {\n throw new Error('Element Template typed list does not support deferred list items.');\n }\n if (listItemPlatformInfo === undefined) {\n throw new Error('Element Template typed list received a non-list-item root in logical slot $0.');\n }\n }\n const uid = reserveElementTemplateId();\n const ref = /* #__NOINLINE__ */ createRenderedHost(\n uid,\n type,\n attributes,\n childSlots,\n subtreeHandles,\n listItemPlatformInfo,\n vnode.templateKey === undefined ? undefined : vnode as unknown as ElementTemplateHost,\n listItemSubtreeHandleIds,\n );\n output.push(ref);\n if (!isList && parentType === 'list' && subtreeHandles.length > 0) {\n const itemHandleIds: number[] = [];\n for (let index = 0; index < subtreeHandles.length; index += 1) {\n itemHandleIds.push(subtreeHandles[index]!.uid);\n }\n result.currentListItemSubtreeHandleIds!.set(uid, itemHandleIds);\n }\n if (parentType === undefined) {\n result.rootSubtreeHandles.push(subtreeHandles);\n }\n}\n\nfunction renderDirect(\n value: unknown,\n context: RenderContext,\n parent: RenderVNode,\n output: ElementTemplateHandle[],\n result: DirectRenderState,\n parentType?: string,\n subtreeHandles?: MainThreadDynamicAttrSubtreeHandle[],\n): void {\n if (value == null || value === true || value === false || value === '') return;\n\n if (typeof value !== 'object') {\n if (typeof value === 'function') return;\n if (__DEV__) {\n validateRoot(result, parentType);\n if (parentType === 'list') {\n throw new Error('Element Template typed list received text logical child.');\n }\n }\n output.push(createElementTemplateWithReservedHandle(\n reserveElementTemplateId(),\n '_et_builtin_raw_text',\n null,\n [(value as string | number) + ''],\n [],\n ));\n if (parentType === undefined) result.rootSubtreeHandles.push([]);\n return;\n }\n\n if (isArray(value)) {\n parent[CHILDREN] = value;\n for (let index = 0; index < value.length; index++) {\n const child: unknown = value[index];\n if (child == null || typeof child === 'boolean') continue;\n renderDirect(child, context, parent, output, result, parentType, subtreeHandles);\n }\n return;\n }\n\n const vnode = value as RenderVNode;\n vnode[PARENT] = parent;\n if (beforeDiff) beforeDiff(vnode);\n if (beforeDiff2) beforeDiff2(vnode, EMPTY_OBJ);\n const type = vnode.type;\n const props = vnode.props;\n if (typeof type === 'function') {\n if (type === __ElementTemplatePage) {\n if (__DEV__) {\n if (parentType !== undefined) {\n throw new Error('Element Template authored <page /> must be the outermost element.');\n }\n if (result.pageAttributes !== undefined) {\n throw new Error('Element Template does not support multiple authored <page /> elements.');\n }\n if (result.rootRefs.length !== 0) {\n throw new Error('Element Template authored <page /> must wrap all materialized roots.');\n }\n result.isInsideAuthoredPage = true;\n }\n result.pageAttributes = prepareTypedElementAttributes(\n ELEMENT_TEMPLATE_PAGE_HANDLE_ID,\n props['attributes'] as RuntimeTypedElementAttributes | undefined,\n );\n }\n /* #__NOINLINE__ */ renderComponentVNode(\n vnode,\n type,\n props,\n context,\n output,\n renderDirect,\n result,\n parentType,\n subtreeHandles,\n );\n if (__DEV__ && type === __ElementTemplatePage) result.isInsideAuthoredPage = false;\n return;\n }\n if (typeof type === 'string') {\n /* #__NOINLINE__ */ renderHost(vnode, context, output, result, parentType, subtreeHandles);\n return;\n }\n if (__DEV__) {\n cleanupVNode(vnode);\n throw new Error('Element Template main-thread renderer received an invalid vnode.');\n }\n}\n"]}
|
|
@@ -9,12 +9,10 @@ import { getReloadVersion } from '../../../core/reload-version.js';
|
|
|
9
9
|
import { profileEnd, profileStart } from '../../debug/profile.js';
|
|
10
10
|
import { ElementTemplateLifecycleConstant } from '../../protocol/lifecycle-constant.js';
|
|
11
11
|
import { ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../../protocol/page.js';
|
|
12
|
-
import { flushInitialElementTemplateListUpdates } from '../list/list.js';
|
|
13
12
|
import { __page } from '../page/page.js';
|
|
14
13
|
import { __root } from '../page/root-instance.js';
|
|
15
14
|
import { insertElementTemplateSubtree } from '../template/handle.js';
|
|
16
15
|
import { applyPendingMainThreadRefAttachments } from '../template/main-thread-dynamic-attr-state.js';
|
|
17
|
-
import { getElementTemplateNativeRef } from '../template/registry.js';
|
|
18
16
|
import { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from '../template/typed-attributes.js';
|
|
19
17
|
function renderMainThread() {
|
|
20
18
|
let rendered;
|
|
@@ -39,7 +37,6 @@ function renderMainThread() {
|
|
|
39
37
|
const rootRef = rootRefs[index];
|
|
40
38
|
insertElementTemplateSubtree(__page, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX, rootRef, null, rootSubtreeHandles[index]);
|
|
41
39
|
}
|
|
42
|
-
flushInitialListUpdates();
|
|
43
40
|
applyPendingMainThreadRefAttachments();
|
|
44
41
|
}
|
|
45
42
|
finally {
|
|
@@ -60,15 +57,5 @@ function renderMainThread() {
|
|
|
60
57
|
profileEnd();
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
|
-
function flushInitialListUpdates() {
|
|
64
|
-
const results = flushInitialElementTemplateListUpdates();
|
|
65
|
-
for (let index = 0; index < results.length; index += 1) {
|
|
66
|
-
const result = results[index];
|
|
67
|
-
const listRef = getElementTemplateNativeRef(result.uid);
|
|
68
|
-
if (listRef) {
|
|
69
|
-
__SetAttributeOfElementTemplate(listRef, TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, result.attributes);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
60
|
export { renderMainThread };
|
|
74
61
|
//# sourceMappingURL=render-main-thread.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-main-thread.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/render-main-thread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,gCAAgC,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,EAAE,qCAAqC,EAAE,MAAM,wBAAwB,CAAC;AAE/E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"render-main-thread.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/render/render-main-thread.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,wBAAwB,C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CAAqC,EACrC,OAAO,EACP,IAAI,EACJ,kBAAkB,CAAC,KAAK,CAAE,CAC3B,CAAC;QACJ,CAAC;QACD,oCAAoC,EAAE,CAAC;IACzC,CAAC;YAAS,CAAC;QACT,UAAU,EAAE,CAAC;IACf,CAAC;IAED,YAAY,CAAC,qCAAqC,CAAC,CAAC;IACpD,IAAI,CAAC;QACH,MAAM,OAAO,GAAwC;YACnD,IAAI,EAAE,0BAA0B,CAAC,MAAM,CAAuB;YAC9D,aAAa,EAAE,gBAAgB,EAAE;SAClC,CAAC;QAEF,IAAI,CAAC,YAAY,EAAE,CAAC,aAAa,CAAC;YAChC,IAAI,EAAE,gCAAgC,CAAC,OAAO;YAC9C,IAAI,EAAE,OAAO;SACd,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,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\n/**\n * Implements the IFR (Instant First-Frame Rendering) on main thread.\n */\n\nimport { renderToElementTemplate } from './render-direct.js';\nimport { getReloadVersion } from '../../../core/reload-version.js';\nimport { profileEnd, profileStart } from '../../debug/profile.js';\nimport { ElementTemplateLifecycleConstant } from '../../protocol/lifecycle-constant.js';\nimport { ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX } from '../../protocol/page.js';\nimport type { ElementTemplateHydrateCommitContext, SerializedPageRoot } from '../../protocol/types.js';\nimport { __page } from '../page/page.js';\nimport { __root } from '../page/root-instance.js';\nimport { insertElementTemplateSubtree } from '../template/handle.js';\nimport { applyPendingMainThreadRefAttachments } from '../template/main-thread-dynamic-attr-state.js';\nimport { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from '../template/typed-attributes.js';\n\nfunction renderMainThread(): void {\n let rendered;\n profileStart('ReactLynx::renderMainThread');\n try {\n rendered = renderToElementTemplate(__root.__jsx, undefined);\n } catch (error) {\n // Like Snapshot, any failure during synchronous rendering is reported at\n // the lifecycle boundary before committing an empty result.\n lynx.reportError(error as Error);\n rendered = { pageAttributes: null, rootRefs: [], rootSubtreeHandles: [] };\n } finally {\n profileEnd();\n }\n\n profileStart('ReactLynx::commitElementTemplate');\n try {\n const { pageAttributes, rootRefs, rootSubtreeHandles } = rendered;\n __SetAttributeOfElementTemplate(__page, TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, pageAttributes);\n for (let index = 0; index < rootRefs.length; index += 1) {\n const rootRef = rootRefs[index]!;\n insertElementTemplateSubtree(\n __page,\n ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX,\n rootRef,\n null,\n rootSubtreeHandles[index]!,\n );\n }\n applyPendingMainThreadRefAttachments();\n } finally {\n profileEnd();\n }\n\n profileStart('ReactLynx::packSerializedETInstance');\n try {\n const payload: ElementTemplateHydrateCommitContext = {\n page: __SerializeElementTemplate(__page) as SerializedPageRoot,\n reloadVersion: getReloadVersion(),\n };\n\n lynx.getJSContext().dispatchEvent({\n type: ElementTemplateLifecycleConstant.hydrate,\n data: payload,\n });\n } finally {\n profileEnd();\n }\n}\n\nexport { renderMainThread };\n"]}
|
|
@@ -9,8 +9,16 @@ import { prepareGestureForNative } from '../../prop-adapters/gesture.js';
|
|
|
9
9
|
import { prepareRefAttrSlot } from '../../prop-adapters/ref.js';
|
|
10
10
|
import { prepareSpreadAttrSlot, prepareTypedSpreadAttrSlot } from '../../prop-adapters/spread.js';
|
|
11
11
|
export const __etAttrPlanMap = Object.create(null);
|
|
12
|
+
const TYPED_LIST_TEMPLATE_TYPE = 'list';
|
|
13
|
+
const TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX = 0;
|
|
14
|
+
const TYPED_LIST_DYNAMIC_SLOT_KINDS = new Map([
|
|
15
|
+
[TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, 'spread'],
|
|
16
|
+
]);
|
|
12
17
|
const mainThreadDynamicAttrSlotKinds = new Map();
|
|
13
18
|
export function getMainThreadDynamicAttrSlotKinds(templateType) {
|
|
19
|
+
if (templateType === TYPED_LIST_TEMPLATE_TYPE) {
|
|
20
|
+
return TYPED_LIST_DYNAMIC_SLOT_KINDS;
|
|
21
|
+
}
|
|
14
22
|
const cached = mainThreadDynamicAttrSlotKinds.get(templateType);
|
|
15
23
|
if (cached !== undefined) {
|
|
16
24
|
return cached ?? undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attr-slot-plan.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/attr-slot-plan.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAsBlG,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAkB,CAAC;AAIpE,MAAM,8BAA8B,GAAG,IAAI,GAAG,EAG3C,CAAC;AAEJ,MAAM,UAAU,iCAAiC,CAC/C,YAAoB;IAEpB,MAAM,MAAM,GAAG,8BAA8B,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAChE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,MAAM,IAAI,SAAS,CAAC;IAC7B,CAAC;IAED,MAAM,QAAQ,GAAG,eAAe,CAAC,YAAY,CAAC,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O,EAAE,gBAAgB,EAAE,CAAC,aAAa,CAAC,CAC3C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,SAAiB,EACjB,aAAqB,EACrB,KAAc,EACd,OAA8B;IAE9B,OAAO,uBAAuB,CAC5B,KAAK,EACL,OAAO,EAAE,qBAAqB,CAAC,aAAa,CAAwC,CAC9C,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,QAAgB,EAChB,aAAqB,EACrB,KAAc,EACd,OAA8B;IAE9B,OAAO,qBAAqB,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,QAAgB,EAChB,aAAqB,EACrB,KAAc;IAEd,OAAO,0BAA0B,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,4EAA4E;IAC5E,uEAAuE;IACvE,KAAK,MAAM,WAAW,IAAI,eAAe,EAAE,CAAC;QAC1C,OAAO,eAAe,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IACD,8BAA8B,CAAC,KAAK,EAAE,CAAC;AACzC,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 { prepareMTEventCtxForNative } from './main-thread-event-ctx.js';\nimport { prepareMTRefForNative } from './main-thread-ref-ctx.js';\nimport { isMainThreadFunction } from '../../../core/main-thread-function.js';\nimport { getEventValue } from '../../prop-adapters/event-value.js';\nimport { prepareGestureForNative } from '../../prop-adapters/gesture.js';\nimport type { GestureSlotValue } from '../../prop-adapters/gesture.js';\nimport { prepareRefAttrSlot } from '../../prop-adapters/ref.js';\nimport { prepareSpreadAttrSlot, prepareTypedSpreadAttrSlot } from '../../prop-adapters/spread.js';\nimport type { SerializableValue } from '../../protocol/types.js';\n\nexport interface EtAttrAdapterContext {\n previousPreparedSlots: readonly unknown[];\n previousRawSlots: readonly unknown[];\n}\n\nexport type EtAttrAdapter = (\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n context?: EtAttrAdapterContext,\n) => SerializableValue | null;\n\nexport type EtAttrPlan = (number | EtAttrAdapter)[];\n\nexport type EtAttrPlanMap = Record<\n string,\n EtAttrPlan | undefined\n>;\n\nexport const __etAttrPlanMap = Object.create(null) as EtAttrPlanMap;\n\nexport type MainThreadDynamicAttrKind = 'mt-event' | 'mt-ref' | 'gesture' | 'spread';\n\nconst mainThreadDynamicAttrSlotKinds = new Map<\n string,\n ReadonlyMap<number, MainThreadDynamicAttrKind> | null\n>();\n\nexport function getMainThreadDynamicAttrSlotKinds(\n templateType: string,\n): ReadonlyMap<number, MainThreadDynamicAttrKind> | undefined {\n const cached = mainThreadDynamicAttrSlotKinds.get(templateType);\n if (cached !== undefined) {\n return cached ?? undefined;\n }\n\n const attrPlan = __etAttrPlanMap[templateType];\n let slotKinds: Map<number, MainThreadDynamicAttrKind> | undefined;\n if (attrPlan) {\n for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {\n const adapter = attrPlan[planIndex + 1];\n let kind: MainThreadDynamicAttrKind | undefined;\n if (adapter === adaptMTEventAttrSlot) {\n kind = 'mt-event';\n } else if (adapter === adaptGestureAttrSlot) {\n kind = 'gesture';\n } else if (adapter === adaptMTRefAttrSlot) {\n kind = 'mt-ref';\n } else if (adapter === adaptSpreadAttrSlot) {\n kind = 'spread';\n }\n if (kind) {\n (slotKinds ??= new Map()).set(attrPlan[planIndex] as number, kind);\n }\n }\n }\n mainThreadDynamicAttrSlotKinds.set(templateType, slotKinds ?? null);\n return slotKinds;\n}\n\nexport function hasMainThreadRefAttrSlot(templateType: string): boolean {\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n if (!slotKinds) {\n return false;\n }\n for (const kind of slotKinds.values()) {\n if (kind === 'mt-ref' || kind === 'spread') {\n return true;\n }\n }\n return false;\n}\n\nexport function adaptEventAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n): SerializableValue | null {\n if (value === null || value === undefined || value === false) {\n return null;\n }\n return getEventValue(handleId, attrSlotIndex);\n}\n\nexport function adaptMTEventAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n context?: EtAttrAdapterContext,\n): SerializableValue | null {\n if (value === null || value === undefined || value === false) {\n return null;\n }\n if (!isMainThreadFunction(value)) {\n if (__DEV__) {\n lynx.reportError(\n new Error(`ElementTemplate main-thread event slot ${handleId}:${attrSlotIndex} expects a worklet ctx object.`),\n );\n }\n return null;\n }\n return prepareMTEventCtxForNative(\n value,\n context?.previousPreparedSlots?.[attrSlotIndex],\n context?.previousRawSlots?.[attrSlotIndex],\n );\n}\n\nexport function adaptRefAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n): SerializableValue | null {\n return prepareRefAttrSlot(handleId, attrSlotIndex, value);\n}\n\nexport function adaptMTRefAttrSlot(\n _handleId: number,\n attrSlotIndex: number,\n value: unknown,\n context?: EtAttrAdapterContext,\n): SerializableValue | null {\n return prepareMTRefForNative(\n value,\n context?.previousPreparedSlots?.[attrSlotIndex],\n context?.previousRawSlots?.[attrSlotIndex],\n );\n}\n\nexport function adaptGestureAttrSlot(\n _handleId: number,\n attrSlotIndex: number,\n value: unknown,\n context?: EtAttrAdapterContext,\n): SerializableValue | null {\n return prepareGestureForNative(\n value,\n context?.previousPreparedSlots[attrSlotIndex] as GestureSlotValue | null | undefined,\n ) as unknown as SerializableValue | null;\n}\n\nexport function adaptSpreadAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n context?: EtAttrAdapterContext,\n): SerializableValue | null {\n return prepareSpreadAttrSlot(handleId, attrSlotIndex, value, context);\n}\n\nexport function adaptTypedSpreadAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n): SerializableValue | null {\n return prepareTypedSpreadAttrSlot(handleId, attrSlotIndex, value);\n}\n\nexport function clearEtAttrPlanMap(): void {\n // The compiled output assigns into the exported side table directly, so the\n // object identity must stay stable when tests or teardown clear state.\n for (const templateKey in __etAttrPlanMap) {\n delete __etAttrPlanMap[templateKey];\n }\n mainThreadDynamicAttrSlotKinds.clear();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"attr-slot-plan.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/attr-slot-plan.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAsBlG,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAkB,CAAC;AAIpE,MAAM,wBAAwB,GAAG,MAAM,CAAC;AACxC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAC9C,MAAM,6BAA6B,GAAmD,IAAI,GAAG,CAAC;IAC5F,CAAC,mCAAmC,EAAE,QAAQ,CAAC;CAChD,CAAC,CAAC;AAEH,MAAM,8BAA8B,GAAG,IAAI,GAAG,EAG3C,CAAC;AAEJ,MAAM,UAAU,iCAAiC,CAC/C,YAAoB;IAEpB,IAAI,YAAY,KAAK,wBAAwB,EAAE,CAAC;QAC9C,OAAO,6BAA6B,CAAC;IACvC,CAAC;IACD,MAAM,MAAM,GAAG,8BAA8B,CAAC,GAAG,CAAC,YAAY,CAAC,CA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ChC,SAAiB,EACjB,aAAqB,EACrB,KAAc,EACd,OAA8B;IAE9B,OAAO,qBAAqB,CAC1B,KAAK,EACL,OAAO,EAAE,qBAAqB,EAAE,CAAC,aAAa,CAAC,EAC/C,OAAO,EAAE,gBAAgB,EAAE,CAAC,aAAa,CAAC,CAC3C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,SAAiB,EACjB,aAAqB,EACrB,KAAc,EACd,OAA8B;IAE9B,OAAO,uBAAuB,CAC5B,KAAK,EACL,OAAO,EAAE,qBAAqB,CAAC,aAAa,CAAwC,CAC9C,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,QAAgB,EAChB,aAAqB,EACrB,KAAc,EACd,OAA8B;IAE9B,OAAO,qBAAqB,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,QAAgB,EAChB,aAAqB,EACrB,KAAc;IAEd,OAAO,0BAA0B,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,4EAA4E;IAC5E,uEAAuE;IACvE,KAAK,MAAM,WAAW,IAAI,eAAe,EAAE,CAAC;QAC1C,OAAO,eAAe,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IACD,8BAA8B,CAAC,KAAK,EAAE,CAAC;AACzC,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 { prepareMTEventCtxForNative } from './main-thread-event-ctx.js';\nimport { prepareMTRefForNative } from './main-thread-ref-ctx.js';\nimport { isMainThreadFunction } from '../../../core/main-thread-function.js';\nimport { getEventValue } from '../../prop-adapters/event-value.js';\nimport { prepareGestureForNative } from '../../prop-adapters/gesture.js';\nimport type { GestureSlotValue } from '../../prop-adapters/gesture.js';\nimport { prepareRefAttrSlot } from '../../prop-adapters/ref.js';\nimport { prepareSpreadAttrSlot, prepareTypedSpreadAttrSlot } from '../../prop-adapters/spread.js';\nimport type { SerializableValue } from '../../protocol/types.js';\n\nexport interface EtAttrAdapterContext {\n previousPreparedSlots: readonly unknown[];\n previousRawSlots: readonly unknown[];\n}\n\nexport type EtAttrAdapter = (\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n context?: EtAttrAdapterContext,\n) => SerializableValue | null;\n\nexport type EtAttrPlan = (number | EtAttrAdapter)[];\n\nexport type EtAttrPlanMap = Record<\n string,\n EtAttrPlan | undefined\n>;\n\nexport const __etAttrPlanMap = Object.create(null) as EtAttrPlanMap;\n\nexport type MainThreadDynamicAttrKind = 'mt-event' | 'mt-ref' | 'gesture' | 'spread';\n\nconst TYPED_LIST_TEMPLATE_TYPE = 'list';\nconst TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX = 0;\nconst TYPED_LIST_DYNAMIC_SLOT_KINDS: ReadonlyMap<number, MainThreadDynamicAttrKind> = new Map([\n [TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, 'spread'],\n]);\n\nconst mainThreadDynamicAttrSlotKinds = new Map<\n string,\n ReadonlyMap<number, MainThreadDynamicAttrKind> | null\n>();\n\nexport function getMainThreadDynamicAttrSlotKinds(\n templateType: string,\n): ReadonlyMap<number, MainThreadDynamicAttrKind> | undefined {\n if (templateType === TYPED_LIST_TEMPLATE_TYPE) {\n return TYPED_LIST_DYNAMIC_SLOT_KINDS;\n }\n const cached = mainThreadDynamicAttrSlotKinds.get(templateType);\n if (cached !== undefined) {\n return cached ?? undefined;\n }\n\n const attrPlan = __etAttrPlanMap[templateType];\n let slotKinds: Map<number, MainThreadDynamicAttrKind> | undefined;\n if (attrPlan) {\n for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {\n const adapter = attrPlan[planIndex + 1];\n let kind: MainThreadDynamicAttrKind | undefined;\n if (adapter === adaptMTEventAttrSlot) {\n kind = 'mt-event';\n } else if (adapter === adaptGestureAttrSlot) {\n kind = 'gesture';\n } else if (adapter === adaptMTRefAttrSlot) {\n kind = 'mt-ref';\n } else if (adapter === adaptSpreadAttrSlot) {\n kind = 'spread';\n }\n if (kind) {\n (slotKinds ??= new Map()).set(attrPlan[planIndex] as number, kind);\n }\n }\n }\n mainThreadDynamicAttrSlotKinds.set(templateType, slotKinds ?? null);\n return slotKinds;\n}\n\nexport function hasMainThreadRefAttrSlot(templateType: string): boolean {\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n if (!slotKinds) {\n return false;\n }\n for (const kind of slotKinds.values()) {\n if (kind === 'mt-ref' || kind === 'spread') {\n return true;\n }\n }\n return false;\n}\n\nexport function adaptEventAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n): SerializableValue | null {\n if (value === null || value === undefined || value === false) {\n return null;\n }\n return getEventValue(handleId, attrSlotIndex);\n}\n\nexport function adaptMTEventAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n context?: EtAttrAdapterContext,\n): SerializableValue | null {\n if (value === null || value === undefined || value === false) {\n return null;\n }\n if (!isMainThreadFunction(value)) {\n if (__DEV__) {\n lynx.reportError(\n new Error(`ElementTemplate main-thread event slot ${handleId}:${attrSlotIndex} expects a worklet ctx object.`),\n );\n }\n return null;\n }\n return prepareMTEventCtxForNative(\n value,\n context?.previousPreparedSlots?.[attrSlotIndex],\n context?.previousRawSlots?.[attrSlotIndex],\n );\n}\n\nexport function adaptRefAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n): SerializableValue | null {\n return prepareRefAttrSlot(handleId, attrSlotIndex, value);\n}\n\nexport function adaptMTRefAttrSlot(\n _handleId: number,\n attrSlotIndex: number,\n value: unknown,\n context?: EtAttrAdapterContext,\n): SerializableValue | null {\n return prepareMTRefForNative(\n value,\n context?.previousPreparedSlots?.[attrSlotIndex],\n context?.previousRawSlots?.[attrSlotIndex],\n );\n}\n\nexport function adaptGestureAttrSlot(\n _handleId: number,\n attrSlotIndex: number,\n value: unknown,\n context?: EtAttrAdapterContext,\n): SerializableValue | null {\n return prepareGestureForNative(\n value,\n context?.previousPreparedSlots[attrSlotIndex] as GestureSlotValue | null | undefined,\n ) as unknown as SerializableValue | null;\n}\n\nexport function adaptSpreadAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n context?: EtAttrAdapterContext,\n): SerializableValue | null {\n return prepareSpreadAttrSlot(handleId, attrSlotIndex, value, context);\n}\n\nexport function adaptTypedSpreadAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n): SerializableValue | null {\n return prepareTypedSpreadAttrSlot(handleId, attrSlotIndex, value);\n}\n\nexport function clearEtAttrPlanMap(): void {\n // The compiled output assigns into the exported side table directly, so the\n // object identity must stay stable when tests or teardown clear state.\n for (const templateKey in __etAttrPlanMap) {\n delete __etAttrPlanMap[templateKey];\n }\n mainThreadDynamicAttrSlotKinds.clear();\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { MainThreadDynamicAttrSubtreeHandle } from './main-thread-dynamic-attr-state.js';
|
|
2
|
-
import type { RuntimeChildSlots, RuntimeOptions, RuntimeTypedElementAttributes,
|
|
2
|
+
import type { RuntimeChildSlots, RuntimeOptions, RuntimeTypedElementAttributes, SerializableValue } from '../../protocol/types.js';
|
|
3
3
|
export declare function getNextElementTemplateId(): number;
|
|
4
4
|
export declare function reserveElementTemplateId(): number;
|
|
5
|
-
export declare function createElementTemplateWithReservedHandle(handleId: number, templateKey: string, bundleUrl: string | null | undefined, attributeSlots: SerializableValue[] | null | undefined, childSlots: RuntimeChildSlots | null | undefined, hasDynamicAttributes?: boolean): ElementTemplateHandle;
|
|
6
|
-
export declare function createTypedElementTemplateWithReservedHandle(handleId: number, type: string, attributes: RuntimeTypedElementAttributes | null | undefined, childSlots: RuntimeChildSlots | null | undefined, options: RuntimeOptions |
|
|
5
|
+
export declare function createElementTemplateWithReservedHandle(handleId: number, templateKey: string, bundleUrl: string | null | undefined, attributeSlots: SerializableValue[] | null | undefined, childSlots: RuntimeChildSlots | null | undefined, hasDynamicAttributes?: boolean, options?: RuntimeOptions | null): ElementTemplateHandle;
|
|
6
|
+
export declare function createTypedElementTemplateWithReservedHandle(handleId: number, type: string, attributes: RuntimeTypedElementAttributes | null | undefined, childSlots: RuntimeChildSlots | null | undefined, options: RuntimeOptions | null | undefined): ElementTemplateHandle;
|
|
7
7
|
export declare function insertElementTemplateSubtree(targetRef: ElementTemplateHandle, childSlotIndex: number, childRef: ElementTemplateHandle, referenceRef: ElementTemplateHandle | null, subtreeHandles: readonly MainThreadDynamicAttrSubtreeHandle[] | null): void;
|
|
8
8
|
export declare function resetTemplateId(): void;
|
|
9
9
|
export declare function destroyElementTemplateId(id: number): void;
|