@lynx-js/react 0.129.0 → 0.129.1
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 +14 -0
- package/components/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/__test__/core/hooks/useLynxGlobalEventListener.test.jsx +1 -1
- package/runtime/__test__/element-template/imports/no-legacy-imports.test.ts +7 -6
- package/runtime/__test__/element-template/internal/legacy-internal-guardrail.test.ts +1 -2
- package/runtime/__test__/element-template/native/main-thread-api.test.ts +5 -2
- package/runtime/__test__/element-template/native/mts-destroy.test.ts +83 -0
- package/runtime/__test__/element-template/native/reload-dual-thread-communication.test.ts +3 -0
- package/runtime/__test__/element-template/native/reload.test.ts +31 -2
- package/runtime/__test__/element-template/runtime/background/update-timing.test.ts +15 -0
- package/runtime/__test__/element-template/runtime/patch/element-template-patch.test.tsx +197 -7
- package/runtime/__test__/element-template/runtime/patch/update-timing.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-direct-suspense.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-direct.test.ts +4 -1
- package/runtime/__test__/element-template/runtime/render/render-main-thread.test.ts +101 -1
- package/runtime/__test__/element-template/runtime/template/element-template-handle.test.ts +32 -0
- package/runtime/__test__/element-template/runtime/template/main-thread-dynamic-attr-state.test.ts +121 -26
- package/runtime/__test__/element-template/test-utils/debug/envManager.ts +8 -5
- package/runtime/__test__/element-template/test-utils/mock/mockNativePapi.ts +35 -2
- package/runtime/__test__/guardrails/snapshot-containment.test.ts +45 -11
- package/runtime/__test__/shared/component-stack.test.ts +211 -0
- package/runtime/__test__/snapshot/debug/formatPatch.test.ts +0 -8
- package/runtime/__test__/snapshot/gesture/prepareGestureForCommit.test.js +1 -1
- package/runtime/__test__/snapshot/lynx/timing.test.jsx +3 -0
- package/runtime/__test__/snapshot/preact.test.jsx +0 -3
- package/runtime/__test__/snapshot/snapshotPatch.test.jsx +0 -33
- package/runtime/__test__/worklet-runtime/jsFunctionLifecycle.test.js +12 -0
- package/runtime/__test__/worklet-runtime/loadRuntime.test.js +68 -0
- package/runtime/__test__/worklet-runtime/workletRuntime.test.js +30 -0
- package/runtime/lazy/element-template-internal.js +0 -1
- package/runtime/lazy/internal.js +1 -1
- package/runtime/lazy/jsx-dev-runtime.js +1 -1
- package/runtime/lazy/jsx-runtime.js +1 -1
- package/runtime/lazy/legacy-react-runtime.js +1 -1
- package/runtime/lazy/react-lepus.js +1 -1
- package/runtime/lazy/react.js +1 -1
- package/runtime/lib/core/capture-main-thread-object.js +2 -1
- package/runtime/lib/core/capture-main-thread-object.js.map +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js +1 -1
- package/runtime/lib/core/compat/legacy-react-runtime.js.map +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.d.ts +125 -1
- package/runtime/lib/core/lynx-data-processors.js +3 -0
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/core/runtime-destroy.js +1 -1
- package/runtime/lib/core/runtime-destroy.js.map +1 -1
- package/runtime/lib/document.js +0 -5
- package/runtime/lib/document.js.map +1 -1
- package/runtime/lib/element-template/background/commit-hook.js +11 -12
- package/runtime/lib/element-template/background/commit-hook.js.map +1 -1
- package/runtime/lib/element-template/client/root.d.ts +1 -1
- package/runtime/lib/element-template/client/root.js.map +1 -1
- package/runtime/lib/element-template/index.d.ts +2 -2
- package/runtime/lib/element-template/index.js.map +1 -1
- package/runtime/lib/element-template/internal.d.ts +1 -1
- package/runtime/lib/element-template/internal.js +0 -13
- package/runtime/lib/element-template/internal.js.map +1 -1
- package/runtime/lib/element-template/lynx/env.js.map +1 -1
- package/runtime/lib/element-template/native/flush.d.ts +1 -0
- package/runtime/lib/element-template/native/flush.js +9 -0
- package/runtime/lib/element-template/native/flush.js.map +1 -0
- package/runtime/lib/element-template/native/main-thread-api.js +3 -7
- package/runtime/lib/element-template/native/main-thread-api.js.map +1 -1
- package/runtime/lib/element-template/native/mts-destroy.js +8 -2
- package/runtime/lib/element-template/native/mts-destroy.js.map +1 -1
- package/runtime/lib/element-template/native/patch-listener.js +57 -50
- package/runtime/lib/element-template/native/patch-listener.js.map +1 -1
- package/runtime/lib/element-template/native/reload-main-thread.js +2 -1
- package/runtime/lib/element-template/native/reload-main-thread.js.map +1 -1
- package/runtime/lib/element-template/protocol/types.js.map +1 -1
- package/runtime/lib/element-template/runtime/page/root-instance.d.ts +0 -1
- package/runtime/lib/element-template/runtime/page/root-instance.js.map +1 -1
- package/runtime/lib/element-template/runtime/patch.js +4 -0
- package/runtime/lib/element-template/runtime/patch.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-components.js +4 -4
- package/runtime/lib/element-template/runtime/render/render-components.js.map +1 -1
- package/runtime/lib/element-template/runtime/render/render-main-thread.js +2 -0
- package/runtime/lib/element-template/runtime/render/render-main-thread.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js +8 -1
- package/runtime/lib/element-template/runtime/template/main-thread-background-function.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.d.ts +1 -0
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js +41 -21
- package/runtime/lib/element-template/runtime/template/main-thread-dynamic-attr-state.js.map +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.d.ts +1 -1
- package/runtime/lib/element-template/runtime/template/main-thread-ref-ctx.js.map +1 -1
- package/runtime/lib/internal.d.ts +1 -1
- package/runtime/lib/internal.js +1 -1
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +2 -125
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/shared/component-stack.d.ts +0 -4
- package/runtime/lib/shared/component-stack.js +21 -5
- package/runtime/lib/shared/component-stack.js.map +1 -1
- package/runtime/lib/snapshot/gesture/{processGestureBagkround.js → processGestureBackground.js} +1 -1
- package/runtime/lib/snapshot/gesture/processGestureBackground.js.map +1 -0
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.d.ts +0 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js +0 -5
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +0 -10
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js +56 -51
- package/runtime/lib/snapshot/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/snapshot/list/listUpdateInfo.js +0 -30
- package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +11 -8
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +0 -52
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/index.js +10 -10
- package/runtime/lib/snapshot/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js +0 -51
- package/runtime/lib/snapshot/renderToOpcodes/opcodes.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/runtime/lib/worklet-runtime/bindings/index.d.ts +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js +1 -0
- package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -1
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.d.ts +8 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js +23 -0
- package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.d.ts +2 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js +6 -0
- package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -1
- package/runtime/lib/worklet-runtime/workletRuntime.js +2 -0
- package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -1
- package/runtime/package.json +2 -3
- package/runtime/src/core/capture-main-thread-object.ts +2 -1
- package/runtime/src/core/compat/legacy-react-runtime.ts +1 -1
- package/runtime/src/core/lynx/lazy-bundle.ts +1 -1
- package/runtime/src/core/lynx-data-processors.ts +124 -1
- package/runtime/src/core/runtime-destroy.ts +1 -1
- package/runtime/src/document.ts +0 -6
- package/runtime/src/element-template/background/commit-hook.ts +18 -12
- package/runtime/src/element-template/client/root.ts +1 -3
- package/runtime/src/element-template/index.ts +2 -2
- package/runtime/src/element-template/internal.ts +0 -20
- package/runtime/src/element-template/lynx/env.ts +1 -1
- package/runtime/src/element-template/native/flush.ts +10 -0
- package/runtime/src/element-template/native/main-thread-api.ts +3 -6
- package/runtime/src/element-template/native/mts-destroy.ts +7 -2
- package/runtime/src/element-template/native/patch-listener.ts +62 -57
- package/runtime/src/element-template/native/reload-main-thread.ts +2 -1
- package/runtime/src/element-template/protocol/types.ts +0 -13
- package/runtime/src/element-template/runtime/page/root-instance.ts +0 -1
- package/runtime/src/element-template/runtime/patch.ts +5 -0
- package/runtime/src/element-template/runtime/render/render-components.ts +3 -3
- package/runtime/src/element-template/runtime/render/render-main-thread.ts +2 -0
- package/runtime/src/element-template/runtime/template/main-thread-background-function.ts +8 -1
- package/runtime/src/element-template/runtime/template/main-thread-dynamic-attr-state.ts +51 -21
- package/runtime/src/element-template/runtime/template/main-thread-ref-ctx.ts +2 -2
- package/runtime/src/element-template/types.d.ts +6 -0
- package/runtime/src/internal.ts +1 -1
- package/runtime/src/lynx-api.ts +2 -124
- package/runtime/src/shared/component-stack.ts +22 -5
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatch.ts +0 -5
- package/runtime/src/snapshot/lifecycle/patch/snapshotPatchApply.ts +0 -10
- package/runtime/src/snapshot/lifecycle/patch/updateMainThread.ts +62 -58
- package/runtime/src/snapshot/list/listUpdateInfo.ts +0 -52
- package/runtime/src/snapshot/lynx/calledByNative.ts +11 -9
- package/runtime/src/snapshot/renderToOpcodes/hydrate.ts +0 -58
- package/runtime/src/snapshot/renderToOpcodes/index.ts +8 -8
- package/runtime/src/snapshot/renderToOpcodes/opcodes.ts +0 -57
- package/runtime/src/snapshot/snapshot/backgroundSnapshot.ts +1 -1
- package/runtime/src/worklet-runtime/README.md +30 -10
- package/runtime/src/worklet-runtime/bindings/index.ts +2 -0
- package/runtime/src/worklet-runtime/bindings/loadRuntime.ts +25 -0
- package/runtime/src/worklet-runtime/jsFunctionLifecycle.ts +6 -0
- package/runtime/src/worklet-runtime/workletRuntime.ts +2 -0
- package/runtime/vitest.config.ts +0 -2
- package/testing-library/.turbo/turbo-build.log +6 -6
- package/testing-library/src/__tests__/act.test.jsx +0 -7
- package/testing-library/src/__tests__/alog.test.jsx +12 -54
- package/testing-library/src/__tests__/end-to-end.test.jsx +0 -7
- package/testing-library/src/__tests__/renderComponent.test.jsx +0 -14
- package/testing-library/src/__tests__/worklet.test.jsx +49 -0
- package/transform/.turbo/turbo-build$colon$wasm.log +98 -376
- package/transform/__test__/defines.spec.js +30 -0
- package/transform/__test__/object-methods.spec.js +79 -0
- package/transform/crates/swc_plugin_worklet/extract_ident.rs +99 -49
- package/transform/crates/swc_plugin_worklet/gen_stmt.rs +56 -48
- package/transform/crates/swc_plugin_worklet/lib.rs +393 -589
- package/transform/crates/swc_plugin_worklet/napi.rs +4 -6
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_js.js +6 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_2_lepus.js +7 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_js.js +9 -0
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_extract_member_expr_lepus.js +12 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_js.js +1 -1
- package/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_preserve_main_thread_objects_in_class_lepus.js +1 -1
- package/transform/dist/wasm.cjs +1 -1
- package/transform/package.json +0 -1
- package/transform/src/lib.rs +1 -1
- package/transform/swc-plugin-reactlynx/.turbo/turbo-build.log +113 -42
- package/transform/swc-plugin-reactlynx/src/lib.rs +1 -4
- package/transform/swc-plugin-reactlynx/swc_plugin_reactlynx.wasm +0 -0
- package/transform/swc-plugin-reactlynx-compat/.turbo/turbo-build.log +273 -66
- package/runtime/lib/snapshot/gesture/processGestureBagkround.js.map +0 -1
- package/runtime/lib/snapshot/worklet/hmr.d.ts +0 -1
- package/runtime/lib/snapshot/worklet/hmr.js +0 -28
- package/runtime/lib/snapshot/worklet/hmr.js.map +0 -1
- package/runtime/src/snapshot/worklet/hmr.ts +0 -34
- /package/runtime/lib/snapshot/gesture/{processGestureBagkround.d.ts → processGestureBackground.d.ts} +0 -0
- /package/runtime/src/snapshot/gesture/{processGestureBagkround.ts → processGestureBackground.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-bundle.js","sourceRoot":"","sources":["../../../src/core/lynx/lazy-bundle.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,6EAA6E;AAC7E,oDAAoD;AACpD,6EAA6E;AAC7E,+CAA+C;AAC/C,4EAA4E;AAC5E,2DAA2D;AAC3D,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAC1C,MAAM,kBAAkB,GAAG,YAAY,CAAC;AACxC,MAAM,WAAW,GAAG,KAAK,CAAC;AAC1B,MA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C,EAAE,CAAC;AAEL,SAAS,iBAAiB;IACxB,iBAAiB,CAAC;IAElB,MAAM,QAAQ,GAKV;QACF,OAAO,EAAE,CAAC,MAAS,EAAQ,EAAE;YAC3B,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QAC3B,CAAC;QACD,MAAM,EAAE,CAAC,KAAY,EAAQ,EAAE;YAC7B,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;QACzB,CAAC;QACD,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,IAAI;KACZ,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n// Inlined rather than imported from `snapshot/` so this `core/` module stays\n// free of runtime-backend dependencies (enforced by\n// `guardrails/snapshot-containment`). `PREPARE_LAZY_BUNDLE_MTS` must stay in\n// sync with `snapshot/lifecycle/constant.ts`'s\n// `LifecycleConstant.prepareLazyBundleMTS`, the lifecycle name the snapshot\n// backend registers the main-thread prepare handler under.\nconst SECTION_MAIN_THREAD = 'main-thread';\nconst SECTION_BACKGROUND = 'background';\nconst SECTION_CSS = 'CSS';\nconst LYNX_LAZY_SYNC_TIMEOUT_SECONDS = 5;\nconst PREPARE_LAZY_BUNDLE_MTS = 'rLynxPrepareLazyBundleMTS';\n\n// Background-thread dedup cache: a `source` whose FetchBundle load fully\n// succeeded maps to its exports, so a repeat load returns the same result\n// without re-fetching or re-triggering the main-thread prepare. Only populated\n// on success — a failed load stays out of the cache and can be retried, exactly\n// like `prepareLazyBundleMTS`'s main-thread cache.\nconst fetchBundleBgCache = new Map<string, unknown>();\n\n/**\n * To make code below works\n * const App1 = lazy(() => import(\"./x\").then(({App1}) => ({default: App1})))\n * const App2 = lazy(() => import(\"./x\").then(({App2}) => ({default: App2})))\n * @internal\n */\nexport const makeSyncThen = function<T>(result: T): Promise<T>['then'] {\n return function<TR1 = T, TR2 = never>(\n this: Promise<T>,\n onF?: ((value: T) => TR1 | PromiseLike<TR1>) | null,\n _onR?: ((reason: any) => TR2 | PromiseLike<TR2>) | null,\n ): Promise<TR1 | TR2> {\n if (onF) {\n let ret: TR1 | PromiseLike<TR1>;\n try {\n ret = onF(result);\n } catch (e) {\n // if (onR) {\n // return Promise.resolve(onR(e));\n // }\n return Promise.reject(e as Error);\n }\n\n if (ret && typeof (ret as PromiseLike<TR1>).then === 'function' /* `thenable` object */) {\n // lazy(() =>\n // import(\"./x\").then(() => new Promise(...))\n // )\n // Calling `then` and passing a callback is standard behavior\n // but in Lepus runtime the callback will never be called\n // So can be simplified to code below\n return ret as Promise<TR1>;\n\n // TODO(hongzhiyuan.hzy): Avoid warning that cannot be turned-off, so the warning is commented\n // lynx.reportError(\n // new Error(\n // 'You returned a Promise in promise-chain of lazy-bundle import (eg. `import(\"./x\").then(() => new Promise(...))`), which will cause related Component unavailable at first-screen, '\n // ),\n // { level: \"warning\" }\n // );\n }\n\n // The Lynx Promise polyfill shares resolved promises for primitive values.\n // Own this promise before replacing `then`, or an undefined callback\n // result would make unrelated Promise.resolve().then(...) calls synchronous.\n const p = new Promise<TR1>(resolve => resolve(ret));\n\n const then = makeSyncThen(ret as TR1);\n p.then = then as Promise<Awaited<TR1>>['then'];\n\n return p as Promise<TR1 | TR2>;\n }\n\n return this as Promise<TR1 | TR2>;\n };\n};\n\nexport type LazyBundleMode = 'sync' | 'async';\n\n// loadScript a background section with `globalThis.globDynamicComponentEntry`\n// set to `entry` (restored after). The bundle's wrapper reads it once as\n// `g.globDynamicComponentEntry || '__Card__'`, so without this its modules — and\n// any nested `import()` it triggers — would resolve against the caller's host.\nfunction loadBackgroundBundle<T>(bundleName: string, entry: string): T {\n const g = globalThis as { globDynamicComponentEntry?: string | undefined };\n const previous = g.globDynamicComponentEntry;\n g.globDynamicComponentEntry = entry;\n try {\n return lynx.loadScript<T>(SECTION_BACKGROUND, { bundleName });\n } finally {\n g.globDynamicComponentEntry = previous;\n }\n}\n\n/**\n * Load dynamic component from source. Designed to be used with `lazy`.\n *\n * The `mode` is threaded in by the chunk-loading runtime from the\n * `import(..., { with: { mode } })` import attribute (see `lynx_acm`), so each\n * lazy import carries its own mode instead of relying on shared mutable state.\n * @param source - where dynamic component template.js locates\n * @param mode - `'sync'` (first-screen blocking) or `'async'` (default)\n * @returns\n * @public\n */\nexport const loadLazyBundle: <\n T extends { default: React.ComponentType<any> },\n>(source: string, mode?: LazyBundleMode, host?: string) => Promise<T> = /*#__PURE__*/ (() => {\n // Default to QueryComponent when `__LAZY_BUNDLE_FETCHER__` is missing —\n // older react-webpack-plugin builds don't stamp it and they predate\n // FetchBundle support, so falling through to QueryComponent is the only\n // safe behavior.\n const useFetchBundle = typeof __LAZY_BUNDLE_FETCHER__ !== 'undefined'\n && __LAZY_BUNDLE_FETCHER__ === 'FetchBundle';\n\n const impl = useFetchBundle\n ? loadLazyBundleWithFetchBundle\n : loadLazyBundleWithQueryComponent;\n\n lynx.loadLazyBundle = impl;\n\n function loadLazyBundleWithQueryComponent<\n T extends { default: React.ComponentType<any> },\n >(source: string, mode?: LazyBundleMode): Promise<T> {\n if (__LEPUS__) {\n const query = __QueryComponent(source);\n let result: T;\n try {\n result = query.evalResult as T;\n } catch (e) {\n // Here we cannot return a rejected promise\n // (which will eventually be an unhandled rejection and cause unnecessary redbox)\n // But we still need a object in shape of Promise\n // So we return a Promise which will never resolve or reject,\n // which fit our principle \"lepus run only once at first-screen\" better\n return new Promise(() => {});\n }\n const r: Promise<T> = Promise.resolve(result);\n // Why we should modify the implementation of `then`?\n // We should make it `sync` so lepus first-screen render can use result above instantly\n // We also should keep promise shape\n r.then = makeSyncThen(result);\n return r;\n } else if (__JS__) {\n if (__DEV__ && mode !== undefined) {\n throw new Error(\n `Lazy bundle import \\`mode: '${mode}'\\` requires FetchBundle, but the current build uses QueryComponent. `\n + `Set \\`engineVersion: '3.9'\\` (or higher) in \\`pluginReactLynx\\` to enable FetchBundle.`,\n );\n }\n const resolver = withSyncResolvers<T>();\n\n const callback: (result: { code: number; detail: { schema: string } }) => void = result => {\n const { code, detail } = result;\n if (code === 0) {\n const { schema } = detail;\n const exports = lynx.getApp().getDynamicComponentExports(schema);\n // `code === 0` means that the lazy bundle has been successfully parsed. However,\n // its javascript files may still fail to run, which would prevent the retrieval of the exports object.\n if (exports) {\n resolver.resolve(exports as T);\n return;\n }\n }\n const e = new Error('Lazy bundle load failed, schema: ' + result.detail.schema);\n // ES5 does not support new Error('message', { cause: 'detail' })\n // So we set cause using `.cause` assignment\n e.cause = JSON.stringify(result);\n resolver.reject(e);\n };\n if (typeof lynx.QueryComponent === 'function') {\n lynx.QueryComponent(source, callback);\n } else {\n lynx.getNativeLynx().QueryComponent!(source, callback);\n }\n\n if (resolver.result !== null) {\n const p = Promise.resolve(resolver.result);\n p.then = makeSyncThen(resolver.result) as Promise<Awaited<T>>['then'];\n return p;\n } else if (resolver.error === null) {\n return new Promise((_resolve, _reject) => {\n resolver.resolve = _resolve;\n resolver.reject = _reject;\n });\n } else {\n return Promise.reject(resolver.error);\n }\n }\n\n throw new Error('unreachable');\n }\n\n function loadLazyBundleWithFetchBundle<\n T extends { default: React.ComponentType<any> },\n >(source: string, mode?: LazyBundleMode, host?: string): Promise<T> {\n if (__MAIN_THREAD__) {\n if (mode !== 'sync') {\n // Fire the fetch and ignore the result so the request goes out early\n // and warms the native bundle cache; the background `async` path then\n // waits less. The main thread renders nothing here.\n try {\n lynx.fetchBundle(source, {});\n } catch {}\n return new Promise(() => {});\n }\n let response;\n try {\n response = lynx.fetchBundle(source, {}).wait(\n LYNX_LAZY_SYNC_TIMEOUT_SECONDS,\n );\n } catch {\n return new Promise(() => {});\n }\n if (!response || response.code !== 0) {\n return new Promise(() => {});\n }\n let result: T;\n try {\n result = lynx.loadScript<(entry: string) => T>(SECTION_MAIN_THREAD, {\n bundleName: response.url,\n })(source);\n const styleSheet = __LoadStyleSheet(SECTION_CSS, response.url);\n if (styleSheet !== null) {\n __AdoptStyleSheet(styleSheet);\n }\n } catch {\n return new Promise(() => {});\n }\n const r: Promise<T> = Promise.resolve(result);\n r.then = makeSyncThen(result);\n return r;\n } else if (__JS__) {\n const cached = fetchBundleBgCache.get(source);\n if (cached !== undefined) {\n const r: Promise<T> = Promise.resolve(cached as T);\n r.then = makeSyncThen(cached as T);\n return r;\n }\n if (mode === 'sync') {\n let response;\n try {\n response = lynx.fetchBundle(source, {}).wait(\n LYNX_LAZY_SYNC_TIMEOUT_SECONDS,\n );\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n if (!response || response.code !== 0) {\n console.error('Lazy bundle load failed', response);\n const e = new Error('Lazy bundle load failed, schema: ' + source);\n e.cause = JSON.stringify(response);\n return Promise.reject(e);\n }\n let result: T;\n try {\n result = loadBackgroundBundle<T>(response.url, source);\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n // A sync bundle that wasn't part of the first-screen main-thread render\n // still needs its main-thread section prepared on the MT (the\n // createSnapshot side effect), or a later patch referencing it hits\n // \"snapshot not found\". Runs synchronously — the bundle is already in\n // the native cache — just like the async path below.\n try {\n lynx.getNativeApp().callLepusMethod(\n PREPARE_LAZY_BUNDLE_MTS,\n { url: source, host },\n () => {},\n );\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n // Fully loaded and prepared — cache so repeat loads skip the work above.\n fetchBundleBgCache.set(source, result);\n const r: Promise<T> = Promise.resolve(result);\n r.then = makeSyncThen(result);\n return r;\n }\n\n // async (default)\n return new Promise<T>((resolve, reject) => {\n let handler;\n try {\n handler = lynx.fetchBundle(source, {});\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n return;\n }\n handler.then((response) => {\n if (!response || response.code !== 0) {\n console.error('Lazy bundle load failed', response);\n const e = new Error('Lazy bundle load failed, schema: ' + source);\n e.cause = JSON.stringify(response);\n reject(e);\n return;\n }\n let btsResult: T;\n try {\n btsResult = loadBackgroundBundle<T>(response.url, source);\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n return;\n }\n // Bundle is now in native cache, so MT's `.then` fires sync and\n // the whole prepare runs synchronously inside `Call`, meaning the\n // cb fires only after MT snapshots are registered.\n try {\n lynx.getNativeApp().callLepusMethod(\n PREPARE_LAZY_BUNDLE_MTS,\n { url: source, host },\n () => {\n // Fully loaded and MT-prepared — cache so repeat loads skip\n // the fetch / background eval / MT prepare above.\n fetchBundleBgCache.set(source, btsResult);\n resolve(btsResult);\n },\n );\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n }\n });\n });\n }\n\n throw new Error('unreachable');\n }\n\n return impl;\n})();\n\nfunction withSyncResolvers<T>() {\n 'background-only';\n\n const resolver: {\n result: T | null;\n error: Error | null;\n resolve(result: T): void;\n reject(error: Error): void;\n } = {\n resolve: (result: T): void => {\n resolver.result = result;\n },\n reject: (error: Error): void => {\n resolver.error = error;\n },\n result: null,\n error: null,\n };\n\n return resolver;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lazy-bundle.js","sourceRoot":"","sources":["../../../src/core/lynx/lazy-bundle.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,6EAA6E;AAC7E,oDAAoD;AACpD,6EAA6E;AAC7E,+CAA+C;AAC/C,4EAA4E;AAC5E,2DAA2D;AAC3D,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAC1C,MAAM,kBAAkB,GAAG,YAAY,CAAC;AACxC,MAAM,WAAW,GAAG,KAAK,CAAC;AAC1B,MAAM,8BAA8B,GAAG,CAAC,CAAC;AACzC,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAE5D,yEAAyE;AACzE,0EAA0E;AAC1E,+EAA+E;AAC/E,gFAAgF;AAChF,mDAAmD;AACnD,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAmB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY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AAK,GAAG,KAAK,CAAC;QACzB,CAAC;QACD,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,IAAI;KACZ,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\n// Inlined rather than imported from `snapshot/` so this `core/` module stays\n// free of runtime-backend dependencies (enforced by\n// `guardrails/snapshot-containment`). `PREPARE_LAZY_BUNDLE_MTS` must stay in\n// sync with `snapshot/lifecycle/constant.ts`'s\n// `LifecycleConstant.prepareLazyBundleMTS`, the lifecycle name the snapshot\n// backend registers the main-thread prepare handler under.\nconst SECTION_MAIN_THREAD = 'main-thread';\nconst SECTION_BACKGROUND = 'background';\nconst SECTION_CSS = 'CSS';\nconst LYNX_LAZY_SYNC_TIMEOUT_SECONDS = 5;\nconst PREPARE_LAZY_BUNDLE_MTS = 'rLynxPrepareLazyBundleMTS';\n\n// Background-thread dedup cache: a `source` whose FetchBundle load fully\n// succeeded maps to its exports, so a repeat load returns the same result\n// without re-fetching or re-triggering the main-thread prepare. Only populated\n// on success — a failed load stays out of the cache and can be retried, exactly\n// like `prepareLazyBundleMTS`'s main-thread cache.\nconst fetchBundleBgCache = new Map<string, unknown>();\n\n/**\n * To make code below works\n * const App1 = lazy(() => import(\"./x\").then(({App1}) => ({default: App1})))\n * const App2 = lazy(() => import(\"./x\").then(({App2}) => ({default: App2})))\n * @internal\n */\nexport const makeSyncThen = function<T>(result: T): Promise<T>['then'] {\n return function<TR1 = T, TR2 = never>(\n this: Promise<T>,\n onF?: ((value: T) => TR1 | PromiseLike<TR1>) | null,\n _onR?: ((reason: any) => TR2 | PromiseLike<TR2>) | null,\n ): Promise<TR1 | TR2> {\n if (onF) {\n let ret: TR1 | PromiseLike<TR1>;\n try {\n ret = onF(result);\n } catch (e) {\n // if (onR) {\n // return Promise.resolve(onR(e));\n // }\n return Promise.reject(e as Error);\n }\n\n if (ret && typeof (ret as PromiseLike<TR1>).then === 'function' /* `thenable` object */) {\n // lazy(() =>\n // import(\"./x\").then(() => new Promise(...))\n // )\n // Calling `then` and passing a callback is standard behavior\n // but in Lepus runtime the callback will never be called\n // So can be simplified to code below\n return ret as Promise<TR1>;\n\n // TODO(hongzhiyuan.hzy): Avoid warning that cannot be turned-off, so the warning is commented\n // lynx.reportError(\n // new Error(\n // 'You returned a Promise in promise-chain of lazy-bundle import (eg. `import(\"./x\").then(() => new Promise(...))`), which will cause related Component unavailable at first-screen, '\n // ),\n // { level: \"warning\" }\n // );\n }\n\n // The Lynx Promise polyfill shares resolved promises for primitive values.\n // Own this promise before replacing `then`, or an undefined callback\n // result would make unrelated Promise.resolve().then(...) calls synchronous.\n const p = new Promise<TR1>(resolve => resolve(ret));\n\n const then = makeSyncThen(ret as TR1);\n p.then = then as Promise<Awaited<TR1>>['then'];\n\n return p as Promise<TR1 | TR2>;\n }\n\n return this as Promise<TR1 | TR2>;\n };\n};\n\nexport type LazyBundleMode = 'sync' | 'async';\n\n// loadScript a background section with `globalThis.globDynamicComponentEntry`\n// set to `entry` (restored after). The bundle's wrapper reads it once as\n// `g.globDynamicComponentEntry || '__Card__'`, so without this its modules — and\n// any nested `import()` it triggers — would resolve against the caller's host.\nfunction loadBackgroundBundle<T>(bundleName: string, entry: string): T {\n const g = globalThis as { globDynamicComponentEntry?: string | undefined };\n const previous = g.globDynamicComponentEntry;\n g.globDynamicComponentEntry = entry;\n try {\n return lynx.loadScript<T>(SECTION_BACKGROUND, { bundleName });\n } finally {\n g.globDynamicComponentEntry = previous;\n }\n}\n\n/**\n * Load dynamic component from source. Designed to be used with `lazy`.\n *\n * The `mode` is threaded in by the chunk-loading runtime from the\n * `import(..., { with: { mode } })` import attribute (see `lynx_acm`), so each\n * lazy import carries its own mode instead of relying on shared mutable state.\n * @param source - where dynamic component template.js locates\n * @param mode - `'sync'` (first-screen blocking) or `'async'` (default)\n * @returns\n * @public\n */\nexport const loadLazyBundle: <\n T extends { default: React.ComponentType<any> },\n>(source: string, mode?: LazyBundleMode, host?: string) => Promise<T> = /*#__PURE__*/ (() => {\n // Default to QueryComponent when `__LAZY_BUNDLE_FETCHER__` is missing —\n // older react-webpack-plugin builds don't stamp it and they predate\n // FetchBundle support, so falling through to QueryComponent is the only\n // safe behavior.\n const useFetchBundle = typeof __LAZY_BUNDLE_FETCHER__ !== 'undefined'\n && __LAZY_BUNDLE_FETCHER__ === 'FetchBundle';\n\n const impl = useFetchBundle\n ? loadLazyBundleWithFetchBundle\n : loadLazyBundleWithQueryComponent;\n\n lynx.loadLazyBundle = impl;\n\n function loadLazyBundleWithQueryComponent<\n T extends { default: React.ComponentType<any> },\n >(source: string, mode?: LazyBundleMode): Promise<T> {\n if (__LEPUS__) {\n const query = __QueryComponent(source);\n let result: T;\n try {\n result = query.evalResult as T;\n } catch (e) {\n // Here we cannot return a rejected promise\n // (which will eventually be an unhandled rejection and cause unnecessary redbox)\n // But we still need a object in shape of Promise\n // So we return a Promise which will never resolve or reject,\n // which fit our principle \"lepus run only once at first-screen\" better\n return new Promise(() => {});\n }\n const r: Promise<T> = Promise.resolve(result);\n // Why we should modify the implementation of `then`?\n // We should make it `sync` so lepus first-screen render can use result above instantly\n // We also should keep promise shape\n r.then = makeSyncThen(result);\n return r;\n } else if (__JS__) {\n if (__DEV__ && mode !== undefined) {\n throw new Error(\n `Lazy bundle import \\`mode: '${mode}'\\` requires FetchBundle, but the current build uses QueryComponent. `\n + `Set \\`engineVersion: '3.9'\\` (or higher) in \\`pluginReactLynx\\` to enable FetchBundle.`,\n );\n }\n const resolver = withSyncResolvers<T>();\n\n const callback: (result: { code: number; detail: { schema: string } }) => void = result => {\n const { code, detail } = result;\n if (code === 0) {\n const { schema } = detail;\n const exports = lynx.getApp().getDynamicComponentExports(schema);\n // `code === 0` means that the lazy bundle has been successfully parsed. However,\n // its javascript files may still fail to run, which would prevent the retrieval of the exports object.\n if (exports) {\n resolver.resolve(exports as T);\n return;\n }\n }\n const e = new Error('Lazy bundle load failed, schema: ' + result.detail.schema);\n // ES5 does not support new Error('message', { cause: 'detail' })\n // So we set cause using `.cause` assignment\n e.cause = JSON.stringify(result);\n resolver.reject(e);\n };\n if (typeof lynx.QueryComponent === 'function') {\n lynx.QueryComponent(source, callback);\n } else {\n lynx.getNativeLynx().QueryComponent!(source, callback);\n }\n\n if (resolver.result !== null) {\n const p = Promise.resolve(resolver.result);\n p.then = makeSyncThen(resolver.result) as Promise<Awaited<T>>['then'];\n return p;\n } else if (resolver.error === null) {\n return new Promise((_resolve, _reject) => {\n resolver.resolve = _resolve;\n resolver.reject = _reject;\n });\n } else {\n return Promise.reject(resolver.error);\n }\n }\n\n throw new Error('unreachable');\n }\n\n function loadLazyBundleWithFetchBundle<\n T extends { default: React.ComponentType<any> },\n >(source: string, mode?: LazyBundleMode, host?: string): Promise<T> {\n if (__MAIN_THREAD__) {\n if (mode !== 'sync') {\n // Fire the fetch and ignore the result so the request goes out early\n // and warms the native bundle cache; the background `async` path then\n // waits less. The main thread renders nothing here.\n try {\n lynx.fetchBundle(source, {});\n } catch {}\n return new Promise(() => {});\n }\n let response;\n try {\n response = lynx.fetchBundle(source, {}).wait(\n LYNX_LAZY_SYNC_TIMEOUT_SECONDS,\n );\n } catch {\n return new Promise(() => {});\n }\n if (!response || response.code !== 0) {\n return new Promise(() => {});\n }\n let result: T;\n try {\n result = lynx.loadScript<(entry: string) => T>(SECTION_MAIN_THREAD, {\n bundleName: response.url,\n })(source);\n const styleSheet = __LoadStyleSheet(SECTION_CSS, response.url);\n if (styleSheet !== null) {\n __AdoptStyleSheet(styleSheet);\n }\n } catch {\n return new Promise(() => {});\n }\n const r: Promise<T> = Promise.resolve(result);\n r.then = makeSyncThen(result);\n return r;\n } else if (__JS__) {\n const cached = fetchBundleBgCache.get(source);\n if (cached !== undefined) {\n const r: Promise<T> = Promise.resolve(cached as T);\n r.then = makeSyncThen(cached as T);\n return r;\n }\n if (mode === 'sync') {\n let response;\n try {\n response = lynx.fetchBundle(source, {}).wait(\n LYNX_LAZY_SYNC_TIMEOUT_SECONDS,\n );\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n if (!response || response.code !== 0) {\n console.error('Lazy bundle load failed', response);\n const e = new Error('Lazy bundle load failed, schema: ' + source);\n e.cause = JSON.stringify(response);\n return Promise.reject(e);\n }\n let result: T;\n try {\n result = loadBackgroundBundle<T>(response.url, source);\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n // A sync bundle that wasn't part of the first-screen main-thread render\n // still needs its main-thread section prepared on the MT (the\n // createSnapshot side effect), or a later patch referencing it hits\n // \"snapshot not found\". Runs synchronously — the bundle is already in\n // the native cache — just like the async path below.\n try {\n lynx.getNativeApp().callLepusMethod(\n PREPARE_LAZY_BUNDLE_MTS,\n { url: source, host },\n () => {},\n );\n } catch (e) {\n return Promise.reject(e instanceof Error ? e : new Error(String(e)));\n }\n // Fully loaded and prepared — cache so repeat loads skip the work above.\n fetchBundleBgCache.set(source, result);\n const r: Promise<T> = Promise.resolve(result);\n r.then = makeSyncThen(result);\n return r;\n }\n\n // async (default)\n return new Promise<T>((resolve, reject) => {\n let handler;\n try {\n handler = lynx.fetchBundle(source, {});\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n return;\n }\n handler.then((response) => {\n if (!response || response.code !== 0) {\n console.error('Lazy bundle load failed', response);\n const e = new Error('Lazy bundle load failed, schema: ' + source);\n e.cause = JSON.stringify(response);\n reject(e);\n return;\n }\n let btsResult: T;\n try {\n btsResult = loadBackgroundBundle<T>(response.url, source);\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n return;\n }\n // Bundle is now in native cache, so MT's `.then` fires sync and\n // the whole prepare runs synchronously inside `Call`, meaning the\n // cb fires only after MT snapshots are registered.\n try {\n lynx.getNativeApp().callLepusMethod(\n PREPARE_LAZY_BUNDLE_MTS,\n { url: source, host },\n () => {\n // Fully loaded and MT-prepared — cache so repeat loads skip\n // the fetch / background eval / MT prepare above.\n fetchBundleBgCache.set(source, btsResult);\n resolve(btsResult);\n },\n );\n } catch (e) {\n reject(e instanceof Error ? e : new Error(String(e)));\n }\n });\n });\n }\n\n throw new Error('unreachable');\n }\n\n return impl;\n})();\n\nfunction withSyncResolvers<T>() {\n 'background only';\n\n const resolver: {\n result: T | null;\n error: Error | null;\n resolve(result: T): void;\n reject(error: Error): void;\n } = {\n resolve: (result: T): void => {\n resolver.result = result;\n },\n reject: (error: Error): void => {\n resolver.error = error;\n },\n result: null,\n error: null,\n };\n\n return resolver;\n}\n"]}
|
|
@@ -1,3 +1,127 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The interface you can extends so that the `defaultDataProcessor` parameter can be customized
|
|
3
|
+
*
|
|
4
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*
|
|
8
|
+
* @group Types
|
|
9
|
+
*/
|
|
10
|
+
export interface InitDataRaw {
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The interface you can extends so that the `defaultDataProcessor` returning value can be customized
|
|
14
|
+
*
|
|
15
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*
|
|
19
|
+
* @group Types
|
|
20
|
+
*/
|
|
21
|
+
export interface InitData {
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The data processors that registered with {@link Lynx.registerDataProcessors}.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
*
|
|
28
|
+
* Extending `dataProcessors` interface
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import type { DataProcessors as WellKnownDataProcessors } from '@lynx-js/react';
|
|
32
|
+
*
|
|
33
|
+
* declare module '@lynx-js/react' {
|
|
34
|
+
* interface DataProcessors extends WellKnownDataProcessors {
|
|
35
|
+
* foo(bar: string): number;
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* Then you can use `lynx.registerDataProcessors` with types.
|
|
41
|
+
*
|
|
42
|
+
* ```js
|
|
43
|
+
* lynx.registerDataProcessors({
|
|
44
|
+
* dataProcessors: {
|
|
45
|
+
* foo(bar) {
|
|
46
|
+
* return 1;
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* })
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*
|
|
54
|
+
* @group Types
|
|
55
|
+
*/
|
|
56
|
+
export interface DataProcessors {
|
|
57
|
+
/**
|
|
58
|
+
* Optional processor to override screen metrics used by the app
|
|
59
|
+
*
|
|
60
|
+
* @param metrics - The physical screen dimensions in pixels
|
|
61
|
+
*
|
|
62
|
+
* @returns New screen dimensions to be used by the app
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* lynx.registerDataProcessors({
|
|
68
|
+
* dataProcessors: {
|
|
69
|
+
* getScreenMetricsOverride: (metrics) => {
|
|
70
|
+
* // Force a specific aspect ratio
|
|
71
|
+
* return {
|
|
72
|
+
* width: metrics.width,
|
|
73
|
+
* height: metrics.width * (16/9)
|
|
74
|
+
* };
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
getScreenMetricsOverride?(metrics: {
|
|
81
|
+
/**
|
|
82
|
+
* The physical pixel width of the screen
|
|
83
|
+
*/
|
|
84
|
+
width: number;
|
|
85
|
+
/**
|
|
86
|
+
* The physical pixel height of the screen
|
|
87
|
+
*/
|
|
88
|
+
height: number;
|
|
89
|
+
}): {
|
|
90
|
+
width: number;
|
|
91
|
+
height: number;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Custom unknown data processors.
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
*
|
|
98
|
+
* You may extends the `DataProcessors` interface for better TypeScript types. See {@link DataProcessors}.
|
|
99
|
+
*/
|
|
100
|
+
[processorName: string]: (...args: any[]) => any;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Definition of DataProcessor(s)
|
|
104
|
+
* @public
|
|
105
|
+
*
|
|
106
|
+
* @group Types
|
|
107
|
+
*/
|
|
108
|
+
export interface DataProcessorDefinition {
|
|
109
|
+
/**
|
|
110
|
+
* You can custom input and output type of `defaultDataProcessor` by extends {@link InitDataRaw} and {@link InitData}
|
|
111
|
+
*
|
|
112
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
113
|
+
*
|
|
114
|
+
* @param rawInitData - initData passed from native code
|
|
115
|
+
* @returns
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
defaultDataProcessor?: (rawInitData: InitDataRaw) => InitData;
|
|
119
|
+
/**
|
|
120
|
+
* Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
dataProcessors?: DataProcessors;
|
|
125
|
+
}
|
|
2
126
|
export declare function isProcessingDefaultData(): boolean;
|
|
3
127
|
export declare function createProcessData(dataProcessorDefinition?: DataProcessorDefinition): (data: InitDataRaw, processorName?: string) => InitData | InitDataRaw;
|
|
@@ -1,3 +1,6 @@
|
|
|
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.
|
|
1
4
|
import { profileEnd, profileStart } from '../shared/profile.js';
|
|
2
5
|
// `true` only while the default data processor is running. `defaultDataProcessor` is
|
|
3
6
|
// invoked by the native side as a separate call *before* `renderPage` / `updatePage`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lynx-data-processors.js","sourceRoot":"","sources":["../../src/core/lynx-data-processors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lynx-data-processors.js","sourceRoot":"","sources":["../../src/core/lynx-data-processors.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA8HhE,qFAAqF;AACrF,sFAAsF;AACtF,qFAAqF;AACrF,mFAAmF;AACnF,oFAAoF;AACpF,2DAA2D;AAC3D,IAAI,qBAAqB,GAAG,KAAK,CAAC;AAElC,MAAM,UAAU,uBAAuB;IACrC,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,uBAAiD;IAEjD,IAAI,+BAA+B,GAAG,KAAK,CAAC;IAE5C,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE;QAC7B,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,YAAY,CAAC,aAAa,CAAC,CAAC;QAC9B,CAAC;QAED,IAAI,MAA8B,CAAC;QACnC,IAAI,CAAC;YACH,IAAI,aAAa,EAAE,CAAC;gBAClB,MAAM,GAAG,uBAAuB,EAAE,cAAc,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,IAAI,CAAa,IAAI,IAAI,CAAC;YAChG,CAAC;iBAAM,CAAC;gBACN,4EAA4E;gBAC5E,gFAAgF;gBAChF,qBAAqB,GAAG,IAAI,CAAC;gBAC7B,IAAI,CAAC;oBACH,MAAM,GAAG,uBAAuB,EAAE,oBAAoB,EAAE,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;gBACzE,CAAC;wBAAS,CAAC;oBACT,qBAAqB,GAAG,KAAK,CAAC;gBAChC,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAI,CAAC,WAAW,CAAC,KAAc,CAAC,CAAC;YACjC,MAAM,GAAG,EAAE,CAAC;QACd,CAAC;QAED,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,WAAW,EAAE,CAAC;YACtD,UAAU,EAAE,CAAC;QACf,CAAC;QAED,IAAI,CAAC,+BAA+B,EAAE,CAAC;YACrC,MAAM,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;QAED,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,+BAA+B,GAAG,IAAI,CAAC;QACzC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB,CAAC,MAA8B;IAC5D,iDAAiD;IACjD,MAAM,uBAAuB,GAAY,UAAU,CAAC,6BAA6B,CAAC;IAClF,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,GAAG;YACP,GAAG,MAAM;YACT,6BAA6B,EAAE,uBAAuB;SACvD,CAAC;IACJ,CAAC;IAED,sDAAsD;IACtD,IAAI,eAAe,EAAE,CAAC;QACpB,sDAAsD;QACtD,MAAM,mBAAmB,GAAY,0BAA0B,CAAC;QAChE,MAAM,GAAG;YACP,GAAG,MAAM;YACT,YAAY,EAAE,mBAAmB;SAClC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { profileEnd, profileStart } from '../shared/profile.js';\n\n/**\n * The interface you can extends so that the `defaultDataProcessor` parameter can be customized\n *\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @public\n *\n * @group Types\n */\nexport interface InitDataRaw {}\n/**\n * The interface you can extends so that the `defaultDataProcessor` returning value can be customized\n *\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @public\n *\n * @group Types\n */\nexport interface InitData {}\n\n/**\n * The data processors that registered with {@link Lynx.registerDataProcessors}.\n *\n * @example\n *\n * Extending `dataProcessors` interface\n *\n * ```ts\n * import type { DataProcessors as WellKnownDataProcessors } from '@lynx-js/react';\n *\n * declare module '@lynx-js/react' {\n * interface DataProcessors extends WellKnownDataProcessors {\n * foo(bar: string): number;\n * }\n * }\n * ```\n *\n * Then you can use `lynx.registerDataProcessors` with types.\n *\n * ```js\n * lynx.registerDataProcessors({\n * dataProcessors: {\n * foo(bar) {\n * return 1;\n * }\n * }\n * })\n * ```\n *\n * @public\n *\n * @group Types\n */\nexport interface DataProcessors {\n /**\n * Optional processor to override screen metrics used by the app\n *\n * @param metrics - The physical screen dimensions in pixels\n *\n * @returns New screen dimensions to be used by the app\n *\n * @example\n *\n * ```ts\n * lynx.registerDataProcessors({\n * dataProcessors: {\n * getScreenMetricsOverride: (metrics) => {\n * // Force a specific aspect ratio\n * return {\n * width: metrics.width,\n * height: metrics.width * (16/9)\n * };\n * }\n * }\n * });\n * ```\n */\n getScreenMetricsOverride?(metrics: {\n /**\n * The physical pixel width of the screen\n */\n width: number;\n /**\n * The physical pixel height of the screen\n */\n height: number;\n }): { width: number; height: number };\n\n /**\n * Custom unknown data processors.\n *\n * @remarks\n *\n * You may extends the `DataProcessors` interface for better TypeScript types. See {@link DataProcessors}.\n */\n [processorName: string]: (...args: any[]) => any;\n}\n\n/**\n * Definition of DataProcessor(s)\n * @public\n *\n * @group Types\n */\nexport interface DataProcessorDefinition {\n /**\n * You can custom input and output type of `defaultDataProcessor` by extends {@link InitDataRaw} and {@link InitData}\n *\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @param rawInitData - initData passed from native code\n * @returns\n * @public\n */\n defaultDataProcessor?: (rawInitData: InitDataRaw) => InitData;\n /**\n * Should be used with `lynx.registerDataProcessors`. See more examples at {@link Lynx.registerDataProcessors}.\n *\n * @public\n */\n dataProcessors?: DataProcessors;\n}\n\n// `true` only while the default data processor is running. `defaultDataProcessor` is\n// invoked by the native side as a separate call *before* `renderPage` / `updatePage`,\n// so a `markFirstScreenSyncReady()` made inside it must not sync the *previous* tree\n// (still latched ready) — a re-render of the data being processed is imminent. The\n// first-screen sync backend reads this to defer such a mark. Lives here (not in the\n// backend) so `core` does not depend on a runtime backend.\nlet processingDefaultData = false;\n\nexport function isProcessingDefaultData(): boolean {\n return processingDefaultData;\n}\n\nexport function createProcessData(\n dataProcessorDefinition?: DataProcessorDefinition,\n): (data: InitDataRaw, processorName?: string) => InitData | InitDataRaw {\n let hasDefaultDataProcessorExecuted = false;\n\n return (data, processorName) => {\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileStart('processData');\n }\n\n let result: InitData | InitDataRaw;\n try {\n if (processorName) {\n result = dataProcessorDefinition?.dataProcessors?.[processorName]?.(data) as InitData ?? data;\n } else {\n // a `markFirstScreenSyncReady()` made inside `defaultDataProcessor` must be\n // deferred until the data being processed renders (see `processingDefaultData`)\n processingDefaultData = true;\n try {\n result = dataProcessorDefinition?.defaultDataProcessor?.(data) ?? data;\n } finally {\n processingDefaultData = false;\n }\n }\n } catch (error: unknown) {\n lynx.reportError(error as Error);\n result = {};\n }\n\n if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {\n profileEnd();\n }\n\n if (!hasDefaultDataProcessorExecuted) {\n result = appendInitDataMetadata(result);\n }\n\n if (!processorName) {\n hasDefaultDataProcessorExecuted = true;\n }\n\n return result;\n };\n}\n\nfunction appendInitDataMetadata(result: InitData | InitDataRaw): InitData | InitDataRaw {\n // @ts-expect-error todo: add types to i18n logic\n const i18nResourceTranslation: unknown = globalThis.__I18N_RESOURCE_TRANSLATION__;\n if (i18nResourceTranslation) {\n result = {\n ...result,\n __I18N_RESOURCE_TRANSLATION__: i18nResourceTranslation,\n };\n }\n\n // @ts-expect-error todo: add types to __EXTRACT_STR__\n if (__EXTRACT_STR__) {\n // @ts-expect-error todo: add types to __EXTRACT_STR__\n const extractStrIdentFlag: unknown = __EXTRACT_STR_IDENT_FLAG__;\n result = {\n ...result,\n _EXTRACT_STR: extractStrIdentFlag,\n };\n }\n\n return result;\n}\n"]}
|
|
@@ -19,9 +19,9 @@ export function registerDestroyTask(task) {
|
|
|
19
19
|
}
|
|
20
20
|
export function runDestroyTasks() {
|
|
21
21
|
const tasks = Array.from(destroyTasks);
|
|
22
|
+
destroyTasks.clear();
|
|
22
23
|
for (const task of tasks) {
|
|
23
24
|
task();
|
|
24
25
|
}
|
|
25
|
-
destroyTasks.clear();
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=runtime-destroy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-destroy.js","sourceRoot":"","sources":["../../src/core/runtime-destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,MAAM,YAAY,GAAG,IAAI,GAAG,EAAe,CAAC;AAC5C,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,sFAAsF;AACtF,MAAM,UAAU,kBAAkB;IAChC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,SAAS,GAAG,IAAI,CAAC;IACjB,eAAe,EAAE,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAiB;IACnD,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,GAAG,EAAE;QACV,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,EAAE,CAAC;IACT,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime-destroy.js","sourceRoot":"","sources":["../../src/core/runtime-destroy.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,MAAM,YAAY,GAAG,IAAI,GAAG,EAAe,CAAC;AAC5C,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,sFAAsF;AACtF,MAAM,UAAU,kBAAkB;IAChC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,SAAS,GAAG,IAAI,CAAC;IACjB,eAAe,EAAE,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAiB;IACnD,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,GAAG,EAAE;QACV,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,YAAY,CAAC,KAAK,EAAE,CAAC;IACrB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,EAAE,CAAC;IACT,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\ntype DestroyTask = () => void;\n\nconst destroyTasks = new Set<DestroyTask>();\nlet destroyed = false;\n\n// Calls from a retired entry stay pending: settling them would run its continuations.\nexport function isRuntimeDestroyed(): boolean {\n return destroyed;\n}\n\nexport function destroyRuntime(): void {\n destroyed = true;\n runDestroyTasks();\n}\n\nexport function registerDestroyTask(task: DestroyTask): () => void {\n destroyTasks.add(task);\n return () => {\n destroyTasks.delete(task);\n };\n}\n\nexport function runDestroyTasks(): void {\n const tasks = Array.from(destroyTasks);\n destroyTasks.clear();\n for (const task of tasks) {\n task();\n }\n}\n"]}
|
package/runtime/lib/document.js
CHANGED
|
@@ -50,10 +50,5 @@ function setupDocument(_document = document) {
|
|
|
50
50
|
return i;
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
// if (__JS__) {
|
|
54
|
-
// setupBackgroundDocument();
|
|
55
|
-
// } else if (__LEPUS__) {
|
|
56
|
-
// setupDocument();
|
|
57
|
-
// }
|
|
58
53
|
export { document, setupBackgroundDocument, setupDocument };
|
|
59
54
|
//# sourceMappingURL=document.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAyBnE,MAAM,QAAQ,GAA4B,EAA6B,CAAC;AAExE;;;GAGG;AACH,SAAS,uBAAuB,CAAC,YAAqC,QAAQ;IAC5E,SAAS,CAAC,aAAa,GAAG,UAAS,IAAY;QAC7C,OAAO,IAAI,0BAA0B,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC;IACF,SAAS,CAAC,eAAe,GAAG,UAAS,GAAW,EAAE,IAAY,EAAE,GAAY;QAC1E,OAAO,IAAI,0BAA0B,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC;IACF,SAAS,CAAC,cAAc,GAAG,UAAS,IAAY;QAC9C,MAAM,CAAC,GAAG,IAAI,0BAA0B,CAAC,IAAyB,CAAC,CAAC;QACpE,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACxB,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE;YAC/B,GAAG,CAAC,CAAC;gBACH,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACvB,CAAC;SACF,CAAC,CAAC;QACH,OAAO,CAAC,CAAC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C,CAAC;IACX,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,aAAa,EAAE,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js';\nimport { SnapshotInstance } from './snapshot/snapshot/snapshot.js';\n\n/**\n * This module implements an Interface Adapter Pattern to integrate Preact's\n * rendering system with Lynx's custom Snapshot-based virtual DOM.\n *\n * It works by:\n * 1. Defining a minimal {@link Document}-like interface that Preact expects\n * 2. Implementing this interface to return our {@link Snapshot} instances\n * 3. Maintaining the same method signatures as the standard DOM API\n *\n * This allows Preact to build its virtual tree using our Snapshot system\n * without knowing it's not working with a real DOM.\n */\n\n/**\n * Defines the minimal document interface that Preact expects, depending on\n * which thread is running.\n */\ninterface SnapshotDocumentAdapter {\n createElement(type: string): BackgroundSnapshotInstance | SnapshotInstance;\n createElementNS(ns: string | null, type: string): BackgroundSnapshotInstance | SnapshotInstance;\n createTextNode(text: string): BackgroundSnapshotInstance | SnapshotInstance;\n}\n\nconst document: SnapshotDocumentAdapter = {} as SnapshotDocumentAdapter;\n\n/**\n * Sets up the document interface for the background thread.\n * All DOM operations are intercepted to create {@link BackgroundSnapshotInstance}.\n */\nfunction setupBackgroundDocument(_document: SnapshotDocumentAdapter = document): void {\n _document.createElement = function(type: string) {\n return new BackgroundSnapshotInstance(type);\n };\n _document.createElementNS = function(_ns: string, type: string, _is?: string) {\n return new BackgroundSnapshotInstance(type);\n };\n _document.createTextNode = function(text: string) {\n const i = new BackgroundSnapshotInstance(null as unknown as string);\n i.setAttribute(0, text);\n Object.defineProperty(i, 'data', {\n set(v) {\n i.setAttribute(0, v);\n },\n });\n return i;\n };\n}\n\n/**\n * Sets up the document interface for the main thread.\n * All DOM operations are intercepted to create {@link SnapshotInstance}.\n */\nfunction setupDocument(_document: SnapshotDocumentAdapter = document): void {\n _document.createElement = function(type: string) {\n const si = new SnapshotInstance(type);\n return si;\n };\n _document.createElementNS = function(_ns: string, type: string, _is?: string) {\n const si = new SnapshotInstance(type);\n return si;\n };\n _document.createTextNode = function(text: string) {\n const i = new SnapshotInstance(null as unknown as string);\n i.setAttribute(0, text);\n Object.defineProperty(i, 'data', {\n set(v) {\n i.setAttribute(0, v);\n },\n });\n return i;\n };\n}\n\nexport { document, setupBackgroundDocument, setupDocument };\n"]}
|
|
@@ -48,6 +48,15 @@ export function cancelElementTemplateRemovedSubtreeCleanup() {
|
|
|
48
48
|
}
|
|
49
49
|
scheduledRemovedSubtreeCleanupTimers.clear();
|
|
50
50
|
}
|
|
51
|
+
function cleanupFailedElementTemplateCommit(removedSubtreesAwaitingTeardown, delayedRunOnMainThreadPayload) {
|
|
52
|
+
if (delayedRunOnMainThreadPayload) {
|
|
53
|
+
dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));
|
|
54
|
+
}
|
|
55
|
+
clearPendingRefs();
|
|
56
|
+
resetGlobalCommitContext();
|
|
57
|
+
setPipeline(undefined);
|
|
58
|
+
scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);
|
|
59
|
+
}
|
|
51
60
|
function flushElementTemplateCommitChanges() {
|
|
52
61
|
const hasNativeOps = globalCommitContext.ops.length > 0;
|
|
53
62
|
const hasDelayedRunOnMainThread = delayedRunOnMainThreadData.length > 0;
|
|
@@ -98,12 +107,7 @@ function flushElementTemplateCommitChanges() {
|
|
|
98
107
|
});
|
|
99
108
|
}
|
|
100
109
|
catch (error) {
|
|
101
|
-
|
|
102
|
-
dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));
|
|
103
|
-
}
|
|
104
|
-
clearPendingRefs();
|
|
105
|
-
resetGlobalCommitContext();
|
|
106
|
-
scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);
|
|
110
|
+
cleanupFailedElementTemplateCommit(removedSubtreesAwaitingTeardown, delayedRunOnMainThreadPayload);
|
|
107
111
|
throw error;
|
|
108
112
|
}
|
|
109
113
|
lynx.getCoreContext().dispatchEvent(updateEvent);
|
|
@@ -131,12 +135,7 @@ export function installElementTemplateCommitHook() {
|
|
|
131
135
|
sendMTRefInitValueToMainThread();
|
|
132
136
|
}
|
|
133
137
|
catch (error) {
|
|
134
|
-
|
|
135
|
-
dropFunctionCallReturnIds(takeDelayedRunOnMainThreadData().map(data => data.resolveId));
|
|
136
|
-
clearPendingRefs();
|
|
137
|
-
resetGlobalCommitContext();
|
|
138
|
-
setPipeline(undefined);
|
|
139
|
-
scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);
|
|
138
|
+
cleanupFailedElementTemplateCommit(takeRemovedSubtreesForPostDispatchTeardown(), takeDelayedRunOnMainThreadData());
|
|
140
139
|
throw error;
|
|
141
140
|
}
|
|
142
141
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit-hook.js","sourceRoot":"","sources":["../../../src/element-template/background/commit-hook.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,0CAA0C,GAC3C,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,+BAA+B,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AACrG,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7G,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EACL,0BAA0B,EAC1B,8BAA8B,GAC/B,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EA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W,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,4CAA4C;IAC1D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;IACT,CAAC;IACD,SAAS,GAAG,KAAK,CAAC;IAClB,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC;QACjC,cAAc,GAAG,SAAS,CAAC;IAC7B,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { options } from 'preact';\n\nimport {\n globalCommitContext,\n resetGlobalCommitContext,\n takeRemovedSubtreesForPostDispatchTeardown,\n} from './commit-context.js';\nimport type { BackgroundElementTemplateInstance } from './instance.js';\nimport { clearElementTemplateRenderScope, resetElementTemplateRenderScope } from './render-scope.js';\nimport { globalPipelineOptions, markTiming, markTimingLegacy, setPipeline } from '../../core/performance.js';\nimport { getReloadVersion } from '../../core/reload-version.js';\nimport {\n delayedRunOnMainThreadData,\n takeDelayedRunOnMainThreadData,\n} from '../../core/thread-function-call/main-thread.js';\nimport { dropFunctionCallReturnIds } from '../../core/thread-function-call/return-value.js';\nimport { COMMIT } from '../../shared/render-constants.js';\nimport { hook, isEmptyObject } from '../../utils.js';\nimport { formatElementTemplateUpdateCommands } from '../debug/alog.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { sendMTRefInitValueToMainThread } from '../main-thread-ref-init-value.js';\nimport { clearPendingRefs, flushPendingRefs, hasPendingRefs } from '../prop-adapters/ref.js';\nimport { createElementTemplateUpdateEvent } from '../protocol/update-event.js';\n\nlet installed = false;\nlet previousCommit: typeof options[typeof COMMIT];\nlet hasHydrated = false;\nconst scheduledRemovedSubtreeCleanupTimers = /*#__PURE__*/ new Set<ReturnType<typeof setTimeout>>();\n\nexport function markElementTemplateHydrated(): void {\n hasHydrated = true;\n}\n\nexport function isElementTemplateHydrated(): boolean {\n return hasHydrated;\n}\n\nexport function resetElementTemplateCommitState(): void {\n hasHydrated = false;\n resetElementTemplateRenderScope();\n resetGlobalCommitContext();\n}\n\nexport function scheduleElementTemplateRemovedSubtreeCleanup(\n removedSubtreesAwaitingTeardown: BackgroundElementTemplateInstance[],\n): void {\n if (removedSubtreesAwaitingTeardown.length === 0) {\n return;\n }\n const timer = setTimeout(() => {\n scheduledRemovedSubtreeCleanupTimers.delete(timer);\n for (const root of removedSubtreesAwaitingTeardown) {\n root.releaseDetachedSubtreeFromManager();\n }\n }, 10000);\n scheduledRemovedSubtreeCleanupTimers.add(timer);\n}\n\nexport function cancelElementTemplateRemovedSubtreeCleanup(): void {\n for (const timer of scheduledRemovedSubtreeCleanupTimers) {\n clearTimeout(timer);\n }\n scheduledRemovedSubtreeCleanupTimers.clear();\n}\n\nfunction flushElementTemplateCommitChanges(): void {\n const hasNativeOps = globalCommitContext.ops.length > 0;\n const hasDelayedRunOnMainThread = delayedRunOnMainThreadData.length > 0;\n const hasUpdatePayload = hasNativeOps\n || !isEmptyObject(globalCommitContext.flushOptions)\n || hasDelayedRunOnMainThread;\n const removedSubtreesAwaitingTeardown = hasNativeOps ? takeRemovedSubtreesForPostDispatchTeardown() : [];\n if (hasUpdatePayload) {\n markTimingLegacy('updateDiffVdomEnd');\n markTiming('diffVdomEnd');\n\n if (__PROFILE__) {\n profileStart('ReactLynx::commitChanges');\n }\n markTiming('packChangesStart');\n if (globalPipelineOptions) {\n globalCommitContext.flushOptions.pipelineOptions = globalPipelineOptions;\n }\n markTiming('packChangesEnd');\n if (globalPipelineOptions) {\n setPipeline(undefined);\n }\n if (__PROFILE__) {\n profileEnd();\n }\n\n if (!hasNativeOps && !hasDelayedRunOnMainThread) {\n globalCommitContext.flushOptions.emptyPatch = true;\n }\n\n const delayedRunOnMainThreadPayload = hasDelayedRunOnMainThread\n ? takeDelayedRunOnMainThreadData()\n : undefined;\n\n let updateEvent: ReturnType<typeof createElementTemplateUpdateEvent>;\n try {\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] ElementTemplate BTS -> MTS update:\\n'\n + JSON.stringify(\n {\n ops: formatElementTemplateUpdateCommands(globalCommitContext.ops),\n flushOptions: globalCommitContext.flushOptions,\n flowIds: globalCommitContext.flowIds,\n delayedRunOnMainThreadDataCount: delayedRunOnMainThreadPayload?.length,\n },\n null,\n 2,\n ),\n );\n }\n\n updateEvent = createElementTemplateUpdateEvent({\n ops: globalCommitContext.ops,\n flushOptions: globalCommitContext.flushOptions,\n reloadVersion: getReloadVersion(),\n flowIds: globalCommitContext.flowIds,\n delayedRunOnMainThreadData: delayedRunOnMainThreadPayload,\n });\n } catch (error) {\n if (delayedRunOnMainThreadPayload) {\n dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));\n }\n clearPendingRefs();\n resetGlobalCommitContext();\n scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);\n throw error;\n }\n\n lynx.getCoreContext().dispatchEvent(updateEvent);\n }\n // When native ops exist, patch first so a newly attached ref observes the\n // committed native state. Ref-only commits still flush through this path.\n flushPendingRefs();\n resetGlobalCommitContext();\n // Match Snapshot's cleanup boundary: start the delayed teardown only\n // after the bridge dispatch, so background JS objects are not torn down\n // before main-thread detach observes the same commit.\n scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);\n}\n\nexport function installElementTemplateCommitHook(): void {\n if (installed) {\n return;\n }\n installed = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n previousCommit = options[COMMIT];\n\n hook(options, COMMIT, (originalCommit, vnode, commitQueue) => {\n if (__BACKGROUND__) {\n clearElementTemplateRenderScope();\n try {\n sendMTRefInitValueToMainThread();\n } catch (error) {\n const removedSubtreesAwaitingTeardown = takeRemovedSubtreesForPostDispatchTeardown();\n dropFunctionCallReturnIds(takeDelayedRunOnMainThreadData().map(data => data.resolveId));\n clearPendingRefs();\n resetGlobalCommitContext();\n setPipeline(undefined);\n scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);\n throw error;\n }\n }\n\n if (__BACKGROUND__ && !hasHydrated && hasPendingRefs()) {\n // User effects can run before ET hydrate arrives, so ordinary refs must be\n // attached on the background commit even though native UI ops are delayed.\n flushPendingRefs();\n } else if (\n __BACKGROUND__ && hasHydrated\n && (\n globalCommitContext.ops.length > 0\n || !isEmptyObject(globalCommitContext.flushOptions)\n || hasPendingRefs()\n || delayedRunOnMainThreadData.length > 0\n )\n ) {\n flushElementTemplateCommitChanges();\n }\n\n originalCommit?.(vnode, commitQueue);\n });\n}\n\n/**\n * Restores the commit option replaced by\n * {@link installElementTemplateCommitHook} so tests can clean up the global\n * Preact `options` object. Assumes the matching install was the most recent\n * commit-option replacement; the snapshot and ElementTemplate runtimes are\n * separate entrypoints and never install their commit hooks in the same\n * context.\n */\nexport function uninstallElementTemplateCommitHookForTesting(): void {\n if (!installed) {\n return;\n }\n installed = false;\n if (previousCommit) {\n options[COMMIT] = previousCommit;\n previousCommit = undefined;\n } else {\n delete options[COMMIT];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"commit-hook.js","sourceRoot":"","sources":["../../../src/element-template/background/commit-hook.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,0CAA0C,GAC3C,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,+BAA+B,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AACrG,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7G,OA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G,CAAC,CACzC,EACD,CAAC;YACD,iCAAiC,EAAE,CAAC;QACtC,CAAC;QAED,cAAc,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,4CAA4C;IAC1D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;IACT,CAAC;IACD,SAAS,GAAG,KAAK,CAAC;IAClB,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC;QACjC,cAAc,GAAG,SAAS,CAAC;IAC7B,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { options } from 'preact';\n\nimport {\n globalCommitContext,\n resetGlobalCommitContext,\n takeRemovedSubtreesForPostDispatchTeardown,\n} from './commit-context.js';\nimport type { BackgroundElementTemplateInstance } from './instance.js';\nimport { clearElementTemplateRenderScope, resetElementTemplateRenderScope } from './render-scope.js';\nimport { globalPipelineOptions, markTiming, markTimingLegacy, setPipeline } from '../../core/performance.js';\nimport { getReloadVersion } from '../../core/reload-version.js';\nimport {\n delayedRunOnMainThreadData,\n takeDelayedRunOnMainThreadData,\n} from '../../core/thread-function-call/main-thread.js';\nimport { dropFunctionCallReturnIds } from '../../core/thread-function-call/return-value.js';\nimport { COMMIT } from '../../shared/render-constants.js';\nimport { hook, isEmptyObject } from '../../utils.js';\nimport { formatElementTemplateUpdateCommands } from '../debug/alog.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { sendMTRefInitValueToMainThread } from '../main-thread-ref-init-value.js';\nimport { clearPendingRefs, flushPendingRefs, hasPendingRefs } from '../prop-adapters/ref.js';\nimport { createElementTemplateUpdateEvent } from '../protocol/update-event.js';\n\nlet installed = false;\nlet previousCommit: typeof options[typeof COMMIT];\nlet hasHydrated = false;\nconst scheduledRemovedSubtreeCleanupTimers = /*#__PURE__*/ new Set<ReturnType<typeof setTimeout>>();\n\nexport function markElementTemplateHydrated(): void {\n hasHydrated = true;\n}\n\nexport function isElementTemplateHydrated(): boolean {\n return hasHydrated;\n}\n\nexport function resetElementTemplateCommitState(): void {\n hasHydrated = false;\n resetElementTemplateRenderScope();\n resetGlobalCommitContext();\n}\n\nexport function scheduleElementTemplateRemovedSubtreeCleanup(\n removedSubtreesAwaitingTeardown: BackgroundElementTemplateInstance[],\n): void {\n if (removedSubtreesAwaitingTeardown.length === 0) {\n return;\n }\n const timer = setTimeout(() => {\n scheduledRemovedSubtreeCleanupTimers.delete(timer);\n for (const root of removedSubtreesAwaitingTeardown) {\n root.releaseDetachedSubtreeFromManager();\n }\n }, 10000);\n scheduledRemovedSubtreeCleanupTimers.add(timer);\n}\n\nexport function cancelElementTemplateRemovedSubtreeCleanup(): void {\n for (const timer of scheduledRemovedSubtreeCleanupTimers) {\n clearTimeout(timer);\n }\n scheduledRemovedSubtreeCleanupTimers.clear();\n}\n\nfunction cleanupFailedElementTemplateCommit(\n removedSubtreesAwaitingTeardown: BackgroundElementTemplateInstance[],\n delayedRunOnMainThreadPayload: readonly { resolveId: number }[] | undefined,\n): void {\n if (delayedRunOnMainThreadPayload) {\n dropFunctionCallReturnIds(delayedRunOnMainThreadPayload.map(data => data.resolveId));\n }\n clearPendingRefs();\n resetGlobalCommitContext();\n setPipeline(undefined);\n scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);\n}\n\nfunction flushElementTemplateCommitChanges(): void {\n const hasNativeOps = globalCommitContext.ops.length > 0;\n const hasDelayedRunOnMainThread = delayedRunOnMainThreadData.length > 0;\n const hasUpdatePayload = hasNativeOps\n || !isEmptyObject(globalCommitContext.flushOptions)\n || hasDelayedRunOnMainThread;\n const removedSubtreesAwaitingTeardown = hasNativeOps ? takeRemovedSubtreesForPostDispatchTeardown() : [];\n if (hasUpdatePayload) {\n markTimingLegacy('updateDiffVdomEnd');\n markTiming('diffVdomEnd');\n\n if (__PROFILE__) {\n profileStart('ReactLynx::commitChanges');\n }\n markTiming('packChangesStart');\n if (globalPipelineOptions) {\n globalCommitContext.flushOptions.pipelineOptions = globalPipelineOptions;\n }\n markTiming('packChangesEnd');\n if (globalPipelineOptions) {\n setPipeline(undefined);\n }\n if (__PROFILE__) {\n profileEnd();\n }\n\n if (!hasNativeOps && !hasDelayedRunOnMainThread) {\n globalCommitContext.flushOptions.emptyPatch = true;\n }\n\n const delayedRunOnMainThreadPayload = hasDelayedRunOnMainThread\n ? takeDelayedRunOnMainThreadData()\n : undefined;\n\n let updateEvent: ReturnType<typeof createElementTemplateUpdateEvent>;\n try {\n if (typeof __ALOG__ !== 'undefined' && __ALOG__) {\n console.alog?.(\n '[ReactLynxDebug] ElementTemplate BTS -> MTS update:\\n'\n + JSON.stringify(\n {\n ops: formatElementTemplateUpdateCommands(globalCommitContext.ops),\n flushOptions: globalCommitContext.flushOptions,\n flowIds: globalCommitContext.flowIds,\n delayedRunOnMainThreadDataCount: delayedRunOnMainThreadPayload?.length,\n },\n null,\n 2,\n ),\n );\n }\n\n updateEvent = createElementTemplateUpdateEvent({\n ops: globalCommitContext.ops,\n flushOptions: globalCommitContext.flushOptions,\n reloadVersion: getReloadVersion(),\n flowIds: globalCommitContext.flowIds,\n delayedRunOnMainThreadData: delayedRunOnMainThreadPayload,\n });\n } catch (error) {\n cleanupFailedElementTemplateCommit(removedSubtreesAwaitingTeardown, delayedRunOnMainThreadPayload);\n throw error;\n }\n\n lynx.getCoreContext().dispatchEvent(updateEvent);\n }\n // When native ops exist, patch first so a newly attached ref observes the\n // committed native state. Ref-only commits still flush through this path.\n flushPendingRefs();\n resetGlobalCommitContext();\n // Match Snapshot's cleanup boundary: start the delayed teardown only\n // after the bridge dispatch, so background JS objects are not torn down\n // before main-thread detach observes the same commit.\n scheduleElementTemplateRemovedSubtreeCleanup(removedSubtreesAwaitingTeardown);\n}\n\nexport function installElementTemplateCommitHook(): void {\n if (installed) {\n return;\n }\n installed = true;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n previousCommit = options[COMMIT];\n\n hook(options, COMMIT, (originalCommit, vnode, commitQueue) => {\n if (__BACKGROUND__) {\n clearElementTemplateRenderScope();\n try {\n sendMTRefInitValueToMainThread();\n } catch (error) {\n cleanupFailedElementTemplateCommit(\n takeRemovedSubtreesForPostDispatchTeardown(),\n takeDelayedRunOnMainThreadData(),\n );\n throw error;\n }\n }\n\n if (__BACKGROUND__ && !hasHydrated && hasPendingRefs()) {\n // User effects can run before ET hydrate arrives, so ordinary refs must be\n // attached on the background commit even though native UI ops are delayed.\n flushPendingRefs();\n } else if (\n __BACKGROUND__ && hasHydrated\n && (\n globalCommitContext.ops.length > 0\n || !isEmptyObject(globalCommitContext.flushOptions)\n || hasPendingRefs()\n || delayedRunOnMainThreadData.length > 0\n )\n ) {\n flushElementTemplateCommitChanges();\n }\n\n originalCommit?.(vnode, commitQueue);\n });\n}\n\n/**\n * Restores the commit option replaced by\n * {@link installElementTemplateCommitHook} so tests can clean up the global\n * Preact `options` object. Assumes the matching install was the most recent\n * commit-option replacement; the snapshot and ElementTemplate runtimes are\n * separate entrypoints and never install their commit hooks in the same\n * context.\n */\nexport function uninstallElementTemplateCommitHookForTesting(): void {\n if (!installed) {\n return;\n }\n installed = false;\n if (previousCommit) {\n options[COMMIT] = previousCommit;\n previousCommit = undefined;\n } else {\n delete options[COMMIT];\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
import type { DataProcessorDefinition } from '../../lynx-
|
|
2
|
+
import type { DataProcessorDefinition } from '../../core/lynx-data-processors.js';
|
|
3
3
|
/**
|
|
4
4
|
* The default root exported by `@lynx-js/react` for you to render a JSX
|
|
5
5
|
* @public
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.js","sourceRoot":"","sources":["../../../src/element-template/client/root.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"root.js","sourceRoot":"","sources":["../../../src/element-template/client/root.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAkC1D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,IAAI,GAAS;IACxB,MAAM,EAAE,CAAC,GAAc,EAAQ,EAAE;QAC/B,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC;QACnB,IAAI,cAAc,EAAE,CAAC;YACnB,IAAI,WAAW,EAAE,CAAC;gBAChB,YAAY,CAAC,6BAA6B,CAAC,CAAC;YAC9C,CAAC;YACD,MAAM,CAAC,GAAqB,EAAE,MAAkC,CAAC,CAAC;YAClE,IAAI,WAAW,EAAE,CAAC;gBAChB,UAAU,EAAE,CAAC;YACf,CAAC;QACH,CAAC;IACH,CAAC;IACD,sBAAsB,EAAE,CAAC,uBAAiD,EAAQ,EAAE;QAClF,IAAI,CAAC,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;IACvD,CAAC;CACF,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\nimport type { ComponentChild, ContainerNode } from 'preact';\nimport { render } from 'preact';\nimport type { ReactNode } from 'react';\n\nimport type { DataProcessorDefinition } from '../../core/lynx-data-processors.js';\nimport { profileEnd, profileStart } from '../debug/profile.js';\nimport { __root } from '../runtime/page/root-instance.js';\n\n/**\n * The default root exported by `@lynx-js/react` for you to render a JSX\n * @public\n */\nexport interface Root {\n /**\n * Use this API to pass in your JSX to render\n *\n * @example\n *\n * ```ts\n * import { root } from \"@lynx-js/react\"\n *\n * function App() {\n * // Your app\n * return <view>...</view>\n * }\n *\n * root.render(<App/>);\n * ```\n *\n * @public\n */\n render: (jsx: ReactNode) => void;\n /**\n * {@inheritDoc Lynx.registerDataProcessors}\n * @deprecated use {@link Lynx.registerDataProcessors | lynx.registerDataProcessors} instead\n * @public\n */\n registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition) => void;\n}\n\n/**\n * The default and only root of ReactLynx for you to render JSX\n * @example\n * ```ts\n * import { root } from \"@lynx-js/react\"\n * ```\n *\n * @public\n */\nexport const root: Root = {\n render: (jsx: ReactNode): void => {\n __root.__jsx = jsx;\n if (__BACKGROUND__) {\n if (__PROFILE__) {\n profileStart('ReactLynx::renderBackground');\n }\n render(jsx as ComponentChild, __root as unknown as ContainerNode);\n if (__PROFILE__) {\n profileEnd();\n }\n }\n },\n registerDataProcessors: (dataProcessorDefinition?: DataProcessorDefinition): void => {\n lynx.registerDataProcessors(dataProcessorDefinition);\n },\n};\n"]}
|
|
@@ -4,7 +4,7 @@ import type { Consumer, FC, ReactNode } from 'react';
|
|
|
4
4
|
import type { GlobalProps } from '../core/globalProps.js';
|
|
5
5
|
import { useLynxGlobalEventListener } from '../core/hooks/useLynxGlobalEventListener.js';
|
|
6
6
|
import { withInitDataInState } from '../core/initData.js';
|
|
7
|
-
import type { InitData } from '../lynx-
|
|
7
|
+
import type { InitData } from '../core/lynx-data-processors.js';
|
|
8
8
|
import './native/index.js';
|
|
9
9
|
export { Component, createContext } from 'preact';
|
|
10
10
|
export { PureComponent } from 'preact/compat';
|
|
@@ -31,4 +31,4 @@ export { MainThreadRef, useMainThreadRef } from '../core/main-thread-ref.js';
|
|
|
31
31
|
export { defineMainThreadObjectType, useMainThreadObject } from '../core/main-thread-object.js';
|
|
32
32
|
export type { GlobalProps } from '../core/globalProps.js';
|
|
33
33
|
export type { MainThreadObjectHandle, MainThreadObjectType, MainThreadObjectTypeDefinition, } from '../core/main-thread-object.js';
|
|
34
|
-
export type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw } from '../lynx-
|
|
34
|
+
export type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw } from '../core/lynx-data-processors.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/element-template/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EACL,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,aAAa,EACb,SAAS,EACT,UAAU,EACV,cAAc,EACd,IAAI,EACJ,IAAI,EACJ,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,WAAW,EACX,UAAU,EACV,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,UAAU,EACV,MAAM,EACN,QAAQ,GACT,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,mBAAmB,CAAC;AAE3B,sBAAsB,EAAE,CAAC;AAEzB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,cAAc,sBAAsB,CAAC;AAErC;;GAEG;AACH,eAAe;IACb,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,SAAS;IACT,eAAe;IACf,MAAM;IACN,mBAAmB;IACnB,OAAO;IACP,WAAW;IACX,UAAU;IACV,aAAa;IACb,oBAAoB;IAEpB,aAAa;IACb,SAAS;IAC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AU,EAAE,CAAC;AAEhB,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC/B,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAEtC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport './runtime-marker.js';\nimport {\n Children,\n Component,\n Fragment,\n PureComponent,\n Suspense,\n cloneElement,\n createContext,\n createElement,\n createRef,\n forwardRef,\n isValidElement,\n lazy,\n memo,\n useSyncExternalStore,\n} from 'preact/compat';\nimport type { Consumer, FC, ReactNode } from 'react';\n\nimport {\n useCallback,\n useContext,\n useDebugValue,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n} from '@lynx-js/react/hooks';\n\nimport { installComponentCompat } from '../core/component.js';\nimport { createGlobalProps } from '../core/globalProps.js';\nimport type { GlobalProps } from '../core/globalProps.js';\nimport { useLynxGlobalEventListener } from '../core/hooks/useLynxGlobalEventListener.js';\nimport { factory, withInitDataInState } from '../core/initData.js';\nimport type { InitData } from '../lynx-
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/element-template/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EACL,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,aAAa,EACb,SAAS,EACT,UAAU,EACV,c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ensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport './runtime-marker.js';\nimport {\n Children,\n Component,\n Fragment,\n PureComponent,\n Suspense,\n cloneElement,\n createContext,\n createElement,\n createRef,\n forwardRef,\n isValidElement,\n lazy,\n memo,\n useSyncExternalStore,\n} from 'preact/compat';\nimport type { Consumer, FC, ReactNode } from 'react';\n\nimport {\n useCallback,\n useContext,\n useDebugValue,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n} from '@lynx-js/react/hooks';\n\nimport { installComponentCompat } from '../core/component.js';\nimport { createGlobalProps } from '../core/globalProps.js';\nimport type { GlobalProps } from '../core/globalProps.js';\nimport { useLynxGlobalEventListener } from '../core/hooks/useLynxGlobalEventListener.js';\nimport { factory, withInitDataInState } from '../core/initData.js';\nimport type { InitData } from '../core/lynx-data-processors.js';\nimport './native/index.js';\n\ninstallComponentCompat();\n\nexport { Component, createContext } from 'preact';\nexport { PureComponent } from 'preact/compat';\nexport * from '@lynx-js/react/hooks';\n\n/**\n * @internal\n */\nexport default {\n // hooks\n useState,\n useReducer,\n useEffect,\n useLayoutEffect,\n useRef,\n useImperativeHandle,\n useMemo,\n useCallback,\n useContext,\n useDebugValue,\n useSyncExternalStore,\n\n createContext,\n createRef,\n Fragment,\n isValidElement,\n Children,\n Component,\n PureComponent,\n memo,\n forwardRef,\n Suspense,\n lazy,\n createElement,\n};\n\nexport {\n Children,\n createRef,\n Fragment,\n isValidElement,\n memo,\n forwardRef,\n Suspense,\n lazy,\n createElement,\n cloneElement,\n useSyncExternalStore,\n};\n\nconst _InitData = /* @__PURE__ */ factory<InitData>(\n {\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n },\n '__initData',\n 'onDataChanged',\n);\n\n// @ts-expect-error make preact and react types work\nexport const InitDataProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _InitData.Provider();\n// @ts-expect-error make preact and react types work\nexport const InitDataConsumer: Consumer<InitData> = /* @__PURE__ */ _InitData.Consumer();\nexport const useInitData: () => InitData = /* @__PURE__ */ _InitData.use();\nexport const useInitDataChanged: (callback: (data: InitData) => void) => void = /* @__PURE__ */ _InitData.useChanged();\n\nconst _GlobalProps = /* @__PURE__ */ createGlobalProps<GlobalProps>({\n createContext,\n useState,\n createElement,\n useLynxGlobalEventListener,\n});\n\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsProvider: FC<{ children?: ReactNode | undefined }> = /* @__PURE__ */ _GlobalProps.Provider();\n// @ts-expect-error make preact and react types work\nexport const GlobalPropsConsumer: Consumer<GlobalProps> = /* @__PURE__ */ _GlobalProps.Consumer();\nexport const useGlobalProps: () => GlobalProps = /* @__PURE__ */ _GlobalProps.use();\nexport const useGlobalPropsChanged: (callback: (data: GlobalProps) => void) => void = /* @__PURE__ */ _GlobalProps\n .useChanged();\n\nexport { withInitDataInState };\nexport { useLynxGlobalEventListener };\n\nexport * from './client/root.js';\nexport { runOnBackground } from './runtime/template/main-thread-background-function.js';\nexport { runOnMainThread } from './runtime/template/main-thread-function.js';\nexport { MainThreadRef, useMainThreadRef } from '../core/main-thread-ref.js';\nexport { defineMainThreadObjectType, useMainThreadObject } from '../core/main-thread-object.js';\n\nexport type { GlobalProps } from '../core/globalProps.js';\nexport type {\n MainThreadObjectHandle,\n MainThreadObjectType,\n MainThreadObjectTypeDefinition,\n} from '../core/main-thread-object.js';\nexport type { DataProcessorDefinition, DataProcessors, InitData, InitDataRaw } from '../core/lynx-data-processors.js';\n"]}
|
|
@@ -9,9 +9,9 @@ export { registerRuntimeVersion, getRuntimeVersion } from '../core/lynx/runtime-
|
|
|
9
9
|
export { RUNTIME_BACKEND_ELEMENT_TEMPLATE, RUNTIME_BACKEND_SNAPSHOT, registerRuntimeBackend, } from '../core/lynx/runtime-backend.js';
|
|
10
10
|
export { withInitDataInState } from '../core/initData.js';
|
|
11
11
|
export { wrapWithLynxComponent } from '../core/compat/lynxComponent.js';
|
|
12
|
+
export { loadLazyBundle } from '../core/lynx/lazy-bundle.js';
|
|
12
13
|
export { transformToWorklet } from './runtime/template/main-thread-background-function.js';
|
|
13
14
|
export { captureMainThreadObject } from '../core/capture-main-thread-object.js';
|
|
14
|
-
export declare function registerWorkletOnBackground(_type: string, _hash: string, _fn: (...args: unknown[]) => unknown): void;
|
|
15
15
|
export { __etAttrPlanMap, adaptEventAttrSlot, adaptMTEventAttrSlot, adaptMTRefAttrSlot, adaptRefAttrSlot, adaptSpreadAttrSlot, } from './runtime/template/attr-slot-plan.js';
|
|
16
16
|
export { __ElementTemplatePage } from './runtime/page/authored-page.js';
|
|
17
17
|
export { __etHost } from './runtime/render/host.js';
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
// import { Suspense, createElement, lazy } from 'preact/compat';
|
|
5
|
-
// import type { FC } from 'react';
|
|
6
4
|
import './runtime-marker.js';
|
|
7
5
|
import './native/index.js';
|
|
8
|
-
// import { factory as factory2 } from '../compat/componentIs.js';
|
|
9
|
-
// import { useMemo } from '../core/hooks/react.js';
|
|
10
6
|
import { __root } from './runtime/page/root-instance.js';
|
|
11
7
|
/**
|
|
12
8
|
* @internal kept only to fail fast when stale internal imports leak into the
|
|
@@ -30,18 +26,9 @@ export { registerRuntimeVersion, getRuntimeVersion } from '../core/lynx/runtime-
|
|
|
30
26
|
export { RUNTIME_BACKEND_ELEMENT_TEMPLATE, RUNTIME_BACKEND_SNAPSHOT, registerRuntimeBackend, } from '../core/lynx/runtime-backend.js';
|
|
31
27
|
export { withInitDataInState } from '../core/initData.js';
|
|
32
28
|
export { wrapWithLynxComponent } from '../core/compat/lynxComponent.js';
|
|
33
|
-
/**
|
|
34
|
-
* @internal a polyfill for <component is=? />
|
|
35
|
-
*/
|
|
36
|
-
// export const __ComponentIsPolyfill: FC<{ is: string }> = /* @__PURE__ */ factory2(
|
|
37
|
-
// // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
38
|
-
// { Suspense, lazy, createElement, useMemo } as any,
|
|
39
|
-
// loadLazyBundle,
|
|
40
|
-
// );
|
|
41
29
|
export { loadLazyBundle } from '../core/lynx/lazy-bundle.js';
|
|
42
30
|
export { transformToWorklet } from './runtime/template/main-thread-background-function.js';
|
|
43
31
|
export { captureMainThreadObject } from '../core/capture-main-thread-object.js';
|
|
44
|
-
export function registerWorkletOnBackground(_type, _hash, _fn) { }
|
|
45
32
|
export { __etAttrPlanMap, adaptEventAttrSlot, adaptMTEventAttrSlot, adaptMTRefAttrSlot, adaptRefAttrSlot, adaptSpreadAttrSlot, } from './runtime/template/attr-slot-plan.js';
|
|
46
33
|
export { __ElementTemplatePage } from './runtime/page/authored-page.js';
|
|
47
34
|
export { __etHost } from './runtime/render/host.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/element-template/internal.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/element-template/internal.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D,OAAO,qBAAqB,CAAC;AAC7B,OAAO,mBAAmB,CAAC;AAE3B,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAEzD;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACR;IAAnB,YAAmB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAC7B,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAC;IAC9F,CAAC;CACF;AAED,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,OAAO,EACL,OAAO;AACP,+EAA+E;AAC/E,SAAS,EACT,OAAO,GACR,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEhF,oEAAoE;AACpE,uCAAuC;AACvC,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAC5F,OAAO,EACL,gCAAgC,EAChC,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uDAAuD,CAAC;AAE3F,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAEhF,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["// Copyright 2024 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport './runtime-marker.js';\nimport './native/index.js';\n\nimport { __root } from './runtime/page/root-instance.js';\n\n/**\n * @internal kept only to fail fast when stale internal imports leak into the\n * Element Template alias surface. This is not a supported ET runtime API.\n */\nexport class SnapshotInstance {\n constructor(public type: string) {\n throw new Error('SnapshotInstance should not be instantiated when using Element Template.');\n }\n}\n\nexport { __root };\n\nexport {\n options,\n // Component is not an internal API, but refresh needs it from 'react/internal'\n Component,\n process,\n} from 'preact';\nexport type { Options } from 'preact';\n\nexport { loadDynamicJS, __dynamicImport } from '../core/lynx/dynamic-import.js';\n\n// Re-exported so lazy bundle shells can reach the host runtime APIs\n// via `target[sExportsReactInternal]`.\nexport { registerRuntimeVersion, getRuntimeVersion } from '../core/lynx/runtime-version.js';\nexport {\n RUNTIME_BACKEND_ELEMENT_TEMPLATE,\n RUNTIME_BACKEND_SNAPSHOT,\n registerRuntimeBackend,\n} from '../core/lynx/runtime-backend.js';\n\nexport { withInitDataInState } from '../core/initData.js';\n\nexport { wrapWithLynxComponent } from '../core/compat/lynxComponent.js';\n\nexport { loadLazyBundle } from '../core/lynx/lazy-bundle.js';\n\nexport { transformToWorklet } from './runtime/template/main-thread-background-function.js';\n\nexport { captureMainThreadObject } from '../core/capture-main-thread-object.js';\n\nexport {\n __etAttrPlanMap,\n adaptEventAttrSlot,\n adaptMTEventAttrSlot,\n adaptMTRefAttrSlot,\n adaptRefAttrSlot,\n adaptSpreadAttrSlot,\n} from './runtime/template/attr-slot-plan.js';\nexport { __ElementTemplatePage } from './runtime/page/authored-page.js';\n\nexport { __etHost } from './runtime/render/host.js';\n"]}
|