@lynx-js/react 0.128.0 → 0.129.1
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 +34 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/entry-re-eval.test.ts +161 -0
- package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
- package/runtime/__test__/core/reload-scoped-dual-thread-communication.test.ts +129 -0
- package/runtime/__test__/core/thread-function-call.test.ts +1 -0
- package/runtime/__test__/element-template/fixtures/background/render/_shared.tsx +2 -0
- package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
- package/runtime/__test__/element-template/native/index.test.ts +8 -0
- package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
- package/runtime/__test__/element-template/native/main-thread-ref-init-value.test.ts +100 -0
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +83 -0
- package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +104 -0
- package/runtime/__test__/element-template/native/reload.test.ts +79 -1
- package/runtime/__test__/element-template/runtime/background/commit-hook.test.ts +104 -47
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +7 -1
- package/runtime/__test__/element-template/runtime/background/re-eval-reload.test.ts +69 -0
- package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
- package/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts +31 -5
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +214 -10
- package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +2 -0
- package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
- package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +121 -26
- package/runtime/__test__/element-template/runtime/template/main-thread-function.test.ts +89 -2
- package/runtime/__test__/element-template/test-utils/debug/compiledFixtureModule.ts +5 -0
- package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
- package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
- package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
- package/runtime/__test__/shared/component-stack.test.ts +211 -0
- package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
- package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
- package/runtime/__test__/snapshot/lifecycle/re-eval-reload.test.jsx +114 -0
- package/runtime/__test__/snapshot/lifecycle/reload-background-function.test.jsx +169 -0
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-background.test.jsx +63 -0
- package/runtime/__test__/snapshot/lifecycle/reload-delayed-main-thread.test.jsx +103 -0
- package/runtime/__test__/snapshot/lifecycle.test.jsx +61 -1
- package/runtime/__test__/snapshot/lynx/lazy-effect-scheduling.test.jsx +105 -0
- package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
- package/runtime/__test__/snapshot/preact.test.jsx +0 -3
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
- package/runtime/__test__/snapshot/ssr.test.jsx +2 -2
- package/runtime/__test__/snapshot/worklet/runOnBackground.test.js +6 -11
- package/runtime/__test__/snapshot/worklet/runOnMainThread.test.jsx +1 -1
- package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +24 -1
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +27 -1
- package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +46 -0
- package/runtime/__test__/worklet-runtime/runOnMainThread.test.js +3 -3
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
- package/runtime/lazy/element-template-internal.js +0 -1
- package/runtime/lazy/internal.js +1 -1
- package/runtime/lazy/jsx-dev-runtime.js +1 -1
- package/runtime/lazy/jsx-runtime.js +1 -1
- package/runtime/lazy/legacy-react-runtime.js +1 -1
- package/runtime/lazy/react-lepus.js +1 -1
- package/runtime/lazy/react.js +1 -1
- package/runtime/lib/core/background-function/exec-map.d.ts +2 -0
- package/runtime/lib/core/background-function/exec-map.js +7 -0
- package/runtime/lib/core/background-function/exec-map.js.map +1 -1
- package/runtime/lib/core/background-function/run-on-background.js +15 -16
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
- package/runtime/lib/core/capture-main-thread-object.js +2 -1
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
- package/runtime/lib/core/card-lifetime.d.ts +5 -0
- package/runtime/lib/core/card-lifetime.js +17 -0
- package/runtime/lib/core/card-lifetime.js.map +1 -0
- package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
- package/runtime/lib/core/entry-reload.d.ts +7 -0
- package/runtime/lib/core/entry-reload.js +49 -0
- package/runtime/lib/core/entry-reload.js.map +1 -0
- package/runtime/lib/core/lynx/lazy-bundle.js +5 -2
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
- package/runtime/lib/core/lynx-data-processors.js +3 -0
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/core/main-thread-ref-id.js +4 -4
- package/runtime/lib/core/main-thread-ref-id.js.map +1 -1
- package/runtime/lib/core/reload-scoped-event.d.ts +5 -0
- package/runtime/lib/core/reload-scoped-event.js +26 -0
- package/runtime/lib/core/reload-scoped-event.js.map +1 -0
- package/runtime/lib/core/reload-version.js +4 -3
- package/runtime/lib/core/reload-version.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.d.ts +2 -0
- package/runtime/lib/core/runtime-destroy.js +10 -1
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/core/thread-function-call/main-thread.js +5 -4
- package/runtime/lib/core/thread-function-call/main-thread.js.map +1 -1
- package/runtime/lib/core/thread-function-call/return-value.js +6 -5
- package/runtime/lib/core/thread-function-call/return-value.js.map +1 -1
- package/runtime/lib/document.js +0 -5
- package/runtime/lib/document.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js +24 -22
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/hydration-listener.js +2 -6
- package/runtime/lib/element-template/background/hydration-listener.js.map +1 -1
- package/runtime/lib/element-template/client/root.d.ts +1 -1
- package/runtime/lib/element-template/client/root.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +2 -2
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +1 -1
- package/runtime/lib/element-template/internal.js +0 -13
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.js.map +1 -1
- package/runtime/lib/element-template/main-thread-ref-init-value.d.ts +3 -0
- package/runtime/lib/element-template/main-thread-ref-init-value.js +38 -0
- package/runtime/lib/element-template/main-thread-ref-init-value.js.map +1 -0
- package/runtime/lib/element-template/native/flush.d.ts +1 -0
- package/runtime/lib/element-template/native/flush.js +9 -0
- package/runtime/lib/element-template/native/flush.js.map +1 -0
- package/runtime/lib/element-template/native/index.js +2 -0
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/native/main-thread-api.js +3 -7
- package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js +10 -2
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +58 -54
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-background.d.ts +1 -1
- package/runtime/lib/element-template/native/reload-background.js +12 -1
- package/runtime/lib/element-template/native/reload-background.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.d.ts +6 -0
- package/runtime/lib/element-template/native/reload-main-thread.js +20 -3
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.d.ts +2 -1
- package/runtime/lib/element-template/protocol/lifecycle-constant.js +1 -0
- package/runtime/lib/element-template/protocol/lifecycle-constant.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +0 -2
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
- package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js +4 -0
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -1
- 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 +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +41 -21
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
- package/runtime/lib/internal.d.ts +1 -1
- package/runtime/lib/internal.js +1 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +2 -125
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/shared/component-stack.d.ts +0 -4
- package/runtime/lib/shared/component-stack.js +21 -5
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/shared/index-map.d.ts +4 -1
- package/runtime/lib/shared/index-map.js +5 -2
- package/runtime/lib/shared/index-map.js.map +1 -1
- package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
- package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
- package/runtime/lib/snapshot/lifecycle/destroy.js +6 -0
- package/runtime/lib/snapshot/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.d.ts +6 -2
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js +21 -18
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.d.ts +9 -2
- package/runtime/lib/snapshot/lifecycle/reload.js +29 -8
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/list/list.js +3 -2
- package/runtime/lib/snapshot/list/list.js.map +1 -1
- package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
- package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +14 -11
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
- package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.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/list.js +2 -1
- package/runtime/lib/snapshot/snapshot/list.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.d.ts +4 -2
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js +11 -11
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +1 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +6 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ctx.d.ts +1 -1
- package/runtime/lib/snapshot/worklet/ctx.js +6 -1
- package/runtime/lib/snapshot/worklet/ctx.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js +6 -0
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js +3 -1
- package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +8 -1
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/listeners.js +2 -2
- package/runtime/lib/worklet-runtime/listeners.js.map +1 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.js +3 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -1
- package/runtime/lib/worklet-runtime/runOnMainThread.js +4 -3
- package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/background-function/exec-map.ts +9 -0
- package/runtime/src/core/background-function/run-on-background.ts +14 -16
- package/runtime/src/core/capture-main-thread-object.ts +2 -1
- package/runtime/src/core/card-lifetime.ts +18 -0
- package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
- package/runtime/src/core/entry-reload.ts +63 -0
- package/runtime/src/core/lynx/lazy-bundle.ts +5 -2
- package/runtime/src/core/lynx-data-processors.ts +124 -1
- package/runtime/src/core/main-thread-ref-id.ts +5 -4
- package/runtime/src/core/reload-scoped-event.ts +35 -0
- package/runtime/src/core/reload-version.ts +5 -3
- package/runtime/src/core/runtime-destroy.ts +12 -1
- package/runtime/src/core/thread-function-call/main-thread.ts +4 -4
- package/runtime/src/core/thread-function-call/return-value.ts +6 -5
- package/runtime/src/document.ts +0 -6
- package/runtime/src/element-template/background/commit-hook.ts +32 -23
- package/runtime/src/element-template/background/hydration-listener.ts +2 -6
- package/runtime/src/element-template/client/root.ts +1 -3
- package/runtime/src/element-template/index.ts +2 -2
- package/runtime/src/element-template/internal.ts +0 -20
- package/runtime/src/element-template/lynx/env.ts +1 -1
- package/runtime/src/element-template/main-thread-ref-init-value.ts +44 -0
- package/runtime/src/element-template/native/flush.ts +10 -0
- package/runtime/src/element-template/native/index.ts +2 -0
- package/runtime/src/element-template/native/main-thread-api.ts +3 -6
- package/runtime/src/element-template/native/mts-destroy.ts +10 -2
- package/runtime/src/element-template/native/patch-listener.ts +62 -62
- package/runtime/src/element-template/native/reload-background.ts +13 -1
- package/runtime/src/element-template/native/reload-main-thread.ts +32 -3
- package/runtime/src/element-template/protocol/lifecycle-constant.ts +1 -0
- package/runtime/src/element-template/protocol/types.ts +0 -15
- package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
- package/runtime/src/element-template/runtime/patch.ts +5 -0
- package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
- package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +51 -21
- package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +2 -2
- package/runtime/src/element-template/types.d.ts +6 -0
- package/runtime/src/internal.ts +1 -1
- package/runtime/src/lynx-api.ts +2 -124
- package/runtime/src/shared/component-stack.ts +22 -5
- package/runtime/src/shared/index-map.ts +3 -2
- package/runtime/src/snapshot/lifecycle/destroy.ts +7 -0
- package/runtime/src/snapshot/lifecycle/event/firstScreenSync.ts +26 -19
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
- package/runtime/src/snapshot/lifecycle/reload.ts +47 -11
- package/runtime/src/snapshot/list/list.ts +9 -2
- package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
- package/runtime/src/snapshot/lynx/calledByNative.ts +14 -13
- package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
- package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
- package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
- package/runtime/src/snapshot/snapshot/list.ts +5 -1
- package/runtime/src/snapshot/snapshot/snapshotInstanceManager.ts +19 -12
- package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +10 -1
- package/runtime/src/snapshot/worklet/ctx.ts +10 -1
- package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +6 -0
- package/runtime/src/worklet-runtime/README.md +33 -0
- package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
- package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
- package/runtime/src/worklet-runtime/delayRunOnBackground.ts +3 -1
- package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +8 -1
- package/runtime/src/worklet-runtime/listeners.ts +4 -7
- package/runtime/src/worklet-runtime/mainThreadObject.ts +2 -1
- package/runtime/src/worklet-runtime/runOnMainThread.ts +4 -3
- package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
- package/runtime/types/types.d.ts +3 -1
- package/runtime/vitest.config.ts +0 -2
- package/testing-library/.turbo/turbo-build.log +7 -7
- package/testing-library/src/__tests__/act.test.jsx +0 -7
- package/testing-library/src/__tests__/alog.test.jsx +12 -54
- package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
- package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
- package/testing-library/src/__tests__/worklet.test.jsx +59 -5
- package/transform/.turbo/turbo-build$colon$wasm.log +63 -136
- package/transform/__test__/defines.spec.js +137 -0
- package/transform/__test__/object-methods.spec.js +79 -0
- package/transform/crates/swc_plugin_worklet/definition_imports.rs +97 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +56 -48
- package/transform/crates/swc_plugin_worklet/lib.rs +400 -595
- package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +6 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +9 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +12 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +1 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +1 -1
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +3 -1
- package/transform/package.json +0 -1
- package/transform/src/lib.rs +173 -12
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +105 -32
- package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +193 -194
- package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
- package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
- package/runtime/lib/snapshot/worklet/hmr.js +0 -28
- package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
- package/runtime/src/snapshot/worklet/hmr.ts +0 -34
- /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
- /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../../src/element-template/runtime/patch.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EACL,oCAAoC,EACpC,uCAAuC,EACvC,sCAAsC,EACtC,sCAAsC,EACtC,6BAA6B,EAC7B,gCAAgC,EAChC,gCAAgC,EAChC,6BAA6B,EAC7B,mCAAmC,EACnC,6BAA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KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QAC7D,OAAO,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;IACzG,CAAC;IACD,IAAI,UAAU,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACrD,OAAO,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;IACrG,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport {\n composeElementTemplateListAttributes,\n createElementTemplateListStateFromItems,\n flushInitialElementTemplateListUpdates,\n flushPendingElementTemplateListUpdates,\n insertElementTemplateListItem,\n markElementTemplateListDestroyed,\n registerElementTemplateListState,\n removeElementTemplateListItem,\n updateElementTemplateListAttributes,\n updateElementTemplateListItem,\n} from './list/list.js';\nimport type { ETListFlushResult, ETListUpdateItem } from './list/list.js';\nimport { insertElementTemplateSubtree } from './template/handle.js';\nimport { elementTemplateRegistry } from './template/registry.js';\nimport { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from './template/typed-attributes.js';\nimport { ElementTemplateUpdateOps } from '../protocol/opcodes.js';\nimport type { ElementTemplateUpdateOp } from '../protocol/opcodes.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID } from '../protocol/page.js';\nimport {\n elementTemplateIdentityKey,\n elementTemplateTypeTag,\n parseElementTemplateType,\n} from '../protocol/template-type.js';\nimport type {\n ElementTemplateHandleSlotsCommand,\n ElementTemplateUpdateCommandStream,\n RuntimeChildSlots,\n RuntimeOptions,\n RuntimeOptionsCommand,\n RuntimeTypedElementAttributes,\n RuntimeTypedListOptions,\n SerializableValue,\n TypedElementAttributesCommand,\n UpdateTypedListItemCommand,\n} from '../protocol/types.js';\nimport {\n deleteMainThreadDynamicAttrStateForSubtree,\n initializeMainThreadDynamicAttrSlots,\n prepareMainThreadDynamicAttrSlotsForNative,\n updateMainThreadEventAttrSlot,\n updateMainThreadRefAttrSlot,\n} from './template/main-thread-dynamic-attr-state.js';\nimport type { MainThreadDynamicAttrSubtreeHandle } from './template/main-thread-dynamic-attr-state.js';\n\nexport type { ElementTemplateUpdateCommandStream } from '../protocol/types.js';\n\n// The update event's JSON transport already normalizes array holes and undefined\n// entries to null. Consume those wire values without copying each attr array.\nexport function applyElementTemplateUpdateCommands(\n stream: ElementTemplateUpdateCommandStream,\n isHydration = false,\n): void {\n let i = 0;\n while (i < stream.length) {\n const op = stream[i++] as ElementTemplateUpdateOp;\n\n switch (op) {\n case ElementTemplateUpdateOps.createTemplate: {\n const handleId = stream[i++] as number;\n const templateKey = stream[i++] as string;\n const bundleUrl = stream[i++] as string | null | undefined;\n const attributeSlots = stream[i++] as SerializableValue[] | null | undefined;\n const childSlots = stream[i++] as ElementTemplateHandleSlotsCommand | null | undefined;\n\n if (__DEV__) {\n const createError = validateCreateTemplatePayload(\n handleId,\n attributeSlots,\n childSlots,\n );\n if (createError) {\n lynx.reportError(createError);\n continue;\n }\n }\n\n const resolvedChildSlots = resolveChildSlots(childSlots);\n if (resolvedChildSlots === undefined) {\n continue;\n }\n\n const templateType = elementTemplateTypeTag(templateKey, bundleUrl);\n const nativeAttributeSlots = prepareMainThreadDynamicAttrSlotsForNative(\n templateType,\n attributeSlots,\n );\n const nativeRef = __CreateElementTemplate(\n templateKey,\n bundleUrl,\n nativeAttributeSlots,\n resolvedChildSlots,\n handleId,\n );\n\n if (nativeRef) {\n elementTemplateRegistry.set(handleId, nativeRef);\n initializeMainThreadDynamicAttrSlots(\n handleId,\n templateType,\n attributeSlots,\n );\n }\n break;\n }\n\n case ElementTemplateUpdateOps.setAttribute: {\n const targetId = stream[i++] as number;\n const attrSlotIndex = stream[i++] as number;\n const value = stream[i++] as SerializableValue | null;\n const nativeRef = resolveTargetHandle(targetId, 'target');\n if (!nativeRef) {\n continue;\n }\n if (attrSlotIndex === TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX) {\n const listAttributes = updateElementTemplateListAttributes(\n targetId,\n value as RuntimeTypedElementAttributes | null,\n );\n if (listAttributes) {\n __SetAttributeOfElementTemplate(nativeRef, attrSlotIndex, listAttributes);\n break;\n }\n }\n __SetAttributeOfElementTemplate(nativeRef, attrSlotIndex, value);\n break;\n }\n\n case ElementTemplateUpdateOps.setMainThreadEvent: {\n const targetId = stream[i++] as number;\n const attrSlotIndex = stream[i++] as number;\n const value = stream[i++] as SerializableValue | null;\n const nativeRef = resolveTargetHandle(targetId, 'target');\n if (!nativeRef) {\n continue;\n }\n __SetAttributeOfElementTemplate(nativeRef, attrSlotIndex, value);\n updateMainThreadEventAttrSlot(targetId, attrSlotIndex, value, isHydration);\n break;\n }\n\n case ElementTemplateUpdateOps.setMainThreadRef: {\n const targetId = stream[i++] as number;\n const attrSlotIndex = stream[i++] as number;\n const value = stream[i++] as SerializableValue | null;\n const nativeRef = resolveTargetHandle(targetId, 'target');\n if (!nativeRef) {\n continue;\n }\n updateMainThreadRefAttrSlot(targetId, attrSlotIndex, value, nativeRef, isHydration);\n break;\n }\n\n case ElementTemplateUpdateOps.createTypedElement: {\n const handleId = stream[i++] as number;\n const type = stream[i++] as string;\n const attributes = stream[i++] as TypedElementAttributesCommand | null | undefined;\n const childSlots = stream[i++] as ElementTemplateHandleSlotsCommand | null | undefined;\n const options = stream[i++] as RuntimeOptionsCommand | null | undefined;\n const isTypedList = type === 'list';\n\n if (__DEV__) {\n const createError = validateCreateHandleId(handleId);\n if (createError) {\n lynx.reportError(createError);\n continue;\n }\n }\n if (__DEV__ && childSlots != null && !Array.isArray(childSlots)) {\n lynx.reportError(\n new Error('ElementTemplate update create childSlots must be an array, null, or undefined.'),\n );\n continue;\n }\n if (\n __DEV__\n && isTypedList\n && !isTypedListChildSlotsEmpty(childSlots)\n ) {\n lynx.reportError(\n new Error('ElementTemplate typed list create must keep logical children in options.listChildren.'),\n );\n continue;\n }\n const resolvedChildSlots = isTypedList ? null : resolveChildSlots(childSlots);\n if (resolvedChildSlots === undefined) {\n continue;\n }\n let resolvedListItems: ETListUpdateItem[] | null = null;\n let nativeOptions: RuntimeOptions | RuntimeTypedListOptions | null | undefined;\n if (isTypedList) {\n const listChildren = getTypedListChildren(options);\n if (__DEV__ && !Array.isArray(listChildren)) {\n lynx.reportError(\n new Error('ElementTemplate typed list create must keep logical children in options.listChildren.'),\n );\n continue;\n }\n resolvedListItems = resolveTypedListItems(listChildren);\n if (resolvedListItems === null) {\n continue;\n }\n nativeOptions = resolveTypedListOptions(options, resolvedListItems);\n } else {\n nativeOptions = options as RuntimeOptions | null | undefined;\n }\n const listState = resolvedListItems\n ? createElementTemplateListStateFromItems(\n resolvedListItems,\n attributes,\n )\n : null;\n const typedAttributes = listState\n ? composeElementTemplateListAttributes(\n undefined,\n listState,\n )\n : attributes;\n\n const nativeRef = __CreateTypedElementTemplate(\n type,\n typedAttributes,\n isTypedList ? null : resolvedChildSlots!,\n handleId,\n nativeOptions,\n );\n\n if (nativeRef) {\n elementTemplateRegistry.set(handleId, nativeRef);\n if (listState) {\n registerElementTemplateListState(handleId, listState, true, nativeRef);\n }\n }\n break;\n }\n\n case ElementTemplateUpdateOps.insertTypedListItem: {\n const listId = stream[i++] as number;\n const item = stream[i++] as UpdateTypedListItemCommand;\n const beforeId = stream[i++] as number;\n const resolvedItem = resolveTypedListItem(item, 'typed list insert item');\n if (resolvedItem === null) {\n continue;\n }\n insertElementTemplateListItem(listId, resolvedItem, beforeId);\n break;\n }\n\n case ElementTemplateUpdateOps.removeTypedListItem: {\n const listId = stream[i++] as number;\n const itemId = stream[i++] as number;\n const removedSubtreeHandleIds = stream[i++] as number[];\n removeElementTemplateListItem(listId, itemId, removedSubtreeHandleIds);\n break;\n }\n\n case ElementTemplateUpdateOps.updateTypedListItem: {\n const listId = stream[i++] as number;\n const item = stream[i++] as UpdateTypedListItemCommand;\n const resolvedItem = resolveTypedListItem(item, 'typed list update item');\n if (resolvedItem === null) {\n continue;\n }\n updateElementTemplateListItem(listId, resolvedItem);\n break;\n }\n\n case ElementTemplateUpdateOps.insertNode: {\n const targetId = stream[i++] as number;\n const childSlotIndex = stream[i++] as number;\n const childId = stream[i++] as number;\n const referenceId = stream[i++] as number;\n const attachedSubtreeHandleIds = stream[i++] as number[] | null;\n const nativeRef = resolveTargetHandle(targetId, 'target');\n const childRef = resolveTargetHandle(childId, 'child');\n const attachedSubtreeHandles = attachedSubtreeHandleIds === null\n ? null\n : resolveSubtreeHandles(attachedSubtreeHandleIds, 'insert subtree');\n if (\n !nativeRef\n || !childRef\n || (attachedSubtreeHandleIds !== null && attachedSubtreeHandles === null)\n ) {\n continue;\n }\n const referenceRef = referenceId === 0 ? null : resolveTargetHandle(referenceId, 'reference');\n if (referenceId !== 0 && !referenceRef) {\n continue;\n }\n insertElementTemplateSubtree(\n nativeRef,\n childSlotIndex,\n childRef,\n referenceRef,\n attachedSubtreeHandles,\n );\n break;\n }\n\n case ElementTemplateUpdateOps.removeNode: {\n const targetId = stream[i++] as number;\n const childSlotIndex = stream[i++] as number;\n const childId = stream[i++] as number;\n const removedSubtreeHandleIds = stream[i++] as number[];\n const nativeRef = resolveTargetHandle(targetId, 'target');\n const childRef = resolveTargetHandle(childId, 'child');\n if (!nativeRef || !childRef) {\n continue;\n }\n __RemoveNodeFromElementTemplate(nativeRef, childSlotIndex, childRef);\n releaseRemovedSubtreeHandles(removedSubtreeHandleIds);\n break;\n }\n\n default: {\n if (__DEV__) {\n lynx.reportError(new Error(`ElementTemplate update opcode ${String(op)} is not supported.`));\n }\n }\n }\n }\n flushPendingListUpdates();\n}\n\nfunction flushPendingListUpdates(): void {\n applyListFlushResults(flushPendingElementTemplateListUpdates());\n applyListFlushResults(flushInitialElementTemplateListUpdates());\n}\n\nfunction applyListFlushResults(results: ETListFlushResult[]): void {\n for (let index = 0; index < results.length; index += 1) {\n const result = results[index]!;\n const listRef = resolveTargetHandle(result.uid, 'typed list');\n if (!listRef) {\n continue;\n }\n __SetAttributeOfElementTemplate(\n listRef,\n TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX,\n result.attributes,\n );\n if (result.removedSubtreeHandleIds) {\n releaseRemovedSubtreeHandles(result.removedSubtreeHandleIds);\n }\n }\n}\n\nfunction releaseRemovedSubtreeHandles(\n removedSubtreeHandleIds: number[],\n): void {\n for (const handleId of removedSubtreeHandleIds) {\n const pendingRemovedSubtreeHandleIds = markElementTemplateListDestroyed(handleId);\n elementTemplateRegistry.delete(handleId);\n deleteMainThreadDynamicAttrStateForSubtree([handleId]);\n if (pendingRemovedSubtreeHandleIds) {\n releaseRemovedSubtreeHandles(pendingRemovedSubtreeHandleIds);\n }\n }\n}\n\nfunction resolveChildSlots(\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n): RuntimeChildSlots | null | undefined {\n if (childSlots == null) {\n return null;\n }\n\n let hasError = false;\n const value: RuntimeChildSlots = [];\n for (let slotIndex = 0; slotIndex < childSlots.length; slotIndex += 1) {\n const children = childSlots[slotIndex];\n if (children == null) {\n continue;\n }\n if (__DEV__ && !Array.isArray(children)) {\n lynx.reportError(\n new Error(`ElementTemplate create slot ${slotIndex} must be an array of child handles, null, or undefined.`),\n );\n hasError = true;\n continue;\n }\n\n const resolvedChildren: ElementTemplateHandle[] = [];\n for (let childIndex = 0; childIndex < children.length; childIndex += 1) {\n const childId = children[childIndex]!;\n const childRef = resolveTargetHandle(childId, 'child');\n if (childRef === null) {\n hasError = true;\n continue;\n }\n resolvedChildren.push(childRef);\n }\n value[slotIndex] = resolvedChildren;\n }\n if (hasError) {\n return undefined;\n }\n return value;\n}\n\nfunction resolveTypedListOptions(\n options: RuntimeOptionsCommand | null | undefined,\n items: ETListUpdateItem[],\n): RuntimeTypedListOptions {\n return {\n ...options!,\n listChildren: items.map(item => item.ref),\n };\n}\n\nfunction getTypedListChildren(\n options: RuntimeOptionsCommand | null | undefined,\n): UpdateTypedListItemCommand[] {\n return (__DEV__ ? options?.['listChildren'] : options!['listChildren']!)! as UpdateTypedListItemCommand[];\n}\n\nfunction resolveTypedListItems(\n items: UpdateTypedListItemCommand[],\n): ETListUpdateItem[] | null {\n const resolvedItems: ETListUpdateItem[] = [];\n for (let index = 0; index < items.length; index += 1) {\n const resolvedItem = resolveTypedListItem(items[index]!, `typed list item ${index}`);\n if (resolvedItem === null) {\n return null;\n }\n resolvedItems.push(resolvedItem);\n }\n return resolvedItems;\n}\n\nfunction resolveTypedListItem(\n item: UpdateTypedListItemCommand,\n role: string,\n): ETListUpdateItem | null {\n const ref = resolveTargetHandle(item.__etHandleRef, role);\n if (ref === null) {\n return null;\n }\n // `item.type` is the full `${globDynamicComponentEntry}:${key}` tag; the\n // native list identifies items by the same identity key the templates were\n // registered under (see the `createTemplate` op above), so normalize it.\n const nativeTemplate = parseElementTemplateType(item.type);\n return {\n uid: item.__etHandleRef,\n ref,\n templateKey: elementTemplateIdentityKey(nativeTemplate.templateKey, nativeTemplate.bundleUrl),\n platformInfo: item.platformInfo,\n };\n}\n\nfunction resolveSubtreeHandles(\n subtreeHandleIds: readonly number[],\n role: string,\n): MainThreadDynamicAttrSubtreeHandle[] | null {\n const subtreeHandles: MainThreadDynamicAttrSubtreeHandle[] = [];\n for (let index = 0; index < subtreeHandleIds.length; index += 1) {\n const uid = subtreeHandleIds[index]!;\n const ref = resolveTargetHandle(uid, role);\n if (!ref) {\n return null;\n }\n subtreeHandles.push({ uid, ref });\n }\n return subtreeHandles;\n}\n\nfunction isTypedListChildSlotsEmpty(childSlots: ElementTemplateHandleSlotsCommand | null | undefined): boolean {\n if (!Array.isArray(childSlots)) {\n return true;\n }\n return childSlots.every(slot => slot == null || (Array.isArray(slot) && slot.length === 0));\n}\n\nfunction resolveTargetHandle(id: number, role: string): ElementTemplateHandle | null {\n const nativeRef = elementTemplateRegistry.getTarget(id);\n if (!nativeRef) {\n lynx.reportError(new Error(`ElementTemplate update ${role} handle ${id} not found.`));\n return null;\n }\n return nativeRef;\n}\n\nfunction isValidHandleId(handleId: number): boolean {\n return Number.isInteger(handleId) && handleId !== ELEMENT_TEMPLATE_PAGE_HANDLE_ID;\n}\n\nfunction validateCreateHandleId(handleId: number): Error | null {\n if (!isValidHandleId(handleId)) {\n return new Error(`ElementTemplate update has invalid handleId ${String(handleId)}.`);\n }\n if (elementTemplateRegistry.get(handleId)) {\n return new Error(`ElementTemplate update received duplicate handleId ${handleId}.`);\n }\n return null;\n}\n\nfunction validateCreateTemplatePayload(\n handleId: number,\n attributeSlots: SerializableValue[] | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n): Error | null {\n const handleError = validateCreateHandleId(handleId);\n if (handleError) {\n return handleError;\n }\n if (attributeSlots != null && !Array.isArray(attributeSlots)) {\n return new Error('ElementTemplate update create attributeSlots must be an array, null, or undefined.');\n }\n if (childSlots != null && !Array.isArray(childSlots)) {\n return new Error('ElementTemplate update create childSlots must be an array, null, or undefined.');\n }\n return null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../../src/element-template/runtime/patch.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EACL,oCAAoC,EACpC,uCAAuC,EACvC,sCAAsC,EACtC,sCAAsC,EACtC,6BAA6B,EAC7B,gCAAgC,EAChC,gCAAgC,EAChC,6BAA6B,EAC7B,mCAAmC,EACnC,6BAA6B,GAC9B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAC;AAEtG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,mCAAmC,EAAE,MAAM,gCAAgC,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,C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,CAAC,EAAE,CAAC;QACrD,OAAO,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;IACrG,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport {\n composeElementTemplateListAttributes,\n createElementTemplateListStateFromItems,\n flushInitialElementTemplateListUpdates,\n flushPendingElementTemplateListUpdates,\n insertElementTemplateListItem,\n markElementTemplateListDestroyed,\n registerElementTemplateListState,\n removeElementTemplateListItem,\n updateElementTemplateListAttributes,\n updateElementTemplateListItem,\n} from './list/list.js';\nimport type { ETListFlushResult, ETListUpdateItem } from './list/list.js';\nimport { insertElementTemplateSubtree } from './template/handle.js';\nimport { retainMainThreadBackgroundFunctionCtx } from './template/main-thread-background-function.js';\nimport type { MTEventNativeWrapper } from './template/main-thread-event-ctx.js';\nimport { elementTemplateRegistry } from './template/registry.js';\nimport { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from './template/typed-attributes.js';\nimport { ElementTemplateUpdateOps } from '../protocol/opcodes.js';\nimport type { ElementTemplateUpdateOp } from '../protocol/opcodes.js';\nimport { ELEMENT_TEMPLATE_PAGE_HANDLE_ID } from '../protocol/page.js';\nimport {\n elementTemplateIdentityKey,\n elementTemplateTypeTag,\n parseElementTemplateType,\n} from '../protocol/template-type.js';\nimport type {\n ElementTemplateHandleSlotsCommand,\n ElementTemplateUpdateCommandStream,\n RuntimeChildSlots,\n RuntimeOptions,\n RuntimeOptionsCommand,\n RuntimeTypedElementAttributes,\n RuntimeTypedListOptions,\n SerializableValue,\n TypedElementAttributesCommand,\n UpdateTypedListItemCommand,\n} from '../protocol/types.js';\nimport {\n deleteMainThreadDynamicAttrStateForSubtree,\n initializeMainThreadDynamicAttrSlots,\n prepareMainThreadDynamicAttrSlotsForNative,\n updateMainThreadEventAttrSlot,\n updateMainThreadRefAttrSlot,\n} from './template/main-thread-dynamic-attr-state.js';\nimport type { MainThreadDynamicAttrSubtreeHandle } from './template/main-thread-dynamic-attr-state.js';\n\nexport type { ElementTemplateUpdateCommandStream } from '../protocol/types.js';\n\n// The update event's JSON transport already normalizes array holes and undefined\n// entries to null. Consume those wire values without copying each attr array.\nexport function applyElementTemplateUpdateCommands(\n stream: ElementTemplateUpdateCommandStream,\n isHydration = false,\n): void {\n let i = 0;\n while (i < stream.length) {\n const op = stream[i++] as ElementTemplateUpdateOp;\n\n switch (op) {\n case ElementTemplateUpdateOps.createTemplate: {\n const handleId = stream[i++] as number;\n const templateKey = stream[i++] as string;\n const bundleUrl = stream[i++] as string | null | undefined;\n const attributeSlots = stream[i++] as SerializableValue[] | null | undefined;\n const childSlots = stream[i++] as ElementTemplateHandleSlotsCommand | null | undefined;\n\n if (__DEV__) {\n const createError = validateCreateTemplatePayload(\n handleId,\n attributeSlots,\n childSlots,\n );\n if (createError) {\n lynx.reportError(createError);\n continue;\n }\n }\n\n const resolvedChildSlots = resolveChildSlots(childSlots);\n if (resolvedChildSlots === undefined) {\n continue;\n }\n\n const templateType = elementTemplateTypeTag(templateKey, bundleUrl);\n const nativeAttributeSlots = prepareMainThreadDynamicAttrSlotsForNative(\n templateType,\n attributeSlots,\n );\n const nativeRef = __CreateElementTemplate(\n templateKey,\n bundleUrl,\n nativeAttributeSlots,\n resolvedChildSlots,\n handleId,\n );\n\n if (nativeRef) {\n elementTemplateRegistry.set(handleId, nativeRef);\n initializeMainThreadDynamicAttrSlots(\n handleId,\n templateType,\n attributeSlots,\n );\n }\n break;\n }\n\n case ElementTemplateUpdateOps.setAttribute: {\n const targetId = stream[i++] as number;\n const attrSlotIndex = stream[i++] as number;\n const value = stream[i++] as SerializableValue | null;\n const nativeRef = resolveTargetHandle(targetId, 'target');\n if (!nativeRef) {\n continue;\n }\n if (attrSlotIndex === TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX) {\n const listAttributes = updateElementTemplateListAttributes(\n targetId,\n value as RuntimeTypedElementAttributes | null,\n );\n if (listAttributes) {\n __SetAttributeOfElementTemplate(nativeRef, attrSlotIndex, listAttributes);\n break;\n }\n }\n __SetAttributeOfElementTemplate(nativeRef, attrSlotIndex, value);\n break;\n }\n\n case ElementTemplateUpdateOps.setMainThreadEvent: {\n const targetId = stream[i++] as number;\n const attrSlotIndex = stream[i++] as number;\n const value = stream[i++] as SerializableValue | null;\n const nativeRef = resolveTargetHandle(targetId, 'target');\n if (!nativeRef) {\n continue;\n }\n if (value != null) {\n retainMainThreadBackgroundFunctionCtx((value as unknown as MTEventNativeWrapper).value);\n }\n __SetAttributeOfElementTemplate(nativeRef, attrSlotIndex, value);\n updateMainThreadEventAttrSlot(targetId, attrSlotIndex, value, isHydration);\n break;\n }\n\n case ElementTemplateUpdateOps.setMainThreadRef: {\n const targetId = stream[i++] as number;\n const attrSlotIndex = stream[i++] as number;\n const value = stream[i++] as SerializableValue | null;\n const nativeRef = resolveTargetHandle(targetId, 'target');\n if (!nativeRef) {\n continue;\n }\n updateMainThreadRefAttrSlot(targetId, attrSlotIndex, value, nativeRef, isHydration);\n break;\n }\n\n case ElementTemplateUpdateOps.createTypedElement: {\n const handleId = stream[i++] as number;\n const type = stream[i++] as string;\n const attributes = stream[i++] as TypedElementAttributesCommand | null | undefined;\n const childSlots = stream[i++] as ElementTemplateHandleSlotsCommand | null | undefined;\n const options = stream[i++] as RuntimeOptionsCommand | null | undefined;\n const isTypedList = type === 'list';\n\n if (__DEV__) {\n const createError = validateCreateHandleId(handleId);\n if (createError) {\n lynx.reportError(createError);\n continue;\n }\n }\n if (__DEV__ && childSlots != null && !Array.isArray(childSlots)) {\n lynx.reportError(\n new Error('ElementTemplate update create childSlots must be an array, null, or undefined.'),\n );\n continue;\n }\n if (\n __DEV__\n && isTypedList\n && !isTypedListChildSlotsEmpty(childSlots)\n ) {\n lynx.reportError(\n new Error('ElementTemplate typed list create must keep logical children in options.listChildren.'),\n );\n continue;\n }\n const resolvedChildSlots = isTypedList ? null : resolveChildSlots(childSlots);\n if (resolvedChildSlots === undefined) {\n continue;\n }\n let resolvedListItems: ETListUpdateItem[] | null = null;\n let nativeOptions: RuntimeOptions | RuntimeTypedListOptions | null | undefined;\n if (isTypedList) {\n const listChildren = getTypedListChildren(options);\n if (__DEV__ && !Array.isArray(listChildren)) {\n lynx.reportError(\n new Error('ElementTemplate typed list create must keep logical children in options.listChildren.'),\n );\n continue;\n }\n resolvedListItems = resolveTypedListItems(listChildren);\n if (resolvedListItems === null) {\n continue;\n }\n nativeOptions = resolveTypedListOptions(options, resolvedListItems);\n } else {\n nativeOptions = options as RuntimeOptions | null | undefined;\n }\n const listState = resolvedListItems\n ? createElementTemplateListStateFromItems(\n resolvedListItems,\n attributes,\n )\n : null;\n const typedAttributes = listState\n ? composeElementTemplateListAttributes(\n undefined,\n listState,\n )\n : attributes;\n\n const nativeRef = __CreateTypedElementTemplate(\n type,\n typedAttributes,\n isTypedList ? null : resolvedChildSlots!,\n handleId,\n nativeOptions,\n );\n\n if (nativeRef) {\n elementTemplateRegistry.set(handleId, nativeRef);\n if (listState) {\n registerElementTemplateListState(handleId, listState, true, nativeRef);\n }\n }\n break;\n }\n\n case ElementTemplateUpdateOps.insertTypedListItem: {\n const listId = stream[i++] as number;\n const item = stream[i++] as UpdateTypedListItemCommand;\n const beforeId = stream[i++] as number;\n const resolvedItem = resolveTypedListItem(item, 'typed list insert item');\n if (resolvedItem === null) {\n continue;\n }\n insertElementTemplateListItem(listId, resolvedItem, beforeId);\n break;\n }\n\n case ElementTemplateUpdateOps.removeTypedListItem: {\n const listId = stream[i++] as number;\n const itemId = stream[i++] as number;\n const removedSubtreeHandleIds = stream[i++] as number[];\n removeElementTemplateListItem(listId, itemId, removedSubtreeHandleIds);\n break;\n }\n\n case ElementTemplateUpdateOps.updateTypedListItem: {\n const listId = stream[i++] as number;\n const item = stream[i++] as UpdateTypedListItemCommand;\n const resolvedItem = resolveTypedListItem(item, 'typed list update item');\n if (resolvedItem === null) {\n continue;\n }\n updateElementTemplateListItem(listId, resolvedItem);\n break;\n }\n\n case ElementTemplateUpdateOps.insertNode: {\n const targetId = stream[i++] as number;\n const childSlotIndex = stream[i++] as number;\n const childId = stream[i++] as number;\n const referenceId = stream[i++] as number;\n const attachedSubtreeHandleIds = stream[i++] as number[] | null;\n const nativeRef = resolveTargetHandle(targetId, 'target');\n const childRef = resolveTargetHandle(childId, 'child');\n const attachedSubtreeHandles = attachedSubtreeHandleIds === null\n ? null\n : resolveSubtreeHandles(attachedSubtreeHandleIds, 'insert subtree');\n if (\n !nativeRef\n || !childRef\n || (attachedSubtreeHandleIds !== null && attachedSubtreeHandles === null)\n ) {\n continue;\n }\n const referenceRef = referenceId === 0 ? null : resolveTargetHandle(referenceId, 'reference');\n if (referenceId !== 0 && !referenceRef) {\n continue;\n }\n insertElementTemplateSubtree(\n nativeRef,\n childSlotIndex,\n childRef,\n referenceRef,\n attachedSubtreeHandles,\n );\n break;\n }\n\n case ElementTemplateUpdateOps.removeNode: {\n const targetId = stream[i++] as number;\n const childSlotIndex = stream[i++] as number;\n const childId = stream[i++] as number;\n const removedSubtreeHandleIds = stream[i++] as number[];\n const nativeRef = resolveTargetHandle(targetId, 'target');\n const childRef = resolveTargetHandle(childId, 'child');\n if (!nativeRef || !childRef) {\n continue;\n }\n __RemoveNodeFromElementTemplate(nativeRef, childSlotIndex, childRef);\n releaseRemovedSubtreeHandles(removedSubtreeHandleIds);\n break;\n }\n\n default: {\n if (__DEV__) {\n lynx.reportError(new Error(`ElementTemplate update opcode ${String(op)} is not supported.`));\n }\n }\n }\n }\n flushPendingListUpdates();\n}\n\nfunction flushPendingListUpdates(): void {\n applyListFlushResults(flushPendingElementTemplateListUpdates());\n applyListFlushResults(flushInitialElementTemplateListUpdates());\n}\n\nfunction applyListFlushResults(results: ETListFlushResult[]): void {\n for (let index = 0; index < results.length; index += 1) {\n const result = results[index]!;\n const listRef = resolveTargetHandle(result.uid, 'typed list');\n if (!listRef) {\n continue;\n }\n __SetAttributeOfElementTemplate(\n listRef,\n TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX,\n result.attributes,\n );\n if (result.removedSubtreeHandleIds) {\n releaseRemovedSubtreeHandles(result.removedSubtreeHandleIds);\n }\n }\n}\n\nfunction releaseRemovedSubtreeHandles(\n removedSubtreeHandleIds: number[],\n): void {\n for (const handleId of removedSubtreeHandleIds) {\n const pendingRemovedSubtreeHandleIds = markElementTemplateListDestroyed(handleId);\n elementTemplateRegistry.delete(handleId);\n deleteMainThreadDynamicAttrStateForSubtree([handleId]);\n if (pendingRemovedSubtreeHandleIds) {\n releaseRemovedSubtreeHandles(pendingRemovedSubtreeHandleIds);\n }\n }\n}\n\nfunction resolveChildSlots(\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n): RuntimeChildSlots | null | undefined {\n if (childSlots == null) {\n return null;\n }\n\n let hasError = false;\n const value: RuntimeChildSlots = [];\n for (let slotIndex = 0; slotIndex < childSlots.length; slotIndex += 1) {\n const children = childSlots[slotIndex];\n if (children == null) {\n continue;\n }\n if (__DEV__ && !Array.isArray(children)) {\n lynx.reportError(\n new Error(`ElementTemplate create slot ${slotIndex} must be an array of child handles, null, or undefined.`),\n );\n hasError = true;\n continue;\n }\n\n const resolvedChildren: ElementTemplateHandle[] = [];\n for (let childIndex = 0; childIndex < children.length; childIndex += 1) {\n const childId = children[childIndex]!;\n const childRef = resolveTargetHandle(childId, 'child');\n if (childRef === null) {\n hasError = true;\n continue;\n }\n resolvedChildren.push(childRef);\n }\n value[slotIndex] = resolvedChildren;\n }\n if (hasError) {\n return undefined;\n }\n return value;\n}\n\nfunction resolveTypedListOptions(\n options: RuntimeOptionsCommand | null | undefined,\n items: ETListUpdateItem[],\n): RuntimeTypedListOptions {\n return {\n ...options!,\n listChildren: items.map(item => item.ref),\n };\n}\n\nfunction getTypedListChildren(\n options: RuntimeOptionsCommand | null | undefined,\n): UpdateTypedListItemCommand[] {\n return (__DEV__ ? options?.['listChildren'] : options!['listChildren']!)! as UpdateTypedListItemCommand[];\n}\n\nfunction resolveTypedListItems(\n items: UpdateTypedListItemCommand[],\n): ETListUpdateItem[] | null {\n const resolvedItems: ETListUpdateItem[] = [];\n for (let index = 0; index < items.length; index += 1) {\n const resolvedItem = resolveTypedListItem(items[index]!, `typed list item ${index}`);\n if (resolvedItem === null) {\n return null;\n }\n resolvedItems.push(resolvedItem);\n }\n return resolvedItems;\n}\n\nfunction resolveTypedListItem(\n item: UpdateTypedListItemCommand,\n role: string,\n): ETListUpdateItem | null {\n const ref = resolveTargetHandle(item.__etHandleRef, role);\n if (ref === null) {\n return null;\n }\n // `item.type` is the full `${globDynamicComponentEntry}:${key}` tag; the\n // native list identifies items by the same identity key the templates were\n // registered under (see the `createTemplate` op above), so normalize it.\n const nativeTemplate = parseElementTemplateType(item.type);\n return {\n uid: item.__etHandleRef,\n ref,\n templateKey: elementTemplateIdentityKey(nativeTemplate.templateKey, nativeTemplate.bundleUrl),\n platformInfo: item.platformInfo,\n };\n}\n\nfunction resolveSubtreeHandles(\n subtreeHandleIds: readonly number[],\n role: string,\n): MainThreadDynamicAttrSubtreeHandle[] | null {\n const subtreeHandles: MainThreadDynamicAttrSubtreeHandle[] = [];\n for (let index = 0; index < subtreeHandleIds.length; index += 1) {\n const uid = subtreeHandleIds[index]!;\n const ref = resolveTargetHandle(uid, role);\n if (!ref) {\n return null;\n }\n subtreeHandles.push({ uid, ref });\n }\n return subtreeHandles;\n}\n\nfunction isTypedListChildSlotsEmpty(childSlots: ElementTemplateHandleSlotsCommand | null | undefined): boolean {\n if (!Array.isArray(childSlots)) {\n return true;\n }\n return childSlots.every(slot => slot == null || (Array.isArray(slot) && slot.length === 0));\n}\n\nfunction resolveTargetHandle(id: number, role: string): ElementTemplateHandle | null {\n const nativeRef = elementTemplateRegistry.getTarget(id);\n if (!nativeRef) {\n lynx.reportError(new Error(`ElementTemplate update ${role} handle ${id} not found.`));\n return null;\n }\n return nativeRef;\n}\n\nfunction isValidHandleId(handleId: number): boolean {\n return Number.isInteger(handleId) && handleId !== ELEMENT_TEMPLATE_PAGE_HANDLE_ID;\n}\n\nfunction validateCreateHandleId(handleId: number): Error | null {\n if (!isValidHandleId(handleId)) {\n return new Error(`ElementTemplate update has invalid handleId ${String(handleId)}.`);\n }\n if (elementTemplateRegistry.get(handleId)) {\n return new Error(`ElementTemplate update received duplicate handleId ${handleId}.`);\n }\n return null;\n}\n\nfunction validateCreateTemplatePayload(\n handleId: number,\n attributeSlots: SerializableValue[] | null | undefined,\n childSlots: ElementTemplateHandleSlotsCommand | null | undefined,\n): Error | null {\n const handleError = validateCreateHandleId(handleId);\n if (handleError) {\n return handleError;\n }\n if (attributeSlots != null && !Array.isArray(attributeSlots)) {\n return new Error('ElementTemplate update create attributeSlots must be an array, null, or undefined.');\n }\n if (childSlots != null && !Array.isArray(childSlots)) {\n return new Error('ElementTemplate update create childSlots must be an array, null, or undefined.');\n }\n return null;\n}\n"]}
|
|
@@ -17,7 +17,7 @@ const assign = /* @__PURE__ */ Object.assign;
|
|
|
17
17
|
// Global state for the current render pass
|
|
18
18
|
export let beforeDiff;
|
|
19
19
|
export let beforeDiff2;
|
|
20
|
-
let afterDiff, renderHook,
|
|
20
|
+
let afterDiff, renderHook, unmountHook;
|
|
21
21
|
export function renderWithHooks(vnode, context, output, renderVNode, result) {
|
|
22
22
|
// Performance optimization: main-thread rendering is synchronous and we
|
|
23
23
|
// therefore don't execute any effects. To do that we pass an empty
|
|
@@ -31,7 +31,7 @@ export function renderWithHooks(vnode, context, output, renderVNode, result) {
|
|
|
31
31
|
beforeDiff2 = options[DIFF2];
|
|
32
32
|
afterDiff = options[DIFFED];
|
|
33
33
|
renderHook = options[RENDER];
|
|
34
|
-
|
|
34
|
+
unmountHook = options.unmount;
|
|
35
35
|
const parent = h(Fragment, null);
|
|
36
36
|
parent[CHILDREN] = [vnode];
|
|
37
37
|
try {
|
|
@@ -91,8 +91,8 @@ export function cleanupVNode(vnode) {
|
|
|
91
91
|
if (afterDiff)
|
|
92
92
|
afterDiff(vnode);
|
|
93
93
|
vnode[PARENT] = undefined;
|
|
94
|
-
if (
|
|
95
|
-
|
|
94
|
+
if (unmountHook)
|
|
95
|
+
unmountHook(vnode);
|
|
96
96
|
}
|
|
97
97
|
export function renderComponentVNode(vnode, type, props, context, output, renderVNode, result, parentType, subtreeHandles, listItemUids) {
|
|
98
98
|
let cctx = context;
|
|
@@ -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;AAE7C,8CAA8C;AAE9C,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC;AAE7C,2CAA2C;AAC3C,MAAM,CAAC,IAAI,UAAkD,CAAC;AAC9D,MAAM,CAAC,IAAI,WAAqF,CAAC;AACjG,IAAI,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC;AAEvC,MAAM,UAAU,eAAe,CAC7B,KAAc,EACd,OAAgB,EAChB,MAAiB,EACjB,WAAqB,EACrB,MAAe;IAEf,wEAAwE;IACxE,mEAAmE;IACnE,qEAAqE;IACrE,6DAA6D;IAC7D,sCAAsC;IACtC,MAAM,mBAAm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AM,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, ummountHook;\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 ummountHook = 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 (ummountHook) ummountHook(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,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;AAE7C,8CAA8C;AAE9C,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC;AAE7C,2CAA2C;AAC3C,MAAM,CAAC,IAAI,UAAkD,CAAC;AAC9D,MAAM,CAAC,IAAI,WAAqF,C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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"]}
|
|
@@ -13,6 +13,7 @@ import { flushInitialElementTemplateListUpdates } from '../list/list.js';
|
|
|
13
13
|
import { __page } from '../page/page.js';
|
|
14
14
|
import { __root } from '../page/root-instance.js';
|
|
15
15
|
import { insertElementTemplateSubtree } from '../template/handle.js';
|
|
16
|
+
import { applyPendingMainThreadRefAttachments } from '../template/main-thread-dynamic-attr-state.js';
|
|
16
17
|
import { getElementTemplateNativeRef } from '../template/registry.js';
|
|
17
18
|
import { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from '../template/typed-attributes.js';
|
|
18
19
|
function renderMainThread() {
|
|
@@ -39,6 +40,7 @@ function renderMainThread() {
|
|
|
39
40
|
insertElementTemplateSubtree(__page, ELEMENT_TEMPLATE_PAGE_ROOT_SLOT_INDEX, rootRef, null, rootSubtreeHandles[index]);
|
|
40
41
|
}
|
|
41
42
|
flushInitialListUpdates();
|
|
43
|
+
applyPendingMainThreadRefAttachments();
|
|
42
44
|
}
|
|
43
45
|
finally {
|
|
44
46
|
profileEnd();
|
|
@@ -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,sCAAsC,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,mCAAmC,EAAE,MAAM,iCAAiC,CAAC;AAEtF,SAAS,gBAAgB;IACvB,IAAI,QAAQ,CAAC;IACb,YAAY,CAAC,6BAA6B,CAAC,CAAC;IAC5C,IAAI,CAAC;QACH,QAAQ,GAAG,uBAAuB,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC9D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,yEAAyE;QACzE,4DAA4D;QAC5D,IAAI,CAAC,WAAW,CAAC,KAAc,CAAC,CAAC;QACjC,QAAQ,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,CAAC;IAC5E,CAAC;YAAS,CAAC;QACT,UAAU,EAAE,CAAC;IACf,CAAC;IAED,YAAY,CAAC,kCAAkC,CAAC,CAAC;IACjD,IAAI,CAAC;QACH,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,GAAG,QAAQ,CAAC;QAClE,+BAA+B,CAAC,MAAM,EAAE,mCAAmC,EAAE,cAAc,CAAC,CAAC;QAC7F,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;YACxD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAE,CAAC;YACjC,4BAA4B,CAC1B,MAAM,EACN,qCAAqC,EACrC,OAAO,EACP,IAAI,EACJ,kBAAkB,CAAC,KAAK,CAAE,CAC3B,CAAC;QACJ,CAAC;QACD,uBAAuB,EAAE,CAAC;
|
|
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,sCAAsC,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO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AAU,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,SAAS,uBAAuB;IAC9B,MAAM,OAAO,GAAG,sCAAsC,EAAE,CAAC;IACzD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACvD,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,2BAA2B,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxD,IAAI,OAAO,EAAE,CAAC;YACZ,+BAA+B,CAAC,OAAO,EAAE,mCAAmC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QACnG,CAAC;IACH,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 { flushInitialElementTemplateListUpdates } from '../list/list.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 { getElementTemplateNativeRef } from '../template/registry.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 flushInitialListUpdates();\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\nfunction flushInitialListUpdates(): void {\n const results = flushInitialElementTemplateListUpdates();\n for (let index = 0; index < results.length; index += 1) {\n const result = results[index]!;\n const listRef = getElementTemplateNativeRef(result.uid);\n if (listRef) {\n __SetAttributeOfElementTemplate(listRef, TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, result.attributes);\n }\n }\n}\n\nexport { renderMainThread };\n"]}
|
|
@@ -5,7 +5,7 @@ import { clearDelayedRunOnBackgroundFunctions, retainWorkletCtx } from '@lynx-js
|
|
|
5
5
|
import { createBackgroundFunctionHandle } from '../../../core/background-function/handle.js';
|
|
6
6
|
import { registerBackgroundFunctionCtx, resetBackgroundFunctionRuntime, runOnBackground, } from '../../../core/background-function/run-on-background.js';
|
|
7
7
|
import { resetFunctionCallReturnListener } from '../../../core/thread-function-call/return-value.js';
|
|
8
|
-
import { isRunOnBackgroundEnabled } from '../../../worklet-runtime/jsFunctionLifecycle.js';
|
|
8
|
+
import { JsFunctionLifecycleManager, isRunOnBackgroundEnabled } from '../../../worklet-runtime/jsFunctionLifecycle.js';
|
|
9
9
|
/**
|
|
10
10
|
* @internal transform-generated runtime helper for background JS function handles.
|
|
11
11
|
*/
|
|
@@ -16,6 +16,8 @@ export function registerMainThreadBackgroundFunctionCtx(ctx) {
|
|
|
16
16
|
registerBackgroundFunctionCtx(ctx);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
// Track the input before Native takes ownership. If Native rejects it, collection
|
|
20
|
+
// must still release its already-registered background execution; slot state commits later.
|
|
19
21
|
export function retainMainThreadBackgroundFunctionCtx(ctx) {
|
|
20
22
|
retainWorkletCtx(ctx);
|
|
21
23
|
}
|
|
@@ -24,6 +26,11 @@ export function resetElementTemplateBackgroundFunctionRuntime() {
|
|
|
24
26
|
resetFunctionCallReturnListener();
|
|
25
27
|
}
|
|
26
28
|
export function resetElementTemplateMainThreadBackgroundFunctionRuntime() {
|
|
29
|
+
const manager = globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager;
|
|
30
|
+
if (manager) {
|
|
31
|
+
manager.dispose();
|
|
32
|
+
globalThis.lynxWorkletImpl._jsFunctionLifecycleManager = new JsFunctionLifecycleManager();
|
|
33
|
+
}
|
|
27
34
|
clearDelayedRunOnBackgroundFunctions();
|
|
28
35
|
resetFunctionCallReturnListener();
|
|
29
36
|
}
|
package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main-thread-background-function.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-background-function.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,oCAAoC,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAEjH,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EACL,6BAA6B,EAC7B,8BAA8B,EAC9B,eAAe,GAChB,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;
|
|
1
|
+
{"version":3,"file":"main-thread-background-function.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-background-function.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,oCAAoC,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAEjH,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EACL,6BAA6B,EAC7B,8BAA8B,EAC9B,eAAe,GAChB,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;AAUvH;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,MAAM,UAAU,uCAAuC,CAAC,GAAoC;IAC1F,IAAI,MAAM,IAAI,wBAAwB,EAAE,EAAE,CAAC;QACzC,6BAA6B,CAAC,GAA4B,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED,kFAAkF;AAClF,4FAA4F;AAC5F,MAAM,UAAU,qCAAqC,CAAC,GAAoC;IACxF,gBAAgB,CAAC,GAA8B,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,6CAA6C;IAC3D,8BAA8B,EAAE,CAAC;IACjC,+BAA+B,EAAE,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,uDAAuD;IACrE,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,EAAE,2BAA2B,CAAC;IACxE,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,OAAO,EAAE,CAAC;QAClB,UAAU,CAAC,eAAe,CAAC,2BAA2B,GAAG,IAAI,0BAA0B,EAAE,CAAC;IAC5F,CAAC;IACD,oCAAoC,EAAE,CAAC;IACvC,+BAA+B,EAAE,CAAC;AACpC,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { clearDelayedRunOnBackgroundFunctions, retainWorkletCtx } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { createBackgroundFunctionHandle } from '../../../core/background-function/handle.js';\nimport {\n registerBackgroundFunctionCtx,\n resetBackgroundFunctionRuntime,\n runOnBackground,\n} from '../../../core/background-function/run-on-background.js';\nimport { resetFunctionCallReturnListener } from '../../../core/thread-function-call/return-value.js';\nimport { JsFunctionLifecycleManager, isRunOnBackgroundEnabled } from '../../../worklet-runtime/jsFunctionLifecycle.js';\n\ntype BackgroundFunctionCtx = Parameters<typeof registerBackgroundFunctionCtx>[0];\ntype RetainableMainThreadCtx = Parameters<typeof retainWorkletCtx>[0];\n\ninterface MainThreadBackgroundFunctionCtx {\n _wkltId: string;\n [key: string]: unknown;\n}\n\n/**\n * @internal transform-generated runtime helper for background JS function handles.\n */\nexport const transformToWorklet = createBackgroundFunctionHandle;\nexport { runOnBackground };\n\nexport function registerMainThreadBackgroundFunctionCtx(ctx: MainThreadBackgroundFunctionCtx): void {\n if (__JS__ && isRunOnBackgroundEnabled()) {\n registerBackgroundFunctionCtx(ctx as BackgroundFunctionCtx);\n }\n}\n\n// Track the input before Native takes ownership. If Native rejects it, collection\n// must still release its already-registered background execution; slot state commits later.\nexport function retainMainThreadBackgroundFunctionCtx(ctx: MainThreadBackgroundFunctionCtx): void {\n retainWorkletCtx(ctx as RetainableMainThreadCtx);\n}\n\nexport function resetElementTemplateBackgroundFunctionRuntime(): void {\n resetBackgroundFunctionRuntime();\n resetFunctionCallReturnListener();\n}\n\nexport function resetElementTemplateMainThreadBackgroundFunctionRuntime(): void {\n const manager = globalThis.lynxWorkletImpl?._jsFunctionLifecycleManager;\n if (manager) {\n manager.dispose();\n globalThis.lynxWorkletImpl._jsFunctionLifecycleManager = new JsFunctionLifecycleManager();\n }\n clearDelayedRunOnBackgroundFunctions();\n resetFunctionCallReturnListener();\n}\n"]}
|
|
@@ -19,6 +19,7 @@ export declare function initializeMainThreadDynamicAttrSlots(handleId: number, t
|
|
|
19
19
|
export declare function updateMainThreadEventAttrSlot(handleId: number, attrSlotIndex: number, value: unknown, isHydration?: boolean): void;
|
|
20
20
|
export declare function updateMainThreadRefAttrSlot(handleId: number, attrSlotIndex: number, value: unknown, nativeRef: ElementTemplateHandle, isHydration?: boolean): void;
|
|
21
21
|
export declare function attachMainThreadDynamicAttrRefsForSubtree(handles: readonly MainThreadDynamicAttrSubtreeHandle[]): void;
|
|
22
|
+
export declare function applyPendingMainThreadRefAttachments(): void;
|
|
22
23
|
export declare function detachMainThreadDynamicAttrRefsForSubtree(handles: readonly MainThreadDynamicAttrSubtreeHandle[]): void;
|
|
23
24
|
export declare function deleteMainThreadDynamicAttrStateForSubtree(handleIds: readonly number[]): void;
|
|
24
25
|
export {};
|
|
@@ -7,7 +7,8 @@ import { retainMainThreadBackgroundFunctionCtx } from './main-thread-background-
|
|
|
7
7
|
import { attachMTRefValue, cleanupMTRefValue, hydrateMTRefValue, retainMTRefValue } from './main-thread-ref-ctx.js';
|
|
8
8
|
const mtEventAttrState = new Map();
|
|
9
9
|
const mtRefAttrState = new Map();
|
|
10
|
-
const
|
|
10
|
+
const attachedMTRefHandleIds = new Set();
|
|
11
|
+
let pendingMTRefAttachments = [];
|
|
11
12
|
function deleteSlotState(state, handleId, attrSlotIndex) {
|
|
12
13
|
const handleState = state.get(handleId);
|
|
13
14
|
if (!handleState) {
|
|
@@ -32,7 +33,6 @@ function setSlotState(state, handleId, attrSlotIndex, value) {
|
|
|
32
33
|
handleState.set(attrSlotIndex, value);
|
|
33
34
|
}
|
|
34
35
|
function setMTEventSlotState(handleId, attrSlotIndex, nativeHeldValue) {
|
|
35
|
-
retainMainThreadBackgroundFunctionCtx(nativeHeldValue);
|
|
36
36
|
setSlotState(mtEventAttrState, handleId, attrSlotIndex, nativeHeldValue);
|
|
37
37
|
}
|
|
38
38
|
function setMTRefSlotState(handleId, attrSlotIndex, value) {
|
|
@@ -49,6 +49,9 @@ export function prepareMainThreadDynamicAttrSlotsForNative(templateType, attribu
|
|
|
49
49
|
}
|
|
50
50
|
let nativeSlots;
|
|
51
51
|
for (const [attrSlotIndex, kind] of slotKinds) {
|
|
52
|
+
if (kind === 'mt-event' && attributeSlots[attrSlotIndex] != null) {
|
|
53
|
+
retainMainThreadBackgroundFunctionCtx(attributeSlots[attrSlotIndex].value);
|
|
54
|
+
}
|
|
52
55
|
if (kind !== 'mt-ref') {
|
|
53
56
|
continue;
|
|
54
57
|
}
|
|
@@ -58,14 +61,19 @@ export function prepareMainThreadDynamicAttrSlotsForNative(templateType, attribu
|
|
|
58
61
|
return nativeSlots ?? attributeSlots;
|
|
59
62
|
}
|
|
60
63
|
export function clearMainThreadDynamicAttrState() {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
try {
|
|
65
|
+
for (const [handleId, handleState] of mtRefAttrState) {
|
|
66
|
+
if (attachedMTRefHandleIds.has(handleId)) {
|
|
67
|
+
cleanupMTRefHandleState(handleState);
|
|
68
|
+
}
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
finally {
|
|
72
|
+
mtEventAttrState.clear();
|
|
73
|
+
mtRefAttrState.clear();
|
|
74
|
+
attachedMTRefHandleIds.clear();
|
|
75
|
+
pendingMTRefAttachments = [];
|
|
76
|
+
}
|
|
69
77
|
}
|
|
70
78
|
export function getMainThreadDynamicAttrState(handleId, attrSlotIndex) {
|
|
71
79
|
const event = mtEventAttrState.get(handleId)?.get(attrSlotIndex);
|
|
@@ -106,15 +114,15 @@ export function updateMainThreadEventAttrSlot(handleId, attrSlotIndex, value, is
|
|
|
106
114
|
}
|
|
107
115
|
export function updateMainThreadRefAttrSlot(handleId, attrSlotIndex, value, nativeRef, isHydration = false) {
|
|
108
116
|
const previousState = mtRefAttrState.get(handleId)?.get(attrSlotIndex);
|
|
109
|
-
const
|
|
117
|
+
const isAttached = attachedMTRefHandleIds.has(handleId);
|
|
110
118
|
if (value == null) {
|
|
111
|
-
if (previousState &&
|
|
119
|
+
if (previousState && isAttached) {
|
|
112
120
|
cleanupMTRefValue(previousState);
|
|
113
121
|
}
|
|
114
122
|
deleteSlotState(mtRefAttrState, handleId, attrSlotIndex);
|
|
115
123
|
return;
|
|
116
124
|
}
|
|
117
|
-
if (previousState &&
|
|
125
|
+
if (previousState && isAttached) {
|
|
118
126
|
cleanupMTRefValue(previousState);
|
|
119
127
|
}
|
|
120
128
|
const nextValue = value.value;
|
|
@@ -122,33 +130,45 @@ export function updateMainThreadRefAttrSlot(handleId, attrSlotIndex, value, nati
|
|
|
122
130
|
if (isHydration) {
|
|
123
131
|
hydrateMTRefValue(nextValue, previousState);
|
|
124
132
|
}
|
|
125
|
-
if (
|
|
126
|
-
|
|
133
|
+
if (isAttached) {
|
|
134
|
+
pendingMTRefAttachments.push({ handleId, attrSlotIndex, value: nextValue, nativeRef });
|
|
127
135
|
}
|
|
128
136
|
}
|
|
129
137
|
export function attachMainThreadDynamicAttrRefsForSubtree(handles) {
|
|
130
138
|
for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {
|
|
131
139
|
const handle = handles[handleIndex];
|
|
132
|
-
if (
|
|
140
|
+
if (attachedMTRefHandleIds.has(handle.uid)) {
|
|
133
141
|
continue;
|
|
134
142
|
}
|
|
135
|
-
|
|
143
|
+
attachedMTRefHandleIds.add(handle.uid);
|
|
136
144
|
const handleState = mtRefAttrState.get(handle.uid);
|
|
137
145
|
if (!handleState) {
|
|
138
146
|
continue;
|
|
139
147
|
}
|
|
140
|
-
for (const value of handleState
|
|
141
|
-
|
|
148
|
+
for (const [attrSlotIndex, value] of handleState) {
|
|
149
|
+
pendingMTRefAttachments.push({ handleId: handle.uid, attrSlotIndex, value, nativeRef: handle.ref });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Consume one queue snapshot, matching Snapshot's ref delivery boundary.
|
|
154
|
+
export function applyPendingMainThreadRefAttachments() {
|
|
155
|
+
const pending = pendingMTRefAttachments;
|
|
156
|
+
pendingMTRefAttachments = [];
|
|
157
|
+
for (const { handleId, attrSlotIndex, value, nativeRef } of pending) {
|
|
158
|
+
const element = __GetElementByAttrSlot(nativeRef, attrSlotIndex);
|
|
159
|
+
if (!element) {
|
|
160
|
+
throw new Error(`ElementTemplate main-thread:ref target ${handleId}:${attrSlotIndex} could not be materialized.`);
|
|
142
161
|
}
|
|
162
|
+
attachMTRefValue(value, element);
|
|
143
163
|
}
|
|
144
164
|
}
|
|
145
165
|
export function detachMainThreadDynamicAttrRefsForSubtree(handles) {
|
|
146
166
|
for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {
|
|
147
167
|
const handleId = handles[handleIndex].uid;
|
|
148
|
-
if (!
|
|
168
|
+
if (!attachedMTRefHandleIds.has(handleId)) {
|
|
149
169
|
continue;
|
|
150
170
|
}
|
|
151
|
-
|
|
171
|
+
attachedMTRefHandleIds.delete(handleId);
|
|
152
172
|
const handleState = mtRefAttrState.get(handleId);
|
|
153
173
|
if (handleState) {
|
|
154
174
|
cleanupMTRefHandleState(handleState);
|
|
@@ -158,10 +178,10 @@ export function detachMainThreadDynamicAttrRefsForSubtree(handles) {
|
|
|
158
178
|
export function deleteMainThreadDynamicAttrStateForSubtree(handleIds) {
|
|
159
179
|
for (const handleId of handleIds) {
|
|
160
180
|
const handleState = mtRefAttrState.get(handleId);
|
|
161
|
-
if (handleState &&
|
|
181
|
+
if (handleState && attachedMTRefHandleIds.has(handleId)) {
|
|
162
182
|
cleanupMTRefHandleState(handleState);
|
|
163
183
|
}
|
|
164
|
-
|
|
184
|
+
attachedMTRefHandleIds.delete(handleId);
|
|
165
185
|
mtEventAttrState.delete(handleId);
|
|
166
186
|
mtRefAttrState.delete(handleId);
|
|
167
187
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main-thread-dynamic-attr-state.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAG5E,OAAO,EAAE,iCAAiC,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,qCAAqC,EAAE,MAAM,sCAAsC,CAAC;AAE7F,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAUpH,MAAM,gBAAgB,GAA8C,IAAI,GAAG,EAAE,CAAC;AAC9E,MAAM,cAAc,GAA8C,IAAI,GAAG,EAAE,CAAC;AAC5E,MAAM,0BAA0B,GAAG,IAAI,GAAG,EAAU,CAAC;AAOrD,SAAS,eAAe,CACtB,KA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GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5D,uBAAuB,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QACD,0BAA0B,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5C,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { hydrateWorkletCtx } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { getMainThreadDynamicAttrSlotKinds } from './attr-slot-plan.js';\nimport { retainMainThreadBackgroundFunctionCtx } from './main-thread-background-function.js';\nimport type { MTEventCtx, MTEventNativeWrapper } from './main-thread-event-ctx.js';\nimport { attachMTRefValue, cleanupMTRefValue, hydrateMTRefValue, retainMTRefValue } from './main-thread-ref-ctx.js';\nimport type { MTRefNativeWrapper, MTRefValue } from './main-thread-ref-ctx.js';\nimport type { SerializableValue } from '../../protocol/types.js';\n\ntype MainThreadDynamicAttrState =\n | { kind: 'mt-event'; nativeHeldValue: MTEventCtx }\n | { kind: 'mt-ref'; value: MTRefValue };\n\ntype MainThreadDynamicAttrStateMap<T> = Map<number, Map<number, T>>;\n\nconst mtEventAttrState: MainThreadDynamicAttrStateMap<MTEventCtx> = new Map();\nconst mtRefAttrState: MainThreadDynamicAttrStateMap<MTRefValue> = new Map();\nconst materializedMTRefHandleIds = new Set<number>();\n\nexport interface MainThreadDynamicAttrSubtreeHandle {\n uid: number;\n ref: ElementTemplateHandle;\n}\n\nfunction deleteSlotState<T>(\n state: MainThreadDynamicAttrStateMap<T>,\n handleId: number,\n attrSlotIndex: number,\n): void {\n const handleState = state.get(handleId);\n if (!handleState) {\n return;\n }\n handleState.delete(attrSlotIndex);\n if (handleState.size === 0) {\n state.delete(handleId);\n }\n}\n\nfunction cleanupMTRefHandleState(handleState: Map<number, MTRefValue>): void {\n for (const value of handleState.values()) {\n cleanupMTRefValue(value);\n }\n}\n\nfunction setSlotState<T>(\n state: MainThreadDynamicAttrStateMap<T>,\n handleId: number,\n attrSlotIndex: number,\n value: T,\n): void {\n let handleState = state.get(handleId);\n if (!handleState) {\n handleState = new Map();\n state.set(handleId, handleState);\n }\n handleState.set(attrSlotIndex, value);\n}\n\nfunction setMTEventSlotState(handleId: number, attrSlotIndex: number, nativeHeldValue: MTEventCtx): void {\n retainMainThreadBackgroundFunctionCtx(nativeHeldValue);\n setSlotState(mtEventAttrState, handleId, attrSlotIndex, nativeHeldValue);\n}\n\nfunction setMTRefSlotState(\n handleId: number,\n attrSlotIndex: number,\n value: MTRefValue,\n): void {\n retainMTRefValue(value);\n setSlotState(mtRefAttrState, handleId, attrSlotIndex, value);\n}\n\nexport function prepareMainThreadDynamicAttrSlotsForNative(\n templateType: string,\n attributeSlots: readonly unknown[] | null | undefined,\n): SerializableValue[] | null | undefined {\n if (attributeSlots == null) {\n return attributeSlots;\n }\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n if (!slotKinds) {\n return attributeSlots as SerializableValue[];\n }\n let nativeSlots: SerializableValue[] | undefined;\n for (const [attrSlotIndex, kind] of slotKinds) {\n if (kind !== 'mt-ref') {\n continue;\n }\n nativeSlots ??= attributeSlots.slice() as SerializableValue[];\n nativeSlots[attrSlotIndex] = null;\n }\n return nativeSlots ?? attributeSlots as SerializableValue[];\n}\n\nexport function clearMainThreadDynamicAttrState(): void {\n for (const [handleId, handleState] of mtRefAttrState) {\n if (materializedMTRefHandleIds.has(handleId)) {\n cleanupMTRefHandleState(handleState);\n }\n }\n mtEventAttrState.clear();\n mtRefAttrState.clear();\n materializedMTRefHandleIds.clear();\n}\n\nexport function getMainThreadDynamicAttrState(\n handleId: number,\n attrSlotIndex: number,\n): MainThreadDynamicAttrState | undefined {\n const event = mtEventAttrState.get(handleId)?.get(attrSlotIndex);\n if (event) {\n return { kind: 'mt-event', nativeHeldValue: event };\n }\n const ref = mtRefAttrState.get(handleId)?.get(attrSlotIndex);\n return ref ? { kind: 'mt-ref', value: ref } : undefined;\n}\n\nexport function initializeMainThreadDynamicAttrSlots(\n handleId: number,\n templateType: string,\n attributeSlots: readonly unknown[] | null | undefined,\n): void {\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n if (!slotKinds) {\n return;\n }\n for (const [attrSlotIndex, kind] of slotKinds) {\n const value = attributeSlots?.[attrSlotIndex];\n if (kind === 'mt-event' && value != null) {\n setMTEventSlotState(handleId, attrSlotIndex, (value as MTEventNativeWrapper).value);\n } else if (kind === 'mt-ref' && value != null) {\n setMTRefSlotState(handleId, attrSlotIndex, (value as MTRefNativeWrapper).value);\n }\n }\n}\n\nexport function updateMainThreadEventAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n isHydration = false,\n): void {\n const previousState = isHydration\n ? mtEventAttrState.get(handleId)?.get(attrSlotIndex)\n : undefined;\n if (value == null) {\n deleteSlotState(mtEventAttrState, handleId, attrSlotIndex);\n return;\n }\n const nextValue = (value as MTEventNativeWrapper).value;\n setMTEventSlotState(handleId, attrSlotIndex, nextValue);\n if (previousState) {\n hydrateWorkletCtx(\n nextValue as Worklet,\n previousState as Worklet,\n );\n }\n}\n\nexport function updateMainThreadRefAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n nativeRef: ElementTemplateHandle,\n isHydration = false,\n): void {\n const previousState = mtRefAttrState.get(handleId)?.get(attrSlotIndex);\n const isMaterialized = materializedMTRefHandleIds.has(handleId);\n if (value == null) {\n if (previousState && isMaterialized) {\n cleanupMTRefValue(previousState);\n }\n deleteSlotState(mtRefAttrState, handleId, attrSlotIndex);\n return;\n }\n if (previousState && isMaterialized) {\n cleanupMTRefValue(previousState);\n }\n const nextValue = (value as MTRefNativeWrapper).value;\n setMTRefSlotState(handleId, attrSlotIndex, nextValue);\n if (isHydration) {\n hydrateMTRefValue(nextValue, previousState);\n }\n if (isMaterialized) {\n attachMTRefValue(nextValue, nativeRef);\n }\n}\n\nexport function attachMainThreadDynamicAttrRefsForSubtree(\n handles: readonly MainThreadDynamicAttrSubtreeHandle[],\n): void {\n for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {\n const handle = handles[handleIndex]!;\n if (materializedMTRefHandleIds.has(handle.uid)) {\n continue;\n }\n materializedMTRefHandleIds.add(handle.uid);\n const handleState = mtRefAttrState.get(handle.uid);\n if (!handleState) {\n continue;\n }\n for (const value of handleState.values()) {\n attachMTRefValue(value, handle.ref);\n }\n }\n}\n\nexport function detachMainThreadDynamicAttrRefsForSubtree(\n handles: readonly MainThreadDynamicAttrSubtreeHandle[],\n): void {\n for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {\n const handleId = handles[handleIndex]!.uid;\n if (!materializedMTRefHandleIds.has(handleId)) {\n continue;\n }\n materializedMTRefHandleIds.delete(handleId);\n const handleState = mtRefAttrState.get(handleId);\n if (handleState) {\n cleanupMTRefHandleState(handleState);\n }\n }\n}\n\nexport function deleteMainThreadDynamicAttrStateForSubtree(\n handleIds: readonly number[],\n): void {\n for (const handleId of handleIds) {\n const handleState = mtRefAttrState.get(handleId);\n if (handleState && materializedMTRefHandleIds.has(handleId)) {\n cleanupMTRefHandleState(handleState);\n }\n materializedMTRefHandleIds.delete(handleId);\n mtEventAttrState.delete(handleId);\n mtRefAttrState.delete(handleId);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"main-thread-dynamic-attr-state.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAG5E,OAAO,EAAE,iCAAiC,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,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;YACxD,uBAAuB,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QACD,sBAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACxC,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { hydrateWorkletCtx } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport { getMainThreadDynamicAttrSlotKinds } from './attr-slot-plan.js';\nimport { retainMainThreadBackgroundFunctionCtx } from './main-thread-background-function.js';\nimport type { MTEventCtx, MTEventNativeWrapper } from './main-thread-event-ctx.js';\nimport { attachMTRefValue, cleanupMTRefValue, hydrateMTRefValue, retainMTRefValue } from './main-thread-ref-ctx.js';\nimport type { MTRefNativeWrapper, MTRefValue } from './main-thread-ref-ctx.js';\nimport type { SerializableValue } from '../../protocol/types.js';\n\ntype MainThreadDynamicAttrState =\n | { kind: 'mt-event'; nativeHeldValue: MTEventCtx }\n | { kind: 'mt-ref'; value: MTRefValue };\n\ntype MainThreadDynamicAttrStateMap<T> = Map<number, Map<number, T>>;\n\nconst mtEventAttrState: MainThreadDynamicAttrStateMap<MTEventCtx> = new Map();\nconst mtRefAttrState: MainThreadDynamicAttrStateMap<MTRefValue> = new Map();\nconst attachedMTRefHandleIds = new Set<number>();\n\ninterface PendingMTRefAttachment {\n handleId: number;\n attrSlotIndex: number;\n value: MTRefValue;\n nativeRef: ElementTemplateHandle;\n}\n\nlet pendingMTRefAttachments: PendingMTRefAttachment[] = [];\n\nexport interface MainThreadDynamicAttrSubtreeHandle {\n uid: number;\n ref: ElementTemplateHandle;\n}\n\nfunction deleteSlotState<T>(\n state: MainThreadDynamicAttrStateMap<T>,\n handleId: number,\n attrSlotIndex: number,\n): void {\n const handleState = state.get(handleId);\n if (!handleState) {\n return;\n }\n handleState.delete(attrSlotIndex);\n if (handleState.size === 0) {\n state.delete(handleId);\n }\n}\n\nfunction cleanupMTRefHandleState(handleState: Map<number, MTRefValue>): void {\n for (const value of handleState.values()) {\n cleanupMTRefValue(value);\n }\n}\n\nfunction setSlotState<T>(\n state: MainThreadDynamicAttrStateMap<T>,\n handleId: number,\n attrSlotIndex: number,\n value: T,\n): void {\n let handleState = state.get(handleId);\n if (!handleState) {\n handleState = new Map();\n state.set(handleId, handleState);\n }\n handleState.set(attrSlotIndex, value);\n}\n\nfunction setMTEventSlotState(handleId: number, attrSlotIndex: number, nativeHeldValue: MTEventCtx): void {\n setSlotState(mtEventAttrState, handleId, attrSlotIndex, nativeHeldValue);\n}\n\nfunction setMTRefSlotState(\n handleId: number,\n attrSlotIndex: number,\n value: MTRefValue,\n): void {\n retainMTRefValue(value);\n setSlotState(mtRefAttrState, handleId, attrSlotIndex, value);\n}\n\nexport function prepareMainThreadDynamicAttrSlotsForNative(\n templateType: string,\n attributeSlots: readonly unknown[] | null | undefined,\n): SerializableValue[] | null | undefined {\n if (attributeSlots == null) {\n return attributeSlots;\n }\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n if (!slotKinds) {\n return attributeSlots as SerializableValue[];\n }\n let nativeSlots: SerializableValue[] | undefined;\n for (const [attrSlotIndex, kind] of slotKinds) {\n if (kind === 'mt-event' && attributeSlots[attrSlotIndex] != null) {\n retainMainThreadBackgroundFunctionCtx((attributeSlots[attrSlotIndex] as MTEventNativeWrapper).value);\n }\n if (kind !== 'mt-ref') {\n continue;\n }\n nativeSlots ??= attributeSlots.slice() as SerializableValue[];\n nativeSlots[attrSlotIndex] = null;\n }\n return nativeSlots ?? attributeSlots as SerializableValue[];\n}\n\nexport function clearMainThreadDynamicAttrState(): void {\n try {\n for (const [handleId, handleState] of mtRefAttrState) {\n if (attachedMTRefHandleIds.has(handleId)) {\n cleanupMTRefHandleState(handleState);\n }\n }\n } finally {\n mtEventAttrState.clear();\n mtRefAttrState.clear();\n attachedMTRefHandleIds.clear();\n pendingMTRefAttachments = [];\n }\n}\n\nexport function getMainThreadDynamicAttrState(\n handleId: number,\n attrSlotIndex: number,\n): MainThreadDynamicAttrState | undefined {\n const event = mtEventAttrState.get(handleId)?.get(attrSlotIndex);\n if (event) {\n return { kind: 'mt-event', nativeHeldValue: event };\n }\n const ref = mtRefAttrState.get(handleId)?.get(attrSlotIndex);\n return ref ? { kind: 'mt-ref', value: ref } : undefined;\n}\n\nexport function initializeMainThreadDynamicAttrSlots(\n handleId: number,\n templateType: string,\n attributeSlots: readonly unknown[] | null | undefined,\n): void {\n const slotKinds = getMainThreadDynamicAttrSlotKinds(templateType);\n if (!slotKinds) {\n return;\n }\n for (const [attrSlotIndex, kind] of slotKinds) {\n const value = attributeSlots?.[attrSlotIndex];\n if (kind === 'mt-event' && value != null) {\n setMTEventSlotState(handleId, attrSlotIndex, (value as MTEventNativeWrapper).value);\n } else if (kind === 'mt-ref' && value != null) {\n setMTRefSlotState(handleId, attrSlotIndex, (value as MTRefNativeWrapper).value);\n }\n }\n}\n\nexport function updateMainThreadEventAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n isHydration = false,\n): void {\n const previousState = isHydration\n ? mtEventAttrState.get(handleId)?.get(attrSlotIndex)\n : undefined;\n if (value == null) {\n deleteSlotState(mtEventAttrState, handleId, attrSlotIndex);\n return;\n }\n const nextValue = (value as MTEventNativeWrapper).value;\n setMTEventSlotState(handleId, attrSlotIndex, nextValue);\n if (previousState) {\n hydrateWorkletCtx(\n nextValue as Worklet,\n previousState as Worklet,\n );\n }\n}\n\nexport function updateMainThreadRefAttrSlot(\n handleId: number,\n attrSlotIndex: number,\n value: unknown,\n nativeRef: ElementTemplateHandle,\n isHydration = false,\n): void {\n const previousState = mtRefAttrState.get(handleId)?.get(attrSlotIndex);\n const isAttached = attachedMTRefHandleIds.has(handleId);\n if (value == null) {\n if (previousState && isAttached) {\n cleanupMTRefValue(previousState);\n }\n deleteSlotState(mtRefAttrState, handleId, attrSlotIndex);\n return;\n }\n if (previousState && isAttached) {\n cleanupMTRefValue(previousState);\n }\n const nextValue = (value as MTRefNativeWrapper).value;\n setMTRefSlotState(handleId, attrSlotIndex, nextValue);\n if (isHydration) {\n hydrateMTRefValue(nextValue, previousState);\n }\n if (isAttached) {\n pendingMTRefAttachments.push({ handleId, attrSlotIndex, value: nextValue, nativeRef });\n }\n}\n\nexport function attachMainThreadDynamicAttrRefsForSubtree(\n handles: readonly MainThreadDynamicAttrSubtreeHandle[],\n): void {\n for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {\n const handle = handles[handleIndex]!;\n if (attachedMTRefHandleIds.has(handle.uid)) {\n continue;\n }\n attachedMTRefHandleIds.add(handle.uid);\n const handleState = mtRefAttrState.get(handle.uid);\n if (!handleState) {\n continue;\n }\n for (const [attrSlotIndex, value] of handleState) {\n pendingMTRefAttachments.push({ handleId: handle.uid, attrSlotIndex, value, nativeRef: handle.ref });\n }\n }\n}\n\n// Consume one queue snapshot, matching Snapshot's ref delivery boundary.\nexport function applyPendingMainThreadRefAttachments(): void {\n const pending = pendingMTRefAttachments;\n pendingMTRefAttachments = [];\n for (const { handleId, attrSlotIndex, value, nativeRef } of pending) {\n const element = __GetElementByAttrSlot(nativeRef, attrSlotIndex);\n if (!element) {\n throw new Error(\n `ElementTemplate main-thread:ref target ${handleId}:${attrSlotIndex} could not be materialized.`,\n );\n }\n attachMTRefValue(value, element);\n }\n}\n\nexport function detachMainThreadDynamicAttrRefsForSubtree(\n handles: readonly MainThreadDynamicAttrSubtreeHandle[],\n): void {\n for (let handleIndex = 0; handleIndex < handles.length; handleIndex += 1) {\n const handleId = handles[handleIndex]!.uid;\n if (!attachedMTRefHandleIds.has(handleId)) {\n continue;\n }\n attachedMTRefHandleIds.delete(handleId);\n const handleState = mtRefAttrState.get(handleId);\n if (handleState) {\n cleanupMTRefHandleState(handleState);\n }\n }\n}\n\nexport function deleteMainThreadDynamicAttrStateForSubtree(\n handleIds: readonly number[],\n): void {\n for (const handleId of handleIds) {\n const handleState = mtRefAttrState.get(handleId);\n if (handleState && attachedMTRefHandleIds.has(handleId)) {\n cleanupMTRefHandleState(handleState);\n }\n attachedMTRefHandleIds.delete(handleId);\n mtEventAttrState.delete(handleId);\n mtRefAttrState.delete(handleId);\n }\n}\n"]}
|
|
@@ -8,6 +8,6 @@ export interface MTRefNativeWrapper {
|
|
|
8
8
|
export declare function isMTRefValue(value: unknown): value is MTRefValue;
|
|
9
9
|
export declare function retainMTRefValue(value: MTRefValue): void;
|
|
10
10
|
export declare function hydrateMTRefValue(value: MTRefValue, previousValue: MTRefValue | undefined): void;
|
|
11
|
-
export declare function attachMTRefValue(value: MTRefValue, nativeRef:
|
|
11
|
+
export declare function attachMTRefValue(value: MTRefValue, nativeRef: ElementRef): void;
|
|
12
12
|
export declare function cleanupMTRefValue(value: MTRefValue): void;
|
|
13
13
|
export declare function prepareMTRefForNative(rawValue: unknown, previousPreparedValue?: unknown, previousRawValue?: unknown): SerializableValue | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main-thread-ref-ctx.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-ref-ctx.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG7G,OAAO,EACL,uCAAuC,EACvC,qCAAqC,GACtC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAUnE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAiB;IAChD,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,qCAAqC,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,KAAiB,EACjB,aAAqC;IAErC,IAAI,oBAAoB,CAAC,KAAK,CAAC,IAAI,aAAa,IAAI,oBAAoB,CAAC,aAAa,CAAC,EAAE,CAAC;QACxF,iBAAiB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,KAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"main-thread-ref-ctx.js","sourceRoot":"","sources":["../../../../src/element-template/runtime/template/main-thread-ref-ctx.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG7G,OAAO,EACL,uCAAuC,EACvC,qCAAqC,GACtC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAUnE,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAiB;IAChD,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,qCAAqC,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,KAAiB,EACjB,aAAqC;IAErC,IAAI,oBAAoB,CAAC,KAAK,CAAC,IAAI,aAAa,I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,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QACxB,uCAAuC,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,QAAQ,CAAC;IACnB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,KAAK;KAC0B,CAAC;AACpC,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { hydrateWorkletCtx, runWorkletCtx, updateWorkletRef } from '@lynx-js/react/worklet-runtime/bindings';\nimport type { Element, Worklet, WorkletRefImpl } from '@lynx-js/react/worklet-runtime/bindings';\n\nimport {\n registerMainThreadBackgroundFunctionCtx,\n retainMainThreadBackgroundFunctionCtx,\n} from './main-thread-background-function.js';\nimport { isMainThreadFunction } from '../../../core/main-thread-function.js';\nimport { isMainThreadRef } from '../../../core/main-thread-ref.js';\nimport type { SerializableValue } from '../../protocol/types.js';\n\nexport type MTRefValue = WorkletRefImpl<Element> | Worklet;\n\nexport interface MTRefNativeWrapper {\n type: 'main-thread-ref';\n value: MTRefValue;\n}\n\nexport function isMTRefValue(value: unknown): value is MTRefValue {\n return isMainThreadRef(value) || isMainThreadFunction(value);\n}\n\nexport function retainMTRefValue(value: MTRefValue): void {\n if (isMainThreadFunction(value)) {\n retainMainThreadBackgroundFunctionCtx(value);\n }\n}\n\nexport function hydrateMTRefValue(\n value: MTRefValue,\n previousValue: MTRefValue | undefined,\n): void {\n if (isMainThreadFunction(value) && previousValue && isMainThreadFunction(previousValue)) {\n hydrateWorkletCtx(value, previousValue);\n }\n}\n\nexport function attachMTRefValue(\n value: MTRefValue,\n nativeRef: ElementRef,\n): void {\n if (isMainThreadRef(value)) {\n updateWorkletRef(value, nativeRef);\n return;\n }\n value._unmount = runWorkletCtx(\n value,\n [{ elementRefptr: nativeRef }] as unknown as Parameters<typeof runWorkletCtx>[1],\n ) as () => void;\n}\n\nexport function cleanupMTRefValue(value: MTRefValue): void {\n if (isMainThreadRef(value)) {\n updateWorkletRef(value, null);\n return;\n }\n if (typeof value._unmount === 'function') {\n value._unmount();\n return;\n }\n runWorkletCtx(value, [null]);\n}\n\nexport function prepareMTRefForNative(\n rawValue: unknown,\n previousPreparedValue?: unknown,\n previousRawValue?: unknown,\n): SerializableValue | null {\n if (rawValue === null || rawValue === undefined) {\n return null;\n }\n if (!isMTRefValue(rawValue)) {\n throw new Error('ElementTemplate main-thread:ref expects a MainThreadRef object or a main-thread function.');\n }\n if (previousRawValue === rawValue) {\n return previousPreparedValue as SerializableValue;\n }\n\n let value: MTRefValue;\n if (isMainThreadFunction(rawValue)) {\n value = { ...rawValue };\n registerMainThreadBackgroundFunctionCtx(value);\n } else {\n value = rawValue;\n }\n\n return {\n type: 'main-thread-ref',\n value,\n } as unknown as SerializableValue;\n}\n"]}
|