@lynx-js/react 0.126.1 → 0.126.2
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 +22 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/refresh/.turbo/turbo-build.log +3 -3
- package/refresh/dist/index.js +1 -2
- package/refresh/package.json +1 -1
- 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/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/suspense-lazy.test.ts +52 -7
- 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/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/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/lazy.test.js +44 -9
- package/runtime/__test__/snapshot/lifecycle/reloadGc.test.jsx +66 -0
- package/runtime/__test__/snapshot/lynx/runtime-version.test.ts +140 -0
- package/runtime/__test__/snapshot/spread.test.jsx +22 -15
- package/runtime/__test__/snapshot/ssr.legacy-slot.test.jsx +168 -0
- package/runtime/__test__/snapshot/ssr.list.test.jsx +211 -0
- package/runtime/__test__/worklet-runtime/hydrate.test.js +92 -0
- package/runtime/__test__/worklet-runtime/runOnBackground.test.js +8 -6
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +3 -2
- package/runtime/lazy/element-template-import.js +0 -4
- package/runtime/lazy/element-template-internal.js +18 -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 +1 -3
- package/runtime/lazy/import.js +0 -4
- package/runtime/lazy/internal.js +15 -1
- package/runtime/lazy/target.js +0 -21
- package/runtime/lib/core/hooks/react.d.ts +2 -0
- package/runtime/lib/core/hooks/react.js +2 -0
- package/runtime/lib/core/hooks/react.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/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 +1 -1
- package/runtime/lib/element-template/index.js +1 -1
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +4 -1
- package/runtime/lib/element-template/internal.js +6 -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/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.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 +3 -1
- package/runtime/lib/internal.js +5 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +15 -6
- package/runtime/lib/lynx-api.js +13 -4
- package/runtime/lib/lynx-api.js.map +1 -1
- 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/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/element.d.ts +2 -0
- package/runtime/lib/snapshot/lynx/element.js +2 -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/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/types.d.ts +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +5 -14
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/src/core/hooks/react.ts +2 -0
- package/runtime/src/core/lynx/runtime-version.ts +62 -0
- 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 +1 -1
- package/runtime/src/element-template/internal.ts +12 -1
- package/runtime/src/element-template/native/index.ts +4 -0
- 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 +10 -1
- package/runtime/src/lynx-api.ts +15 -6
- 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/reload.ts +4 -0
- package/runtime/src/snapshot/lynx/calledByNative.ts +4 -0
- package/runtime/src/snapshot/lynx/element.ts +2 -0
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +2 -1
- package/runtime/src/worklet-runtime/bindings/types.ts +1 -1
- package/runtime/src/worklet-runtime/hydrate.ts +1 -1
- package/runtime/src/worklet-runtime/workletRuntime.ts +5 -14
- package/runtime/types/types.d.ts +2 -0
- package/runtime/worklet-runtime/dev.js +4 -16
- 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 +2 -2
- 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/node_modules/.bin/rsbuild +19 -6
- package/testing-library/node_modules/.bin/rspeedy +17 -4
- package/testing-library/node_modules/.bin/rstest +19 -6
- package/testing-library/package.json +2 -2
- package/testing-library/src/__tests__/reload/reloadGc.test.jsx +64 -0
- package/testing-library/src/__tests__/reload/reloadTemplate.js +39 -0
- package/testing-library/types/entry.d.ts +2 -2
- package/transform/.turbo/turbo-build$colon$wasm.log +68 -56
- package/transform/__test__/fixture.spec.js +17 -20
- 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_plugins_shared/jsx_helpers.rs +8 -4
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +7 -6
- package/transform/node_modules/.bin/esbuild +17 -4
- package/transform/node_modules/.bin/napi +17 -4
- 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 +310 -114
- 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 +10 -208
- 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/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/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 → runtime-marker.d.ts} +0 -0
- /package/runtime/lib/{runtime-backend-marker.d.ts → runtime-marker.d.ts} +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { getRuntimeVersion, registerRuntimeVersion, sRuntimeVersion } from '../../../src/core/lynx/runtime-version.js';
|
|
7
|
+
|
|
8
|
+
function restoreDescriptor(
|
|
9
|
+
target: typeof globalThis & Record<symbol, unknown>,
|
|
10
|
+
symbol: symbol,
|
|
11
|
+
descriptor: PropertyDescriptor | undefined,
|
|
12
|
+
): void {
|
|
13
|
+
if (descriptor) {
|
|
14
|
+
Object.defineProperty(target, symbol, descriptor);
|
|
15
|
+
} else {
|
|
16
|
+
delete target[symbol];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('runtime version marker', () => {
|
|
21
|
+
let originalLynxDescriptor: PropertyDescriptor | undefined;
|
|
22
|
+
let originalGlobalDescriptor: PropertyDescriptor | undefined;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
originalLynxDescriptor = Object.getOwnPropertyDescriptor(lynx, sRuntimeVersion);
|
|
26
|
+
originalGlobalDescriptor = Object.getOwnPropertyDescriptor(globalThis, sRuntimeVersion);
|
|
27
|
+
delete (lynx as typeof lynx & Record<symbol, unknown>)[sRuntimeVersion];
|
|
28
|
+
delete (globalThis as typeof globalThis & Record<symbol, unknown>)[sRuntimeVersion];
|
|
29
|
+
vi.stubGlobal('__LEPUS__', false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
restoreDescriptor(
|
|
34
|
+
lynx as typeof lynx & Record<symbol, unknown>,
|
|
35
|
+
sRuntimeVersion,
|
|
36
|
+
originalLynxDescriptor,
|
|
37
|
+
);
|
|
38
|
+
restoreDescriptor(
|
|
39
|
+
globalThis as typeof globalThis & Record<symbol, unknown>,
|
|
40
|
+
sRuntimeVersion,
|
|
41
|
+
originalGlobalDescriptor,
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('registerRuntimeVersion', () => {
|
|
46
|
+
test('records the runtime version on the background target', () => {
|
|
47
|
+
registerRuntimeVersion('0.126.1');
|
|
48
|
+
|
|
49
|
+
expect((lynx as typeof lynx & Record<symbol, unknown>)[sRuntimeVersion]).toBe(
|
|
50
|
+
'0.126.1',
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('records the runtime version on the main-thread target', () => {
|
|
55
|
+
vi.stubGlobal('__LEPUS__', true);
|
|
56
|
+
|
|
57
|
+
registerRuntimeVersion('0.126.1');
|
|
58
|
+
|
|
59
|
+
expect((globalThis as typeof globalThis & Record<symbol, unknown>)[sRuntimeVersion]).toBe(
|
|
60
|
+
'0.126.1',
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('does nothing when the version is not stamped', () => {
|
|
65
|
+
registerRuntimeVersion(undefined);
|
|
66
|
+
|
|
67
|
+
expect(getRuntimeVersion()).toBeUndefined();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('keeps the host version when a lazy bundle registers later', () => {
|
|
71
|
+
// Host registers first.
|
|
72
|
+
registerRuntimeVersion('1.2.0');
|
|
73
|
+
|
|
74
|
+
// A later lazy bundle must not overwrite the host's recorded version.
|
|
75
|
+
registerRuntimeVersion('2.0.0');
|
|
76
|
+
expect(getRuntimeVersion()).toBe('1.2.0');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('logs the runtime version into Alog on registration', () => {
|
|
80
|
+
const alog = vi.fn();
|
|
81
|
+
vi.stubGlobal('console', { ...console, alog });
|
|
82
|
+
|
|
83
|
+
registerRuntimeVersion('0.126.1');
|
|
84
|
+
|
|
85
|
+
expect(alog).toHaveBeenCalledWith(
|
|
86
|
+
'[ReactLynx] new runtime version: 0.126.1',
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('logs both the recorded and the incoming version for later lazy bundles', () => {
|
|
91
|
+
const alog = vi.fn();
|
|
92
|
+
vi.stubGlobal('console', { ...console, alog });
|
|
93
|
+
|
|
94
|
+
registerRuntimeVersion('1.2.0');
|
|
95
|
+
registerRuntimeVersion('2.0.0');
|
|
96
|
+
|
|
97
|
+
expect(alog).toHaveBeenNthCalledWith(
|
|
98
|
+
1,
|
|
99
|
+
'[ReactLynx] new runtime version: 1.2.0',
|
|
100
|
+
);
|
|
101
|
+
expect(alog).toHaveBeenNthCalledWith(
|
|
102
|
+
2,
|
|
103
|
+
'[ReactLynx] new runtime version: 2.0.0, current version: 1.2.0',
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('does not log when the version is not stamped', () => {
|
|
108
|
+
const alog = vi.fn();
|
|
109
|
+
vi.stubGlobal('console', { ...console, alog });
|
|
110
|
+
|
|
111
|
+
registerRuntimeVersion(undefined);
|
|
112
|
+
|
|
113
|
+
expect(alog).not.toHaveBeenCalled();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('does not log on the main-thread build', () => {
|
|
117
|
+
vi.stubGlobal('__JS__', false);
|
|
118
|
+
const alog = vi.fn();
|
|
119
|
+
vi.stubGlobal('console', { ...console, alog });
|
|
120
|
+
|
|
121
|
+
registerRuntimeVersion('0.126.1');
|
|
122
|
+
|
|
123
|
+
expect(alog).not.toHaveBeenCalled();
|
|
124
|
+
// The version is still recorded so `getRuntimeVersion` keeps working.
|
|
125
|
+
expect(getRuntimeVersion()).toBe('0.126.1');
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('getRuntimeVersion', () => {
|
|
130
|
+
test('returns undefined before any registration', () => {
|
|
131
|
+
expect(getRuntimeVersion()).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('returns the recorded host version', () => {
|
|
135
|
+
registerRuntimeVersion('0.126.1');
|
|
136
|
+
|
|
137
|
+
expect(getRuntimeVersion()).toBe('0.126.1');
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -3,7 +3,7 @@
|
|
|
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 } from 'preact';
|
|
6
|
+
import { options, render } from 'preact';
|
|
7
7
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
8
8
|
|
|
9
9
|
import { useState } from '../../src/index';
|
|
@@ -690,7 +690,7 @@ describe('spreadUpdate', () => {
|
|
|
690
690
|
`);
|
|
691
691
|
});
|
|
692
692
|
|
|
693
|
-
it('circular reference', async () => {
|
|
693
|
+
it.each(['root', 'scheduled'])('circular reference during %s render', async (renderMode) => {
|
|
694
694
|
await import('../../src/lynx');
|
|
695
695
|
let patch;
|
|
696
696
|
let setSpread_;
|
|
@@ -723,19 +723,26 @@ describe('spreadUpdate', () => {
|
|
|
723
723
|
render(<Comp />, scratchBackground);
|
|
724
724
|
|
|
725
725
|
initGlobalSnapshotPatch();
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
726
|
+
const previousDebounce = options.debounceRendering;
|
|
727
|
+
let flushScheduledRender;
|
|
728
|
+
options.debounceRendering = callback => {
|
|
729
|
+
flushScheduledRender = callback;
|
|
730
|
+
};
|
|
731
|
+
try {
|
|
732
|
+
setSpread_(a);
|
|
733
|
+
|
|
734
|
+
expect(() => {
|
|
735
|
+
if (renderMode === 'scheduled') {
|
|
736
|
+
flushScheduledRender();
|
|
737
|
+
} else {
|
|
738
|
+
render(<Comp />, scratchBackground);
|
|
739
|
+
}
|
|
740
|
+
}).toThrowError(/Converting circular structure to JSON[\s\S]*in Bar\n in Comp\n$/);
|
|
741
|
+
patch = takeGlobalSnapshotPatch();
|
|
742
|
+
expect(patch).toEqual([]);
|
|
743
|
+
} finally {
|
|
744
|
+
options.debounceRendering = previousDebounce;
|
|
745
|
+
}
|
|
739
746
|
});
|
|
740
747
|
|
|
741
748
|
it('should remove __self and __source when spreading props onto element', async function() {
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/** @jsxImportSource ../../lepus */
|
|
2
|
+
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import { globalEnvManager } from './utils/envManager';
|
|
6
|
+
import { elementTree, options } from './utils/nativeMethod';
|
|
7
|
+
import { __root } from '../../src/root';
|
|
8
|
+
import { clearPage } from '../../src/snapshot';
|
|
9
|
+
import { gRecycleMap, gSignMap } from '../../src/snapshot/list/list';
|
|
10
|
+
import { DynamicPartType } from '../../src/snapshot/snapshot/dynamicPartType';
|
|
11
|
+
|
|
12
|
+
const ssrIDMap = new Map();
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
globalEnvManager.resetEnv();
|
|
16
|
+
elementTree.clear();
|
|
17
|
+
let ssrID = 0;
|
|
18
|
+
options.onCreateElement = element => {
|
|
19
|
+
element.ssrID = `${ssrID++}`;
|
|
20
|
+
element.toJSON = function() {
|
|
21
|
+
return { ssrID: this.ssrID };
|
|
22
|
+
};
|
|
23
|
+
ssrIDMap.set(element.ssrID, element);
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
delete options.onCreateElement;
|
|
29
|
+
vi.restoreAllMocks();
|
|
30
|
+
vi.unstubAllGlobals();
|
|
31
|
+
clearPage();
|
|
32
|
+
globalEnvManager.resetEnv();
|
|
33
|
+
elementTree.clear();
|
|
34
|
+
ssrIDMap.clear();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Legacy slot codegen keeps the surrounding views and list in one snapshot.
|
|
38
|
+
// The SSR path keeps custom-list-name undefined throughout hydration.
|
|
39
|
+
function WrappedList({ children }) {
|
|
40
|
+
return (
|
|
41
|
+
<view>
|
|
42
|
+
<list id='ssr-list' custom-list-name={undefined} scroll-orientation='horizontal'>
|
|
43
|
+
{children}
|
|
44
|
+
</list>
|
|
45
|
+
</view>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function NestedWrappedList({ children }) {
|
|
50
|
+
return (
|
|
51
|
+
<view>
|
|
52
|
+
<view>
|
|
53
|
+
<list id='ssr-list' custom-list-name={undefined} scroll-orientation='horizontal'>
|
|
54
|
+
{children}
|
|
55
|
+
</list>
|
|
56
|
+
</view>
|
|
57
|
+
</view>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function StoreWithProduct({ shop }) {
|
|
62
|
+
return (
|
|
63
|
+
<view>
|
|
64
|
+
<text>{shop.name}</text>
|
|
65
|
+
</view>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe.each([
|
|
70
|
+
{ List: WrappedList, listElementIndex: 1 },
|
|
71
|
+
{ List: NestedWrappedList, listElementIndex: 2 },
|
|
72
|
+
])('SSR list at element index $listElementIndex', ({ List, listElementIndex }) => {
|
|
73
|
+
it.each([0, 3])('hydrates %i items on the list and preserves the snapshot root', itemCount => {
|
|
74
|
+
const shops = Array.from({ length: itemCount }, (_, index) => ({ id: `${index}`, name: `Shop ${index}` }));
|
|
75
|
+
function App() {
|
|
76
|
+
return (
|
|
77
|
+
<List>
|
|
78
|
+
{shops.map(shop => (
|
|
79
|
+
<list-item key={shop.id} item-key={shop.id}>
|
|
80
|
+
<StoreWithProduct shop={shop} />
|
|
81
|
+
</list-item>
|
|
82
|
+
))}
|
|
83
|
+
</List>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
__root.__jsx = <App />;
|
|
88
|
+
renderPage();
|
|
89
|
+
|
|
90
|
+
const holder = __root.childNodes[0];
|
|
91
|
+
const page = __root.__element_root;
|
|
92
|
+
const view = holder.__element_root;
|
|
93
|
+
const list = elementTree.getElementById('ssr-list');
|
|
94
|
+
// Ensure this fixture exercises the coalesced snapshot from the regression.
|
|
95
|
+
expect(holder.__snapshot_def.slot).toEqual([[DynamicPartType.ListChildren, listElementIndex]]);
|
|
96
|
+
expect(holder.__elements[0]).toBe(view);
|
|
97
|
+
expect(holder.__elements[listElementIndex]).toBe(list);
|
|
98
|
+
expect(list.props['custom-list-name']).toBeUndefined();
|
|
99
|
+
const signs = shops.map((_, index) => elementTree.triggerComponentAtIndex(list, index));
|
|
100
|
+
const itemElements = [...list.children];
|
|
101
|
+
const info = ssrEncode();
|
|
102
|
+
|
|
103
|
+
clearPage();
|
|
104
|
+
globalEnvManager.resetEnv();
|
|
105
|
+
// Native SSR elements survive, but their server-side callbacks do not.
|
|
106
|
+
delete list.componentAtIndex;
|
|
107
|
+
delete list.enqueueComponent;
|
|
108
|
+
delete list.componentAtIndexes;
|
|
109
|
+
vi.stubGlobal('__GetPageElement', () => page);
|
|
110
|
+
vi.stubGlobal('__GetTemplateParts', () => Object.fromEntries(ssrIDMap));
|
|
111
|
+
const updateListCallbacks = vi.spyOn(globalThis, '__UpdateListCallbacks');
|
|
112
|
+
|
|
113
|
+
ssrHydrate(info);
|
|
114
|
+
|
|
115
|
+
const hydratedHolder = __root.childNodes[0];
|
|
116
|
+
expect(hydratedHolder.__element_root).toBe(view);
|
|
117
|
+
expect(hydratedHolder.__elements[listElementIndex]).toBe(list);
|
|
118
|
+
expect(page.children).toEqual([view]);
|
|
119
|
+
expect(list.props['custom-list-name']).toBeUndefined();
|
|
120
|
+
expect(updateListCallbacks).toHaveBeenCalledTimes(1);
|
|
121
|
+
expect(updateListCallbacks).toHaveBeenCalledWith(
|
|
122
|
+
list,
|
|
123
|
+
expect.any(Function),
|
|
124
|
+
expect.any(Function),
|
|
125
|
+
expect.any(Function),
|
|
126
|
+
);
|
|
127
|
+
for (const element of hydratedHolder.__elements.slice(0, listElementIndex)) {
|
|
128
|
+
expect(element.componentAtIndex).toBeUndefined();
|
|
129
|
+
expect(element.enqueueComponent).toBeUndefined();
|
|
130
|
+
expect(element.componentAtIndexes).toBeUndefined();
|
|
131
|
+
expect(gSignMap[__GetElementUniqueID(element)]).toBeUndefined();
|
|
132
|
+
expect(gRecycleMap[__GetElementUniqueID(element)]).toBeUndefined();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const listID = __GetElementUniqueID(list);
|
|
136
|
+
expect(gSignMap[listID].size).toBe(itemCount);
|
|
137
|
+
expect(gRecycleMap[listID]).toBeInstanceOf(Map);
|
|
138
|
+
signs.forEach((sign, index) => {
|
|
139
|
+
const child = hydratedHolder.childNodes[index];
|
|
140
|
+
expect(gSignMap[listID].get(sign)).toBe(child);
|
|
141
|
+
expect(gRecycleMap[listID].get(child.type).get(sign)).toBe(child);
|
|
142
|
+
expect(elementTree.triggerComponentAtIndex(list, index)).toBe(sign);
|
|
143
|
+
expect(child.__element_root).toBe(itemElements[index]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Exercise recycling and the batch callback on the actual native list.
|
|
147
|
+
signs.forEach(sign => elementTree.triggerEnqueueComponent(list, sign));
|
|
148
|
+
const indexes = shops.map((_, index) => index).reverse();
|
|
149
|
+
const operationIDs = indexes.map(index => 100 + index);
|
|
150
|
+
const flushElementTree = vi.spyOn(globalThis, '__FlushElementTree');
|
|
151
|
+
elementTree.triggerComponentAtIndexes(list, indexes, operationIDs, false, false);
|
|
152
|
+
expect(flushElementTree).toHaveBeenLastCalledWith(list, {
|
|
153
|
+
triggerLayout: true,
|
|
154
|
+
operationIDs,
|
|
155
|
+
elementIDs: indexes.map(index => signs[index]),
|
|
156
|
+
listID,
|
|
157
|
+
});
|
|
158
|
+
expect(list.children).toEqual(itemElements);
|
|
159
|
+
|
|
160
|
+
// Subsequent page updates must remove the outer view, not the inner list.
|
|
161
|
+
const removeElement = vi.spyOn(globalThis, '__RemoveElement');
|
|
162
|
+
__root.__jsx = null;
|
|
163
|
+
updatePage({});
|
|
164
|
+
expect(removeElement).toHaveBeenCalledTimes(1);
|
|
165
|
+
expect(removeElement).toHaveBeenCalledWith(page, view);
|
|
166
|
+
expect(page.children).toEqual([]);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/** @jsxImportSource ../../lepus */
|
|
2
|
+
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import { globalEnvManager } from './utils/envManager';
|
|
6
|
+
import { elementTree, options } from './utils/nativeMethod';
|
|
7
|
+
import { __root } from '../../src/root';
|
|
8
|
+
import { clearPage } from '../../src/snapshot';
|
|
9
|
+
import { gRecycleMap, gSignMap } from '../../src/snapshot/list/list';
|
|
10
|
+
import { DynamicPartType } from '../../src/snapshot/snapshot/dynamicPartType';
|
|
11
|
+
|
|
12
|
+
const ssrIDMap = new Map();
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
globalEnvManager.resetEnv();
|
|
16
|
+
elementTree.clear();
|
|
17
|
+
let ssrID = 0;
|
|
18
|
+
options.onCreateElement = element => {
|
|
19
|
+
element.ssrID = `${ssrID++}`;
|
|
20
|
+
element.toJSON = function() {
|
|
21
|
+
return { ssrID: this.ssrID };
|
|
22
|
+
};
|
|
23
|
+
ssrIDMap.set(element.ssrID, element);
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
delete options.onCreateElement;
|
|
29
|
+
vi.restoreAllMocks();
|
|
30
|
+
vi.unstubAllGlobals();
|
|
31
|
+
clearPage();
|
|
32
|
+
globalEnvManager.resetEnv();
|
|
33
|
+
elementTree.clear();
|
|
34
|
+
ssrIDMap.clear();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function findSnapshot(element, snapshot = __root) {
|
|
38
|
+
if (snapshot.__element_root === element) return snapshot;
|
|
39
|
+
for (const child of snapshot.childNodes) {
|
|
40
|
+
const found = findSnapshot(element, child);
|
|
41
|
+
if (found) return found;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function restoreSSR() {
|
|
46
|
+
const page = __root.__element_root;
|
|
47
|
+
const info = ssrEncode();
|
|
48
|
+
clearPage();
|
|
49
|
+
globalEnvManager.resetEnv();
|
|
50
|
+
for (const element of ssrIDMap.values()) {
|
|
51
|
+
if (element.type === 'list') {
|
|
52
|
+
delete element.componentAtIndex;
|
|
53
|
+
delete element.enqueueComponent;
|
|
54
|
+
delete element.componentAtIndexes;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
vi.stubGlobal('__GetPageElement', () => page);
|
|
58
|
+
vi.stubGlobal('__GetTemplateParts', () => Object.fromEntries(ssrIDMap));
|
|
59
|
+
ssrHydrate(info);
|
|
60
|
+
return page;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function StoreWithProduct({ shop }) {
|
|
64
|
+
return (
|
|
65
|
+
<view>
|
|
66
|
+
<text>{shop.name}</text>
|
|
67
|
+
</view>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function ShopList({ shops }) {
|
|
72
|
+
return (
|
|
73
|
+
<list id='ssr-list' custom-list-name={undefined} scroll-orientation='horizontal'>
|
|
74
|
+
{shops.map(shop => (
|
|
75
|
+
<list-item key={shop.id} item-key={shop.id}>
|
|
76
|
+
<StoreWithProduct shop={shop} />
|
|
77
|
+
</list-item>
|
|
78
|
+
))}
|
|
79
|
+
</list>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Compile the nested list inline so separation is performed by the default
|
|
84
|
+
// list transform, rather than by a user-authored component boundary.
|
|
85
|
+
function WrappedList({ shops, nested }) {
|
|
86
|
+
const items = shops.map(shop => (
|
|
87
|
+
<list-item key={shop.id} item-key={shop.id}>
|
|
88
|
+
<StoreWithProduct shop={shop} />
|
|
89
|
+
</list-item>
|
|
90
|
+
));
|
|
91
|
+
return nested
|
|
92
|
+
? (
|
|
93
|
+
<view>
|
|
94
|
+
<view>
|
|
95
|
+
<list id='ssr-list' custom-list-name={undefined}>{items}</list>
|
|
96
|
+
</view>
|
|
97
|
+
</view>
|
|
98
|
+
)
|
|
99
|
+
: (
|
|
100
|
+
<view>
|
|
101
|
+
<list id='ssr-list' custom-list-name={undefined}>{items}</list>
|
|
102
|
+
</view>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function createShops(count) {
|
|
107
|
+
return Array.from({ length: count }, (_, index) => ({ id: `${index}`, name: `Shop ${index}` }));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
describe.each([false, true])('SSR default list slots, nested=%s', nested => {
|
|
111
|
+
it.each([0, 3])('restores callbacks and reuses %i items', count => {
|
|
112
|
+
__root.__jsx = <WrappedList shops={createShops(count)} nested={nested} />;
|
|
113
|
+
renderPage();
|
|
114
|
+
const view = __root.childNodes[0].__element_root;
|
|
115
|
+
const list = elementTree.getElementById('ssr-list');
|
|
116
|
+
expect(findSnapshot(list).__snapshot_def.slot).toEqual([[DynamicPartType.ListSlotV2, 0]]);
|
|
117
|
+
const signs = Array.from({ length: count }, (_, index) => elementTree.triggerComponentAtIndex(list, index));
|
|
118
|
+
const items = [...list.children];
|
|
119
|
+
const updateListCallbacks = vi.spyOn(globalThis, '__UpdateListCallbacks');
|
|
120
|
+
const page = restoreSSR();
|
|
121
|
+
|
|
122
|
+
expect(__root.childNodes[0].__element_root).toBe(view);
|
|
123
|
+
expect(findSnapshot(list).__elements).toEqual([list]);
|
|
124
|
+
expect(updateListCallbacks).toHaveBeenCalledTimes(1);
|
|
125
|
+
expect(updateListCallbacks).toHaveBeenCalledWith(
|
|
126
|
+
list,
|
|
127
|
+
expect.any(Function),
|
|
128
|
+
expect.any(Function),
|
|
129
|
+
expect.any(Function),
|
|
130
|
+
);
|
|
131
|
+
expect(view.componentAtIndex).toBeUndefined();
|
|
132
|
+
expect(gSignMap[__GetElementUniqueID(view)]).toBeUndefined();
|
|
133
|
+
expect(gRecycleMap[__GetElementUniqueID(view)]).toBeUndefined();
|
|
134
|
+
const listID = __GetElementUniqueID(list);
|
|
135
|
+
expect(gSignMap[listID].size).toBe(count);
|
|
136
|
+
expect(gRecycleMap[listID]).toBeInstanceOf(Map);
|
|
137
|
+
signs.forEach((sign, index) => {
|
|
138
|
+
const child = findSnapshot(list).childNodes[index];
|
|
139
|
+
expect(gSignMap[listID].get(sign)).toBe(child);
|
|
140
|
+
expect(gRecycleMap[listID].get(child.type).get(sign)).toBe(child);
|
|
141
|
+
expect(elementTree.triggerComponentAtIndex(list, index)).toBe(sign);
|
|
142
|
+
expect(child.__element_root).toBe(items[index]);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
signs.forEach(sign => elementTree.triggerEnqueueComponent(list, sign));
|
|
146
|
+
const indexes = signs.map((_, index) => index).reverse();
|
|
147
|
+
const operationIDs = indexes.map(index => 100 + index);
|
|
148
|
+
const flush = vi.spyOn(globalThis, '__FlushElementTree');
|
|
149
|
+
elementTree.triggerComponentAtIndexes(list, indexes, operationIDs, false, false);
|
|
150
|
+
expect(flush).toHaveBeenLastCalledWith(list, {
|
|
151
|
+
triggerLayout: true,
|
|
152
|
+
operationIDs,
|
|
153
|
+
elementIDs: indexes.map(index => signs[index]),
|
|
154
|
+
listID,
|
|
155
|
+
});
|
|
156
|
+
expect(list.children).toEqual(items);
|
|
157
|
+
|
|
158
|
+
const remove = vi.spyOn(globalThis, '__RemoveElement');
|
|
159
|
+
__root.__jsx = null;
|
|
160
|
+
updatePage({});
|
|
161
|
+
expect(remove).toHaveBeenCalledTimes(1);
|
|
162
|
+
expect(remove).toHaveBeenCalledWith(page, view);
|
|
163
|
+
expect(page.children).toEqual([]);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('preserves sibling slot indexes when updating a hydrated list', () => {
|
|
168
|
+
function App({ shops, header }) {
|
|
169
|
+
return (
|
|
170
|
+
<view id='catalog'>
|
|
171
|
+
{header && <text id='header'>{header}</text>}
|
|
172
|
+
<text id='separator'>Products</text>
|
|
173
|
+
<ShopList shops={shops} />
|
|
174
|
+
<text id='footer'>Footer</text>
|
|
175
|
+
</view>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
const shops = createShops(3);
|
|
179
|
+
__root.__jsx = <App shops={shops} />;
|
|
180
|
+
renderPage();
|
|
181
|
+
const list = elementTree.getElementById('ssr-list');
|
|
182
|
+
const catalog = elementTree.getElementById('catalog');
|
|
183
|
+
const slotContainers = [...catalog.children];
|
|
184
|
+
const footer = elementTree.getElementById('footer');
|
|
185
|
+
const signs = shops.map((_, index) => elementTree.triggerComponentAtIndex(list, index));
|
|
186
|
+
const listSlotIndex = findSnapshot(list).__slotIndex;
|
|
187
|
+
expect(listSlotIndex).toBeGreaterThan(0);
|
|
188
|
+
restoreSSR();
|
|
189
|
+
expect(findSnapshot(list).__slotIndex).toBe(listSlotIndex);
|
|
190
|
+
|
|
191
|
+
__root.__jsx = (
|
|
192
|
+
<App shops={[{ ...shops[2], name: 'Updated shop' }, shops[0], { id: 'new', name: 'New shop' }]} header='Header' />
|
|
193
|
+
);
|
|
194
|
+
updatePage({});
|
|
195
|
+
expect(elementTree.getElementById('ssr-list')).toBe(list);
|
|
196
|
+
expect(elementTree.getElementById('footer')).toBe(footer);
|
|
197
|
+
expect(catalog.children).toEqual(slotContainers);
|
|
198
|
+
expect(slotContainers[0].children).toEqual([elementTree.getElementById('header')]);
|
|
199
|
+
expect(slotContainers[2].children).toEqual([list]);
|
|
200
|
+
expect(findSnapshot(list).childNodes.map(child => child.__listItemPlatformInfo['item-key'])).toEqual([
|
|
201
|
+
'2',
|
|
202
|
+
'0',
|
|
203
|
+
'new',
|
|
204
|
+
]);
|
|
205
|
+
expect(elementTree.triggerComponentAtIndex(list, 0)).toBe(signs[2]);
|
|
206
|
+
expect(elementTree.triggerComponentAtIndex(list, 1)).toBe(signs[0]);
|
|
207
|
+
expect(elementTree.triggerComponentAtIndex(list, 2)).toBe(signs[1]);
|
|
208
|
+
expect(list.children.some(item => item.children[0]?.children[0]?.children[0]?.props.text === 'Updated shop')).toBe(
|
|
209
|
+
true,
|
|
210
|
+
);
|
|
211
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
|
|
6
|
+
import { onHydrationFinished, onWorkletCtxUpdate } from '../../src/worklet-runtime/bindings/observers';
|
|
7
|
+
import { updateWorkletRefInitValueChanges } from '../../src/worklet-runtime/workletRef';
|
|
8
|
+
import { initWorklet } from '../../src/worklet-runtime/workletRuntime';
|
|
9
|
+
|
|
10
|
+
function nestContext(ctx, depth) {
|
|
11
|
+
for (let i = 1; i <= depth; i++) {
|
|
12
|
+
ctx = { _wkltId: `parent-${i}`, _c: { child: ctx } };
|
|
13
|
+
}
|
|
14
|
+
return ctx;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
globalThis.SystemInfo = { lynxSdkVersion: '2.16' };
|
|
19
|
+
initWorklet();
|
|
20
|
+
for (let i = 1; i <= 2; i++) {
|
|
21
|
+
globalThis.registerWorklet('main-thread', `parent-${i}`, function(...args) {
|
|
22
|
+
return this._c.child(...args);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
// Model collection of weak targets deterministically. Hydration must work
|
|
26
|
+
// through the live function even when no weak reference can recover its original context.
|
|
27
|
+
vi.spyOn(globalThis, 'WeakRef').mockImplementation(function() {
|
|
28
|
+
return { deref: () => undefined };
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
vi.restoreAllMocks();
|
|
34
|
+
delete globalThis.lynxWorkletImpl;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe.each([0, 1, 2])('hydration at nesting depth %i', (depth) => {
|
|
38
|
+
it('preserves first-screen ref identity and writes across event contexts', () => {
|
|
39
|
+
globalThis.registerWorklet('main-thread', 'write', function(width) {
|
|
40
|
+
this._c.ref.current.width = width;
|
|
41
|
+
return this._c.ref;
|
|
42
|
+
});
|
|
43
|
+
globalThis.registerWorklet('main-thread', 'read', function() {
|
|
44
|
+
return this._c.ref;
|
|
45
|
+
});
|
|
46
|
+
const firstScreen = nestContext({
|
|
47
|
+
_wkltId: 'write',
|
|
48
|
+
_c: { ref: { _wvid: -1, _initValue: { width: 0 } } },
|
|
49
|
+
}, depth);
|
|
50
|
+
const firstScreenRef = globalThis.runWorklet(firstScreen, [240]);
|
|
51
|
+
const background = nestContext({
|
|
52
|
+
_wkltId: 'write',
|
|
53
|
+
_c: { ref: { _wvid: 1 } },
|
|
54
|
+
}, depth);
|
|
55
|
+
background._execId = 8;
|
|
56
|
+
updateWorkletRefInitValueChanges([[1, { width: 0 }]]);
|
|
57
|
+
|
|
58
|
+
onWorkletCtxUpdate(background, firstScreen, true, {});
|
|
59
|
+
onHydrationFinished();
|
|
60
|
+
|
|
61
|
+
const reader = { _wkltId: 'read', _c: { ref: { _wvid: 1 } } };
|
|
62
|
+
const hydratedRef = globalThis.runWorklet(reader, []);
|
|
63
|
+
expect(hydratedRef).toBe(firstScreenRef);
|
|
64
|
+
expect(hydratedRef.current.width).toBe(240);
|
|
65
|
+
globalThis.runWorklet(background, [480]);
|
|
66
|
+
expect(globalThis.runWorklet(reader, []).current.width).toBe(480);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('runs first-screen delayed background calls after hydration', () => {
|
|
70
|
+
const task = vi.fn();
|
|
71
|
+
globalThis.registerWorklet('main-thread', 'call', function() {
|
|
72
|
+
globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayRunOnBackground(this._jsFn.callback, task);
|
|
73
|
+
});
|
|
74
|
+
const firstScreen = nestContext({
|
|
75
|
+
_wkltId: 'call',
|
|
76
|
+
_jsFn: { callback: { _isFirstScreen: true } },
|
|
77
|
+
}, depth);
|
|
78
|
+
globalThis.runWorklet(firstScreen, []);
|
|
79
|
+
expect(task).not.toHaveBeenCalled();
|
|
80
|
+
const background = nestContext({
|
|
81
|
+
_wkltId: 'call',
|
|
82
|
+
_jsFn: { callback: { _jsFnId: 3 } },
|
|
83
|
+
}, depth);
|
|
84
|
+
background._execId = 8;
|
|
85
|
+
|
|
86
|
+
onWorkletCtxUpdate(background, firstScreen, true, {});
|
|
87
|
+
onHydrationFinished();
|
|
88
|
+
|
|
89
|
+
expect(task).toHaveBeenCalledExactlyOnceWith(3, 8);
|
|
90
|
+
expect(globalThis.lynxWorkletImpl._runOnBackgroundDelayImpl.delayedBackgroundFunctionArray).toHaveLength(0);
|
|
91
|
+
});
|
|
92
|
+
});
|