@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
|
@@ -3,14 +3,24 @@
|
|
|
3
3
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
4
4
|
// LICENSE file in the root directory of this source tree.
|
|
5
5
|
*/
|
|
6
|
-
import { render, options, Component } from 'preact';
|
|
7
|
-
import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
6
|
+
import { render, options, Component, createElement } from 'preact';
|
|
7
|
+
import { beforeAll, beforeEach, describe, expect, onTestFinished, test, vi } from 'vitest';
|
|
8
8
|
|
|
9
9
|
import { setupDocument } from '../../../src/document';
|
|
10
10
|
import { setupPage, snapshotInstanceManager } from '../../../src/snapshot';
|
|
11
11
|
import { initProfileHook } from '../../../src/snapshot/debug/profileHooks';
|
|
12
12
|
import { useState } from '../../../src/index';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
COMMIT,
|
|
15
|
+
COMPONENT,
|
|
16
|
+
DIFF,
|
|
17
|
+
DIFF2,
|
|
18
|
+
DIFFED,
|
|
19
|
+
HOOKS,
|
|
20
|
+
LIST,
|
|
21
|
+
RENDER,
|
|
22
|
+
VNODE,
|
|
23
|
+
} from '../../../src/shared/render-constants';
|
|
14
24
|
|
|
15
25
|
describe('profile', () => {
|
|
16
26
|
let scratch;
|
|
@@ -25,6 +35,101 @@ describe('profile', () => {
|
|
|
25
35
|
lynx.performance.profileMark.mockClear();
|
|
26
36
|
});
|
|
27
37
|
|
|
38
|
+
test.each(['main', 'background'])('preserves profiling callback contracts on %s', target => {
|
|
39
|
+
vi.stubGlobal('__MAIN_THREAD__', target === 'main');
|
|
40
|
+
vi.stubGlobal('__BACKGROUND__', target === 'background');
|
|
41
|
+
const previousHooks = {
|
|
42
|
+
[COMMIT]: options[COMMIT],
|
|
43
|
+
[DIFF]: options[DIFF],
|
|
44
|
+
[DIFF2]: options[DIFF2],
|
|
45
|
+
[DIFFED]: options[DIFFED],
|
|
46
|
+
[RENDER]: options[RENDER],
|
|
47
|
+
};
|
|
48
|
+
const previousSetState = Component.prototype.setState;
|
|
49
|
+
onTestFinished(() => {
|
|
50
|
+
Object.assign(options, previousHooks);
|
|
51
|
+
Component.prototype.setState = previousSetState;
|
|
52
|
+
vi.unstubAllGlobals();
|
|
53
|
+
});
|
|
54
|
+
const events = [];
|
|
55
|
+
const performance = lynx.performance;
|
|
56
|
+
const oldSetState = Component.prototype.setState = vi.fn(function(state, callback) {
|
|
57
|
+
expect(this).toBe(instance);
|
|
58
|
+
expect(state).toBe(nextState);
|
|
59
|
+
expect(callback).toBe(setStateCallback);
|
|
60
|
+
events.push('old setState');
|
|
61
|
+
});
|
|
62
|
+
const oldDiff = options[DIFF] = vi.fn(() => events.push('old before diff'));
|
|
63
|
+
const oldCommit = options[COMMIT] = vi.fn(() => {
|
|
64
|
+
expect(performance.profileStart).toHaveBeenLastCalledWith('ReactLynx::commit', {});
|
|
65
|
+
events.push('old commit');
|
|
66
|
+
});
|
|
67
|
+
const oldDiff2 = options[DIFF2] = vi.fn(() => {
|
|
68
|
+
expect(performance.profileStart).toHaveBeenLastCalledWith('ReactLynx::diff::Example', {});
|
|
69
|
+
events.push('old diff');
|
|
70
|
+
});
|
|
71
|
+
const oldDiffed = options[DIFFED] = vi.fn(() => {
|
|
72
|
+
expect(performance.profileEnd).toHaveBeenCalledTimes(2);
|
|
73
|
+
events.push('old diffed');
|
|
74
|
+
});
|
|
75
|
+
const oldRender = options[RENDER] = vi.fn(() => {
|
|
76
|
+
expect(instance.render).not.toBe(originalRender);
|
|
77
|
+
events.push('old render');
|
|
78
|
+
});
|
|
79
|
+
initProfileHook();
|
|
80
|
+
|
|
81
|
+
const failure = new Error('render failed');
|
|
82
|
+
class Example extends Component {
|
|
83
|
+
render() {
|
|
84
|
+
expect(this).toBe(instance);
|
|
85
|
+
expect(performance.profileStart).toHaveBeenLastCalledWith('ReactLynx::render::Example');
|
|
86
|
+
events.push('render');
|
|
87
|
+
throw failure;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const vnode = createElement(Example, {});
|
|
91
|
+
const oldVNode = createElement(Example, {});
|
|
92
|
+
const instance = vnode[COMPONENT] = new Example({});
|
|
93
|
+
const originalRender = instance.render;
|
|
94
|
+
|
|
95
|
+
const nextState = { count: 1 };
|
|
96
|
+
const setStateCallback = () => {};
|
|
97
|
+
const commitQueue = [instance];
|
|
98
|
+
instance.setState(nextState, setStateCallback);
|
|
99
|
+
options[DIFF]?.(vnode);
|
|
100
|
+
options[DIFF2]?.(vnode, oldVNode);
|
|
101
|
+
options[RENDER]?.(vnode);
|
|
102
|
+
expect(() => instance.render()).toThrow(failure);
|
|
103
|
+
expect(instance.render).toBe(originalRender);
|
|
104
|
+
options[DIFFED]?.(vnode);
|
|
105
|
+
|
|
106
|
+
if (target === 'background') {
|
|
107
|
+
options[COMMIT]?.(vnode, commitQueue);
|
|
108
|
+
expect(oldCommit.mock.calls).toEqual([[vnode, commitQueue]]);
|
|
109
|
+
expect(oldCommit.mock.contexts).toEqual([undefined]);
|
|
110
|
+
expect(performance.profileEnd).toHaveBeenCalledTimes(3);
|
|
111
|
+
expect(oldDiff.mock.contexts).toEqual([undefined]);
|
|
112
|
+
}
|
|
113
|
+
expect(oldSetState.mock.calls).toEqual([[nextState, setStateCallback]]);
|
|
114
|
+
expect(oldSetState.mock.contexts).toEqual([instance]);
|
|
115
|
+
expect(oldDiff.mock.calls).toEqual([[vnode]]);
|
|
116
|
+
expect(oldDiff2.mock.calls).toEqual([[vnode, oldVNode]]);
|
|
117
|
+
expect(oldRender.mock.calls).toEqual([[vnode]]);
|
|
118
|
+
expect(oldDiffed.mock.calls).toEqual([[vnode]]);
|
|
119
|
+
expect(oldDiff2.mock.contexts).toEqual([undefined]);
|
|
120
|
+
expect(oldRender.mock.contexts).toEqual([undefined]);
|
|
121
|
+
expect(oldDiffed.mock.contexts).toEqual([undefined]);
|
|
122
|
+
expect(events).toEqual([
|
|
123
|
+
'old setState',
|
|
124
|
+
'old before diff',
|
|
125
|
+
'old diff',
|
|
126
|
+
'old render',
|
|
127
|
+
'render',
|
|
128
|
+
'old diffed',
|
|
129
|
+
...(target === 'background' ? ['old commit'] : []),
|
|
130
|
+
]);
|
|
131
|
+
});
|
|
132
|
+
|
|
28
133
|
test('original options hooks should be called', async () => {
|
|
29
134
|
const noop = vi.fn();
|
|
30
135
|
|
|
@@ -221,7 +221,7 @@ describe('eventUpdate', () => {
|
|
|
221
221
|
]
|
|
222
222
|
`);
|
|
223
223
|
globalEnvManager.switchToMainThread();
|
|
224
|
-
snapshotPatchApply(patch);
|
|
224
|
+
snapshotPatchApply(patch, 42, false);
|
|
225
225
|
expect(__root.__element_root).toMatchInlineSnapshot(`
|
|
226
226
|
<page
|
|
227
227
|
cssId="default-entry-from-native:0"
|
|
@@ -324,7 +324,7 @@ describe('eventUpdate', () => {
|
|
|
324
324
|
]
|
|
325
325
|
`);
|
|
326
326
|
globalEnvManager.switchToMainThread();
|
|
327
|
-
snapshotPatchApply(patch);
|
|
327
|
+
snapshotPatchApply(patch, 42, false);
|
|
328
328
|
expect(__root.__element_root).toMatchInlineSnapshot(`
|
|
329
329
|
<page
|
|
330
330
|
cssId="default-entry-from-native:0"
|
|
@@ -437,7 +437,7 @@ describe('eventUpdate', () => {
|
|
|
437
437
|
patch = takeGlobalSnapshotPatch();
|
|
438
438
|
expect(patch).toMatchInlineSnapshot(`[]`);
|
|
439
439
|
globalEnvManager.switchToMainThread();
|
|
440
|
-
snapshotPatchApply(patch);
|
|
440
|
+
snapshotPatchApply(patch, 42, false);
|
|
441
441
|
globalEnvManager.switchToBackground();
|
|
442
442
|
|
|
443
443
|
lynx.getApp().publishEvent('-2:0:', 'data3');
|
|
@@ -616,7 +616,7 @@ describe('eventUpdate', () => {
|
|
|
616
616
|
]
|
|
617
617
|
`);
|
|
618
618
|
globalEnvManager.switchToMainThread();
|
|
619
|
-
snapshotPatchApply(patch);
|
|
619
|
+
snapshotPatchApply(patch, 42, false);
|
|
620
620
|
expect(__root.__element_root).toMatchInlineSnapshot(`
|
|
621
621
|
<page
|
|
622
622
|
cssId="default-entry-from-native:0"
|
|
@@ -784,7 +784,7 @@ describe('event in spread', () => {
|
|
|
784
784
|
]
|
|
785
785
|
`);
|
|
786
786
|
globalEnvManager.switchToMainThread();
|
|
787
|
-
snapshotPatchApply(patch);
|
|
787
|
+
snapshotPatchApply(patch, 42, false);
|
|
788
788
|
expect(__root.__element_root).toMatchInlineSnapshot(`
|
|
789
789
|
<page
|
|
790
790
|
cssId="default-entry-from-native:0"
|
|
@@ -858,7 +858,7 @@ describe('event in spread', () => {
|
|
|
858
858
|
`);
|
|
859
859
|
|
|
860
860
|
globalEnvManager.switchToMainThread();
|
|
861
|
-
snapshotPatchApply(patch);
|
|
861
|
+
snapshotPatchApply(patch, 42, false);
|
|
862
862
|
expect(__root.__element_root).toMatchInlineSnapshot(`
|
|
863
863
|
<page
|
|
864
864
|
cssId="default-entry-from-native:0"
|
|
@@ -953,7 +953,7 @@ describe('event in spread', () => {
|
|
|
953
953
|
]
|
|
954
954
|
`);
|
|
955
955
|
globalEnvManager.switchToMainThread();
|
|
956
|
-
snapshotPatchApply(patch);
|
|
956
|
+
snapshotPatchApply(patch, 42, false);
|
|
957
957
|
expect(__root.__element_root).toMatchInlineSnapshot(`
|
|
958
958
|
<page
|
|
959
959
|
cssId="default-entry-from-native:0"
|
|
@@ -9,12 +9,17 @@ import * as ReactJSXRuntimeExports from '../../lazy/jsx-runtime.js';
|
|
|
9
9
|
import * as ReactJSXDevRuntimeExports from '../../lazy/jsx-dev-runtime.js';
|
|
10
10
|
import * as ReactLegacyReactRuntimeExports from '../../lazy/legacy-react-runtime.js';
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
sExportsReact,
|
|
13
|
+
sExportsReactCompat,
|
|
14
|
+
sExportsReactInternal,
|
|
15
15
|
sRuntimeBackend,
|
|
16
16
|
target,
|
|
17
17
|
} from '../../lazy/target.js';
|
|
18
|
+
const {
|
|
19
|
+
RUNTIME_BACKEND_ELEMENT_TEMPLATE,
|
|
20
|
+
RUNTIME_BACKEND_SNAPSHOT,
|
|
21
|
+
registerRuntimeBackend,
|
|
22
|
+
} = ReactInternalExports;
|
|
18
23
|
|
|
19
24
|
function restoreDescriptor(target, symbol, descriptor) {
|
|
20
25
|
if (descriptor) {
|
|
@@ -44,6 +49,18 @@ async function withRuntimeBackend(backend, callback) {
|
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
|
|
52
|
+
async function withoutRecordedRuntimeVersion(callback) {
|
|
53
|
+
const symbol = Symbol.for('__REACT_LYNX_RUNTIME_VERSION__');
|
|
54
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, symbol);
|
|
55
|
+
delete target[symbol];
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
return await callback();
|
|
59
|
+
} finally {
|
|
60
|
+
restoreDescriptor(target, symbol, descriptor);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
47
64
|
describe('Lazy Exports', () => {
|
|
48
65
|
test('export APIs from "react"', async () => {
|
|
49
66
|
const realAPIs = Object.assign(
|
|
@@ -136,6 +153,60 @@ describe('Lazy Exports', () => {
|
|
|
136
153
|
);
|
|
137
154
|
});
|
|
138
155
|
|
|
156
|
+
test('forwards MainThreadObject lazy exports from the host runtime', () => {
|
|
157
|
+
expect(ReactExports.defineMainThreadObjectType).toBe(
|
|
158
|
+
target[sExportsReact].defineMainThreadObjectType,
|
|
159
|
+
);
|
|
160
|
+
expect(ReactExports.useMainThreadObject).toBe(target[sExportsReact].useMainThreadObject);
|
|
161
|
+
expect(ReactCompatExports.defineMainThreadObjectType).toBe(
|
|
162
|
+
target[sExportsReactCompat].defineMainThreadObjectType,
|
|
163
|
+
);
|
|
164
|
+
expect(ReactCompatExports.useMainThreadObject).toBe(
|
|
165
|
+
target[sExportsReactCompat].useMainThreadObject,
|
|
166
|
+
);
|
|
167
|
+
expect(ReactInternalExports.captureMainThreadObject).toBe(
|
|
168
|
+
target[sExportsReactInternal].captureMainThreadObject,
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('registers a MainThreadObject type while evaluating a lazy MTS module', () => {
|
|
173
|
+
const originalJS = globalThis.__JS__;
|
|
174
|
+
const originalLepus = globalThis.__LEPUS__;
|
|
175
|
+
const originalMainThread = globalThis.__MAIN_THREAD__;
|
|
176
|
+
const originalBackground = globalThis.__BACKGROUND__;
|
|
177
|
+
const originalWorkletImpl = globalThis.lynxWorkletImpl;
|
|
178
|
+
const registerMainThreadObjectType = vi.fn();
|
|
179
|
+
const create = value => ({ value });
|
|
180
|
+
|
|
181
|
+
globalThis.__JS__ = false;
|
|
182
|
+
globalThis.__LEPUS__ = true;
|
|
183
|
+
globalThis.__MAIN_THREAD__ = true;
|
|
184
|
+
globalThis.__BACKGROUND__ = false;
|
|
185
|
+
globalThis.lynxWorkletImpl = {
|
|
186
|
+
_refImpl: {
|
|
187
|
+
registerMainThreadObjectType,
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
ReactExports.defineMainThreadObjectType({
|
|
193
|
+
type: '@test/lazy-module-evaluation',
|
|
194
|
+
create,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
expect(registerMainThreadObjectType).toHaveBeenCalledWith(
|
|
198
|
+
'@test/lazy-module-evaluation',
|
|
199
|
+
create,
|
|
200
|
+
);
|
|
201
|
+
} finally {
|
|
202
|
+
globalThis.__JS__ = originalJS;
|
|
203
|
+
globalThis.__LEPUS__ = originalLepus;
|
|
204
|
+
globalThis.__MAIN_THREAD__ = originalMainThread;
|
|
205
|
+
globalThis.__BACKGROUND__ = originalBackground;
|
|
206
|
+
globalThis.lynxWorkletImpl = originalWorkletImpl;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
139
210
|
test('target background', async () => {
|
|
140
211
|
vi.resetModules();
|
|
141
212
|
|
|
@@ -161,20 +232,56 @@ describe('Lazy Exports', () => {
|
|
|
161
232
|
expect(target[sRuntimeBackend]).toBe(RUNTIME_BACKEND_SNAPSHOT);
|
|
162
233
|
});
|
|
163
234
|
|
|
235
|
+
test('records a stamped runtime version from the host runtime marker', async () => {
|
|
236
|
+
await withoutRecordedRuntimeVersion(async () => {
|
|
237
|
+
vi.stubGlobal('__RUNTIME_VERSION__', '1.2.0');
|
|
238
|
+
onTestFinished(() => vi.unstubAllGlobals());
|
|
239
|
+
vi.resetModules();
|
|
240
|
+
|
|
241
|
+
await import('../../src/runtime-marker.ts');
|
|
242
|
+
|
|
243
|
+
expect(ReactInternalExports.getRuntimeVersion()).toBe('1.2.0');
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('records a stamped runtime version from the standalone lazy import', async () => {
|
|
248
|
+
await withoutRecordedRuntimeVersion(async () => {
|
|
249
|
+
vi.stubGlobal('__RUNTIME_VERSION__', '1.2.0');
|
|
250
|
+
onTestFinished(() => vi.unstubAllGlobals());
|
|
251
|
+
vi.resetModules();
|
|
252
|
+
|
|
253
|
+
await import('../../lazy/internal.js');
|
|
254
|
+
|
|
255
|
+
expect(ReactInternalExports.getRuntimeVersion()).toBe('1.2.0');
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('allows a standalone lazy import without a stamped runtime version', async () => {
|
|
260
|
+
await withoutRecordedRuntimeVersion(async () => {
|
|
261
|
+
vi.stubGlobal('__RUNTIME_VERSION__', undefined);
|
|
262
|
+
onTestFinished(() => vi.unstubAllGlobals());
|
|
263
|
+
vi.resetModules();
|
|
264
|
+
|
|
265
|
+
await import('../../lazy/internal.js');
|
|
266
|
+
|
|
267
|
+
expect(ReactInternalExports.getRuntimeVersion()).toBeUndefined();
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
164
271
|
test('records a lazy backend when no main template marker exists', async () => {
|
|
165
272
|
await withRuntimeBackend(undefined, () => {
|
|
166
|
-
|
|
273
|
+
registerRuntimeBackend(RUNTIME_BACKEND_SNAPSHOT);
|
|
167
274
|
|
|
168
275
|
expect(target[sRuntimeBackend]).toBe(RUNTIME_BACKEND_SNAPSHOT);
|
|
169
276
|
});
|
|
170
277
|
});
|
|
171
278
|
|
|
172
279
|
test('allows matching lazy backend registration', () => {
|
|
173
|
-
expect(() =>
|
|
280
|
+
expect(() => registerRuntimeBackend(RUNTIME_BACKEND_SNAPSHOT)).not.toThrow();
|
|
174
281
|
});
|
|
175
282
|
|
|
176
283
|
test('throws when a lazy bundle backend does not match the main template backend', () => {
|
|
177
|
-
expect(() =>
|
|
284
|
+
expect(() => registerRuntimeBackend(RUNTIME_BACKEND_ELEMENT_TEMPLATE)).toThrow(
|
|
178
285
|
'Snapshot and Element Template templates cannot share lazy bundles.',
|
|
179
286
|
);
|
|
180
287
|
});
|
|
@@ -192,7 +299,7 @@ describe('Lazy Exports', () => {
|
|
|
192
299
|
await withRuntimeBackend(undefined, async () => {
|
|
193
300
|
vi.resetModules();
|
|
194
301
|
|
|
195
|
-
await import('../../src/element-template/runtime-
|
|
302
|
+
await import('../../src/element-template/runtime-marker.ts');
|
|
196
303
|
expect(target[sRuntimeBackend]).toBe(RUNTIME_BACKEND_ELEMENT_TEMPLATE);
|
|
197
304
|
|
|
198
305
|
await expect(import('../../lazy/import.js')).rejects.toThrow(
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
3
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
4
|
+
// LICENSE file in the root directory of this source tree.
|
|
5
|
+
*/
|
|
6
|
+
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { BasicMT } from './reloadMT';
|
|
9
|
+
import { replaceCommitHook } from '../../../src/snapshot/lifecycle/patch/commit';
|
|
10
|
+
import { injectUpdateMainThread } from '../../../src/snapshot/lifecycle/patch/updateMainThread';
|
|
11
|
+
import { __root } from '../../../src/root';
|
|
12
|
+
import { setupPage } from '../../../src/snapshot';
|
|
13
|
+
import { globalEnvManager } from '../utils/envManager';
|
|
14
|
+
import { elementTree } from '../utils/nativeMethod';
|
|
15
|
+
|
|
16
|
+
beforeAll(() => {
|
|
17
|
+
setupPage(__CreatePage('0', 0));
|
|
18
|
+
|
|
19
|
+
replaceCommitHook();
|
|
20
|
+
injectUpdateMainThread();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
globalEnvManager.resetEnv();
|
|
25
|
+
globalEnvManager.switchToMainThread();
|
|
26
|
+
__root.__jsx = BasicMT;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
delete globalThis.lepusng_gc;
|
|
31
|
+
globalEnvManager.resetEnv();
|
|
32
|
+
elementTree.clear();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('gc after the rendered tree is replaced', () => {
|
|
36
|
+
it('runs after reloadTemplate', () => {
|
|
37
|
+
globalThis.lepusng_gc = vi.fn();
|
|
38
|
+
renderPage({ text: 'Hello' });
|
|
39
|
+
expect(globalThis.lepusng_gc).not.toHaveBeenCalled();
|
|
40
|
+
|
|
41
|
+
updatePage({ text: 'Enjoy' }, { reloadTemplate: true });
|
|
42
|
+
expect(globalThis.lepusng_gc).toHaveBeenCalledTimes(1);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('runs after an update before first-screen sync, not after one that follows it', () => {
|
|
46
|
+
globalThis.__FIRST_SCREEN_SYNC_TIMING__ = 'jsReady';
|
|
47
|
+
try {
|
|
48
|
+
globalThis.lepusng_gc = vi.fn();
|
|
49
|
+
renderPage({ text: 'Hello' });
|
|
50
|
+
|
|
51
|
+
updatePage({ text: 'Enjoy' });
|
|
52
|
+
expect(globalThis.lepusng_gc).toHaveBeenCalledTimes(1);
|
|
53
|
+
|
|
54
|
+
globalThis.rLynxFirstScreenSyncReady();
|
|
55
|
+
updatePage({ text: 'Again' });
|
|
56
|
+
expect(globalThis.lepusng_gc).toHaveBeenCalledTimes(1);
|
|
57
|
+
} finally {
|
|
58
|
+
globalThis.__FIRST_SCREEN_SYNC_TIMING__ = 'immediately';
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('is skipped when the engine does not expose it', () => {
|
|
63
|
+
renderPage({ text: 'Hello' });
|
|
64
|
+
expect(() => updatePage({ text: 'Enjoy' }, { reloadTemplate: true })).not.toThrow();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -521,12 +521,16 @@ describe('snapshotPatchApply for nodesRef ops', () => {
|
|
|
521
521
|
globalEnvManager.switchToMainThread();
|
|
522
522
|
lynx.getJSContext().dispatchEvent.mockClear();
|
|
523
523
|
expect(() =>
|
|
524
|
-
snapshotPatchApply(
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
524
|
+
snapshotPatchApply(
|
|
525
|
+
[
|
|
526
|
+
SnapshotOperation.nodesRefInsertBefore,
|
|
527
|
+
'[react-ref-999-0]',
|
|
528
|
+
99999,
|
|
529
|
+
undefined,
|
|
530
|
+
],
|
|
531
|
+
42,
|
|
532
|
+
false,
|
|
533
|
+
)
|
|
530
534
|
).not.toThrow();
|
|
531
535
|
expect(lynx.getJSContext().dispatchEvent.mock.calls).toMatchInlineSnapshot(`
|
|
532
536
|
[
|
|
@@ -534,6 +538,11 @@ describe('snapshotPatchApply for nodesRef ops', () => {
|
|
|
534
538
|
{
|
|
535
539
|
"data": {
|
|
536
540
|
"id": 99999,
|
|
541
|
+
"options": {
|
|
542
|
+
"commitId": 42,
|
|
543
|
+
"isHydration": false,
|
|
544
|
+
"operation": "nodesRefInsertBefore",
|
|
545
|
+
},
|
|
537
546
|
},
|
|
538
547
|
"type": "Lynx.Error.CtxNotFound",
|
|
539
548
|
},
|
|
@@ -546,11 +555,15 @@ describe('snapshotPatchApply for nodesRef ops', () => {
|
|
|
546
555
|
globalEnvManager.switchToMainThread();
|
|
547
556
|
lynx.getJSContext().dispatchEvent.mockClear();
|
|
548
557
|
expect(() =>
|
|
549
|
-
snapshotPatchApply(
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
558
|
+
snapshotPatchApply(
|
|
559
|
+
[
|
|
560
|
+
SnapshotOperation.nodesRefRemoveChild,
|
|
561
|
+
'[react-ref-999-0]',
|
|
562
|
+
99999,
|
|
563
|
+
],
|
|
564
|
+
43,
|
|
565
|
+
false,
|
|
566
|
+
)
|
|
554
567
|
).not.toThrow();
|
|
555
568
|
expect(lynx.getJSContext().dispatchEvent.mock.calls).toMatchInlineSnapshot(`
|
|
556
569
|
[
|
|
@@ -558,6 +571,11 @@ describe('snapshotPatchApply for nodesRef ops', () => {
|
|
|
558
571
|
{
|
|
559
572
|
"data": {
|
|
560
573
|
"id": 99999,
|
|
574
|
+
"options": {
|
|
575
|
+
"commitId": 43,
|
|
576
|
+
"isHydration": false,
|
|
577
|
+
"operation": "nodesRefRemoveChild",
|
|
578
|
+
},
|
|
561
579
|
},
|
|
562
580
|
"type": "Lynx.Error.CtxNotFound",
|
|
563
581
|
},
|
|
@@ -576,20 +594,28 @@ describe('snapshotPatchApply for nodesRef ops', () => {
|
|
|
576
594
|
it('throws when host selector cannot be resolved on insert', () => {
|
|
577
595
|
globalEnvManager.switchToMainThread();
|
|
578
596
|
const childId = -9999;
|
|
579
|
-
snapshotPatchApply(
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
597
|
+
snapshotPatchApply(
|
|
598
|
+
[
|
|
599
|
+
SnapshotOperation.CreateElement,
|
|
600
|
+
'__snapshot_a94a8_test_1',
|
|
601
|
+
childId,
|
|
602
|
+
],
|
|
603
|
+
42,
|
|
604
|
+
false,
|
|
605
|
+
);
|
|
584
606
|
expect(snapshotInstanceManager.values.has(childId)).toBe(true);
|
|
585
607
|
|
|
586
608
|
expect(() =>
|
|
587
|
-
snapshotPatchApply(
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
609
|
+
snapshotPatchApply(
|
|
610
|
+
[
|
|
611
|
+
SnapshotOperation.nodesRefInsertBefore,
|
|
612
|
+
'[no-such-attr]',
|
|
613
|
+
childId,
|
|
614
|
+
undefined,
|
|
615
|
+
],
|
|
616
|
+
42,
|
|
617
|
+
false,
|
|
618
|
+
)
|
|
593
619
|
).toThrowErrorMatchingInlineSnapshot(
|
|
594
620
|
`[Error: [createPortal] cannot resolve host for selector "[no-such-attr]". The host element does not exist on the main thread — check that the \`NodesRef\` passed to \`createPortal\` points at a currently mounted element.]`,
|
|
595
621
|
);
|
|
@@ -600,21 +626,29 @@ describe('snapshotPatchApply for nodesRef ops', () => {
|
|
|
600
626
|
// Materialize a child with an `__element_root` (the realistic state at
|
|
601
627
|
// remove time — an earlier `nodesRefInsertBefore` op would have set it).
|
|
602
628
|
const childId = -9998;
|
|
603
|
-
snapshotPatchApply(
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
629
|
+
snapshotPatchApply(
|
|
630
|
+
[
|
|
631
|
+
SnapshotOperation.CreateElement,
|
|
632
|
+
'__snapshot_a94a8_test_1',
|
|
633
|
+
childId,
|
|
634
|
+
],
|
|
635
|
+
42,
|
|
636
|
+
false,
|
|
637
|
+
);
|
|
608
638
|
snapshotInstanceManager.values.get(childId).ensureElements();
|
|
609
639
|
|
|
610
640
|
// Remove must not throw even when the host is gone — see the comment
|
|
611
641
|
// on `applyNodesRefRemoveChild`. The portal child SI is still cleaned up.
|
|
612
642
|
expect(() =>
|
|
613
|
-
snapshotPatchApply(
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
643
|
+
snapshotPatchApply(
|
|
644
|
+
[
|
|
645
|
+
SnapshotOperation.nodesRefRemoveChild,
|
|
646
|
+
'[no-such-attr]',
|
|
647
|
+
childId,
|
|
648
|
+
],
|
|
649
|
+
42,
|
|
650
|
+
false,
|
|
651
|
+
)
|
|
618
652
|
).not.toThrow();
|
|
619
653
|
expect(snapshotInstanceManager.values.has(childId)).toBe(false);
|
|
620
654
|
});
|
|
@@ -637,11 +671,15 @@ describe('snapshotPatchApply for nodesRef ops', () => {
|
|
|
637
671
|
expect(listElement.componentAtIndex).not.toBeNull();
|
|
638
672
|
|
|
639
673
|
globalEnvManager.switchToMainThread();
|
|
640
|
-
snapshotPatchApply(
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
674
|
+
snapshotPatchApply(
|
|
675
|
+
[
|
|
676
|
+
SnapshotOperation.nodesRefRemoveChild,
|
|
677
|
+
'[no-such-attr]',
|
|
678
|
+
childId,
|
|
679
|
+
],
|
|
680
|
+
42,
|
|
681
|
+
false,
|
|
682
|
+
);
|
|
645
683
|
// After `snapshotDestroyList`, the cleanup trio replaces the real
|
|
646
684
|
// callbacks: `componentAtIndex` returns `-1`, the others are no-ops.
|
|
647
685
|
expect(listElement.componentAtIndex()).toBe(-1);
|