@lynx-js/react 0.126.1 → 0.127.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/docs/directives.md +90 -0
- package/docs/global-events.md +50 -0
- package/docs/import-attributes.md +43 -0
- package/docs/macros.md +285 -0
- package/package.json +4 -3
- package/refresh/.turbo/turbo-build.log +4 -4
- package/refresh/dist/index.js +27 -8
- package/refresh/package.json +2 -2
- package/runtime/__test__/core/main-thread-object.test.js +149 -0
- package/runtime/__test__/element-template/debug/profile-installation.test.tsx +97 -1
- package/runtime/__test__/element-template/fixtures/background/hydrate-compiled/children.non-string-raw-text-key-on-main/output.txt +1 -1
- package/runtime/__test__/element-template/fixtures/background/main-thread-function/run-on-main-thread/index.tsx +26 -3
- package/runtime/__test__/element-template/fixtures/render/child-siblings/index.js.txt +15 -11
- package/runtime/__test__/element-template/fixtures/render/component/index.js.txt +8 -7
- package/runtime/__test__/element-template/fixtures/render/component-slot-content/index.js.txt +14 -10
- package/runtime/__test__/element-template/fixtures/render/css-scope-dynamic-bundle-url/index.js.txt +4 -3
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/_shared.ts +2 -9
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/case.ts +2 -4
- package/runtime/__test__/element-template/fixtures/render/direct-native/creates-template-from-attrs-and-slot-text/case.ts +20 -0
- package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/case.ts +3 -16
- package/runtime/__test__/element-template/fixtures/render/direct-native/handles-multiple-text-nodes-in-the-same-slot/case.ts +18 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/inserts-nested-templates-into-parent-slots/case.ts +20 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/keeps-slot-children-separated-and-ordered/case.ts +18 -0
- package/runtime/__test__/element-template/fixtures/render/direct-native/passes-bundle-url-to-native-create/case.ts +15 -0
- package/runtime/__test__/element-template/fixtures/render/mapped-view-children/index.js.txt +12 -11
- package/runtime/__test__/element-template/fixtures/render/mixed-children/index.js.txt +8 -7
- package/runtime/__test__/element-template/fixtures/render/multiple-text/index.js.txt +15 -13
- package/runtime/__test__/element-template/fixtures/render/nested-templates/index.js.txt +9 -7
- package/runtime/__test__/element-template/fixtures/render/react-example/index.js.txt +17 -20
- package/runtime/__test__/element-template/fixtures/render/sparse-element-slot/index.js.txt +13 -10
- package/runtime/__test__/element-template/fixtures/render/template-dedupe/index.js.txt +14 -11
- package/runtime/__test__/element-template/imports/main-thread-object-api.test.ts +10 -0
- package/runtime/__test__/element-template/imports/suspense-lazy.test.ts +52 -7
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +3 -0
- package/runtime/__test__/element-template/native/reload.test.ts +10 -26
- package/runtime/__test__/element-template/runtime/background/component-stack.test.tsx +76 -0
- package/runtime/__test__/element-template/runtime/background/hydrate.test.ts +87 -43
- package/runtime/__test__/element-template/runtime/background/instance.test.ts +14 -0
- package/runtime/__test__/element-template/runtime/background/main-thread-function/compiled-fixtures.test.tsx +4 -0
- package/runtime/__test__/element-template/runtime/render/compact-host-debug.test.ts +57 -0
- package/runtime/__test__/element-template/runtime/render/compact-host.test.ts +199 -0
- package/runtime/__test__/element-template/runtime/render/render-components.test.jsx +292 -0
- package/runtime/__test__/element-template/runtime/render/{render-opcodes-into-element-template.et.test.tsx → render-direct-native.test.tsx} +50 -314
- package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +378 -0
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +491 -0
- package/runtime/__test__/element-template/runtime/render/render-main-thread.contract.test.ts +2 -28
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +21 -35
- package/runtime/__test__/element-template/runtime/render/render-transform.contract.test.ts +6 -5
- package/runtime/__test__/element-template/test-utils/debug/renderFixtureRunner.ts +4 -4
- package/runtime/__test__/element-template/vitest.config.ts +2 -1
- package/runtime/__test__/snapshot/ctxNotFound.test.ts +271 -0
- package/runtime/__test__/snapshot/debug/main-thread-children-with-same-key.test.ts +28 -0
- package/runtime/__test__/snapshot/debug/profile.test.jsx +108 -3
- package/runtime/__test__/snapshot/event.test.jsx +7 -7
- package/runtime/__test__/snapshot/lazy.test.js +114 -7
- package/runtime/__test__/snapshot/lifecycle/reloadGc.test.jsx +66 -0
- package/runtime/__test__/snapshot/lynx/portals.test.jsx +75 -37
- package/runtime/__test__/snapshot/lynx/runtime-version.test.ts +140 -0
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +59 -47
- package/runtime/__test__/snapshot/spread.test.jsx +32 -25
- package/runtime/__test__/snapshot/ssr.legacy-slot.test.jsx +168 -0
- package/runtime/__test__/snapshot/ssr.list.test.jsx +211 -0
- package/runtime/__test__/snapshot/worklet/main-thread-object.test.jsx +306 -0
- package/runtime/__test__/snapshot/worklet/workletRef.test.jsx +1 -0
- package/runtime/__test__/worklet-runtime/hydrate.test.js +92 -0
- package/runtime/__test__/worklet-runtime/mainThreadObject.test.js +182 -0
- package/runtime/__test__/worklet-runtime/object-methods.test.js +60 -0
- package/runtime/__test__/worklet-runtime/runOnBackground.test.js +8 -6
- package/runtime/__test__/worklet-runtime/workletRef.test.js +362 -2
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +249 -3
- package/runtime/lazy/compat.js +2 -0
- package/runtime/lazy/element-template-import.js +0 -4
- package/runtime/lazy/element-template-internal.js +19 -8
- package/runtime/lazy/element-template-jsx-dev-runtime.js +1 -8
- package/runtime/lazy/element-template-jsx-runtime.js +1 -3
- package/runtime/lazy/element-template.js +3 -3
- package/runtime/lazy/import.js +0 -4
- package/runtime/lazy/internal.js +17 -1
- package/runtime/lazy/react.js +2 -0
- package/runtime/lazy/target.js +0 -21
- package/runtime/lib/core/background-function/run-on-background.d.ts +16 -0
- package/runtime/lib/core/background-function/run-on-background.js +16 -0
- package/runtime/lib/core/background-function/run-on-background.js.map +1 -1
- package/runtime/lib/core/capture-main-thread-object.js +16 -0
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -0
- package/runtime/lib/core/globalProps.d.ts +2 -0
- package/runtime/lib/core/globalProps.js.map +1 -1
- package/runtime/lib/core/hooks/react.d.ts +6 -0
- package/runtime/lib/core/hooks/react.js +6 -0
- package/runtime/lib/core/hooks/react.js.map +1 -1
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.d.ts +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js +2 -0
- package/runtime/lib/core/hooks/useLynxGlobalEventListener.js.map +1 -1
- package/runtime/lib/core/initData.d.ts +2 -0
- package/runtime/lib/core/initData.js +2 -0
- package/runtime/lib/core/initData.js.map +1 -1
- package/runtime/lib/core/lynx/runtime-version.d.ts +16 -0
- package/runtime/lib/core/lynx/runtime-version.js +51 -0
- package/runtime/lib/core/lynx/runtime-version.js.map +1 -0
- package/runtime/lib/core/main-thread-object-handle-registry.d.ts +3 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js +17 -0
- package/runtime/lib/core/main-thread-object-handle-registry.js.map +1 -0
- package/runtime/lib/core/main-thread-object.d.ts +77 -0
- package/runtime/lib/core/main-thread-object.js +261 -0
- package/runtime/lib/core/main-thread-object.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-id.js +14 -0
- package/runtime/lib/core/main-thread-ref-id.js.map +1 -0
- package/runtime/lib/core/main-thread-ref-init-value.d.ts +1 -1
- package/runtime/lib/core/main-thread-ref-init-value.js +4 -2
- package/runtime/lib/core/main-thread-ref-init-value.js.map +1 -1
- package/runtime/lib/core/main-thread-ref.d.ts +4 -0
- package/runtime/lib/core/main-thread-ref.js +5 -8
- package/runtime/lib/core/main-thread-ref.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/background/document.d.ts +1 -1
- package/runtime/lib/element-template/background/document.js +1 -1
- package/runtime/lib/element-template/background/document.js.map +1 -1
- package/runtime/lib/element-template/background/hydrate.js +51 -19
- package/runtime/lib/element-template/background/hydrate.js.map +1 -1
- package/runtime/lib/element-template/background/instance.js +5 -6
- package/runtime/lib/element-template/background/instance.js.map +1 -1
- package/runtime/lib/element-template/debug/profile.js +38 -22
- package/runtime/lib/element-template/debug/profile.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +3 -1
- package/runtime/lib/element-template/index.js +2 -1
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +5 -1
- package/runtime/lib/element-template/internal.js +7 -1
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/native/index.js +4 -0
- package/runtime/lib/element-template/native/index.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.d.ts +1 -1
- package/runtime/lib/element-template/runtime/list/list.d.ts +1 -0
- package/runtime/lib/element-template/runtime/list/list.js +3 -0
- package/runtime/lib/element-template/runtime/list/list.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/create-rendered-host.d.ts +7 -0
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js +65 -0
- package/runtime/lib/element-template/runtime/render/create-rendered-host.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/host.d.ts +18 -0
- package/runtime/lib/element-template/runtime/render/host.js +25 -0
- package/runtime/lib/element-template/runtime/render/host.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/render-components.d.ts +6 -0
- package/runtime/lib/element-template/runtime/render/render-components.js +190 -0
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/{render-opcodes.d.ts → render-direct.d.ts} +3 -1
- package/runtime/lib/element-template/runtime/render/render-direct.js +194 -0
- package/runtime/lib/element-template/runtime/render/render-direct.js.map +1 -0
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +10 -9
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/handle.d.ts +2 -1
- package/runtime/lib/element-template/runtime/template/handle.js +12 -4
- package/runtime/lib/element-template/runtime/template/handle.js.map +1 -1
- package/runtime/lib/element-template/runtime-marker.d.ts +1 -0
- package/runtime/lib/element-template/runtime-marker.js +13 -0
- package/runtime/lib/element-template/runtime-marker.js.map +1 -0
- package/runtime/lib/index.d.ts +1 -1
- package/runtime/lib/index.js +1 -1
- package/runtime/lib/index.js.map +1 -1
- package/runtime/lib/internal.d.ts +4 -1
- package/runtime/lib/internal.js +6 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +49 -6
- package/runtime/lib/lynx-api.js +34 -4
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +4 -1
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/runtime-marker.d.ts +1 -0
- package/runtime/lib/runtime-marker.js +13 -0
- package/runtime/lib/runtime-marker.js.map +1 -0
- package/runtime/lib/shared/component-stack.js +5 -1
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/snapshot/debug/profileHooks.js +38 -22
- package/runtime/lib/snapshot/debug/profileHooks.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.d.ts +11 -1
- package/runtime/lib/snapshot/lifecycle/patch/error.js +24 -16
- package/runtime/lib/snapshot/lifecycle/patch/error.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.d.ts +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +29 -7
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +2 -2
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.js +3 -0
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +3 -0
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/lynx/children.d.ts +2 -0
- package/runtime/lib/snapshot/lynx/children.js.map +1 -1
- package/runtime/lib/snapshot/lynx/element.d.ts +10 -0
- package/runtime/lib/snapshot/lynx/element.js +6 -0
- package/runtime/lib/snapshot/lynx/element.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +2 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.d.ts +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js +2 -0
- package/runtime/lib/snapshot/worklet/call/runOnMainThread.js.map +1 -1
- package/runtime/lib/snapshot/worklet/ref/updateInitValue.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.d.ts +3 -3
- package/runtime/lib/worklet-runtime/bindings/bindings.js +9 -1
- package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/types.d.ts +3 -6
- package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -1
- package/runtime/lib/worklet-runtime/hydrate.js +27 -8
- package/runtime/lib/worklet-runtime/hydrate.js.map +1 -1
- package/runtime/lib/worklet-runtime/mainThreadObject.d.ts +8 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js +67 -0
- package/runtime/lib/worklet-runtime/mainThreadObject.js.map +1 -0
- package/runtime/lib/worklet-runtime/workletRef.d.ts +11 -7
- package/runtime/lib/worklet-runtime/workletRef.js +72 -9
- package/runtime/lib/worklet-runtime/workletRef.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +69 -19
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/background-function/run-on-background.ts +16 -0
- package/runtime/src/core/capture-main-thread-object.ts +17 -0
- package/runtime/src/core/globalProps.ts +2 -0
- package/runtime/src/core/hooks/react.ts +6 -0
- package/runtime/src/core/hooks/useLynxGlobalEventListener.ts +2 -0
- package/runtime/src/core/initData.ts +2 -0
- package/runtime/src/core/lynx/runtime-version.ts +62 -0
- package/runtime/src/core/main-thread-object-handle-registry.ts +25 -0
- package/runtime/src/core/main-thread-object.ts +387 -0
- package/runtime/src/core/main-thread-ref-id.ts +16 -0
- package/runtime/src/core/main-thread-ref-init-value.ts +12 -4
- package/runtime/src/core/main-thread-ref.ts +7 -8
- package/runtime/src/element-template/background/commit-hook.ts +1 -1
- package/runtime/src/element-template/background/document.ts +3 -3
- package/runtime/src/element-template/background/hydrate.ts +61 -29
- package/runtime/src/element-template/background/instance.ts +5 -6
- package/runtime/src/element-template/debug/profile.ts +48 -36
- package/runtime/src/element-template/index.ts +7 -1
- package/runtime/src/element-template/internal.ts +14 -1
- package/runtime/src/element-template/native/index.ts +4 -0
- package/runtime/src/element-template/protocol/types.ts +1 -1
- package/runtime/src/element-template/runtime/list/list.ts +4 -0
- package/runtime/src/element-template/runtime/render/create-rendered-host.ts +126 -0
- package/runtime/src/element-template/runtime/render/host.ts +51 -0
- package/runtime/src/element-template/runtime/render/render-components.ts +255 -0
- package/runtime/src/element-template/runtime/render/render-direct.ts +275 -0
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +10 -9
- package/runtime/src/element-template/runtime/template/handle.ts +17 -7
- package/runtime/src/element-template/runtime-marker.ts +17 -0
- package/runtime/src/index.ts +1 -1
- package/runtime/src/internal.ts +11 -1
- package/runtime/src/lynx-api.ts +53 -6
- package/runtime/src/lynx.ts +5 -1
- package/runtime/src/runtime-marker.ts +17 -0
- package/runtime/src/shared/component-stack.ts +5 -1
- package/runtime/src/snapshot/debug/profileHooks.ts +52 -40
- package/runtime/src/snapshot/lifecycle/patch/error.ts +36 -19
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +29 -7
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +2 -2
- package/runtime/src/snapshot/lifecycle/reload.ts +4 -0
- package/runtime/src/snapshot/lynx/calledByNative.ts +4 -0
- package/runtime/src/snapshot/lynx/children.ts +2 -0
- package/runtime/src/snapshot/lynx/element.ts +10 -0
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +2 -1
- package/runtime/src/snapshot/worklet/call/runOnMainThread.ts +2 -0
- package/runtime/src/snapshot/worklet/ref/updateInitValue.ts +1 -1
- package/runtime/src/worklet-runtime/bindings/bindings.ts +17 -2
- package/runtime/src/worklet-runtime/bindings/types.ts +7 -11
- package/runtime/src/worklet-runtime/hydrate.ts +44 -11
- package/runtime/src/worklet-runtime/mainThreadObject.ts +117 -0
- package/runtime/src/worklet-runtime/workletRef.ts +120 -19
- package/runtime/src/worklet-runtime/workletRuntime.ts +84 -21
- package/runtime/types/types.d.ts +2 -0
- package/runtime/worklet-runtime/dev.js +155 -30
- package/runtime/worklet-runtime/main.js +1 -1
- package/testing-library/.turbo/turbo-build.log +12 -12
- package/testing-library/dist/env/index.js +2 -2
- package/testing-library/dist/index.d.ts +167 -4
- package/testing-library/dist/plugins/index.js +1 -1
- package/testing-library/dist/pure.js +45 -44
- package/testing-library/etc/react-lynx-testing-library.api.md +1 -1
- package/testing-library/package.json +4 -3
- package/testing-library/src/__tests__/lynx.test.jsx +1 -1
- package/testing-library/src/__tests__/reload/reloadGc.test.jsx +64 -0
- package/testing-library/src/__tests__/reload/reloadTemplate.js +39 -0
- package/testing-library/src/__tests__/worklet.test.jsx +46 -1
- package/testing-library/tsconfig.docs.json +9 -0
- package/testing-library/typedoc.json +22 -0
- package/testing-library/types/entry.d.ts +2 -2
- package/transform/.turbo/turbo-build$colon$wasm.log +151 -67
- package/transform/__test__/fixture.spec.js +89 -50
- package/transform/__test__/object-methods.spec.js +84 -0
- package/transform/__test__/text.spec.js +75 -0
- package/transform/crates/swc_plugin_compat/lib.rs +4 -3
- package/transform/crates/swc_plugin_compat/napi.rs +4 -3
- package/transform/crates/swc_plugin_define_dce/napi.rs +1 -1
- package/transform/crates/swc_plugin_dynamic_import/lib.rs +105 -3
- package/transform/crates/swc_plugin_dynamic_import/tests/__swc_snapshots__/lib.rs/should_suffix_webpack_chunk_name.js +5 -0
- package/transform/crates/swc_plugin_element_template/host_lowering.rs +111 -0
- package/transform/crates/swc_plugin_element_template/lib.rs +41 -5
- package/transform/crates/swc_plugin_element_template/lowering.rs +39 -7
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_generate_attribute_slots_for_dynamic_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_background_conditional_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_boolean_and_number_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_complex_text_structure.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dataset_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_deeply_nested_user_components.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_dynamic_class_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_events_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_id_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_inline_styles.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_interpolated_text_with_siblings_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_mixed_content.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_nested_structure_and_dynamic_content.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_refs_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_sibling_user_components.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_spread_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_handle_user_component.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_isolate_arrays_with_child_slot_placeholder.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_keep_code_and_template_attribute_slots_in_sync_for_spread.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_element_template_simple_lepus.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_output_template_with_static_attributes.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_template_structure_complex.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/__combined_snapshots__/should_verify_text_attribute_and_child_text_slots.snap +1 -1
- package/transform/crates/swc_plugin_element_template/tests/element_template.rs +70 -66
- package/transform/crates/swc_plugin_element_template/tests/element_template_contract.rs +94 -8
- package/transform/crates/swc_plugin_shake/lib.rs +1 -1
- package/transform/crates/swc_plugin_shake/napi.rs +1 -1
- package/transform/crates/swc_plugin_text/lib.rs +57 -16
- package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_keep_children_for_dynamic_or_multiple_text.js +13 -0
- package/transform/crates/swc_plugin_text/tests/__swc_snapshots__/lib.rs/should_transform_string_expressions_to_text_attr.js +13 -0
- package/transform/crates/swc_plugin_worklet/decl_collect.rs +10 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +14 -0
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +202 -3
- package/transform/crates/swc_plugin_worklet/lib.rs +468 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_js.js +8 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_capture_env_lepus.js +10 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_js.js +27 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_expose_object_method_capture_channels_lepus.js +45 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +16 -14
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +16 -16
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +7 -5
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +7 -7
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_computed_object_method_key_lepus.js +24 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_not_capture_object_method_local_decls_lepus.js +16 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +42 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +58 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_js.js +3 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_lepus.js +3 -3
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_js.js +9 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_transform_object_methods_lepus.js +16 -0
- package/transform/crates/swc_plugins_shared/jsx_helpers.rs +8 -4
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +7 -6
- package/transform/rspack-napi/tsconfig.tsbuildinfo +1 -1
- package/transform/src/swc_plugin_extract_str/mod.rs +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +63 -270
- package/transform/swc-plugin-reactlynx/index.d.ts +2 -2
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +306 -170
- package/transform/swc-plugin-reactlynx-compat/index.d.ts +3 -3
- package/transform/swc-plugin-reactlynx-compat/swc_plugin_reactlynx_compat.wasm +0 -0
- package/transform/vitest.config.ts +5 -1
- package/types/react.docs.d.ts +130 -11
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/creates-template-from-attrs-and-slot-text/case.ts +0 -39
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/handles-multiple-text-nodes-in-the-same-slot/case.ts +0 -29
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/inserts-nested-templates-into-parent-slots/case.ts +0 -42
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/keeps-slot-children-separated-and-ordered/case.ts +0 -31
- package/runtime/__test__/element-template/fixtures/render/opcodes-into-element-template/passes-bundle-url-to-native-create/case.ts +0 -20
- package/runtime/__test__/element-template/runtime/render/render-to-opcodes.et.test.jsx +0 -522
- package/runtime/lib/element-template/runtime/render/render-opcodes.js +0 -216
- package/runtime/lib/element-template/runtime/render/render-opcodes.js.map +0 -1
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.d.ts +0 -16
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.js +0 -324
- package/runtime/lib/element-template/runtime/render/render-to-opcodes.js.map +0 -1
- package/runtime/lib/element-template/runtime-backend-marker.js +0 -6
- package/runtime/lib/element-template/runtime-backend-marker.js.map +0 -1
- package/runtime/lib/runtime-backend-marker.js +0 -6
- package/runtime/lib/runtime-backend-marker.js.map +0 -1
- package/runtime/src/element-template/runtime/render/render-opcodes.ts +0 -313
- package/runtime/src/element-template/runtime/render/render-to-opcodes.ts +0 -411
- package/runtime/src/element-template/runtime-backend-marker.ts +0 -7
- package/runtime/src/runtime-backend-marker.ts +0 -7
- package/testing-library/node_modules/.bin/rsbuild +0 -55
- package/testing-library/node_modules/.bin/rspeedy +0 -55
- package/testing-library/node_modules/.bin/rstest +0 -55
- package/transform/node_modules/.bin/esbuild +0 -46
- package/transform/node_modules/.bin/napi +0 -55
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/appends-root-text-via-append-element/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/creates-template-from-attrs-and-slot-text/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-template-children-in-the-same-slot/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/handles-multiple-text-nodes-in-the-same-slot/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/inserts-nested-templates-into-parent-slots/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/native-log.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/keeps-slot-children-separated-and-ordered/output.txt +0 -0
- /package/runtime/__test__/element-template/fixtures/render/{opcodes-into-element-template → direct-native}/passes-bundle-url-to-native-create/native-log.txt +0 -0
- /package/runtime/lib/{element-template/runtime-backend-marker.d.ts → core/capture-main-thread-object.d.ts} +0 -0
- /package/runtime/lib/{runtime-backend-marker.d.ts → core/main-thread-ref-id.d.ts} +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
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 type { SerializableValue } from '../../protocol/types.js';
|
|
6
|
+
import type { ETListItemPlatformInfo } from '../list/list.js';
|
|
7
|
+
|
|
8
|
+
/** Compiler-owned first-screen data. Construction does not create native nodes. */
|
|
9
|
+
export function __etHost(
|
|
10
|
+
type: string,
|
|
11
|
+
templateKey: string,
|
|
12
|
+
bundleUrl: string,
|
|
13
|
+
key: unknown,
|
|
14
|
+
attributeSlots: SerializableValue[] | undefined,
|
|
15
|
+
slotChildren: unknown[] | undefined,
|
|
16
|
+
__listItemPlatformInfo: ETListItemPlatformInfo | undefined,
|
|
17
|
+
// Set only when the compiler proves no attribute adapters or list-item setup are needed.
|
|
18
|
+
plain?: true,
|
|
19
|
+
): ElementTemplateHost {
|
|
20
|
+
const host: ElementTemplateHost = {
|
|
21
|
+
type,
|
|
22
|
+
templateKey,
|
|
23
|
+
bundleUrl,
|
|
24
|
+
key,
|
|
25
|
+
attributeSlots,
|
|
26
|
+
slotChildren,
|
|
27
|
+
__listItemPlatformInfo,
|
|
28
|
+
plain,
|
|
29
|
+
};
|
|
30
|
+
if (__DEV__) {
|
|
31
|
+
// Preact debug formats host props in diagnostics such as duplicate keys.
|
|
32
|
+
// The renderer consumes the compact fields in both development and production.
|
|
33
|
+
host.props = { attributeSlots, children: slotChildren };
|
|
34
|
+
}
|
|
35
|
+
return host;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ElementTemplateHost {
|
|
39
|
+
plain?: true | undefined;
|
|
40
|
+
type: string;
|
|
41
|
+
templateKey: string;
|
|
42
|
+
bundleUrl: string;
|
|
43
|
+
key: unknown;
|
|
44
|
+
attributeSlots: SerializableValue[] | undefined;
|
|
45
|
+
slotChildren: unknown[] | undefined;
|
|
46
|
+
__listItemPlatformInfo?: ETListItemPlatformInfo | undefined;
|
|
47
|
+
props?: {
|
|
48
|
+
attributeSlots: SerializableValue[] | undefined;
|
|
49
|
+
children: unknown[] | undefined;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Synchronous component traversal for Element Template rendering.
|
|
7
|
+
* This module is modified from preact-render-to-string@6.0.3 to generate
|
|
8
|
+
* host output instead of HTML strings for Lynx.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// @ts-nocheck
|
|
12
|
+
|
|
13
|
+
import { Fragment, h, options } from 'preact';
|
|
14
|
+
|
|
15
|
+
import { discardRenderedHostsSince } from './create-rendered-host.js';
|
|
16
|
+
import { getNextElementTemplateId } from '../template/handle.js';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
BITS,
|
|
20
|
+
CHILDREN,
|
|
21
|
+
COMMIT,
|
|
22
|
+
COMPONENT,
|
|
23
|
+
COMPONENT_DIRTY,
|
|
24
|
+
DIFF,
|
|
25
|
+
DIFF2,
|
|
26
|
+
DIFFED,
|
|
27
|
+
GLOBAL_CONTEXT,
|
|
28
|
+
NEXT_STATE,
|
|
29
|
+
PARENT,
|
|
30
|
+
RENDER,
|
|
31
|
+
SKIP_EFFECTS,
|
|
32
|
+
VNODE,
|
|
33
|
+
} from '../../../shared/render-constants.js';
|
|
34
|
+
|
|
35
|
+
/** @typedef {import('preact').VNode} VNode */
|
|
36
|
+
|
|
37
|
+
const EMPTY_ARR = [];
|
|
38
|
+
const assign = /* @__PURE__ */ Object.assign;
|
|
39
|
+
|
|
40
|
+
// Global state for the current render pass
|
|
41
|
+
export let beforeDiff: ((vnode: unknown) => void) | undefined;
|
|
42
|
+
export let beforeDiff2: ((vnode: unknown, context: Record<string, unknown>) => void) | undefined;
|
|
43
|
+
let afterDiff, renderHook, ummountHook;
|
|
44
|
+
|
|
45
|
+
export function renderWithHooks(
|
|
46
|
+
vnode: unknown,
|
|
47
|
+
context: unknown,
|
|
48
|
+
output: unknown[],
|
|
49
|
+
renderVNode: Function,
|
|
50
|
+
result: unknown,
|
|
51
|
+
): unknown[] {
|
|
52
|
+
// Performance optimization: main-thread rendering is synchronous and we
|
|
53
|
+
// therefore don't execute any effects. To do that we pass an empty
|
|
54
|
+
// array to `options._commit` (`__c`). But we can go one step further
|
|
55
|
+
// and avoid a lot of dirty checks and allocations by setting
|
|
56
|
+
// `options._skipEffects` (`__s`) too.
|
|
57
|
+
const previousSkipEffects = options[SKIP_EFFECTS];
|
|
58
|
+
options[SKIP_EFFECTS] = true;
|
|
59
|
+
|
|
60
|
+
// store options hooks once before each synchronous render call
|
|
61
|
+
beforeDiff = options[DIFF];
|
|
62
|
+
beforeDiff2 = options[DIFF2];
|
|
63
|
+
afterDiff = options[DIFFED];
|
|
64
|
+
renderHook = options[RENDER];
|
|
65
|
+
ummountHook = options.unmount;
|
|
66
|
+
|
|
67
|
+
const parent = h(Fragment, null);
|
|
68
|
+
parent[CHILDREN] = [vnode];
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
renderVNode(
|
|
72
|
+
vnode,
|
|
73
|
+
context || EMPTY_OBJ,
|
|
74
|
+
parent,
|
|
75
|
+
output,
|
|
76
|
+
result,
|
|
77
|
+
);
|
|
78
|
+
} finally {
|
|
79
|
+
// options._commit, we don't schedule any effects in this library right now,
|
|
80
|
+
// so we can pass an empty queue to this hook.
|
|
81
|
+
if (options[COMMIT]) options[COMMIT](vnode, EMPTY_ARR);
|
|
82
|
+
options[SKIP_EFFECTS] = previousSkipEffects;
|
|
83
|
+
EMPTY_ARR.length = 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return output;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Installed as setState/forceUpdate for function components
|
|
90
|
+
/* v8 ignore start */
|
|
91
|
+
function markAsDirty() {
|
|
92
|
+
this[BITS] |= COMPONENT_DIRTY;
|
|
93
|
+
}
|
|
94
|
+
/* v8 ignore stop */
|
|
95
|
+
|
|
96
|
+
export const EMPTY_OBJ: Record<string, unknown> = {};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {VNode} vnode
|
|
100
|
+
* @param {Record<string, unknown>} context
|
|
101
|
+
*/
|
|
102
|
+
function renderClassComponent(vnode, context, globalContext) {
|
|
103
|
+
const type = /** @type {import("preact").ComponentClass<typeof vnode.props>} */ (vnode.type);
|
|
104
|
+
|
|
105
|
+
let c;
|
|
106
|
+
if (vnode[COMPONENT]) {
|
|
107
|
+
c = vnode[COMPONENT];
|
|
108
|
+
c.state = c[NEXT_STATE];
|
|
109
|
+
} else {
|
|
110
|
+
c = new type(vnode.props, context);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
vnode[COMPONENT] = c;
|
|
114
|
+
c[VNODE] = vnode;
|
|
115
|
+
|
|
116
|
+
c.props = vnode.props;
|
|
117
|
+
c.context = context;
|
|
118
|
+
c[GLOBAL_CONTEXT] = globalContext;
|
|
119
|
+
// turn off stateful re-rendering:
|
|
120
|
+
c[BITS] |= COMPONENT_DIRTY;
|
|
121
|
+
|
|
122
|
+
if (c.state == null) c.state = EMPTY_OBJ;
|
|
123
|
+
|
|
124
|
+
if (c[NEXT_STATE] == null) {
|
|
125
|
+
c[NEXT_STATE] = c.state;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (type.getDerivedStateFromProps) {
|
|
129
|
+
c.state = assign(
|
|
130
|
+
{},
|
|
131
|
+
c.state,
|
|
132
|
+
type.getDerivedStateFromProps(c.props, c.state),
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (renderHook) renderHook(vnode);
|
|
137
|
+
|
|
138
|
+
return c.render(c.props, c.state, context);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function cleanupVNode(vnode: unknown): void {
|
|
142
|
+
if (afterDiff) afterDiff(vnode);
|
|
143
|
+
vnode[PARENT] = undefined;
|
|
144
|
+
if (ummountHook) ummountHook(vnode);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function renderComponentVNode(
|
|
148
|
+
vnode: unknown,
|
|
149
|
+
type: unknown,
|
|
150
|
+
props: unknown,
|
|
151
|
+
context: unknown,
|
|
152
|
+
output: unknown[],
|
|
153
|
+
renderVNode: Function,
|
|
154
|
+
result: unknown,
|
|
155
|
+
parentType?: string,
|
|
156
|
+
subtreeHandles?: unknown[],
|
|
157
|
+
listItemUids?: number[],
|
|
158
|
+
): void {
|
|
159
|
+
let cctx = context;
|
|
160
|
+
let rendered;
|
|
161
|
+
let component;
|
|
162
|
+
const outputLength = output.length;
|
|
163
|
+
|
|
164
|
+
if (type === Fragment) {
|
|
165
|
+
rendered = props.children;
|
|
166
|
+
} else {
|
|
167
|
+
const contextType = type.contextType;
|
|
168
|
+
if (contextType != null) {
|
|
169
|
+
const provider = context[contextType.__c];
|
|
170
|
+
cctx = provider ? provider.props.value : contextType.__;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (type.prototype && typeof type.prototype.render === 'function') {
|
|
174
|
+
rendered = /**#__NOINLINE__**/ renderClassComponent(vnode, cctx, context);
|
|
175
|
+
component = vnode[COMPONENT];
|
|
176
|
+
} else {
|
|
177
|
+
component = {
|
|
178
|
+
__v: vnode,
|
|
179
|
+
props,
|
|
180
|
+
context: cctx,
|
|
181
|
+
[GLOBAL_CONTEXT]: context,
|
|
182
|
+
// silently drop state updates
|
|
183
|
+
setState: markAsDirty,
|
|
184
|
+
forceUpdate: markAsDirty,
|
|
185
|
+
__g: COMPONENT_DIRTY,
|
|
186
|
+
// hooks
|
|
187
|
+
__h: [],
|
|
188
|
+
};
|
|
189
|
+
vnode[COMPONENT] = component;
|
|
190
|
+
component.constructor = type;
|
|
191
|
+
component.render = doRender;
|
|
192
|
+
|
|
193
|
+
let count = 0;
|
|
194
|
+
while (component[BITS] & COMPONENT_DIRTY && count++ < 25) {
|
|
195
|
+
component[BITS] &= ~COMPONENT_DIRTY;
|
|
196
|
+
|
|
197
|
+
if (renderHook) renderHook(vnode);
|
|
198
|
+
|
|
199
|
+
rendered = component.render(props, component.state, cctx);
|
|
200
|
+
}
|
|
201
|
+
component[BITS] |= COMPONENT_DIRTY;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (component.getChildContext != null) {
|
|
205
|
+
context = assign({}, context, component.getChildContext());
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const isTopLevelFragment = rendered != null && rendered.type === Fragment
|
|
210
|
+
&& rendered.key == null;
|
|
211
|
+
rendered = isTopLevelFragment ? rendered.props.children : rendered;
|
|
212
|
+
|
|
213
|
+
// A Suspense boundary owns the IDs allocated while rendering its children,
|
|
214
|
+
// as well as the entries added to the enclosing commit collectors.
|
|
215
|
+
const checkpoint = component && component.__c
|
|
216
|
+
? {
|
|
217
|
+
rootSubtreeHandlesLength: result.rootSubtreeHandles.length,
|
|
218
|
+
subtreeHandlesLength: subtreeHandles?.length,
|
|
219
|
+
listItemUidsLength: listItemUids?.length,
|
|
220
|
+
nextId: getNextElementTemplateId(),
|
|
221
|
+
pageAttributes: result.pageAttributes,
|
|
222
|
+
isInsideAuthoredPage: result.isInsideAuthoredPage,
|
|
223
|
+
}
|
|
224
|
+
: undefined;
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles, listItemUids);
|
|
228
|
+
} catch (e) {
|
|
229
|
+
if (
|
|
230
|
+
checkpoint && e && typeof e === 'object' && e.then
|
|
231
|
+
) {
|
|
232
|
+
component.setState({ /* _suspended */ __a: true });
|
|
233
|
+
|
|
234
|
+
rendered = renderClassComponent(vnode, context, context);
|
|
235
|
+
|
|
236
|
+
output.length = outputLength;
|
|
237
|
+
result.rootSubtreeHandles.length = checkpoint.rootSubtreeHandlesLength;
|
|
238
|
+
if (subtreeHandles) subtreeHandles.length = checkpoint.subtreeHandlesLength;
|
|
239
|
+
if (listItemUids) listItemUids.length = checkpoint.listItemUidsLength;
|
|
240
|
+
discardRenderedHostsSince(checkpoint.nextId);
|
|
241
|
+
result.pageAttributes = checkpoint.pageAttributes;
|
|
242
|
+
if (__DEV__) result.isInsideAuthoredPage = checkpoint.isInsideAuthoredPage;
|
|
243
|
+
renderVNode(rendered, context, vnode, output, result, parentType, subtreeHandles, listItemUids);
|
|
244
|
+
} else {
|
|
245
|
+
throw e;
|
|
246
|
+
}
|
|
247
|
+
} finally {
|
|
248
|
+
cleanupVNode(vnode);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** The `.render()` method for a PFC backing instance. */
|
|
253
|
+
function doRender(props, state, context) {
|
|
254
|
+
return this.constructor(props, context);
|
|
255
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
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 { createRenderedHost, discardRenderedHostsSince } from './create-rendered-host.js';
|
|
6
|
+
import type { RenderAttributes } from './create-rendered-host.js';
|
|
7
|
+
import type { ElementTemplateHost } from './host.js';
|
|
8
|
+
import {
|
|
9
|
+
EMPTY_OBJ,
|
|
10
|
+
beforeDiff,
|
|
11
|
+
beforeDiff2,
|
|
12
|
+
cleanupVNode,
|
|
13
|
+
renderComponentVNode,
|
|
14
|
+
renderWithHooks,
|
|
15
|
+
} from './render-components.js';
|
|
16
|
+
import { CHILDREN, PARENT } from '../../../shared/render-constants.js';
|
|
17
|
+
import { ELEMENT_TEMPLATE_PAGE_HANDLE_ID } from '../../protocol/page.js';
|
|
18
|
+
import type { RuntimeTypedElementAttributes, TypedElementAttributesCommand } from '../../protocol/types.js';
|
|
19
|
+
import { clearPendingElementTemplateListItems } from '../list/list.js';
|
|
20
|
+
import type { ETListItemPlatformInfo } from '../list/list.js';
|
|
21
|
+
import { __ElementTemplatePage } from '../page/authored-page.js';
|
|
22
|
+
import {
|
|
23
|
+
createElementTemplateWithReservedHandle,
|
|
24
|
+
getNextElementTemplateId,
|
|
25
|
+
reserveElementTemplateId,
|
|
26
|
+
} from '../template/handle.js';
|
|
27
|
+
import type { MainThreadDynamicAttrSubtreeHandle } from '../template/main-thread-dynamic-attr-state.js';
|
|
28
|
+
import { prepareTypedElementAttributes } from '../template/typed-attributes.js';
|
|
29
|
+
|
|
30
|
+
export interface MainThreadCreateResult {
|
|
31
|
+
pageAttributes: TypedElementAttributesCommand | null;
|
|
32
|
+
rootRefs: ElementTemplateHandle[];
|
|
33
|
+
rootSubtreeHandles: MainThreadDynamicAttrSubtreeHandle[][];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface DirectRenderState extends Omit<MainThreadCreateResult, 'pageAttributes'> {
|
|
37
|
+
pageAttributes: TypedElementAttributesCommand | null | undefined;
|
|
38
|
+
isInsideAuthoredPage?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface RenderVNode {
|
|
42
|
+
type: unknown;
|
|
43
|
+
props: Record<string, unknown>;
|
|
44
|
+
templateKey?: string;
|
|
45
|
+
[PARENT]?: RenderVNode | undefined;
|
|
46
|
+
[CHILDREN]?: unknown[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type RenderContext = Record<string, unknown>;
|
|
50
|
+
|
|
51
|
+
const isArray = /* @__PURE__ */ Array.isArray;
|
|
52
|
+
|
|
53
|
+
export function renderToElementTemplate(vnode: unknown, context?: RenderContext | null): MainThreadCreateResult {
|
|
54
|
+
const checkpoint = getNextElementTemplateId();
|
|
55
|
+
const result: DirectRenderState = {
|
|
56
|
+
pageAttributes: undefined,
|
|
57
|
+
rootRefs: [],
|
|
58
|
+
rootSubtreeHandles: [],
|
|
59
|
+
};
|
|
60
|
+
if (__DEV__) {
|
|
61
|
+
result.isInsideAuthoredPage = false;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
/* #__NOINLINE__ */ renderWithHooks(vnode, context, result.rootRefs, renderDirect, result);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
discardRenderedHostsSince(checkpoint);
|
|
67
|
+
throw error;
|
|
68
|
+
} finally {
|
|
69
|
+
// Completed lists consume their item records. Anything left belongs to
|
|
70
|
+
// abandoned content, including children discarded by Suspense.
|
|
71
|
+
clearPendingElementTemplateListItems();
|
|
72
|
+
}
|
|
73
|
+
result.pageAttributes ??= null;
|
|
74
|
+
return result as MainThreadCreateResult;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function validateRoot(result: DirectRenderState, parentType: string | undefined): void {
|
|
78
|
+
if (
|
|
79
|
+
parentType === undefined && result.pageAttributes !== undefined
|
|
80
|
+
&& !result.isInsideAuthoredPage
|
|
81
|
+
) {
|
|
82
|
+
throw new Error('Element Template authored <page /> must wrap all materialized roots.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function renderHost(
|
|
87
|
+
vnode: RenderVNode,
|
|
88
|
+
context: RenderContext,
|
|
89
|
+
output: ElementTemplateHandle[],
|
|
90
|
+
result: DirectRenderState,
|
|
91
|
+
parentType: string | undefined,
|
|
92
|
+
parentSubtreeHandles: MainThreadDynamicAttrSubtreeHandle[] | undefined,
|
|
93
|
+
parentListItemUids: number[] | undefined,
|
|
94
|
+
): void {
|
|
95
|
+
const type = vnode.type as string;
|
|
96
|
+
const props = vnode.templateKey === undefined ? vnode.props : vnode as unknown as Record<string, unknown>;
|
|
97
|
+
const isList = type === 'list';
|
|
98
|
+
const attributes = (isList ? props['attributes'] : props['attributeSlots']) as RenderAttributes;
|
|
99
|
+
const listItemPlatformInfo = props['__listItemPlatformInfo'] as ETListItemPlatformInfo | undefined;
|
|
100
|
+
let deferredListItemMarker = false;
|
|
101
|
+
if (__DEV__) {
|
|
102
|
+
deferredListItemMarker = props['isReady'] !== undefined;
|
|
103
|
+
validateRoot(result, parentType);
|
|
104
|
+
}
|
|
105
|
+
if (!isList && !(type.startsWith('_et_') || type.includes(':_et_'))) {
|
|
106
|
+
cleanupVNode(vnode);
|
|
107
|
+
throw new Error(`Element Template main-thread renderer received an uncompiled host vnode: ${type}`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Recursive locals retain the inputs until children finish. Only native
|
|
111
|
+
// child arrays and the root/list-item ref collector survive this call.
|
|
112
|
+
const subtreeHandles = parentType === undefined || parentType === 'list' ? [] : parentSubtreeHandles!;
|
|
113
|
+
let childSlots: ElementTemplateHandle[][] | undefined;
|
|
114
|
+
let listItemUids: number[] | undefined;
|
|
115
|
+
if (isList) {
|
|
116
|
+
try {
|
|
117
|
+
if (__DEV__) {
|
|
118
|
+
for (const name in props) {
|
|
119
|
+
if (name.startsWith('$') && name !== '$0') {
|
|
120
|
+
throw new Error('Element Template typed list only supports logical slot $0.');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const children = props['$0'];
|
|
125
|
+
if (children != null && children !== true && children !== false) {
|
|
126
|
+
const refs: ElementTemplateHandle[] = [];
|
|
127
|
+
childSlots = [refs];
|
|
128
|
+
listItemUids = [];
|
|
129
|
+
renderDirect(children, context, vnode, refs, result, type, subtreeHandles, listItemUids);
|
|
130
|
+
}
|
|
131
|
+
} finally {
|
|
132
|
+
cleanupVNode(vnode);
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
// Ordered inputs belong to the caller. Named inputs are collected into a
|
|
136
|
+
// renderer-owned array that can also hold the resulting native refs.
|
|
137
|
+
let childrenBySlot = props['slotChildren'] as unknown[] | undefined;
|
|
138
|
+
if (vnode.templateKey === undefined && childrenBySlot === undefined) {
|
|
139
|
+
for (const name in props) {
|
|
140
|
+
if (name.startsWith('$')) {
|
|
141
|
+
const children = props[name];
|
|
142
|
+
if (children == null || children === true || children === false) continue;
|
|
143
|
+
(childrenBySlot ??= [])[+name.slice(1)] = children;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
childSlots = childrenBySlot as ElementTemplateHandle[][] | undefined;
|
|
147
|
+
}
|
|
148
|
+
if (childrenBySlot !== undefined) {
|
|
149
|
+
for (let slotId = 0; slotId < childrenBySlot.length; slotId++) {
|
|
150
|
+
const children = childrenBySlot[slotId];
|
|
151
|
+
if (children == null || children === true || children === false) continue;
|
|
152
|
+
const refs = (childSlots ??= [])[slotId] = [];
|
|
153
|
+
renderDirect(children, context, vnode, refs, result, type, subtreeHandles, undefined);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
cleanupVNode(vnode);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (__DEV__ && !isList && parentType === 'list') {
|
|
160
|
+
if (deferredListItemMarker) {
|
|
161
|
+
throw new Error('Element Template typed list does not support deferred list items.');
|
|
162
|
+
}
|
|
163
|
+
if (listItemPlatformInfo === undefined) {
|
|
164
|
+
throw new Error('Element Template typed list received a non-list-item root in logical slot $0.');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const uid = reserveElementTemplateId();
|
|
168
|
+
const ref = /* #__NOINLINE__ */ createRenderedHost(
|
|
169
|
+
uid,
|
|
170
|
+
type,
|
|
171
|
+
attributes,
|
|
172
|
+
childSlots,
|
|
173
|
+
listItemUids,
|
|
174
|
+
subtreeHandles,
|
|
175
|
+
listItemPlatformInfo,
|
|
176
|
+
vnode.templateKey === undefined ? undefined : vnode as unknown as ElementTemplateHost,
|
|
177
|
+
);
|
|
178
|
+
output.push(ref);
|
|
179
|
+
if (parentType === undefined) {
|
|
180
|
+
result.rootSubtreeHandles.push(isList ? [] : subtreeHandles);
|
|
181
|
+
} else if (parentListItemUids !== undefined) {
|
|
182
|
+
parentListItemUids.push(uid);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function renderDirect(
|
|
187
|
+
value: unknown,
|
|
188
|
+
context: RenderContext,
|
|
189
|
+
parent: RenderVNode,
|
|
190
|
+
output: ElementTemplateHandle[],
|
|
191
|
+
result: DirectRenderState,
|
|
192
|
+
parentType?: string,
|
|
193
|
+
subtreeHandles?: MainThreadDynamicAttrSubtreeHandle[],
|
|
194
|
+
listItemUids?: number[],
|
|
195
|
+
): void {
|
|
196
|
+
if (value == null || value === true || value === false || value === '') return;
|
|
197
|
+
|
|
198
|
+
if (typeof value !== 'object') {
|
|
199
|
+
if (typeof value === 'function') return;
|
|
200
|
+
if (__DEV__) {
|
|
201
|
+
validateRoot(result, parentType);
|
|
202
|
+
if (parentType === 'list') {
|
|
203
|
+
throw new Error('Element Template typed list received text logical child.');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
output.push(createElementTemplateWithReservedHandle(
|
|
207
|
+
reserveElementTemplateId(),
|
|
208
|
+
'_et_builtin_raw_text',
|
|
209
|
+
null,
|
|
210
|
+
[(value as string | number) + ''],
|
|
211
|
+
[],
|
|
212
|
+
));
|
|
213
|
+
if (parentType === undefined) result.rootSubtreeHandles.push([]);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (isArray(value)) {
|
|
218
|
+
parent[CHILDREN] = value;
|
|
219
|
+
for (let index = 0; index < value.length; index++) {
|
|
220
|
+
const child: unknown = value[index];
|
|
221
|
+
if (child == null || typeof child === 'boolean') continue;
|
|
222
|
+
renderDirect(child, context, parent, output, result, parentType, subtreeHandles, listItemUids);
|
|
223
|
+
}
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const vnode = value as RenderVNode;
|
|
228
|
+
vnode[PARENT] = parent;
|
|
229
|
+
if (beforeDiff) beforeDiff(vnode);
|
|
230
|
+
if (beforeDiff2) beforeDiff2(vnode, EMPTY_OBJ);
|
|
231
|
+
const type = vnode.type;
|
|
232
|
+
const props = vnode.props;
|
|
233
|
+
if (typeof type === 'function') {
|
|
234
|
+
if (type === __ElementTemplatePage) {
|
|
235
|
+
if (__DEV__) {
|
|
236
|
+
if (parentType !== undefined) {
|
|
237
|
+
throw new Error('Element Template authored <page /> must be the outermost element.');
|
|
238
|
+
}
|
|
239
|
+
if (result.pageAttributes !== undefined) {
|
|
240
|
+
throw new Error('Element Template does not support multiple authored <page /> elements.');
|
|
241
|
+
}
|
|
242
|
+
if (result.rootRefs.length !== 0) {
|
|
243
|
+
throw new Error('Element Template authored <page /> must wrap all materialized roots.');
|
|
244
|
+
}
|
|
245
|
+
result.isInsideAuthoredPage = true;
|
|
246
|
+
}
|
|
247
|
+
result.pageAttributes = prepareTypedElementAttributes(
|
|
248
|
+
ELEMENT_TEMPLATE_PAGE_HANDLE_ID,
|
|
249
|
+
props['attributes'] as RuntimeTypedElementAttributes | undefined,
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
/* #__NOINLINE__ */ renderComponentVNode(
|
|
253
|
+
vnode,
|
|
254
|
+
type,
|
|
255
|
+
props,
|
|
256
|
+
context,
|
|
257
|
+
output,
|
|
258
|
+
renderDirect,
|
|
259
|
+
result,
|
|
260
|
+
parentType,
|
|
261
|
+
subtreeHandles,
|
|
262
|
+
listItemUids,
|
|
263
|
+
);
|
|
264
|
+
if (__DEV__ && type === __ElementTemplatePage) result.isInsideAuthoredPage = false;
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (typeof type === 'string') {
|
|
268
|
+
/* #__NOINLINE__ */ renderHost(vnode, context, output, result, parentType, subtreeHandles, listItemUids);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (__DEV__) {
|
|
272
|
+
cleanupVNode(vnode);
|
|
273
|
+
throw new Error('Element Template main-thread renderer received an invalid vnode.');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* Implements the IFR (Instant First-Frame Rendering) on main thread.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import { render as renderToString } from './render-to-opcodes.js';
|
|
9
|
+
import { renderToElementTemplate } from './render-direct.js';
|
|
11
10
|
import { getReloadVersion } from '../../../core/reload-version.js';
|
|
12
11
|
import { profileEnd, profileStart } from '../../debug/profile.js';
|
|
13
12
|
import { ElementTemplateLifecycleConstant } from '../../protocol/lifecycle-constant.js';
|
|
@@ -21,20 +20,22 @@ import { getElementTemplateNativeRef } from '../template/registry.js';
|
|
|
21
20
|
import { TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX } from '../template/typed-attributes.js';
|
|
22
21
|
|
|
23
22
|
function renderMainThread(): void {
|
|
24
|
-
let
|
|
23
|
+
let rendered;
|
|
25
24
|
profileStart('ReactLynx::renderMainThread');
|
|
26
25
|
try {
|
|
27
|
-
|
|
28
|
-
} catch (
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
rendered = renderToElementTemplate(__root.__jsx, undefined);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
// Like Snapshot, any failure during synchronous rendering is reported at
|
|
29
|
+
// the lifecycle boundary before committing an empty result.
|
|
30
|
+
lynx.reportError(error as Error);
|
|
31
|
+
rendered = { pageAttributes: null, rootRefs: [], rootSubtreeHandles: [] };
|
|
31
32
|
} finally {
|
|
32
33
|
profileEnd();
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
profileStart('ReactLynx::
|
|
36
|
+
profileStart('ReactLynx::commitElementTemplate');
|
|
36
37
|
try {
|
|
37
|
-
const { pageAttributes, rootRefs, rootSubtreeHandles } =
|
|
38
|
+
const { pageAttributes, rootRefs, rootSubtreeHandles } = rendered;
|
|
38
39
|
__SetAttributeOfElementTemplate(__page, TYPED_ELEMENT_ATTRIBUTES_SLOT_INDEX, pageAttributes);
|
|
39
40
|
for (let index = 0; index < rootRefs.length; index += 1) {
|
|
40
41
|
const rootRef = rootRefs[index]!;
|
|
@@ -22,6 +22,10 @@ import type {
|
|
|
22
22
|
// Main-thread IFR allocates ids as consecutive negative integers.
|
|
23
23
|
let nextId = -1;
|
|
24
24
|
|
|
25
|
+
export function getNextElementTemplateId(): number {
|
|
26
|
+
return nextId;
|
|
27
|
+
}
|
|
28
|
+
|
|
25
29
|
export function reserveElementTemplateId(): number {
|
|
26
30
|
const id = nextId--;
|
|
27
31
|
return id;
|
|
@@ -33,9 +37,13 @@ export function createElementTemplateWithReservedHandle(
|
|
|
33
37
|
bundleUrl: string | null | undefined,
|
|
34
38
|
attributeSlots: SerializableValue[] | null | undefined,
|
|
35
39
|
childSlots: RuntimeChildSlots | null | undefined,
|
|
40
|
+
hasDynamicAttributes = true,
|
|
36
41
|
): ElementTemplateHandle {
|
|
37
|
-
|
|
38
|
-
const
|
|
42
|
+
// Adapter-free compiled hosts need neither dynamic state nor native slot preparation.
|
|
43
|
+
const templateType = hasDynamicAttributes ? elementTemplateTypeTag(templateKey, bundleUrl) : undefined;
|
|
44
|
+
const nativeAttributeSlots = templateType === undefined
|
|
45
|
+
? attributeSlots
|
|
46
|
+
: prepareMainThreadDynamicAttrSlotsForNative(templateType, attributeSlots);
|
|
39
47
|
const nativeRef = __CreateElementTemplate(
|
|
40
48
|
templateKey,
|
|
41
49
|
bundleUrl,
|
|
@@ -45,11 +53,13 @@ export function createElementTemplateWithReservedHandle(
|
|
|
45
53
|
);
|
|
46
54
|
if (nativeRef) {
|
|
47
55
|
setElementTemplateNativeRef(handleId, nativeRef);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
if (templateType !== undefined) {
|
|
57
|
+
initializeMainThreadDynamicAttrSlots(
|
|
58
|
+
handleId,
|
|
59
|
+
templateType,
|
|
60
|
+
attributeSlots,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
53
63
|
}
|
|
54
64
|
return nativeRef;
|
|
55
65
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
|
|
5
|
+
// Side-effect entry that registers this bundle's runtime markers (backend,
|
|
6
|
+
// version, ...) on load. Imported once by the element-template runtime entry
|
|
7
|
+
// so later-loaded lazy bundles register their own markers too.
|
|
8
|
+
|
|
9
|
+
import { RUNTIME_BACKEND_ELEMENT_TEMPLATE, registerRuntimeBackend } from '../core/lynx/runtime-backend.js';
|
|
10
|
+
import { registerRuntimeVersion } from '../core/lynx/runtime-version.js';
|
|
11
|
+
|
|
12
|
+
registerRuntimeBackend(RUNTIME_BACKEND_ELEMENT_TEMPLATE);
|
|
13
|
+
// An older `react-webpack-plugin` may not stamp `__RUNTIME_VERSION__`. Guard
|
|
14
|
+
// with `typeof` so referencing it does not throw when the define is missing.
|
|
15
|
+
registerRuntimeVersion(
|
|
16
|
+
typeof __RUNTIME_VERSION__ === 'undefined' ? undefined : __RUNTIME_VERSION__,
|
|
17
|
+
);
|
package/runtime/src/index.ts
CHANGED