@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
|
@@ -212,13 +212,13 @@ describe('hydrate', () => {
|
|
|
212
212
|
expect(stream).toEqual([]);
|
|
213
213
|
});
|
|
214
214
|
|
|
215
|
-
it('forces MTRef hydrate clears when native serialization
|
|
215
|
+
it.each([null, undefined])('forces MTRef hydrate clears when native serialization contains %s', (before) => {
|
|
216
216
|
__etAttrPlanMap.root = [0, adaptMTRefAttrSlot];
|
|
217
217
|
const root = new BackgroundElementTemplateInstance('root', [null]);
|
|
218
218
|
|
|
219
219
|
const stream = hydrate(
|
|
220
220
|
createHydrationTemplate(root.instanceId, 'root', {
|
|
221
|
-
attributeSlots: [
|
|
221
|
+
attributeSlots: [before],
|
|
222
222
|
}),
|
|
223
223
|
root,
|
|
224
224
|
);
|
|
@@ -1206,41 +1206,51 @@ describe('hydrate', () => {
|
|
|
1206
1206
|
(globalThis as { __LYNX_REPORT_ERROR_CALLS?: Error[] }).__LYNX_REPORT_ERROR_CALLS = [];
|
|
1207
1207
|
});
|
|
1208
1208
|
|
|
1209
|
-
it('
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1209
|
+
it.each(['matching', 'reordered'])(
|
|
1210
|
+
'drops the hydrate stream when a matched child fails with %s siblings',
|
|
1211
|
+
(order) => {
|
|
1212
|
+
const oldReportError = lynx.reportError;
|
|
1213
|
+
const reportError = vi.fn();
|
|
1214
|
+
lynx.reportError = reportError;
|
|
1215
|
+
|
|
1216
|
+
try {
|
|
1217
|
+
const root = new BackgroundElementTemplateInstance('root', ['after-root']);
|
|
1218
|
+
const child = new BackgroundElementTemplateInstance('child');
|
|
1219
|
+
const sibling = new BackgroundElementTemplateInstance('sibling');
|
|
1220
|
+
root.appendChild(child);
|
|
1221
|
+
root.appendChild(sibling);
|
|
1222
|
+
const serializedChildren = [
|
|
1223
|
+
createHydrationChild(-1, 'child'),
|
|
1224
|
+
createHydrationChild(-10, 'sibling'),
|
|
1225
|
+
];
|
|
1226
|
+
if (order === 'reordered') {
|
|
1227
|
+
serializedChildren.reverse();
|
|
1228
|
+
}
|
|
1229
|
+
const oldRootId = root.instanceId;
|
|
1230
|
+
const oldChildId = child.instanceId;
|
|
1231
|
+
|
|
1232
|
+
const stream = hydrate(
|
|
1233
|
+
createHydrationTemplate(-1, 'root', {
|
|
1234
|
+
attributeSlots: ['before-root'],
|
|
1235
|
+
childSlots: [serializedChildren],
|
|
1236
|
+
}),
|
|
1237
|
+
root,
|
|
1238
|
+
);
|
|
1239
|
+
|
|
1240
|
+
expect(stream).toEqual([]);
|
|
1241
|
+
expect(reportError).toHaveBeenCalledTimes(1);
|
|
1242
|
+
expect(String(reportError.mock.calls[0]?.[0]?.message ?? '')).toContain(
|
|
1243
|
+
'invalid uid -1 for \'child\'',
|
|
1244
|
+
);
|
|
1245
|
+
expect(backgroundElementTemplateInstanceManager.get(oldRootId)).toBeUndefined();
|
|
1246
|
+
expect(backgroundElementTemplateInstanceManager.get(-1)).toBe(root);
|
|
1247
|
+
expect(backgroundElementTemplateInstanceManager.get(oldChildId)).toBe(child);
|
|
1248
|
+
} finally {
|
|
1249
|
+
lynx.reportError = oldReportError;
|
|
1250
|
+
(globalThis as { __LYNX_REPORT_ERROR_CALLS?: Error[] }).__LYNX_REPORT_ERROR_CALLS = [];
|
|
1251
|
+
}
|
|
1252
|
+
},
|
|
1253
|
+
);
|
|
1244
1254
|
|
|
1245
1255
|
it('treats missing serialized slot arrays as empty', () => {
|
|
1246
1256
|
const root = new BackgroundElementTemplateInstance('root');
|
|
@@ -1299,18 +1309,52 @@ describe('hydrate', () => {
|
|
|
1299
1309
|
expect(stream).toEqual([]);
|
|
1300
1310
|
});
|
|
1301
1311
|
|
|
1302
|
-
it(
|
|
1303
|
-
|
|
1312
|
+
it.each([
|
|
1313
|
+
{ before: [null], after: [] },
|
|
1314
|
+
{ before: [], after: [null] },
|
|
1315
|
+
{ before: [undefined], after: [undefined] },
|
|
1316
|
+
{ before: [undefined], after: [null] },
|
|
1317
|
+
{ before: [null], after: [undefined] },
|
|
1318
|
+
])('does not patch absent hydration slots: $before -> $after', ({ before, after }) => {
|
|
1319
|
+
const root = new BackgroundElementTemplateInstance('root', after);
|
|
1320
|
+
const stream = hydrate(
|
|
1321
|
+
createHydrationTemplate(root.instanceId, 'root', { attributeSlots: before }),
|
|
1322
|
+
root,
|
|
1323
|
+
);
|
|
1324
|
+
expect(stream).toEqual([]);
|
|
1325
|
+
expect(root.attributeSlots).toEqual(after.map(value => value ?? null));
|
|
1326
|
+
});
|
|
1304
1327
|
|
|
1328
|
+
it('preserves real changes and removals around absent hydration slots', () => {
|
|
1329
|
+
const root = new BackgroundElementTemplateInstance('root', [undefined, 0, false, '', '1']);
|
|
1305
1330
|
const stream = hydrate(
|
|
1306
1331
|
createHydrationTemplate(root.instanceId, 'root', {
|
|
1307
|
-
attributeSlots: [null],
|
|
1332
|
+
attributeSlots: ['remove', undefined, null, undefined, 1],
|
|
1308
1333
|
}),
|
|
1309
1334
|
root,
|
|
1310
1335
|
);
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1336
|
+
expect(stream).toEqual([
|
|
1337
|
+
ElementTemplateUpdateOps.setAttribute,
|
|
1338
|
+
root.instanceId,
|
|
1339
|
+
0,
|
|
1340
|
+
null,
|
|
1341
|
+
ElementTemplateUpdateOps.setAttribute,
|
|
1342
|
+
root.instanceId,
|
|
1343
|
+
1,
|
|
1344
|
+
0,
|
|
1345
|
+
ElementTemplateUpdateOps.setAttribute,
|
|
1346
|
+
root.instanceId,
|
|
1347
|
+
2,
|
|
1348
|
+
false,
|
|
1349
|
+
ElementTemplateUpdateOps.setAttribute,
|
|
1350
|
+
root.instanceId,
|
|
1351
|
+
3,
|
|
1352
|
+
'',
|
|
1353
|
+
ElementTemplateUpdateOps.setAttribute,
|
|
1354
|
+
root.instanceId,
|
|
1355
|
+
4,
|
|
1356
|
+
'1',
|
|
1357
|
+
]);
|
|
1314
1358
|
});
|
|
1315
1359
|
|
|
1316
1360
|
it('skips sparse background slot indexes when checking trailing slots', () => {
|
|
@@ -203,6 +203,20 @@ describe('BackgroundElementTemplateInstance', () => {
|
|
|
203
203
|
expect(doc.createElement('_et_item')).not.toBeInstanceOf(BackgroundTypedElementTemplateInstance);
|
|
204
204
|
});
|
|
205
205
|
|
|
206
|
+
it.each([0, 1500, -3.5, '1500', ''])('hydrates document text %j without rewriting unchanged content', (value) => {
|
|
207
|
+
const doc = setupBackgroundElementTemplateDocument();
|
|
208
|
+
const text = doc.createTextNode(value);
|
|
209
|
+
const serialized = { templateKey: BUILTIN_RAW_TEXT_TEMPLATE_KEY, uid: -10, attributeSlots: [String(value)] };
|
|
210
|
+
expect(hydrateBackground(serialized, text)).toEqual([]);
|
|
211
|
+
expect(text.attributeSlots).toEqual([String(value)]);
|
|
212
|
+
markElementTemplateHydrated();
|
|
213
|
+
globalCommitContext.ops = [];
|
|
214
|
+
text.data = String(value);
|
|
215
|
+
expect(globalCommitContext.ops).toEqual([]);
|
|
216
|
+
text.data = 'changed';
|
|
217
|
+
expect(globalCommitContext.ops).toEqual([ElementTemplateUpdateOps.setAttribute, -10, 0, 'changed']);
|
|
218
|
+
});
|
|
219
|
+
|
|
206
220
|
it('emits exact list create as typed holder with logical children in command options', () => {
|
|
207
221
|
const list = new BackgroundListElementTemplateInstance();
|
|
208
222
|
const item = new BackgroundElementTemplateInstance('_et_list_item');
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import 'preact/debug';
|
|
2
|
+
import { expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { __etHost } from '../../../../src/element-template/runtime/render/host.js';
|
|
5
|
+
import { renderToElementTemplate } from '../../../../src/element-template/runtime/render/render-direct.js';
|
|
6
|
+
import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
|
|
7
|
+
import { registerTemplates } from '../../test-utils/debug/registry.js';
|
|
8
|
+
|
|
9
|
+
it.each(
|
|
10
|
+
[
|
|
11
|
+
[undefined, false],
|
|
12
|
+
[undefined, true],
|
|
13
|
+
[true, false],
|
|
14
|
+
[true, true],
|
|
15
|
+
] as const,
|
|
16
|
+
)('preact/debug - plain=%s children with duplicate keys: %s', (plain, duplicate) => {
|
|
17
|
+
globalThis.__MAIN_THREAD__ = true;
|
|
18
|
+
globalThis.__BACKGROUND__ = false;
|
|
19
|
+
elementTemplateRegistry.clear();
|
|
20
|
+
registerTemplates([
|
|
21
|
+
{
|
|
22
|
+
templateId: '_et_debug_root',
|
|
23
|
+
compiledTemplate: {
|
|
24
|
+
kind: 'element',
|
|
25
|
+
type: 'view',
|
|
26
|
+
children: [{ kind: 'childSlot', type: 'slot', elementSlotIndex: 0 }],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{ templateId: '_et_debug_leaf', compiledTemplate: { kind: 'element', type: 'view' } },
|
|
30
|
+
]);
|
|
31
|
+
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
32
|
+
const children = ['first', duplicate ? 'first' : 'second'].map(key =>
|
|
33
|
+
__etHost('_et_debug_leaf', '_et_debug_leaf', '__Card__', key, undefined, undefined, undefined, plain)
|
|
34
|
+
);
|
|
35
|
+
const host = __etHost(
|
|
36
|
+
'_et_debug_root',
|
|
37
|
+
'_et_debug_root',
|
|
38
|
+
'__Card__',
|
|
39
|
+
undefined,
|
|
40
|
+
undefined,
|
|
41
|
+
[children],
|
|
42
|
+
undefined,
|
|
43
|
+
plain,
|
|
44
|
+
);
|
|
45
|
+
try {
|
|
46
|
+
const result = renderToElementTemplate(host);
|
|
47
|
+
expect(__SerializeElementTemplate(result.rootRefs[0]!).childSlots?.[0]).toHaveLength(2);
|
|
48
|
+
if (duplicate) {
|
|
49
|
+
expect(error).toHaveBeenCalledExactlyOnceWith(expect.stringContaining('same key attribute: "first"'));
|
|
50
|
+
expect(error.mock.calls[0]![0]).toContain('<_et_debug_root');
|
|
51
|
+
} else {
|
|
52
|
+
expect(error).not.toHaveBeenCalled();
|
|
53
|
+
}
|
|
54
|
+
} finally {
|
|
55
|
+
error.mockRestore();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { createContext, h, options } from 'preact';
|
|
6
|
+
import { useContext, useId, useState } from '@lynx-js/react/lepus/hooks';
|
|
7
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { __etHost } from '../../../../src/element-template/runtime/render/host.js';
|
|
10
|
+
import { destroyAllElementTemplateListStates } from '../../../../src/element-template/runtime/list/list.js';
|
|
11
|
+
import { renderToElementTemplate } from '../../../../src/element-template/runtime/render/render-direct.js';
|
|
12
|
+
import { createElementTemplatePage, setupPage } from '../../../../src/element-template/runtime/page/page.js';
|
|
13
|
+
import {
|
|
14
|
+
__etAttrPlanMap,
|
|
15
|
+
adaptEventAttrSlot,
|
|
16
|
+
adaptMTRefAttrSlot,
|
|
17
|
+
clearEtAttrPlanMap,
|
|
18
|
+
} from '../../../../src/element-template/runtime/template/attr-slot-plan.js';
|
|
19
|
+
import { resetTemplateId } from '../../../../src/element-template/runtime/template/handle.js';
|
|
20
|
+
import { clearMainThreadDynamicAttrState } from '../../../../src/element-template/runtime/template/main-thread-dynamic-attr-state.js';
|
|
21
|
+
import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
|
|
22
|
+
import { registerBuiltinRawTextTemplate, registerTemplates } from '../../test-utils/debug/registry.js';
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
globalThis.__MAIN_THREAD__ = true;
|
|
26
|
+
globalThis.__BACKGROUND__ = false;
|
|
27
|
+
resetTemplateId();
|
|
28
|
+
elementTemplateRegistry.clear();
|
|
29
|
+
clearEtAttrPlanMap();
|
|
30
|
+
clearMainThreadDynamicAttrState();
|
|
31
|
+
registerBuiltinRawTextTemplate();
|
|
32
|
+
registerTemplates([
|
|
33
|
+
{
|
|
34
|
+
templateId: '_et_compact_root',
|
|
35
|
+
compiledTemplate: {
|
|
36
|
+
kind: 'element',
|
|
37
|
+
type: 'view',
|
|
38
|
+
children: [{ kind: 'childSlot', type: 'slot', elementSlotIndex: 0 }],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
templateId: '_et_compact_leaf',
|
|
43
|
+
compiledTemplate: {
|
|
44
|
+
kind: 'element',
|
|
45
|
+
type: 'view',
|
|
46
|
+
attributesArray: [{ kind: 'slot', key: 'id', attrSlotIndex: 0 }],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
setupPage(createElementTemplatePage());
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
vi.restoreAllMocks();
|
|
55
|
+
vi.unstubAllGlobals();
|
|
56
|
+
clearEtAttrPlanMap();
|
|
57
|
+
clearMainThreadDynamicAttrState();
|
|
58
|
+
destroyAllElementTemplateListStates();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe.each([['compact', undefined], ['plain', true]] as const)(
|
|
62
|
+
'%s host direct materialization',
|
|
63
|
+
(_name, plain) => {
|
|
64
|
+
it('defers compact host creation and preserves reusable sparse inputs and explicit key', () => {
|
|
65
|
+
vi.stubGlobal('__DEV__', false);
|
|
66
|
+
const create = vi.spyOn(globalThis, '__CreateElementTemplate');
|
|
67
|
+
const attrs = ['leaf'];
|
|
68
|
+
const leaf = __etHost(
|
|
69
|
+
'__Card__:_et_compact_leaf',
|
|
70
|
+
'_et_compact_leaf',
|
|
71
|
+
'__Card__',
|
|
72
|
+
'key',
|
|
73
|
+
attrs,
|
|
74
|
+
undefined,
|
|
75
|
+
undefined,
|
|
76
|
+
plain,
|
|
77
|
+
);
|
|
78
|
+
const children = [leaf];
|
|
79
|
+
const slots = [, children, false];
|
|
80
|
+
const host = __etHost(
|
|
81
|
+
'__Card__:_et_compact_root',
|
|
82
|
+
'_et_compact_root',
|
|
83
|
+
'__Card__',
|
|
84
|
+
undefined,
|
|
85
|
+
undefined,
|
|
86
|
+
slots,
|
|
87
|
+
undefined,
|
|
88
|
+
plain,
|
|
89
|
+
);
|
|
90
|
+
expect(create).not.toHaveBeenCalled();
|
|
91
|
+
expect(leaf.key).toBe('key');
|
|
92
|
+
expect(leaf).not.toHaveProperty('props');
|
|
93
|
+
for (let i = 0; i < 2; i++) {
|
|
94
|
+
renderToElementTemplate(host);
|
|
95
|
+
const args = create.mock.calls.at(-1)!;
|
|
96
|
+
expect(args.slice(0, 3)).toEqual(['_et_compact_root', null, null]);
|
|
97
|
+
expect(args[3]).toHaveLength(2);
|
|
98
|
+
expect(Object.hasOwn(args[3]!, 0)).toBe(false);
|
|
99
|
+
expect(args[3]![1]).toHaveLength(1);
|
|
100
|
+
expect(slots).toEqual([, [leaf], false]);
|
|
101
|
+
expect(attrs).toEqual(['leaf']);
|
|
102
|
+
expect(leaf).not.toHaveProperty('props');
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('keeps hooks and component/native ordering through compact host ancestry', () => {
|
|
107
|
+
const Context = createContext('default');
|
|
108
|
+
const order: string[] = [];
|
|
109
|
+
const ids: string[] = [];
|
|
110
|
+
const create = globalThis.__CreateElementTemplate;
|
|
111
|
+
vi.spyOn(globalThis, '__CreateElementTemplate').mockImplementation((...args) => {
|
|
112
|
+
order.push('create:' + args[0]);
|
|
113
|
+
return create(...args);
|
|
114
|
+
});
|
|
115
|
+
function Child({ value }: { value: string }) {
|
|
116
|
+
order.push('render:' + value);
|
|
117
|
+
ids.push(useId());
|
|
118
|
+
const context = useContext(Context);
|
|
119
|
+
const [state] = useState(value);
|
|
120
|
+
return __etHost(
|
|
121
|
+
'__Card__:_et_compact_leaf',
|
|
122
|
+
'_et_compact_leaf',
|
|
123
|
+
'__Card__',
|
|
124
|
+
undefined,
|
|
125
|
+
[context + state],
|
|
126
|
+
undefined,
|
|
127
|
+
undefined,
|
|
128
|
+
plain,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const host = __etHost(
|
|
132
|
+
'__Card__:_et_compact_root',
|
|
133
|
+
'_et_compact_root',
|
|
134
|
+
'__Card__',
|
|
135
|
+
undefined,
|
|
136
|
+
undefined,
|
|
137
|
+
[[
|
|
138
|
+
h(Child, { value: 'a' }),
|
|
139
|
+
h(Child, { value: 'b' }),
|
|
140
|
+
]],
|
|
141
|
+
undefined,
|
|
142
|
+
plain,
|
|
143
|
+
);
|
|
144
|
+
const afterDiff = vi.fn();
|
|
145
|
+
const previousDiffed = options.diffed;
|
|
146
|
+
options.diffed = afterDiff;
|
|
147
|
+
let result: ReturnType<typeof renderToElementTemplate>;
|
|
148
|
+
try {
|
|
149
|
+
result = renderToElementTemplate(h(Context.Provider, { value: 'provided:', children: host as never }));
|
|
150
|
+
} finally {
|
|
151
|
+
options.diffed = previousDiffed;
|
|
152
|
+
}
|
|
153
|
+
expect(afterDiff).toHaveBeenCalledWith(host);
|
|
154
|
+
expect(order).toEqual([
|
|
155
|
+
'render:a',
|
|
156
|
+
'create:_et_compact_leaf',
|
|
157
|
+
'render:b',
|
|
158
|
+
'create:_et_compact_leaf',
|
|
159
|
+
'create:_et_compact_root',
|
|
160
|
+
]);
|
|
161
|
+
expect(new Set(ids).size).toBe(2);
|
|
162
|
+
expect(__SerializeElementTemplate(result.rootRefs[0]!)).toMatchObject({
|
|
163
|
+
childSlots: [[{ attributeSlots: ['provided:a'] }, { attributeSlots: ['provided:b'] }]],
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('prepares compact host events and MTRefs without changing input attributes', () => {
|
|
168
|
+
const mtRef = { _wvid: 123 };
|
|
169
|
+
const attrs = [1, mtRef];
|
|
170
|
+
__etAttrPlanMap['__Card__:_et_compact_leaf'] = [0, adaptEventAttrSlot, 1, adaptMTRefAttrSlot];
|
|
171
|
+
const create = vi.spyOn(globalThis, '__CreateElementTemplate');
|
|
172
|
+
const host = __etHost(
|
|
173
|
+
'__Card__:_et_compact_leaf',
|
|
174
|
+
'_et_compact_leaf',
|
|
175
|
+
'__Card__',
|
|
176
|
+
undefined,
|
|
177
|
+
attrs,
|
|
178
|
+
undefined,
|
|
179
|
+
undefined,
|
|
180
|
+
);
|
|
181
|
+
const parent = __etHost(
|
|
182
|
+
'__Card__:_et_compact_root',
|
|
183
|
+
'_et_compact_root',
|
|
184
|
+
'__Card__',
|
|
185
|
+
undefined,
|
|
186
|
+
undefined,
|
|
187
|
+
[[
|
|
188
|
+
host,
|
|
189
|
+
]],
|
|
190
|
+
undefined,
|
|
191
|
+
plain,
|
|
192
|
+
);
|
|
193
|
+
const result = renderToElementTemplate(parent);
|
|
194
|
+
expect(create.mock.calls[0]!.slice(0, 3)).toEqual(['_et_compact_leaf', null, ['-1:0:', null]]);
|
|
195
|
+
expect(result.rootSubtreeHandles).toEqual([[{ uid: -1, ref: create.mock.results[0]!.value }]]);
|
|
196
|
+
expect(attrs).toEqual([1, mtRef]);
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
);
|