@lynx-js/react 0.106.1 → 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 +8 -0
- package/package.json +1 -1
- 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/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/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
|
@@ -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
|