@lynx-js/react 0.122.1 → 0.123.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -0
- package/components/lib/Page.js +1 -1
- package/components/lib/Page.js.map +1 -1
- package/components/src/Page.ts +1 -1
- package/package.json +1 -1
- package/runtime/lazy/compat.js +1 -0
- package/runtime/lazy/react.js +1 -0
- package/runtime/lib/core/lynx/dynamic-import.d.ts +1 -0
- package/runtime/lib/core/lynx/dynamic-import.js +3 -2
- package/runtime/lib/core/lynx/dynamic-import.js.map +1 -1
- package/runtime/lib/core/lynx/lazy-bundle.d.ts +7 -1
- package/runtime/lib/core/lynx/lazy-bundle.js +182 -3
- package/runtime/lib/core/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/core/lynx-data-processors.d.ts +1 -0
- package/runtime/lib/core/lynx-data-processors.js +19 -1
- package/runtime/lib/core/lynx-data-processors.js.map +1 -1
- package/runtime/lib/internal.js +9 -0
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +19 -0
- package/runtime/lib/lynx-api.js +38 -5
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +5 -0
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/constant.d.ts +3 -2
- package/runtime/lib/snapshot/lifecycle/constant.js +4 -1
- package/runtime/lib/snapshot/lifecycle/constant.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.d.ts +9 -0
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js +80 -0
- package/runtime/lib/snapshot/lifecycle/event/firstScreenSync.js.map +1 -0
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js +5 -4
- package/runtime/lib/snapshot/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/snapshot/lifecycle/reload.js +3 -3
- package/runtime/lib/snapshot/lifecycle/reload.js.map +1 -1
- package/runtime/lib/snapshot/list/listUpdateInfo.js +8 -0
- package/runtime/lib/snapshot/list/listUpdateInfo.js.map +1 -1
- package/runtime/lib/snapshot/lynx/calledByNative.js +20 -9
- package/runtime/lib/snapshot/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/snapshot/lynx/injectLepusMethods.js +1 -1
- package/runtime/lib/snapshot/lynx/injectLepusMethods.js.map +1 -1
- package/runtime/lib/snapshot/lynx/lazyBundleConstants.d.ts +4 -0
- package/runtime/lib/snapshot/lynx/lazyBundleConstants.js +8 -0
- package/runtime/lib/snapshot/lynx/lazyBundleConstants.js.map +1 -0
- package/runtime/lib/snapshot/lynx/prepareLazyBundleMTS.d.ts +1 -0
- package/runtime/lib/snapshot/lynx/prepareLazyBundleMTS.js +60 -0
- package/runtime/lib/snapshot/lynx/prepareLazyBundleMTS.js.map +1 -0
- package/runtime/lib/snapshot/lynx/tt.js +3 -3
- package/runtime/lib/snapshot/lynx/tt.js.map +1 -1
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js +7 -0
- package/runtime/lib/snapshot/renderToOpcodes/hydrate.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js +5 -2
- package/runtime/lib/snapshot/snapshot/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/definition.js +4 -4
- package/runtime/lib/snapshot/snapshot/definition.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/platformInfo.d.ts +3 -1
- package/runtime/lib/snapshot/snapshot/platformInfo.js +21 -2
- package/runtime/lib/snapshot/snapshot/platformInfo.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshot.d.ts +2 -5
- package/runtime/lib/snapshot/snapshot/snapshot.js +14 -16
- package/runtime/lib/snapshot/snapshot/snapshot.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotCreatorMap.d.ts +16 -1
- package/runtime/lib/snapshot/snapshot/snapshotCreatorMap.js +8 -0
- package/runtime/lib/snapshot/snapshot/snapshotCreatorMap.js.map +1 -1
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.d.ts +6 -0
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js +16 -0
- package/runtime/lib/snapshot/snapshot/snapshotInstanceManager.js.map +1 -0
- package/runtime/lib/snapshot/snapshot/spread.d.ts +1 -1
- package/runtime/lib/snapshot/snapshot/spread.js +11 -5
- package/runtime/lib/snapshot/snapshot/spread.js.map +1 -1
- package/runtime/lib/tsconfig.tsbuildinfo +1 -1
- package/testing-library/dist/0~@rstest/adapter-rsbuild.js +59 -7
- package/transform/dist/wasm.cjs +332 -125
- package/transform/index.d.ts +40 -0
- package/types/react.docs.d.ts +6 -0
- package/runtime/lib/snapshot/lifecycle/event/jsReady.d.ts +0 -6
- package/runtime/lib/snapshot/lifecycle/event/jsReady.js +0 -44
- package/runtime/lib/snapshot/lifecycle/event/jsReady.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,83 @@
|
|
|
1
1
|
# @lynx-js/react
|
|
2
2
|
|
|
3
|
+
## 0.123.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Stop injecting `webpackChunkName` into dynamic imports so lazy bundle intermediate files stay inside the output directory. ([#2961](https://github.com/lynx-family/lynx-stack/pull/2961))
|
|
8
|
+
|
|
9
|
+
The ReactLynx transform injected `webpackChunkName: "<request>-react__<layer>"`, so a dynamic import resolving above the compiler context (e.g. `import('../../Foo.js')`) leaked `../` into `[name]`/`[id]` and the intermediate js/css/hmr files escaped the output directory. Async chunks now keep rspack's own ids, `__webpack_require__.lynx_aci` maps them by chunk id, and each lazy bundle's intermediate JS and CSS are emitted under `.rspeedy/async/<bundle-name>/<layer>.js` and `<layer>.css` next to its other intermediate outputs (`tasm.json`, `debug-metadata.json`, CSS hot-update files). Explicit `webpackChunkName` comments written by users are still honored and keep the user-controlled `[name]` placement. Main-thread chunks no longer emit CSS hot-update files — CSS only exists on the background thread, and the main-thread HMR runtime receives updates from it.
|
|
10
|
+
|
|
11
|
+
These packages release together and must be upgraded together: `@lynx-js/react-webpack-plugin` and `@lynx-js/css-extract-webpack-plugin` require `@lynx-js/template-webpack-plugin` `^0.13.0`, and `@lynx-js/react-rsbuild-plugin` requires `@lynx-js/react` `^0.123.0`.
|
|
12
|
+
|
|
13
|
+
- Add the `lynx.fetchBundle`-based lazy bundle loader. Control whether the first ([#2584](https://github.com/lynx-family/lynx-stack/pull/2584))
|
|
14
|
+
screen blocks on the fetch with the `mode` import attribute:
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import('./Foo.jsx', { with: { mode: 'sync' } }); // block the first screen
|
|
18
|
+
import('./Foo.jsx', { with: { mode: 'async' } }); // default, non-blocking
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Enable it by setting `engineVersion: '3.9'` (or higher) in `pluginReactLynx`. The
|
|
22
|
+
lazy bundle's main-thread section is bytecoded by default (skipped in dev or when
|
|
23
|
+
`DEBUG` includes `rspeedy`).
|
|
24
|
+
|
|
25
|
+
- Add `firstScreenSyncTiming: 'manual'` and a new `markFirstScreenSyncReady()` API exported by `@lynx-js/react`. ([#2826](https://github.com/lynx-family/lynx-stack/pull/2826))
|
|
26
|
+
|
|
27
|
+
In `'manual'` mode, the main thread holds the UI control after the first screen until the business calls `markFirstScreenSyncReady()`, so the handover timing to the background thread (for hydration) is fully controlled by the user. The API can be called from both threads (a background-thread call is forwarded to the main thread) and takes effect once the first-screen tree has finished rendering.
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
pluginReactLynx({
|
|
31
|
+
firstScreenSyncTiming: 'manual',
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { markFirstScreenSyncReady } from '@lynx-js/react';
|
|
37
|
+
|
|
38
|
+
markFirstScreenSyncReady();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- Add `compat.legacySlot` to `pluginReactLynx`. When enabled, dynamic children are compiled to the pre-SlotV2 form (JSX `children` + `wrapper` elements + `__DynamicPartChildren`/`__DynamicPartSlot` symbols instead of `$0`/`$1` slot props + `SlotV2`), so the compiled output stays compatible with legacy runtimes without `SlotV2` support (`< 0.120.0`, which shipped the SlotV2 refactor in #1764) — e.g. a standalone lazy bundle consumed by a host App that ships an older runtime. ([#2947](https://github.com/lynx-family/lynx-stack/pull/2947))
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import { defineConfig } from '@lynx-js/rspeedy';
|
|
47
|
+
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';
|
|
48
|
+
|
|
49
|
+
export default defineConfig({
|
|
50
|
+
plugins: [
|
|
51
|
+
pluginReactLynx({
|
|
52
|
+
compat: {
|
|
53
|
+
legacySlot: true,
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The default (SlotV2) codegen is unchanged, and the runtime keeps supporting both forms.
|
|
61
|
+
|
|
62
|
+
- Keep DevTools Lepus ID mapping wired to the shared snapshot instance manager, so production devtools builds can resolve native unique IDs without importing the full snapshot runtime into the main-thread bundle. ([#2960](https://github.com/lynx-family/lynx-stack/pull/2960))
|
|
63
|
+
|
|
64
|
+
- Add ALOG diagnostics for list flush and hydration update information. ([#2975](https://github.com/lynx-family/lynx-stack/pull/2975))
|
|
65
|
+
|
|
66
|
+
- Fix the error when using dynamic `key` with spread attributes on `<list-item>`. ([#1948](https://github.com/lynx-family/lynx-stack/pull/1948))
|
|
67
|
+
|
|
68
|
+
**Error Message:**
|
|
69
|
+
|
|
70
|
+
```text
|
|
71
|
+
Native error:
|
|
72
|
+
code: 220201
|
|
73
|
+
message: Error for illegal list item-key in parse insert with indexes: [0, ]
|
|
74
|
+
fix_suggestion: Please check the legality of the item-key.
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- Preserve list item platform info when item-key is provided through spread props. ([#2918](https://github.com/lynx-family/lynx-stack/pull/2918))
|
|
78
|
+
|
|
79
|
+
- Bind the snapshot runtime via `import` in development instead of inline `require('@lynx-js/react/internal')`, so dev builds work with async (promise) externals. Dev snapshot creators now receive the runtime as a parameter (staying self-contained for cross-thread HMR `DEV_ONLY_AddSnapshot`) with a temporary `__runtime__ || require(...)` fallback for older runtimes that call creators with a single argument; production creators keep the statically tree-shakeable module-scope reference. ([#2939](https://github.com/lynx-family/lynx-stack/pull/2939))
|
|
80
|
+
|
|
3
81
|
## 0.122.1
|
|
4
82
|
|
|
5
83
|
### Patch Changes
|
package/components/lib/Page.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Page.js","sourceRoot":"","sources":["../src/Page.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAI1D,+BAA+B;AAC/B,6FAA6F;AAC7F,4CAA4C;AAC5C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEhF,IAAI,WAAW,GAAG,KAAK,CAAC;AAExB,MAAM,IAAI;AACR,eAAe,CAAC,CAAC;IACf,IAAI,SAAS,EAAE,CAAC;QACd,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,MAAO,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAiC,EAAE,EAAE;YACtG,qBAAqB;YACrB,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;gBACvB,OAAO;YACT,CAAC;YACD,oBAAoB;YACpB,YAAY,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"Page.js","sourceRoot":"","sources":["../src/Page.ts"],"names":[],"mappings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GAAG,KAAK,CAAC;YACrC,CAAC;iBAAM,CAAC;gBACN,WAAW,GAAG,IAAI,CAAC;YACrB,CAAC;YAED,OAAO,GAAG,EAAE;gBACV,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE;oBAC5B;wBACE,GAAG,MAAM,CAAC,WAAW,CACnB,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;4BAC5C,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;wBAC1B,CAAC,CAAC,CACH;wBACD,QAAQ,EAAE,IAAI;qBACf;iBACF,CAAC,CAAC;gBACH,oBAAoB;gBACpB,IAAI,kBAAkB,CAAC,OAAO;oBAAE,WAAW,GAAG,KAAK,CAAC;YACtD,CAAC,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,QAAQ,CAAC;IAClB,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,EAAE,CAAC;AAEP,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/components/src/Page.ts
CHANGED
package/package.json
CHANGED
package/runtime/lazy/compat.js
CHANGED
package/runtime/lazy/react.js
CHANGED
|
@@ -20,9 +20,10 @@ export function loadDynamicJS(url) {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
export function __dynamicImport(url, options) {
|
|
23
|
-
const
|
|
23
|
+
const w = options?.with;
|
|
24
|
+
const t = w?.type;
|
|
24
25
|
if (t === 'component' || t === 'tsx' || t === 'jsx') {
|
|
25
|
-
return loadLazyBundle(url);
|
|
26
|
+
return loadLazyBundle(url, w?.mode);
|
|
26
27
|
}
|
|
27
28
|
else {
|
|
28
29
|
return loadDynamicJS(url);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-import.js","sourceRoot":"","sources":["../../../src/core/lynx/dynamic-import.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;A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,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YAC5C,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAS,CAAC,CAAC;YACrB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,GAAW,EACX,OAAoF;IAEpF,MAAM,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC;IACxB,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAClB,IAAI,CAAC,KAAK,WAAW,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC;QACpD,OAAO,cAAc,CAAM,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;SAAM,CAAC;QACN,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
export type LazyBundleMode = 'sync' | 'async';
|
|
1
2
|
/**
|
|
2
3
|
* Load dynamic component from source. Designed to be used with `lazy`.
|
|
4
|
+
*
|
|
5
|
+
* The `mode` is threaded in by the chunk-loading runtime from the
|
|
6
|
+
* `import(..., { with: { mode } })` import attribute (see `lynx_acm`), so each
|
|
7
|
+
* lazy import carries its own mode instead of relying on shared mutable state.
|
|
3
8
|
* @param source - where dynamic component template.js locates
|
|
9
|
+
* @param mode - `'sync'` (first-screen blocking) or `'async'` (default)
|
|
4
10
|
* @returns
|
|
5
11
|
* @public
|
|
6
12
|
*/
|
|
7
13
|
export declare const loadLazyBundle: <T extends {
|
|
8
14
|
default: React.ComponentType<any>;
|
|
9
|
-
}>(source: string) => Promise<T>;
|
|
15
|
+
}>(source: string, mode?: LazyBundleMode, host?: string) => Promise<T>;
|
|
@@ -1,6 +1,23 @@
|
|
|
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
|
+
// Inlined rather than imported from `snapshot/` so this `core/` module stays
|
|
5
|
+
// free of runtime-backend dependencies (enforced by
|
|
6
|
+
// `guardrails/snapshot-containment`). `PREPARE_LAZY_BUNDLE_MTS` must stay in
|
|
7
|
+
// sync with `snapshot/lifecycle/constant.ts`'s
|
|
8
|
+
// `LifecycleConstant.prepareLazyBundleMTS`, the lifecycle name the snapshot
|
|
9
|
+
// backend registers the main-thread prepare handler under.
|
|
10
|
+
const SECTION_MAIN_THREAD = 'main-thread';
|
|
11
|
+
const SECTION_BACKGROUND = 'background';
|
|
12
|
+
const SECTION_CSS = 'CSS';
|
|
13
|
+
const LYNX_LAZY_SYNC_TIMEOUT_SECONDS = 5;
|
|
14
|
+
const PREPARE_LAZY_BUNDLE_MTS = 'rLynxPrepareLazyBundleMTS';
|
|
15
|
+
// Background-thread dedup cache: a `source` whose FetchBundle load fully
|
|
16
|
+
// succeeded maps to its exports, so a repeat load returns the same result
|
|
17
|
+
// without re-fetching or re-triggering the main-thread prepare. Only populated
|
|
18
|
+
// on success — a failed load stays out of the cache and can be retried, exactly
|
|
19
|
+
// like `prepareLazyBundleMTS`'s main-thread cache.
|
|
20
|
+
const fetchBundleBgCache = new Map();
|
|
4
21
|
/**
|
|
5
22
|
* To make code below works
|
|
6
23
|
* const App1 = lazy(() => import("./x").then(({App1}) => ({default: App1})))
|
|
@@ -44,15 +61,44 @@ export const makeSyncThen = function (result) {
|
|
|
44
61
|
return this;
|
|
45
62
|
};
|
|
46
63
|
};
|
|
64
|
+
// loadScript a background section with `globalThis.globDynamicComponentEntry`
|
|
65
|
+
// set to `entry` (restored after). The bundle's wrapper reads it once as
|
|
66
|
+
// `g.globDynamicComponentEntry || '__Card__'`, so without this its modules — and
|
|
67
|
+
// any nested `import()` it triggers — would resolve against the caller's host.
|
|
68
|
+
function loadBackgroundBundle(bundleName, entry) {
|
|
69
|
+
const g = globalThis;
|
|
70
|
+
const previous = g.globDynamicComponentEntry;
|
|
71
|
+
g.globDynamicComponentEntry = entry;
|
|
72
|
+
try {
|
|
73
|
+
return lynx.loadScript(SECTION_BACKGROUND, { bundleName });
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
g.globDynamicComponentEntry = previous;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
47
79
|
/**
|
|
48
80
|
* Load dynamic component from source. Designed to be used with `lazy`.
|
|
81
|
+
*
|
|
82
|
+
* The `mode` is threaded in by the chunk-loading runtime from the
|
|
83
|
+
* `import(..., { with: { mode } })` import attribute (see `lynx_acm`), so each
|
|
84
|
+
* lazy import carries its own mode instead of relying on shared mutable state.
|
|
49
85
|
* @param source - where dynamic component template.js locates
|
|
86
|
+
* @param mode - `'sync'` (first-screen blocking) or `'async'` (default)
|
|
50
87
|
* @returns
|
|
51
88
|
* @public
|
|
52
89
|
*/
|
|
53
90
|
export const loadLazyBundle = /*#__PURE__*/ (() => {
|
|
54
|
-
|
|
55
|
-
|
|
91
|
+
// Default to QueryComponent when `__LAZY_BUNDLE_FETCHER__` is missing —
|
|
92
|
+
// older react-webpack-plugin builds don't stamp it and they predate
|
|
93
|
+
// FetchBundle support, so falling through to QueryComponent is the only
|
|
94
|
+
// safe behavior.
|
|
95
|
+
const useFetchBundle = typeof __LAZY_BUNDLE_FETCHER__ !== 'undefined'
|
|
96
|
+
&& __LAZY_BUNDLE_FETCHER__ === 'FetchBundle';
|
|
97
|
+
const impl = useFetchBundle
|
|
98
|
+
? loadLazyBundleWithFetchBundle
|
|
99
|
+
: loadLazyBundleWithQueryComponent;
|
|
100
|
+
lynx.loadLazyBundle = impl;
|
|
101
|
+
function loadLazyBundleWithQueryComponent(source, mode) {
|
|
56
102
|
if (__LEPUS__) {
|
|
57
103
|
const query = __QueryComponent(source);
|
|
58
104
|
let result;
|
|
@@ -75,6 +121,10 @@ export const loadLazyBundle = /*#__PURE__*/ (() => {
|
|
|
75
121
|
return r;
|
|
76
122
|
}
|
|
77
123
|
else if (__JS__) {
|
|
124
|
+
if (__DEV__ && mode !== undefined) {
|
|
125
|
+
throw new Error(`Lazy bundle import \`mode: '${mode}'\` requires FetchBundle, but the current build uses QueryComponent. `
|
|
126
|
+
+ `Set \`engineVersion: '3.9'\` (or higher) in \`pluginReactLynx\` to enable FetchBundle.`);
|
|
127
|
+
}
|
|
78
128
|
const resolver = withSyncResolvers();
|
|
79
129
|
const callback = result => {
|
|
80
130
|
const { code, detail } = result;
|
|
@@ -117,7 +167,136 @@ export const loadLazyBundle = /*#__PURE__*/ (() => {
|
|
|
117
167
|
}
|
|
118
168
|
throw new Error('unreachable');
|
|
119
169
|
}
|
|
120
|
-
|
|
170
|
+
function loadLazyBundleWithFetchBundle(source, mode, host) {
|
|
171
|
+
if (__MAIN_THREAD__) {
|
|
172
|
+
if (mode !== 'sync') {
|
|
173
|
+
// Fire the fetch and ignore the result so the request goes out early
|
|
174
|
+
// and warms the native bundle cache; the background `async` path then
|
|
175
|
+
// waits less. The main thread renders nothing here.
|
|
176
|
+
try {
|
|
177
|
+
lynx.fetchBundle(source, {});
|
|
178
|
+
}
|
|
179
|
+
catch { }
|
|
180
|
+
return new Promise(() => { });
|
|
181
|
+
}
|
|
182
|
+
let response;
|
|
183
|
+
try {
|
|
184
|
+
response = lynx.fetchBundle(source, {}).wait(LYNX_LAZY_SYNC_TIMEOUT_SECONDS);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return new Promise(() => { });
|
|
188
|
+
}
|
|
189
|
+
if (!response || response.code !== 0) {
|
|
190
|
+
return new Promise(() => { });
|
|
191
|
+
}
|
|
192
|
+
let result;
|
|
193
|
+
try {
|
|
194
|
+
result = lynx.loadScript(SECTION_MAIN_THREAD, {
|
|
195
|
+
bundleName: response.url,
|
|
196
|
+
})(source);
|
|
197
|
+
const styleSheet = __LoadStyleSheet(SECTION_CSS, response.url);
|
|
198
|
+
if (styleSheet !== null) {
|
|
199
|
+
__AdoptStyleSheet(styleSheet);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return new Promise(() => { });
|
|
204
|
+
}
|
|
205
|
+
const r = Promise.resolve(result);
|
|
206
|
+
r.then = makeSyncThen(result);
|
|
207
|
+
return r;
|
|
208
|
+
}
|
|
209
|
+
else if (__JS__) {
|
|
210
|
+
const cached = fetchBundleBgCache.get(source);
|
|
211
|
+
if (cached !== undefined) {
|
|
212
|
+
const r = Promise.resolve(cached);
|
|
213
|
+
r.then = makeSyncThen(cached);
|
|
214
|
+
return r;
|
|
215
|
+
}
|
|
216
|
+
if (mode === 'sync') {
|
|
217
|
+
let response;
|
|
218
|
+
try {
|
|
219
|
+
response = lynx.fetchBundle(source, {}).wait(LYNX_LAZY_SYNC_TIMEOUT_SECONDS);
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
return Promise.reject(e instanceof Error ? e : new Error(String(e)));
|
|
223
|
+
}
|
|
224
|
+
if (!response || response.code !== 0) {
|
|
225
|
+
console.error('Lazy bundle load failed', response);
|
|
226
|
+
const e = new Error('Lazy bundle load failed, schema: ' + source);
|
|
227
|
+
e.cause = JSON.stringify(response);
|
|
228
|
+
return Promise.reject(e);
|
|
229
|
+
}
|
|
230
|
+
let result;
|
|
231
|
+
try {
|
|
232
|
+
result = loadBackgroundBundle(response.url, source);
|
|
233
|
+
}
|
|
234
|
+
catch (e) {
|
|
235
|
+
return Promise.reject(e instanceof Error ? e : new Error(String(e)));
|
|
236
|
+
}
|
|
237
|
+
// A sync bundle that wasn't part of the first-screen main-thread render
|
|
238
|
+
// still needs its main-thread section prepared on the MT (the
|
|
239
|
+
// createSnapshot side effect), or a later patch referencing it hits
|
|
240
|
+
// "snapshot not found". Runs synchronously — the bundle is already in
|
|
241
|
+
// the native cache — just like the async path below.
|
|
242
|
+
try {
|
|
243
|
+
lynx.getNativeApp().callLepusMethod(PREPARE_LAZY_BUNDLE_MTS, { url: source, host }, () => { });
|
|
244
|
+
}
|
|
245
|
+
catch (e) {
|
|
246
|
+
return Promise.reject(e instanceof Error ? e : new Error(String(e)));
|
|
247
|
+
}
|
|
248
|
+
// Fully loaded and prepared — cache so repeat loads skip the work above.
|
|
249
|
+
fetchBundleBgCache.set(source, result);
|
|
250
|
+
const r = Promise.resolve(result);
|
|
251
|
+
r.then = makeSyncThen(result);
|
|
252
|
+
return r;
|
|
253
|
+
}
|
|
254
|
+
// async (default)
|
|
255
|
+
return new Promise((resolve, reject) => {
|
|
256
|
+
let handler;
|
|
257
|
+
try {
|
|
258
|
+
handler = lynx.fetchBundle(source, {});
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
reject(e instanceof Error ? e : new Error(String(e)));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
handler.then((response) => {
|
|
265
|
+
if (!response || response.code !== 0) {
|
|
266
|
+
console.error('Lazy bundle load failed', response);
|
|
267
|
+
const e = new Error('Lazy bundle load failed, schema: ' + source);
|
|
268
|
+
e.cause = JSON.stringify(response);
|
|
269
|
+
reject(e);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
let btsResult;
|
|
273
|
+
try {
|
|
274
|
+
btsResult = loadBackgroundBundle(response.url, source);
|
|
275
|
+
}
|
|
276
|
+
catch (e) {
|
|
277
|
+
reject(e instanceof Error ? e : new Error(String(e)));
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
// Bundle is now in native cache, so MT's `.then` fires sync and
|
|
281
|
+
// the whole prepare runs synchronously inside `Call`, meaning the
|
|
282
|
+
// cb fires only after MT snapshots are registered.
|
|
283
|
+
try {
|
|
284
|
+
lynx.getNativeApp().callLepusMethod(PREPARE_LAZY_BUNDLE_MTS, { url: source, host }, () => {
|
|
285
|
+
// Fully loaded and MT-prepared — cache so repeat loads skip
|
|
286
|
+
// the fetch / background eval / MT prepare above.
|
|
287
|
+
fetchBundleBgCache.set(source, btsResult);
|
|
288
|
+
resolve(btsResult);
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
catch (e) {
|
|
292
|
+
reject(e instanceof Error ? e : new Error(String(e)));
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
throw new Error('unreachable');
|
|
298
|
+
}
|
|
299
|
+
return impl;
|
|
121
300
|
})();
|
|
122
301
|
function withSyncResolvers() {
|
|
123
302
|
'background-only';
|
|
@@ -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;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,UAAY,MAAS;IAC/C,OAAO,UAEL,GAAmD,EACnD,IAAuD;QAEvD,IAAI,GAAG,EAAE,CAAC;YACR,IAAI,GAA2B,CAAC;YAChC,IAAI,CAAC;gBACH,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,aAAa;gBACb,oCAAoC;gBACpC,IAAI;gBACJ,OAAO,OAAO,CAAC,MAAM,CAAC,CAAU,CAAC,CAAC;YACpC,CAAC;YAED,IAAI,GAAG,IAAI,OAAQ,GAAwB,CAAC,IAAI,KAAK,UAAU,CAAC,uBAAuB,EAAE,CAAC;gBACxF,aAAa;gBACb,+CAA+C;gBAC/C,IAAI;gBACJ,6DAA6D;gBAC7D,yDAAyD;gBACzD,qCAAqC;gBACrC,OAAO,GAAmB,CAAC;gBAE3B,8FAA8F;gBAC9F,oBAAoB;gBACpB,eAAe;gBACf,2LAA2L;gBAC3L,OAAO;gBACP,yBAAyB;gBACzB,KAAK;YACP,CAAC;YAED,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAE/B,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C,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;4BAC1C,OAAO,CAAC,SAAS,CAAC,CAAC;wBACrB,CAAC,CACF,CAAC;oBACJ,CAAC;oBAAC,OAAO,CAAC,EAAE,CAAC;wBACX,MAAM,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBACxD,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,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"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { DataProcessorDefinition, InitData, InitDataRaw } from '../lynx-api.js';
|
|
2
|
+
export declare function isProcessingDefaultData(): boolean;
|
|
2
3
|
export declare function createProcessData(dataProcessorDefinition?: DataProcessorDefinition): (data: InitDataRaw, processorName?: string) => InitData | InitDataRaw;
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { profileEnd, profileStart } from '../shared/profile.js';
|
|
2
|
+
// `true` only while the default data processor is running. `defaultDataProcessor` is
|
|
3
|
+
// invoked by the native side as a separate call *before* `renderPage` / `updatePage`,
|
|
4
|
+
// so a `markFirstScreenSyncReady()` made inside it must not sync the *previous* tree
|
|
5
|
+
// (still latched ready) — a re-render of the data being processed is imminent. The
|
|
6
|
+
// first-screen sync backend reads this to defer such a mark. Lives here (not in the
|
|
7
|
+
// backend) so `core` does not depend on a runtime backend.
|
|
8
|
+
let processingDefaultData = false;
|
|
9
|
+
export function isProcessingDefaultData() {
|
|
10
|
+
return processingDefaultData;
|
|
11
|
+
}
|
|
2
12
|
export function createProcessData(dataProcessorDefinition) {
|
|
3
13
|
let hasDefaultDataProcessorExecuted = false;
|
|
4
14
|
return (data, processorName) => {
|
|
@@ -11,7 +21,15 @@ export function createProcessData(dataProcessorDefinition) {
|
|
|
11
21
|
result = dataProcessorDefinition?.dataProcessors?.[processorName]?.(data) ?? data;
|
|
12
22
|
}
|
|
13
23
|
else {
|
|
14
|
-
|
|
24
|
+
// a `markFirstScreenSyncReady()` made inside `defaultDataProcessor` must be
|
|
25
|
+
// deferred until the data being processed renders (see `processingDefaultData`)
|
|
26
|
+
processingDefaultData = true;
|
|
27
|
+
try {
|
|
28
|
+
result = dataProcessorDefinition?.defaultDataProcessor?.(data) ?? data;
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
processingDefaultData = false;
|
|
32
|
+
}
|
|
15
33
|
}
|
|
16
34
|
}
|
|
17
35
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lynx-data-processors.js","sourceRoot":"","sources":["../../src/core/lynx-data-processors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEhE,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;QA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I,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"}
|
package/runtime/lib/internal.js
CHANGED
|
@@ -6,6 +6,7 @@ import './runtime-backend-marker.js';
|
|
|
6
6
|
import './lynx.js';
|
|
7
7
|
import { useMemo } from './core/hooks/react.js';
|
|
8
8
|
import { loadLazyBundle } from './core/lynx/lazy-bundle.js';
|
|
9
|
+
import * as ReactLynxInternalSelf from './internal.js';
|
|
9
10
|
import { __root } from './root.js';
|
|
10
11
|
import { factory as factory2 } from './snapshot/compat/componentIs.js';
|
|
11
12
|
import { BackgroundSnapshotInstance } from './snapshot/snapshot/backgroundSnapshot.js';
|
|
@@ -13,6 +14,7 @@ import { __page, __pageId, createSnapshot, snapshotManager } from './snapshot/sn
|
|
|
13
14
|
import { DynamicPartType } from './snapshot/snapshot/dynamicPartType.js';
|
|
14
15
|
import { snapshotCreateList } from './snapshot/snapshot/list.js';
|
|
15
16
|
import { SnapshotInstance, snapshotCreatorMap } from './snapshot/snapshot/snapshot.js';
|
|
17
|
+
import { setSnapshotCreatorRuntime } from './snapshot/snapshot/snapshotCreatorMap.js';
|
|
16
18
|
export { CHILDREN, COMPONENT, DIFF, DIRTY, DOM, FLAGS, INDEX, PARENT } from './shared/render-constants.js';
|
|
17
19
|
export { __page, __pageId, __root };
|
|
18
20
|
export { BackgroundSnapshotInstance, SnapshotInstance, snapshotCreateList, createSnapshot, snapshotManager, snapshotCreatorMap, };
|
|
@@ -48,4 +50,11 @@ export { loadLazyBundle } from './core/lynx/lazy-bundle.js';
|
|
|
48
50
|
export { createBackgroundFunctionHandle as transformToWorklet } from './core/background-function/handle.js';
|
|
49
51
|
export { registerWorkletOnBackground } from './snapshot/worklet/hmr.js';
|
|
50
52
|
export { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings';
|
|
53
|
+
if (__DEV__) {
|
|
54
|
+
// Dev snapshot creators take the runtime as a parameter (they are
|
|
55
|
+
// stringified for cross-thread HMR and must not capture module bindings);
|
|
56
|
+
// register this namespace as that runtime. Production creators close over
|
|
57
|
+
// their own module's runtime import, so this reference is dropped there.
|
|
58
|
+
setSnapshotCreatorRuntime(ReactLynxInternalSelf);
|
|
59
|
+
}
|
|
51
60
|
//# sourceMappingURL=internal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D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sync when `firstScreenSyncTiming` is `'manual'`.
|
|
74
|
+
*
|
|
75
|
+
* The main thread holds the UI control until this is called, so the handover timing to
|
|
76
|
+
* the background thread (for hydration) is fully controlled by the user. It can be called
|
|
77
|
+
* from both threads (a background-thread call is forwarded to the main thread), is a no-op
|
|
78
|
+
* unless `firstScreenSyncTiming` is `'manual'`, and has no further effect once called.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { markFirstScreenSyncReady } from "@lynx-js/react"
|
|
84
|
+
*
|
|
85
|
+
* markFirstScreenSyncReady();
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export declare function markFirstScreenSyncReady(): void;
|
|
72
91
|
/**
|
|
73
92
|
* The {@link https://react.dev/reference/react/createContext#provider | Provider} Component that provide `initData`,
|
|
74
93
|
* you must wrap your JSX inside it
|
package/runtime/lib/lynx-api.js
CHANGED
|
@@ -10,6 +10,7 @@ import { factory, withInitDataInState } from './core/initData.js';
|
|
|
10
10
|
import { __root } from './root.js';
|
|
11
11
|
import { profileEnd, profileStart } from './shared/profile.js';
|
|
12
12
|
import { LifecycleConstant } from './snapshot/lifecycle/constant.js';
|
|
13
|
+
import { onFirstScreenSyncReady } from './snapshot/lifecycle/event/firstScreenSync.js';
|
|
13
14
|
import { flushDelayedLifecycleEvents } from './snapshot/lynx/tt.js';
|
|
14
15
|
/**
|
|
15
16
|
* The default and only root of ReactLynx for you to render JSX
|
|
@@ -36,13 +37,16 @@ export const root = {
|
|
|
36
37
|
if (typeof __PROFILE__ !== 'undefined' && __PROFILE__) {
|
|
37
38
|
profileEnd();
|
|
38
39
|
}
|
|
39
|
-
if (__FIRST_SCREEN_SYNC_TIMING__ === '
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
|
|
40
|
+
if (__FIRST_SCREEN_SYNC_TIMING__ === 'jsReady') {
|
|
41
|
+
// `jsReady` is a special case of the `manual` first-screen sync: the
|
|
42
|
+
// framework marks ready automatically once the background is ready.
|
|
43
|
+
lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
45
|
-
|
|
46
|
+
// `immediately` or `manual`: the first screen is synced without waiting
|
|
47
|
+
// for the background, so the `firstScreen` message might have been
|
|
48
|
+
// reached when `root.render()` is called asynchronously.
|
|
49
|
+
flushDelayedLifecycleEvents();
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
52
|
},
|
|
@@ -51,6 +55,35 @@ export const root = {
|
|
|
51
55
|
lynx.registerDataProcessors(dataProcessorDefinition);
|
|
52
56
|
},
|
|
53
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Mark the first screen as ready to sync when `firstScreenSyncTiming` is `'manual'`.
|
|
60
|
+
*
|
|
61
|
+
* The main thread holds the UI control until this is called, so the handover timing to
|
|
62
|
+
* the background thread (for hydration) is fully controlled by the user. It can be called
|
|
63
|
+
* from both threads (a background-thread call is forwarded to the main thread), is a no-op
|
|
64
|
+
* unless `firstScreenSyncTiming` is `'manual'`, and has no further effect once called.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { markFirstScreenSyncReady } from "@lynx-js/react"
|
|
70
|
+
*
|
|
71
|
+
* markFirstScreenSyncReady();
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
export function markFirstScreenSyncReady() {
|
|
77
|
+
if (__FIRST_SCREEN_SYNC_TIMING__ !== 'manual') {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) {
|
|
81
|
+
// The sync happens on the main thread, forward the mark to it.
|
|
82
|
+
lynx.getNativeApp().callLepusMethod(LifecycleConstant.firstScreenSyncReady, {});
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
onFirstScreenSyncReady();
|
|
86
|
+
}
|
|
54
87
|
const _InitData = /* @__PURE__ */ factory({
|
|
55
88
|
createContext,
|
|
56
89
|
useState,
|