@lynx-js/react 0.126.1 → 0.127.0
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 +40 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/docs/directives.md +90 -0
- package/docs/global-events.md +50 -0
- package/docs/import-attributes.md +43 -0
- package/docs/macros.md +285 -0
- package/package.json +4 -3
- package/refresh/.turbo/turbo-build.log +4 -4
- package/refresh/dist/index.js +27 -8
- package/refresh/package.json +2 -2
- package/runtime/__test__/core/main-thread-object.test.js +149 -0
- package/runtime/__test__/element-template/debug/profile-installation.test.tsx +97 -1
- package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -1
- package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +26 -3
- package/runtime/__test__/element-template/fixtures/render/child-siblings/index.js.txt +15 -11
- package/runtime/__test__/element-template/fixtures/render/component/index.js.txt +8 -7
- package/runtime/__test__/element-template/fixtures/render/component-slot-content/index.js.txt +14 -10
- package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/index.js.txt +4 -3
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/_shared.ts +2 -9
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/case.ts +2 -4
- package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/case.ts +20 -0
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/case.ts +3 -16
- package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/case.ts +18 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/case.ts +20 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/case.ts +18 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/case.ts +15 -0
- package/runtime/__test__/element-template/fixtures/render/mapped-view-children/index.js.txt +12 -11
- package/runtime/__test__/element-template/fixtures/render/mixed-children/index.js.txt +8 -7
- package/runtime/__test__/element-template/fixtures/render/multiple-text/index.js.txt +15 -13
- package/runtime/__test__/element-template/fixtures/render/nested-templates/index.js.txt +9 -7
- package/runtime/__test__/element-template/fixtures/render/react-example/index.js.txt +17 -20
- package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/index.js.txt +13 -10
- package/runtime/__test__/element-template/fixtures/render/template-dedupe/index.js.txt +14 -11
- package/runtime/__test__/element-template/imports/main-thread-object-api.test.ts +10 -0
- package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +52 -7
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +3 -0
- package/runtime/__test__/element-template/native/reload.test.ts +10 -26
- package/runtime/__test__/element-template/runtime/background/component-stack.test.tsx +76 -0
- package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +87 -43
- package/runtime/__test__/element-template/runtime/background/instance.test.ts +14 -0
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +4 -0
- package/runtime/__test__/element-template/runtime/render/compact-host-debug.test.ts +57 -0
- package/runtime/__test__/element-template/runtime/render/compact-host.test.ts +199 -0
- package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +292 -0
- package/runtime/__test__/element-template/runtime/render/{render-opcodes-into-element-template.et.test.tsx → render-direct-native.test.tsx} +50 -314
- package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +378 -0
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +491 -0
- package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -28
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +21 -35
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -5
- package/runtime/__test__/element-template/test-utils/debug/renderFixtureRunner.ts +4 -4
- package/runtime/__test__/element-template/vitest.config.ts +2 -1
- package/runtime/__test__/snapshot/ctxNotFound.test.ts +271 -0
- package/runtime/__test__/snapshot/debug/main-thread-children-with-same-key.test.ts +28 -0
- package/runtime/__test__/snapshot/debug/profile.test.jsx +108 -3
- package/runtime/__test__/snapshot/event.test.jsx +7 -7
- package/runtime/__test__/snapshot/lazy.test.js +114 -7
- package/runtime/__test__/snapshot/lifecycle/reloadGc.test.jsx +66 -0
- package/runtime/__test__/snapshot/lynx/portals.test.jsx +75 -37
- package/runtime/__test__/snapshot/lynx/runtime-version.test.ts +140 -0
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +59 -47
- package/runtime/__test__/snapshot/spread.test.jsx +32 -25
- package/runtime/__test__/snapshot/ssr.legacy-slot.test.jsx +168 -0
- package/runtime/__test__/snapshot/ssr.list.test.jsx +211 -0
- package/runtime/__test__/snapshot/worklet/main-thread-object.test.jsx +306 -0
- package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +1 -0
- package/runtime/__test__/worklet-runtime/hydrate.test.js +92 -0
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +182 -0
- package/runtime/__test__/worklet-runtime/object-methods.test.js +60 -0
- package/runtime/__test__/worklet-runtime/runOnBackground.test.js +8 -6
- package/runtime/__test__/worklet-runtime/workletRef.test.js +362 -2
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +249 -3
- package/runtime/lazy/compat.js +2 -0
- package/runtime/lazy/element-template-import.js +0 -4
- package/runtime/lazy/element-template-internal.js +19 -8
- package/runtime/lazy/element-template-jsx-dev-runtime.js +1 -8
- package/runtime/lazy/element-template-jsx-runtime.js +1 -3
- package/runtime/lazy/element-template.js +3 -3
- package/runtime/lazy/import.js +0 -4
- package/runtime/lazy/internal.js +17 -1
- package/runtime/lazy/react.js +2 -0
- package/runtime/lazy/target.js +0 -21
- package/runtime/lib/core/background-function/run-on-background.d.ts +16 -0
- package/runtime/lib/core/background-function/run-on-background.js +16 -0
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
- package/runtime/lib/core/capture-main-thread-object.js +16 -0
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -0
- package/runtime/lib/core/globalProps.d.ts +2 -0
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/hooks/react.d.ts +6 -0
- package/runtime/lib/core/hooks/react.js +6 -0
- package/runtime/lib/core/hooks/react.js.map +1 -1
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.d.ts +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
- package/runtime/lib/core/initData.d.ts +2 -0
- package/runtime/lib/core/initData.js +2 -0
- package/runtime/lib/core/initData.js.map +1 -1
- package/runtime/lib/core/lynx/runtime-version.d.ts +16 -0
- package/runtime/lib/core/lynx/runtime-version.js +51 -0
- package/runtime/lib/core/lynx/runtime-version.js.map +1 -0
- package/runtime/lib/core/main-thread-object-handle-registry.d.ts +3 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js +17 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -0
- package/runtime/lib/core/main-thread-object.d.ts +77 -0
- package/runtime/lib/core/main-thread-object.js +261 -0
- package/runtime/lib/core/main-thread-object.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-id.js +14 -0
- package/runtime/lib/core/main-thread-ref-id.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-init-value.d.ts +1 -1
- package/runtime/lib/core/main-thread-ref-init-value.js +4 -2
- package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
- package/runtime/lib/core/main-thread-ref.d.ts +4 -0
- package/runtime/lib/core/main-thread-ref.js +5 -8
- package/runtime/lib/core/main-thread-ref.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/document.d.ts +1 -1
- package/runtime/lib/element-template/background/document.js +1 -1
- package/runtime/lib/element-template/background/document.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +51 -19
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/instance.js +5 -6
- package/runtime/lib/element-template/background/instance.js.map +1 -1
- package/runtime/lib/element-template/debug/profile.js +38 -22
- package/runtime/lib/element-template/debug/profile.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +3 -1
- package/runtime/lib/element-template/index.js +2 -1
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +5 -1
- package/runtime/lib/element-template/internal.js +7 -1
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/native/index.js +4 -0
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +1 -1
- package/runtime/lib/element-template/runtime/list/list.d.ts +1 -0
- package/runtime/lib/element-template/runtime/list/list.js +3 -0
- package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +7 -0
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js +65 -0
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/host.d.ts +18 -0
- package/runtime/lib/element-template/runtime/render/host.js +25 -0
- package/runtime/lib/element-template/runtime/render/host.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/render-components.d.ts +6 -0
- package/runtime/lib/element-template/runtime/render/render-components.js +190 -0
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/{render-opcodes.d.ts → render-direct.d.ts} +3 -1
- package/runtime/lib/element-template/runtime/render/render-direct.js +194 -0
- package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +10 -9
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.d.ts +2 -1
- package/runtime/lib/element-template/runtime/template/handle.js +12 -4
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
- package/runtime/lib/element-template/runtime-marker.d.ts +1 -0
- package/runtime/lib/element-template/runtime-marker.js +13 -0
- package/runtime/lib/element-template/runtime-marker.js.map +1 -0
- package/runtime/lib/index.d.ts +1 -1
- package/runtime/lib/index.js +1 -1
- package/runtime/lib/index.js.map +1 -1
- package/runtime/lib/internal.d.ts +4 -1
- package/runtime/lib/internal.js +6 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +49 -6
- package/runtime/lib/lynx-api.js +34 -4
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +4 -1
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/runtime-marker.d.ts +1 -0
- package/runtime/lib/runtime-marker.js +13 -0
- package/runtime/lib/runtime-marker.js.map +1 -0
- package/runtime/lib/shared/component-stack.js +5 -1
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js +38 -22
- package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.d.ts +11 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.js +24 -16
- package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.d.ts +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +29 -7
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +2 -2
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.js +3 -0
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +3 -0
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/lynx/children.d.ts +2 -0
- package/runtime/lib/snapshot/lynx/children.js.map +1 -1
- package/runtime/lib/snapshot/lynx/element.d.ts +10 -0
- package/runtime/lib/snapshot/lynx/element.js +6 -0
- package/runtime/lib/snapshot/lynx/element.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +2 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -3
- package/runtime/lib/worklet-runtime/bindings/bindings.js +9 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/types.d.ts +3 -6
- package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js +27 -8
- package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.d.ts +8 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js +67 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -0
- package/runtime/lib/worklet-runtime/workletRef.d.ts +11 -7
- package/runtime/lib/worklet-runtime/workletRef.js +72 -9
- package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +69 -19
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/background-function/run-on-background.ts +16 -0
- package/runtime/src/core/capture-main-thread-object.ts +17 -0
- package/runtime/src/core/globalProps.ts +2 -0
- package/runtime/src/core/hooks/react.ts +6 -0
- package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +2 -0
- package/runtime/src/core/initData.ts +2 -0
- package/runtime/src/core/lynx/runtime-version.ts +62 -0
- package/runtime/src/core/main-thread-object-handle-registry.ts +25 -0
- package/runtime/src/core/main-thread-object.ts +387 -0
- package/runtime/src/core/main-thread-ref-id.ts +16 -0
- package/runtime/src/core/main-thread-ref-init-value.ts +12 -4
- package/runtime/src/core/main-thread-ref.ts +7 -8
- package/runtime/src/element-template/background/commit-hook.ts +1 -1
- package/runtime/src/element-template/background/document.ts +3 -3
- package/runtime/src/element-template/background/hydrate.ts +61 -29
- package/runtime/src/element-template/background/instance.ts +5 -6
- package/runtime/src/element-template/debug/profile.ts +48 -36
- package/runtime/src/element-template/index.ts +7 -1
- package/runtime/src/element-template/internal.ts +14 -1
- package/runtime/src/element-template/native/index.ts +4 -0
- package/runtime/src/element-template/protocol/types.ts +1 -1
- package/runtime/src/element-template/runtime/list/list.ts +4 -0
- package/runtime/src/element-template/runtime/render/create-rendered-host.ts +126 -0
- package/runtime/src/element-template/runtime/render/host.ts +51 -0
- package/runtime/src/element-template/runtime/render/render-components.ts +255 -0
- package/runtime/src/element-template/runtime/render/render-direct.ts +275 -0
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +10 -9
- package/runtime/src/element-template/runtime/template/handle.ts +17 -7
- package/runtime/src/element-template/runtime-marker.ts +17 -0
- package/runtime/src/index.ts +1 -1
- package/runtime/src/internal.ts +11 -1
- package/runtime/src/lynx-api.ts +53 -6
- package/runtime/src/lynx.ts +5 -1
- package/runtime/src/runtime-marker.ts +17 -0
- package/runtime/src/shared/component-stack.ts +5 -1
- package/runtime/src/snapshot/debug/profileHooks.ts +52 -40
- package/runtime/src/snapshot/lifecycle/patch/error.ts +36 -19
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +29 -7
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +2 -2
- package/runtime/src/snapshot/lifecycle/reload.ts +4 -0
- package/runtime/src/snapshot/lynx/calledByNative.ts +4 -0
- package/runtime/src/snapshot/lynx/children.ts +2 -0
- package/runtime/src/snapshot/lynx/element.ts +10 -0
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +2 -1
- package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +2 -0
- package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +1 -1
- package/runtime/src/worklet-runtime/bindings/bindings.ts +17 -2
- package/runtime/src/worklet-runtime/bindings/types.ts +7 -11
- package/runtime/src/worklet-runtime/hydrate.ts +44 -11
- package/runtime/src/worklet-runtime/mainThreadObject.ts +117 -0
- package/runtime/src/worklet-runtime/workletRef.ts +120 -19
- package/runtime/src/worklet-runtime/workletRuntime.ts +84 -21
- package/runtime/types/types.d.ts +2 -0
- package/runtime/worklet-runtime/dev.js +155 -30
- package/runtime/worklet-runtime/main.js +1 -1
- package/testing-library/.turbo/turbo-build.log +12 -12
- package/testing-library/dist/env/index.js +2 -2
- package/testing-library/dist/index.d.ts +167 -4
- package/testing-library/dist/plugins/index.js +1 -1
- package/testing-library/dist/pure.js +45 -44
- package/testing-library/etc/react-lynx-testing-library.api.md +1 -1
- package/testing-library/package.json +4 -3
- package/testing-library/src/__tests__/lynx.test.jsx +1 -1
- package/testing-library/src/__tests__/reload/reloadGc.test.jsx +64 -0
- package/testing-library/src/__tests__/reload/reloadTemplate.js +39 -0
- package/testing-library/src/__tests__/worklet.test.jsx +46 -1
- package/testing-library/tsconfig.docs.json +9 -0
- package/testing-library/typedoc.json +22 -0
- package/testing-library/types/entry.d.ts +2 -2
- package/transform/.turbo/turbo-build$colon$wasm.log +151 -67
- package/transform/__test__/fixture.spec.js +89 -50
- package/transform/__test__/object-methods.spec.js +84 -0
- package/transform/__test__/text.spec.js +75 -0
- package/transform/crates/swc_plugin_compat/lib.rs +4 -3
- package/transform/crates/swc_plugin_compat/napi.rs +4 -3
- package/transform/crates/swc_plugin_define_dce/napi.rs +1 -1
- package/transform/crates/swc_plugin_dynamic_import/lib.rs +105 -3
- package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_suffix_webpack_chunk_name.js +5 -0
- package/transform/crates/swc_plugin_element_template/host_lowering.rs +111 -0
- package/transform/crates/swc_plugin_element_template/lib.rs +41 -5
- package/transform/crates/swc_plugin_element_template/lowering.rs +39 -7
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_generate_attribute_slots_for_dynamic_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_background_conditional_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_boolean_and_number_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_complex_text_structure.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dataset_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_deeply_nested_user_components.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dynamic_class_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_events_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_id_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_inline_styles.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_interpolated_text_with_siblings_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_mixed_content.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_nested_structure_and_dynamic_content.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_refs_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_sibling_user_components.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_spread_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_user_component.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_isolate_arrays_with_child_slot_placeholder.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_keep_code_and_template_attribute_slots_in_sync_for_spread.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_element_template_simple_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_template_with_static_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_template_structure_complex.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_text_attribute_and_child_text_slots.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/element_template.rs +70 -66
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +94 -8
- package/transform/crates/swc_plugin_shake/lib.rs +1 -1
- package/transform/crates/swc_plugin_shake/napi.rs +1 -1
- package/transform/crates/swc_plugin_text/lib.rs +57 -16
- package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_keep_children_for_dynamic_or_multiple_text.js +13 -0
- package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_transform_string_expressions_to_text_attr.js +13 -0
- package/transform/crates/swc_plugin_worklet/decl_collect.rs +10 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +14 -0
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +202 -3
- package/transform/crates/swc_plugin_worklet/lib.rs +468 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +8 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +10 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_js.js +27 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +45 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +16 -14
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +16 -16
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +7 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +7 -7
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +24 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +16 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +42 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +58 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +3 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +3 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_js.js +9 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +16 -0
- package/transform/crates/swc_plugins_shared/jsx_helpers.rs +8 -4
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +7 -6
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/src/swc_plugin_extract_str/mod.rs +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +63 -270
- package/transform/swc-plugin-reactlynx/index.d.ts +2 -2
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +306 -170
- package/transform/swc-plugin-reactlynx-compat/index.d.ts +3 -3
- package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
- package/transform/vitest.config.ts +5 -1
- package/types/react.docs.d.ts +130 -11
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/case.ts +0 -39
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/case.ts +0 -29
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/case.ts +0 -42
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/case.ts +0 -31
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/passes-bundle-url-to-native-create/case.ts +0 -20
- package/runtime/__test__/element-template/runtime/render/render-to-opcodes.et.test.jsx +0 -522
- package/runtime/lib/element-template/runtime/render/render-opcodes.js +0 -216
- package/runtime/lib/element-template/runtime/render/render-opcodes.js.map +0 -1
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.d.ts +0 -16
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.js +0 -324
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.js.map +0 -1
- package/runtime/lib/element-template/runtime-backend-marker.js +0 -6
- package/runtime/lib/element-template/runtime-backend-marker.js.map +0 -1
- package/runtime/lib/runtime-backend-marker.js +0 -6
- package/runtime/lib/runtime-backend-marker.js.map +0 -1
- package/runtime/src/element-template/runtime/render/render-opcodes.ts +0 -313
- package/runtime/src/element-template/runtime/render/render-to-opcodes.ts +0 -411
- package/runtime/src/element-template/runtime-backend-marker.ts +0 -7
- package/runtime/src/runtime-backend-marker.ts +0 -7
- package/testing-library/node_modules/.bin/rsbuild +0 -55
- package/testing-library/node_modules/.bin/rspeedy +0 -55
- package/testing-library/node_modules/.bin/rstest +0 -55
- package/transform/node_modules/.bin/esbuild +0 -46
- package/transform/node_modules/.bin/napi +0 -55
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/passes-bundle-url-to-native-create/native-log.txt +0 -0
- /package/runtime/lib/{element-template/runtime-backend-marker.d.ts → core/capture-main-thread-object.d.ts} +0 -0
- /package/runtime/lib/{runtime-backend-marker.d.ts → core/main-thread-ref-id.d.ts} +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { onHydrationFinished, onWorkletCtxUpdate } from '../../src/worklet-runtime/bindings/observers';
|
|
7
|
+
import { updateWorkletRefInitValueChanges } from '../../src/worklet-runtime/workletRef';
|
|
8
|
+
import { initWorklet } from '../../src/worklet-runtime/workletRuntime';
|
|
9
|
+
|
|
10
|
+
function nestContext(ctx, depth) {
|
|
11
|
+
for (let i = 1; i <= depth; i++) {
|
|
12
|
+
ctx = { _wkltId: `parent-${i}`, _c: { child: ctx } };
|
|
13
|
+
}
|
|
14
|
+
return ctx;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
globalThis.SystemInfo = { lynxSdkVersion: '2.16' };
|
|
19
|
+
initWorklet();
|
|
20
|
+
for (let i = 1; i <= 2; i++) {
|
|
21
|
+
globalThis.registerWorklet('main-thread', `parent-${i}`, function(...args) {
|
|
22
|
+
return this._c.child(...args);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
// Model collection of weak targets deterministically. Hydration must work
|
|
26
|
+
// through the live function even when no weak reference can recover its original context.
|
|
27
|
+
vi.spyOn(globalThis, 'WeakRef').mockImplementation(function() {
|
|
28
|
+
return { deref: () => undefined };
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
vi.restoreAllMocks();
|
|
34
|
+
delete globalThis.lynxWorkletImpl;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe.each([0, 1, 2])('hydration at nesting depth %i', (depth) => {
|
|
38
|
+
it('preserves first-screen ref identity and writes across event contexts', () => {
|
|
39
|
+
globalThis.registerWorklet('main-thread', 'write', function(width) {
|
|
40
|
+
this._c.ref.current.width = width;
|
|
41
|
+
return this._c.ref;
|
|
42
|
+
});
|
|
43
|
+
globalThis.registerWorklet('main-thread', 'read', function() {
|
|
44
|
+
return this._c.ref;
|
|
45
|
+
});
|
|
46
|
+
const firstScreen = nestContext({
|
|
47
|
+
_wkltId: 'write',
|
|
48
|
+
_c: { ref: { _wvid: -1, _initValue: { width: 0 } } },
|
|
49
|
+
}, depth);
|
|
50
|
+
const firstScreenRef = globalThis.runWorklet(firstScreen, [240]);
|
|
51
|
+
const background = nestContext({
|
|
52
|
+
_wkltId: 'write',
|
|
53
|
+
_c: { ref: { _wvid: 1 } },
|
|
54
|
+
}, depth);
|
|
55
|
+
background._execId = 8;
|
|
56
|
+
updateWorkletRefInitValueChanges([[1, { width: 0 }]]);
|
|
57
|
+
|
|
58
|
+
onWorkletCtxUpdate(background, firstScreen, true, {});
|
|
59
|
+
onHydrationFinished();
|
|
60
|
+
|
|
61
|
+
const reader = { _wkltId: 'read', _c: { ref: { _wvid: 1 } } };
|
|
62
|
+
const hydratedRef = globalThis.runWorklet(reader, []);
|
|
63
|
+
expect(hydratedRef).toBe(firstScreenRef);
|
|
64
|
+
expect(hydratedRef.current.width).toBe(240);
|
|
65
|
+
globalThis.runWorklet(background, [480]);
|
|
66
|
+
expect(globalThis.runWorklet(reader, []).current.width).toBe(480);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('runs first-screen delayed background calls after hydration', () => {
|
|
70
|
+
const task = vi.fn();
|
|
71
|
+
globalThis.registerWorklet('main-thread', 'call', function() {
|
|
72
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground(this._jsFn.callback, task);
|
|
73
|
+
});
|
|
74
|
+
const firstScreen = nestContext({
|
|
75
|
+
_wkltId: 'call',
|
|
76
|
+
_jsFn: { callback: { _isFirstScreen: true } },
|
|
77
|
+
}, depth);
|
|
78
|
+
globalThis.runWorklet(firstScreen, []);
|
|
79
|
+
expect(task).not.toHaveBeenCalled();
|
|
80
|
+
const background = nestContext({
|
|
81
|
+
_wkltId: 'call',
|
|
82
|
+
_jsFn: { callback: { _jsFnId: 3 } },
|
|
83
|
+
}, depth);
|
|
84
|
+
background._execId = 8;
|
|
85
|
+
|
|
86
|
+
onWorkletCtxUpdate(background, firstScreen, true, {});
|
|
87
|
+
onHydrationFinished();
|
|
88
|
+
|
|
89
|
+
expect(task).toHaveBeenCalledExactlyOnceWith(3, 8);
|
|
90
|
+
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(0);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
getFromWorkletRefMap,
|
|
8
|
+
isHydratedWorkletValue,
|
|
9
|
+
removeValueFromWorkletRefMap,
|
|
10
|
+
updateWorkletRefInitValueChanges,
|
|
11
|
+
} from '../../src/worklet-runtime/workletRef';
|
|
12
|
+
import { initWorklet } from '../../src/worklet-runtime/workletRuntime';
|
|
13
|
+
|
|
14
|
+
const originalDev = globalThis.__DEV__;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
globalThis.__DEV__ = false;
|
|
18
|
+
globalThis.SystemInfo = {
|
|
19
|
+
lynxSdkVersion: '2.16',
|
|
20
|
+
};
|
|
21
|
+
initWorklet();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
globalThis.__DEV__ = originalDev;
|
|
26
|
+
delete globalThis.lynxWorkletImpl;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('MainThreadObject registry and realization', () => {
|
|
30
|
+
it('creates registered main-thread objects from typed patches', () => {
|
|
31
|
+
const value = { get: () => 42 };
|
|
32
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
33
|
+
'@test/value',
|
|
34
|
+
() => value,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
updateWorkletRefInitValueChanges([[7, 42, '@test/value']]);
|
|
38
|
+
|
|
39
|
+
expect(getFromWorkletRefMap({ _wvid: 7 })).toBe(value);
|
|
40
|
+
removeValueFromWorkletRefMap(7);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('lazily resolves and caches Main Thread Function factory descriptors', () => {
|
|
44
|
+
const create = vi.fn(value => ({ value }));
|
|
45
|
+
const createDescriptor = { _wkltId: 'create-test-value' };
|
|
46
|
+
const bindFactory = vi.spyOn(create, 'bind');
|
|
47
|
+
|
|
48
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
49
|
+
'@test/lazy-factory',
|
|
50
|
+
createDescriptor,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// Type definition evaluation happens before the compiler-appended
|
|
54
|
+
// registerWorklet calls at the end of the MTS module.
|
|
55
|
+
globalThis.registerWorklet('main-thread', 'create-test-value', create);
|
|
56
|
+
const lookupFactory = vi.fn(() => create);
|
|
57
|
+
Object.defineProperty(lynxWorkletImpl._workletMap, 'create-test-value', { get: lookupFactory });
|
|
58
|
+
|
|
59
|
+
updateWorkletRefInitValueChanges([
|
|
60
|
+
[71, 'first', '@test/lazy-factory'],
|
|
61
|
+
[72, 'second', '@test/lazy-factory'],
|
|
62
|
+
]);
|
|
63
|
+
expect(getFromWorkletRefMap({ _wvid: 71 })).toMatchObject({ value: 'first' });
|
|
64
|
+
expect(getFromWorkletRefMap({ _wvid: 72 })).toMatchObject({ value: 'second' });
|
|
65
|
+
expect(create).toHaveBeenCalledTimes(2);
|
|
66
|
+
expect(lookupFactory).toHaveBeenCalledOnce();
|
|
67
|
+
expect(bindFactory).not.toHaveBeenCalled();
|
|
68
|
+
|
|
69
|
+
removeValueFromWorkletRefMap(71);
|
|
70
|
+
removeValueFromWorkletRefMap(72);
|
|
71
|
+
expect(lookupFactory).toHaveBeenCalledOnce();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('rejects an unregistered main-thread object type', () => {
|
|
75
|
+
expect(() => {
|
|
76
|
+
updateWorkletRefInitValueChanges([[8, 42, '@test/missing']]);
|
|
77
|
+
}).toThrow('MainThreadObject type is not registered: "@test/missing"');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it.each([{}, { _lepusWorkletHash: 'legacy' }, { _wkltId: 'legacy', _lepusWorkletHash: 'legacy' }])(
|
|
81
|
+
'rejects invalid factory descriptors %j',
|
|
82
|
+
(descriptor) => {
|
|
83
|
+
lynxWorkletImpl._refImpl.registerMainThreadObjectType('@test/invalid-factory', descriptor);
|
|
84
|
+
expect(() => updateWorkletRefInitValueChanges([[1, null, '@test/invalid-factory']]))
|
|
85
|
+
.toThrow('Cannot resolve an invalid Main Thread Function.');
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
it('rejects conflicting registrations for the same type key', () => {
|
|
90
|
+
const create = value => ({ value });
|
|
91
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
92
|
+
'@test/value',
|
|
93
|
+
create,
|
|
94
|
+
);
|
|
95
|
+
expect(() => {
|
|
96
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
97
|
+
'@test/value',
|
|
98
|
+
value => ({ conflictingValue: value }),
|
|
99
|
+
);
|
|
100
|
+
}).toThrow('Conflicting MainThreadObject registration for type "@test/value"');
|
|
101
|
+
expect(() => {
|
|
102
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
103
|
+
'@test/value',
|
|
104
|
+
create,
|
|
105
|
+
);
|
|
106
|
+
}).not.toThrow();
|
|
107
|
+
|
|
108
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
109
|
+
'@test/worklet-value',
|
|
110
|
+
{ _wkltId: 'stable-create' },
|
|
111
|
+
);
|
|
112
|
+
expect(() => {
|
|
113
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
114
|
+
'@test/worklet-value',
|
|
115
|
+
{ _wkltId: 'stable-create' },
|
|
116
|
+
);
|
|
117
|
+
}).not.toThrow();
|
|
118
|
+
expect(() => {
|
|
119
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
120
|
+
'@test/worklet-value',
|
|
121
|
+
{ _wkltId: 'different-create' },
|
|
122
|
+
);
|
|
123
|
+
}).toThrow('Conflicting MainThreadObject registration for type "@test/worklet-value"');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('reserves the legacy MainThreadRef type key for typed registrations', () => {
|
|
127
|
+
expect(() => {
|
|
128
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
129
|
+
'main-thread',
|
|
130
|
+
value => ({ value }),
|
|
131
|
+
);
|
|
132
|
+
}).toThrow(
|
|
133
|
+
'MainThreadObject type "main-thread" is reserved for MainThreadRef.',
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('allows equivalent registrations from separately evaluated modules', () => {
|
|
138
|
+
const createDefinition = () => value => ({ value });
|
|
139
|
+
const createA = createDefinition();
|
|
140
|
+
const createB = createDefinition();
|
|
141
|
+
|
|
142
|
+
expect(createA).not.toBe(createB);
|
|
143
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
144
|
+
'@test/lazy-duplicate',
|
|
145
|
+
createA,
|
|
146
|
+
);
|
|
147
|
+
expect(() => {
|
|
148
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
149
|
+
'@test/lazy-duplicate',
|
|
150
|
+
createB,
|
|
151
|
+
);
|
|
152
|
+
}).not.toThrow();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('rejects factories that do not create objects', () => {
|
|
156
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
157
|
+
'@test/invalid',
|
|
158
|
+
() => 42,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
expect(() => {
|
|
162
|
+
updateWorkletRefInitValueChanges([[10, 42, '@test/invalid']]);
|
|
163
|
+
}).toThrow('MainThreadObject type "@test/invalid" created a non-object value.');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('recognizes realized objects before inspecting their properties', () => {
|
|
167
|
+
const value = new Proxy({ value: 42 }, {
|
|
168
|
+
get() {
|
|
169
|
+
throw new Error('unexpected property access');
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
globalThis.lynxWorkletImpl._refImpl.registerMainThreadObjectType(
|
|
173
|
+
'@test/proxy-value',
|
|
174
|
+
() => value,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
updateWorkletRefInitValueChanges([[93, null, '@test/proxy-value']]);
|
|
178
|
+
|
|
179
|
+
expect(isHydratedWorkletValue(getFromWorkletRefMap({ _wvid: 93 }))).toBe(true);
|
|
180
|
+
removeValueFromWorkletRefMap(93);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 that can be found in the LICENSE file in the root directory.
|
|
3
|
+
import { afterEach, expect, it } from 'vitest';
|
|
4
|
+
import { transformReactLynxSync } from '@lynx-js/react-transform';
|
|
5
|
+
|
|
6
|
+
import { initApiEnv } from '../../src/worklet-runtime/api/lynxApi';
|
|
7
|
+
import { initWorklet } from '../../src/worklet-runtime/workletRuntime';
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
delete globalThis.lynxWorkletImpl;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('resolves a compiler-generated object method through whole-object captures', () => {
|
|
14
|
+
globalThis.SystemInfo = { lynxSdkVersion: '2.16' };
|
|
15
|
+
initApiEnv();
|
|
16
|
+
initWorklet();
|
|
17
|
+
const result = transformReactLynxSync(
|
|
18
|
+
`
|
|
19
|
+
export const source = {
|
|
20
|
+
value: 1,
|
|
21
|
+
method() { 'main thread'; return this.value; },
|
|
22
|
+
};
|
|
23
|
+
`,
|
|
24
|
+
{
|
|
25
|
+
mode: 'test',
|
|
26
|
+
pluginName: '',
|
|
27
|
+
filename: 'method.js',
|
|
28
|
+
sourcemap: false,
|
|
29
|
+
cssScope: false,
|
|
30
|
+
shake: false,
|
|
31
|
+
compat: false,
|
|
32
|
+
refresh: false,
|
|
33
|
+
defineDCE: { define: {} },
|
|
34
|
+
directiveDCE: { target: 'LEPUS' },
|
|
35
|
+
snapshot: {
|
|
36
|
+
preserveJsx: false,
|
|
37
|
+
runtimePkg: '@lynx-js/react/internal',
|
|
38
|
+
jsxImportSource: '@lynx-js/react/lepus',
|
|
39
|
+
target: 'LEPUS',
|
|
40
|
+
filename: 'method',
|
|
41
|
+
},
|
|
42
|
+
worklet: { target: 'LEPUS', filename: 'method.js', runtimePkg: '@lynx-js/react/internal' },
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
const source = new Function(
|
|
46
|
+
'__loadWorkletRuntime',
|
|
47
|
+
'registerWorkletInternal',
|
|
48
|
+
`${result.code.replace(/^import .*;$/gm, '').replace('export const source', 'const source')}\nreturn source;`,
|
|
49
|
+
)(() => true, registerWorklet);
|
|
50
|
+
registerWorklet('main-thread', 'parent', function() {
|
|
51
|
+
return this._c.source.method;
|
|
52
|
+
});
|
|
53
|
+
const first = runWorklet({ _wkltId: 'parent', _c: { source } }, []);
|
|
54
|
+
expect(first()).toBe(1);
|
|
55
|
+
source.value = 2;
|
|
56
|
+
const second = runWorklet({ _wkltId: 'parent', _c: { source } }, []);
|
|
57
|
+
expect(second()).toBe(2);
|
|
58
|
+
expect(first()).toBe(1);
|
|
59
|
+
expect(Object.getOwnPropertyDescriptor(source, 'method').get).toBeTypeOf('function');
|
|
60
|
+
});
|
|
@@ -17,7 +17,7 @@ afterEach(() => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
describe('runOnBackground', () => {
|
|
20
|
-
it('should
|
|
20
|
+
it('should expose the bound copy without retaining the original nested context', () => {
|
|
21
21
|
const childCtx = {
|
|
22
22
|
_wkltId: 'child',
|
|
23
23
|
};
|
|
@@ -29,15 +29,17 @@ describe('runOnBackground', () => {
|
|
|
29
29
|
globalThis.registerWorklet('main-thread', 'parent', function() {
|
|
30
30
|
return this.child;
|
|
31
31
|
});
|
|
32
|
-
globalThis.registerWorklet('main-thread', 'child', function() {
|
|
32
|
+
globalThis.registerWorklet('main-thread', 'child', function() {
|
|
33
|
+
return this;
|
|
34
|
+
});
|
|
33
35
|
|
|
34
36
|
const childWorklet = globalThis.runWorklet(parentCtx, []);
|
|
35
|
-
expect(childWorklet).
|
|
37
|
+
expect(childWorklet.boundCtx).toBe(childWorklet());
|
|
38
|
+
expect(childWorklet.boundCtx).not.toBe(childCtx);
|
|
36
39
|
expect(childWorklet).not.toHaveProperty('ctx');
|
|
37
|
-
expect(childWorklet.ctxRef.deref()).toBe(childCtx);
|
|
38
40
|
});
|
|
39
41
|
|
|
40
|
-
it('should hydrate nested worklet ctx from
|
|
42
|
+
it('should hydrate nested worklet ctx from its bound context', () => {
|
|
41
43
|
const firstScreenChildCtx = {
|
|
42
44
|
_wkltId: 'child',
|
|
43
45
|
_jsFn: {
|
|
@@ -47,7 +49,7 @@ describe('runOnBackground', () => {
|
|
|
47
49
|
const firstScreenWorklet = {
|
|
48
50
|
_wkltId: 'parent',
|
|
49
51
|
child: Object.assign(function() {}, {
|
|
50
|
-
|
|
52
|
+
boundCtx: firstScreenChildCtx,
|
|
51
53
|
}),
|
|
52
54
|
};
|
|
53
55
|
const worklet = {
|