@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
package/runtime/src/internal.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { Suspense, createElement, lazy, cloneElement as preactCloneElement } from 'preact/compat';
|
|
6
6
|
import type { FC } from 'react';
|
|
7
7
|
|
|
8
|
-
import './runtime-
|
|
8
|
+
import './runtime-marker.js';
|
|
9
9
|
import './lynx.js';
|
|
10
10
|
|
|
11
11
|
import { useMemo } from './core/hooks/react.js';
|
|
@@ -73,6 +73,15 @@ export type { Options } from 'preact';
|
|
|
73
73
|
|
|
74
74
|
export { loadDynamicJS, __dynamicImport } from './core/lynx/dynamic-import.js';
|
|
75
75
|
|
|
76
|
+
// Re-exported so lazy bundle shells can reach the host runtime APIs
|
|
77
|
+
// via `target[sExportsReactInternal]`.
|
|
78
|
+
export { registerRuntimeVersion, getRuntimeVersion } from './core/lynx/runtime-version.js';
|
|
79
|
+
export {
|
|
80
|
+
RUNTIME_BACKEND_ELEMENT_TEMPLATE,
|
|
81
|
+
RUNTIME_BACKEND_SNAPSHOT,
|
|
82
|
+
registerRuntimeBackend,
|
|
83
|
+
} from './core/lynx/runtime-backend.js';
|
|
84
|
+
|
|
76
85
|
export { withInitDataInState } from './core/initData.js';
|
|
77
86
|
|
|
78
87
|
export { wrapWithLynxComponent } from './core/compat/lynxComponent.js';
|
|
@@ -92,6 +101,7 @@ export { createBackgroundFunctionHandle as transformToWorklet } from './core/bac
|
|
|
92
101
|
export { registerWorkletOnBackground } from './snapshot/worklet/hmr.js';
|
|
93
102
|
|
|
94
103
|
export { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings';
|
|
104
|
+
export { captureMainThreadObject } from './core/capture-main-thread-object.js';
|
|
95
105
|
|
|
96
106
|
if (__DEV__) {
|
|
97
107
|
// Dev snapshot creators take the runtime as a parameter (they are
|
package/runtime/src/lynx-api.ts
CHANGED
|
@@ -19,6 +19,8 @@ import { flushDelayedLifecycleEvents } from './snapshot/lynx/tt.js';
|
|
|
19
19
|
/**
|
|
20
20
|
* The default root exported by `@lynx-js/react` for you to render a JSX
|
|
21
21
|
* @public
|
|
22
|
+
*
|
|
23
|
+
* @group Types
|
|
22
24
|
*/
|
|
23
25
|
export interface Root {
|
|
24
26
|
/**
|
|
@@ -83,6 +85,8 @@ export interface Root {
|
|
|
83
85
|
* ```
|
|
84
86
|
*
|
|
85
87
|
* @public
|
|
88
|
+
*
|
|
89
|
+
* @group Functions
|
|
86
90
|
*/
|
|
87
91
|
export const root: Root = {
|
|
88
92
|
render: (jsx: ReactNode): void => {
|
|
@@ -134,6 +138,8 @@ export const root: Root = {
|
|
|
134
138
|
* ```
|
|
135
139
|
*
|
|
136
140
|
* @public
|
|
141
|
+
*
|
|
142
|
+
* @group Functions
|
|
137
143
|
*/
|
|
138
144
|
export function markFirstScreenSyncReady(): void {
|
|
139
145
|
if (__FIRST_SCREEN_SYNC_TIMING__ !== 'manual') {
|
|
@@ -182,6 +188,8 @@ const _InitData = /* @__PURE__ */ factory<InitData>(
|
|
|
182
188
|
* ```
|
|
183
189
|
*
|
|
184
190
|
* @public
|
|
191
|
+
*
|
|
192
|
+
* @function
|
|
185
193
|
*/
|
|
186
194
|
// @ts-expect-error make preact and react types work
|
|
187
195
|
export const InitDataProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _InitData.Provider();
|
|
@@ -190,6 +198,8 @@ export const InitDataProvider: FC<{ children?: ReactNode | undefined }> = /* @__
|
|
|
190
198
|
* This should be used with {@link InitDataProvider}
|
|
191
199
|
* @group Components
|
|
192
200
|
* @public
|
|
201
|
+
*
|
|
202
|
+
* @function
|
|
193
203
|
*/
|
|
194
204
|
// @ts-expect-error make preact and react types work
|
|
195
205
|
export const InitDataConsumer: Consumer<InitData> = /* @__PURE__ */ _InitData.Consumer();
|
|
@@ -207,7 +217,10 @@ export const InitDataConsumer: Consumer<InitData> = /* @__PURE__ */ _InitData.Co
|
|
|
207
217
|
* }
|
|
208
218
|
* ```
|
|
209
219
|
*
|
|
220
|
+
* @function
|
|
210
221
|
* @public
|
|
222
|
+
*
|
|
223
|
+
* @group Hooks
|
|
211
224
|
*/
|
|
212
225
|
export const useInitData: () => InitData = /* @__PURE__ */ _InitData.use();
|
|
213
226
|
/**
|
|
@@ -221,7 +234,10 @@ export const useInitData: () => InitData = /* @__PURE__ */ _InitData.use();
|
|
|
221
234
|
* })
|
|
222
235
|
* }
|
|
223
236
|
* ```
|
|
237
|
+
* @function
|
|
224
238
|
* @public
|
|
239
|
+
*
|
|
240
|
+
* @group Hooks
|
|
225
241
|
*/
|
|
226
242
|
export const useInitDataChanged: (callback: (data: InitData) => void) => void = /* @__PURE__ */ _InitData.useChanged();
|
|
227
243
|
|
|
@@ -235,12 +251,15 @@ const _GlobalProps = /* @__PURE__ */ createGlobalProps<GlobalProps>({
|
|
|
235
251
|
});
|
|
236
252
|
|
|
237
253
|
/**
|
|
238
|
-
* The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `lynx.__globalProps
|
|
239
|
-
*
|
|
254
|
+
* The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `lynx.__globalProps`.
|
|
255
|
+
* Only needed with `globalPropsMode: 'event'`; in the default `'reactive'` mode it renders its children directly
|
|
256
|
+
* and updates come from a full re-render.
|
|
240
257
|
* @group Components
|
|
241
258
|
*
|
|
242
259
|
* @example
|
|
243
260
|
*
|
|
261
|
+
* With `globalPropsMode: 'event'`:
|
|
262
|
+
*
|
|
244
263
|
* ```ts
|
|
245
264
|
* import { root } from "@lynx-js/react"
|
|
246
265
|
*
|
|
@@ -259,22 +278,28 @@ const _GlobalProps = /* @__PURE__ */ createGlobalProps<GlobalProps>({
|
|
|
259
278
|
* ```
|
|
260
279
|
*
|
|
261
280
|
* @public
|
|
281
|
+
*
|
|
282
|
+
* @function
|
|
262
283
|
*/
|
|
263
284
|
// @ts-expect-error make preact and react types work
|
|
264
285
|
export const GlobalPropsProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _GlobalProps.Provider();
|
|
265
286
|
|
|
266
287
|
/**
|
|
267
288
|
* The {@link https://react.dev/reference/react/createContext#consumer | Consumer} Component that provide `lynx.__globalProps`.
|
|
268
|
-
*
|
|
289
|
+
* Only needed with `globalPropsMode: 'event'`, together with {@link GlobalPropsProvider}; in the default `'reactive'` mode
|
|
290
|
+
* it calls `children` with `lynx.__globalProps` directly and updates come from a full re-render.
|
|
269
291
|
* @group Components
|
|
270
292
|
* @public
|
|
293
|
+
*
|
|
294
|
+
* @function
|
|
271
295
|
*/
|
|
272
296
|
// @ts-expect-error make preact and react types work
|
|
273
297
|
export const GlobalPropsConsumer: Consumer<GlobalProps> = /* @__PURE__ */ _GlobalProps.Consumer();
|
|
274
298
|
|
|
275
299
|
/**
|
|
276
300
|
* A React Hooks for you to get `lynx.__globalProps`.
|
|
277
|
-
*
|
|
301
|
+
* With `globalPropsMode: 'event'`, the component re-renders when `lynx.__globalProps` changes;
|
|
302
|
+
* in the default `'reactive'` mode, updates arrive through a full re-render.
|
|
278
303
|
*
|
|
279
304
|
* @example
|
|
280
305
|
*
|
|
@@ -286,7 +311,10 @@ export const GlobalPropsConsumer: Consumer<GlobalProps> = /* @__PURE__ */ _Globa
|
|
|
286
311
|
* }
|
|
287
312
|
* ```
|
|
288
313
|
*
|
|
314
|
+
* @function
|
|
289
315
|
* @public
|
|
316
|
+
*
|
|
317
|
+
* @group Hooks
|
|
290
318
|
*/
|
|
291
319
|
export const useGlobalProps: () => GlobalProps = /* @__PURE__ */ _GlobalProps.use();
|
|
292
320
|
|
|
@@ -302,7 +330,10 @@ export const useGlobalProps: () => GlobalProps = /* @__PURE__ */ _GlobalProps.us
|
|
|
302
330
|
* })
|
|
303
331
|
* }
|
|
304
332
|
* ```
|
|
333
|
+
* @function
|
|
305
334
|
* @public
|
|
335
|
+
*
|
|
336
|
+
* @group Hooks
|
|
306
337
|
*/
|
|
307
338
|
export const useGlobalPropsChanged: (callback: (data: GlobalProps) => void) => void = /* @__PURE__ */ _GlobalProps
|
|
308
339
|
.useChanged();
|
|
@@ -313,6 +344,8 @@ export const useGlobalPropsChanged: (callback: (data: GlobalProps) => void) => v
|
|
|
313
344
|
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
314
345
|
*
|
|
315
346
|
* @public
|
|
347
|
+
*
|
|
348
|
+
* @group Types
|
|
316
349
|
*/
|
|
317
350
|
export interface InitDataRaw {}
|
|
318
351
|
/**
|
|
@@ -321,6 +354,8 @@ export interface InitDataRaw {}
|
|
|
321
354
|
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
322
355
|
*
|
|
323
356
|
* @public
|
|
357
|
+
*
|
|
358
|
+
* @group Types
|
|
324
359
|
*/
|
|
325
360
|
export interface InitData {}
|
|
326
361
|
|
|
@@ -356,6 +391,8 @@ export { withInitDataInState };
|
|
|
356
391
|
* ```
|
|
357
392
|
*
|
|
358
393
|
* @public
|
|
394
|
+
*
|
|
395
|
+
* @group Types
|
|
359
396
|
*/
|
|
360
397
|
export interface DataProcessors {
|
|
361
398
|
/**
|
|
@@ -405,6 +442,8 @@ export interface DataProcessors {
|
|
|
405
442
|
/**
|
|
406
443
|
* Definition of DataProcessor(s)
|
|
407
444
|
* @public
|
|
445
|
+
*
|
|
446
|
+
* @group Types
|
|
408
447
|
*/
|
|
409
448
|
export interface DataProcessorDefinition {
|
|
410
449
|
/**
|
|
@@ -437,6 +476,8 @@ export interface DataProcessorDefinition {
|
|
|
437
476
|
* ```
|
|
438
477
|
*
|
|
439
478
|
* @public
|
|
479
|
+
*
|
|
480
|
+
* @group Types
|
|
440
481
|
*/
|
|
441
482
|
export interface Lynx {
|
|
442
483
|
/**
|
|
@@ -523,7 +564,7 @@ export interface Lynx {
|
|
|
523
564
|
* they can achieve it by extends interface `InitDataRaw` and `InitData`.
|
|
524
565
|
*
|
|
525
566
|
* ```ts
|
|
526
|
-
* import {
|
|
567
|
+
* import { useInitData } from "@lynx-js/react"
|
|
527
568
|
*
|
|
528
569
|
* interface AnotherExistingInterface {
|
|
529
570
|
* someAnotherPropertyFromExistingInterface: number
|
|
@@ -535,7 +576,7 @@ export interface Lynx {
|
|
|
535
576
|
* }
|
|
536
577
|
* }
|
|
537
578
|
*
|
|
538
|
-
*
|
|
579
|
+
* lynx.registerDataProcessors({
|
|
539
580
|
* defaultDataProcessor: () => {
|
|
540
581
|
* return {
|
|
541
582
|
* someCustomProperty: 'value', // will be typed
|
|
@@ -561,3 +602,9 @@ export { useLynxGlobalEventListener } from './core/hooks/useLynxGlobalEventListe
|
|
|
561
602
|
export { runOnBackground } from './core/background-function/run-on-background.js';
|
|
562
603
|
export { runOnMainThread } from './snapshot/worklet/call/runOnMainThread.js';
|
|
563
604
|
export { MainThreadRef, useMainThreadRef } from './core/main-thread-ref.js';
|
|
605
|
+
export { defineMainThreadObjectType, useMainThreadObject } from './core/main-thread-object.js';
|
|
606
|
+
export type {
|
|
607
|
+
MainThreadObjectHandle,
|
|
608
|
+
MainThreadObjectType,
|
|
609
|
+
MainThreadObjectTypeDefinition,
|
|
610
|
+
} from './core/main-thread-object.js';
|
package/runtime/src/lynx.ts
CHANGED
|
@@ -69,7 +69,7 @@ if (typeof __ALOG_ELEMENT_API__ !== 'undefined' && __ALOG_ELEMENT_API__) {
|
|
|
69
69
|
initElementPAPICallAlog();
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
function initBackgroundRuntime(): void {
|
|
73
73
|
// Trick Preact and TypeScript to accept our custom document adapter.
|
|
74
74
|
options.document = document as unknown as Document;
|
|
75
75
|
options.requestAnimationFrame = lynxQueueMicrotask;
|
|
@@ -90,4 +90,8 @@ if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
94
|
+
initBackgroundRuntime();
|
|
95
|
+
}
|
|
96
|
+
|
|
93
97
|
setupLynxEnv();
|
|
@@ -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 runtime entry so later-loaded
|
|
7
|
+
// lazy bundles register their own markers too.
|
|
8
|
+
|
|
9
|
+
import { RUNTIME_BACKEND_SNAPSHOT, registerRuntimeBackend } from './core/lynx/runtime-backend.js';
|
|
10
|
+
import { registerRuntimeVersion } from './core/lynx/runtime-version.js';
|
|
11
|
+
|
|
12
|
+
registerRuntimeBackend(RUNTIME_BACKEND_SNAPSHOT);
|
|
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
|
+
);
|
|
@@ -154,7 +154,11 @@ export function setupComponentStack(): void {
|
|
|
154
154
|
};
|
|
155
155
|
|
|
156
156
|
options.vnode = (vnode: PatchedVNode) => {
|
|
157
|
-
|
|
157
|
+
// Scheduled component updates clone the vnode before entering its render scope.
|
|
158
|
+
// Preserve the original owner when Preact invokes this hook for that clone.
|
|
159
|
+
if (vnode._owner === undefined) {
|
|
160
|
+
vnode._owner = ownerStack.length > 0 ? ownerStack[ownerStack.length - 1]! : null;
|
|
161
|
+
}
|
|
158
162
|
if (oldVNode) oldVNode(vnode);
|
|
159
163
|
};
|
|
160
164
|
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
VALUE,
|
|
23
23
|
VNODE,
|
|
24
24
|
} from '../../shared/render-constants.js';
|
|
25
|
-
import { getDisplayName
|
|
25
|
+
import { getDisplayName } from '../../utils.js';
|
|
26
26
|
import { globalPatchOptions } from '../lifecycle/patch/commit.js';
|
|
27
27
|
import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';
|
|
28
28
|
|
|
@@ -103,33 +103,35 @@ export function initProfileHook(): void {
|
|
|
103
103
|
type PatchedComponent = Component & { [sFlowID]?: number };
|
|
104
104
|
|
|
105
105
|
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
old?.call(this, state, callback);
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
107
|
+
const oldSetState = Component.prototype.setState;
|
|
108
|
+
Component.prototype.setState = function(this: PatchedComponent & { [NEXT_STATE]: unknown }, state, callback) {
|
|
109
|
+
oldSetState?.call(this, state, callback);
|
|
111
110
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
if (this[BITS] & COMPONENT_DIRTY) {
|
|
112
|
+
const type = this[VNODE]!.type;
|
|
113
|
+
const isClassComponent = typeof type === 'function' && ('prototype' in type)
|
|
114
|
+
&& ('render' in type.prototype);
|
|
116
115
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
116
|
+
if (isClassComponent) {
|
|
117
|
+
profileMark('ReactLynx::setState', {
|
|
118
|
+
flowId: this[sFlowID] ??= profileFlowId(),
|
|
119
|
+
args: buildSetStateProfileMarkArgs(
|
|
120
|
+
type,
|
|
121
|
+
this.state,
|
|
122
|
+
this[NEXT_STATE],
|
|
123
|
+
),
|
|
124
|
+
});
|
|
127
125
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
126
|
+
}
|
|
127
|
+
};
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
|
|
130
|
+
// These hot callbacks have fixed signatures; avoid collecting and spreading
|
|
131
|
+
// an argument array for every host and component visited.
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
133
|
+
const oldDiff2 = options[DIFF2];
|
|
134
|
+
options[DIFF2] = (vnode, oldVNode) => {
|
|
133
135
|
// We only add profiling trace for Component
|
|
134
136
|
if (typeof vnode.type === 'function') {
|
|
135
137
|
const profileOptions: TraceOption = {};
|
|
@@ -152,10 +154,12 @@ export function initProfileHook(): void {
|
|
|
152
154
|
profileOptions,
|
|
153
155
|
);
|
|
154
156
|
}
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
+
oldDiff2?.(vnode, oldVNode);
|
|
158
|
+
};
|
|
157
159
|
|
|
158
|
-
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
161
|
+
const oldDiffed = options[DIFFED];
|
|
162
|
+
options[DIFFED] = vnode => {
|
|
159
163
|
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
160
164
|
const hooks = vnode[COMPONENT]?.[HOOKS];
|
|
161
165
|
const hookList = hooks?.[LIST];
|
|
@@ -205,11 +209,13 @@ export function initProfileHook(): void {
|
|
|
205
209
|
if (typeof vnode.type === 'function') {
|
|
206
210
|
profileEnd(); // for options[DIFF2]
|
|
207
211
|
}
|
|
208
|
-
|
|
209
|
-
}
|
|
212
|
+
oldDiffed?.(vnode);
|
|
213
|
+
};
|
|
210
214
|
|
|
211
215
|
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
212
|
-
|
|
216
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
217
|
+
const oldCommit = options[COMMIT];
|
|
218
|
+
options[COMMIT] = (vnode, commitQueue) => {
|
|
213
219
|
profileStart('ReactLynx::commit', {
|
|
214
220
|
...globalPatchOptions.flowIds
|
|
215
221
|
? {
|
|
@@ -218,14 +224,16 @@ export function initProfileHook(): void {
|
|
|
218
224
|
}
|
|
219
225
|
: {},
|
|
220
226
|
});
|
|
221
|
-
|
|
227
|
+
oldCommit?.(vnode, commitQueue);
|
|
222
228
|
profileEnd();
|
|
223
|
-
}
|
|
229
|
+
};
|
|
224
230
|
}
|
|
225
231
|
}
|
|
226
232
|
|
|
227
233
|
// Profile the user-provided `render`.
|
|
228
|
-
|
|
234
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
235
|
+
const oldRender = options[RENDER];
|
|
236
|
+
options[RENDER] = (vnode: VNode) => {
|
|
229
237
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
230
238
|
const originalRender = vnode[COMPONENT]!.render;
|
|
231
239
|
vnode[COMPONENT]!.render = function render(this, props, state, context) {
|
|
@@ -237,22 +245,26 @@ export function initProfileHook(): void {
|
|
|
237
245
|
vnode[COMPONENT]!.render = originalRender;
|
|
238
246
|
}
|
|
239
247
|
};
|
|
240
|
-
|
|
241
|
-
}
|
|
248
|
+
oldRender?.(vnode);
|
|
249
|
+
};
|
|
242
250
|
|
|
243
251
|
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
244
252
|
const sPatchLength = Symbol('PATCH_LENGTH');
|
|
245
253
|
|
|
246
254
|
type PatchedVNode = VNode & { [sPatchLength]?: number };
|
|
247
255
|
|
|
248
|
-
|
|
256
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
257
|
+
const oldDiff = options[DIFF];
|
|
258
|
+
options[DIFF] = (vnode: PatchedVNode) => {
|
|
249
259
|
if (typeof vnode.type === 'function' && __globalSnapshotPatch) {
|
|
250
260
|
vnode[sPatchLength] = __globalSnapshotPatch.length;
|
|
251
261
|
}
|
|
252
|
-
|
|
253
|
-
}
|
|
262
|
+
oldDiff?.(vnode);
|
|
263
|
+
};
|
|
254
264
|
|
|
255
|
-
|
|
265
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
266
|
+
const oldPatchDiffed = options[DIFFED];
|
|
267
|
+
options[DIFFED] = (vnode: PatchedVNode) => {
|
|
256
268
|
if (typeof vnode.type === 'function') {
|
|
257
269
|
const patchLength = vnode[sPatchLength];
|
|
258
270
|
delete vnode[sPatchLength];
|
|
@@ -265,7 +277,7 @@ export function initProfileHook(): void {
|
|
|
265
277
|
});
|
|
266
278
|
}
|
|
267
279
|
}
|
|
268
|
-
|
|
269
|
-
}
|
|
280
|
+
oldPatchDiffed?.(vnode);
|
|
281
|
+
};
|
|
270
282
|
}
|
|
271
283
|
}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
|
|
5
5
|
import { backgroundSnapshotInstanceManager } from '../../snapshot/backgroundSnapshot.js';
|
|
6
|
-
import { snapshotManager } from '../../snapshot/definition.js';
|
|
7
6
|
|
|
8
7
|
export const ctxNotFoundType = 'Lynx.Error.CtxNotFound';
|
|
9
8
|
|
|
@@ -11,39 +10,57 @@ const errorMsg = 'snapshotPatchApply failed: ctx not found';
|
|
|
11
10
|
|
|
12
11
|
let ctxNotFoundEventListener: ((e: RuntimeProxy.Event) => void) | null = null;
|
|
13
12
|
|
|
13
|
+
export interface CtxNotFoundOptions {
|
|
14
|
+
operation: string;
|
|
15
|
+
commitId: number;
|
|
16
|
+
isHydration: boolean;
|
|
17
|
+
parent?: number;
|
|
18
|
+
child?: number;
|
|
19
|
+
/** Missing main-thread contexts: 1 for parent, 2 for child, 3 for both. */
|
|
20
|
+
missingNode?: 1 | 2 | 3;
|
|
21
|
+
}
|
|
22
|
+
|
|
14
23
|
export interface CtxNotFoundData {
|
|
15
24
|
id: number;
|
|
25
|
+
options: CtxNotFoundOptions;
|
|
16
26
|
}
|
|
17
27
|
|
|
18
|
-
export function sendCtxNotFoundEventToBackground(id: number): void {
|
|
19
|
-
/* v8 ignore next 3 */
|
|
28
|
+
export function sendCtxNotFoundEventToBackground(id: number, options: CtxNotFoundOptions): void {
|
|
20
29
|
if (!lynx.getJSContext) {
|
|
21
30
|
throw new Error(errorMsg);
|
|
22
31
|
}
|
|
23
32
|
lynx.getJSContext().dispatchEvent({
|
|
24
33
|
type: ctxNotFoundType,
|
|
25
|
-
data: {
|
|
26
|
-
id,
|
|
27
|
-
} as CtxNotFoundData,
|
|
34
|
+
data: { id, options },
|
|
28
35
|
});
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
export function reportCtxNotFound(data: CtxNotFoundData): void {
|
|
32
|
-
const id = data
|
|
39
|
+
const { id, options } = data;
|
|
33
40
|
const instance = backgroundSnapshotInstanceManager.values.get(id);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const snapshotType = instance?.__snapshot_def ? instance.type ?? 'null' : 'null';
|
|
42
|
+
const { operation, commitId, isHydration, child, missingNode } = options;
|
|
43
|
+
const parent = options.parent ?? instance?.parentNode?.__id;
|
|
44
|
+
let parentInfo = 'parent: null';
|
|
45
|
+
if (parent !== undefined) {
|
|
46
|
+
const parentInstance = backgroundSnapshotInstanceManager.values.get(parent);
|
|
47
|
+
const parentType = parentInstance?.__snapshot_def ? parentInstance.type ?? 'null' : 'null';
|
|
48
|
+
const missingInfo = missingNode === undefined
|
|
49
|
+
? ''
|
|
50
|
+
: `, missing: ${missingNode === 1 || missingNode === 3}`;
|
|
51
|
+
parentInfo = `parent: { id: ${parent}, snapshot type: '${parentType}'${missingInfo} }`;
|
|
44
52
|
}
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
let ctxInfo = parentInfo;
|
|
54
|
+
if (child !== undefined) {
|
|
55
|
+
const childInstance = backgroundSnapshotInstanceManager.values.get(child);
|
|
56
|
+
const childType = childInstance?.__snapshot_def ? childInstance.type ?? 'null' : 'null';
|
|
57
|
+
const missingInfo = missingNode === undefined
|
|
58
|
+
? ''
|
|
59
|
+
: `, missing: ${missingNode === 2 || missingNode === 3}`;
|
|
60
|
+
ctxInfo = `${parentInfo}, child: { id: ${child}, snapshot type: '${childType}'${missingInfo} }`;
|
|
61
|
+
}
|
|
62
|
+
let message =
|
|
63
|
+
`${errorMsg}, snapshot type: '${snapshotType}', ${ctxInfo}, operation: '${operation}', commitId: ${commitId}, isHydration: ${isHydration}`;
|
|
47
64
|
if (__DEV__) {
|
|
48
65
|
message += '. You can set environment variable `REACT_ALOG=true` and restart your dev server for troubleshooting.';
|
|
49
66
|
}
|
|
@@ -24,7 +24,7 @@ import { SnapshotInstance, snapshotCreatorMap, snapshotInstanceManager } from '.
|
|
|
24
24
|
* This is the counterpart to the patch generation in the background thread.
|
|
25
25
|
* Each operation in the patch is processed sequentially to update the DOM.
|
|
26
26
|
*/
|
|
27
|
-
export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
27
|
+
export function snapshotPatchApply(snapshotPatch: SnapshotPatch, commitId: number, isHydration: boolean): void {
|
|
28
28
|
const length = snapshotPatch.length;
|
|
29
29
|
for (let i = 0; i < length; ++i) {
|
|
30
30
|
switch (snapshotPatch[i]) {
|
|
@@ -43,7 +43,14 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
43
43
|
const child = snapshotInstanceManager.values.get(childId);
|
|
44
44
|
const existingNode = snapshotInstanceManager.values.get(beforeId!);
|
|
45
45
|
if (!parent || !child) {
|
|
46
|
-
sendCtxNotFoundEventToBackground(parent ? childId : parentId
|
|
46
|
+
sendCtxNotFoundEventToBackground(parent ? childId : parentId, {
|
|
47
|
+
operation: 'InsertBefore',
|
|
48
|
+
commitId,
|
|
49
|
+
isHydration,
|
|
50
|
+
parent: parentId,
|
|
51
|
+
child: childId,
|
|
52
|
+
missingNode: parent ? 2 : (child ? 1 : 3),
|
|
53
|
+
});
|
|
47
54
|
} else {
|
|
48
55
|
child.__slotIndex = __slotIndex;
|
|
49
56
|
parent.insertBefore(child, existingNode);
|
|
@@ -56,7 +63,14 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
56
63
|
const parent = snapshotInstanceManager.values.get(parentId);
|
|
57
64
|
const child = snapshotInstanceManager.values.get(childId);
|
|
58
65
|
if (!parent || !child) {
|
|
59
|
-
sendCtxNotFoundEventToBackground(parent ? childId : parentId
|
|
66
|
+
sendCtxNotFoundEventToBackground(parent ? childId : parentId, {
|
|
67
|
+
operation: 'RemoveChild',
|
|
68
|
+
commitId,
|
|
69
|
+
isHydration,
|
|
70
|
+
parent: parentId,
|
|
71
|
+
child: childId,
|
|
72
|
+
missingNode: parent ? 2 : (child ? 1 : 3),
|
|
73
|
+
});
|
|
60
74
|
} else {
|
|
61
75
|
parent.removeChild(child);
|
|
62
76
|
}
|
|
@@ -70,7 +84,11 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
70
84
|
if (child) {
|
|
71
85
|
applyNodesRefInsertBefore(identifier, child, beforeId);
|
|
72
86
|
} else {
|
|
73
|
-
sendCtxNotFoundEventToBackground(childId
|
|
87
|
+
sendCtxNotFoundEventToBackground(childId, {
|
|
88
|
+
operation: 'nodesRefInsertBefore',
|
|
89
|
+
commitId,
|
|
90
|
+
isHydration,
|
|
91
|
+
});
|
|
74
92
|
}
|
|
75
93
|
break;
|
|
76
94
|
}
|
|
@@ -81,7 +99,11 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
81
99
|
if (child) {
|
|
82
100
|
applyNodesRefRemoveChild(identifier, child);
|
|
83
101
|
} else {
|
|
84
|
-
sendCtxNotFoundEventToBackground(childId
|
|
102
|
+
sendCtxNotFoundEventToBackground(childId, {
|
|
103
|
+
operation: 'nodesRefRemoveChild',
|
|
104
|
+
commitId,
|
|
105
|
+
isHydration,
|
|
106
|
+
});
|
|
85
107
|
}
|
|
86
108
|
break;
|
|
87
109
|
}
|
|
@@ -93,7 +115,7 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
93
115
|
if (si) {
|
|
94
116
|
si.setAttribute(dynamicPartIndex, value);
|
|
95
117
|
} else {
|
|
96
|
-
sendCtxNotFoundEventToBackground(id);
|
|
118
|
+
sendCtxNotFoundEventToBackground(id, { operation: 'SetAttribute', commitId, isHydration });
|
|
97
119
|
}
|
|
98
120
|
break;
|
|
99
121
|
}
|
|
@@ -104,7 +126,7 @@ export function snapshotPatchApply(snapshotPatch: SnapshotPatch): void {
|
|
|
104
126
|
if (si) {
|
|
105
127
|
si.setAttribute('values', values);
|
|
106
128
|
} else {
|
|
107
|
-
sendCtxNotFoundEventToBackground(id);
|
|
129
|
+
sendCtxNotFoundEventToBackground(id, { operation: 'SetAttributes', commitId, isHydration });
|
|
108
130
|
}
|
|
109
131
|
break;
|
|
110
132
|
}
|
|
@@ -66,10 +66,10 @@ function updateMainThread(
|
|
|
66
66
|
setMainThreadHydrating(true);
|
|
67
67
|
}
|
|
68
68
|
try {
|
|
69
|
-
for (const { snapshotPatch } of patchList) {
|
|
69
|
+
for (const { snapshotPatch, id } of patchList) {
|
|
70
70
|
__pendingListUpdates.clearAttachedLists();
|
|
71
71
|
if (snapshotPatch) {
|
|
72
|
-
snapshotPatchApply(snapshotPatch);
|
|
72
|
+
snapshotPatchApply(snapshotPatch, id, patchOptions.isHydration === true);
|
|
73
73
|
}
|
|
74
74
|
__pendingListUpdates.flush();
|
|
75
75
|
// console.debug('********** Lepus updatePatch:');
|
|
@@ -52,6 +52,10 @@ function reloadMainThread(data: unknown, options: UpdatePageOption): void {
|
|
|
52
52
|
__pendingListUpdates.flush();
|
|
53
53
|
applyRefQueue();
|
|
54
54
|
|
|
55
|
+
if (typeof lepusng_gc === 'function') {
|
|
56
|
+
lepusng_gc();
|
|
57
|
+
}
|
|
58
|
+
|
|
55
59
|
if (isFirstScreenSynced) {
|
|
56
60
|
__OnLifecycleEvent([
|
|
57
61
|
LifecycleConstant.firstScreen, /* FIRST_SCREEN */
|
|
@@ -161,6 +161,10 @@ function updatePage(data: Record<string, unknown> | undefined, options?: UpdateP
|
|
|
161
161
|
|
|
162
162
|
flushOptions.triggerDataUpdated = true;
|
|
163
163
|
markTiming('updateDiffVdomEnd');
|
|
164
|
+
|
|
165
|
+
if (typeof lepusng_gc === 'function') {
|
|
166
|
+
lepusng_gc();
|
|
167
|
+
}
|
|
164
168
|
}
|
|
165
169
|
|
|
166
170
|
__FlushElementTree(__page, flushOptions);
|
|
@@ -9,6 +9,8 @@ import { Children as PreactChildren } from 'preact/compat';
|
|
|
9
9
|
* Type of ReactLynx children utilities.
|
|
10
10
|
*
|
|
11
11
|
* @public
|
|
12
|
+
*
|
|
13
|
+
* @group Types
|
|
12
14
|
*/
|
|
13
15
|
export type ReactLynxChildren = Omit<typeof PreactChildren, 'map' | 'forEach' | 'toArray'> & {
|
|
14
16
|
map<T extends ComponentChild, R>(
|