@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
|
@@ -21,17 +21,12 @@ import {
|
|
|
21
21
|
} from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
|
|
22
22
|
import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
|
|
23
23
|
|
|
24
|
-
vi.mock('../../../../src/element-template/runtime/render/render-
|
|
25
|
-
|
|
24
|
+
vi.mock('../../../../src/element-template/runtime/render/render-direct.js', () => ({
|
|
25
|
+
renderToElementTemplate: vi.fn(),
|
|
26
26
|
registerSlot: vi.fn(),
|
|
27
27
|
}));
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
renderOpcodesIntoElementTemplate: vi.fn(),
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
import { render as mockRender } from '../../../../src/element-template/runtime/render/render-to-opcodes.js';
|
|
34
|
-
import { renderOpcodesIntoElementTemplate as mockRenderOpcodesIntoElementTemplate } from '../../../../src/element-template/runtime/render/render-opcodes.js';
|
|
29
|
+
import { renderToElementTemplate as mockRender } from '../../../../src/element-template/runtime/render/render-direct.js';
|
|
35
30
|
|
|
36
31
|
describe('renderMainThread', () => {
|
|
37
32
|
let dispatchEvent: ReturnType<typeof vi.fn>;
|
|
@@ -39,7 +34,6 @@ describe('renderMainThread', () => {
|
|
|
39
34
|
|
|
40
35
|
beforeEach(() => {
|
|
41
36
|
vi.mocked(mockRender).mockReset();
|
|
42
|
-
vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReset();
|
|
43
37
|
setRoot({ __jsx: { type: 'test-root' } });
|
|
44
38
|
pageRef = { type: 'page', children: [] } as unknown as ElementTemplateHandle;
|
|
45
39
|
setupPage(pageRef);
|
|
@@ -60,7 +54,7 @@ describe('renderMainThread', () => {
|
|
|
60
54
|
destroyAllElementTemplateListStates();
|
|
61
55
|
clearMainThreadDynamicAttrState();
|
|
62
56
|
clearEtAttrPlanMap();
|
|
63
|
-
vi.mocked(
|
|
57
|
+
vi.mocked(mockRender).mockReturnValue({
|
|
64
58
|
pageAttributes: null,
|
|
65
59
|
rootRefs: [],
|
|
66
60
|
rootSubtreeHandles: [],
|
|
@@ -74,7 +68,7 @@ describe('renderMainThread', () => {
|
|
|
74
68
|
clearEtAttrPlanMap();
|
|
75
69
|
});
|
|
76
70
|
|
|
77
|
-
it('
|
|
71
|
+
it('reports a failed component render and commits an empty page', () => {
|
|
78
72
|
const reportErrorSpy = vi.fn();
|
|
79
73
|
const serializedPage = {
|
|
80
74
|
tag: 'page',
|
|
@@ -94,21 +88,17 @@ describe('renderMainThread', () => {
|
|
|
94
88
|
renderMainThread();
|
|
95
89
|
|
|
96
90
|
expect(reportErrorSpy).toHaveBeenCalledWith(expect.objectContaining({ message: 'Render failed' }));
|
|
97
|
-
expect(mockRenderOpcodesIntoElementTemplate).toHaveBeenCalledWith([]);
|
|
98
91
|
expect(__SetAttributeOfElementTemplate).toHaveBeenCalledWith(pageRef, 0, null);
|
|
99
92
|
expect(__InsertNodeToElementTemplate).not.toHaveBeenCalled();
|
|
100
93
|
expect(__SerializeElementTemplate).toHaveBeenCalledWith(pageRef);
|
|
101
94
|
expect(dispatchEvent).toHaveBeenCalledWith({
|
|
102
95
|
type: 'rLynxElementTemplateHydrate',
|
|
103
|
-
data: {
|
|
104
|
-
page: serializedPage,
|
|
105
|
-
reloadVersion: getReloadVersion(),
|
|
106
|
-
},
|
|
96
|
+
data: { page: serializedPage, reloadVersion: getReloadVersion() },
|
|
107
97
|
});
|
|
98
|
+
reportErrorSpy.mockClear();
|
|
108
99
|
});
|
|
109
100
|
|
|
110
|
-
it('
|
|
111
|
-
const opcodes = [0, 'opcode'];
|
|
101
|
+
it('commits completed roots into the current page and dispatches hydrate data', () => {
|
|
112
102
|
const rootRefA = { type: 'ref-a' } as unknown as ElementTemplateHandle;
|
|
113
103
|
const rootRefB = { type: 'ref-b' } as unknown as ElementTemplateHandle;
|
|
114
104
|
const dispatchEvent = vi.fn();
|
|
@@ -130,8 +120,7 @@ describe('renderMainThread', () => {
|
|
|
130
120
|
childSlots: [[serializedA, serializedB]],
|
|
131
121
|
uid: 0,
|
|
132
122
|
};
|
|
133
|
-
vi.mocked(mockRender).mockReturnValue(
|
|
134
|
-
vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
|
|
123
|
+
vi.mocked(mockRender).mockReturnValue({
|
|
135
124
|
pageAttributes: null,
|
|
136
125
|
rootRefs: [rootRefA, rootRefB],
|
|
137
126
|
rootSubtreeHandles: [[], []],
|
|
@@ -146,9 +135,6 @@ describe('renderMainThread', () => {
|
|
|
146
135
|
|
|
147
136
|
expect(() => renderMainThread()).not.toThrow();
|
|
148
137
|
expect(mockRender).toHaveBeenCalledWith({ type: 'test-root' }, undefined);
|
|
149
|
-
expect(mockRenderOpcodesIntoElementTemplate).toHaveBeenCalledWith(
|
|
150
|
-
opcodes,
|
|
151
|
-
);
|
|
152
138
|
expect(__InsertNodeToElementTemplate).toHaveBeenNthCalledWith(
|
|
153
139
|
1,
|
|
154
140
|
pageRef,
|
|
@@ -177,13 +163,17 @@ describe('renderMainThread', () => {
|
|
|
177
163
|
});
|
|
178
164
|
});
|
|
179
165
|
|
|
180
|
-
it('
|
|
181
|
-
vi.mocked(mockRender).
|
|
182
|
-
vi.mocked(mockRenderOpcodesIntoElementTemplate).mockImplementationOnce(() => {
|
|
166
|
+
it('propagates an exception from reportError without committing an empty result', () => {
|
|
167
|
+
vi.mocked(mockRender).mockImplementationOnce(() => {
|
|
183
168
|
throw new Error('Materialization failed');
|
|
184
169
|
});
|
|
185
170
|
|
|
186
|
-
|
|
171
|
+
vi.mocked(lynx.reportError).mockImplementationOnce(() => {
|
|
172
|
+
throw new Error('reportError failed');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
expect(() => renderMainThread()).toThrow('reportError failed');
|
|
176
|
+
expect(lynx.reportError).toHaveBeenCalledWith(expect.objectContaining({ message: 'Materialization failed' }));
|
|
187
177
|
expect(__SetAttributeOfElementTemplate).not.toHaveBeenCalled();
|
|
188
178
|
expect(__InsertNodeToElementTemplate).not.toHaveBeenCalled();
|
|
189
179
|
expect(__SerializeElementTemplate).not.toHaveBeenCalled();
|
|
@@ -191,8 +181,7 @@ describe('renderMainThread', () => {
|
|
|
191
181
|
|
|
192
182
|
it('applies authored page attrs before inserting rendered roots', () => {
|
|
193
183
|
const rootRef = { type: 'root-ref' } as unknown as ElementTemplateHandle;
|
|
194
|
-
vi.mocked(mockRender).mockReturnValue(
|
|
195
|
-
vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
|
|
184
|
+
vi.mocked(mockRender).mockReturnValue({
|
|
196
185
|
pageAttributes: {
|
|
197
186
|
id: 'screen',
|
|
198
187
|
bindtap: '0:0:bindtap',
|
|
@@ -249,8 +238,7 @@ describe('renderMainThread', () => {
|
|
|
249
238
|
}]],
|
|
250
239
|
uid: 0,
|
|
251
240
|
};
|
|
252
|
-
vi.mocked(mockRender).mockReturnValue(
|
|
253
|
-
vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
|
|
241
|
+
vi.mocked(mockRender).mockReturnValue({
|
|
254
242
|
pageAttributes: null,
|
|
255
243
|
rootRefs: [rootRef],
|
|
256
244
|
rootSubtreeHandles: [[]],
|
|
@@ -306,8 +294,7 @@ describe('renderMainThread', () => {
|
|
|
306
294
|
'_et_ref',
|
|
307
295
|
[{ type: 'main-thread-ref', value: ref }],
|
|
308
296
|
);
|
|
309
|
-
vi.mocked(mockRender).mockReturnValue(
|
|
310
|
-
vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
|
|
297
|
+
vi.mocked(mockRender).mockReturnValue({
|
|
311
298
|
pageAttributes: null,
|
|
312
299
|
rootRefs: [rootRef],
|
|
313
300
|
rootSubtreeHandles: [[{ uid: -1, ref: rootRef }]],
|
|
@@ -353,8 +340,7 @@ describe('renderMainThread', () => {
|
|
|
353
340
|
'_et_ref',
|
|
354
341
|
[{ type: 'main-thread-ref', value: ref }],
|
|
355
342
|
);
|
|
356
|
-
vi.mocked(mockRender).mockReturnValue(
|
|
357
|
-
vi.mocked(mockRenderOpcodesIntoElementTemplate).mockReturnValue({
|
|
343
|
+
vi.mocked(mockRender).mockReturnValue({
|
|
358
344
|
pageAttributes: null,
|
|
359
345
|
rootRefs: [rootRef],
|
|
360
346
|
rootSubtreeHandles: [[{ uid: -1, ref: rootRef }]],
|
|
@@ -20,7 +20,8 @@ import {
|
|
|
20
20
|
import { backgroundElementTemplateInstanceManager } from '../../../../src/element-template/background/manager.js';
|
|
21
21
|
import { applyElementTemplateUpdateCommands } from '../../../../src/element-template/runtime/patch.js';
|
|
22
22
|
import { ElementTemplateUpdateOps } from '../../../../src/element-template/protocol/opcodes.js';
|
|
23
|
-
import {
|
|
23
|
+
import { renderToElementTemplate } from '../../../../src/element-template/runtime/render/render-direct.js';
|
|
24
|
+
import { resetElementTemplatePatchListener } from '../../../../src/element-template/native/patch-listener.js';
|
|
24
25
|
import { resetTemplateId } from '../../../../src/element-template/runtime/template/handle.js';
|
|
25
26
|
import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
|
|
26
27
|
import type {
|
|
@@ -28,7 +29,6 @@ import type {
|
|
|
28
29
|
SerializedEtNode,
|
|
29
30
|
SerializedTypedListNode,
|
|
30
31
|
} from '../../../../src/element-template/protocol/types.js';
|
|
31
|
-
import { renderToString } from '../../../../src/element-template/runtime/render/render-to-opcodes.js';
|
|
32
32
|
import { hydrateBackground } from '../../test-utils/debug/hydrate.js';
|
|
33
33
|
import { clearTemplates, registerBuiltinRawTextTemplate, registerTemplates } from '../../test-utils/debug/registry.js';
|
|
34
34
|
import { installMockNativePapi, lastMock } from '../../test-utils/mock/mockNativePapi.js';
|
|
@@ -168,8 +168,7 @@ async function compileAndRender(
|
|
|
168
168
|
};
|
|
169
169
|
|
|
170
170
|
const vnode = { type: module.App, props: {}, key: null, ref: null };
|
|
171
|
-
const
|
|
172
|
-
const { rootRefs } = renderOpcodesIntoElementTemplate(opcodes);
|
|
171
|
+
const { rootRefs } = renderToElementTemplate(vnode);
|
|
173
172
|
|
|
174
173
|
expect(rootRefs).toHaveLength(1);
|
|
175
174
|
|
|
@@ -181,6 +180,7 @@ async function compileAndRender(
|
|
|
181
180
|
code: transformedCode,
|
|
182
181
|
};
|
|
183
182
|
} finally {
|
|
183
|
+
resetElementTemplatePatchListener();
|
|
184
184
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
185
185
|
}
|
|
186
186
|
}
|
|
@@ -422,7 +422,8 @@ describe('render transform contract', () => {
|
|
|
422
422
|
|
|
423
423
|
expect(result.code).toContain('DeferredListItem');
|
|
424
424
|
expect(result.code).toContain('unmountRecycled');
|
|
425
|
-
expect(result.code).toContain('
|
|
425
|
+
expect(result.code).toContain('__etHost');
|
|
426
|
+
expect(result.code).toContain('"item-key": "late"');
|
|
426
427
|
});
|
|
427
428
|
|
|
428
429
|
it('chains create, serialize, update, and callbacks', async () => {
|
|
@@ -4,12 +4,12 @@ import { pathToFileURL } from 'node:url';
|
|
|
4
4
|
|
|
5
5
|
import { vi } from 'vitest';
|
|
6
6
|
|
|
7
|
+
import { resetElementTemplatePatchListener } from '../../../../src/element-template/native/patch-listener.js';
|
|
7
8
|
import { resetElementTemplateHydrationListener } from '../../../../src/element-template/background/hydration-listener.js';
|
|
8
|
-
import { renderOpcodesIntoElementTemplate } from '../../../../src/element-template/runtime/render/render-opcodes.js';
|
|
9
9
|
import { clearEtAttrPlanMap } from '../../../../src/element-template/runtime/template/attr-slot-plan.js';
|
|
10
10
|
import { resetTemplateId } from '../../../../src/element-template/runtime/template/handle.js';
|
|
11
11
|
import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
|
|
12
|
-
import {
|
|
12
|
+
import { renderToElementTemplate } from '../../../../src/element-template/runtime/render/render-direct.js';
|
|
13
13
|
import {
|
|
14
14
|
assertMissingFile,
|
|
15
15
|
assertOrUpdateTextFile,
|
|
@@ -238,8 +238,7 @@ async function runCompiledRenderFixture(options: {
|
|
|
238
238
|
try {
|
|
239
239
|
const module = (await import(`${pathToFileURL(tempImportPath).href}?t=${Date.now()}`)) as { App: unknown };
|
|
240
240
|
const vnode = { type: module.App, props: {}, key: null, ref: null };
|
|
241
|
-
const
|
|
242
|
-
const { rootRefs } = renderOpcodesIntoElementTemplate(opcodes);
|
|
241
|
+
const { rootRefs } = renderToElementTemplate(vnode, null);
|
|
243
242
|
for (const rootRef of rootRefs) {
|
|
244
243
|
__InsertNodeToElementTemplate(root, 0, rootRef, null);
|
|
245
244
|
}
|
|
@@ -267,6 +266,7 @@ async function runCompiledRenderFixture(options: {
|
|
|
267
266
|
expectReportErrorCount(0);
|
|
268
267
|
} finally {
|
|
269
268
|
resetElementTemplateHydrationListener();
|
|
269
|
+
resetElementTemplatePatchListener();
|
|
270
270
|
clearEtAttrPlanMap();
|
|
271
271
|
cleanup();
|
|
272
272
|
globalThis.__USE_ELEMENT_TEMPLATE__ = undefined;
|
|
@@ -5,7 +5,7 @@ import type { Plugin, UserConfigExport } from 'vitest/config';
|
|
|
5
5
|
import { defineConfig } from 'vitest/config';
|
|
6
6
|
|
|
7
7
|
const require = createRequire(import.meta.url);
|
|
8
|
-
const elementTemplateRuntimePkg = require.resolve('../../src/element-template/internal.ts');
|
|
8
|
+
const elementTemplateRuntimePkg = require.resolve('../../src/element-template/internal.ts').split(path.sep).join('/');
|
|
9
9
|
|
|
10
10
|
function transformReactLynxPlugin(): Plugin {
|
|
11
11
|
return {
|
|
@@ -105,6 +105,7 @@ const config: UserConfigExport = defineConfig({
|
|
|
105
105
|
},
|
|
106
106
|
test: {
|
|
107
107
|
name: 'react/runtime-et',
|
|
108
|
+
root: path.resolve(__dirname, '../..'),
|
|
108
109
|
include: ['**/__test__/element-template/**/*.{test,spec}.{js,ts,jsx,tsx}'],
|
|
109
110
|
coverage: {
|
|
110
111
|
include: ['src/element-template/**', 'lazy/element-template*.js'],
|
|
@@ -0,0 +1,271 @@
|
|
|
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, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { globalEnvManager } from './utils/envManager.js';
|
|
7
|
+
import { addCtxNotFoundEventListener, reportCtxNotFound } from '../../src/snapshot/lifecycle/patch/error.js';
|
|
8
|
+
import { SnapshotOperation } from '../../src/snapshot/lifecycle/patch/snapshotPatch.js';
|
|
9
|
+
import { snapshotPatchApply } from '../../src/snapshot/lifecycle/patch/snapshotPatchApply.js';
|
|
10
|
+
import { injectUpdateMainThread } from '../../src/snapshot/lifecycle/patch/updateMainThread.js';
|
|
11
|
+
import { LifecycleConstant } from '../../src/snapshot/lifecycle/constant.js';
|
|
12
|
+
import { getReloadVersion } from '../../src/core/reload-version.js';
|
|
13
|
+
import { createSnapshot, setupPage, snapshotManager } from '../../src/snapshot/snapshot/definition.js';
|
|
14
|
+
import { SnapshotInstance } from '../../src/snapshot/snapshot/snapshot.js';
|
|
15
|
+
import { BackgroundSnapshotInstance } from '../../src/snapshot/snapshot/backgroundSnapshot.js';
|
|
16
|
+
|
|
17
|
+
beforeAll(() => {
|
|
18
|
+
globalEnvManager.resetEnv();
|
|
19
|
+
globalEnvManager.switchToBackground();
|
|
20
|
+
addCtxNotFoundEventListener();
|
|
21
|
+
globalEnvManager.switchToMainThread();
|
|
22
|
+
setupPage(__CreatePage('0', 0));
|
|
23
|
+
injectUpdateMainThread();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
globalEnvManager.resetEnv();
|
|
28
|
+
vi.clearAllMocks();
|
|
29
|
+
vi.spyOn(lynx, 'reportError');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
vi.restoreAllMocks();
|
|
34
|
+
vi.unstubAllGlobals();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function reportedMessage(): string {
|
|
38
|
+
return (vi.mocked(lynx.reportError).mock.calls[0]![0] as Error).message;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe('ctx-not-found diagnostics', () => {
|
|
42
|
+
it.each(['InsertBefore', 'RemoveChild'] as const)(
|
|
43
|
+
'reports parent and child IDs when either node is missing in %s',
|
|
44
|
+
operation => {
|
|
45
|
+
const cases = [
|
|
46
|
+
{ parentExists: false, childExists: true, missingNode: 1 },
|
|
47
|
+
{ parentExists: true, childExists: false, missingNode: 2 },
|
|
48
|
+
{ parentExists: false, childExists: false, missingNode: 3 },
|
|
49
|
+
];
|
|
50
|
+
for (const { parentExists, childExists, missingNode } of cases) {
|
|
51
|
+
globalEnvManager.resetEnv();
|
|
52
|
+
vi.clearAllMocks();
|
|
53
|
+
if (parentExists) {
|
|
54
|
+
new SnapshotInstance('view', 100);
|
|
55
|
+
}
|
|
56
|
+
if (childExists) {
|
|
57
|
+
new SnapshotInstance('view', 101);
|
|
58
|
+
}
|
|
59
|
+
const patch = operation === 'InsertBefore'
|
|
60
|
+
? [SnapshotOperation.InsertBefore, 100, 101, undefined, 0]
|
|
61
|
+
: [SnapshotOperation.RemoveChild, 100, 101];
|
|
62
|
+
snapshotPatchApply(patch, 42, false);
|
|
63
|
+
expect(lynx.getJSContext().dispatchEvent).toHaveBeenCalledExactlyOnceWith({
|
|
64
|
+
type: 'Lynx.Error.CtxNotFound',
|
|
65
|
+
data: {
|
|
66
|
+
id: parentExists ? 101 : 100,
|
|
67
|
+
options: {
|
|
68
|
+
operation,
|
|
69
|
+
commitId: 42,
|
|
70
|
+
isHydration: false,
|
|
71
|
+
parent: 100,
|
|
72
|
+
child: 101,
|
|
73
|
+
missingNode,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
expect(lynx.reportError).toHaveBeenCalledTimes(1);
|
|
78
|
+
expect(reportedMessage()).toBe(
|
|
79
|
+
`snapshotPatchApply failed: ctx not found, snapshot type: 'null', parent: { id: 100, snapshot type: 'null', missing: ${!parentExists} }, child: { id: 101, snapshot type: 'null', missing: ${!childExists} }, operation: '${operation}', commitId: 42, isHydration: false. You can set environment variable \`REACT_ALOG=true\` and restart your dev server for troubleshooting.`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
it.each([undefined, false, true])('reports commit IDs and hydration flag %s', flag => {
|
|
86
|
+
vi.stubGlobal('__ALOG__', false);
|
|
87
|
+
vi.stubGlobal('__DEV__', false);
|
|
88
|
+
const isHydration = flag === true;
|
|
89
|
+
const patchList = [
|
|
90
|
+
{ id: 41, snapshotPatch: [SnapshotOperation.RemoveChild, 100, 101] },
|
|
91
|
+
{ id: 42, snapshotPatch: [SnapshotOperation.SetAttributes, 102, ['attribute-value']] },
|
|
92
|
+
];
|
|
93
|
+
Reflect.get(globalThis, LifecycleConstant.patchUpdate)({
|
|
94
|
+
data: JSON.stringify({ patchList }),
|
|
95
|
+
patchOptions: { reloadVersion: getReloadVersion(), ...(flag === undefined ? {} : { isHydration: flag }) },
|
|
96
|
+
});
|
|
97
|
+
expect(lynx.getJSContext().dispatchEvent).toHaveBeenCalledTimes(2);
|
|
98
|
+
expect(vi.mocked(lynx.getJSContext().dispatchEvent).mock.calls.map(([event]) => event.data)).toEqual([
|
|
99
|
+
{
|
|
100
|
+
id: 100,
|
|
101
|
+
options: {
|
|
102
|
+
operation: 'RemoveChild',
|
|
103
|
+
commitId: 41,
|
|
104
|
+
isHydration,
|
|
105
|
+
parent: 100,
|
|
106
|
+
child: 101,
|
|
107
|
+
missingNode: 3,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{ id: 102, options: { operation: 'SetAttributes', commitId: 42, isHydration } },
|
|
111
|
+
]);
|
|
112
|
+
expect(vi.mocked(lynx.reportError).mock.calls.map(([error]) => (error as Error).message)).toEqual([
|
|
113
|
+
`snapshotPatchApply failed: ctx not found, snapshot type: 'null', parent: { id: 100, snapshot type: 'null', missing: true }, child: { id: 101, snapshot type: 'null', missing: true }, operation: 'RemoveChild', commitId: 41, isHydration: ${isHydration}`,
|
|
114
|
+
`snapshotPatchApply failed: ctx not found, snapshot type: 'null', parent: null, operation: 'SetAttributes', commitId: 42, isHydration: ${isHydration}`,
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it.each(['SetAttribute', 'SetAttributes'] as const)('includes the background parent in %s errors', operation => {
|
|
119
|
+
vi.stubGlobal('__DEV__', false);
|
|
120
|
+
globalEnvManager.switchToBackground();
|
|
121
|
+
const parent = new BackgroundSnapshotInstance('view');
|
|
122
|
+
const child = new BackgroundSnapshotInstance('text');
|
|
123
|
+
parent.appendChild(child);
|
|
124
|
+
globalEnvManager.switchToMainThread();
|
|
125
|
+
const patch = operation === 'SetAttribute'
|
|
126
|
+
? [SnapshotOperation.SetAttribute, child.__id, 0, 'attribute-value']
|
|
127
|
+
: [SnapshotOperation.SetAttributes, child.__id, ['attribute-value']];
|
|
128
|
+
snapshotPatchApply(patch, 42, false);
|
|
129
|
+
expect(lynx.getJSContext().dispatchEvent).toHaveBeenCalledTimes(1);
|
|
130
|
+
expect(reportedMessage()).toBe(
|
|
131
|
+
`snapshotPatchApply failed: ctx not found, snapshot type: 'text', parent: { id: ${parent.__id}, snapshot type: 'view' }, operation: '${operation}', commitId: 42, isHydration: false`,
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('includes both snapshot types in one error even when reporting throws', () => {
|
|
136
|
+
vi.stubGlobal('__DEV__', false);
|
|
137
|
+
globalEnvManager.switchToBackground();
|
|
138
|
+
const parent = new BackgroundSnapshotInstance('view');
|
|
139
|
+
const child = new BackgroundSnapshotInstance('text');
|
|
140
|
+
globalEnvManager.switchToMainThread();
|
|
141
|
+
vi.mocked(lynx.reportError).mockImplementationOnce(error => {
|
|
142
|
+
throw error;
|
|
143
|
+
});
|
|
144
|
+
expect(() => snapshotPatchApply([SnapshotOperation.RemoveChild, parent.__id, child.__id], 42, false))
|
|
145
|
+
.toThrowError(
|
|
146
|
+
`snapshotPatchApply failed: ctx not found, snapshot type: 'view', parent: { id: ${parent.__id}, snapshot type: 'view', missing: true }, child: { id: ${child.__id}, snapshot type: 'text', missing: true }, operation: 'RemoveChild', commitId: 42, isHydration: false`,
|
|
147
|
+
);
|
|
148
|
+
expect(lynx.getJSContext().dispatchEvent).toHaveBeenCalledTimes(1);
|
|
149
|
+
expect(lynx.reportError).toHaveBeenCalledTimes(1);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('uses the explicit parent ID instead of the background parent', () => {
|
|
153
|
+
vi.stubGlobal('__DEV__', false);
|
|
154
|
+
globalEnvManager.switchToBackground();
|
|
155
|
+
const backgroundParent = new BackgroundSnapshotInstance('view');
|
|
156
|
+
const child = new BackgroundSnapshotInstance('text');
|
|
157
|
+
const explicitParent = new BackgroundSnapshotInstance('view');
|
|
158
|
+
backgroundParent.appendChild(child);
|
|
159
|
+
reportCtxNotFound({
|
|
160
|
+
id: child.__id,
|
|
161
|
+
options: {
|
|
162
|
+
operation: 'InsertBefore',
|
|
163
|
+
commitId: 42,
|
|
164
|
+
isHydration: true,
|
|
165
|
+
parent: explicitParent.__id,
|
|
166
|
+
child: child.__id,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
expect(lynx.reportError).toHaveBeenCalledTimes(1);
|
|
170
|
+
expect(reportedMessage()).toBe(
|
|
171
|
+
`snapshotPatchApply failed: ctx not found, snapshot type: 'text', parent: { id: ${explicitParent.__id}, snapshot type: 'view' }, child: { id: ${child.__id}, snapshot type: 'text' }, operation: 'InsertBefore', commitId: 42, isHydration: true`,
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('preserves zero parent and child IDs', () => {
|
|
176
|
+
vi.stubGlobal('__DEV__', false);
|
|
177
|
+
globalEnvManager.switchToBackground();
|
|
178
|
+
const parent = new BackgroundSnapshotInstance('view');
|
|
179
|
+
const child = new BackgroundSnapshotInstance('text');
|
|
180
|
+
parent.appendChild(child);
|
|
181
|
+
reportCtxNotFound({
|
|
182
|
+
id: child.__id,
|
|
183
|
+
options: {
|
|
184
|
+
operation: 'InsertBefore',
|
|
185
|
+
commitId: 42,
|
|
186
|
+
isHydration: false,
|
|
187
|
+
parent: 0,
|
|
188
|
+
child: 0,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
expect(lynx.reportError).toHaveBeenCalledTimes(1);
|
|
192
|
+
expect(reportedMessage()).toBe(
|
|
193
|
+
'snapshotPatchApply failed: ctx not found, snapshot type: \'text\', parent: { id: 0, snapshot type: \'null\' }, child: { id: 0, snapshot type: \'null\' }, operation: \'InsertBefore\', commitId: 42, isHydration: false',
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it.each(['div', null])('preserves null snapshot types for parent and child with type %s', type => {
|
|
198
|
+
vi.stubGlobal('__DEV__', false);
|
|
199
|
+
globalEnvManager.switchToBackground();
|
|
200
|
+
const parent = new BackgroundSnapshotInstance(type as string);
|
|
201
|
+
const child = new BackgroundSnapshotInstance(type as string);
|
|
202
|
+
globalEnvManager.switchToMainThread();
|
|
203
|
+
snapshotPatchApply([SnapshotOperation.RemoveChild, parent.__id, child.__id], 42, false);
|
|
204
|
+
expect(reportedMessage()).toBe(
|
|
205
|
+
`snapshotPatchApply failed: ctx not found, snapshot type: 'null', parent: { id: ${parent.__id}, snapshot type: 'null', missing: true }, child: { id: ${child.__id}, snapshot type: 'null', missing: true }, operation: 'RemoveChild', commitId: 42, isHydration: false`,
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it.each(['removed', 'replaced'] as const)('reports instance types after their definitions are %s', change => {
|
|
210
|
+
vi.stubGlobal('__DEV__', false);
|
|
211
|
+
globalEnvManager.switchToBackground();
|
|
212
|
+
const parent = new BackgroundSnapshotInstance('ctx-not-found-parent');
|
|
213
|
+
const child = new BackgroundSnapshotInstance('ctx-not-found-child');
|
|
214
|
+
parent.appendChild(child);
|
|
215
|
+
for (const instance of [parent, child]) {
|
|
216
|
+
if (change === 'removed') {
|
|
217
|
+
snapshotManager.values.delete(instance.type);
|
|
218
|
+
} else {
|
|
219
|
+
createSnapshot(instance.type, null, null, [], undefined, undefined, null, true);
|
|
220
|
+
}
|
|
221
|
+
expect(snapshotManager.values.get(instance.type)).not.toBe(instance.__snapshot_def);
|
|
222
|
+
}
|
|
223
|
+
globalEnvManager.switchToMainThread();
|
|
224
|
+
snapshotPatchApply([SnapshotOperation.SetAttributes, child.__id, []], 42, false);
|
|
225
|
+
snapshotPatchApply([SnapshotOperation.RemoveChild, parent.__id, child.__id], 43, false);
|
|
226
|
+
expect(lynx.getJSContext().dispatchEvent).toHaveBeenCalledTimes(2);
|
|
227
|
+
expect(vi.mocked(lynx.reportError).mock.calls.map(([error]) => (error as Error).message)).toEqual([
|
|
228
|
+
`snapshotPatchApply failed: ctx not found, snapshot type: 'ctx-not-found-child', parent: { id: ${parent.__id}, snapshot type: 'ctx-not-found-parent' }, operation: 'SetAttributes', commitId: 42, isHydration: false`,
|
|
229
|
+
`snapshotPatchApply failed: ctx not found, snapshot type: 'ctx-not-found-parent', parent: { id: ${parent.__id}, snapshot type: 'ctx-not-found-parent', missing: true }, child: { id: ${child.__id}, snapshot type: 'ctx-not-found-child', missing: true }, operation: 'RemoveChild', commitId: 43, isHydration: false`,
|
|
230
|
+
]);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('includes diagnostics in production without attribute values', () => {
|
|
234
|
+
vi.stubGlobal('__DEV__', false);
|
|
235
|
+
snapshotPatchApply([SnapshotOperation.SetAttributes, 999, ['attribute-value']], 42, false);
|
|
236
|
+
expect(reportedMessage()).toBe(
|
|
237
|
+
'snapshotPatchApply failed: ctx not found, snapshot type: \'null\', parent: null, operation: \'SetAttributes\', commitId: 42, isHydration: false',
|
|
238
|
+
);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it.each(['div', null])('preserves the null snapshot type for %s', type => {
|
|
242
|
+
vi.stubGlobal('__DEV__', false);
|
|
243
|
+
globalEnvManager.switchToBackground();
|
|
244
|
+
const instance = new BackgroundSnapshotInstance(type as string);
|
|
245
|
+
globalEnvManager.switchToMainThread();
|
|
246
|
+
snapshotPatchApply([SnapshotOperation.SetAttributes, instance.__id, []], 42, false);
|
|
247
|
+
expect(reportedMessage()).toBe(
|
|
248
|
+
'snapshotPatchApply failed: ctx not found, snapshot type: \'null\', parent: null, operation: \'SetAttributes\', commitId: 42, isHydration: false',
|
|
249
|
+
);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it.each([false, true])('preserves the fallback error with hydration flag %s', isHydration => {
|
|
253
|
+
vi.stubGlobal('lynx', { ...lynx, getJSContext: undefined });
|
|
254
|
+
expect(() => snapshotPatchApply([SnapshotOperation.SetAttributes, 999, []], 42, isHydration))
|
|
255
|
+
.toThrowError(new Error('snapshotPatchApply failed: ctx not found'));
|
|
256
|
+
expect(() => snapshotPatchApply([SnapshotOperation.RemoveChild, 100, 101], 42, isHydration))
|
|
257
|
+
.toThrowError(new Error('snapshotPatchApply failed: ctx not found'));
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('reports diagnostics and preserves the fallback error when ALOG is unavailable', () => {
|
|
261
|
+
vi.stubGlobal('__DEV__', false);
|
|
262
|
+
vi.stubGlobal('console', { ...console, alog: undefined });
|
|
263
|
+
snapshotPatchApply([SnapshotOperation.SetAttributes, 999, []], 42, false);
|
|
264
|
+
expect(reportedMessage()).toBe(
|
|
265
|
+
'snapshotPatchApply failed: ctx not found, snapshot type: \'null\', parent: null, operation: \'SetAttributes\', commitId: 42, isHydration: false',
|
|
266
|
+
);
|
|
267
|
+
vi.stubGlobal('lynx', { ...lynx, getJSContext: undefined });
|
|
268
|
+
expect(() => snapshotPatchApply([SnapshotOperation.SetAttributes, 999, []], 42, true))
|
|
269
|
+
.toThrowError(new Error('snapshotPatchApply failed: ctx not found'));
|
|
270
|
+
});
|
|
271
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
it.each([false, true])('preact/debug - Snapshot main-thread children with duplicate keys: %s', async (duplicate) => {
|
|
4
|
+
vi.stubGlobal('__MAIN_THREAD__', true)
|
|
5
|
+
.stubGlobal('__LEPUS__', true)
|
|
6
|
+
.stubGlobal('__BACKGROUND__', false);
|
|
7
|
+
await import('preact/debug');
|
|
8
|
+
const { h } = await import('preact');
|
|
9
|
+
const { jsx } = await import('../../../lepus/jsx-runtime/index.js');
|
|
10
|
+
const { default: renderToString } = await import('../../../src/snapshot/renderToOpcodes/index.js');
|
|
11
|
+
const { __root } = await import('../../../src/root.js');
|
|
12
|
+
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
13
|
+
const Child = () => null;
|
|
14
|
+
const children = ['first', duplicate ? 'first' : 'second'].map(key => h(Child, { key }));
|
|
15
|
+
const host = jsx('view', { children });
|
|
16
|
+
try {
|
|
17
|
+
expect(() => renderToString(host, null, __root)).not.toThrow();
|
|
18
|
+
if (duplicate) {
|
|
19
|
+
expect(error).toHaveBeenCalledExactlyOnceWith(expect.stringContaining('same key attribute: "first"'));
|
|
20
|
+
expect(error.mock.calls[0]![0]).toContain('<view');
|
|
21
|
+
} else {
|
|
22
|
+
expect(error).not.toHaveBeenCalled();
|
|
23
|
+
}
|
|
24
|
+
} finally {
|
|
25
|
+
error.mockRestore();
|
|
26
|
+
vi.unstubAllGlobals();
|
|
27
|
+
}
|
|
28
|
+
});
|