@lynx-js/react 0.106.0 → 0.106.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +2 -2
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/lazy/internal.js +1 -1
- package/runtime/lib/lifecycle/event/jsReady.d.ts +6 -0
- package/runtime/lib/lifecycle/event/jsReady.js +29 -0
- package/runtime/lib/lifecycle/event/jsReady.js.map +1 -0
- package/runtime/lib/lifecycle/patch/commit.js +2 -1
- package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/lifecycle/reload.d.ts +1 -1
- package/runtime/lib/lifecycle/reload.js +18 -14
- package/runtime/lib/lifecycle/reload.js.map +1 -1
- package/runtime/lib/lynx/calledByNative.js +11 -30
- package/runtime/lib/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/lynx/lazy-bundle.d.ts +2 -2
- package/runtime/lib/lynx/lazy-bundle.js +49 -46
- package/runtime/lib/lynx/lazy-bundle.js.map +1 -1
- package/runtime/src/lifecycle/event/jsReady.ts +33 -0
- package/runtime/src/lifecycle/patch/commit.ts +2 -1
- package/runtime/src/lifecycle/reload.ts +20 -15
- package/runtime/src/lynx/calledByNative.ts +13 -33
- package/runtime/src/lynx/lazy-bundle.ts +52 -46
- package/transform/dist/wasm.cjs +1 -1
|
@@ -1,19 +1,18 @@
|
|
|
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 {
|
|
5
|
-
|
|
6
|
-
import { render as renderToString } from '../renderToOpcodes/index.js';
|
|
7
|
-
import { LifecycleConstant } from '../lifecycleConstant.js';
|
|
8
|
-
import { takeGlobalRefPatchMap } from '../snapshot/ref.js';
|
|
9
|
-
import { isEmptyObject } from '../utils.js';
|
|
10
|
-
import { __root, setRoot } from '../root.js';
|
|
4
|
+
import { hydrate } from '../hydrate.js';
|
|
5
|
+
import { isJSReady, jsReady, jsReadyEventIdSwap, resetJSReady } from '../lifecycle/event/jsReady.js';
|
|
11
6
|
import { reloadMainThread } from '../lifecycle/reload.js';
|
|
12
7
|
import { renderMainThread } from '../lifecycle/render.js';
|
|
13
|
-
import {
|
|
14
|
-
import { markTiming, PerformanceTimingKeys, setPipeline } from './performance.js';
|
|
8
|
+
import { LifecycleConstant } from '../lifecycleConstant.js';
|
|
15
9
|
import { __pendingListUpdates } from '../list.js';
|
|
16
10
|
import { ssrHydrateByOpcodes } from '../opcodes.js';
|
|
11
|
+
import { __root, setRoot } from '../root.js';
|
|
12
|
+
import { takeGlobalRefPatchMap } from '../snapshot/ref.js';
|
|
13
|
+
import { SnapshotInstance, __page, setupPage } from '../snapshot.js';
|
|
14
|
+
import { isEmptyObject } from '../utils.js';
|
|
15
|
+
import { PerformanceTimingKeys, markTiming, setPipeline } from './performance.js';
|
|
17
16
|
|
|
18
17
|
function ssrEncode() {
|
|
19
18
|
const { __opcodes } = __root;
|
|
@@ -52,10 +51,8 @@ function ssrHydrate(info: string) {
|
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
function injectCalledByNative(): void {
|
|
55
|
-
if (process.env['NODE_ENV'] !== 'test') {
|
|
56
|
-
|
|
57
|
-
throw new Error('`firstScreenSyncTiming` must be `jsReady` when SSR is enabled');
|
|
58
|
-
}
|
|
54
|
+
if (process.env['NODE_ENV'] !== 'test' && __FIRST_SCREEN_SYNC_TIMING__ !== 'jsReady' && __ENABLE_SSR__) {
|
|
55
|
+
throw new Error('`firstScreenSyncTiming` must be `jsReady` when SSR is enabled');
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
const calledByNative: LynxCallByNative = {
|
|
@@ -77,8 +74,7 @@ function injectCalledByNative(): void {
|
|
|
77
74
|
|
|
78
75
|
function renderPage(data: any): void {
|
|
79
76
|
// reset `jsReady` state
|
|
80
|
-
|
|
81
|
-
jsReadyEventIdSwap = {};
|
|
77
|
+
resetJSReady();
|
|
82
78
|
|
|
83
79
|
lynx.__initData = data || {};
|
|
84
80
|
|
|
@@ -96,14 +92,13 @@ function renderPage(data: any): void {
|
|
|
96
92
|
}
|
|
97
93
|
}
|
|
98
94
|
|
|
99
|
-
function updatePage(data: any, options?: UpdatePageOption
|
|
95
|
+
function updatePage(data: any, options?: UpdatePageOption): void {
|
|
100
96
|
if (options?.reloadTemplate) {
|
|
101
97
|
reloadMainThread(data, options);
|
|
102
98
|
return;
|
|
103
99
|
}
|
|
104
100
|
|
|
105
101
|
if (options?.resetPageData) {
|
|
106
|
-
// @ts-ignore
|
|
107
102
|
lynx.__initData = {};
|
|
108
103
|
}
|
|
109
104
|
|
|
@@ -146,7 +141,7 @@ function updatePage(data: any, options?: UpdatePageOption | undefined): void {
|
|
|
146
141
|
}
|
|
147
142
|
}
|
|
148
143
|
|
|
149
|
-
function updateGlobalProps(_data: any, options?: UpdatePageOption
|
|
144
|
+
function updateGlobalProps(_data: any, options?: UpdatePageOption): void {
|
|
150
145
|
if (options) {
|
|
151
146
|
__FlushElementTree(__page, options);
|
|
152
147
|
} else {
|
|
@@ -154,21 +149,6 @@ function updateGlobalProps(_data: any, options?: UpdatePageOption | undefined):
|
|
|
154
149
|
}
|
|
155
150
|
}
|
|
156
151
|
|
|
157
|
-
let isJSReady: boolean;
|
|
158
|
-
let jsReadyEventIdSwap: Record<number, number>;
|
|
159
|
-
function jsReady() {
|
|
160
|
-
__OnLifecycleEvent([
|
|
161
|
-
LifecycleConstant.firstScreen, /* FIRST_SCREEN */
|
|
162
|
-
{
|
|
163
|
-
root: JSON.stringify(__root),
|
|
164
|
-
refPatch: JSON.stringify(takeGlobalRefPatchMap()),
|
|
165
|
-
jsReadyEventIdSwap,
|
|
166
|
-
},
|
|
167
|
-
]);
|
|
168
|
-
isJSReady = true;
|
|
169
|
-
jsReadyEventIdSwap = {};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
152
|
/**
|
|
173
153
|
* @internal
|
|
174
154
|
*/
|
|
@@ -54,57 +54,63 @@ export const makeSyncThen = function<T>(result: T) {
|
|
|
54
54
|
* @returns
|
|
55
55
|
* @public
|
|
56
56
|
*/
|
|
57
|
-
export
|
|
57
|
+
export const loadLazyBundle: <
|
|
58
58
|
T extends { default: React.ComponentType<any> },
|
|
59
|
-
>(source: string)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
59
|
+
>(source: string) => Promise<T> = /*#__PURE__*/ (() => {
|
|
60
|
+
lynx.loadLazyBundle = loadLazyBundle;
|
|
61
|
+
|
|
62
|
+
function loadLazyBundle<
|
|
63
|
+
T extends { default: React.ComponentType<any> },
|
|
64
|
+
>(source: string): Promise<T> {
|
|
65
|
+
if (__LEPUS__) {
|
|
66
|
+
const query = __QueryComponent(source);
|
|
67
|
+
let result: T;
|
|
68
|
+
try {
|
|
69
|
+
result = query.evalResult;
|
|
70
|
+
} catch (e) {
|
|
71
|
+
// Here we cannot return a rejected promise
|
|
72
|
+
// (which will eventually be an unhandled rejection and cause unnecessary redbox)
|
|
73
|
+
// But we still need a object in shape of Promise
|
|
74
|
+
// So we return a Promise which will never resolve or reject,
|
|
75
|
+
// which fit our principle "lepus run only once at first-screen" better
|
|
76
|
+
return new Promise(() => {});
|
|
77
|
+
}
|
|
78
|
+
const r: Promise<T> = Promise.resolve(result);
|
|
79
|
+
// Why we should modify the implementation of `then`?
|
|
80
|
+
// We should make it `sync` so lepus first-screen render can use result above instantly
|
|
81
|
+
// We also should keep promise shape
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
r.then = makeSyncThen(result);
|
|
84
|
+
return r;
|
|
85
|
+
} else if (__JS__) {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
const callback: (result: any) => void = result => {
|
|
88
|
+
const { code, detail } = result;
|
|
89
|
+
if (code === 0) {
|
|
90
|
+
const { schema } = detail;
|
|
91
|
+
const exports = lynxCoreInject.tt.getDynamicComponentExports(schema);
|
|
92
|
+
// `code === 0` means that the lazy bundle has been successfully parsed. However,
|
|
93
|
+
// its javascript files may still fail to run, which would prevent the retrieval of the exports object.
|
|
94
|
+
if (exports) {
|
|
95
|
+
resolve(exports);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
92
98
|
}
|
|
99
|
+
reject(new Error('Lazy bundle load failed: ' + JSON.stringify(result)));
|
|
100
|
+
};
|
|
101
|
+
if (typeof lynx.QueryComponent === 'function') {
|
|
102
|
+
lynx.QueryComponent(source, callback);
|
|
103
|
+
} else {
|
|
104
|
+
lynx.getNativeLynx().QueryComponent!(source, callback);
|
|
93
105
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (typeof lynx.QueryComponent === 'function') {
|
|
97
|
-
lynx.QueryComponent(source, callback);
|
|
98
|
-
} else {
|
|
99
|
-
lynx.getNativeLynx().QueryComponent!(source, callback);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
103
108
|
|
|
104
|
-
|
|
105
|
-
}
|
|
109
|
+
throw new Error('unreachable');
|
|
110
|
+
}
|
|
106
111
|
|
|
107
|
-
|
|
112
|
+
return loadLazyBundle;
|
|
113
|
+
})();
|
|
108
114
|
|
|
109
115
|
/**
|
|
110
116
|
* @internal
|