@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,292 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { Component, Fragment, createContext, h, options } from 'preact';
|
|
5
|
+
import { Suspense, use } from 'preact/compat';
|
|
6
|
+
import { useState } from '@lynx-js/react/lepus/hooks';
|
|
7
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { renderToElementTemplate } from '../../../../src/element-template/runtime/render/render-direct.js';
|
|
10
|
+
import { __ElementTemplatePage } from '../../../../src/element-template/runtime/page/authored-page.js';
|
|
11
|
+
import { resetTemplateId } from '../../../../src/element-template/runtime/template/handle.js';
|
|
12
|
+
import { elementTemplateRegistry } from '../../../../src/element-template/runtime/template/registry.js';
|
|
13
|
+
import { registerBuiltinRawTextTemplate } from '../../test-utils/debug/registry.js';
|
|
14
|
+
import { DIFFED, PARENT } from '../../../../src/shared/render-constants.js';
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
resetTemplateId();
|
|
18
|
+
elementTemplateRegistry.clear();
|
|
19
|
+
registerBuiltinRawTextTemplate();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function renderText(vnode) {
|
|
23
|
+
return renderToElementTemplate(vnode).rootRefs.map(ref => __SerializeElementTemplate(ref).attributeSlots[0]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('Element Template synchronous components', () => {
|
|
27
|
+
it('lets use() read a context', () => {
|
|
28
|
+
const Ctx = createContext('default');
|
|
29
|
+
|
|
30
|
+
function Reader() {
|
|
31
|
+
return use(Ctx);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
expect(
|
|
35
|
+
renderText(h(Ctx.Provider, { value: 'provided' }, h(Reader, null))),
|
|
36
|
+
).toContain('provided');
|
|
37
|
+
expect(renderText(h(Reader, null))).toContain('default');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('lets use() read a context from a class that declares contextType', () => {
|
|
41
|
+
const Ctx = createContext('default');
|
|
42
|
+
const seen = [];
|
|
43
|
+
|
|
44
|
+
class Reader extends Component {
|
|
45
|
+
static contextType = Ctx;
|
|
46
|
+
render() {
|
|
47
|
+
seen.push(['this.context', this.context], ['use', use(Ctx)]);
|
|
48
|
+
return 'ok';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
renderText(h(Ctx.Provider, { value: 'provided' }, h(Reader, null)));
|
|
53
|
+
|
|
54
|
+
expect(seen).toEqual([['this.context', 'provided'], ['use', 'provided']]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('lets use() read a context from a function that declares contextType', () => {
|
|
58
|
+
const Ctx = createContext('default');
|
|
59
|
+
const seen = [];
|
|
60
|
+
|
|
61
|
+
function Reader(_props, context) {
|
|
62
|
+
seen.push(['arg', context], ['use', use(Ctx)]);
|
|
63
|
+
return 'ok';
|
|
64
|
+
}
|
|
65
|
+
Reader.contextType = Ctx;
|
|
66
|
+
|
|
67
|
+
renderText(h(Ctx.Provider, { value: 'provided' }, h(Reader, null)));
|
|
68
|
+
|
|
69
|
+
// `context` is the resolved contextType value here, so `use` has to read
|
|
70
|
+
// the provider map from `_globalContext` instead.
|
|
71
|
+
expect(seen).toEqual([['arg', 'provided'], ['use', 'provided']]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it.each(['direct', 'spread'])('prepares %s page refs from typed attributes', mode => {
|
|
75
|
+
const ref = () => {};
|
|
76
|
+
const attributes = mode === 'direct'
|
|
77
|
+
? { id: 'screen', ref }
|
|
78
|
+
: { id: 'screen', ...{ ref } };
|
|
79
|
+
const vnode = h(__ElementTemplatePage, { attributes });
|
|
80
|
+
|
|
81
|
+
expect(renderToElementTemplate(vnode).pageAttributes).toEqual({ id: 'screen', ref: '0-0' });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('rejects non-list uncompiled hosts outside development too', () => {
|
|
85
|
+
const originalDev = globalThis.__DEV__;
|
|
86
|
+
globalThis.__DEV__ = false;
|
|
87
|
+
try {
|
|
88
|
+
expect(() => renderText(h('view', null))).toThrow(
|
|
89
|
+
'Element Template main-thread renderer received an uncompiled host vnode: view',
|
|
90
|
+
);
|
|
91
|
+
} finally {
|
|
92
|
+
globalThis.__DEV__ = originalDev;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('cleans vnodes before throwing development renderer invariant errors', () => {
|
|
97
|
+
const previousDiffed = options[DIFFED];
|
|
98
|
+
const cleaned = [];
|
|
99
|
+
const plainHostVNode = h('view', null);
|
|
100
|
+
const invalidVNode = { type: null, props: {} };
|
|
101
|
+
options[DIFFED] = vnode => {
|
|
102
|
+
cleaned.push(vnode);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
expect(() => renderText(plainHostVNode)).toThrow(
|
|
107
|
+
'Element Template main-thread renderer received an uncompiled host vnode: view',
|
|
108
|
+
);
|
|
109
|
+
expect(() => renderText(invalidVNode)).toThrow(
|
|
110
|
+
'Element Template main-thread renderer received an invalid vnode.',
|
|
111
|
+
);
|
|
112
|
+
} finally {
|
|
113
|
+
options[DIFFED] = previousDiffed;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
expect(cleaned).toEqual([plainHostVNode, invalidVNode]);
|
|
117
|
+
expect(plainHostVNode[PARENT]).toBeUndefined();
|
|
118
|
+
expect(invalidVNode[PARENT]).toBeUndefined();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('calls the unmount option while cleaning rendered vnodes', () => {
|
|
122
|
+
const previousUnmount = options.unmount;
|
|
123
|
+
let unmountCount = 0;
|
|
124
|
+
options.unmount = () => {
|
|
125
|
+
unmountCount += 1;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
renderText(h('_et_builtin_raw_text', { attributeSlots: ['cleanup'] }));
|
|
130
|
+
} finally {
|
|
131
|
+
options.unmount = previousUnmount;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
expect(unmountCount).toBeGreaterThan(0);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('renders direct fragments', () => {
|
|
138
|
+
expect(renderText(
|
|
139
|
+
h(Fragment, null, 'direct-fragment'),
|
|
140
|
+
)).toContain('direct-fragment');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('unwraps unkeyed top-level fragments returned from components', () => {
|
|
144
|
+
function UnkeyedFragment() {
|
|
145
|
+
return h(Fragment, null, 'unkeyed-fragment');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
expect(renderText(h(UnkeyedFragment, null))).toContain('unkeyed-fragment');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('reuses class component instances and reapplies derived state from props', () => {
|
|
152
|
+
class DerivedMessage extends Component {
|
|
153
|
+
state = {
|
|
154
|
+
value: 'seed',
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
static getDerivedStateFromProps(props, state) {
|
|
158
|
+
return {
|
|
159
|
+
value: `${props.label}:${state.value}`,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
render() {
|
|
164
|
+
return this.state.value;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const vnode = h(DerivedMessage, { label: 'Ada' });
|
|
169
|
+
expect(renderText(vnode)).toContain('Ada:seed');
|
|
170
|
+
|
|
171
|
+
vnode.props = { label: 'Linus' };
|
|
172
|
+
expect(renderText(vnode)).toContain('Linus:seed');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('passes both modern and legacy context into component rendering', () => {
|
|
176
|
+
const ThemeContext = createContext('light');
|
|
177
|
+
|
|
178
|
+
class LegacyProvider extends Component {
|
|
179
|
+
getChildContext() {
|
|
180
|
+
return {
|
|
181
|
+
legacyTheme: 'legacy-dark',
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
render() {
|
|
186
|
+
return this.props.children;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
class ModernReader extends Component {
|
|
191
|
+
static contextType = ThemeContext;
|
|
192
|
+
|
|
193
|
+
render() {
|
|
194
|
+
return this.context;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function LegacyReader(_props, context) {
|
|
199
|
+
return context.legacyTheme;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function FragmentWrapper() {
|
|
203
|
+
return h(
|
|
204
|
+
Fragment,
|
|
205
|
+
null,
|
|
206
|
+
h(ModernReader, null),
|
|
207
|
+
h(LegacyReader, null),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const text = renderText(
|
|
212
|
+
h(
|
|
213
|
+
ThemeContext.Provider,
|
|
214
|
+
{ value: 'modern-dark' },
|
|
215
|
+
h(
|
|
216
|
+
LegacyProvider,
|
|
217
|
+
null,
|
|
218
|
+
h(FragmentWrapper, null),
|
|
219
|
+
),
|
|
220
|
+
),
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
expect(text).toContain('modern-dark');
|
|
224
|
+
expect(text).toContain('legacy-dark');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('renders already resolved Suspense content without fallback', async () => {
|
|
228
|
+
let resolved = false;
|
|
229
|
+
const pending = Promise.resolve();
|
|
230
|
+
void pending.then(() => {
|
|
231
|
+
resolved = true;
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
function Suspender() {
|
|
235
|
+
if (!resolved) {
|
|
236
|
+
throw pending;
|
|
237
|
+
}
|
|
238
|
+
return 'ready';
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const pendingText = renderText(
|
|
242
|
+
h(
|
|
243
|
+
Suspense,
|
|
244
|
+
{ fallback: 'loading' },
|
|
245
|
+
h(Suspender, null),
|
|
246
|
+
),
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
expect(pendingText).toContain('loading');
|
|
250
|
+
expect(pendingText).not.toContain('ready');
|
|
251
|
+
|
|
252
|
+
await pending;
|
|
253
|
+
|
|
254
|
+
const resolvedText = renderText(
|
|
255
|
+
h(
|
|
256
|
+
Suspense,
|
|
257
|
+
{ fallback: 'loading' },
|
|
258
|
+
h(Suspender, null),
|
|
259
|
+
),
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
expect(resolvedText).toContain('ready');
|
|
263
|
+
expect(resolvedText).not.toContain('loading');
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('does not re-render function components when main-thread hooks schedule an update during render', () => {
|
|
267
|
+
function DirtyHookComponent() {
|
|
268
|
+
const [count, setCount] = useState(0);
|
|
269
|
+
if (count === 0) {
|
|
270
|
+
setCount(1);
|
|
271
|
+
}
|
|
272
|
+
return String(count);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
expect(renderText(h(DirtyHookComponent, null))).toContain('0');
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('falls back to the default context value when no provider is mounted', () => {
|
|
279
|
+
const ThemeContext = createContext('default-theme');
|
|
280
|
+
|
|
281
|
+
class ThemeReader extends Component {
|
|
282
|
+
static contextType = ThemeContext;
|
|
283
|
+
|
|
284
|
+
render() {
|
|
285
|
+
return this.context;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const text = renderText(h(ThemeReader, null));
|
|
290
|
+
expect(text).toContain('default-theme');
|
|
291
|
+
});
|
|
292
|
+
});
|